mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 14:04:31 -04:00
Support cloning invoices to quotes and vice versa
This commit is contained in:
parent
af641a4b63
commit
dd661a97d0
@ -98,8 +98,10 @@ class InvoiceController extends BaseController
|
||||
$clients = Client::scope()->withTrashed()->with('contacts', 'country');
|
||||
|
||||
if ($clone) {
|
||||
$entityType = $clone == INVOICE_TYPE_STANDARD ? ENTITY_INVOICE : ENTITY_QUOTE;
|
||||
$invoice->id = $invoice->public_id = null;
|
||||
$invoice->is_public = false;
|
||||
$invoice->invoice_type_id = $clone;
|
||||
$invoice->invoice_number = $account->getNextNumber($invoice);
|
||||
$invoice->due_date = null;
|
||||
$invoice->balance = $invoice->amount;
|
||||
@ -371,8 +373,10 @@ class InvoiceController extends BaseController
|
||||
$message = trans("texts.updated_{$entityType}");
|
||||
Session::flash('message', $message);
|
||||
|
||||
if ($action == 'clone') {
|
||||
return url(sprintf('%ss/%s/clone', $entityType, $invoice->public_id));
|
||||
if ($action == 'clone_invoice') {
|
||||
return url(sprintf('invoices/%s/clone', $invoice->public_id));
|
||||
} else if ($action == 'clone_quote') {
|
||||
return url(sprintf('quotes/%s/clone', $invoice->public_id));
|
||||
} elseif ($action == 'convert') {
|
||||
return $this->convertQuote($request, $invoice->public_id);
|
||||
} elseif ($action == 'email') {
|
||||
@ -506,7 +510,12 @@ class InvoiceController extends BaseController
|
||||
|
||||
public function cloneInvoice(InvoiceRequest $request, $publicId)
|
||||
{
|
||||
return self::edit($request, $publicId, true);
|
||||
return self::edit($request, $publicId, INVOICE_TYPE_STANDARD);
|
||||
}
|
||||
|
||||
public function cloneQuote(InvoiceRequest $request, $publicId)
|
||||
{
|
||||
return self::edit($request, $publicId, INVOICE_TYPE_QUOTE);
|
||||
}
|
||||
|
||||
public function invoiceHistory(InvoiceRequest $request)
|
||||
|
@ -190,7 +190,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
|
||||
Route::delete('documents/{documents}', 'DocumentController@delete');
|
||||
|
||||
Route::get('quotes/create/{client_id?}', 'QuoteController@create');
|
||||
Route::get('quotes/{invoices}/clone', 'InvoiceController@cloneInvoice');
|
||||
Route::get('quotes/{invoices}/clone', 'InvoiceController@cloneQuote');
|
||||
Route::get('quotes/{invoices}/edit', 'InvoiceController@edit');
|
||||
Route::put('quotes/{invoices}', 'InvoiceController@update');
|
||||
Route::get('quotes/{invoices}', 'InvoiceController@edit');
|
||||
|
@ -83,23 +83,23 @@ class InvoiceDatatable extends EntityDatatable
|
||||
|
||||
return [
|
||||
[
|
||||
trans("texts.edit_{$entityType}"),
|
||||
function ($model) use ($entityType) {
|
||||
return URL::to("{$entityType}s/{$model->public_id}/edit");
|
||||
},
|
||||
trans("texts.clone_invoice"),
|
||||
function ($model) {
|
||||
return Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
||||
},
|
||||
],
|
||||
[
|
||||
trans("texts.clone_{$entityType}"),
|
||||
function ($model) use ($entityType) {
|
||||
return URL::to("{$entityType}s/{$model->public_id}/clone");
|
||||
return URL::to("invoices/{$model->public_id}/clone");
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->can('create', ENTITY_INVOICE);
|
||||
},
|
||||
],
|
||||
[
|
||||
trans("texts.clone_quote"),
|
||||
function ($model) {
|
||||
return URL::to("quotes/{$model->public_id}/clone");
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->can('create', ENTITY_QUOTE);
|
||||
},
|
||||
],
|
||||
[
|
||||
trans('texts.view_history'),
|
||||
function ($model) use ($entityType) {
|
||||
|
@ -8,6 +8,7 @@ use Carbon;
|
||||
use DropdownButton;
|
||||
use stdClass;
|
||||
use Utils;
|
||||
use Auth;
|
||||
|
||||
class InvoicePresenter extends EntityPresenter
|
||||
{
|
||||
@ -217,11 +218,16 @@ class InvoicePresenter extends EntityPresenter
|
||||
$entityType = $invoice->getEntityType();
|
||||
|
||||
$actions = [
|
||||
['url' => 'javascript:onCloneClick()', 'label' => trans("texts.clone_{$entityType}")],
|
||||
['url' => url("{$entityType}s/{$entityType}_history/{$invoice->public_id}"), 'label' => trans('texts.view_history')],
|
||||
DropdownButton::DIVIDER,
|
||||
['url' => 'javascript:onCloneInvoiceClick()', 'label' => trans("texts.clone_invoice")]
|
||||
];
|
||||
|
||||
if (Auth::user()->can('create', ENTITY_QUOTE)) {
|
||||
$actions[] = ['url' => 'javascript:onCloneQuoteClick()', 'label' => trans("texts.clone_quote")];
|
||||
}
|
||||
|
||||
$actions[] = ['url' => url("{$entityType}s/{$entityType}_history/{$invoice->public_id}"), 'label' => trans('texts.view_history')];
|
||||
$actions[] = DropdownButton::DIVIDER;
|
||||
|
||||
if ($entityType == ENTITY_QUOTE) {
|
||||
if ($invoice->quote_invoice_id) {
|
||||
$actions[] = ['url' => url("invoices/{$invoice->quote_invoice_id}/edit"), 'label' => trans('texts.view_invoice')];
|
||||
|
@ -1468,8 +1468,12 @@
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function onCloneClick() {
|
||||
submitAction('clone');
|
||||
function onCloneInvoiceClick() {
|
||||
submitAction('clone_invoice');
|
||||
}
|
||||
|
||||
function onCloneQuoteClick() {
|
||||
submitAction('clone_quote');
|
||||
}
|
||||
|
||||
function onConvertClick() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user