diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 67c185d0bd42..b77278433fdd 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -244,7 +244,7 @@ class AccountController extends BaseController } if ($subSection == ACCOUNT_CUSTOMIZE_DESIGN) { - $data['customDesign'] = $account->custom_design && !$design ? $account->custom_design : $design; + $data['customDesign'] = ($account->custom_design && !$design) ? $account->custom_design : $design; } } else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) { $data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE); @@ -698,25 +698,21 @@ class AccountController extends BaseController if ($file = Input::file('logo')) { $path = Input::file('logo')->getRealPath(); File::delete('logo/'.$account->account_key.'.jpg'); + File::delete('logo/'.$account->account_key.'.png'); $image = Image::make($path); $mimeType = $file->getMimeType(); - - if ($mimeType == 'image/jpeg') { + + if ($mimeType == 'image/jpeg' && $account->utf8_invoices) { $file->move('logo/', $account->account_key . '.jpg'); - } else if ($mimeType == 'image/png') { + } else if ($mimeType == 'image/png' && $account->utf8_invoices) { $file->move('logo/', $account->account_key . '.png'); - - if (!$account->utf8_invoices) { - $account->utf8_invoices = true; - $account->save(); - } } else { $image->resize(200, 120, function ($constraint) { $constraint->aspectRatio(); }); Image::canvas($image->width(), $image->height(), '#FFFFFF') - ->insert($image)->save('logo/'.$this->account_key.'.jpg'); + ->insert($image)->save('logo/'.$account->account_key.'.jpg'); } } @@ -730,6 +726,7 @@ class AccountController extends BaseController public function removeLogo() { File::delete('logo/'.Auth::user()->account->account_key.'.jpg'); + File::delete('logo/'.Auth::user()->account->account_key.'.png'); Session::flash('message', trans('texts.removed_logo')); diff --git a/public/js/built.js b/public/js/built.js index 4a6291fc333d..8e1227e06416 100644 --- a/public/js/built.js +++ b/public/js/built.js @@ -33260,30 +33260,25 @@ function GetPdfMake(invoice, javascript, callback) { javascript = NINJA.decodeJavascript(invoice, javascript); function jsonCallBack(key, val) { - if ((val+'').indexOf('$borderTopAndBottom') === 0) { + if ((val+'').indexOf('$firstAndLast') === 0) { var parts = val.split(':'); return function (i, node) { return (i === 0 || i === node.table.body.length) ? parseFloat(parts[1]) : 0; }; - } else if ((val+'').indexOf('$borderNone') === 0) { + } else if ((val+'').indexOf('$none') === 0) { return function (i, node) { return 0; }; - } else if ((val+'').indexOf('$borderNotTop') === 0) { + } else if ((val+'').indexOf('$notFirst') === 0) { var parts = val.split(':'); return function (i, node) { return i === 0 ? 0 : parseFloat(parts[1]); }; - } else if ((val+'').indexOf('$border') === 0) { + } else if ((val+'').indexOf('$amount') === 0) { var parts = val.split(':'); return function (i, node) { return parseFloat(parts[1]); }; - } else if ((val+'').indexOf('$padding') === 0) { - var parts = val.split(':'); - return function (i, node) { - return parseInt(parts[1], 10); - }; } else if ((val+'').indexOf('$primaryColor') === 0) { var parts = val.split(':'); return NINJA.primaryColor || parts[1]; @@ -33344,18 +33339,10 @@ NINJA.decodeJavascript = function(invoice, javascript) 'subtotalsHeight': NINJA.subtotals(invoice).length * 22, 'subtotalsWithoutBalance': NINJA.subtotals(invoice, true), 'balanceDue': formatMoney(invoice.balance_amount, invoice.client.currency_id), - 'balanceDueLabel': invoiceLabels.balance_due, 'invoiceFooter': account.invoice_footer || ' ', 'invoiceNumber': invoice.invoice_number || ' ', 'entityType': invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice, - 'entityTypeUpper': (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(), - 'yourInvoice': invoiceLabels.your_invoice, - 'yourInvoiceUpper': invoiceLabels.your_invoice.toUpperCase(), - 'invoiceIssuedTo': invoiceLabels.invoice_issued_to + ':', - 'invoiceTo': invoiceLabels.invoice_to + ':', - 'details': invoiceLabels.details + ':', - 'fromUpper': invoiceLabels.from.toUpperCase() + ':', - 'toUpper': invoiceLabels.to.toUpperCase() + ':', + 'entityTypeUC': (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(), 'fontSize': NINJA.fontSize, 'fontSizeLarger': NINJA.fontSize + 1, 'fontSizeLargest': NINJA.fontSize + 2, @@ -33368,7 +33355,7 @@ NINJA.decodeJavascript = function(invoice, javascript) } // search/replace labels - var regExp = new RegExp('"\\$\\\w*?Label(UC)?"', 'g'); + var regExp = new RegExp('"\\$\\\w*?Label(UC)?(:)?(\\\?)?"', 'g'); var matches = javascript.match(regExp); if (matches) { @@ -33376,13 +33363,21 @@ NINJA.decodeJavascript = function(invoice, javascript) var match = matches[i]; field = match.substring(2, match.indexOf('Label')); field = toSnakeCase(field); - var label = invoiceLabels[field]; - if (match.indexOf('UC') >= 0) { - if (!label) console.log('match: ' + field); - label = label.toUpperCase(); + var value = getDescendantProp(invoice, field); + if (match.indexOf('?') < 0) { + var label = invoiceLabels[field]; + if (match.indexOf('UC') >= 0) { + if (!label) console.log('match: ' + field); + label = label.toUpperCase(); + } + if (match.indexOf(':') >= 0) { + label = label + ':'; + } + } else { + label = ' '; } javascript = javascript.replace(match, '"'+label+'"'); - } + } } // search/replace values @@ -33394,8 +33389,8 @@ NINJA.decodeJavascript = function(invoice, javascript) var match = matches[i]; field = match.substring(2, match.indexOf('Value')); field = toSnakeCase(field); - var value = getDescendantProp(invoice, field) || ' '; - if (field.indexOf('date') >= 0) { + var value = getDescendantProp(invoice, field) || ' '; + if (field.toLowerCase().indexOf('date') >= 0 && value != ' ') { value = moment(value, 'YYYY-MM-DD').format('MMM D YYYY'); } javascript = javascript.replace(match, '"'+value+'"'); @@ -33594,11 +33589,11 @@ NINJA.invoiceDetails = function(invoice) { ], [ {text: invoiceLabels.invoice_date}, - {text: invoice.invoice_date} + {text: moment(invoice.invoice_date, 'YYYY-MM-DD').format('MMM D YYYY')} ], [ {text: invoiceLabels.due_date}, - {text: invoice.due_date} + {text: invoice.due_date ? moment(invoice.due_date, 'YYYY-MM-DD').format('MMM D YYYY') : false} ] ]; diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js index a968376abb78..0f7b1639f832 100644 --- a/public/js/pdf.pdfmake.js +++ b/public/js/pdf.pdfmake.js @@ -18,30 +18,25 @@ function GetPdfMake(invoice, javascript, callback) { javascript = NINJA.decodeJavascript(invoice, javascript); function jsonCallBack(key, val) { - if ((val+'').indexOf('$borderTopAndBottom') === 0) { + if ((val+'').indexOf('$firstAndLast') === 0) { var parts = val.split(':'); return function (i, node) { return (i === 0 || i === node.table.body.length) ? parseFloat(parts[1]) : 0; }; - } else if ((val+'').indexOf('$borderNone') === 0) { + } else if ((val+'').indexOf('$none') === 0) { return function (i, node) { return 0; }; - } else if ((val+'').indexOf('$borderNotTop') === 0) { + } else if ((val+'').indexOf('$notFirst') === 0) { var parts = val.split(':'); return function (i, node) { return i === 0 ? 0 : parseFloat(parts[1]); }; - } else if ((val+'').indexOf('$border') === 0) { + } else if ((val+'').indexOf('$amount') === 0) { var parts = val.split(':'); return function (i, node) { return parseFloat(parts[1]); }; - } else if ((val+'').indexOf('$padding') === 0) { - var parts = val.split(':'); - return function (i, node) { - return parseInt(parts[1], 10); - }; } else if ((val+'').indexOf('$primaryColor') === 0) { var parts = val.split(':'); return NINJA.primaryColor || parts[1]; @@ -102,18 +97,10 @@ NINJA.decodeJavascript = function(invoice, javascript) 'subtotalsHeight': NINJA.subtotals(invoice).length * 22, 'subtotalsWithoutBalance': NINJA.subtotals(invoice, true), 'balanceDue': formatMoney(invoice.balance_amount, invoice.client.currency_id), - 'balanceDueLabel': invoiceLabels.balance_due, 'invoiceFooter': account.invoice_footer || ' ', 'invoiceNumber': invoice.invoice_number || ' ', 'entityType': invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice, - 'entityTypeUpper': (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(), - 'yourInvoice': invoiceLabels.your_invoice, - 'yourInvoiceUpper': invoiceLabels.your_invoice.toUpperCase(), - 'invoiceIssuedTo': invoiceLabels.invoice_issued_to + ':', - 'invoiceTo': invoiceLabels.invoice_to + ':', - 'details': invoiceLabels.details + ':', - 'fromUpper': invoiceLabels.from.toUpperCase() + ':', - 'toUpper': invoiceLabels.to.toUpperCase() + ':', + 'entityTypeUC': (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(), 'fontSize': NINJA.fontSize, 'fontSizeLarger': NINJA.fontSize + 1, 'fontSizeLargest': NINJA.fontSize + 2, @@ -126,7 +113,7 @@ NINJA.decodeJavascript = function(invoice, javascript) } // search/replace labels - var regExp = new RegExp('"\\$\\\w*?Label(UC)?"', 'g'); + var regExp = new RegExp('"\\$\\\w*?Label(UC)?(:)?(\\\?)?"', 'g'); var matches = javascript.match(regExp); if (matches) { @@ -134,13 +121,21 @@ NINJA.decodeJavascript = function(invoice, javascript) var match = matches[i]; field = match.substring(2, match.indexOf('Label')); field = toSnakeCase(field); - var label = invoiceLabels[field]; - if (match.indexOf('UC') >= 0) { - if (!label) console.log('match: ' + field); - label = label.toUpperCase(); + var value = getDescendantProp(invoice, field); + if (match.indexOf('?') < 0) { + var label = invoiceLabels[field]; + if (match.indexOf('UC') >= 0) { + if (!label) console.log('match: ' + field); + label = label.toUpperCase(); + } + if (match.indexOf(':') >= 0) { + label = label + ':'; + } + } else { + label = ' '; } javascript = javascript.replace(match, '"'+label+'"'); - } + } } // search/replace values @@ -152,8 +147,8 @@ NINJA.decodeJavascript = function(invoice, javascript) var match = matches[i]; field = match.substring(2, match.indexOf('Value')); field = toSnakeCase(field); - var value = getDescendantProp(invoice, field) || ' '; - if (field.indexOf('date') >= 0) { + var value = getDescendantProp(invoice, field) || ' '; + if (field.toLowerCase().indexOf('date') >= 0 && value != ' ') { value = moment(value, 'YYYY-MM-DD').format('MMM D YYYY'); } javascript = javascript.replace(match, '"'+value+'"'); @@ -352,11 +347,11 @@ NINJA.invoiceDetails = function(invoice) { ], [ {text: invoiceLabels.invoice_date}, - {text: invoice.invoice_date} + {text: moment(invoice.invoice_date, 'YYYY-MM-DD').format('MMM D YYYY')} ], [ {text: invoiceLabels.due_date}, - {text: invoice.due_date} + {text: invoice.due_date ? moment(invoice.due_date, 'YYYY-MM-DD').format('MMM D YYYY') : false} ] ]; diff --git a/public/js/templates/bold.js b/public/js/templates/bold.js index 529c397b918f..79a4388ad038 100644 --- a/public/js/templates/bold.js +++ b/public/js/templates/bold.js @@ -10,7 +10,7 @@ { "width": 300, "stack": [ - {"text":"$yourInvoiceUpper", "style": "yourInvoice"}, + {"text":"$yourInvoiceLabelUC", "style": "yourInvoice"}, "$clientDetails" ], "margin": [-32, 120, 0, 0] @@ -48,12 +48,12 @@ "body": "$invoiceLineItems" }, "layout": { - "hLineWidth": "$borderNone", - "vLineWidth": "$borderNone", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:14", - "paddingBottom": "$padding:14" + "hLineWidth": "$none", + "vLineWidth": "$none", + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:14", + "paddingBottom": "$amount:14" } }, { @@ -69,12 +69,12 @@ "body": "$subtotals" }, "layout": { - "hLineWidth": "$borderNone", - "vLineWidth": "$borderNone", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:4", - "paddingBottom": "$padding:4" + "hLineWidth": "$none", + "vLineWidth": "$none", + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:4", + "paddingBottom": "$amount:4" } }] } diff --git a/public/js/templates/clean.js b/public/js/templates/clean.js index 17301faa895c..86cdfdf3ff45 100644 --- a/public/js/templates/clean.js +++ b/public/js/templates/clean.js @@ -3,11 +3,11 @@ "columns": [ { "image": "$accountLogo", - "width": 100 + "width": 140 }, { "stack": "$accountDetails", - "margin": [80, 0, 0, 0] + "margin": [40, 0, 0, 0] }, { "stack": "$accountAddress" @@ -15,7 +15,7 @@ ] }, { - "text": "$entityTypeUpper", + "text": "$entityTypeUC", "margin": [8, 50, 8, 5], "style": "entityTypeLabel" @@ -43,13 +43,13 @@ ] }, "layout": { - "hLineWidth": "$borderTopAndBottom:.5", - "vLineWidth": "$borderNone", + "hLineWidth": "$firstAndLast:.5", + "vLineWidth": "$none", "hLineColor": "#D8D8D8", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:4", - "paddingBottom": "$padding:4" + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:4", + "paddingBottom": "$amount:4" } }, { @@ -60,13 +60,13 @@ "body": "$invoiceLineItems" }, "layout": { - "hLineWidth": "$borderNotTop:.5", - "vLineWidth": "$borderNone", + "hLineWidth": "$notFirst:.5", + "vLineWidth": "$none", "hLineColor": "#D8D8D8", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:14", - "paddingBottom": "$padding:14" + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:14", + "paddingBottom": "$amount:14" } }, { @@ -78,12 +78,12 @@ "body": "$subtotals" }, "layout": { - "hLineWidth": "$borderNone", - "vLineWidth": "$borderNone", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:4", - "paddingBottom": "$padding:4" + "hLineWidth": "$none", + "vLineWidth": "$none", + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:4", + "paddingBottom": "$amount:4" } } ] diff --git a/public/js/templates/modern.js b/public/js/templates/modern.js index 21eee276c5dc..86c229db4536 100644 --- a/public/js/templates/modern.js +++ b/public/js/templates/modern.js @@ -23,13 +23,13 @@ "body": "$invoiceLineItems" }, "layout": { - "hLineWidth": "$borderNotTop:.5", - "vLineWidth": "$borderNone", + "hLineWidth": "$notFirst:.5", + "vLineWidth": "$none", "hLineColor": "#888888", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:8", - "paddingBottom": "$padding:8" + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:8", + "paddingBottom": "$amount:8" } }, { @@ -41,12 +41,12 @@ "body": "$subtotalsWithoutBalance" }, "layout": { - "hLineWidth": "$borderNone", - "vLineWidth": "$borderNone", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:4", - "paddingBottom": "$padding:4" + "hLineWidth": "$none", + "vLineWidth": "$none", + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:4", + "paddingBottom": "$amount:4" } } ] diff --git a/public/js/templates/plain.js b/public/js/templates/plain.js index b908c35eace0..bbcc7b6a1229 100644 --- a/public/js/templates/plain.js +++ b/public/js/templates/plain.js @@ -48,13 +48,13 @@ "body": "$invoiceLineItems" }, "layout": { - "hLineWidth": "$borderNotTop:1", - "vLineWidth": "$borderNone", + "hLineWidth": "$notFirst:1", + "vLineWidth": "$none", "hLineColor": "#e6e6e6", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:8", - "paddingBottom": "$padding:8" + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:8", + "paddingBottom": "$amount:8" } }, { @@ -70,12 +70,12 @@ "body": "$subtotals" }, "layout": { - "hLineWidth": "$borderNone", - "vLineWidth": "$borderNone", - "paddingLeft": "$padding:8", - "paddingRight": "$padding:8", - "paddingTop": "$padding:4", - "paddingBottom": "$padding:4" + "hLineWidth": "$none", + "vLineWidth": "$none", + "paddingLeft": "$amount:8", + "paddingRight": "$amount:8", + "paddingTop": "$amount:4", + "paddingBottom": "$amount:4" } } ] diff --git a/resources/views/accounts/customize_design.blade.php b/resources/views/accounts/customize_design.blade.php index a48414cd5db1..d5e93afe6848 100644 --- a/resources/views/accounts/customize_design.blade.php +++ b/resources/views/accounts/customize_design.blade.php @@ -36,7 +36,7 @@ var invoiceDesigns = {!! $invoiceDesigns !!}; var invoice = {!! json_encode($invoice) !!}; var sections = ['content', 'styles', 'defaultStyle', 'pageMargins', 'header', 'footer']; - var customDesign = origCustomDesign = {!! $customDesign !!}; + var customDesign = origCustomDesign = {!! $customDesign ?: 'JSON.parse(invoiceDesigns[0].javascript);' !!}; function getPDFString(cb, force) { invoice.is_pro = {!! Auth::user()->isPro() ? 'true' : 'false' !!}; @@ -57,8 +57,10 @@ showMoreDesigns(); $('#invoice_design_id').val(1); return invoiceDesigns[0].javascript; - } else { + } else if (customDesign) { return JSON.stringify(customDesign); + } else { + return invoiceDesigns[0].javascript; } } @@ -150,7 +152,9 @@