mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add filter options to the client statement
This commit is contained in:
parent
fda0eeaf5e
commit
aa4049a018
@ -224,25 +224,51 @@ class ClientController extends BaseController
|
|||||||
return $this->returnBulk(ENTITY_CLIENT, $action, $ids);
|
return $this->returnBulk(ENTITY_CLIENT, $action, $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function statement()
|
public function statement($clientPublicId, $statusId = false, $startDate = false, $endDate = false)
|
||||||
{
|
{
|
||||||
$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) {
|
||||||
|
$startDate = Utils::today(false)->modify('-6 month')->format('Y-m-d');
|
||||||
|
$endDate = Utils::today(false)->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
$invoice = $account->createInvoice(ENTITY_INVOICE);
|
$invoice = $account->createInvoice(ENTITY_INVOICE);
|
||||||
$invoice->client = $client;
|
$invoice->client = $client;
|
||||||
$invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY';
|
$invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY';
|
||||||
$invoice->invoice_items = Invoice::scope()
|
|
||||||
|
$invoices = Invoice::scope()
|
||||||
->with(['client'])
|
->with(['client'])
|
||||||
->whereClientId($client->id)
|
|
||||||
->invoices()
|
->invoices()
|
||||||
|
->whereClientId($client->id)
|
||||||
->whereIsPublic(true)
|
->whereIsPublic(true)
|
||||||
->where('balance', '>', 0)
|
->orderBy('invoice_date', 'asc');
|
||||||
->get();
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'showBreadcrumbs' => false,
|
'showBreadcrumbs' => false,
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
'invoice' => $invoice,
|
'account' => $account,
|
||||||
|
'startDate' => $startDate,
|
||||||
|
'endDate' => $endDate,
|
||||||
];
|
];
|
||||||
|
|
||||||
return view('clients.statement', $data);
|
return view('clients.statement', $data);
|
||||||
|
@ -144,7 +144,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}', 'ClientController@statement');
|
Route::get('clients/statement/{client_id}/{status_id?}/{start_date?}/{end_date?}', 'ClientController@statement');
|
||||||
|
|
||||||
Route::resource('tasks', 'TaskController');
|
Route::resource('tasks', 'TaskController');
|
||||||
Route::get('api/tasks/{client_id?}', 'TaskController@getDatatable');
|
Route::get('api/tasks/{client_id?}', 'TaskController@getDatatable');
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
@section('head')
|
@section('head')
|
||||||
@parent
|
@parent
|
||||||
|
|
||||||
|
<script src="{{ asset('js/daterangepicker.min.js') }}" type="text/javascript"></script>
|
||||||
|
<link href="{{ asset('css/daterangepicker.css') }}" rel="stylesheet" type="text/css"/>
|
||||||
|
|
||||||
@include('money_script')
|
@include('money_script')
|
||||||
@foreach (Auth::user()->account->getFontFolders() as $font)
|
@foreach (Auth::user()->account->getFontFolders() as $font)
|
||||||
<script src="{{ asset('js/vfs_fonts/'.$font.'.js') }}" type="text/javascript"></script>
|
<script src="{{ asset('js/vfs_fonts/'.$font.'.js') }}" type="text/javascript"></script>
|
||||||
@ -13,8 +16,10 @@
|
|||||||
|
|
||||||
var invoiceDesigns = {!! \App\Models\InvoiceDesign::getDesigns() !!};
|
var invoiceDesigns = {!! \App\Models\InvoiceDesign::getDesigns() !!};
|
||||||
var invoiceFonts = {!! Cache::get('fonts') !!};
|
var invoiceFonts = {!! Cache::get('fonts') !!};
|
||||||
var currentInvoice = {!! $invoice !!};
|
|
||||||
var invoice = {!! $invoice !!};
|
var statementStartDate = moment("{{ $startDate }}");
|
||||||
|
var statementEndDate = moment("{{ $endDate }}");
|
||||||
|
var dateRanges = {!! $account->present()->dateRangeOptions !!};
|
||||||
|
|
||||||
function getPDFString(cb) {
|
function getPDFString(cb) {
|
||||||
|
|
||||||
@ -40,9 +45,73 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
refreshPDF();
|
if (isStorageSupported()) {
|
||||||
|
var lastRange = localStorage.getItem('last:statement_range');
|
||||||
|
var lastStatusId = localStorage.getItem('last:statement_status_id');
|
||||||
|
lastRange = dateRanges[lastRange];
|
||||||
|
if (lastRange) {
|
||||||
|
statementStartDate = lastRange[0];
|
||||||
|
statementEndDate = lastRange[1];
|
||||||
|
}
|
||||||
|
if (lastStatusId) {
|
||||||
|
$('#status_id').val(lastStatusId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize date range selector
|
||||||
|
function cb(start, end, label) {
|
||||||
|
statementStartDate = start;
|
||||||
|
statementEndDate = end;
|
||||||
|
$('#reportrange span').html(start.format('{{ $account->getMomentDateFormat() }}') + ' - ' + end.format('{{ $account->getMomentDateFormat() }}'));
|
||||||
|
$('#start_date').val(start.format('YYYY-MM-DD'));
|
||||||
|
$('#end_date').val(end.format('YYYY-MM-DD'));
|
||||||
|
|
||||||
|
if (isStorageSupported() && label && label != "{{ trans('texts.custom_range') }}") {
|
||||||
|
localStorage.setItem('last:statement_range', label);
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshData();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#reportrange').daterangepicker({
|
||||||
|
locale: {
|
||||||
|
format: "{{ $account->getMomentDateFormat() }}",
|
||||||
|
customRangeLabel: "{{ trans('texts.custom_range') }}",
|
||||||
|
},
|
||||||
|
startDate: statementStartDate,
|
||||||
|
endDate: statementEndDate,
|
||||||
|
linkedCalendars: false,
|
||||||
|
ranges: dateRanges,
|
||||||
|
}, cb);
|
||||||
|
|
||||||
|
cb(statementStartDate, statementEndDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function refreshData() {
|
||||||
|
var statusId = $('#status_id').val();
|
||||||
|
if (statusId == {{ INVOICE_STATUS_UNPAID }}) {
|
||||||
|
$('#reportrange').css('color', '#AAA');
|
||||||
|
$('#reportrange').css('pointer-events', 'none');
|
||||||
|
} else {
|
||||||
|
$('#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';
|
||||||
|
$.get(url, function(response) {
|
||||||
|
invoice = currentInvoice = JSON.parse(response);
|
||||||
|
refreshPDF();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStatusChange() {
|
||||||
|
if (isStorageSupported()) {
|
||||||
|
localStorage.setItem('last:statement_status_id', $('#status_id').val());
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshData();
|
||||||
|
}
|
||||||
|
|
||||||
function onDownloadClick() {
|
function onDownloadClick() {
|
||||||
var doc = generatePDF(invoice, invoiceDesigns[0].javascript, true);
|
var doc = generatePDF(invoice, invoiceDesigns[0].javascript, true);
|
||||||
doc.save("{{ str_replace(' ', '_', trim($client->getDisplayName())) . '-' . trans('texts.statement') }}" + '.pdf');
|
doc.save("{{ str_replace(' ', '_', trim($client->getDisplayName())) . '-' . trans('texts.statement') }}" + '.pdf');
|
||||||
@ -70,6 +139,39 @@
|
|||||||
<p> </p>
|
<p> </p>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
|
||||||
|
<div class="well" style="background: #eeeeee">
|
||||||
|
{!! Former::inline_open() !!}
|
||||||
|
|
||||||
|
{{ trans('texts.status') }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{!! Former::select('status_id')
|
||||||
|
->onchange('onStatusChange()')
|
||||||
|
->label('status')
|
||||||
|
->addOption(trans('texts.unpaid'), INVOICE_STATUS_UNPAID)
|
||||||
|
->addOption(trans('texts.paid'), INVOICE_STATUS_PAID)
|
||||||
|
->addOption(trans('texts.all'), 'false') !!}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{ trans('texts.date_range') }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span id="reportrange" style="background: #f9f9f9; cursor: pointer; padding: 9px 14px; border: 1px solid #dfe0e1; margin-top: 0px;">
|
||||||
|
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
|
||||||
|
<span></span> <b class="caret"></b>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div style="display:none">
|
||||||
|
{!! Former::text('start_date') !!}
|
||||||
|
{!! Former::text('end_date') !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!! Former::close() !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
@include('invoices.pdf', ['account' => Auth::user()->account, 'pdfHeight' => 800])
|
@include('invoices.pdf', ['account' => Auth::user()->account, 'pdfHeight' => 800])
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user