1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on client statements

This commit is contained in:
Hillel Coren 2018-04-29 09:00:37 +03:00
parent f64a2583b8
commit 489fc02dfc
6 changed files with 146 additions and 33 deletions

View File

@ -7,6 +7,7 @@ use App\Http\Requests\CreateClientRequest;
use App\Http\Requests\UpdateClientRequest; use App\Http\Requests\UpdateClientRequest;
use App\Jobs\LoadPostmarkHistory; use App\Jobs\LoadPostmarkHistory;
use App\Jobs\ReactivatePostmarkEmail; use App\Jobs\ReactivatePostmarkEmail;
use App\Jobs\Client\GenerateStatementData;
use App\Models\Account; use App\Models\Account;
use App\Models\Client; use App\Models\Client;
use App\Models\Credit; 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; $account = Auth::user()->account;
$statusId = intval($statusId);
$client = Client::scope(request()->client_id)->with('contacts')->firstOrFail(); $client = Client::scope(request()->client_id)->with('contacts')->firstOrFail();
if (! $startDate) { if (! $startDate) {
@ -250,32 +253,8 @@ class ClientController extends BaseController
$endDate = Utils::today(false)->format('Y-m-d'); $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) { if (request()->json) {
return json_encode($invoice); return dispatch(new \App\Jobs\Client\GenerateStatementData($client, request()->all()));
} }
$data = [ $data = [

View File

@ -0,0 +1,61 @@
<?php
namespace App\Jobs\Client;
use App\Models\Invoice;
class GenerateStatementData
{
public function __construct($client, $options)
{
$this->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()
{
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Jobs\Client;
use App\Models\Invoice;
class GenerateStatementData
{
public function __construct($client, $options)
{
$this->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);
}
}

View File

@ -2839,6 +2839,8 @@ $LANG = array(
'guide' => 'Guide', 'guide' => 'Guide',
'gateway_fee_item' => 'Gateway Fee Item', 'gateway_fee_item' => 'Gateway Fee Item',
'gateway_fee_description' => 'Gateway Fee Surcharge', 'gateway_fee_description' => 'Gateway Fee Surcharge',
'show_payments' => 'Show Payments',
'show_aging' => 'Show Aging',
); );

View File

@ -98,8 +98,15 @@
$('#reportrange').css('color', '#000'); $('#reportrange').css('color', '#000');
$('#reportrange').css('pointer-events', 'auto'); $('#reportrange').css('pointer-events', 'auto');
} }
var url = '{{ url('/clients/statement/' . $client->public_id) }}' + '/' + statusId + '/' + var url = '{{ url('/clients/statement/' . $client->public_id) }}' +
statementStartDate.format('YYYY-MM-DD') + '/' + statementEndDate.format('YYYY-MM-DD') + '?json=true'; '?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) { $.get(url, function(response) {
invoice = currentInvoice = JSON.parse(response); invoice = currentInvoice = JSON.parse(response);
refreshPDF(); refreshPDF();
@ -110,8 +117,6 @@
if (isStorageSupported()) { if (isStorageSupported()) {
localStorage.setItem('last:statement_status_id', $('#status_id').val()); localStorage.setItem('last:statement_status_id', $('#status_id').val());
} }
refreshData();
} }
function onDownloadClick() { function onDownloadClick() {
@ -142,7 +147,7 @@
<p>&nbsp;</p> <p>&nbsp;</p>
<div class="well" style="background: #eeeeee"> <div class="well" style="background: #eeeeee">
{!! Former::inline_open() !!} {!! Former::inline_open()->onchange('refreshData()') !!}
{{ trans('texts.status') }} {{ trans('texts.status') }}
@ -171,6 +176,16 @@
{!! Former::text('end_date') !!} {!! Former::text('end_date') !!}
</div> </div>
&nbsp;&nbsp;&nbsp;&nbsp;
{!! Former::checkbox('show_payments')
->text('show_payments') !!}
&nbsp;&nbsp;&nbsp;&nbsp;
{!! Former::checkbox('show_aging')
->text('show_aging')!!}
{!! Former::close() !!} {!! Former::close() !!}
</div> </div>

View File

@ -150,7 +150,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
Route::get('api/clients', 'ClientController@getDatatable'); Route::get('api/clients', 'ClientController@getDatatable');
Route::get('api/activities/{client_id?}', 'ActivityController@getDatatable'); Route::get('api/activities/{client_id?}', 'ActivityController@getDatatable');
Route::post('clients/bulk', 'ClientController@bulk'); Route::post('clients/bulk', 'ClientController@bulk');
Route::get('clients/statement/{client_id}/{status_id?}/{start_date?}/{end_date?}', 'ClientController@statement'); Route::get('clients/statement/{client_id}', 'ClientController@statement');
Route::post('email_history', 'ClientController@getEmailHistory'); Route::post('email_history', 'ClientController@getEmailHistory');
Route::post('reactivate_email/{bounce_id}', 'ClientController@reactivateEmail'); Route::post('reactivate_email/{bounce_id}', 'ClientController@reactivateEmail');