mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Working on cloning products
This commit is contained in:
parent
1000a32bd3
commit
26572c8785
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProductRequest;
|
||||
use App\Models\Product;
|
||||
use App\Models\TaxRate;
|
||||
use App\Ninja\Datatables\ProductDatatable;
|
||||
@ -71,23 +72,39 @@ class ProductController extends BaseController
|
||||
return $this->productService->getDatatable(Auth::user()->account_id, Input::get('sSearch'));
|
||||
}
|
||||
|
||||
public function cloneProduct(ProductRequest $request, $publicId)
|
||||
{
|
||||
return self::edit($request, $publicId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $publicId
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($publicId)
|
||||
public function edit($publicId, $clone = false)
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$product = Product::scope($publicId)->withTrashed()->firstOrFail();
|
||||
|
||||
if ($clone) {
|
||||
$product->id = null;
|
||||
$product->public_id = null;
|
||||
$product->deleted_at = null;
|
||||
$url = 'products';
|
||||
$method = 'POST';
|
||||
} else {
|
||||
$url = 'products/'.$publicId;
|
||||
$method = 'PUT';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'account' => $account,
|
||||
'taxRates' => $account->invoice_item_taxes ? TaxRate::scope()->whereIsInclusive(false)->get() : null,
|
||||
'product' => $product,
|
||||
'entity' => $product,
|
||||
'method' => 'PUT',
|
||||
'url' => 'products/'.$publicId,
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'title' => trans('texts.edit_product'),
|
||||
];
|
||||
|
||||
@ -149,11 +166,16 @@ class ProductController extends BaseController
|
||||
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
|
||||
Session::flash('message', $message);
|
||||
|
||||
if (in_array(request('action'), ['archive', 'delete', 'restore', 'invoice'])) {
|
||||
$action = request('action');
|
||||
if (in_array($action, ['archive', 'delete', 'restore', 'invoice'])) {
|
||||
return self::bulk();
|
||||
}
|
||||
|
||||
return Redirect::to("products/{$product->public_id}/edit");
|
||||
if ($action == 'clone') {
|
||||
return redirect()->to(sprintf('products/%s/clone', $product->public_id));
|
||||
} else {
|
||||
return redirect()->to("products/{$product->public_id}/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,6 +68,15 @@ class ProductDatatable extends EntityDatatable
|
||||
return URL::to("products/{$model->public_id}/edit");
|
||||
},
|
||||
],
|
||||
[
|
||||
trans('texts.clone_product'),
|
||||
function ($model) {
|
||||
return "javascript:submitForm_product('clone', {$model->public_id})";
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->can('create', ENTITY_PRODUCT);
|
||||
},
|
||||
],
|
||||
[
|
||||
trans('texts.invoice_product'),
|
||||
function ($model) {
|
||||
|
@ -27,10 +27,16 @@ class ProductPresenter extends EntityPresenter
|
||||
public function moreActions()
|
||||
{
|
||||
$product = $this->entity;
|
||||
$actions = [];
|
||||
|
||||
if (! $product->trashed()) {
|
||||
if (auth()->user()->can('create', ENTITY_PRODUCT)) {
|
||||
$actions[] = ['url' => 'javascript:submitAction("clone")', 'label' => trans('texts.clone_product')];
|
||||
}
|
||||
if (auth()->user()->can('create', ENTITY_INVOICE)) {
|
||||
$actions[] = ['url' => 'javascript:submitAction("invoice")', 'label' => trans('texts.invoice_product')];
|
||||
}
|
||||
if (count($actions)) {
|
||||
$actions[] = DropdownButton::DIVIDER;
|
||||
}
|
||||
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans("texts.archive_product")];
|
||||
|
@ -2789,6 +2789,7 @@ $LANG = array(
|
||||
'purge_client' => 'Purge Client',
|
||||
'purged_client' => 'Successfully purged client',
|
||||
'purge_client_warning' => 'All related records (invoices, tasks, expenses, documents, etc) will also be deleted.',
|
||||
'clone_product' => 'Clone Product',
|
||||
|
||||
);
|
||||
|
||||
|
@ -247,6 +247,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
|
||||
Route::get('api/credits/{client_id?}', 'CreditController@getDatatable');
|
||||
Route::post('credits/bulk', 'CreditController@bulk');
|
||||
|
||||
Route::get('products/{products}/clone', 'ProductController@cloneProduct');
|
||||
Route::get('api/products', 'ProductController@getDatatable');
|
||||
Route::resource('products', 'ProductController');
|
||||
Route::post('products/bulk', 'ProductController@bulk');
|
||||
|
Loading…
Reference in New Issue
Block a user