diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index abebe92f5b4f..5c4d71fa2eb0 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -7,6 +7,7 @@ use App\Http\Requests\CreateClientRequest; use App\Http\Requests\UpdateClientRequest; use App\Jobs\LoadPostmarkHistory; use App\Jobs\ReactivatePostmarkEmail; +use App\Jobs\Client\GenerateStatementData; use App\Models\Account; use App\Models\Client; use App\Models\Credit; @@ -239,10 +240,12 @@ class ClientController extends BaseController } } - public function statement($clientPublicId, $statusId = false, $startDate = false, $endDate = false) + public function statement($clientPublicId) { + $statusId = request()->status_id; + $startDate = request()->start_date; + $endDate = request()->end_date; $account = Auth::user()->account; - $statusId = intval($statusId); $client = Client::scope(request()->client_id)->with('contacts')->firstOrFail(); if (! $startDate) { @@ -250,32 +253,8 @@ class ClientController extends BaseController $endDate = Utils::today(false)->format('Y-m-d'); } - $invoice = $account->createInvoice(ENTITY_INVOICE); - $invoice->client = $client; - $invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY'; - - $invoices = Invoice::scope() - ->with(['client']) - ->invoices() - ->whereClientId($client->id) - ->whereIsPublic(true) - ->orderBy('invoice_date', 'asc'); - - if ($statusId == INVOICE_STATUS_PAID) { - $invoices->where('invoice_status_id', '=', INVOICE_STATUS_PAID); - } elseif ($statusId == INVOICE_STATUS_UNPAID) { - $invoices->where('invoice_status_id', '!=', INVOICE_STATUS_PAID); - } - - if ($statusId == INVOICE_STATUS_PAID || ! $statusId) { - $invoices->where('invoice_date', '>=', $startDate) - ->where('invoice_date', '<=', $endDate); - } - - $invoice->invoice_items = $invoices->get(); - if (request()->json) { - return json_encode($invoice); + return dispatch(new \App\Jobs\Client\GenerateStatementData($client, request()->all())); } $data = [ diff --git a/app/Jobs/Client/GenerateStatementData (hillel-NIX's conflicted copy 2018-04-29).php b/app/Jobs/Client/GenerateStatementData (hillel-NIX's conflicted copy 2018-04-29).php new file mode 100644 index 000000000000..7c868722e87f --- /dev/null +++ b/app/Jobs/Client/GenerateStatementData (hillel-NIX's conflicted copy 2018-04-29).php @@ -0,0 +1,61 @@ +client = $client; + $this->options = $options; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $client = $this->client; + $account = $client->account; + + $options = $this->options; + $statusId = intval($options['status_id']); + $startDate = $options['start_date']; + $endDate = $options['end_date']; + + $invoice = $account->createInvoice(ENTITY_INVOICE); + $invoice->client = $client; + $invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY'; + + $invoices = Invoice::scope() + ->with(['client']) + ->invoices() + ->whereClientId($client->id) + ->whereIsPublic(true) + ->orderBy('invoice_date', 'asc'); + + if ($statusId == INVOICE_STATUS_PAID) { + $invoices->where('invoice_status_id', '=', INVOICE_STATUS_PAID); + } elseif ($statusId == INVOICE_STATUS_UNPAID) { + $invoices->where('invoice_status_id', '!=', INVOICE_STATUS_PAID); + } + + if ($statusId == INVOICE_STATUS_PAID || ! $statusId) { + $invoices->where('invoice_date', '>=', $startDate) + ->where('invoice_date', '<=', $endDate); + } + + $invoice->invoice_items = $invoices->get(); + + return json_encode($invoice); + } + + private function getInvoices() + { + + } +} diff --git a/app/Jobs/Client/GenerateStatementData.php b/app/Jobs/Client/GenerateStatementData.php new file mode 100644 index 000000000000..6912883a1432 --- /dev/null +++ b/app/Jobs/Client/GenerateStatementData.php @@ -0,0 +1,56 @@ +client = $client; + $this->options = $options; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $client = $this->client; + $account = $client->account; + + $options = $this->options; + $statusId = intval($options['status_id']); + $startDate = $options['start_date']; + $endDate = $options['end_date']; + + $invoice = $account->createInvoice(ENTITY_INVOICE); + $invoice->client = $client; + $invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY'; + + $invoices = Invoice::scope() + ->with(['client']) + ->invoices() + ->whereClientId($client->id) + ->whereIsPublic(true) + ->orderBy('invoice_date', 'asc'); + + if ($statusId == INVOICE_STATUS_PAID) { + $invoices->where('invoice_status_id', '=', INVOICE_STATUS_PAID); + } elseif ($statusId == INVOICE_STATUS_UNPAID) { + $invoices->where('invoice_status_id', '!=', INVOICE_STATUS_PAID); + } + + if ($statusId == INVOICE_STATUS_PAID || ! $statusId) { + $invoices->where('invoice_date', '>=', $startDate) + ->where('invoice_date', '<=', $endDate); + } + + $invoice->invoice_items = $invoices->get(); + + return json_encode($invoice); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 0d2bd461e8f3..21ad9c0e39e6 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2839,6 +2839,8 @@ $LANG = array( 'guide' => 'Guide', 'gateway_fee_item' => 'Gateway Fee Item', 'gateway_fee_description' => 'Gateway Fee Surcharge', + 'show_payments' => 'Show Payments', + 'show_aging' => 'Show Aging', ); diff --git a/resources/views/clients/statement.blade.php b/resources/views/clients/statement.blade.php index 876a6268da72..f85bd7c21d7d 100644 --- a/resources/views/clients/statement.blade.php +++ b/resources/views/clients/statement.blade.php @@ -98,8 +98,15 @@ $('#reportrange').css('color', '#000'); $('#reportrange').css('pointer-events', 'auto'); } - var url = '{{ url('/clients/statement/' . $client->public_id) }}' + '/' + statusId + '/' + - statementStartDate.format('YYYY-MM-DD') + '/' + statementEndDate.format('YYYY-MM-DD') + '?json=true'; + var url = '{{ url('/clients/statement/' . $client->public_id) }}' + + '?status_id=' + statusId + + '&start_date=' + statementStartDate.format('YYYY-MM-DD') + + '&end_date=' + statementEndDate.format('YYYY-MM-DD') + + '&show_payments=' + $('#show_payments').is(':checked') + + '&show_aging=' + $('#show_aging').is(':checked') + + '&json=true'; + console.log(url); + $.get(url, function(response) { invoice = currentInvoice = JSON.parse(response); refreshPDF(); @@ -110,8 +117,6 @@ if (isStorageSupported()) { localStorage.setItem('last:statement_status_id', $('#status_id').val()); } - - refreshData(); } function onDownloadClick() { @@ -142,7 +147,7 @@