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

Working on product fields

This commit is contained in:
Hillel Coren 2017-10-29 16:06:40 +02:00
parent 450e4ae66a
commit 7ecd06921f
5 changed files with 97 additions and 42 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -221,10 +221,12 @@ NINJA.decodeJavascript = function(invoice, javascript)
'invoiceDetails': NINJA.invoiceDetails(invoice), 'invoiceDetails': NINJA.invoiceDetails(invoice),
'invoiceDetailsHeight': (NINJA.invoiceDetails(invoice).length * 16) + 16, 'invoiceDetailsHeight': (NINJA.invoiceDetails(invoice).length * 16) + 16,
'invoiceLineItems': invoice.is_statement ? NINJA.statementLines(invoice) : NINJA.invoiceLines(invoice), 'invoiceLineItems': invoice.is_statement ? NINJA.statementLines(invoice) : NINJA.invoiceLines(invoice),
'invoiceLineItemColumns': invoice.is_statement ? NINJA.statementColumns(invoice) : NINJA.invoiceColumns(invoice), 'invoiceLineItemColumns': invoice.is_statement ? NINJA.statementColumns(invoice) : NINJA.invoiceColumns(invoice, javascript),
'taskLineItems': NINJA.invoiceLines(invoice, true), 'taskLineItems': NINJA.invoiceLines(invoice, true),
'taskLineItemColumns': NINJA.invoiceColumns(invoice, true), 'taskLineItemColumns': NINJA.invoiceColumns(invoice, javascript, true),
'invoiceDocuments' : NINJA.invoiceDocuments(invoice), 'invoiceDocuments' : NINJA.invoiceDocuments(invoice),
'quantityWidth': NINJA.quantityWidth(invoice),
'taxWidth': NINJA.taxWidth(invoice),
'clientDetails': NINJA.clientDetails(invoice), 'clientDetails': NINJA.clientDetails(invoice),
'notesAndTerms': NINJA.notesAndTerms(invoice), 'notesAndTerms': NINJA.notesAndTerms(invoice),
'subtotals': invoice.is_statement ? NINJA.statementSubtotals(invoice) : NINJA.subtotals(invoice), 'subtotals': invoice.is_statement ? NINJA.statementSubtotals(invoice) : NINJA.subtotals(invoice),
@ -246,9 +248,15 @@ NINJA.decodeJavascript = function(invoice, javascript)
} }
for (var key in json) { for (var key in json) {
var regExp = new RegExp('"\\$'+key+'"', 'g'); // remove trailing commas for these fields
var val = JSON.stringify(json[key]); if (['quantityWidth', 'taxWidth'].indexOf(key) >= 0) {
val = doubleDollarSign(val); var regExp = new RegExp('"\\$'+key+'",', 'g');
val = json[key];
} else {
var regExp = new RegExp('"\\$'+key+'"', 'g');
var val = JSON.stringify(json[key]);
val = doubleDollarSign(val);
}
javascript = javascript.replace(regExp, val); javascript = javascript.replace(regExp, val);
} }
@ -391,32 +399,60 @@ NINJA.statementLines = function(invoice)
return NINJA.prepareDataTable(grid, 'invoiceItems'); return NINJA.prepareDataTable(grid, 'invoiceItems');
} }
NINJA.invoiceColumns = function(invoice, isTasks) NINJA.invoiceColumns = function(invoice, design, isTasks)
{ {
var account = invoice.account; var account = invoice.account;
var columns = []; var columns = [];
var fields = NINJA.productFields(invoice, isTasks); var fields = NINJA.productFields(invoice, isTasks);
var hasDescription = fields.indexOf('product.description') >= 0; var hasDescription = fields.indexOf('product.description') >= 0;
var hasPadding = design.indexOf('"pageMargins":[0') == -1;
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {
var field = fields[i]; var field = fields[i];
var width = 0;
if (field == 'product.custom_value1') { if (field == 'product.custom_value1') {
if (invoice.has_custom_item_value1) { if (invoice.has_custom_item_value1) {
columns.push(hasDescription ? '10%' : '*'); width = 10;
} else {
continue;
} }
} else if (field == 'product.custom_value2') { } else if (field == 'product.custom_value2') {
if (invoice.has_custom_item_value2) { if (invoice.has_custom_item_value2) {
columns.push(hasDescription ? '10%' : '*'); width = 10;
} else {
continue;
} }
} else if (field == 'product.tax') { } else if (field == 'product.tax') {
if (invoice.has_item_taxes) { if (invoice.has_item_taxes) {
columns.push(hasDescription ? '15%' : '*'); width = 15;
} else {
continue;
} }
} else if (field == 'product.description') { } else if (field == 'product.description') {
columns.push('*'); width = 0;
} else { } else {
columns.push(hasDescription ? '15%' : '*'); width = 14;
} }
if (width) {
if (! hasDescription) {
width = '*';
} else {
// make the first and last columns of the Bold design a bit wider
if (! hasPadding) {
if (i == 0 || i == fields.length - 1) {
width += 7;
}
}
width += '%';
}
} else {
width = '*';
}
columns.push(width)
} }
return columns; return columns;
@ -437,6 +473,16 @@ NINJA.invoiceFooter = function(invoice)
} }
} }
NINJA.quantityWidth = function(invoice)
{
return invoice.account.hide_quantity == '1' ? '' : '"14%", ';
}
NINJA.taxWidth = function(invoice)
{
return invoice.account.show_item_taxes == '1' ? '"14%", ' : '';
}
NINJA.productFields = function(invoice, isTasks) { NINJA.productFields = function(invoice, isTasks) {
var account = invoice.account; var account = invoice.account;
var fields = JSON.parse(account.invoice_fields); var fields = JSON.parse(account.invoice_fields);
@ -478,6 +524,7 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
} }
var fields = NINJA.productFields(invoice, isTasks); var fields = NINJA.productFields(invoice, isTasks);
consle.log(fields);
var hasDescription = fields.indexOf('product.description') >= 0; var hasDescription = fields.indexOf('product.description') >= 0;
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {
@ -604,6 +651,12 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
value = lineTotal; value = lineTotal;
} }
if (j == 0) {
styles.push('firstColumn');
} else if (j == fields.length - 1) {
styles.push('lastColumn');
}
row.push({text:value || ' ', style:styles}); row.push({text:value || ' ', style:styles});
} }

View File

@ -107,8 +107,9 @@
var needsRefresh = false; var needsRefresh = false;
function refreshPDF(force) { function refreshPDF(force) {
try { //try {
return getPDFString(refreshPDFCB, force); return getPDFString(refreshPDFCB, force);
/*
} catch (exception) { } catch (exception) {
@if (Utils::isTravis()) @if (Utils::isTravis())
var message = exception.message || ''; var message = exception.message || '';
@ -130,6 +131,7 @@
} }
@endif @endif
} }
*/
} }
function refreshPDFCB(string) { function refreshPDFCB(string) {

View File

@ -39,7 +39,7 @@
"style": "invoiceLineItemsTable", "style": "invoiceLineItemsTable",
"table": { "table": {
"headerRows": 1, "headerRows": 1,
"widths": ["22%", "*", "14%", "$quantityWidth", "$taxWidth", "22%"], "widths": "$invoiceLineItemColumns",
"body": "$invoiceLineItems" "body": "$invoiceLineItems"
}, },
"layout": { "layout": {
@ -165,11 +165,7 @@
"margin": [0, 2, 0, 1] "margin": [0, 2, 0, 1]
}, },
"odd": { "odd": {
"fillColor": "#ebebeb", "fillColor": "#ebebeb"
"margin": [0,0,0,0]
},
"productKey": {
"color": "$primaryColor:#36a498"
}, },
"subtotalsBalanceDueLabel": { "subtotalsBalanceDueLabel": {
"fontSize": "$fontSizeLargest", "fontSize": "$fontSizeLargest",
@ -209,9 +205,14 @@
"alignment": "right", "alignment": "right",
"margin": [0, 0, 40, 0] "margin": [0, 0, 40, 0]
}, },
"firstColumn": {
"margin": [40, 0, 0, 0]
},
"lastColumn": {
"margin": [0, 0, 40, 0]
},
"productKey": { "productKey": {
"color": "$primaryColor:#36a498", "color": "$primaryColor:#36a498",
"margin": [40,0,0,0],
"bold": true "bold": true
}, },
"yourInvoice": { "yourInvoice": {
@ -237,8 +238,7 @@
"alignment": "right" "alignment": "right"
}, },
"lineTotal": { "lineTotal": {
"alignment": "right", "alignment": "right"
"margin": [0, 0, 40, 0]
}, },
"subtotals": { "subtotals": {
"alignment": "right", "alignment": "right",