mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Support editing credits
This commit is contained in:
parent
556737f929
commit
55340b8d13
@ -7,8 +7,10 @@ use URL;
|
||||
use Utils;
|
||||
use View;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Services\CreditService;
|
||||
use App\Ninja\Repositories\CreditRepository;
|
||||
use App\Http\Requests\UpdateCreditRequest;
|
||||
use App\Http\Requests\CreateCreditRequest;
|
||||
use App\Http\Requests\CreditRequest;
|
||||
use App\Ninja\Datatables\CreditDatatable;
|
||||
@ -60,10 +62,9 @@ class CreditController extends BaseController
|
||||
return View::make('credits.edit', $data);
|
||||
}
|
||||
|
||||
/*
|
||||
public function edit($publicId)
|
||||
{
|
||||
$credit = Credit::scope($publicId)->firstOrFail();
|
||||
$credit = Credit::withTrashed()->scope($publicId)->firstOrFail();
|
||||
|
||||
$this->authorize('edit', $credit);
|
||||
|
||||
@ -71,23 +72,37 @@ class CreditController extends BaseController
|
||||
|
||||
$data = array(
|
||||
'client' => null,
|
||||
'clientPublicId' => $credit->client->public_id,
|
||||
'credit' => $credit,
|
||||
'method' => 'PUT',
|
||||
'url' => 'credits/'.$publicId,
|
||||
'title' => 'Edit Credit',
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
);
|
||||
|
||||
return View::make('credit.edit', $data);
|
||||
return View::make('credits.edit', $data);
|
||||
}
|
||||
|
||||
public function update(UpdateCreditRequest $request)
|
||||
{
|
||||
$credit = $request->entity();
|
||||
|
||||
return $this->save($credit);
|
||||
}
|
||||
*/
|
||||
|
||||
public function store(CreateCreditRequest $request)
|
||||
{
|
||||
$credit = $this->creditRepo->save($request->input());
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
Session::flash('message', trans('texts.created_credit'));
|
||||
private function save($credit = null)
|
||||
{
|
||||
$credit = $this->creditService->save(Input::all(), $credit);
|
||||
|
||||
return redirect()->to($credit->client->getRoute());
|
||||
$message = $credit->wasRecentlyCreated ? trans('texts.created_created') : trans('texts.updated_credit');
|
||||
Session::flash('message', $message);
|
||||
|
||||
return redirect()->to("credits/{$credit->public_id}/edit");
|
||||
}
|
||||
|
||||
public function bulk()
|
||||
|
27
app/Http/Requests/UpdateCreditRequest.php
Normal file
27
app/Http/Requests/UpdateCreditRequest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php namespace App\Http\Requests;
|
||||
|
||||
class UpdateCreditRequest extends CreditRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->user()->can('edit', $this->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'client' => 'required',
|
||||
'amount' => 'required|positive',
|
||||
];
|
||||
}
|
||||
}
|
@ -61,6 +61,14 @@ class Credit extends EntityModel
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
return "/credits/{$this->public_id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -53,6 +53,15 @@ class CreditDatatable extends EntityDatatable
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
[
|
||||
trans('texts.edit_credit'),
|
||||
function ($model) {
|
||||
return URL::to("credits/{$model->public_id}/edit");
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->can('editByOwner', [ENTITY_CREDIT, $model->user_id]);
|
||||
}
|
||||
],
|
||||
[
|
||||
trans('texts.apply_credit'),
|
||||
function ($model) {
|
||||
|
@ -44,9 +44,9 @@ class CreditService extends BaseService
|
||||
* @param $data
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function save($data)
|
||||
public function save($data, $credit = null)
|
||||
{
|
||||
return $this->creditRepo->save($data);
|
||||
return $this->creditRepo->save($data, $credit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2249,7 +2249,9 @@ $LANG = array(
|
||||
'deleted_product' => 'Successfully deleted product',
|
||||
'deleted_products' => 'Successfully deleted :count products',
|
||||
'restored_product' => 'Successfully restored product',
|
||||
|
||||
'update_credit' => 'Update credit',
|
||||
'updated_credit' => 'Successfully updated credit',
|
||||
'edit_credit' => 'Edit credit',
|
||||
|
||||
);
|
||||
|
||||
|
@ -8,6 +8,13 @@
|
||||
'amount' => 'required',
|
||||
)) !!}
|
||||
|
||||
@if ($credit)
|
||||
{!! Former::populate($credit) !!}
|
||||
<div style="display:none">
|
||||
{!! Former::text('public_id') !!}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-md-offset-1">
|
||||
|
||||
@ -60,7 +67,7 @@
|
||||
$clientSelect.combobox();
|
||||
|
||||
$('#currency_id').combobox();
|
||||
$('#credit_date').datepicker('update', new Date());
|
||||
$('#credit_date').datepicker('update', '{{ $credit ? $credit->credit_date : 'new Date()' }}');
|
||||
|
||||
@if (!$clientPublicId)
|
||||
$('.client-select input.form-control').focus();
|
||||
|
@ -55,7 +55,7 @@
|
||||
{!! Button::normal(trans('texts.projects'))->asLinkTo(URL::to('/projects'))->appendIcon(Icon::create('list')) !!}
|
||||
@endif
|
||||
|
||||
@if (empty($clientId) && empty($vendorId) && Auth::user()->can('create', $entityType))
|
||||
@if (Auth::user()->can('create', $entityType))
|
||||
{!! Button::primary(trans("texts.new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create'))->appendIcon(Icon::create('plus-sign')) !!}
|
||||
@endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user