mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Show credit amount on new payment form
This commit is contained in:
parent
2330f07b4c
commit
9721491072
@ -89,16 +89,29 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function create(PaymentRequest $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$account = $user->account;
|
||||
|
||||
$invoices = Invoice::scope()
|
||||
->invoices()
|
||||
->where('invoices.invoice_status_id', '!=', INVOICE_STATUS_PAID)
|
||||
->with('client', 'invoice_status')
|
||||
->orderBy('invoice_number')->get();
|
||||
|
||||
$clientPublicId = Input::old('client') ? Input::old('client') : ($request->client_id ?: 0);
|
||||
$invoicePublicId = Input::old('invoice') ? Input::old('invoice') : ($request->invoice_id ?: 0);
|
||||
|
||||
$totalCredit = false;
|
||||
if ($clientPublicId && $client = Client::scope($clientPublicId)->first()) {
|
||||
$totalCredit = $account->formatMoney($client->getTotalCredit(), $client);
|
||||
} elseif ($invoicePublicId && $invoice = Invoice::scope($invoicePublicId)->first()) {
|
||||
$totalCredit = $account->formatMoney($invoice->client->getTotalCredit(), $client);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'account' => Auth::user()->account,
|
||||
'clientPublicId' => Input::old('client') ? Input::old('client') : ($request->client_id ?: 0),
|
||||
'invoicePublicId' => Input::old('invoice') ? Input::old('invoice') : ($request->invoice_id ?: 0),
|
||||
'clientPublicId' => $clientPublicId,
|
||||
'invoicePublicId' => $invoicePublicId,
|
||||
'invoice' => null,
|
||||
'invoices' => $invoices,
|
||||
'payment' => null,
|
||||
@ -106,7 +119,9 @@ class PaymentController extends BaseController
|
||||
'url' => 'payments',
|
||||
'title' => trans('texts.new_payment'),
|
||||
'paymentTypeId' => Input::get('paymentTypeId'),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ];
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'totalCredit' => $totalCredit,
|
||||
];
|
||||
|
||||
return View::make('payments.edit', $data);
|
||||
}
|
||||
|
@ -162,6 +162,9 @@
|
||||
}
|
||||
|
||||
$(function() {
|
||||
@if ($totalCredit)
|
||||
$('#payment_type_id option:contains("{{ trans('texts.apply_credit') }}")').text("{{ trans('texts.apply_credit') }} | {{ $totalCredit}}");
|
||||
@endif
|
||||
|
||||
@if (Input::old('data'))
|
||||
// this means we failed so we'll reload the previous state
|
||||
@ -408,12 +411,14 @@
|
||||
|
||||
if (invoiceId) {
|
||||
var invoice = invoiceMap[invoiceId];
|
||||
var client = clientMap[invoice.client.public_id];
|
||||
invoice.client = client;
|
||||
setComboboxValue($('.invoice-select'), invoice.public_id, (invoice.invoice_number + ' - ' +
|
||||
invoice.invoice_status.name + ' - ' + getClientDisplayName(client) + ' - ' +
|
||||
formatMoneyInvoice(invoice.amount, invoice) + ' | ' + formatMoneyInvoice(invoice.balance, invoice)));
|
||||
$invoiceSelect.trigger('change');
|
||||
if (invoice) {
|
||||
var client = clientMap[invoice.client.public_id];
|
||||
invoice.client = client;
|
||||
setComboboxValue($('.invoice-select'), invoice.public_id, (invoice.invoice_number + ' - ' +
|
||||
invoice.invoice_status.name + ' - ' + getClientDisplayName(client) + ' - ' +
|
||||
formatMoneyInvoice(invoice.amount, invoice) + ' | ' + formatMoneyInvoice(invoice.balance, invoice)));
|
||||
$invoiceSelect.trigger('change');
|
||||
}
|
||||
} else if (clientId) {
|
||||
var client = clientMap[clientId];
|
||||
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
|
||||
|
Loading…
Reference in New Issue
Block a user