mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Added ability to edit payments
This commit is contained in:
parent
d57fe62c49
commit
dc23bad422
@ -71,7 +71,9 @@ class PaymentController extends \BaseController
|
||||
<ul class="dropdown-menu" role="menu">';
|
||||
|
||||
if (!$model->deleted_at || $model->deleted_at == '0000-00-00') {
|
||||
$str .= '<li><a href="javascript:archiveEntity('.$model->public_id.')">'.trans('texts.archive_payment').'</a></li>';
|
||||
$str .= '<li><a href="payments/'.$model->public_id.'/edit">'.trans('texts.edit_payment').'</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="javascript:archiveEntity('.$model->public_id.')">'.trans('texts.archive_payment').'</a></li>';
|
||||
} else {
|
||||
$str .= '<li><a href="javascript:restoreEntity('.$model->public_id.')">'.trans('texts.restore_payment').'</a></li>';
|
||||
}
|
||||
@ -141,7 +143,7 @@ class PaymentController extends \BaseController
|
||||
'payment' => $payment,
|
||||
'method' => 'PUT',
|
||||
'url' => 'payments/'.$publicId,
|
||||
'title' => 'Edit Payment',
|
||||
'title' => trans('texts.edit_payment'),
|
||||
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
|
||||
'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
@ -687,7 +689,7 @@ class PaymentController extends \BaseController
|
||||
|
||||
private function save($publicId = null)
|
||||
{
|
||||
if ($errors = $this->paymentRepo->getErrors(Input::all())) {
|
||||
if (!$publicId && $errors = $this->paymentRepo->getErrors(Input::all())) {
|
||||
$url = $publicId ? 'payments/'.$publicId.'/edit' : 'payments/create';
|
||||
|
||||
return Redirect::to($url)
|
||||
@ -695,10 +697,14 @@ class PaymentController extends \BaseController
|
||||
->withInput();
|
||||
} else {
|
||||
$this->paymentRepo->save($publicId, Input::all());
|
||||
|
||||
Session::flash('message', trans('texts.created_payment'));
|
||||
|
||||
return Redirect::to('clients/'.Input::get('client'));
|
||||
|
||||
if ($publicId) {
|
||||
Session::flash('message', trans('texts.updated_payment'));
|
||||
return Redirect::to('payments/');
|
||||
} else {
|
||||
Session::flash('message', trans('texts.created_payment'));
|
||||
return Redirect::to('clients/'.Input::get('client'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,4 +497,7 @@ return array(
|
||||
'select_versiony' => 'Select version',
|
||||
'view_history' => 'View History',
|
||||
|
||||
'edit_payment' => 'Edit Payment',
|
||||
'updated_payment' => 'Successfully updated payment',
|
||||
|
||||
);
|
||||
|
@ -94,29 +94,33 @@ class PaymentRepository
|
||||
}
|
||||
|
||||
$paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null;
|
||||
$clientId = Client::getPrivateId($input['client']);
|
||||
$amount = Utils::parseFloat($input['amount']);
|
||||
|
||||
if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
|
||||
$credits = Credit::scope()->where('client_id', '=', $clientId)
|
||||
->where('balance', '>', 0)->orderBy('created_at')->get();
|
||||
$applied = 0;
|
||||
|
||||
foreach ($credits as $credit) {
|
||||
$applied += $credit->apply($amount);
|
||||
|
||||
if ($applied >= $amount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payment->client_id = $clientId;
|
||||
$payment->invoice_id = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
|
||||
$payment->payment_type_id = $paymentTypeId;
|
||||
$payment->payment_date = Utils::toSqlDate($input['payment_date']);
|
||||
$payment->amount = $amount;
|
||||
$payment->transaction_reference = trim($input['transaction_reference']);
|
||||
|
||||
if (!$publicId) {
|
||||
$clientId = Client::getPrivateId($input['client']);
|
||||
$amount = Utils::parseFloat($input['amount']);
|
||||
|
||||
if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
|
||||
$credits = Credit::scope()->where('client_id', '=', $clientId)
|
||||
->where('balance', '>', 0)->orderBy('created_at')->get();
|
||||
$applied = 0;
|
||||
|
||||
foreach ($credits as $credit) {
|
||||
$applied += $credit->apply($amount);
|
||||
|
||||
if ($applied >= $amount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payment->client_id = $clientId;
|
||||
$payment->invoice_id = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
|
||||
$payment->amount = $amount;
|
||||
}
|
||||
|
||||
$payment->save();
|
||||
|
||||
return $payment;
|
||||
|
@ -132,9 +132,6 @@ Route::group(array('before' => 'auth'), function() {
|
||||
Route::get('api/quotes/{client_id?}', array('as'=>'api.quotes', 'uses'=>'QuoteController@getDatatable'));
|
||||
Route::post('quotes/bulk', 'QuoteController@bulk');
|
||||
|
||||
Route::get('payments/{id}/edit', function() {
|
||||
return View::make('header');
|
||||
});
|
||||
Route::resource('payments', 'PaymentController');
|
||||
Route::get('payments/create/{client_id?}/{invoice_id?}', 'PaymentController@create');
|
||||
Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable'));
|
||||
|
@ -13,13 +13,20 @@
|
||||
'invoice' => 'required',
|
||||
'amount' => 'required',
|
||||
)); }}
|
||||
|
||||
@if ($payment)
|
||||
{{ Former::populate($payment) }}
|
||||
@endif
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
|
||||
{{ Former::select('client')->addOption('', '')->addGroupClass('client-select') }}
|
||||
{{ Former::select('invoice')->addOption('', '')->addGroupClass('invoice-select') }}
|
||||
{{ Former::text('amount') }}
|
||||
@if (!$payment)
|
||||
{{ Former::select('client')->addOption('', '')->addGroupClass('client-select') }}
|
||||
{{ Former::select('invoice')->addOption('', '')->addGroupClass('invoice-select') }}
|
||||
{{ Former::text('amount') }}
|
||||
@endif
|
||||
|
||||
{{ Former::select('payment_type_id')->addOption('','')
|
||||
->fromQuery($paymentTypes, 'name', 'id') }}
|
||||
{{ Former::text('payment_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('<i class="glyphicon glyphicon-calendar"></i>') }}
|
||||
@ -35,7 +42,7 @@
|
||||
|
||||
<center class="buttons">
|
||||
{{ Button::lg_primary_submit_success(trans('texts.save'))->append_with_icon('floppy-disk') }}
|
||||
{{ Button::lg_default_link('payments/' . ($payment ? $payment->public_id : ''), trans('texts.cancel'))->append_with_icon('remove-circle'); }}
|
||||
{{ Button::lg_default_link('payments/', trans('texts.cancel'))->append_with_icon('remove-circle'); }}
|
||||
</center>
|
||||
|
||||
{{ Former::close() }}
|
||||
@ -47,10 +54,14 @@
|
||||
|
||||
$(function() {
|
||||
|
||||
populateInvoiceComboboxes({{ $clientPublicId }}, {{ $invoicePublicId }});
|
||||
@if ($payment)
|
||||
$('#payment_date').datepicker('update', '{{ $payment->payment_date }}')
|
||||
@else
|
||||
$('#payment_date').datepicker('update', new Date());
|
||||
populateInvoiceComboboxes({{ $clientPublicId }}, {{ $invoicePublicId }});
|
||||
@endif
|
||||
|
||||
$('#payment_type_id').combobox();
|
||||
$('#payment_date').datepicker('update', new Date());
|
||||
$('#payment_type_id').combobox();
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user