1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01: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),
'invoiceDetailsHeight': (NINJA.invoiceDetails(invoice).length * 16) + 16,
'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),
'taskLineItemColumns': NINJA.invoiceColumns(invoice, true),
'taskLineItemColumns': NINJA.invoiceColumns(invoice, javascript, true),
'invoiceDocuments' : NINJA.invoiceDocuments(invoice),
'quantityWidth': NINJA.quantityWidth(invoice),
'taxWidth': NINJA.taxWidth(invoice),
'clientDetails': NINJA.clientDetails(invoice),
'notesAndTerms': NINJA.notesAndTerms(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) {
// remove trailing commas for these fields
if (['quantityWidth', 'taxWidth'].indexOf(key) >= 0) {
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);
}
@ -391,32 +399,60 @@ NINJA.statementLines = function(invoice)
return NINJA.prepareDataTable(grid, 'invoiceItems');
}
NINJA.invoiceColumns = function(invoice, isTasks)
NINJA.invoiceColumns = function(invoice, design, isTasks)
{
var account = invoice.account;
var columns = [];
var fields = NINJA.productFields(invoice, isTasks);
var hasDescription = fields.indexOf('product.description') >= 0;
var hasPadding = design.indexOf('"pageMargins":[0') == -1;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
var width = 0;
if (field == 'product.custom_value1') {
if (invoice.has_custom_item_value1) {
columns.push(hasDescription ? '10%' : '*');
width = 10;
} else {
continue;
}
} else if (field == 'product.custom_value2') {
if (invoice.has_custom_item_value2) {
columns.push(hasDescription ? '10%' : '*');
width = 10;
} else {
continue;
}
} else if (field == 'product.tax') {
if (invoice.has_item_taxes) {
columns.push(hasDescription ? '15%' : '*');
width = 15;
} else {
continue;
}
} else if (field == 'product.description') {
columns.push('*');
width = 0;
} 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;
@ -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) {
var account = invoice.account;
var fields = JSON.parse(account.invoice_fields);
@ -478,6 +524,7 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
}
var fields = NINJA.productFields(invoice, isTasks);
consle.log(fields);
var hasDescription = fields.indexOf('product.description') >= 0;
for (var i=0; i<fields.length; i++) {
@ -604,6 +651,12 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
value = lineTotal;
}
if (j == 0) {
styles.push('firstColumn');
} else if (j == fields.length - 1) {
styles.push('lastColumn');
}
row.push({text:value || ' ', style:styles});
}

View File

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

View File

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