Bug fixes

This commit is contained in:
Hillel Coren 2014-10-26 21:54:37 +02:00
parent 8cae66c2ff
commit d6eff8f913
2 changed files with 298 additions and 248 deletions

View File

@ -46570,15 +46570,13 @@ function displayAccount(doc, invoice, x, y, layout) {
return;
}
var data = [
var data1 = [
account.name,
account.work_email,
account.work_phone
];
displayGrid(doc, invoice, data, x, y, layout, {hasHeader:true});
data = [
var data2 = [
concatStrings(account.address1, account.address2),
concatStrings(account.city, account.state, account.postal_code),
account.country ? account.country.name : false,
@ -46586,13 +46584,21 @@ function displayAccount(doc, invoice, x, y, layout) {
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
];
if (layout.singleColumn) {
displayGrid(doc, invoice, data1.concat(data2), x, y, layout, {hasHeader:true});
} else {
displayGrid(doc, invoice, data1, x, y, layout, {hasHeader:true});
var nameWidth = account.name ? (doc.getStringUnitWidth(account.name) * doc.internal.getFontSize() * 1.1) : 0;
var emailWidth = account.work_email ? (doc.getStringUnitWidth(account.work_email) * doc.internal.getFontSize() * 1.1) : 0;
width = Math.max(emailWidth, nameWidth, 120);
x += width;
displayGrid(doc, invoice, data, x, y, layout);
displayGrid(doc, invoice, data2, x, y, layout);
}
}
@ -46606,7 +46612,7 @@ function displayClient(doc, invoice, x, y, layout) {
concatStrings(client.address1, client.address2),
concatStrings(client.city, client.state, client.postal_code),
client.country ? client.country.name : false,
client.contacts ? client.contacts[0].email : false,
client.contacts && getClientDisplayName(client) != client.contacts[0].email ? client.contacts[0].email : false,
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
];
@ -46895,11 +46901,6 @@ function getInvoiceTaxRate(invoice) {
function displayInvoiceHeader(doc, invoice, layout) {
var costX = layout.unitCostRight - (doc.getStringUnitWidth(invoiceLabels.unit_cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(invoiceLabels.quantity) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(invoiceLabels.tax) * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(invoiceLabels.line_total) * doc.internal.getFontSize());
if (invoice.invoice_design_id == 6 || invoice.invoice_design_id == 8 || invoice.invoice_design_id == 10) {
invoiceLabels.item = invoiceLabels.item.toUpperCase();
invoiceLabels.description = invoiceLabels.description.toUpperCase();
@ -46909,6 +46910,11 @@ function displayInvoiceHeader(doc, invoice, layout) {
invoiceLabels.tax = invoiceLabels.tax.toUpperCase();
}
var costX = layout.unitCostRight - (doc.getStringUnitWidth(invoiceLabels.unit_cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(invoiceLabels.quantity) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(invoiceLabels.tax) * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(invoiceLabels.line_total) * doc.internal.getFontSize());
doc.text(layout.marginLeft, layout.tableTop, invoiceLabels.item);
doc.text(layout.descriptionLeft, layout.tableTop, invoiceLabels.description);
doc.text(costX, layout.tableTop, invoiceLabels.unit_cost);
@ -46937,6 +46943,23 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.setFontSize(8);
for (var i=0; i<invoice.invoice_items.length; i++) {
var item = invoice.invoice_items[i];
var cost = formatMoney(item.cost, currencyId, true);
var qty = NINJA.parseFloat(item.qty) ? NINJA.parseFloat(item.qty) + '' : '';
var notes = item.notes;
var productKey = item.product_key;
var tax = 0;
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;
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
//console.log('num lines %s', numLines);
@ -46956,23 +46979,6 @@ function displayInvoiceItems(doc, invoice, layout) {
var left = layout.marginLeft - layout.tablePadding;
var width = layout.marginRight + layout.tablePadding;
var cost = formatMoney(item.cost, currencyId, true);
var qty = NINJA.parseFloat(item.qty) ? NINJA.parseFloat(item.qty) + '' : '';
var notes = item.notes;
var productKey = item.product_key;
var tax = 0;
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);
@ -46988,6 +46994,7 @@ function displayInvoiceItems(doc, invoice, layout) {
}
lineTotal = formatMoney(lineTotal, currencyId);
var costX = layout.unitCostRight - (doc.getStringUnitWidth(cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(qty) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(tax+'%') * doc.internal.getFontSize());
@ -47110,6 +47117,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(totalX-27, y-16,totalX-27, y+55);
}
/*
if (invoice.invoice_design_id == 8) {
doc.setDrawColor(30, 30, 30);
@ -47119,7 +47127,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(layout.descriptionLeft-8, y-60,layout.descriptionLeft-8, y+20);
doc.line(costX-30, y-60,costX-30, y+20);
console.log('CostX: %s', costX);
doc.line(qtyX-45, y-60,qtyX-45, y+20);
if (invoice.has_taxes) {
@ -47131,6 +47139,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(totalX+35, y-60,totalX+35, y+120);
}
*/
SetPdfColor('Black', doc);
doc.setFontType('normal');
@ -47148,7 +47157,6 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.setTextColor(205,81,56);
}
doc.text(totalX, y+2, lineTotal);
doc.setFontType('normal');
SetPdfColor('Black', doc);
if (tax) {
@ -47157,6 +47165,23 @@ function displayInvoiceItems(doc, invoice, layout) {
}
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;

View File

@ -635,15 +635,13 @@ function displayAccount(doc, invoice, x, y, layout) {
return;
}
var data = [
var data1 = [
account.name,
account.work_email,
account.work_phone
];
displayGrid(doc, invoice, data, x, y, layout, {hasHeader:true});
data = [
var data2 = [
concatStrings(account.address1, account.address2),
concatStrings(account.city, account.state, account.postal_code),
account.country ? account.country.name : false,
@ -651,13 +649,21 @@ function displayAccount(doc, invoice, x, y, layout) {
invoice.account.custom_value2 ? invoice.account['custom_label2'] + ' ' + invoice.account.custom_value2 : false,
];
if (layout.singleColumn) {
displayGrid(doc, invoice, data1.concat(data2), x, y, layout, {hasHeader:true});
} else {
displayGrid(doc, invoice, data1, x, y, layout, {hasHeader:true});
var nameWidth = account.name ? (doc.getStringUnitWidth(account.name) * doc.internal.getFontSize() * 1.1) : 0;
var emailWidth = account.work_email ? (doc.getStringUnitWidth(account.work_email) * doc.internal.getFontSize() * 1.1) : 0;
width = Math.max(emailWidth, nameWidth, 120);
x += width;
displayGrid(doc, invoice, data, x, y, layout);
displayGrid(doc, invoice, data2, x, y, layout);
}
}
@ -671,7 +677,7 @@ function displayClient(doc, invoice, x, y, layout) {
concatStrings(client.address1, client.address2),
concatStrings(client.city, client.state, client.postal_code),
client.country ? client.country.name : false,
client.contacts ? client.contacts[0].email : false,
client.contacts && getClientDisplayName(client) != client.contacts[0].email ? client.contacts[0].email : false,
invoice.client.custom_value1 ? invoice.account['custom_client_label1'] + ' ' + invoice.client.custom_value1 : false,
invoice.client.custom_value2 ? invoice.account['custom_client_label2'] + ' ' + invoice.client.custom_value2 : false,
];
@ -960,11 +966,6 @@ function getInvoiceTaxRate(invoice) {
function displayInvoiceHeader(doc, invoice, layout) {
var costX = layout.unitCostRight - (doc.getStringUnitWidth(invoiceLabels.unit_cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(invoiceLabels.quantity) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(invoiceLabels.tax) * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(invoiceLabels.line_total) * doc.internal.getFontSize());
if (invoice.invoice_design_id == 6 || invoice.invoice_design_id == 8 || invoice.invoice_design_id == 10) {
invoiceLabels.item = invoiceLabels.item.toUpperCase();
invoiceLabels.description = invoiceLabels.description.toUpperCase();
@ -974,6 +975,11 @@ function displayInvoiceHeader(doc, invoice, layout) {
invoiceLabels.tax = invoiceLabels.tax.toUpperCase();
}
var costX = layout.unitCostRight - (doc.getStringUnitWidth(invoiceLabels.unit_cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(invoiceLabels.quantity) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(invoiceLabels.tax) * doc.internal.getFontSize());
var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(invoiceLabels.line_total) * doc.internal.getFontSize());
doc.text(layout.marginLeft, layout.tableTop, invoiceLabels.item);
doc.text(layout.descriptionLeft, layout.tableTop, invoiceLabels.description);
doc.text(costX, layout.tableTop, invoiceLabels.unit_cost);
@ -1002,6 +1008,23 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.setFontSize(8);
for (var i=0; i<invoice.invoice_items.length; i++) {
var item = invoice.invoice_items[i];
var cost = formatMoney(item.cost, currencyId, true);
var qty = NINJA.parseFloat(item.qty) ? NINJA.parseFloat(item.qty) + '' : '';
var notes = item.notes;
var productKey = item.product_key;
var tax = 0;
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;
var numLines = doc.splitTextToSize(item.notes, 200).length + 2;
//console.log('num lines %s', numLines);
@ -1021,23 +1044,6 @@ function displayInvoiceItems(doc, invoice, layout) {
var left = layout.marginLeft - layout.tablePadding;
var width = layout.marginRight + layout.tablePadding;
var cost = formatMoney(item.cost, currencyId, true);
var qty = NINJA.parseFloat(item.qty) ? NINJA.parseFloat(item.qty) + '' : '';
var notes = item.notes;
var productKey = item.product_key;
var tax = 0;
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);
@ -1053,6 +1059,7 @@ function displayInvoiceItems(doc, invoice, layout) {
}
lineTotal = formatMoney(lineTotal, currencyId);
var costX = layout.unitCostRight - (doc.getStringUnitWidth(cost) * doc.internal.getFontSize());
var qtyX = layout.qtyRight - (doc.getStringUnitWidth(qty) * doc.internal.getFontSize());
var taxX = layout.taxRight - (doc.getStringUnitWidth(tax+'%') * doc.internal.getFontSize());
@ -1175,6 +1182,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(totalX-27, y-16,totalX-27, y+55);
}
/*
if (invoice.invoice_design_id == 8) {
doc.setDrawColor(30, 30, 30);
@ -1184,7 +1192,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(layout.descriptionLeft-8, y-60,layout.descriptionLeft-8, y+20);
doc.line(costX-30, y-60,costX-30, y+20);
console.log('CostX: %s', costX);
doc.line(qtyX-45, y-60,qtyX-45, y+20);
if (invoice.has_taxes) {
@ -1196,6 +1204,7 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.line(totalX+35, y-60,totalX+35, y+120);
}
*/
SetPdfColor('Black', doc);
doc.setFontType('normal');
@ -1213,7 +1222,6 @@ function displayInvoiceItems(doc, invoice, layout) {
doc.setTextColor(205,81,56);
}
doc.text(totalX, y+2, lineTotal);
doc.setFontType('normal');
SetPdfColor('Black', doc);
if (tax) {
@ -1222,6 +1230,23 @@ function displayInvoiceItems(doc, invoice, layout) {
}
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;