Working on statements

This commit is contained in:
Hillel Coren 2018-05-01 15:47:19 +03:00
parent e51baa4058
commit 898a64288c
3 changed files with 17 additions and 7 deletions

View File

@ -35,7 +35,8 @@ class GenerateStatementData
$invoice->invoice_items = $this->getInvoices(); $invoice->invoice_items = $this->getInvoices();
if ($this->options['show_payments']) { if ($this->options['show_payments']) {
$invoice->invoice_items = $invoice->invoice_items->merge($this->getPayments()); $payments = $this->getPayments($invoice->invoice_items);
$invoice->invoice_items = $invoice->invoice_items->merge($payments);
} }
return json_encode($invoice); return json_encode($invoice);
@ -75,6 +76,7 @@ class GenerateStatementData
for ($i=0; $i<$invoices->count(); $i++) { for ($i=0; $i<$invoices->count(); $i++) {
$invoice = $invoices[$i]; $invoice = $invoices[$i];
$item = new InvoiceItem(); $item = new InvoiceItem();
$item->id = $invoice->id;
$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;
@ -93,7 +95,7 @@ class GenerateStatementData
return $data; return $data;
} }
private function getPayments() private function getPayments($invoices)
{ {
$payments = Payment::with('invoice', 'payment_type') $payments = Payment::with('invoice', 'payment_type')
->withArchived() ->withArchived()
@ -101,6 +103,10 @@ class GenerateStatementData
->where('payment_date', '>=', $this->options['start_date']) ->where('payment_date', '>=', $this->options['start_date'])
->where('payment_date', '<=', $this->options['end_date']); ->where('payment_date', '<=', $this->options['end_date']);
if ($this->contact) {
$payments->whereIn('invoice_id', $invoices->pluck('id'));
}
$payments = $payments->get(); $payments = $payments->get();
$data = collect(); $data = collect();
@ -109,7 +115,7 @@ class GenerateStatementData
$item = new InvoiceItem(); $item = new InvoiceItem();
$item->product_key = $payment->invoice->invoice_number; $item->product_key = $payment->invoice->invoice_number;
$item->custom_value1 = $payment->payment_date; $item->custom_value1 = $payment->payment_date;
$item->custom_value2 = $payment->payment_type->name; $item->custom_value2 = $payment->present()->payment_type;
$item->cost = $payment->getCompletedAmount(); $item->cost = $payment->getCompletedAmount();
$item->invoice_item_type_id = 3; $item->invoice_item_type_id = 3;
$data->push($item); $data->push($item);

View File

@ -37,6 +37,11 @@ class PaymentPresenter extends EntityPresenter
return Carbon::parse($this->entity->payment_date)->format('Y m'); return Carbon::parse($this->entity->payment_date)->format('Y m');
} }
public function payment_type()
{
return $this->entity->payment_type ? $this->entity->payment_type->name : trans('texts.manual_entry');
}
public function method() public function method()
{ {
if ($this->entity->account_gateway) { if ($this->entity->account_gateway) {

View File

@ -87,15 +87,14 @@
$('#reportrange').css('color', '#000'); $('#reportrange').css('color', '#000');
$('#reportrange').css('pointer-events', 'auto'); $('#reportrange').css('pointer-events', 'auto');
} }
console.log("{{ request()->path() }}");
var url = '/{{ request()->path() . '/' . $client->public_id }}' + var url = '/{{ request()->path() }}' +
'?status_id=' + statusId + '?status_id=' + statusId +
'&start_date=' + statementStartDate.format('YYYY-MM-DD') + '&start_date=' + statementStartDate.format('YYYY-MM-DD') +
'&end_date=' + statementEndDate.format('YYYY-MM-DD') + '&end_date=' + statementEndDate.format('YYYY-MM-DD') +
'&show_payments=' + ($('#show_payments').is(':checked') ? '1' : '') + '&show_payments=' + ($('#show_payments').is(':checked') ? '1' : '') +
'&show_aging=' + ($('#show_aging').is(':checked') ? '1' : '') + '&show_aging=' + ($('#show_aging').is(':checked') ? '1' : '') +
'&json=true'; '&json=true';
console.log(url);
$.get(url, function(response) { $.get(url, function(response) {
invoice = currentInvoice = JSON.parse(response); invoice = currentInvoice = JSON.parse(response);