mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Working on statements
This commit is contained in:
parent
422d5c5cdc
commit
3359562410
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Jobs\Client;
|
||||
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Eloquent;
|
||||
|
||||
class GenerateStatementData
|
||||
{
|
||||
@ -59,7 +61,27 @@ class GenerateStatementData
|
||||
->where('invoice_date', '<=', $this->options['end_date']);
|
||||
}
|
||||
|
||||
return $invoices->get();
|
||||
$invoices = $invoices->get();
|
||||
$data = collect();
|
||||
|
||||
for ($i=0; $i<$invoices->count(); $i++) {
|
||||
$invoice = $invoices[$i];
|
||||
$item = new InvoiceItem();
|
||||
$item->product_key = $invoice->invoice_number;
|
||||
$item->custom_value1 = $invoice->invoice_date;
|
||||
$item->custom_value2 = $invoice->due_date;
|
||||
$item->cost = $invoice->amount;
|
||||
$item->qty = $invoice->balance;
|
||||
$item->invoice_item_type_id = 1;
|
||||
$data->push($item);
|
||||
}
|
||||
|
||||
if ($this->options['show_aging']) {
|
||||
$aging = $this->getAging($invoices);
|
||||
$data = $data->merge($aging);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getPayments()
|
||||
@ -71,11 +93,48 @@ class GenerateStatementData
|
||||
->where('payment_date', '>=', $this->options['start_date'])
|
||||
->where('payment_date', '<=', $this->options['end_date']);
|
||||
|
||||
return $payments->get();
|
||||
$payments = $payments->get();
|
||||
$data = collect();
|
||||
|
||||
for ($i=0; $i<$payments->count(); $i++) {
|
||||
$payment = $payments[$i];
|
||||
$item = new InvoiceItem();
|
||||
$item->product_key = $payment->invoice->invoice_number;
|
||||
$item->custom_value1 = $payment->payment_date;
|
||||
$item->custom_value2 = $payment->payment_type->name;
|
||||
$item->cost = $payment->getCompletedAmount();
|
||||
$item->invoice_item_type_id = 3;
|
||||
$data->push($item);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getAging()
|
||||
private function getAging($invoices)
|
||||
{
|
||||
$data = collect();
|
||||
$ageGroups = [
|
||||
'age_group_0' => 0,
|
||||
'age_group_30' => 0,
|
||||
'age_group_60' => 0,
|
||||
'age_group_90' => 0,
|
||||
'age_group_120' => 0,
|
||||
];
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$age = $invoice->present()->ageGroup;
|
||||
$ageGroups[$age] += $invoice->getRequestedAmount();
|
||||
}
|
||||
|
||||
$item = new InvoiceItem();
|
||||
$item->product_key = $ageGroups['age_group_0'];
|
||||
$item->notes = $ageGroups['age_group_30'];
|
||||
$item->custom_value1 = $ageGroups['age_group_60'];
|
||||
$item->custom_value1 = $ageGroups['age_group_90'];
|
||||
$item->cost = $ageGroups['age_group_120'];
|
||||
$item->invoice_item_type_id = 4;
|
||||
$data->push($item);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -445,12 +445,10 @@ NINJA.statementDetails = function(invoice) {
|
||||
var hasAging = false;
|
||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||
var item = invoice.invoice_items[i];
|
||||
if (! item.invoice_number) {
|
||||
if (item.invoice_id) {
|
||||
hasPayments = true;
|
||||
} else {
|
||||
hasAging = true;
|
||||
}
|
||||
if (item.invoice_item_type_id == 3) {
|
||||
hasPayments = true;
|
||||
} else if (item.invoice_item_type_id == 4) {
|
||||
hasAging = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,6 +458,7 @@ NINJA.statementDetails = function(invoice) {
|
||||
data.stack.push(clone);
|
||||
|
||||
if (hasPayments) {
|
||||
console.log('hasPayments...');
|
||||
var clone = JSON.parse(JSON.stringify(table));
|
||||
clone.table.body = NINJA.prepareDataTable(NINJA.statementPayments(invoice), 'invoiceItems');
|
||||
clone.table.widths = ["22%", "22%", "39%", "17%"];
|
||||
@ -469,6 +468,7 @@ NINJA.statementDetails = function(invoice) {
|
||||
if (hasAging) {
|
||||
var clone = JSON.parse(JSON.stringify(table));
|
||||
clone.table.body = NINJA.prepareDataTable(NINJA.statementAging(invoice), 'invoiceItems');
|
||||
clone.table.widths = ["20%", "20%", "20%", "20%", "20%"];
|
||||
data.stack.push(clone);
|
||||
}
|
||||
|
||||
@ -485,16 +485,16 @@ NINJA.statementInvoices = function(invoice) {
|
||||
|
||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||
var item = invoice.invoice_items[i];
|
||||
if (! item.invoice_number) {
|
||||
if (item.invoice_item_type_id != 1) {
|
||||
continue;
|
||||
}
|
||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
||||
grid.push([
|
||||
{text: item.invoice_number, style:['invoiceNumber', 'productKey', rowStyle]},
|
||||
{text: item.invoice_date && item.invoice_date != '0000-00-00' ? moment(item.invoice_date).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
||||
{text: item.due_date && item.due_date != '0000-00-00' ? moment(item.due_date).format(invoice.date_format) : ' ', style:['dueDate', rowStyle]},
|
||||
{text: formatMoneyInvoice(item.amount, invoice), style:['subtotals', rowStyle]},
|
||||
{text: formatMoneyInvoice(item.balance, invoice), style:['lineTotal', 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_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.qty, invoice), style:['lineTotal', rowStyle]},
|
||||
]);
|
||||
}
|
||||
|
||||
@ -503,6 +503,7 @@ NINJA.statementInvoices = function(invoice) {
|
||||
|
||||
NINJA.statementPayments = function(invoice) {
|
||||
var grid = [[]];
|
||||
|
||||
grid[0].push({text: invoiceLabels.invoice_number, style: ['tableHeader', 'itemTableHeader']});
|
||||
grid[0].push({text: invoiceLabels.payment_date, style: ['tableHeader', 'invoiceDateTableHeader']});
|
||||
grid[0].push({text: invoiceLabels.method, style: ['tableHeader', 'dueDateTableHeader']});
|
||||
@ -511,23 +512,46 @@ NINJA.statementPayments = function(invoice) {
|
||||
|
||||
for (var i = 0; i < invoice.invoice_items.length; i++) {
|
||||
var item = invoice.invoice_items[i];
|
||||
if (! item.invoice_id) {
|
||||
if (item.invoice_item_type_id != 3) {
|
||||
continue;
|
||||
}
|
||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
||||
grid.push([
|
||||
{text: item.invoice.invoice_number, style:['invoiceNumber', 'productKey', rowStyle]},
|
||||
{text: item.payment_date && item.payment_date != '0000-00-00' ? moment(item.payment_date).format(invoice.date_format) : ' ', style:['invoiceDate', rowStyle]},
|
||||
{text: item.payment_type ? item.payment_type.name : ' ', style:['dueDate', 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_value2 ? item.custom_value2 : ' ', style:['dueDate', rowStyle]},
|
||||
//{text: item.transaction_reference, style:['subtotals', rowStyle]},
|
||||
{text: formatMoneyInvoice(item.amount - item.refunded, invoice), style:['lineTotal', rowStyle]},
|
||||
{text: formatMoneyInvoice(item.cost, invoice), style:['lineTotal', rowStyle]},
|
||||
]);
|
||||
}
|
||||
|
||||
console.log(grid);
|
||||
return grid;
|
||||
}
|
||||
|
||||
NINJA.statementAging = function(invoice) {
|
||||
var grid = [[],[]];
|
||||
|
||||
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++) {
|
||||
var item = invoice.invoice_items[i];
|
||||
if (item.invoice_item_type_id != 4) {
|
||||
continue;
|
||||
}
|
||||
console.log(item);
|
||||
var rowStyle = (i % 2 == 0) ? 'odd' : 'even';
|
||||
grid[1].push(
|
||||
{text: formatMoneyInvoice(item.cost, invoice), style:['lineTotal', rowStyle]},
|
||||
);
|
||||
}
|
||||
console.log(grid);
|
||||
*/
|
||||
return grid;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user