mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:34:34 -04:00
Working on invoice actions
This commit is contained in:
parent
94fe6ff7a2
commit
706625e83f
25
app/Factory/CloneInvoiceFactory.php
Normal file
25
app/Factory/CloneInvoiceFactory.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\Models\Invoice;
|
||||||
|
|
||||||
|
class CloneInvoiceFactory
|
||||||
|
{
|
||||||
|
public static function create(Invoice $invoice, $user_id) : ?Invoice
|
||||||
|
{
|
||||||
|
$clone_invoice = $invoice->replicate();
|
||||||
|
$clone_invoice->status_id = Invoice::STATUS_DRAFT;
|
||||||
|
$clone_invoice->invoice_number = '';
|
||||||
|
$clone_invoice->invoice_date = null;
|
||||||
|
$clone_invoice->due_date = null;
|
||||||
|
$clone_invoice->partial_due_date = null;
|
||||||
|
$clone_invoice->user_id = $user_id;
|
||||||
|
$clone_invoice->balance = $invoice->amount;
|
||||||
|
$clone_invoice->settings = $invoice->settings;
|
||||||
|
$clone_invoice->line_items = $invoice->line_items;
|
||||||
|
|
||||||
|
return $clone_invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,8 +17,13 @@ class InvoiceFactory
|
|||||||
$invoice->discount = 0;
|
$invoice->discount = 0;
|
||||||
$invoice->is_amount_discount = true;
|
$invoice->is_amount_discount = true;
|
||||||
$invoice->po_number = '';
|
$invoice->po_number = '';
|
||||||
|
$invoice->footer = '';
|
||||||
|
$invoice->terms = '';
|
||||||
|
$invoice->public_notes = '';
|
||||||
|
$invoice->private_notes = '';
|
||||||
$invoice->invoice_date = null;
|
$invoice->invoice_date = null;
|
||||||
$invoice->due_date = null;
|
$invoice->due_date = null;
|
||||||
|
$invoice->partial_due_date = null;
|
||||||
$invoice->is_deleted = false;
|
$invoice->is_deleted = false;
|
||||||
$invoice->line_items = json_encode([]);
|
$invoice->line_items = json_encode([]);
|
||||||
$invoice->settings = ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()); //todo need to embed the settings here
|
$invoice->settings = ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()); //todo need to embed the settings here
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Factory\CloneInvoiceFactory;
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Filters\InvoiceFilters;
|
use App\Filters\InvoiceFilters;
|
||||||
|
use App\Http\Requests\Invoice\ActionInvoiceRequest;
|
||||||
use App\Http\Requests\Invoice\CreateInvoiceRequest;
|
use App\Http\Requests\Invoice\CreateInvoiceRequest;
|
||||||
use App\Http\Requests\Invoice\DestroyInvoiceRequest;
|
use App\Http\Requests\Invoice\DestroyInvoiceRequest;
|
||||||
use App\Http\Requests\Invoice\EditInvoiceRequest;
|
use App\Http\Requests\Invoice\EditInvoiceRequest;
|
||||||
@ -15,6 +17,7 @@ use App\Repositories\InvoiceRepository;
|
|||||||
use App\Transformers\InvoiceTransformer;
|
use App\Transformers\InvoiceTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class InvoiceController
|
* Class InvoiceController
|
||||||
@ -161,5 +164,41 @@ class InvoiceController extends BaseController
|
|||||||
return response()->json([], 200);
|
return response()->json([], 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case 'clone':
|
||||||
|
$invoice = CloneInvoiceFactory::create($invoice, auth()->user()->id);
|
||||||
|
return $this->itemResponse($invoice);
|
||||||
|
break;
|
||||||
|
case 'clone_to_quote':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'history':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'delivery_note':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'mark_paid':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'archive':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
case 'email':
|
||||||
|
//dispatch email to queue
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
21
app/Http/Requests/Invoice/ActionInvoiceRequest.php
Normal file
21
app/Http/Requests/Invoice/ActionInvoiceRequest.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Invoice;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
|
||||||
|
class ActionInvoiceRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function authorize() : bool
|
||||||
|
{
|
||||||
|
return auth()->user()->can('edit', $this->invoice);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,9 +23,10 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
const STATUS_DRAFT = 1;
|
const STATUS_DRAFT = 1;
|
||||||
const STATUS_SENT = 2;
|
const STATUS_SENT = 2;
|
||||||
const STATUS_VIEWED = 3;
|
|
||||||
const STATUS_PARTIAL = 5;
|
const STATUS_PARTIAL = 5;
|
||||||
const STATUS_PAID = 6;
|
const STATUS_PAID = 6;
|
||||||
|
const STATUS_REVERSED = 7; //new for V2
|
||||||
|
|
||||||
const STATUS_OVERDUE = -1;
|
const STATUS_OVERDUE = -1;
|
||||||
const STATUS_UNPAID = -2;
|
const STATUS_UNPAID = -2;
|
||||||
|
|
||||||
|
@ -125,22 +125,16 @@ class InvoiceTransformer extends EntityTransformer
|
|||||||
'invoice_status_id' => (int) ($invoice->invoice_status_id ?: 1),
|
'invoice_status_id' => (int) ($invoice->invoice_status_id ?: 1),
|
||||||
'updated_at' => $invoice->updated_at,
|
'updated_at' => $invoice->updated_at,
|
||||||
'archived_at' => $invoice->deleted_at,
|
'archived_at' => $invoice->deleted_at,
|
||||||
'invoice_number' => $invoice->is_recurring ? '' : $invoice->invoice_number,
|
'invoice_number' => $invoice->invoice_number,
|
||||||
'discount' => (float) $invoice->discount,
|
'discount' => (float) $invoice->discount,
|
||||||
'po_number' => $invoice->po_number,
|
'po_number' => $invoice->po_number,
|
||||||
'invoice_date' => $invoice->invoice_date ?: '',
|
'invoice_date' => $invoice->invoice_date ?: '',
|
||||||
'due_date' => $invoice->due_date ?: '',
|
'due_date' => $invoice->due_date ?: '',
|
||||||
'terms' => $invoice->terms,
|
'terms' => $invoice->terms ?: '',
|
||||||
'public_notes' => $invoice->public_notes ?: '',
|
'public_notes' => $invoice->public_notes ?: '',
|
||||||
'private_notes' => $invoice->private_notes ?: '',
|
'private_notes' => $invoice->private_notes ?: '',
|
||||||
'is_deleted' => (bool) $invoice->is_deleted,
|
'is_deleted' => (bool) $invoice->is_deleted,
|
||||||
'invoice_type_id' => (int) $invoice->invoice_type_id,
|
'invoice_type_id' => (int) $invoice->invoice_type_id,
|
||||||
'is_recurring' => (bool) $invoice->is_recurring,
|
|
||||||
'frequency_id' => (int) $invoice->frequency_id,
|
|
||||||
'start_date' => $invoice->start_date ?: '',
|
|
||||||
'end_date' => $invoice->end_date ?: '',
|
|
||||||
'last_sent_date' => $invoice->last_sent_date ?: '',
|
|
||||||
'recurring_invoice_id' => (int) ($invoice->recurring_invoice_id ?: 0),
|
|
||||||
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
|
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
|
||||||
'tax_rate1' => (float) $invoice->tax_rate1,
|
'tax_rate1' => (float) $invoice->tax_rate1,
|
||||||
'tax_name2' => $invoice->tax_name2 ? $invoice->tax_name2 : '',
|
'tax_name2' => $invoice->tax_name2 ? $invoice->tax_name2 : '',
|
||||||
@ -149,18 +143,16 @@ class InvoiceTransformer extends EntityTransformer
|
|||||||
'invoice_footer' => $invoice->invoice_footer ?: '',
|
'invoice_footer' => $invoice->invoice_footer ?: '',
|
||||||
'partial' => (float) ($invoice->partial ?: 0.0),
|
'partial' => (float) ($invoice->partial ?: 0.0),
|
||||||
'partial_due_date' => $invoice->partial_due_date ?: '',
|
'partial_due_date' => $invoice->partial_due_date ?: '',
|
||||||
'has_tasks' => (bool) $invoice->has_tasks,
|
|
||||||
'auto_bill' => (bool) $invoice->auto_bill,
|
|
||||||
'custom_value1' => (float) $invoice->custom_value1,
|
'custom_value1' => (float) $invoice->custom_value1,
|
||||||
'custom_value2' => (float) $invoice->custom_value2,
|
'custom_value2' => (float) $invoice->custom_value2,
|
||||||
'custom_taxes1' => (bool) $invoice->custom_taxes1,
|
'custom_taxes1' => (bool) $invoice->custom_taxes1,
|
||||||
'custom_taxes2' => (bool) $invoice->custom_taxes2,
|
'custom_taxes2' => (bool) $invoice->custom_taxes2,
|
||||||
|
'has_tasks' => (bool) $invoice->has_tasks,
|
||||||
'has_expenses' => (bool) $invoice->has_expenses,
|
'has_expenses' => (bool) $invoice->has_expenses,
|
||||||
'quote_invoice_id' => (int) ($invoice->quote_invoice_id ?: 0),
|
|
||||||
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
|
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
|
||||||
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
|
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
|
||||||
'is_public' => (bool) $invoice->is_public,
|
|
||||||
'backup' => $invoice->backup ?: '',
|
'backup' => $invoice->backup ?: '',
|
||||||
|
'settings' => $invoice->settings,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -357,6 +357,12 @@ class CreateUsersTable extends Migration
|
|||||||
$t->text('settings')->nullable();
|
$t->text('settings')->nullable();
|
||||||
$t->text('backup')->nullable();
|
$t->text('backup')->nullable();
|
||||||
|
|
||||||
|
$t->text('footer')->nullable();
|
||||||
|
$t->text('public_notes')->nullable();
|
||||||
|
$t->text('private_notes')->nullable();
|
||||||
|
$t->text('terms')->nullable();
|
||||||
|
|
||||||
|
|
||||||
$t->string('tax_name1');
|
$t->string('tax_name1');
|
||||||
$t->decimal('tax_rate1', 13, 3);
|
$t->decimal('tax_rate1', 13, 3);
|
||||||
|
|
||||||
@ -371,6 +377,9 @@ class CreateUsersTable extends Migration
|
|||||||
$t->decimal('amount', 13, 2);
|
$t->decimal('amount', 13, 2);
|
||||||
$t->decimal('balance', 13, 2);
|
$t->decimal('balance', 13, 2);
|
||||||
$t->decimal('partial', 13, 2)->nullable();
|
$t->decimal('partial', 13, 2)->nullable();
|
||||||
|
$t->date('partial_due_date')->nullable();
|
||||||
|
|
||||||
|
$t->datetime('last_viewed')->nullable();
|
||||||
|
|
||||||
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||||
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||||
|
@ -34,6 +34,8 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth'], 'prefix' =
|
|||||||
|
|
||||||
Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit
|
Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
|
Route::get('invoices/{invoice}/{action}', 'InvoiceController@action');
|
||||||
|
|
||||||
Route::post('invoices/bulk', 'InvoiceController@bulk')->name('invoices.bulk');
|
Route::post('invoices/bulk', 'InvoiceController@bulk')->name('invoices.bulk');
|
||||||
|
|
||||||
Route::resource('products', 'ProductController'); // name = (products. index / create / show / update / destroy / edit
|
Route::resource('products', 'ProductController'); // name = (products. index / create / show / update / destroy / edit
|
||||||
|
@ -49,7 +49,7 @@ class MakesDatesTest extends TestCase
|
|||||||
{
|
{
|
||||||
|
|
||||||
$date_src = '2007-04-19 23:59';
|
$date_src = '2007-04-19 23:59';
|
||||||
$client_timezone = 'Atlantic/Cape_Verde'; // +1 UTC
|
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
|
||||||
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
|
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
|
||||||
|
|
||||||
$utc_date = $this->createUtcDate($date_time, $client_timezone);
|
$utc_date = $this->createUtcDate($date_time, $client_timezone);
|
||||||
@ -61,7 +61,7 @@ class MakesDatesTest extends TestCase
|
|||||||
{
|
{
|
||||||
|
|
||||||
$date_src = '2007-04-19 22:59';
|
$date_src = '2007-04-19 22:59';
|
||||||
$client_timezone = 'Atlantic/Cape_Verde'; // +1 UTC
|
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
|
||||||
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
|
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
|
||||||
|
|
||||||
$utc_date = $this->createUtcDate($date_time, $client_timezone);
|
$utc_date = $this->createUtcDate($date_time, $client_timezone);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user