mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 05:40:56 -04:00
Working on statements
This commit is contained in:
parent
3359562410
commit
b501e971ef
@ -70,8 +70,9 @@ class GenerateStatementData
|
|||||||
$item->product_key = $invoice->invoice_number;
|
$item->product_key = $invoice->invoice_number;
|
||||||
$item->custom_value1 = $invoice->invoice_date;
|
$item->custom_value1 = $invoice->invoice_date;
|
||||||
$item->custom_value2 = $invoice->due_date;
|
$item->custom_value2 = $invoice->due_date;
|
||||||
$item->cost = $invoice->amount;
|
$item->notes = $invoice->amount;
|
||||||
$item->qty = $invoice->balance;
|
$item->cost = $invoice->balance;
|
||||||
|
$item->qty = 1;
|
||||||
$item->invoice_item_type_id = 1;
|
$item->invoice_item_type_id = 1;
|
||||||
$data->push($item);
|
$data->push($item);
|
||||||
}
|
}
|
||||||
|
@ -341,6 +341,7 @@ trait PresentsInvoice
|
|||||||
'payment_date',
|
'payment_date',
|
||||||
'reference',
|
'reference',
|
||||||
'amount',
|
'amount',
|
||||||
|
'amount_paid',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -164,6 +164,7 @@ function GetPdfMake(invoice, javascript, callback) {
|
|||||||
// support setting noWrap as a style
|
// support setting noWrap as a style
|
||||||
dd.styles.noWrap = {'noWrap': true};
|
dd.styles.noWrap = {'noWrap': true};
|
||||||
dd.styles.discount = {'alignment': 'right'};
|
dd.styles.discount = {'alignment': 'right'};
|
||||||
|
dd.styles.alignRight = {'alignment': 'right'};
|
||||||
|
|
||||||
// set page size
|
// set page size
|
||||||
dd.pageSize = invoice.account.page_size;
|
dd.pageSize = invoice.account.page_size;
|
||||||
@ -425,6 +426,7 @@ NINJA.statementDetails = function(invoice) {
|
|||||||
|
|
||||||
var table = {
|
var table = {
|
||||||
"style": "invoiceLineItemsTable",
|
"style": "invoiceLineItemsTable",
|
||||||
|
"margin": [0, 20, 0, 16],
|
||||||
"table": {
|
"table": {
|
||||||
"headerRows": 1,
|
"headerRows": 1,
|
||||||
"widths": false,
|
"widths": false,
|
||||||
@ -441,11 +443,41 @@ NINJA.statementDetails = function(invoice) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var subtotals = {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"text": " ",
|
||||||
|
"width": "60%",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"table": {
|
||||||
|
"widths": [
|
||||||
|
"*",
|
||||||
|
"40%"
|
||||||
|
],
|
||||||
|
"body": false,
|
||||||
|
},
|
||||||
|
"margin": [0, 0, 0, 16],
|
||||||
|
"layout": {
|
||||||
|
"hLineWidth": "$none",
|
||||||
|
"vLineWidth": "$none",
|
||||||
|
"paddingLeft": "$amount:34",
|
||||||
|
"paddingRight": "$amount:8",
|
||||||
|
"paddingTop": "$amount:4",
|
||||||
|
"paddingBottom": "$amount:4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var hasPayments = false;
|
var hasPayments = false;
|
||||||
var hasAging = false;
|
var hasAging = false;
|
||||||
|
var paymentTotal = 0;
|
||||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||||
var item = invoice.invoice_items[i];
|
var item = invoice.invoice_items[i];
|
||||||
if (item.invoice_item_type_id == 3) {
|
if (item.invoice_item_type_id == 3) {
|
||||||
|
paymentTotal += item.cost;
|
||||||
hasPayments = true;
|
hasPayments = true;
|
||||||
} else if (item.invoice_item_type_id == 4) {
|
} else if (item.invoice_item_type_id == 4) {
|
||||||
hasAging = true;
|
hasAging = true;
|
||||||
@ -457,12 +489,26 @@ NINJA.statementDetails = function(invoice) {
|
|||||||
clone.table.widths = ["22%", "22%", "22%", "17%", "17%"];
|
clone.table.widths = ["22%", "22%", "22%", "17%", "17%"];
|
||||||
data.stack.push(clone);
|
data.stack.push(clone);
|
||||||
|
|
||||||
|
var clone = JSON.parse(JSON.stringify(subtotals));
|
||||||
|
clone.columns[1].table.body = [[
|
||||||
|
{ text: invoiceLabels.balance_due, style: ['subtotalsLabel', 'subtotalsBalanceDueLabel'] },
|
||||||
|
{ text: formatMoneyInvoice(invoice.balance_amount, invoice), style: ['subtotals', 'subtotalsBalanceDue'] }
|
||||||
|
]];
|
||||||
|
data.stack.push(clone);
|
||||||
|
|
||||||
if (hasPayments) {
|
if (hasPayments) {
|
||||||
console.log('hasPayments...');
|
console.log('hasPayments...');
|
||||||
var clone = JSON.parse(JSON.stringify(table));
|
var clone = JSON.parse(JSON.stringify(table));
|
||||||
clone.table.body = NINJA.prepareDataTable(NINJA.statementPayments(invoice), 'invoiceItems');
|
clone.table.body = NINJA.prepareDataTable(NINJA.statementPayments(invoice), 'invoiceItems');
|
||||||
clone.table.widths = ["22%", "22%", "39%", "17%"];
|
clone.table.widths = ["22%", "22%", "39%", "17%"];
|
||||||
data.stack.push(clone);
|
data.stack.push(clone);
|
||||||
|
|
||||||
|
var clone = JSON.parse(JSON.stringify(subtotals));
|
||||||
|
clone.columns[1].table.body = [[
|
||||||
|
{ text: invoiceLabels.amount_paid, style: ['subtotalsLabel', 'subtotalsBalanceDueLabel'] },
|
||||||
|
{ text: formatMoneyInvoice(paymentTotal, invoice), style: ['subtotals', 'subtotalsBalanceDue'] }
|
||||||
|
]];
|
||||||
|
data.stack.push(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAging) {
|
if (hasAging) {
|
||||||
@ -483,18 +529,19 @@ NINJA.statementInvoices = function(invoice) {
|
|||||||
grid[0].push({text: invoiceLabels.total, style: ['tableHeader', 'totalTableHeader']});
|
grid[0].push({text: invoiceLabels.total, style: ['tableHeader', 'totalTableHeader']});
|
||||||
grid[0].push({text: invoiceLabels.balance, style: ['tableHeader', 'balanceTableHeader']});
|
grid[0].push({text: invoiceLabels.balance, style: ['tableHeader', 'balanceTableHeader']});
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||||
var item = invoice.invoice_items[i];
|
var item = invoice.invoice_items[i];
|
||||||
if (item.invoice_item_type_id != 1) {
|
if (item.invoice_item_type_id != 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
var rowStyle = (counter++ % 2 == 0) ? 'odd' : 'even';
|
||||||
grid.push([
|
grid.push([
|
||||||
{text: item.product_key, style:['invoiceNumber', 'productKey', rowStyle]},
|
{text: item.product_key, style:['invoiceNumber', 'productKey', rowStyle]},
|
||||||
{text: item.custom_value1 && item.custom_value1 != '0000-00-00' ? moment(item.custom_value1).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
{text: item.custom_value1 && item.custom_value1 != '0000-00-00' ? moment(item.custom_value1).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
||||||
{text: item.custom_value2 && item.custom_value2 != '0000-00-00' ? moment(item.custom_value2).format(invoice.date_format) : ' ', style:['dueDate', rowStyle]},
|
{text: item.custom_value2 && item.custom_value2 != '0000-00-00' ? moment(item.custom_value2).format(invoice.date_format) : ' ', style:['dueDate', rowStyle]},
|
||||||
{text: formatMoneyInvoice(item.cost, invoice), style:['subtotals', rowStyle]},
|
{text: formatMoneyInvoice(item.notes, invoice), style:['subtotals', rowStyle]},
|
||||||
{text: formatMoneyInvoice(item.qty, invoice), style:['lineTotal', rowStyle]},
|
{text: formatMoneyInvoice(item.cost, invoice), style:['lineTotal', rowStyle]},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,12 +557,13 @@ NINJA.statementPayments = function(invoice) {
|
|||||||
//grid[0].push({text: invoiceLabels.reference, style: ['tableHeader', 'totalTableHeader']});
|
//grid[0].push({text: invoiceLabels.reference, style: ['tableHeader', 'totalTableHeader']});
|
||||||
grid[0].push({text: invoiceLabels.amount, style: ['tableHeader', 'balanceTableHeader']});
|
grid[0].push({text: invoiceLabels.amount, style: ['tableHeader', 'balanceTableHeader']});
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||||
var item = invoice.invoice_items[i];
|
var item = invoice.invoice_items[i];
|
||||||
if (item.invoice_item_type_id != 3) {
|
if (item.invoice_item_type_id != 3) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
var rowStyle = (counter++ % 2 == 0) ? 'odd' : 'even';
|
||||||
grid.push([
|
grid.push([
|
||||||
{text: item.product_key, style:['invoiceNumber', 'productKey', rowStyle]},
|
{text: item.product_key, style:['invoiceNumber', 'productKey', rowStyle]},
|
||||||
{text: item.custom_value1 && item.custom_value1 != '0000-00-00' ? moment(item.custom_value1).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
{text: item.custom_value1 && item.custom_value1 != '0000-00-00' ? moment(item.custom_value1).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
||||||
@ -528,31 +576,30 @@ NINJA.statementPayments = function(invoice) {
|
|||||||
console.log(grid);
|
console.log(grid);
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
NINJA.statementAging = function(invoice) {
|
NINJA.statementAging = function(invoice) {
|
||||||
var grid = [[],[]];
|
var grid = [[]];
|
||||||
|
|
||||||
|
grid[0].push({text: '0 - 30', style: ['tableHeader', 'alignRight']});
|
||||||
|
grid[0].push({text: '30 - 60', style: ['tableHeader', 'alignRight']});
|
||||||
|
grid[0].push({text: '60 - 90', style: ['tableHeader', 'alignRight']});
|
||||||
|
grid[0].push({text: '90 - 120', style: ['tableHeader', 'alignRight']});
|
||||||
|
grid[0].push({text: '120+', style: ['tableHeader', 'alignRight']});
|
||||||
|
|
||||||
grid[0].push({text: '0 - 30', style: ['tableHeader', 'itemTableHeader']});
|
|
||||||
grid[0].push({text: '30 - 60', style: ['tableHeader', 'invoiceDateTableHeader']});
|
|
||||||
grid[0].push({text: '60 - 90', style: ['tableHeader', 'dueDateTableHeader']});
|
|
||||||
grid[0].push({text: '90 - 120', style: ['tableHeader', 'totalTableHeader']});
|
|
||||||
grid[0].push({text: '120+', style: ['tableHeader', 'balanceTableHeader']});
|
|
||||||
/*
|
|
||||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||||
var item = invoice.invoice_items[i];
|
var item = invoice.invoice_items[i];
|
||||||
if (item.invoice_item_type_id != 4) {
|
if (item.invoice_item_type_id != 4) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
console.log(item);
|
grid.push([
|
||||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
{text: formatMoneyInvoice(item.product_key, invoice), style:['subtotals', 'odd']},
|
||||||
grid[1].push(
|
{text: formatMoneyInvoice(item.notes, invoice), style:['subtotals', 'odd']},
|
||||||
{text: formatMoneyInvoice(item.cost, invoice), style:['lineTotal', rowStyle]},
|
{text: formatMoneyInvoice(item.custom_value1, invoice), style:['subtotals', 'odd']},
|
||||||
);
|
{text: formatMoneyInvoice(item.custom_value1, invoice), style:['subtotals', 'odd']},
|
||||||
|
{text: formatMoneyInvoice(item.cost, invoice), style:['subtotals', 'odd']},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
console.log(grid);
|
|
||||||
*/
|
|
||||||
return grid;
|
|
||||||
|
|
||||||
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
NINJA.signature = function(invoice) {
|
NINJA.signature = function(invoice) {
|
||||||
|
@ -586,19 +586,16 @@ function calculateAmounts(invoice) {
|
|||||||
// sum line item
|
// sum line item
|
||||||
for (var i=0; i<invoice.invoice_items.length; i++) {
|
for (var i=0; i<invoice.invoice_items.length; i++) {
|
||||||
var item = invoice.invoice_items[i];
|
var item = invoice.invoice_items[i];
|
||||||
if (invoice.is_statement) {
|
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty));
|
||||||
var lineTotal = roundToTwo(NINJA.parseFloat(item.balance));
|
var discount = roundToTwo(NINJA.parseFloat(item.discount));
|
||||||
} else {
|
if (discount != 0) {
|
||||||
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty));
|
if (parseInt(invoice.is_amount_discount)) {
|
||||||
var discount = roundToTwo(NINJA.parseFloat(item.discount));
|
lineTotal -= discount;
|
||||||
if (discount != 0) {
|
} else {
|
||||||
if (parseInt(invoice.is_amount_discount)) {
|
lineTotal -= roundToTwo(lineTotal * discount / 100);
|
||||||
lineTotal -= discount;
|
|
||||||
} else {
|
|
||||||
lineTotal -= roundToTwo(lineTotal * discount / 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lineTotal = roundToTwo(lineTotal);
|
lineTotal = roundToTwo(lineTotal);
|
||||||
if (lineTotal) {
|
if (lineTotal) {
|
||||||
total += lineTotal;
|
total += lineTotal;
|
||||||
|
@ -2842,6 +2842,7 @@ $LANG = array(
|
|||||||
'show_payments' => 'Show Payments',
|
'show_payments' => 'Show Payments',
|
||||||
'show_aging' => 'Show Aging',
|
'show_aging' => 'Show Aging',
|
||||||
'reference' => 'Reference',
|
'reference' => 'Reference',
|
||||||
|
'amount_paid' => 'Amount Paid',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user