From 9398c45b5657ed30fc9c559bc98217e39577b747 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 4 Dec 2016 12:24:48 +0200 Subject: [PATCH] Prevent changing credit's client --- app/Http/Controllers/CreditController.php | 6 ++-- app/Http/Requests/UpdateCreditRequest.php | 1 - app/Ninja/Datatables/CreditDatatable.php | 6 +++- app/Ninja/Repositories/CreditRepository.php | 2 +- resources/views/clients/show.blade.php | 3 +- resources/views/credits/edit.blade.php | 37 ++++++++++++--------- resources/views/list.blade.php | 2 +- 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index ff648824d5..e7fca9d922 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -71,13 +71,13 @@ class CreditController extends BaseController $credit->credit_date = Utils::fromSqlDate($credit->credit_date); $data = array( - 'client' => null, + 'client' => $credit->client, 'clientPublicId' => $credit->client->public_id, 'credit' => $credit, 'method' => 'PUT', 'url' => 'credits/'.$publicId, 'title' => 'Edit Credit', - 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), + 'clients' => null, ); return View::make('credits.edit', $data); @@ -102,7 +102,7 @@ class CreditController extends BaseController $message = $credit->wasRecentlyCreated ? trans('texts.created_credit') : trans('texts.updated_credit'); Session::flash('message', $message); - return redirect()->to("credits/{$credit->public_id}/edit"); + return redirect()->to("clients/{$credit->client->public_id}#credits"); } public function bulk() diff --git a/app/Http/Requests/UpdateCreditRequest.php b/app/Http/Requests/UpdateCreditRequest.php index c5c1d4c6c2..0bc9d64066 100644 --- a/app/Http/Requests/UpdateCreditRequest.php +++ b/app/Http/Requests/UpdateCreditRequest.php @@ -20,7 +20,6 @@ class UpdateCreditRequest extends CreditRequest public function rules() { return [ - 'client' => 'required', 'amount' => 'required|positive', ]; } diff --git a/app/Ninja/Datatables/CreditDatatable.php b/app/Ninja/Datatables/CreditDatatable.php index 5e07cfe343..6e2dd491b1 100644 --- a/app/Ninja/Datatables/CreditDatatable.php +++ b/app/Ninja/Datatables/CreditDatatable.php @@ -38,7 +38,11 @@ class CreditDatatable extends EntityDatatable [ 'credit_date', function ($model) { - return Utils::fromSqlDate($model->credit_date); + if ( ! Auth::user()->can('viewByOwner', [ENTITY_CREDIT, $model->user_id])){ + return Utils::fromSqlDate($model->credit_date); + } + + return link_to("credits/{$model->public_id}/edit", Utils::fromSqlDate($model->credit_date))->toHtml(); } ], [ diff --git a/app/Ninja/Repositories/CreditRepository.php b/app/Ninja/Repositories/CreditRepository.php index 00fffd8f42..f7f4637ca3 100644 --- a/app/Ninja/Repositories/CreditRepository.php +++ b/app/Ninja/Repositories/CreditRepository.php @@ -94,9 +94,9 @@ class CreditRepository extends BaseRepository \Log::warning('Entity not set in credit repo save'); } else { $credit = Credit::createNew(); + $credit->client_id = Client::getPrivateId($input['client']); } - $credit->client_id = Client::getPrivateId($input['client']); $credit->credit_date = Utils::toSqlDate($input['credit_date']); $credit->amount = Utils::parseFloat($input['amount']); $credit->balance = Utils::parseFloat($input['amount']); diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index f09912a47b..3db9ccb8e0 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -304,7 +304,8 @@ window['load_' + target](); } }); - var tab = localStorage.getItem('client_tab') || ''; + + var tab = window.location.hash || (localStorage.getItem('client_tab') || ''); var selector = '.nav-tabs a[href="#' + tab.replace('#', '') + '"]'; if (tab && tab != 'activity' && $(selector).length) { $(selector).tab('show'); diff --git a/resources/views/credits/edit.blade.php b/resources/views/credits/edit.blade.php index 18b00b4807..72973733af 100644 --- a/resources/views/credits/edit.blade.php +++ b/resources/views/credits/edit.blade.php @@ -21,7 +21,12 @@
- {!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!} + @if ($credit) + {!! Former::plaintext()->label('client')->value($client->present()->link) !!} + @else + {!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!} + @endif + {!! Former::text('amount') !!} {!! Former::text('credit_date') ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT)) @@ -46,25 +51,27 @@