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

Prevent changing credit's client

This commit is contained in:
Hillel Coren 2016-12-04 12:24:48 +02:00
parent 280bf559b4
commit 9398c45b56
7 changed files with 34 additions and 23 deletions

View File

@ -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()

View File

@ -20,7 +20,6 @@ class UpdateCreditRequest extends CreditRequest
public function rules()
{
return [
'client' => 'required',
'amount' => 'required|positive',
];
}

View File

@ -38,8 +38,12 @@ class CreditDatatable extends EntityDatatable
[
'credit_date',
function ($model) {
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();
}
],
[
'private_notes',

View File

@ -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']);

View File

@ -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');

View File

@ -21,7 +21,12 @@
<div class="panel panel-default">
<div class="panel-body">
@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,10 +51,11 @@
<script type="text/javascript">
var clients = {!! $clients !!};
var clients = {!! $clients ?: 'false' !!};
$(function() {
@if ( ! $credit)
var $clientSelect = $('select#client');
for (var i=0; i<clients.length; i++) {
var client = clients[i];
@ -65,6 +71,7 @@
}
$clientSelect.combobox();
@endif
$('#currency_id').combobox();
$('#credit_date').datepicker('update', '{{ $credit ? $credit->credit_date : 'new Date()' }}');

View File

@ -56,7 +56,7 @@
@endif
@if (Auth::user()->can('create', $entityType))
{!! Button::primary(trans("texts.new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create'))->appendIcon(Icon::create('plus-sign')) !!}
{!! Button::primary(trans("texts.new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create/' . (isset($clientId) ? $clientId : '')))->appendIcon(Icon::create('plus-sign')) !!}
@endif
</div>