2015-05-22 09:22:24 +02:00
|
|
|
var NINJA = NINJA || {};
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.TEMPLATES = {
|
|
|
|
CLEAN: "1",
|
|
|
|
BOLD:"2",
|
|
|
|
MODERN: "3",
|
|
|
|
NORMAL:"4",
|
|
|
|
BUSINESS:"5",
|
|
|
|
CREATIVE:"6",
|
|
|
|
ELEGANT:"7",
|
|
|
|
HIPSTER:"8",
|
|
|
|
PLAYFUL:"9",
|
|
|
|
PHOTO:"10"
|
|
|
|
};
|
|
|
|
|
|
|
|
function GetPdfMake(invoice, javascript, callback) {
|
|
|
|
|
|
|
|
javascript = NINJA.decodeJavascript(invoice, javascript);
|
|
|
|
|
|
|
|
function jsonCallBack(key, val) {
|
2015-07-26 22:05:38 +02:00
|
|
|
if ((val+'').indexOf('$firstAndLast') === 0) {
|
2015-07-21 20:51:56 +02:00
|
|
|
var parts = val.split(':');
|
|
|
|
return function (i, node) {
|
|
|
|
return (i === 0 || i === node.table.body.length) ? parseFloat(parts[1]) : 0;
|
|
|
|
};
|
2015-07-26 22:05:38 +02:00
|
|
|
} else if ((val+'').indexOf('$none') === 0) {
|
2015-07-21 20:51:56 +02:00
|
|
|
return function (i, node) {
|
|
|
|
return 0;
|
|
|
|
};
|
2015-07-26 22:05:38 +02:00
|
|
|
} else if ((val+'').indexOf('$notFirst') === 0) {
|
2015-07-21 20:51:56 +02:00
|
|
|
var parts = val.split(':');
|
|
|
|
return function (i, node) {
|
|
|
|
return i === 0 ? 0 : parseFloat(parts[1]);
|
|
|
|
};
|
2015-07-26 22:05:38 +02:00
|
|
|
} else if ((val+'').indexOf('$amount') === 0) {
|
2015-07-24 16:13:17 +02:00
|
|
|
var parts = val.split(':');
|
|
|
|
return function (i, node) {
|
|
|
|
return parseFloat(parts[1]);
|
|
|
|
};
|
2015-07-21 20:51:56 +02:00
|
|
|
} else if ((val+'').indexOf('$primaryColor') === 0) {
|
|
|
|
var parts = val.split(':');
|
|
|
|
return NINJA.primaryColor || parts[1];
|
|
|
|
} else if ((val+'').indexOf('$secondaryColor') === 0) {
|
|
|
|
var parts = val.split(':');
|
|
|
|
return NINJA.secondaryColor || parts[1];
|
|
|
|
}
|
2015-05-22 09:22:24 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
return val;
|
|
|
|
}
|
2015-05-22 09:22:24 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
//console.log(javascript);
|
|
|
|
var dd = JSON.parse(javascript, jsonCallBack);
|
2015-07-24 16:13:17 +02:00
|
|
|
|
|
|
|
if (!invoice.is_pro && dd.footer.hasOwnProperty('columns')) {
|
|
|
|
dd.footer.columns.push({image: logoImages.imageLogo1, alignment: 'right', width: 130})
|
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
//console.log(JSON.stringify(dd));
|
2015-05-22 09:22:24 +02:00
|
|
|
|
2015-05-19 21:14:00 +02:00
|
|
|
/*
|
2015-07-21 20:51:56 +02:00
|
|
|
var fonts = {
|
2015-05-19 21:14:00 +02:00
|
|
|
Roboto: {
|
|
|
|
normal: 'Roboto-Regular.ttf',
|
|
|
|
bold: 'Roboto-Medium.ttf',
|
|
|
|
italics: 'Roboto-Italic.ttf',
|
|
|
|
bolditalics: 'Roboto-Italic.ttf'
|
|
|
|
},
|
|
|
|
};
|
|
|
|
*/
|
2015-06-03 19:55:48 +02:00
|
|
|
|
2015-05-19 21:14:00 +02:00
|
|
|
doc = pdfMake.createPdf(dd);
|
|
|
|
doc.save = function(fileName) {
|
|
|
|
this.download(fileName);
|
|
|
|
};
|
|
|
|
return doc;
|
2015-04-13 08:02:33 +02:00
|
|
|
}
|
2015-05-22 09:22:24 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.decodeJavascript = function(invoice, javascript)
|
|
|
|
{
|
|
|
|
var account = invoice.account;
|
|
|
|
var blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=';
|
|
|
|
|
2015-07-24 16:13:17 +02:00
|
|
|
// search/replace variables
|
2015-07-21 20:51:56 +02:00
|
|
|
var json = {
|
|
|
|
'accountName': account.name || ' ',
|
|
|
|
'accountLogo': window.accountLogo || blankImage,
|
|
|
|
'accountDetails': NINJA.accountDetails(invoice),
|
|
|
|
'accountAddress': NINJA.accountAddress(invoice),
|
|
|
|
'invoiceDetails': NINJA.invoiceDetails(invoice),
|
|
|
|
'invoiceDetailsHeight': NINJA.invoiceDetails(invoice).length * 22,
|
|
|
|
'invoiceLineItems': NINJA.invoiceLines(invoice),
|
|
|
|
'invoiceLineItemColumns': NINJA.invoiceColumns(invoice),
|
|
|
|
'clientDetails': NINJA.clientDetails(invoice),
|
|
|
|
'notesAndTerms': NINJA.notesAndTerms(invoice),
|
|
|
|
'subtotals': NINJA.subtotals(invoice),
|
|
|
|
'subtotalsHeight': NINJA.subtotals(invoice).length * 22,
|
|
|
|
'subtotalsWithoutBalance': NINJA.subtotals(invoice, true),
|
|
|
|
'balanceDue': formatMoney(invoice.balance_amount, invoice.client.currency_id),
|
|
|
|
'invoiceFooter': account.invoice_footer || ' ',
|
2015-07-24 16:13:17 +02:00
|
|
|
'invoiceNumber': invoice.invoice_number || ' ',
|
2015-07-21 20:51:56 +02:00
|
|
|
'entityType': invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice,
|
2015-07-26 22:05:38 +02:00
|
|
|
'entityTypeUC': (invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(),
|
2015-07-21 20:51:56 +02:00
|
|
|
'fontSize': NINJA.fontSize,
|
|
|
|
'fontSizeLarger': NINJA.fontSize + 1,
|
2015-07-24 16:13:17 +02:00
|
|
|
'fontSizeLargest': NINJA.fontSize + 2,
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in json) {
|
|
|
|
var regExp = new RegExp('"\\$'+key+'"', 'g');
|
|
|
|
var val = JSON.stringify(json[key]);
|
|
|
|
javascript = javascript.replace(regExp, val);
|
|
|
|
}
|
|
|
|
|
2015-07-24 16:13:17 +02:00
|
|
|
// search/replace labels
|
2015-07-26 22:05:38 +02:00
|
|
|
var regExp = new RegExp('"\\$\\\w*?Label(UC)?(:)?(\\\?)?"', 'g');
|
2015-07-24 16:13:17 +02:00
|
|
|
var matches = javascript.match(regExp);
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
for (var i=0; i<matches.length; i++) {
|
|
|
|
var match = matches[i];
|
|
|
|
field = match.substring(2, match.indexOf('Label'));
|
|
|
|
field = toSnakeCase(field);
|
2015-07-26 22:05:38 +02:00
|
|
|
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 = ' ';
|
2015-07-24 16:13:17 +02:00
|
|
|
}
|
|
|
|
javascript = javascript.replace(match, '"'+label+'"');
|
2015-07-26 22:05:38 +02:00
|
|
|
}
|
2015-07-24 16:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// search/replace values
|
|
|
|
var regExp = new RegExp('"\\$\\\w*?Value"', 'g');
|
|
|
|
var matches = javascript.match(regExp);
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
for (var i=0; i<matches.length; i++) {
|
|
|
|
var match = matches[i];
|
|
|
|
field = match.substring(2, match.indexOf('Value'));
|
|
|
|
field = toSnakeCase(field);
|
2015-07-26 22:05:38 +02:00
|
|
|
var value = getDescendantProp(invoice, field) || ' ';
|
|
|
|
if (field.toLowerCase().indexOf('date') >= 0 && value != ' ') {
|
2015-07-24 16:13:17 +02:00
|
|
|
value = moment(value, 'YYYY-MM-DD').format('MMM D YYYY');
|
|
|
|
}
|
|
|
|
javascript = javascript.replace(match, '"'+value+'"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
return javascript;
|
|
|
|
}
|
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
NINJA.notesAndTerms = function(invoice)
|
2015-04-13 22:45:09 +02:00
|
|
|
{
|
2015-07-21 20:51:56 +02:00
|
|
|
var data = [];
|
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
if (invoice.public_notes) {
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push({text:invoice.public_notes, style: ['notes']});
|
|
|
|
data.push({text:' '});
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
2015-04-13 22:45:09 +02:00
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
if (invoice.terms) {
|
2015-07-24 16:13:17 +02:00
|
|
|
data.push({text:invoiceLabels.terms, style: ['termsLabel']});
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push({text:invoice.terms, style: ['terms']});
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
2015-04-13 22:45:09 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
return NINJA.prepareDataList(data, 'notesAndTerms');
|
|
|
|
}
|
|
|
|
|
|
|
|
NINJA.invoiceColumns = function(invoice)
|
|
|
|
{
|
|
|
|
if (invoice.has_taxes) {
|
|
|
|
return ["15%", "*", "auto", "auto", "auto", "15%"];
|
|
|
|
} else {
|
|
|
|
return ["15%", "*", "auto", "auto", "15%"]
|
|
|
|
}
|
2015-04-13 22:45:09 +02:00
|
|
|
}
|
2015-04-13 14:37:42 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
NINJA.invoiceLines = function(invoice) {
|
2015-05-19 21:14:00 +02:00
|
|
|
var grid = [
|
|
|
|
[
|
2015-07-21 20:51:56 +02:00
|
|
|
{text: invoiceLabels.item, style: ['tableHeader', 'itemTableHeader']},
|
|
|
|
{text: invoiceLabels.description, style: ['tableHeader', 'descriptionTableHeader']},
|
|
|
|
{text: invoiceLabels.unit_cost, style: ['tableHeader', 'costTableHeader']},
|
|
|
|
{text: invoiceLabels.quantity, style: ['tableHeader', 'qtyTableHeader']},
|
|
|
|
{text: invoice.has_taxes ? invoiceLabels.tax : '', style: ['tableHeader', 'taxTableHeader']},
|
|
|
|
{text: invoiceLabels.line_total, style: ['tableHeader', 'lineTotalTableHeader']}
|
2015-05-19 21:14:00 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
var total = 0;
|
|
|
|
var shownItem = false;
|
|
|
|
var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1;
|
|
|
|
var hideQuantity = invoice.account.hide_quantity == '1';
|
|
|
|
|
|
|
|
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
var row = [];
|
|
|
|
var item = invoice.invoice_items[i];
|
|
|
|
var cost = formatMoney(item.cost, currencyId, true);
|
|
|
|
var qty = NINJA.parseFloat(item.qty) ? roundToTwo(NINJA.parseFloat(item.qty)) + '' : '';
|
|
|
|
var notes = item.notes;
|
|
|
|
var productKey = item.product_key;
|
2015-07-21 20:51:56 +02:00
|
|
|
var tax = '';
|
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
if (item.tax && parseFloat(item.tax.rate)) {
|
|
|
|
tax = parseFloat(item.tax.rate);
|
|
|
|
} else if (item.tax_rate && parseFloat(item.tax_rate)) {
|
|
|
|
tax = parseFloat(item.tax_rate);
|
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
// show at most one blank line
|
2015-07-24 16:13:17 +02:00
|
|
|
if (shownItem && (!cost || cost == '0.00') && !notes && !productKey) {
|
2015-05-22 09:22:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
shownItem = true;
|
2015-05-05 11:48:23 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
// process date variables
|
|
|
|
if (invoice.is_recurring) {
|
|
|
|
notes = processVariables(notes);
|
|
|
|
productKey = processVariables(productKey);
|
|
|
|
}
|
2015-05-05 11:48:23 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
var lineTotal = roundToTwo(NINJA.parseFloat(item.cost)) * roundToTwo(NINJA.parseFloat(item.qty));
|
|
|
|
if (tax) {
|
|
|
|
lineTotal += lineTotal * tax / 100;
|
|
|
|
}
|
|
|
|
if (lineTotal) {
|
|
|
|
total += lineTotal;
|
|
|
|
}
|
|
|
|
lineTotal = formatMoney(lineTotal, currencyId);
|
2015-05-05 11:48:23 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
|
|
|
|
|
|
|
row.push({style:["productKey", rowStyle], text:productKey || ' '}); // product key can be blank when selecting from a datalist
|
|
|
|
row.push({style:["notes", rowStyle], text:notes || ' '});
|
|
|
|
row.push({style:["cost", rowStyle], text:cost});
|
|
|
|
row.push({style:["quantity", rowStyle], text:qty || ' '});
|
|
|
|
|
|
|
|
if (invoice.has_taxes) {
|
|
|
|
row.push({style:["tax", rowStyle], text: tax+'' || ''});
|
|
|
|
}
|
2015-05-05 11:48:23 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
row.push({style:["lineTotal", rowStyle], text:lineTotal || ' '});
|
2015-05-05 11:48:23 +02:00
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
grid.push(row);
|
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
return NINJA.prepareDataTable(grid, 'invoiceItems');
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.subtotals = function(invoice, removeBalance)
|
2015-05-05 11:48:23 +02:00
|
|
|
{
|
|
|
|
if (!invoice) {
|
|
|
|
return;
|
2015-04-13 14:37:42 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
var account = invoice.account;
|
|
|
|
var data = [];
|
|
|
|
data.push([{text: invoiceLabels.subtotal}, {text: formatMoney(invoice.subtotal_amount, invoice.client.currency_id)}]);
|
2015-05-19 21:14:00 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
if (invoice.discount_amount != 0) {
|
|
|
|
data.push([{text: invoiceLabels.discount}, {text: formatMoney(invoice.discount_amount, invoice.client.currency_id)}]);
|
2015-04-13 14:37:42 +02:00
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push([{text: account.custom_invoice_label1}, {text: formatMoney(invoice.custom_value1, invoice.client.currency_id)}]);
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push([{text: account.custom_invoice_label2}, {text: formatMoney(invoice.custom_value2, invoice.client.currency_id)}]);
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
if (invoice.tax && invoice.tax.name || invoice.tax_name) {
|
|
|
|
data.push([{text: invoiceLabels.tax}, {text: formatMoney(invoice.tax_amount, invoice.client.currency_id)}]);
|
2015-04-13 14:37:42 +02:00
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
|
|
|
|
data.push([{text: account.custom_invoice_label1}, {text: formatMoney(invoice.custom_value1, invoice.client.currency_id)}]);
|
2015-04-13 14:37:42 +02:00
|
|
|
}
|
2015-05-05 11:48:23 +02:00
|
|
|
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push([{text: account.custom_invoice_label2}, {text: formatMoney(invoice.custom_value2, invoice.client.currency_id)}]);
|
|
|
|
}
|
2015-04-13 14:37:42 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
var paid = invoice.amount - invoice.balance;
|
2015-05-05 11:48:23 +02:00
|
|
|
if (invoice.account.hide_paid_to_date != '1' || paid) {
|
2015-07-21 20:51:56 +02:00
|
|
|
data.push([{text:invoiceLabels.paid_to_date}, {text:formatMoney(paid, invoice.client.currency_id)}]);
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
2015-04-14 12:23:35 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
if (!removeBalance) {
|
|
|
|
data.push([
|
|
|
|
{text:invoice.is_quote ? invoiceLabels.balance_due : invoiceLabels.balance_due, style:['balanceDueLabel']},
|
|
|
|
{text:formatMoney(invoice.balance_amount, invoice.client.currency_id), style:['balanceDue']}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NINJA.prepareDataPairs(data, 'subtotals');
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.accountDetails = function(invoice) {
|
|
|
|
var account = invoice.account;
|
|
|
|
var data = [
|
|
|
|
{text:account.name, style: ['accountName']},
|
|
|
|
{text:account.id_number},
|
|
|
|
{text:account.vat_number},
|
|
|
|
{text:account.work_email},
|
|
|
|
{text:account.work_phone}
|
|
|
|
];
|
|
|
|
return NINJA.prepareDataList(data, 'accountDetails');
|
2015-04-14 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.accountAddress = function(invoice) {
|
|
|
|
var account = invoice.account;
|
|
|
|
var cityStatePostal = '';
|
2015-05-05 11:48:23 +02:00
|
|
|
if (account.city || account.state || account.postal_code) {
|
2015-07-21 20:51:56 +02:00
|
|
|
cityStatePostal = ((account.city ? account.city + ', ' : '') + account.state + ' ' + account.postal_code).trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = [
|
|
|
|
{text: account.address1},
|
|
|
|
{text: account.address2},
|
|
|
|
{text: cityStatePostal},
|
|
|
|
{text: account.country ? account.country.name : ''}
|
|
|
|
];
|
|
|
|
|
|
|
|
return NINJA.prepareDataList(data, 'accountAddress');
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
NINJA.invoiceDetails = function(invoice) {
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2015-05-05 11:48:23 +02:00
|
|
|
var data = [
|
|
|
|
[
|
2015-07-21 20:51:56 +02:00
|
|
|
{text: (invoice.is_quote ? invoiceLabels.quote_number : invoiceLabels.invoice_number), style: ['invoiceNumberLabel']},
|
|
|
|
{text: invoice.invoice_number, style: ['invoiceNumber']}
|
2015-05-05 11:48:23 +02:00
|
|
|
],
|
|
|
|
[
|
2015-07-21 20:51:56 +02:00
|
|
|
{text: invoiceLabels.po_number},
|
|
|
|
{text: invoice.po_number}
|
2015-05-05 11:48:23 +02:00
|
|
|
],
|
|
|
|
[
|
2015-07-21 20:51:56 +02:00
|
|
|
{text: invoiceLabels.invoice_date},
|
2015-07-26 22:05:38 +02:00
|
|
|
{text: moment(invoice.invoice_date, 'YYYY-MM-DD').format('MMM D YYYY')}
|
2015-05-05 11:48:23 +02:00
|
|
|
],
|
2015-07-21 20:51:56 +02:00
|
|
|
[
|
|
|
|
{text: invoiceLabels.due_date},
|
2015-07-26 22:05:38 +02:00
|
|
|
{text: invoice.due_date ? moment(invoice.due_date, 'YYYY-MM-DD').format('MMM D YYYY') : false}
|
2015-07-21 20:51:56 +02:00
|
|
|
]
|
2015-05-05 11:48:23 +02:00
|
|
|
];
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
if (NINJA.parseFloat(invoice.balance) < NINJA.parseFloat(invoice.amount)) {
|
|
|
|
data.push([
|
|
|
|
{text: invoiceLabels.total},
|
|
|
|
{text: formatMoney(invoice.amount, invoice.client.currency_id)}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NINJA.parseFloat(invoice.partial)) {
|
|
|
|
data.push([
|
|
|
|
{text: invoiceLabels.balance},
|
|
|
|
{text: formatMoney(invoice.total_amount, invoice.client.currency_id)}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
data.push([
|
2015-07-24 16:13:17 +02:00
|
|
|
{text: invoiceLabels.balance_due, style: ['invoiceDetailBalanceDueLabel']},
|
2015-07-21 20:51:56 +02:00
|
|
|
{text: formatMoney(invoice.balance_amount, invoice.client.currency_id), style: ['invoiceDetailBalanceDue']}
|
|
|
|
])
|
|
|
|
|
|
|
|
return NINJA.prepareDataPairs(data, 'invoiceDetails');
|
2015-04-14 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
NINJA.clientDetails = function(invoice) {
|
2015-05-05 11:48:23 +02:00
|
|
|
var client = invoice.client;
|
2015-07-21 20:51:56 +02:00
|
|
|
var data;
|
2015-05-05 11:48:23 +02:00
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
var contact = client.contacts[0];
|
|
|
|
var clientName = client.name || (contact.first_name || contact.last_name ? (contact.first_name + ' ' + contact.last_name) : contact.email);
|
|
|
|
var clientEmail = client.contacts[0].email == clientName ? '' : client.contacts[0].email;
|
|
|
|
|
|
|
|
data = [
|
|
|
|
{text:clientName || ' ', style: ['clientName']},
|
|
|
|
{text:client.address1},
|
|
|
|
{text:concatStrings(client.city, client.state, client.postal_code)},
|
|
|
|
{text:client.country ? client.country.name : ''},
|
|
|
|
{text:clientEmail}
|
2015-05-05 11:48:23 +02:00
|
|
|
];
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
return NINJA.prepareDataList(data, 'clientDetails');
|
2015-05-05 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 09:22:24 +02:00
|
|
|
NINJA.getPrimaryColor = function(defaultColor) {
|
|
|
|
return NINJA.primaryColor ? NINJA.primaryColor : defaultColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
NINJA.getSecondaryColor = function(defaultColor) {
|
|
|
|
return NINJA.primaryColor ? NINJA.secondaryColor : defaultColor;
|
2015-04-14 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
// remove blanks and add section style to all elements
|
|
|
|
NINJA.prepareDataList = function(oldData, section) {
|
|
|
|
var newData = [];
|
|
|
|
for (var i=0; i<oldData.length; i++) {
|
|
|
|
var item = NINJA.processItem(oldData[i], section);
|
|
|
|
if (item.text) {
|
|
|
|
newData.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newData;
|
|
|
|
}
|
|
|
|
|
|
|
|
NINJA.prepareDataTable = function(oldData, section) {
|
|
|
|
var newData = [];
|
|
|
|
for (var i=0; i<oldData.length; i++) {
|
|
|
|
var row = oldData[i];
|
|
|
|
var newRow = [];
|
|
|
|
for (var j=0; j<row.length; j++) {
|
|
|
|
var item = NINJA.processItem(row[j], section);
|
|
|
|
if (item.text) {
|
|
|
|
newRow.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newRow.length) {
|
|
|
|
newData.push(newRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newData;
|
|
|
|
}
|
|
|
|
|
|
|
|
NINJA.prepareDataPairs = function(oldData, section) {
|
|
|
|
var newData = [];
|
|
|
|
for (var i=0; i<oldData.length; i++) {
|
|
|
|
var row = oldData[i];
|
|
|
|
var isBlank = false;
|
|
|
|
for (var j=0; j<row.length; j++) {
|
|
|
|
var item = NINJA.processItem(row[j], section);
|
|
|
|
if (!item.text) {
|
|
|
|
isBlank = true;
|
|
|
|
}
|
|
|
|
if (j == 1) {
|
|
|
|
NINJA.processItem(row[j], section + "Value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isBlank) {
|
|
|
|
newData.push(oldData[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newData;
|
|
|
|
}
|
|
|
|
|
|
|
|
NINJA.processItem = function(item, section) {
|
|
|
|
if (item.style && item.style instanceof Array) {
|
|
|
|
item.style.push(section);
|
|
|
|
} else {
|
|
|
|
item.style = [section];
|
|
|
|
}
|
|
|
|
return item;
|
2015-04-14 12:23:35 +02:00
|
|
|
}
|