From 898a64288c11456072daa4c3ce1b2a6b41988b5a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 1 May 2018 15:47:19 +0300 Subject: [PATCH] Working on statements --- app/Jobs/Client/GenerateStatementData.php | 14 ++++++++++---- app/Ninja/Presenters/PaymentPresenter.php | 5 +++++ resources/views/clients/statement.blade.php | 5 ++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Jobs/Client/GenerateStatementData.php b/app/Jobs/Client/GenerateStatementData.php index 79ceb7bedc42..ee724dd9a402 100644 --- a/app/Jobs/Client/GenerateStatementData.php +++ b/app/Jobs/Client/GenerateStatementData.php @@ -26,7 +26,7 @@ class GenerateStatementData $client = $this->client; $client->load('contacts'); $account = $client->account; - + $invoice = new Invoice(); $invoice->account = $account; $invoice->client = $client; @@ -35,7 +35,8 @@ class GenerateStatementData $invoice->invoice_items = $this->getInvoices(); 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); @@ -75,6 +76,7 @@ class GenerateStatementData for ($i=0; $i<$invoices->count(); $i++) { $invoice = $invoices[$i]; $item = new InvoiceItem(); + $item->id = $invoice->id; $item->product_key = $invoice->invoice_number; $item->custom_value1 = $invoice->invoice_date; $item->custom_value2 = $invoice->due_date; @@ -93,7 +95,7 @@ class GenerateStatementData return $data; } - private function getPayments() + private function getPayments($invoices) { $payments = Payment::with('invoice', 'payment_type') ->withArchived() @@ -101,6 +103,10 @@ class GenerateStatementData ->where('payment_date', '>=', $this->options['start_date']) ->where('payment_date', '<=', $this->options['end_date']); + if ($this->contact) { + $payments->whereIn('invoice_id', $invoices->pluck('id')); + } + $payments = $payments->get(); $data = collect(); @@ -109,7 +115,7 @@ class GenerateStatementData $item = new InvoiceItem(); $item->product_key = $payment->invoice->invoice_number; $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->invoice_item_type_id = 3; $data->push($item); diff --git a/app/Ninja/Presenters/PaymentPresenter.php b/app/Ninja/Presenters/PaymentPresenter.php index ade396567ea6..9c2a37c9d0be 100644 --- a/app/Ninja/Presenters/PaymentPresenter.php +++ b/app/Ninja/Presenters/PaymentPresenter.php @@ -37,6 +37,11 @@ class PaymentPresenter extends EntityPresenter 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() { if ($this->entity->account_gateway) { diff --git a/resources/views/clients/statement.blade.php b/resources/views/clients/statement.blade.php index e96f6bde2004..b9a57fa63b13 100644 --- a/resources/views/clients/statement.blade.php +++ b/resources/views/clients/statement.blade.php @@ -87,15 +87,14 @@ $('#reportrange').css('color', '#000'); $('#reportrange').css('pointer-events', 'auto'); } - console.log("{{ request()->path() }}"); - var url = '/{{ request()->path() . '/' . $client->public_id }}' + + + var url = '/{{ request()->path() }}' + '?status_id=' + statusId + '&start_date=' + statementStartDate.format('YYYY-MM-DD') + '&end_date=' + statementEndDate.format('YYYY-MM-DD') + '&show_payments=' + ($('#show_payments').is(':checked') ? '1' : '') + '&show_aging=' + ($('#show_aging').is(':checked') ? '1' : '') + '&json=true'; - console.log(url); $.get(url, function(response) { invoice = currentInvoice = JSON.parse(response);