1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Support cloning expenses

This commit is contained in:
Hillel Coren 2017-07-20 18:03:05 +03:00
parent 297bc6f18a
commit 7e9add625b
5 changed files with 47 additions and 5 deletions

View File

@ -94,11 +94,20 @@ class ExpenseController extends BaseController
return View::make('expenses.edit', $data);
}
public function edit(ExpenseRequest $request)
public function clone(ExpenseRequest $request, $publicId)
{
return self::edit($request, $publicId, true);
}
public function edit(ExpenseRequest $request, $publicId = false, $clone = false)
{
$expense = $request->entity();
$actions = [];
if (! $clone) {
$actions[] = ['url' => 'javascript:submitAction("clone")', 'label' => trans("texts.clone_expense")];
}
if ($expense->invoice) {
$actions[] = ['url' => URL::to("invoices/{$expense->invoice->public_id}/edit"), 'label' => trans('texts.view_invoice')];
} else {
@ -124,12 +133,28 @@ class ExpenseController extends BaseController
$actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')];
}
if ($clone) {
$expense->id = null;
$expense->public_id = null;
$expense->expense_date = date_create()->format('Y-m-d');
$expense->deleted_at = null;
$expense->invoice_id = null;
$expense->payment_date = null;
$expense->payment_type_id = null;
$expense->transaction_reference = null;
$method = 'POST';
$url = 'expenses';
} else {
$method = 'PUT';
$url = 'expenses/' . $expense->public_id;
}
$data = [
'vendor' => null,
'expense' => $expense,
'entity' => $expense,
'method' => 'PUT',
'url' => 'expenses/'.$expense->public_id,
'method' => $method,
'url' => $url,
'title' => 'Edit Expense',
'actions' => $actions,
'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(),
@ -165,7 +190,11 @@ class ExpenseController extends BaseController
return self::bulk();
}
return redirect()->to("expenses/{$expense->public_id}/edit");
if ($action == 'clone') {
return redirect()->to(sprintf('expenses/%s/clone', $expense->public_id));
} else {
return redirect()->to("expenses/{$expense->public_id}/edit");
}
}
public function store(CreateExpenseRequest $request)

View File

@ -224,6 +224,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
// Expense
Route::resource('expenses', 'ExpenseController');
Route::get('expenses/create/{vendor_id?}/{client_id?}/{category_id?}', 'ExpenseController@create');
Route::get('expenses/{expenses}/clone', 'ExpenseController@clone');
Route::get('api/expenses', 'ExpenseController@getDatatable');
Route::get('api/expenses/{id}', 'ExpenseController@getDatatableVendor');
Route::post('expenses/bulk', 'ExpenseController@bulk');

View File

@ -108,6 +108,15 @@ class ExpenseDatatable extends EntityDatatable
return Auth::user()->can('editByOwner', [ENTITY_EXPENSE, $model->user_id]);
},
],
[
trans("texts.clone_expense"),
function ($model) {
return URL::to("expenses/{$model->public_id}/clone");
},
function ($model) {
return Auth::user()->can('create', ENTITY_EXPENSE);
},
],
[
trans('texts.view_invoice'),
function ($model) {

View File

@ -33,7 +33,9 @@ class EntityPresenter extends Presenter
{
$class = $text = '';
if ($this->entity->is_deleted) {
if (! $this->entity->id) {
return '';
} elseif ($this->entity->is_deleted) {
$class = 'danger';
$label = trans('texts.deleted');
} elseif ($this->entity->trashed()) {

View File

@ -2315,6 +2315,7 @@ $LANG = array(
'downloaded_quote' => 'An email will be sent with the quote PDF',
'downloaded_invoices' => 'An email will be sent with the invoice PDFs',
'downloaded_quotes' => 'An email will be sent with the quote PDFs',
'clone_expense' => 'Clone Expense',
);