mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
display invoice lines
This commit is contained in:
parent
5f1495073f
commit
3b427eeae6
@ -33347,6 +33347,106 @@ function GetPdfMake(invoice, javascript, callback) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invoiceLines(invoice) {
|
||||||
|
var grid =
|
||||||
|
[[{text: 'Item', style: 'tableHeader'},
|
||||||
|
{text: 'Description', style: 'tableHeader'},
|
||||||
|
{text: 'Unit Cost', style: 'tableHeader'},
|
||||||
|
{text: 'Quantity', style: 'tableHeader'},
|
||||||
|
{text: invoice.has_taxes?'Tax':'', style: 'tableHeader'},
|
||||||
|
{text: 'Line Total', style: 'tableHeader'}]];
|
||||||
|
//grid.push(['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3']);
|
||||||
|
//grid.push(['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3']);
|
||||||
|
|
||||||
|
var line = 1;
|
||||||
|
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++) {
|
||||||
|
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;
|
||||||
|
var tax = "";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// show at most one blank line
|
||||||
|
if (shownItem && (!cost || cost == '0.00') && !notes && !productKey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
shownItem = true;
|
||||||
|
|
||||||
|
// process date variables
|
||||||
|
if (invoice.is_recurring) {
|
||||||
|
notes = processVariables(notes);
|
||||||
|
productKey = processVariables(productKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
rowStyle = i%2===0?'odd':'even';
|
||||||
|
|
||||||
|
row[0] = {style:["productKey", rowStyle], text:productKey};
|
||||||
|
row[1] = {style:["notes", rowStyle], text:notes};
|
||||||
|
row[2] = {style:["cost", rowStyle], text:cost};
|
||||||
|
row[3] = {style:["quantity", rowStyle], text:qty};
|
||||||
|
row[4] = {style:["tax", rowStyle], text:""+tax};
|
||||||
|
row[5] = {style:["lineTotal", rowStyle], text:lineTotal};
|
||||||
|
|
||||||
|
grid.push(row);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
y = tableTop + (line * layout.tableRowHeight) + (3 * layout.tablePadding);
|
||||||
|
|
||||||
|
if (invoice.invoice_design_id == 8) {
|
||||||
|
doc.setDrawColor(30, 30, 30);
|
||||||
|
doc.setLineWidth(0.5);
|
||||||
|
|
||||||
|
var topX = tableTop - 14;
|
||||||
|
doc.line(layout.marginLeft - 10, topX, layout.marginLeft - 10, y);
|
||||||
|
doc.line(layout.descriptionLeft - 8, topX, layout.descriptionLeft - 8, y);
|
||||||
|
doc.line(layout.unitCostRight - 55, topX, layout.unitCostRight - 55, y);
|
||||||
|
doc.line(layout.qtyRight - 50, topX, layout.qtyRight - 50, y);
|
||||||
|
if (invoice.has_taxes) {
|
||||||
|
doc.line(layout.taxRight - 28, topX, layout.taxRight - 28, y);
|
||||||
|
}
|
||||||
|
doc.line(totalX - 25, topX, totalX - 25, y + 90);
|
||||||
|
doc.line(totalX + 45, topX, totalX + 45, y + 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cutoff = 700;
|
||||||
|
if (invoice.terms) {
|
||||||
|
cutoff -= 50;
|
||||||
|
}
|
||||||
|
if (invoice.public_notes) {
|
||||||
|
cutoff -= 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y > cutoff) {
|
||||||
|
doc.addPage();
|
||||||
|
return layout.marginLeft;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var doc = new jsPDF('portrait', 'pt', 'a4');
|
var doc = new jsPDF('portrait', 'pt', 'a4');
|
||||||
|
|
||||||
|
@ -6,6 +6,106 @@ function GetPdfMake(invoice, javascript, callback) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invoiceLines(invoice) {
|
||||||
|
var grid =
|
||||||
|
[[{text: 'Item', style: 'tableHeader'},
|
||||||
|
{text: 'Description', style: 'tableHeader'},
|
||||||
|
{text: 'Unit Cost', style: 'tableHeader'},
|
||||||
|
{text: 'Quantity', style: 'tableHeader'},
|
||||||
|
{text: invoice.has_taxes?'Tax':'', style: 'tableHeader'},
|
||||||
|
{text: 'Line Total', style: 'tableHeader'}]];
|
||||||
|
//grid.push(['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3']);
|
||||||
|
//grid.push(['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3']);
|
||||||
|
|
||||||
|
var line = 1;
|
||||||
|
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++) {
|
||||||
|
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;
|
||||||
|
var tax = "";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// show at most one blank line
|
||||||
|
if (shownItem && (!cost || cost == '0.00') && !notes && !productKey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
shownItem = true;
|
||||||
|
|
||||||
|
// process date variables
|
||||||
|
if (invoice.is_recurring) {
|
||||||
|
notes = processVariables(notes);
|
||||||
|
productKey = processVariables(productKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
rowStyle = i%2===0?'odd':'even';
|
||||||
|
|
||||||
|
row[0] = {style:["productKey", rowStyle], text:productKey};
|
||||||
|
row[1] = {style:["notes", rowStyle], text:notes};
|
||||||
|
row[2] = {style:["cost", rowStyle], text:cost};
|
||||||
|
row[3] = {style:["quantity", rowStyle], text:qty};
|
||||||
|
row[4] = {style:["tax", rowStyle], text:""+tax};
|
||||||
|
row[5] = {style:["lineTotal", rowStyle], text:lineTotal};
|
||||||
|
|
||||||
|
grid.push(row);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
y = tableTop + (line * layout.tableRowHeight) + (3 * layout.tablePadding);
|
||||||
|
|
||||||
|
if (invoice.invoice_design_id == 8) {
|
||||||
|
doc.setDrawColor(30, 30, 30);
|
||||||
|
doc.setLineWidth(0.5);
|
||||||
|
|
||||||
|
var topX = tableTop - 14;
|
||||||
|
doc.line(layout.marginLeft - 10, topX, layout.marginLeft - 10, y);
|
||||||
|
doc.line(layout.descriptionLeft - 8, topX, layout.descriptionLeft - 8, y);
|
||||||
|
doc.line(layout.unitCostRight - 55, topX, layout.unitCostRight - 55, y);
|
||||||
|
doc.line(layout.qtyRight - 50, topX, layout.qtyRight - 50, y);
|
||||||
|
if (invoice.has_taxes) {
|
||||||
|
doc.line(layout.taxRight - 28, topX, layout.taxRight - 28, y);
|
||||||
|
}
|
||||||
|
doc.line(totalX - 25, topX, totalX - 25, y + 90);
|
||||||
|
doc.line(totalX + 45, topX, totalX + 45, y + 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cutoff = 700;
|
||||||
|
if (invoice.terms) {
|
||||||
|
cutoff -= 50;
|
||||||
|
}
|
||||||
|
if (invoice.public_notes) {
|
||||||
|
cutoff -= 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y > cutoff) {
|
||||||
|
doc.addPage();
|
||||||
|
return layout.marginLeft;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var doc = new jsPDF('portrait', 'pt', 'a4');
|
var doc = new jsPDF('portrait', 'pt', 'a4');
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ var dd = {
|
|||||||
return 0;//(i === 0 || i === node.table.widths.length) ? 2 : 1;
|
return 0;//(i === 0 || i === node.table.widths.length) ? 2 : 1;
|
||||||
},
|
},
|
||||||
hLineColor: function (i, node) {
|
hLineColor: function (i, node) {
|
||||||
return 'gray';//(i === 0 || i === node.table.body.length) ? 'black' : 'gray';
|
return '#D8D8D8';//(i === 0 || i === node.table.body.length) ? 'black' : 'gray';
|
||||||
},
|
},
|
||||||
/*vLineColor: function (i, node) {
|
/*vLineColor: function (i, node) {
|
||||||
return (i === 0 || i === node.table.widths.length) ? 'black' : 'gray';
|
return (i === 0 || i === node.table.widths.length) ? 'black' : 'gray';
|
||||||
@ -62,17 +62,33 @@ var dd = {
|
|||||||
style: 'tableExample',
|
style: 'tableExample',
|
||||||
table: {
|
table: {
|
||||||
headerRows: 1,
|
headerRows: 1,
|
||||||
widths: ['auto', '*', 'auto', 'auto', 'auto'],
|
widths: ['auto', '*', 'auto', 'auto', 'auto', 'auto'],
|
||||||
body: [
|
body:invoiceLines(invoice),
|
||||||
[{text: 'Item', style: 'tableHeader'}, {text: 'Description', style: 'tableHeader'}, {text: 'Unit Cost', style: 'tableHeader'}, {text: 'Quantity', style: 'tableHeader'}, {text: 'Line Total', style: 'tableHeader'}],
|
/*body: [
|
||||||
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'],
|
[{text: 'Item', style: 'tableHeader'},
|
||||||
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'],
|
{text: 'Description', style: 'tableHeader'},
|
||||||
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'],
|
{text: 'Unit Cost', style: 'tableHeader'},
|
||||||
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'],
|
{text: 'Quantity', style: 'tableHeader'},
|
||||||
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3']
|
{text: invoice.has_taxes?'Tax':'', style: 'tableHeader'},
|
||||||
]
|
{text: 'Line Total', style: 'tableHeader'}]
|
||||||
|
/*['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3'],
|
||||||
|
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3'],
|
||||||
|
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3'],
|
||||||
|
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3'],
|
||||||
|
['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', invoice.has_taxes?'Sample value 2':'','Sample value 3']*
|
||||||
|
].push(invoiceLines(invoice))*/
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
hLineWidth: function (i, node) {
|
||||||
|
return i === 0 ? 0 : 1;
|
||||||
|
},
|
||||||
|
vLineWidth: function (i, node) {
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
hLineColor: function (i, node) {
|
||||||
|
return '#D8D8D8';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
layout: 'lightHorizontalLines'
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
defaultStyle: {
|
defaultStyle: {
|
||||||
@ -81,6 +97,15 @@ var dd = {
|
|||||||
styles: {
|
styles: {
|
||||||
bold: {
|
bold: {
|
||||||
bold: true
|
bold: true
|
||||||
|
},
|
||||||
|
even: {
|
||||||
|
},
|
||||||
|
odd: {
|
||||||
|
fillColor:'#F4F4F4'
|
||||||
|
},
|
||||||
|
cost: {
|
||||||
|
alignment: 'right'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user