Added page size and live preview settings

This commit is contained in:
Hillel Coren 2016-04-19 10:51:57 +03:00
parent 0c27e22b51
commit 9f5fe33059
10 changed files with 162 additions and 40 deletions

View File

@ -389,6 +389,58 @@ class AccountController extends BaseController
$data['invoiceDesigns'] = InvoiceDesign::getDesigns(); $data['invoiceDesigns'] = InvoiceDesign::getDesigns();
$data['invoiceFonts'] = Cache::get('fonts'); $data['invoiceFonts'] = Cache::get('fonts');
$data['section'] = $section; $data['section'] = $section;
$pageSizes = [
'A0',
'A1',
'A2',
'A3',
'A4',
'A5',
'A6',
'A7',
'A8',
'A9',
'A10',
'B0',
'B1',
'B2',
'B3',
'B4',
'B5',
'B6',
'B7',
'B8',
'B9',
'B10',
'C0',
'C1',
'C2',
'C3',
'C4',
'C5',
'C6',
'C7',
'C8',
'C9',
'C10',
'RA0',
'RA1',
'RA2',
'RA3',
'RA4',
'SRA0',
'SRA1',
'SRA2',
'SRA3',
'SRA4',
'Executive',
'Folio',
'Legal',
'Letter',
'Tabloid',
];
$data['pageSizes'] = array_combine($pageSizes, $pageSizes);
$design = false; $design = false;
foreach ($data['invoiceDesigns'] as $item) { foreach ($data['invoiceDesigns'] as $item) {
@ -764,10 +816,9 @@ class AccountController extends BaseController
$account->primary_color = Input::get('primary_color'); $account->primary_color = Input::get('primary_color');
$account->secondary_color = Input::get('secondary_color'); $account->secondary_color = Input::get('secondary_color');
$account->invoice_design_id = Input::get('invoice_design_id'); $account->invoice_design_id = Input::get('invoice_design_id');
$account->font_size = intval(Input::get('font_size'));
if (Input::has('font_size')) { $account->page_size = Input::get('page_size');
$account->font_size = intval(Input::get('font_size')); $account->live_preview = Input::get('live_preview') ? true : false;
}
$labels = []; $labels = [];
foreach (['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms', 'balance_due', 'partial_due'] as $field) { foreach (['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms', 'balance_due', 'partial_due'] as $field) {

View File

@ -1110,17 +1110,6 @@ class Account extends Eloquent
return $css; return $css;
} }
public function hasLargeFont()
{
foreach (['chinese', 'japanese'] as $language) {
if (stripos($this->getBodyFontName(), $language) || stripos($this->getHeaderFontName(), $language)) {
return true;
}
}
return false;
}
public function getFontsUrl($protocol = ''){ public function getFontsUrl($protocol = ''){
$bodyFont = $this->getHeaderFontId(); $bodyFont = $this->getHeaderFontId();
$headerFont = $this->getBodyFontId(); $headerFont = $this->getBodyFontId();

View File

@ -474,7 +474,8 @@ class Invoice extends EntityModel implements BalanceAffecting
'custom_invoice_text_label2', 'custom_invoice_text_label2',
'custom_invoice_item_label1', 'custom_invoice_item_label1',
'custom_invoice_item_label2', 'custom_invoice_item_label2',
'invoice_embed_documents' 'invoice_embed_documents',
'page_size',
]); ]);
foreach ($this->invoice_items as $invoiceItem) { foreach ($this->invoice_items as $invoiceItem) {

View File

@ -0,0 +1,72 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPageSize extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function ($table) {
$table->string('page_size')->default('A4');
$table->boolean('live_preview')->default(true);
$table->smallInteger('invoice_number_padding')->default(4);
});
Schema::table('fonts', function ($table) {
$table->dropColumn('is_early_access');
});
Schema::create('expense_categories', function($table)
{
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('account_id')->index();
$table->timestamps();
$table->softDeletes();
$table->string('name')->nullable();
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unsignedInteger('public_id')->index();
$table->unique( array('account_id','public_id') );
});
Schema::table('expenses', function ($table) {
$table->unsignedInteger('expense_category_id')->nullable()->index();
$table->foreign('expense_category_id')->references('id')->on('expense_categories')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('accounts', function ($table) {
$table->dropColumn('page_size');
$table->dropColumn('live_preview');
$table->dropColumn('invoice_number_padding');
});
Schema::table('fonts', function ($table) {
$table->boolean('is_early_access');
});
Schema::dropIfExists('expense_categories');
Schema::table('expenses', function ($table) {
$table->dropColumn('expense_category_id');
});
}
}

View File

@ -246,7 +246,6 @@ class FontsSeeder extends Seeder
foreach ($fonts as $font) { foreach ($fonts as $font) {
if (!DB::table('fonts')->where('name', '=', $font['name'])->get()) { if (!DB::table('fonts')->where('name', '=', $font['name'])->get()) {
$font['is_early_access'] = false;
Font::create($font); Font::create($font);
} }
} }

View File

@ -31100,7 +31100,8 @@ function GetPdfMake(invoice, javascript, callback) {
} }
} }
// set page size
dd.pageSize = invoice.account.page_size;
pdfMake.fonts = {} pdfMake.fonts = {}
fonts = window.invoiceFonts || invoice.invoice_fonts; fonts = window.invoiceFonts || invoice.invoice_fonts;

View File

@ -96,7 +96,8 @@ function GetPdfMake(invoice, javascript, callback) {
} }
} }
// set page size
dd.pageSize = invoice.account.page_size;
pdfMake.fonts = {} pdfMake.fonts = {}
fonts = window.invoiceFonts || invoice.invoice_fonts; fonts = window.invoiceFonts || invoice.invoice_fonts;

View File

@ -976,9 +976,9 @@ $LANG = array(
'expense_error_mismatch_currencies' => 'The client\'s currency does not match the expense currency.', 'expense_error_mismatch_currencies' => 'The client\'s currency does not match the expense currency.',
'trello_roadmap' => 'Trello Roadmap', 'trello_roadmap' => 'Trello Roadmap',
'header_footer' => 'Header/Footer', 'header_footer' => 'Header/Footer',
'first_page' => 'first page', 'first_page' => 'First page',
'all_pages' => 'all pages', 'all_pages' => 'All pages',
'last_page' => 'last page', 'last_page' => 'Last page',
'all_pages_header' => 'Show header on', 'all_pages_header' => 'Show header on',
'all_pages_footer' => 'Show footer on', 'all_pages_footer' => 'Show footer on',
'invoice_currency' => 'Invoice Currency', 'invoice_currency' => 'Invoice Currency',
@ -1126,7 +1126,9 @@ $LANG = array(
'enable_client_portal_help' => 'Show/hide the client portal.', 'enable_client_portal_help' => 'Show/hide the client portal.',
'enable_client_portal_dashboard' => 'Dashboard', 'enable_client_portal_dashboard' => 'Dashboard',
'enable_client_portal_dashboard_help' => 'Show/hide the dashboard page in the client portal.', 'enable_client_portal_dashboard_help' => 'Show/hide the dashboard page in the client portal.',
'live_preview' => 'Live Preview',
'page_size' => 'Page Size',
); );
return $LANG; return $LANG;

View File

@ -51,16 +51,14 @@
invoice.account.invoice_embed_documents = $('#invoice_embed_documents').is(":checked"); invoice.account.invoice_embed_documents = $('#invoice_embed_documents').is(":checked");
invoice.account.hide_paid_to_date = $('#hide_paid_to_date').is(":checked"); invoice.account.hide_paid_to_date = $('#hide_paid_to_date').is(":checked");
invoice.invoice_design_id = $('#invoice_design_id').val(); invoice.invoice_design_id = $('#invoice_design_id').val();
invoice.account.page_size = $('#page_size option:selected').text();
NINJA.primaryColor = $('#primary_color').val(); NINJA.primaryColor = $('#primary_color').val();
NINJA.secondaryColor = $('#secondary_color').val(); NINJA.secondaryColor = $('#secondary_color').val();
NINJA.fontSize = parseInt($('#font_size').val()); NINJA.fontSize = parseInt($('#font_size').val());
@if (Auth::user()->isPro()) NINJA.headerFont = $('#header_font_id option:selected').text();
NINJA.headerFont = $('#header_font_id option:selected').text(); NINJA.bodyFont = $('#body_font_id option:selected').text();
NINJA.bodyFont = $('#body_font_id option:selected').text();
@else
NINJA.headerFont = NINJA.bodyFont = 'Roboto';
@endif
var fields = [ var fields = [
'item', 'item',
'description', 'description',
@ -112,7 +110,16 @@
<div class="col-md-12"> <div class="col-md-12">
{!! Former::open()->addClass('warn-on-exit')->onchange('if(!window.loadingFonts)refreshPDF()') !!} {!! Former::open()->addClass('warn-on-exit')->onchange('if(!window.loadingFonts)refreshPDF()') !!}
{!! Former::populate($account) !!}
{!! Former::populateField('invoice_design_id', $account->invoice_design_id) !!}
{!! Former::populateField('body_font_id', $account->body_font_id) !!}
{!! Former::populateField('header_font_id', $account->header_font_id) !!}
{!! Former::populateField('live_preview', intval($account->live_preview)) !!}
{!! Former::populateField('font_size', $account->font_size) !!}
{!! Former::populateField('page_size', $account->page_size) !!}
{!! Former::populateField('invoice_embed_documents', intval($account->invoice_embed_documents)) !!}
{!! Former::populateField('primary_color', $account->primary_color) !!}
{!! Former::populateField('secondary_color', $account->secondary_color) !!}
{!! Former::populateField('hide_quantity', intval($account->hide_quantity)) !!} {!! Former::populateField('hide_quantity', intval($account->hide_quantity)) !!}
{!! Former::populateField('hide_paid_to_date', intval($account->hide_paid_to_date)) !!} {!! Former::populateField('hide_paid_to_date', intval($account->hide_paid_to_date)) !!}
{!! Former::populateField('all_pages_header', intval($account->all_pages_header)) !!} {!! Former::populateField('all_pages_header', intval($account->all_pages_header)) !!}
@ -156,13 +163,17 @@
{!! Former::select('header_font_id') {!! Former::select('header_font_id')
->fromQuery($invoiceFonts, 'name', 'id') !!} ->fromQuery($invoiceFonts, 'name', 'id') !!}
{!! Former::checkbox('live_preview')->text(trans('texts.enable')) !!}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{{ Former::setOption('TwitterBootstrap3.labelWidths.large', 6) }} {{ Former::setOption('TwitterBootstrap3.labelWidths.large', 6) }}
{{ Former::setOption('TwitterBootstrap3.labelWidths.small', 6) }} {{ Former::setOption('TwitterBootstrap3.labelWidths.small', 6) }}
{!! Former::select('page_size')
->options($pageSizes) !!}
{!! Former::text('font_size') {!! Former::text('font_size')
->type('number') ->type('number')
->min('0') ->min('0')
@ -171,6 +182,7 @@
{!! Former::text('primary_color') !!} {!! Former::text('primary_color') !!}
{!! Former::text('secondary_color') !!} {!! Former::text('secondary_color') !!}
{{ Former::setOption('TwitterBootstrap3.labelWidths.large', 4) }} {{ Former::setOption('TwitterBootstrap3.labelWidths.large', 4) }}
{{ Former::setOption('TwitterBootstrap3.labelWidths.small', 4) }} {{ Former::setOption('TwitterBootstrap3.labelWidths.small', 4) }}

View File

@ -493,12 +493,6 @@
{!! Former::text('pdfupload') !!} {!! Former::text('pdfupload') !!}
</div> </div>
@if ($account->hasLargeFont())
<label for="livePreview" class="control-label" style="padding-right:10px">
<input id="livePreview" type="checkbox"/> {{ trans('texts.live_preview') }}
</label>
@endif
@if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST) @if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST)
{!! Former::select('invoice_design_id')->style('display:inline;width:150px;background-color:white !important')->raw()->fromQuery($invoiceDesigns, 'name', 'id')->data_bind("value: invoice_design_id")->addOption(trans('texts.more_designs') . '...', '-1') !!} {!! Former::select('invoice_design_id')->style('display:inline;width:150px;background-color:white !important')->raw()->fromQuery($invoiceDesigns, 'name', 'id')->data_bind("value: invoice_design_id")->addOption(trans('texts.more_designs') . '...', '-1') !!}
@else @else
@ -1097,8 +1091,8 @@
window.generatedPDF = false; window.generatedPDF = false;
function getPDFString(cb, force) { function getPDFString(cb, force) {
@if ($account->hasLargeFont()) @if (!$account->live_preview)
if (!$('#livePreview').is(':checked') && window.generatedPDF) { if (window.generatedPDF) {
return; return;
} }
@endif @endif