use invoice colors

This commit is contained in:
sigitas 2015-04-14 13:23:35 +03:00
parent d2e22167da
commit c36e47a07c
4 changed files with 190 additions and 36 deletions

View File

@ -58,8 +58,8 @@ module.exports = function(grunt) {
'public/vendor/jspdf/dist/jspdf.min.js', 'public/vendor/jspdf/dist/jspdf.min.js',
//'public/vendor/handsontable/dist/jquery.handsontable.full.min.js', //'public/vendor/handsontable/dist/jquery.handsontable.full.min.js',
'public/vendor/pdfmake/build/pdfmake.min.js', 'public/vendor/pdfmake/build/pdfmake.min.js',
//'public/vendor/pdfmake/build/vfs_fonts.js', 'public/vendor/pdfmake/build/vfs_fonts.js',
'public/js/vfs_fonts.js', //'public/js/vfs_fonts.js',
'public/js/lightbox.min.js', 'public/js/lightbox.min.js',
'public/js/bootstrap-combobox.js', 'public/js/bootstrap-combobox.js',
'public/js/script.js', 'public/js/script.js',

File diff suppressed because one or more lines are too long

View File

@ -83,3 +83,68 @@ function invoiceLines(invoice) {
return grid; return grid;
} }
function subtotals(invoice)
{
if (!invoice) {
return;
}
var data = [
[invoiceLabels.subtotal, formatMoney(invoice.subtotal_amount, invoice.client.currency_id)],
];
if(invoice.discount_amount != 0) {
data.push([invoiceLabels.discount, formatMoney(invoice.discount_amount, invoice.client.currency_id)]);
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
data.push([invoiceLabels.custom_invoice_label1, formatMoney(invoice.custom_value1, invoice.client.currency_id)]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
data.push([invoiceLabels.custom_invoice_label2, formatMoney(invoice.custom_value2, invoice.client.currency_id)]);
}
if(invoice.tax && invoice.tax.name || invoice.tax_name) {
data.push([invoiceLabels.tax, formatMoney(invoice.tax_amount, invoice.client.currency_id)]);
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
data.push([invoiceLabels.custom_invoice_label1, formatMoney(invoice.custom_value1, invoice.client.currency_id)]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
data.push([invoiceLabels.custom_invoice_label2, formatMoney(invoice.custom_value2, invoice.client.currency_id)]);
}
var paid = invoice.amount - invoice.balance;
if (invoice.account.hide_paid_to_date != '1' || paid) {
data.push([invoiceLabels.paid_to_date, formatMoney(paid, invoice.client.currency_id)]);
}
return data;
}
function accountDetails(account) {
var data = [];
if(account.name) data.push({text:account.name, style:'accountDetails'});
if(account.id_number) data.push({text:account.id_number, style:'accountDetails'});
if(account.vat_number) data.push({text:account.vat_number, style:'accountDetails'});
if(account.work_email) data.push({text:account.work_email, style:'accountDetails'});
if(account.work_phone) data.push({text:account.work_phone, style:'accountDetails'});
return data;
}
function accountAddress(account) {
var data = [];
if(account.address1) data.push({text:account.address1, style:'accountDetails'});
if(account.address2) data.push({text:account.address2, style:'accountDetails'});
if(account.city) data.push({text:account.city, style:'accountDetails'});
if(account.state) data.push({text:account.state, style:'accountDetails'});
if(account.postal_code) data.push({text:account.postal_code, style:'accountDetails'});
return data;
}
function primaryColor( defaultColor) {
return NINJA.primaryColor?NINJA.primaryColor:defaultColor;
}
function secondaryColor( defaultColor) {
return NINJA.primaryColor?NINJA.secondaryColor:defaultColor;
}

View File

@ -7,7 +7,7 @@ var templateFonts = {
bolditalics: 'FreeSansBoldOblique.ttf' bolditalics: 'FreeSansBoldOblique.ttf'
} }
}; };
window.pdfMake.fonts = templateFonts; //window.pdfMake.fonts = templateFonts;
var dd = { var dd = {
content: [ content: [
{ {
@ -20,17 +20,18 @@ var dd = {
}:"" }:""
], ],
{ {
text: [account.name, account.id_number, account.vat_number, account.work_email, account.work_phone].join('\n') stack: accountDetails(account)
}, },
{ {
text: [ stack: accountAddress(account)
concatStrings(account.address1, account.address2) + "\n",
concatStrings(account.city, account.state, account.postal_code)
]
} }
] ]
}, },
(invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(), {
text:(invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice).toUpperCase(),
margin: [8, 16, 8, 16],
style: 'primaryColor'
},
{ {
style: 'tableExample', style: 'tableExample',
table: { table: {
@ -55,32 +56,18 @@ var dd = {
/*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';
},*/ },*/
// paddingLeft: function(i, node) { return 4; }, paddingLeft: function(i, node) { return 8; },
// paddingRight: function(i, node) { return 4; }, paddingRight: function(i, node) { return 8; },
// paddingTop: function(i, node) { return 2; }, paddingTop: function(i, node) { return 4; },
// paddingBottom: function(i, node) { return 2; } paddingBottom: function(i, node) { return 4; }
} }
}, },
'\n', '\n',
{ {
style: 'tableExample',
table: { table: {
headerRows: 1, headerRows: 1,
widths: ['auto', '*', 'auto', 'auto', 'auto', 'auto'], widths: ['auto', '*', 'auto', 'auto', 'auto', 'auto'],
body:invoiceLines(invoice), 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: { layout: {
hLineWidth: function (i, node) { hLineWidth: function (i, node) {
@ -91,16 +78,36 @@ var dd = {
}, },
hLineColor: function (i, node) { hLineColor: function (i, node) {
return '#D8D8D8'; return '#D8D8D8';
} },
paddingLeft: function(i, node) { return 8; },
paddingRight: function(i, node) { return 8; },
paddingTop: function(i, node) { return 8; },
paddingBottom: function(i, node) { return 8; }
}, },
}, },
{ {
columns: [ columns: [
notesAndTerms(invoice), notesAndTerms(invoice),
{ {
text: "" style: 'subtotals',
} table: {
] widths: ['*', '*'],
body: subtotals(invoice),
},
layout: {
hLineWidth: function (i, node) {
return 0;
},
vLineWidth: function (i, node) {
return 0;
},
paddingLeft: function(i, node) { return 8; },
paddingRight: function(i, node) { return 8; },
paddingTop: function(i, node) { return 4; },
paddingBottom: function(i, node) { return 4; }
},
}
]
}, },
], ],
@ -117,9 +124,18 @@ var dd = {
}, },
defaultStyle: { defaultStyle: {
font: 'sans' //font: 'sans'
fontSize: 9,
margin: [8, 4, 8, 4]
}, },
styles: { styles: {
primaryColor:{
color: primaryColor('#299CC2')
},
accountDetails: {
margin: [4, 2, 4, 2],
color: '#AAA9A9'
},
bold: { bold: {
bold: true bold: true
}, },
@ -128,6 +144,9 @@ var dd = {
odd: { odd: {
fillColor:'#F4F4F4' fillColor:'#F4F4F4'
}, },
productKey: {
color:primaryColor('#299CC2')
},
cost: { cost: {
alignment: 'right' alignment: 'right'
}, },
@ -139,6 +158,15 @@ var dd = {
}, },
lineTotal: { lineTotal: {
alignment: 'right' alignment: 'right'
},
right: {
alignment: 'right'
},
subtotals: {
alignment: 'right'
},
tableHeader: {
bold: true
} }
}, },
pageMargins: [72, 40, 40, 80] pageMargins: [72, 40, 40, 80]