From c6ff456d4d9bf705d0d6a8461bbdd92d08dbcb23 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 14:37:23 +0200 Subject: [PATCH 1/6] Fixes #608 --- resources/views/accounts/templates_and_reminders.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/accounts/templates_and_reminders.blade.php b/resources/views/accounts/templates_and_reminders.blade.php index a709890b8634..6b88ab70f9be 100644 --- a/resources/views/accounts/templates_and_reminders.blade.php +++ b/resources/views/accounts/templates_and_reminders.blade.php @@ -242,7 +242,9 @@ var fieldName = 'email_' + section + '_' + field; var value = templates[field][section]; $('#' + fieldName).val(value); - editors[field].setHTML(value); + if (section == 'template') { + editors[field].setHTML(value); + } refreshPreview(); } From 08fd14a4c1fbf399ac9aeaa0b76642c6e2cae512 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 16:22:40 +0200 Subject: [PATCH 2/6] Added a 'Live Preview' option when using a large font --- app/Models/Account.php | 6 +++++- resources/lang/en/texts.php | 1 + resources/views/invoices/edit.blade.php | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index 456facf62df5..04e32fad7818 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -20,7 +20,6 @@ class Account extends Eloquent protected $presenter = 'App\Ninja\Presenters\AccountPresenter'; protected $dates = ['deleted_at']; protected $hidden = ['ip']; - public $fonts_obj = null; public static $basicSettings = [ ACCOUNT_COMPANY_DETAILS, @@ -897,6 +896,11 @@ class Account extends Eloquent return $css; } + public function hasLargeFont() + { + return stripos($this->getBodyFontName(), 'chinese') || stripos($this->getHeaderFontName(), 'chinese'); + } + public function getFontsUrl($protocol = ''){ if ($this->isPro()){ $bodyFont = $this->body_font_id; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3b1582a3df20..10e253be27b0 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1031,4 +1031,5 @@ return array( 'body_font_id' => 'Body Font', 'color_font_help' => 'Note: the primary color and fonts are also used in the client portal and custom email designs.', + 'live_preview' => 'Live Preview', ); \ No newline at end of file diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index e62313d6f8ae..a0d91604697c 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -393,6 +393,11 @@ {!! Former::text('pdfupload') !!} + @if ($account->hasLargeFont()) + + @endif @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') !!} @@ -942,11 +947,20 @@ return invoice; } + window.generatedPDF = false; function getPDFString(cb, force) { + @if ($account->hasLargeFont()) + console.log('checked: %s', $('#livePreview').is(':checked')); + if (!$('#livePreview').is(':checked') && window.generatedPDF) { + console.log('returning'); + return; + } + @endif var invoice = createInvoiceModel(); var design = getDesignJavascript(); if (!design) return; generatePDF(invoice, design, force, cb); + window.generatedPDF = true; } function getDesignJavascript() { From 36859c826240483f8cdd2743031d9a6f03d49c16 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 16:31:56 +0200 Subject: [PATCH 3/6] Only show header on the first page of the PDF --- public/js/built.js | 9 +++++++-- public/js/pdf.pdfmake.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/public/js/built.js b/public/js/built.js index 044b9c6931bd..4331c8699121 100644 --- a/public/js/built.js +++ b/public/js/built.js @@ -30926,8 +30926,13 @@ function GetPdfMake(invoice, javascript, callback) { } } - // only show the footer on the last page - if (invoice.is_pro && key === 'footer') { + // only show the header on the first page + // and the footer on the last page + if (key === 'header') { + return function(page, pages) { + return page === 1 ? val : ''; + } + } else if (invoice.is_pro && key === 'footer') { return function(page, pages) { return page === pages ? val : ''; } diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js index 52f3910b5020..11403d60cb64 100644 --- a/public/js/pdf.pdfmake.js +++ b/public/js/pdf.pdfmake.js @@ -54,8 +54,13 @@ function GetPdfMake(invoice, javascript, callback) { } } - // only show the footer on the last page - if (invoice.is_pro && key === 'footer') { + // only show the header on the first page + // and the footer on the last page + if (key === 'header') { + return function(page, pages) { + return page === 1 ? val : ''; + } + } else if (invoice.is_pro && key === 'footer') { return function(page, pages) { return page === pages ? val : ''; } From 5fbe59fa8bea5160a5c515411f32168ede386f99 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 20:17:55 +0200 Subject: [PATCH 4/6] Auto-set last used design as account default for non pro --- app/Listeners/InvoiceListener.php | 32 ++++++++++++++++++++------ app/Providers/EventServiceProvider.php | 1 + 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/Listeners/InvoiceListener.php b/app/Listeners/InvoiceListener.php index 55759ba82ff8..ac4918af1d2a 100644 --- a/app/Listeners/InvoiceListener.php +++ b/app/Listeners/InvoiceListener.php @@ -1,7 +1,10 @@ payment; - $invoice = $payment->invoice; - $adjustment = $payment->amount * -1; - $partial = max(0, $invoice->partial - $payment->amount); + if (Utils::isPro()) { + return; + } - $invoice->updateBalances($adjustment, $partial); - $invoice->updatePaidStatus(); + $invoice = $event->invoice; + $account = Auth::user()->account; + + if ($account->invoice_design_id != $invoice->invoice_design_id) { + $account->invoice_design_id = $invoice->invoice_design_id; + $account->save(); + } } public function updatedInvoice(InvoiceWasUpdated $event) @@ -32,6 +39,17 @@ class InvoiceListener $invitation->markViewed(); } + public function createdPayment(PaymentWasCreated $event) + { + $payment = $event->payment; + $invoice = $payment->invoice; + $adjustment = $payment->amount * -1; + $partial = max(0, $invoice->partial - $payment->amount); + + $invoice->updateBalances($adjustment, $partial); + $invoice->updatePaidStatus(); + } + public function deletedPayment(PaymentWasDeleted $event) { $payment = $event->payment; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 7e0743d501c4..37a09fbc44ca 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -31,6 +31,7 @@ class EventServiceProvider extends ServiceProvider { 'App\Events\InvoiceWasCreated' => [ 'App\Listeners\ActivityListener@createdInvoice', 'App\Listeners\SubscriptionListener@createdInvoice', + 'App\Listeners\InvoiceListener@createdInvoice', ], 'App\Events\InvoiceWasUpdated' => [ 'App\Listeners\ActivityListener@updatedInvoice', From 9436f5a51e20b6b24fe4a9db24855c9e57365290 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 20:25:15 +0200 Subject: [PATCH 5/6] Fixed issue where a tab on the client page can be blank on page load --- resources/views/clients/show.blade.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index a7939f12e487..06b0e7774abb 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -327,9 +327,10 @@ } } }); - var tab = localStorage.getItem('client_tab'); - if (tab && tab != 'activity') { - $('.nav-tabs a[href="#' + tab.replace('#', '') + '"]').tab('show'); + var tab = localStorage.getItem('client_tab') || ''; + var selector = '.nav-tabs a[href="#' + tab.replace('#', '') + '"]'; + if (tab && tab != 'activity' && $(selector).length) { + $(selector).tab('show'); } else { window['load_activity'](); } From d72ff27e6270fdbd051810cf906fb6f3e0ab0165 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 10 Jan 2016 20:40:04 +0200 Subject: [PATCH 6/6] Improved invoice design form layout --- app/Models/Account.php | 2 +- .../views/accounts/invoice_design.blade.php | 62 ++++++++++++------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index 04e32fad7818..cecb48237406 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -35,8 +35,8 @@ class Account extends Eloquent public static $advancedSettings = [ ACCOUNT_INVOICE_SETTINGS, ACCOUNT_INVOICE_DESIGN, - ACCOUNT_CLIENT_PORTAL, ACCOUNT_EMAIL_SETTINGS, + ACCOUNT_CLIENT_PORTAL, ACCOUNT_TEMPLATES_AND_REMINDERS, ACCOUNT_CHARTS_AND_REPORTS, ACCOUNT_DATA_VISUALIZATIONS, diff --git a/resources/views/accounts/invoice_design.blade.php b/resources/views/accounts/invoice_design.blade.php index 38db2a601b11..98dac26a6f5d 100644 --- a/resources/views/accounts/invoice_design.blade.php +++ b/resources/views/accounts/invoice_design.blade.php @@ -122,32 +122,46 @@
- @if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST) - {!! Former::select('invoice_design_id') - ->style('display:inline; width:300px') - ->fromQuery($invoiceDesigns, 'name', 'id') - ->addOption(trans('texts.more_designs') . '...', '-1') !!} - @else - {!! Former::select('invoice_design_id') - ->style('display:inline; width:300px') - ->fromQuery($invoiceDesigns, 'name', 'id') !!} - @endif - {!! Former::select('header_font_id') - ->style('display:inline; width:300px') - ->fromQuery($invoiceFonts, 'name', 'id') !!} - {!! Former::select('body_font_id') - ->style('display:inline; width:300px') - ->fromQuery($invoiceFonts, 'name', 'id') !!} +
+
- {!! Former::text('font_size') - ->style('width:300px') - ->type('number') - ->min('0') - ->step('1') !!} + @if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST) + {!! Former::select('invoice_design_id') + ->fromQuery($invoiceDesigns, 'name', 'id') + ->addOption(trans('texts.more_designs') . '...', '-1') !!} + @else + {!! Former::select('invoice_design_id') + ->fromQuery($invoiceDesigns, 'name', 'id') !!} + @endif + {!! Former::select('body_font_id') + ->fromQuery($invoiceFonts, 'name', 'id') !!} + {!! Former::select('header_font_id') + ->fromQuery($invoiceFonts, 'name', 'id') !!} - {!! Former::text('primary_color') !!} - {!! Former::text('secondary_color') - ->help('
'.trans('texts.color_font_help')) !!} +
+
+ + + {{ Former::setOption('TwitterBootstrap3.labelWidths.large', 6) }} + {{ Former::setOption('TwitterBootstrap3.labelWidths.small', 6) }} + + {!! Former::text('font_size') + ->type('number') + ->min('0') + ->step('1') !!} + + {!! Former::text('primary_color') !!} + {!! Former::text('secondary_color') !!} + + {{ Former::setOption('TwitterBootstrap3.labelWidths.large', 4) }} + {{ Former::setOption('TwitterBootstrap3.labelWidths.small', 4) }} + +
+
+ +
+ {{ trans('texts.color_font_help') }} +