Merge remote-tracking branch 'upstream/master'

This commit is contained in:
David Bomba 2016-01-11 19:52:46 +11:00
commit d9bbafa3ca
10 changed files with 106 additions and 41 deletions

View File

@ -1,7 +1,10 @@
<?php namespace app\Listeners; <?php namespace app\Listeners;
use Utils;
use Auth;
use App\Events\InvoiceWasEmailed; use App\Events\InvoiceWasEmailed;
use App\Events\InvoiceWasUpdated; use App\Events\InvoiceWasUpdated;
use App\Events\InvoiceWasCreated;
use App\Events\PaymentWasCreated; use App\Events\PaymentWasCreated;
use App\Events\PaymentWasDeleted; use App\Events\PaymentWasDeleted;
use App\Events\PaymentWasRestored; use App\Events\PaymentWasRestored;
@ -9,15 +12,19 @@ use App\Events\InvoiceInvitationWasViewed;
class InvoiceListener class InvoiceListener
{ {
public function createdPayment(PaymentWasCreated $event) public function createdInvoice(InvoiceWasCreated $event)
{ {
$payment = $event->payment; if (Utils::isPro()) {
$invoice = $payment->invoice; return;
$adjustment = $payment->amount * -1; }
$partial = max(0, $invoice->partial - $payment->amount);
$invoice->updateBalances($adjustment, $partial); $invoice = $event->invoice;
$invoice->updatePaidStatus(); $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) public function updatedInvoice(InvoiceWasUpdated $event)
@ -32,6 +39,17 @@ class InvoiceListener
$invitation->markViewed(); $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) public function deletedPayment(PaymentWasDeleted $event)
{ {
$payment = $event->payment; $payment = $event->payment;

View File

@ -20,7 +20,6 @@ class Account extends Eloquent
protected $presenter = 'App\Ninja\Presenters\AccountPresenter'; protected $presenter = 'App\Ninja\Presenters\AccountPresenter';
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
protected $hidden = ['ip']; protected $hidden = ['ip'];
public $fonts_obj = null;
public static $basicSettings = [ public static $basicSettings = [
ACCOUNT_COMPANY_DETAILS, ACCOUNT_COMPANY_DETAILS,
@ -36,8 +35,8 @@ class Account extends Eloquent
public static $advancedSettings = [ public static $advancedSettings = [
ACCOUNT_INVOICE_SETTINGS, ACCOUNT_INVOICE_SETTINGS,
ACCOUNT_INVOICE_DESIGN, ACCOUNT_INVOICE_DESIGN,
ACCOUNT_CLIENT_PORTAL,
ACCOUNT_EMAIL_SETTINGS, ACCOUNT_EMAIL_SETTINGS,
ACCOUNT_CLIENT_PORTAL,
ACCOUNT_TEMPLATES_AND_REMINDERS, ACCOUNT_TEMPLATES_AND_REMINDERS,
ACCOUNT_CHARTS_AND_REPORTS, ACCOUNT_CHARTS_AND_REPORTS,
ACCOUNT_DATA_VISUALIZATIONS, ACCOUNT_DATA_VISUALIZATIONS,
@ -897,6 +896,11 @@ class Account extends Eloquent
return $css; return $css;
} }
public function hasLargeFont()
{
return stripos($this->getBodyFontName(), 'chinese') || stripos($this->getHeaderFontName(), 'chinese');
}
public function getFontsUrl($protocol = ''){ public function getFontsUrl($protocol = ''){
if ($this->isPro()){ if ($this->isPro()){
$bodyFont = $this->body_font_id; $bodyFont = $this->body_font_id;

View File

@ -31,6 +31,7 @@ class EventServiceProvider extends ServiceProvider {
'App\Events\InvoiceWasCreated' => [ 'App\Events\InvoiceWasCreated' => [
'App\Listeners\ActivityListener@createdInvoice', 'App\Listeners\ActivityListener@createdInvoice',
'App\Listeners\SubscriptionListener@createdInvoice', 'App\Listeners\SubscriptionListener@createdInvoice',
'App\Listeners\InvoiceListener@createdInvoice',
], ],
'App\Events\InvoiceWasUpdated' => [ 'App\Events\InvoiceWasUpdated' => [
'App\Listeners\ActivityListener@updatedInvoice', 'App\Listeners\ActivityListener@updatedInvoice',

View File

@ -30926,8 +30926,13 @@ function GetPdfMake(invoice, javascript, callback) {
} }
} }
// only show the footer on the last page // only show the header on the first page
if (invoice.is_pro && key === 'footer') { // 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 function(page, pages) {
return page === pages ? val : ''; return page === pages ? val : '';
} }

View File

@ -54,8 +54,13 @@ function GetPdfMake(invoice, javascript, callback) {
} }
} }
// only show the footer on the last page // only show the header on the first page
if (invoice.is_pro && key === 'footer') { // 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 function(page, pages) {
return page === pages ? val : ''; return page === pages ? val : '';
} }

View File

@ -1031,4 +1031,5 @@ return array(
'body_font_id' => 'Body Font', '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.', 'color_font_help' => 'Note: the primary color and fonts are also used in the client portal and custom email designs.',
'live_preview' => 'Live Preview',
); );

View File

@ -122,32 +122,46 @@
<div role="tabpanel" class="tab-pane active" id="generalSettings"> <div role="tabpanel" class="tab-pane active" id="generalSettings">
<div class="panel-body"> <div class="panel-body">
@if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST) <div class="row">
{!! Former::select('invoice_design_id') <div class="col-md-6">
->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') @if (!Utils::isPro() || \App\Models\InvoiceDesign::count() == COUNT_FREE_DESIGNS_SELF_HOST)
->style('width:300px') {!! Former::select('invoice_design_id')
->type('number') ->fromQuery($invoiceDesigns, 'name', 'id')
->min('0') ->addOption(trans('texts.more_designs') . '...', '-1') !!}
->step('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') !!} </div>
{!! Former::text('secondary_color') <div class="col-md-6">
->help('<br/>'.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) }}
</div>
</div>
<div class="help-block">
{{ trans('texts.color_font_help') }}
</div>
</div> </div>
</div> </div>

View File

@ -242,7 +242,9 @@
var fieldName = 'email_' + section + '_' + field; var fieldName = 'email_' + section + '_' + field;
var value = templates[field][section]; var value = templates[field][section];
$('#' + fieldName).val(value); $('#' + fieldName).val(value);
editors[field].setHTML(value); if (section == 'template') {
editors[field].setHTML(value);
}
refreshPreview(); refreshPreview();
} }

View File

@ -327,9 +327,10 @@
} }
} }
}); });
var tab = localStorage.getItem('client_tab'); var tab = localStorage.getItem('client_tab') || '';
if (tab && tab != 'activity') { var selector = '.nav-tabs a[href="#' + tab.replace('#', '') + '"]';
$('.nav-tabs a[href="#' + tab.replace('#', '') + '"]').tab('show'); if (tab && tab != 'activity' && $(selector).length) {
$(selector).tab('show');
} else { } else {
window['load_activity'](); window['load_activity']();
} }

View File

@ -393,6 +393,11 @@
{!! 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') !!}
@ -942,11 +947,20 @@
return invoice; return invoice;
} }
window.generatedPDF = false;
function getPDFString(cb, force) { 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 invoice = createInvoiceModel();
var design = getDesignJavascript(); var design = getDesignJavascript();
if (!design) return; if (!design) return;
generatePDF(invoice, design, force, cb); generatePDF(invoice, design, force, cb);
window.generatedPDF = true;
} }
function getDesignJavascript() { function getDesignJavascript() {