mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Working on client statements
This commit is contained in:
parent
f64a2583b8
commit
489fc02dfc
@ -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 = [
|
||||
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
56
app/Jobs/Client/GenerateStatementData.php
Normal file
56
app/Jobs/Client/GenerateStatementData.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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',
|
||||
|
||||
);
|
||||
|
||||
|
@ -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 @@
|
||||
<p> </p>
|
||||
|
||||
<div class="well" style="background: #eeeeee">
|
||||
{!! Former::inline_open() !!}
|
||||
{!! Former::inline_open()->onchange('refreshData()') !!}
|
||||
|
||||
{{ trans('texts.status') }}
|
||||
|
||||
@ -171,6 +176,16 @@
|
||||
{!! Former::text('end_date') !!}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{!! Former::checkbox('show_payments')
|
||||
->text('show_payments') !!}
|
||||
|
||||
|
||||
|
||||
{!! Former::checkbox('show_aging')
|
||||
->text('show_aging')!!}
|
||||
|
||||
{!! Former::close() !!}
|
||||
</div>
|
||||
|
||||
|
@ -150,7 +150,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
|
||||
Route::get('api/clients', 'ClientController@getDatatable');
|
||||
Route::get('api/activities/{client_id?}', 'ActivityController@getDatatable');
|
||||
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('reactivate_email/{bounce_id}', 'ClientController@reactivateEmail');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user