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:
parent
450e4ae66a
commit
7ecd06921f
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canvas": [
|
"canvas": [
|
||||||
{
|
{
|
||||||
"type": "rect",
|
"type": "rect",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"w": 225,
|
"w": 225,
|
||||||
"h": "$invoiceDetailsHeight",
|
"h": "$invoiceDetailsHeight",
|
||||||
"r":0,
|
"r":0,
|
||||||
"lineWidth": 1,
|
"lineWidth": 1,
|
||||||
"color": "$primaryColor:#36a498"
|
"color": "$primaryColor:#36a498"
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@
|
|||||||
"width":10,
|
"width":10,
|
||||||
"margin":[-10,100,0,10]
|
"margin":[-10,100,0,10]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table": {
|
"table": {
|
||||||
"body": "$invoiceDetails"
|
"body": "$invoiceDetails"
|
||||||
},
|
},
|
||||||
"layout": "noBorders",
|
"layout": "noBorders",
|
||||||
@ -39,15 +39,15 @@
|
|||||||
"style": "invoiceLineItemsTable",
|
"style": "invoiceLineItemsTable",
|
||||||
"table": {
|
"table": {
|
||||||
"headerRows": 1,
|
"headerRows": 1,
|
||||||
"widths": ["22%", "*", "14%", "$quantityWidth", "$taxWidth", "22%"],
|
"widths": "$invoiceLineItemColumns",
|
||||||
"body": "$invoiceLineItems"
|
"body": "$invoiceLineItems"
|
||||||
},
|
},
|
||||||
"layout": {
|
"layout": {
|
||||||
"hLineWidth": "$none",
|
"hLineWidth": "$none",
|
||||||
"vLineWidth": "$none",
|
"vLineWidth": "$none",
|
||||||
"paddingLeft": "$amount:8",
|
"paddingLeft": "$amount:8",
|
||||||
"paddingRight": "$amount:8",
|
"paddingRight": "$amount:8",
|
||||||
"paddingTop": "$amount:14",
|
"paddingTop": "$amount:14",
|
||||||
"paddingBottom": "$amount:14"
|
"paddingBottom": "$amount:14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -66,10 +66,10 @@
|
|||||||
"layout": {
|
"layout": {
|
||||||
"hLineWidth": "$none",
|
"hLineWidth": "$none",
|
||||||
"vLineWidth": "$none",
|
"vLineWidth": "$none",
|
||||||
"paddingLeft": "$amount:8",
|
"paddingLeft": "$amount:8",
|
||||||
"paddingRight": "$amount:8",
|
"paddingRight": "$amount:8",
|
||||||
"paddingTop": "$amount:4",
|
"paddingTop": "$amount:4",
|
||||||
"paddingBottom": "$amount:4"
|
"paddingBottom": "$amount:4"
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
@ -112,7 +112,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
"image": "$accountLogo",
|
"image": "$accountLogo",
|
||||||
"fit": [120, 60],
|
"fit": [120, 60],
|
||||||
"margin": [30, 16, 0, 0]
|
"margin": [30, 16, 0, 0]
|
||||||
@ -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,15 +205,20 @@
|
|||||||
"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": {
|
||||||
"font": "$headerFont",
|
"font": "$headerFont",
|
||||||
"bold": true,
|
"bold": true,
|
||||||
"fontSize": 14,
|
"fontSize": 14,
|
||||||
"color": "$primaryColor:#36a498",
|
"color": "$primaryColor:#36a498",
|
||||||
"margin": [0,0,0,8]
|
"margin": [0,0,0,8]
|
||||||
},
|
},
|
||||||
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user