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

Working on statements

This commit is contained in:
Hillel Coren 2018-04-30 23:00:22 +03:00
parent 446c30f37c
commit e51baa4058
5 changed files with 28 additions and 31 deletions

View File

@ -17,6 +17,7 @@ use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\PaymentRepository;
use App\Ninja\Repositories\TaskRepository;
use App\Services\PaymentService;
use App\Jobs\Client\GenerateStatementData;
use Auth;
use Barracuda\ArchiveStream\ZipArchive;
use Cache;
@ -1025,7 +1026,6 @@ class ClientPortalController extends BaseController
$statusId = request()->status_id;
$startDate = request()->start_date;
$endDate = request()->end_date;
$account = auth()->user()->account;
if (! $startDate) {
$startDate = Utils::today(false)->modify('-6 month')->format('Y-m-d');
@ -1033,7 +1033,7 @@ class ClientPortalController extends BaseController
}
if (request()->json) {
return dispatch(new GenerateStatementData($client, request()->all()));
return dispatch(new GenerateStatementData($client, request()->all(), $contact));
}
$data = [

View File

@ -9,10 +9,11 @@ use App\Models\Eloquent;
class GenerateStatementData
{
public function __construct($client, $options)
public function __construct($client, $options, $contact = false)
{
$this->client = $client;
$this->options = $options;
$this->contact = $contact;
}
/**
@ -23,9 +24,11 @@ class GenerateStatementData
public function handle()
{
$client = $this->client;
$client->load('contacts');
$account = $client->account;
$invoice = $account->createInvoice(ENTITY_INVOICE);
$invoice = new Invoice();
$invoice->account = $account;
$invoice->client = $client;
$invoice->date_format = $account->date_format ? $account->date_format->format_moment : 'MMM D, YYYY';
@ -42,8 +45,7 @@ class GenerateStatementData
{
$statusId = intval($this->options['status_id']);
$invoices = Invoice::scope()
->with(['client'])
$invoices = Invoice::with(['client'])
->invoices()
->whereClientId($this->client->id)
->whereIsPublic(true)
@ -61,6 +63,12 @@ class GenerateStatementData
->where('invoice_date', '<=', $this->options['end_date']);
}
if ($this->contact) {
$invoices->whereHas('invitations', function ($query) {
$query->where('contact_id', $this->contact->id);
});
}
$invoices = $invoices->get();
$data = collect();
@ -87,8 +95,7 @@ class GenerateStatementData
private function getPayments()
{
$payments = Payment::scope()
->with('invoice', 'payment_type')
$payments = Payment::with('invoice', 'payment_type')
->withArchived()
->whereClientId($this->client->id)
->where('payment_date', '>=', $this->options['start_date'])

View File

@ -112,7 +112,7 @@ class EntityModel extends Eloquent
return $className::scope($publicId)->withTrashed()->value('id');
} else {
return $className::scope($publicId)->value('id');
}
}
}
/**

View File

@ -7,14 +7,14 @@
<link href="{{ asset('css/daterangepicker.css') }}" rel="stylesheet" type="text/css"/>
@include('money_script')
@foreach (Auth::user()->account->getFontFolders() as $font)
@foreach ($account->getFontFolders() as $font)
<script src="{{ asset('js/vfs_fonts/'.$font.'.js') }}" type="text/javascript"></script>
@endforeach
<script src="{{ asset('pdf.built.js') }}?no_cache={{ NINJA_VERSION }}" type="text/javascript"></script>
<script>
var invoiceDesigns = {!! \App\Models\InvoiceDesign::getDesigns() !!};
var invoiceDesign = JSON.stringify({!! Utils::getFromCache($account->invoice_design_id ?: 1, 'invoiceDesigns')->pdfmake !!});
var invoiceFonts = {!! Cache::get('fonts') !!};
var statementStartDate = moment("{{ $startDate }}");
@ -22,26 +22,15 @@
var dateRanges = {!! $account->present()->dateRangeOptions !!};
function getPDFString(cb) {
invoice.is_statement = true;
invoice.image = window.accountLogo;
invoice.features = {
customize_invoice_design:{{ Auth::user()->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN) ? 'true' : 'false' }},
remove_created_by:{{ Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY) ? 'true' : 'false' }},
invoice_settings:{{ Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS) ? 'true' : 'false' }}
customize_invoice_design:{{ $account->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN) ? 'true' : 'false' }},
remove_created_by:{{ $account->hasFeature(FEATURE_REMOVE_CREATED_BY) ? 'true' : 'false' }},
invoice_settings:{{ $account->hasFeature(FEATURE_INVOICE_SETTINGS) ? 'true' : 'false' }}
};
var invoiceDesignId = parseInt(invoice.invoice_design_id);
// We don't currently support the hipster design to be used as a statement
if (invoiceDesignId == 8) {
invoiceDesignId = 1;
}
var invoiceDesign = _.findWhere(invoiceDesigns, {id: invoiceDesignId});
if (!invoiceDesign) {
invoiceDesign = invoiceDesigns[0];
}
generatePDF(invoice, invoiceDesign.javascript, true, cb);
generatePDF(invoice, invoiceDesign, true, cb);
}
$(function() {
@ -98,7 +87,8 @@
$('#reportrange').css('color', '#000');
$('#reportrange').css('pointer-events', 'auto');
}
var url = '{{ url('/clients/statement/' . $client->public_id) }}' +
console.log("{{ request()->path() }}");
var url = '/{{ request()->path() . '/' . $client->public_id }}' +
'?status_id=' + statusId +
'&start_date=' + statementStartDate.format('YYYY-MM-DD') +
'&end_date=' + statementEndDate.format('YYYY-MM-DD') +
@ -120,7 +110,7 @@
}
function onDownloadClick() {
var doc = generatePDF(invoice, invoiceDesigns[0].javascript, true);
var doc = generatePDF(invoice, invoiceDesign, true);
doc.save("{{ str_replace(' ', '_', trim($client->getDisplayName())) . '-' . trans('texts.statement') }}" + '.pdf');
}
@ -205,6 +195,6 @@
&nbsp;
</div>
@include('invoices.pdf', ['account' => Auth::user()->account])
@include('invoices.pdf', ['account' => $account])
@stop

View File

@ -28,7 +28,7 @@ Route::group(['middleware' => ['lookup:contact', 'auth:client']], function () {
Route::match(['GET', 'POST'], 'complete/{invitation_key?}/{gateway_type?}', 'OnlinePaymentController@offsitePayment');
Route::get('bank/{routing_number}', 'OnlinePaymentController@getBankInfo');
Route::get('client/payment_methods', 'ClientPortalController@paymentMethods');
Route::get('client/statement', 'ClientPortalController@statement');
Route::get('client/statement/{client_id?}', 'ClientPortalController@statement');
Route::post('client/payment_methods/verify', 'ClientPortalController@verifyPaymentMethod');
Route::post('client/payment_methods/default', 'ClientPortalController@setDefaultPaymentMethod');
Route::post('client/payment_methods/{source_id}/remove', 'ClientPortalController@removePaymentMethod');