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