diff --git a/public/js/built.js b/public/js/built.js index 67469c630e4f..a51a61e78ecc 100644 --- a/public/js/built.js +++ b/public/js/built.js @@ -33347,6 +33347,106 @@ function GetPdfMake(invoice, javascript, callback) { 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'); diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js index 96bd50e21220..6a2e2da02e68 100644 --- a/public/js/pdf.pdfmake.js +++ b/public/js/pdf.pdfmake.js @@ -6,6 +6,106 @@ function GetPdfMake(invoice, javascript, callback) { 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'); diff --git a/public/js/templates/clean.js b/public/js/templates/clean.js index 190e6de55a94..a3a75b14fa23 100644 --- a/public/js/templates/clean.js +++ b/public/js/templates/clean.js @@ -46,7 +46,7 @@ var dd = { return 0;//(i === 0 || i === node.table.widths.length) ? 2 : 1; }, 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) { return (i === 0 || i === node.table.widths.length) ? 'black' : 'gray'; @@ -62,17 +62,33 @@ var dd = { style: 'tableExample', table: { headerRows: 1, - widths: ['auto', '*', 'auto', 'auto', 'auto'], - body: [ - [{text: 'Item', style: 'tableHeader'}, {text: 'Description', style: 'tableHeader'}, {text: 'Unit Cost', style: 'tableHeader'}, {text: 'Quantity', style: 'tableHeader'}, {text: 'Line Total', style: 'tableHeader'}], - ['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'], - ['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'], - ['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'], - ['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'], - ['Sample value 1', 'Sample value 2', 'Sample value 3', 'Sample value 2', 'Sample value 3'] - ] + widths: ['auto', '*', 'auto', 'auto', 'auto', 'auto'], + body:invoiceLines(invoice), + /*body: [ + [{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'}] + /*['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: { @@ -81,6 +97,15 @@ var dd = { styles: { bold: { bold: true + }, + even: { + }, + odd: { + fillColor:'#F4F4F4' + }, + cost: { + alignment: 'right' } + } }; \ No newline at end of file