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:
parent
280bf559b4
commit
9398c45b56
@ -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()
|
||||
|
@ -20,7 +20,6 @@ class UpdateCreditRequest extends CreditRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'client' => 'required',
|
||||
'amount' => 'required|positive',
|
||||
];
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
],
|
||||
[
|
||||
|
@ -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']);
|
||||
|
@ -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');
|
||||
|
@ -21,7 +21,12 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
|
||||
{!! 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 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
var clients = {!! $clients !!};
|
||||
var clients = {!! $clients ?: 'false' !!};
|
||||
|
||||
$(function() {
|
||||
|
||||
var $clientSelect = $('select#client');
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
var client = clients[i];
|
||||
var clientName = getClientDisplayName(client);
|
||||
if (!clientName) {
|
||||
continue;
|
||||
}
|
||||
$clientSelect.append(new Option(clientName, client.public_id));
|
||||
}
|
||||
@if ( ! $credit)
|
||||
var $clientSelect = $('select#client');
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
var client = clients[i];
|
||||
var clientName = getClientDisplayName(client);
|
||||
if (!clientName) {
|
||||
continue;
|
||||
}
|
||||
$clientSelect.append(new Option(clientName, client.public_id));
|
||||
}
|
||||
|
||||
if ({{ $clientPublicId ? 'true' : 'false' }}) {
|
||||
$clientSelect.val({{ $clientPublicId }});
|
||||
}
|
||||
if ({{ $clientPublicId ? 'true' : 'false' }}) {
|
||||
$clientSelect.val({{ $clientPublicId }});
|
||||
}
|
||||
|
||||
$clientSelect.combobox();
|
||||
$clientSelect.combobox();
|
||||
@endif
|
||||
|
||||
$('#currency_id').combobox();
|
||||
$('#credit_date').datepicker('update', '{{ $credit ? $credit->credit_date : 'new Date()' }}');
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user