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 Utils;
|
||||||
use View;
|
use View;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Credit;
|
||||||
use App\Services\CreditService;
|
use App\Services\CreditService;
|
||||||
use App\Ninja\Repositories\CreditRepository;
|
use App\Ninja\Repositories\CreditRepository;
|
||||||
|
use App\Http\Requests\UpdateCreditRequest;
|
||||||
use App\Http\Requests\CreateCreditRequest;
|
use App\Http\Requests\CreateCreditRequest;
|
||||||
use App\Http\Requests\CreditRequest;
|
use App\Http\Requests\CreditRequest;
|
||||||
use App\Ninja\Datatables\CreditDatatable;
|
use App\Ninja\Datatables\CreditDatatable;
|
||||||
@ -60,10 +62,9 @@ class CreditController extends BaseController
|
|||||||
return View::make('credits.edit', $data);
|
return View::make('credits.edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function edit($publicId)
|
public function edit($publicId)
|
||||||
{
|
{
|
||||||
$credit = Credit::scope($publicId)->firstOrFail();
|
$credit = Credit::withTrashed()->scope($publicId)->firstOrFail();
|
||||||
|
|
||||||
$this->authorize('edit', $credit);
|
$this->authorize('edit', $credit);
|
||||||
|
|
||||||
@ -71,23 +72,37 @@ class CreditController extends BaseController
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'client' => null,
|
'client' => null,
|
||||||
|
'clientPublicId' => $credit->client->public_id,
|
||||||
'credit' => $credit,
|
'credit' => $credit,
|
||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'url' => 'credits/'.$publicId,
|
'url' => 'credits/'.$publicId,
|
||||||
'title' => 'Edit Credit',
|
'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)
|
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()
|
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 '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRoute()
|
||||||
|
{
|
||||||
|
return "/credits/{$this->public_id}";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
@ -53,6 +53,15 @@ class CreditDatatable extends EntityDatatable
|
|||||||
public function actions()
|
public function actions()
|
||||||
{
|
{
|
||||||
return [
|
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'),
|
trans('texts.apply_credit'),
|
||||||
function ($model) {
|
function ($model) {
|
||||||
|
@ -44,9 +44,9 @@ class CreditService extends BaseService
|
|||||||
* @param $data
|
* @param $data
|
||||||
* @return mixed|null
|
* @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_product' => 'Successfully deleted product',
|
||||||
'deleted_products' => 'Successfully deleted :count products',
|
'deleted_products' => 'Successfully deleted :count products',
|
||||||
'restored_product' => 'Successfully restored product',
|
'restored_product' => 'Successfully restored product',
|
||||||
|
'update_credit' => 'Update credit',
|
||||||
|
'updated_credit' => 'Successfully updated credit',
|
||||||
|
'edit_credit' => 'Edit credit',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@
|
|||||||
'amount' => 'required',
|
'amount' => 'required',
|
||||||
)) !!}
|
)) !!}
|
||||||
|
|
||||||
|
@if ($credit)
|
||||||
|
{!! Former::populate($credit) !!}
|
||||||
|
<div style="display:none">
|
||||||
|
{!! Former::text('public_id') !!}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10 col-md-offset-1">
|
<div class="col-md-10 col-md-offset-1">
|
||||||
|
|
||||||
@ -60,7 +67,7 @@
|
|||||||
$clientSelect.combobox();
|
$clientSelect.combobox();
|
||||||
|
|
||||||
$('#currency_id').combobox();
|
$('#currency_id').combobox();
|
||||||
$('#credit_date').datepicker('update', new Date());
|
$('#credit_date').datepicker('update', '{{ $credit ? $credit->credit_date : 'new Date()' }}');
|
||||||
|
|
||||||
@if (!$clientPublicId)
|
@if (!$clientPublicId)
|
||||||
$('.client-select input.form-control').focus();
|
$('.client-select input.form-control').focus();
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
{!! Button::normal(trans('texts.projects'))->asLinkTo(URL::to('/projects'))->appendIcon(Icon::create('list')) !!}
|
{!! Button::normal(trans('texts.projects'))->asLinkTo(URL::to('/projects'))->appendIcon(Icon::create('list')) !!}
|
||||||
@endif
|
@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')) !!}
|
{!! Button::primary(trans("texts.new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create'))->appendIcon(Icon::create('plus-sign')) !!}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user