1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

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;
use Utils;
use Auth;
use App\Events\InvoiceWasEmailed;
use App\Events\InvoiceWasUpdated;
use App\Events\InvoiceWasCreated;
use App\Events\PaymentWasCreated;
use App\Events\PaymentWasDeleted;
use App\Events\PaymentWasRestored;
@ -9,15 +12,19 @@ use App\Events\InvoiceInvitationWasViewed;
class InvoiceListener
{
public function createdPayment(PaymentWasCreated $event)
public function createdInvoice(InvoiceWasCreated $event)
{
$payment = $event->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;

View File

@ -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,
@ -36,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,
@ -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;

View File

@ -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',

View File

@ -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 : '';
}

View File

@ -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 : '';
}

View File

@ -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',
);

View File

@ -122,32 +122,46 @@
<div role="tabpanel" class="tab-pane active" id="generalSettings">
<div class="panel-body">
@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') !!}
<div class="row">
<div class="col-md-6">
{!! 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('<br/>'.trans('texts.color_font_help')) !!}
</div>
<div class="col-md-6">
{{ 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>

View File

@ -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();
}

View File

@ -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']();
}

View File

@ -393,6 +393,11 @@
{!! Former::text('pdfupload') !!}
</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)
{!! 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() {