1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on invoice customizer

This commit is contained in:
Hillel Coren 2015-07-26 23:05:38 +03:00
parent 912fe5b7a3
commit 76a53ed5dc
8 changed files with 118 additions and 127 deletions

View File

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

View File

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

View File

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

View File

@ -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"
}
}]
}

View File

@ -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"
}
}
]

View File

@ -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"
}
}
]

View File

@ -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"
}
}
]

View File

@ -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 @@
<div class="pull-right">
{!! Button::normal(trans('texts.documentation'))->asLinkTo(PDFMAKE_DOCS)->withAttributes(['target' => '_blank'])->appendIcon(Icon::create('info-sign')) !!}
{!! Button::normal(trans('texts.cancel'))->asLinkTo(URL::to('/company/advanced_settings/invoice_design'))->appendIcon(Icon::create('remove-circle')) !!}
{!! Button::success(trans('texts.save'))->withAttributes(['onclick' => 'submitForm()'])->appendIcon(Icon::create('floppy-disk')) !!}
@if (Auth::user()->isPro())
{!! Button::success(trans('texts.save'))->withAttributes(['onclick' => 'submitForm()'])->appendIcon(Icon::create('floppy-disk')) !!}
@endif
</div>
</div>