mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-20 15:55:19 +00:00
Consolidate single-action controllers into resource controllers
Merge 11 single-action controllers into their parent resource controllers: - Invoice: send, sendPreview, clone, changeStatus -> InvoicesController - Estimate: send, sendPreview, clone, convertToInvoice, changeStatus -> EstimatesController - Payment: send, sendPreview -> PaymentsController Extract clone and convert business logic from controllers into services: - InvoiceService: add clone(), changeStatus() - EstimateService: add clone(), convertToInvoice(), changeStatus() Previously this logic was inlined in controllers (~80-90 lines each).
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Estimate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ChangeEstimateStatusController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$estimate->update($request->only('status'));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\EstimateResource;
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\Estimate;
|
||||
use App\Services\SerialNumberService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CloneEstimateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('view', $estimate);
|
||||
$this->authorize('create', Estimate::class);
|
||||
|
||||
$date = Carbon::now();
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel($estimate)
|
||||
->setCompany($estimate->company_id)
|
||||
->setCustomer($estimate->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$due_date = null;
|
||||
$dueDateEnabled = CompanySetting::getSetting(
|
||||
'estimate_set_expiry_date_automatically',
|
||||
$request->header('company')
|
||||
);
|
||||
|
||||
if ($dueDateEnabled === 'YES') {
|
||||
$dueDateDays = intval(CompanySetting::getSetting(
|
||||
'estimate_expiry_date_days',
|
||||
$request->header('company')
|
||||
));
|
||||
$due_date = Carbon::now()->addDays($dueDateDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$exchange_rate = $estimate->exchange_rate;
|
||||
|
||||
$newEstimate = Estimate::create([
|
||||
'estimate_date' => $date->format('Y-m-d'),
|
||||
'expiry_date' => $due_date,
|
||||
'estimate_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $estimate->reference_number,
|
||||
'customer_id' => $estimate->customer_id,
|
||||
'company_id' => $request->header('company'),
|
||||
'template_name' => $estimate->template_name,
|
||||
'status' => Estimate::STATUS_DRAFT,
|
||||
'sub_total' => $estimate->sub_total,
|
||||
'discount' => $estimate->discount,
|
||||
'discount_type' => $estimate->discount_type,
|
||||
'discount_val' => $estimate->discount_val,
|
||||
'total' => $estimate->total,
|
||||
'due_amount' => $estimate->total,
|
||||
'tax_per_item' => $estimate->tax_per_item,
|
||||
'discount_per_item' => $estimate->discount_per_item,
|
||||
'tax' => $estimate->tax,
|
||||
'notes' => $estimate->notes,
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_total' => $estimate->total * $exchange_rate,
|
||||
'base_discount_val' => $estimate->discount_val * $exchange_rate,
|
||||
'base_sub_total' => $estimate->sub_total * $exchange_rate,
|
||||
'base_tax' => $estimate->tax * $exchange_rate,
|
||||
'base_due_amount' => $estimate->total * $exchange_rate,
|
||||
'currency_id' => $estimate->currency_id,
|
||||
'sales_tax_type' => $estimate->sales_tax_type,
|
||||
'sales_tax_address_type' => $estimate->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$newEstimate->unique_hash = Hashids::connection(Estimate::class)->encode($newEstimate->id);
|
||||
$newEstimate->save();
|
||||
$estimate->load('items.taxes');
|
||||
|
||||
$estimateItems = $estimate->items->toArray();
|
||||
|
||||
foreach ($estimateItems as $estimateItem) {
|
||||
$estimateItem['company_id'] = $request->header('company');
|
||||
$estimateItem['name'] = $estimateItem['name'];
|
||||
$estimateItem['exchange_rate'] = $exchange_rate;
|
||||
$estimateItem['base_price'] = $estimateItem['price'] * $exchange_rate;
|
||||
$estimateItem['base_discount_val'] = $estimateItem['discount_val'] * $exchange_rate;
|
||||
$estimateItem['base_tax'] = $estimateItem['tax'] * $exchange_rate;
|
||||
$estimateItem['base_total'] = $estimateItem['total'] * $exchange_rate;
|
||||
|
||||
$item = $newEstimate->items()->create($estimateItem);
|
||||
|
||||
if (array_key_exists('taxes', $estimateItem) && $estimateItem['taxes']) {
|
||||
foreach ($estimateItem['taxes'] as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
|
||||
if ($tax['amount']) {
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($estimate->taxes) {
|
||||
foreach ($estimate->taxes->toArray() as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$newEstimate->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
|
||||
if ($estimate->fields()->exists()) {
|
||||
$customFields = [];
|
||||
|
||||
foreach ($estimate->fields as $data) {
|
||||
$customFields[] = [
|
||||
'id' => $data->custom_field_id,
|
||||
'value' => $data->defaultAnswer,
|
||||
];
|
||||
}
|
||||
|
||||
$newEstimate->addCustomFields($customFields);
|
||||
}
|
||||
|
||||
return new EstimateResource($newEstimate);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\Estimate;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\SerialNumberService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ConvertEstimateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request, Estimate $estimate, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('create', Invoice::class);
|
||||
|
||||
$estimate->load(['items', 'items.taxes', 'customer', 'taxes']);
|
||||
|
||||
$invoice_date = Carbon::now();
|
||||
$due_date = null;
|
||||
|
||||
$dueDateEnabled = CompanySetting::getSetting(
|
||||
'invoice_set_due_date_automatically',
|
||||
$request->header('company')
|
||||
);
|
||||
|
||||
if ($dueDateEnabled === 'YES') {
|
||||
$dueDateDays = intval(CompanySetting::getSetting(
|
||||
'invoice_due_date_days',
|
||||
$request->header('company')
|
||||
));
|
||||
$due_date = Carbon::now()->addDays($dueDateDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel($invoice)
|
||||
->setCompany($estimate->company_id)
|
||||
->setCustomer($estimate->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$templateName = $estimate->getInvoiceTemplateName();
|
||||
|
||||
$exchange_rate = $estimate->exchange_rate;
|
||||
|
||||
$invoice = Invoice::create([
|
||||
'creator_id' => Auth::id(),
|
||||
'invoice_date' => $invoice_date->format('Y-m-d'),
|
||||
'due_date' => $due_date,
|
||||
'invoice_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $serial->getNextNumber(),
|
||||
'customer_id' => $estimate->customer_id,
|
||||
'company_id' => $request->header('company'),
|
||||
'template_name' => $templateName,
|
||||
'status' => Invoice::STATUS_DRAFT,
|
||||
'paid_status' => Invoice::STATUS_UNPAID,
|
||||
'sub_total' => $estimate->sub_total,
|
||||
'discount' => $estimate->discount,
|
||||
'discount_type' => $estimate->discount_type,
|
||||
'discount_val' => $estimate->discount_val,
|
||||
'total' => $estimate->total,
|
||||
'due_amount' => $estimate->total,
|
||||
'tax_per_item' => $estimate->tax_per_item,
|
||||
'discount_per_item' => $estimate->discount_per_item,
|
||||
'tax' => $estimate->tax,
|
||||
'notes' => $estimate->notes,
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_discount_val' => $estimate->discount_val * $exchange_rate,
|
||||
'base_sub_total' => $estimate->sub_total * $exchange_rate,
|
||||
'base_total' => $estimate->total * $exchange_rate,
|
||||
'base_tax' => $estimate->tax * $exchange_rate,
|
||||
'currency_id' => $estimate->currency_id,
|
||||
'sales_tax_type' => $estimate->sales_tax_type,
|
||||
'sales_tax_address_type' => $estimate->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$invoice->unique_hash = Hashids::connection(Invoice::class)->encode($invoice->id);
|
||||
$invoice->save();
|
||||
$invoiceItems = $estimate->items->toArray();
|
||||
|
||||
foreach ($invoiceItems as $invoiceItem) {
|
||||
$invoiceItem['company_id'] = $request->header('company');
|
||||
$invoiceItem['name'] = $invoiceItem['name'];
|
||||
$estimateItem['exchange_rate'] = $exchange_rate;
|
||||
$estimateItem['base_price'] = $invoiceItem['price'] * $exchange_rate;
|
||||
$estimateItem['base_discount_val'] = $invoiceItem['discount_val'] * $exchange_rate;
|
||||
$estimateItem['base_tax'] = $invoiceItem['tax'] * $exchange_rate;
|
||||
$estimateItem['base_total'] = $invoiceItem['total'] * $exchange_rate;
|
||||
|
||||
$item = $invoice->items()->create($invoiceItem);
|
||||
|
||||
if (array_key_exists('taxes', $invoiceItem) && $invoiceItem['taxes']) {
|
||||
foreach ($invoiceItem['taxes'] as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
|
||||
if ($tax['amount']) {
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($estimate->taxes) {
|
||||
foreach ($estimate->taxes->toArray() as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$tax['exchange_rate'] = $exchange_rate;
|
||||
$tax['base_amount'] = $tax['amount'] * $exchange_rate;
|
||||
$tax['currency_id'] = $estimate->currency_id;
|
||||
unset($tax['estimate_id']);
|
||||
|
||||
$invoice->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
|
||||
$estimate->checkForEstimateConvertAction();
|
||||
|
||||
$invoice = Invoice::find($invoice->id);
|
||||
|
||||
return new InvoiceResource($invoice);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,15 @@ namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\DeleteEstimatesRequest;
|
||||
use App\Http\Requests\EstimatesRequest;
|
||||
use App\Http\Requests\SendEstimatesRequest;
|
||||
use App\Http\Resources\EstimateResource;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Jobs\GenerateEstimatePdfJob;
|
||||
use App\Models\Estimate;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\EstimateService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class EstimatesController extends Controller
|
||||
{
|
||||
@@ -83,4 +87,55 @@ class EstimatesController extends Controller
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function send(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$response = $this->estimateService->send($estimate, $request->all());
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function sendPreview(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->estimateService->sendEstimateData($estimate, $request->all());
|
||||
$data['url'] = $estimate->estimatePdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.estimate', ['data' => $data]);
|
||||
}
|
||||
|
||||
public function clone(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('view', $estimate);
|
||||
$this->authorize('create', Estimate::class);
|
||||
|
||||
$newEstimate = $this->estimateService->clone($estimate);
|
||||
|
||||
return new EstimateResource($newEstimate);
|
||||
}
|
||||
|
||||
public function convertToInvoice(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('create', Invoice::class);
|
||||
|
||||
$invoice = $this->estimateService->convertToInvoice($estimate);
|
||||
|
||||
return new InvoiceResource($invoice);
|
||||
}
|
||||
|
||||
public function changeStatus(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$this->estimateService->changeStatus($estimate, $request->status);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SendEstimatesRequest;
|
||||
use App\Models\Estimate;
|
||||
use App\Services\EstimateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SendEstimateController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EstimateService $estimateService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$response = $this->estimateService->send($estimate, $request->all());
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SendEstimatesRequest;
|
||||
use App\Models\Estimate;
|
||||
use App\Services\EstimateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class SendEstimatePreviewController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EstimateService $estimateService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->estimateService->sendEstimateData($estimate, $request->all());
|
||||
$data['url'] = $estimate->estimatePdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.estimate', ['data' => $data]);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ChangeInvoiceStatusController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
if ($request->status == Invoice::STATUS_SENT) {
|
||||
$invoice->status = Invoice::STATUS_SENT;
|
||||
$invoice->sent = true;
|
||||
$invoice->save();
|
||||
} elseif ($request->status == Invoice::STATUS_COMPLETED) {
|
||||
$invoice->status = Invoice::STATUS_COMPLETED;
|
||||
$invoice->paid_status = Invoice::STATUS_PAID;
|
||||
$invoice->due_amount = 0;
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\SerialNumberService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CloneInvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('view', $invoice);
|
||||
$this->authorize('create', Invoice::class);
|
||||
|
||||
$date = Carbon::now();
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel($invoice)
|
||||
->setCompany($invoice->company_id)
|
||||
->setCustomer($invoice->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$due_date = null;
|
||||
$dueDateEnabled = CompanySetting::getSetting(
|
||||
'invoice_set_due_date_automatically',
|
||||
$request->header('company')
|
||||
);
|
||||
|
||||
if ($dueDateEnabled === 'YES') {
|
||||
$dueDateDays = intval(CompanySetting::getSetting(
|
||||
'invoice_due_date_days',
|
||||
$request->header('company')
|
||||
));
|
||||
$due_date = Carbon::now()->addDays($dueDateDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$exchange_rate = $invoice->exchange_rate;
|
||||
|
||||
$dateFormat = 'Y-m-d';
|
||||
$invoiceTimeEnabled = CompanySetting::getSetting(
|
||||
'invoice_use_time',
|
||||
$request->header('company')
|
||||
);
|
||||
|
||||
if ($invoiceTimeEnabled === 'YES') {
|
||||
$dateFormat .= ' H:i';
|
||||
}
|
||||
|
||||
$newInvoice = Invoice::create([
|
||||
'invoice_date' => $date->format('Y-m-d'),
|
||||
'due_date' => $due_date,
|
||||
'invoice_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $invoice->reference_number,
|
||||
'customer_id' => $invoice->customer_id,
|
||||
'company_id' => $request->header('company'),
|
||||
'template_name' => $invoice->template_name,
|
||||
'status' => Invoice::STATUS_DRAFT,
|
||||
'paid_status' => Invoice::STATUS_UNPAID,
|
||||
'sub_total' => $invoice->sub_total,
|
||||
'discount' => $invoice->discount,
|
||||
'discount_type' => $invoice->discount_type,
|
||||
'discount_val' => $invoice->discount_val,
|
||||
'total' => $invoice->total,
|
||||
'due_amount' => $invoice->total,
|
||||
'tax_per_item' => $invoice->tax_per_item,
|
||||
'discount_per_item' => $invoice->discount_per_item,
|
||||
'tax' => $invoice->tax,
|
||||
'notes' => $invoice->notes,
|
||||
'exchange_rate' => $exchange_rate,
|
||||
'base_total' => $invoice->total * $exchange_rate,
|
||||
'base_discount_val' => $invoice->discount_val * $exchange_rate,
|
||||
'base_sub_total' => $invoice->sub_total * $exchange_rate,
|
||||
'base_tax' => $invoice->tax * $exchange_rate,
|
||||
'base_due_amount' => $invoice->total * $exchange_rate,
|
||||
'currency_id' => $invoice->currency_id,
|
||||
'sales_tax_type' => $invoice->sales_tax_type,
|
||||
'sales_tax_address_type' => $invoice->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$newInvoice->unique_hash = Hashids::connection(Invoice::class)->encode($newInvoice->id);
|
||||
$newInvoice->save();
|
||||
$invoice->load('items.taxes');
|
||||
|
||||
$invoiceItems = $invoice->items->toArray();
|
||||
|
||||
foreach ($invoiceItems as $invoiceItem) {
|
||||
$invoiceItem['company_id'] = $request->header('company');
|
||||
$invoiceItem['name'] = $invoiceItem['name'];
|
||||
$invoiceItem['exchange_rate'] = $exchange_rate;
|
||||
$invoiceItem['base_price'] = $invoiceItem['price'] * $exchange_rate;
|
||||
$invoiceItem['base_discount_val'] = $invoiceItem['discount_val'] * $exchange_rate;
|
||||
$invoiceItem['base_tax'] = $invoiceItem['tax'] * $exchange_rate;
|
||||
$invoiceItem['base_total'] = $invoiceItem['total'] * $exchange_rate;
|
||||
|
||||
$item = $newInvoice->items()->create($invoiceItem);
|
||||
|
||||
if (array_key_exists('taxes', $invoiceItem) && $invoiceItem['taxes']) {
|
||||
foreach ($invoiceItem['taxes'] as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
|
||||
if ($tax['amount']) {
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($invoice->taxes) {
|
||||
foreach ($invoice->taxes->toArray() as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$newInvoice->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
|
||||
if ($invoice->fields()->exists()) {
|
||||
$customFields = [];
|
||||
|
||||
foreach ($invoice->fields as $data) {
|
||||
$customFields[] = [
|
||||
'id' => $data->custom_field_id,
|
||||
'value' => $data->defaultAnswer,
|
||||
];
|
||||
}
|
||||
|
||||
$newInvoice->addCustomFields($customFields);
|
||||
}
|
||||
|
||||
return new InvoiceResource($newInvoice);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@ namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\DeleteInvoiceRequest;
|
||||
use App\Http\Requests\SendInvoiceRequest;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Jobs\GenerateInvoicePdfJob;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\InvoiceService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class InvoicesController extends Controller
|
||||
{
|
||||
@@ -111,4 +113,48 @@ class InvoicesController extends Controller
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function send(SendInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
$this->invoiceService->send($invoice, $request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendPreview(SendInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->invoiceService->sendInvoiceData($invoice, $request->all());
|
||||
$data['url'] = $invoice->invoicePdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.invoice', ['data' => $data]);
|
||||
}
|
||||
|
||||
public function clone(Request $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('view', $invoice);
|
||||
$this->authorize('create', Invoice::class);
|
||||
|
||||
$newInvoice = $this->invoiceService->clone($invoice);
|
||||
|
||||
return new InvoiceResource($newInvoice);
|
||||
}
|
||||
|
||||
public function changeStatus(Request $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
$this->invoiceService->changeStatus($invoice, $request->status);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SendInvoiceRequest;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\InvoiceService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SendInvoiceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvoiceService $invoiceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(SendInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
$this->invoiceService->send($invoice, $request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SendInvoiceRequest;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\InvoiceService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class SendInvoicePreviewController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvoiceService $invoiceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(SendInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$this->authorize('send invoice', $invoice);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->invoiceService->sendInvoiceData($invoice, $request->all());
|
||||
$data['url'] = $invoice->invoicePdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.invoice', ['data' => $data]);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,13 @@ namespace App\Http\Controllers\V1\Admin\Payment;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\DeletePaymentsRequest;
|
||||
use App\Http\Requests\PaymentRequest;
|
||||
use App\Http\Requests\SendPaymentRequest;
|
||||
use App\Http\Resources\PaymentResource;
|
||||
use App\Models\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class PaymentsController extends Controller
|
||||
{
|
||||
@@ -88,4 +90,25 @@ class PaymentsController extends Controller
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function send(SendPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
$this->authorize('send payment', $payment);
|
||||
|
||||
$response = $this->paymentService->send($payment, $request->all());
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function sendPreview(Request $request, Payment $payment)
|
||||
{
|
||||
$this->authorize('send payment', $payment);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->paymentService->sendPaymentData($payment, $request->all());
|
||||
$data['url'] = $payment->paymentPdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.payment', ['data' => $data]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Payment;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\SendPaymentRequest;
|
||||
use App\Models\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SendPaymentController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PaymentService $paymentService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(SendPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
$this->authorize('send payment', $payment);
|
||||
|
||||
$response = $this->paymentService->send($payment, $request->all());
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Payment;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class SendPaymentPreviewController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PaymentService $paymentService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request, Payment $payment)
|
||||
{
|
||||
$this->authorize('send payment', $payment);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->paymentService->sendPaymentData($payment, $request->all());
|
||||
$data['url'] = $payment->paymentPdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.payment', ['data' => $data]);
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,11 @@ use App\Models\CompanySetting;
|
||||
use App\Models\CustomField;
|
||||
use App\Models\Estimate;
|
||||
use App\Models\ExchangeRateLog;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\Pdf\PdfTemplateUtils;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EstimateService
|
||||
{
|
||||
@@ -199,4 +202,169 @@ class EstimateService
|
||||
|
||||
return Pdf::loadView($templatePath);
|
||||
}
|
||||
|
||||
public function clone(Estimate $estimate): Estimate
|
||||
{
|
||||
$date = Carbon::now();
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel($estimate)
|
||||
->setCompany($estimate->company_id)
|
||||
->setCustomer($estimate->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$expiryDate = null;
|
||||
$expiryEnabled = CompanySetting::getSetting(
|
||||
'estimate_set_expiry_date_automatically',
|
||||
$estimate->company_id
|
||||
);
|
||||
|
||||
if ($expiryEnabled === 'YES') {
|
||||
$expiryDays = intval(CompanySetting::getSetting(
|
||||
'estimate_expiry_date_days',
|
||||
$estimate->company_id
|
||||
));
|
||||
$expiryDate = Carbon::now()->addDays($expiryDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$exchangeRate = $estimate->exchange_rate;
|
||||
|
||||
$newEstimate = Estimate::create([
|
||||
'estimate_date' => $date->format('Y-m-d'),
|
||||
'expiry_date' => $expiryDate,
|
||||
'estimate_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $estimate->reference_number,
|
||||
'customer_id' => $estimate->customer_id,
|
||||
'company_id' => $estimate->company_id,
|
||||
'template_name' => $estimate->template_name,
|
||||
'status' => Estimate::STATUS_DRAFT,
|
||||
'sub_total' => $estimate->sub_total,
|
||||
'discount' => $estimate->discount,
|
||||
'discount_type' => $estimate->discount_type,
|
||||
'discount_val' => $estimate->discount_val,
|
||||
'total' => $estimate->total,
|
||||
'due_amount' => $estimate->total,
|
||||
'tax_per_item' => $estimate->tax_per_item,
|
||||
'discount_per_item' => $estimate->discount_per_item,
|
||||
'tax' => $estimate->tax,
|
||||
'notes' => $estimate->notes,
|
||||
'exchange_rate' => $exchangeRate,
|
||||
'base_total' => $estimate->total * $exchangeRate,
|
||||
'base_discount_val' => $estimate->discount_val * $exchangeRate,
|
||||
'base_sub_total' => $estimate->sub_total * $exchangeRate,
|
||||
'base_tax' => $estimate->tax * $exchangeRate,
|
||||
'base_due_amount' => $estimate->total * $exchangeRate,
|
||||
'currency_id' => $estimate->currency_id,
|
||||
'sales_tax_type' => $estimate->sales_tax_type,
|
||||
'sales_tax_address_type' => $estimate->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$newEstimate->unique_hash = Hashids::connection(Estimate::class)->encode($newEstimate->id);
|
||||
$newEstimate->save();
|
||||
|
||||
$estimate->load('items.taxes');
|
||||
$this->documentItemService->createItems($newEstimate, $estimate->items->toArray());
|
||||
|
||||
if ($estimate->taxes) {
|
||||
$this->documentItemService->createTaxes($newEstimate, $estimate->taxes->toArray());
|
||||
}
|
||||
|
||||
if ($estimate->fields()->exists()) {
|
||||
$customFields = [];
|
||||
|
||||
foreach ($estimate->fields as $data) {
|
||||
$customFields[] = [
|
||||
'id' => $data->custom_field_id,
|
||||
'value' => $data->defaultAnswer,
|
||||
];
|
||||
}
|
||||
|
||||
$newEstimate->addCustomFields($customFields);
|
||||
}
|
||||
|
||||
return $newEstimate;
|
||||
}
|
||||
|
||||
public function convertToInvoice(Estimate $estimate): Invoice
|
||||
{
|
||||
$estimate->load(['items', 'items.taxes', 'customer', 'taxes']);
|
||||
|
||||
$invoiceDate = Carbon::now();
|
||||
$dueDate = null;
|
||||
|
||||
$dueDateEnabled = CompanySetting::getSetting(
|
||||
'invoice_set_due_date_automatically',
|
||||
$estimate->company_id
|
||||
);
|
||||
|
||||
if ($dueDateEnabled === 'YES') {
|
||||
$dueDateDays = intval(CompanySetting::getSetting(
|
||||
'invoice_due_date_days',
|
||||
$estimate->company_id
|
||||
));
|
||||
$dueDate = Carbon::now()->addDays($dueDateDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel(new Invoice)
|
||||
->setCompany($estimate->company_id)
|
||||
->setCustomer($estimate->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$templateName = $estimate->getInvoiceTemplateName();
|
||||
$exchangeRate = $estimate->exchange_rate;
|
||||
|
||||
$invoice = Invoice::create([
|
||||
'creator_id' => Auth::id(),
|
||||
'invoice_date' => $invoiceDate->format('Y-m-d'),
|
||||
'due_date' => $dueDate,
|
||||
'invoice_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $serial->getNextNumber(),
|
||||
'customer_id' => $estimate->customer_id,
|
||||
'company_id' => $estimate->company_id,
|
||||
'template_name' => $templateName,
|
||||
'status' => Invoice::STATUS_DRAFT,
|
||||
'paid_status' => Invoice::STATUS_UNPAID,
|
||||
'sub_total' => $estimate->sub_total,
|
||||
'discount' => $estimate->discount,
|
||||
'discount_type' => $estimate->discount_type,
|
||||
'discount_val' => $estimate->discount_val,
|
||||
'total' => $estimate->total,
|
||||
'due_amount' => $estimate->total,
|
||||
'tax_per_item' => $estimate->tax_per_item,
|
||||
'discount_per_item' => $estimate->discount_per_item,
|
||||
'tax' => $estimate->tax,
|
||||
'notes' => $estimate->notes,
|
||||
'exchange_rate' => $exchangeRate,
|
||||
'base_discount_val' => $estimate->discount_val * $exchangeRate,
|
||||
'base_sub_total' => $estimate->sub_total * $exchangeRate,
|
||||
'base_total' => $estimate->total * $exchangeRate,
|
||||
'base_tax' => $estimate->tax * $exchangeRate,
|
||||
'currency_id' => $estimate->currency_id,
|
||||
'sales_tax_type' => $estimate->sales_tax_type,
|
||||
'sales_tax_address_type' => $estimate->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$invoice->unique_hash = Hashids::connection(Invoice::class)->encode($invoice->id);
|
||||
$invoice->save();
|
||||
|
||||
$this->documentItemService->createItems($invoice, $estimate->items->toArray());
|
||||
|
||||
if ($estimate->taxes) {
|
||||
$this->documentItemService->createTaxes($invoice, $estimate->taxes->toArray());
|
||||
}
|
||||
|
||||
$estimate->checkForEstimateConvertAction();
|
||||
|
||||
return Invoice::find($invoice->id);
|
||||
}
|
||||
|
||||
public function changeStatus(Estimate $estimate, string $status): void
|
||||
{
|
||||
$estimate->update(['status' => $status]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Models\CustomField;
|
||||
use App\Models\ExchangeRateLog;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\Pdf\PdfTemplateUtils;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@@ -264,4 +265,103 @@ class InvoiceService
|
||||
|
||||
return Pdf::loadView($templatePath);
|
||||
}
|
||||
|
||||
public function clone(Invoice $invoice): Invoice
|
||||
{
|
||||
$date = Carbon::now();
|
||||
|
||||
$serial = (new SerialNumberService)
|
||||
->setModel($invoice)
|
||||
->setCompany($invoice->company_id)
|
||||
->setCustomer($invoice->customer_id)
|
||||
->setNextNumbers();
|
||||
|
||||
$dueDate = null;
|
||||
$dueDateEnabled = CompanySetting::getSetting(
|
||||
'invoice_set_due_date_automatically',
|
||||
$invoice->company_id
|
||||
);
|
||||
|
||||
if ($dueDateEnabled === 'YES') {
|
||||
$dueDateDays = intval(CompanySetting::getSetting(
|
||||
'invoice_due_date_days',
|
||||
$invoice->company_id
|
||||
));
|
||||
$dueDate = Carbon::now()->addDays($dueDateDays)->format('Y-m-d');
|
||||
}
|
||||
|
||||
$exchangeRate = $invoice->exchange_rate;
|
||||
|
||||
$newInvoice = Invoice::create([
|
||||
'invoice_date' => $date->format('Y-m-d'),
|
||||
'due_date' => $dueDate,
|
||||
'invoice_number' => $serial->getNextNumber(),
|
||||
'sequence_number' => $serial->nextSequenceNumber,
|
||||
'customer_sequence_number' => $serial->nextCustomerSequenceNumber,
|
||||
'reference_number' => $invoice->reference_number,
|
||||
'customer_id' => $invoice->customer_id,
|
||||
'company_id' => $invoice->company_id,
|
||||
'template_name' => $invoice->template_name,
|
||||
'status' => Invoice::STATUS_DRAFT,
|
||||
'paid_status' => Invoice::STATUS_UNPAID,
|
||||
'sub_total' => $invoice->sub_total,
|
||||
'discount' => $invoice->discount,
|
||||
'discount_type' => $invoice->discount_type,
|
||||
'discount_val' => $invoice->discount_val,
|
||||
'total' => $invoice->total,
|
||||
'due_amount' => $invoice->total,
|
||||
'tax_per_item' => $invoice->tax_per_item,
|
||||
'discount_per_item' => $invoice->discount_per_item,
|
||||
'tax' => $invoice->tax,
|
||||
'notes' => $invoice->notes,
|
||||
'exchange_rate' => $exchangeRate,
|
||||
'base_total' => $invoice->total * $exchangeRate,
|
||||
'base_discount_val' => $invoice->discount_val * $exchangeRate,
|
||||
'base_sub_total' => $invoice->sub_total * $exchangeRate,
|
||||
'base_tax' => $invoice->tax * $exchangeRate,
|
||||
'base_due_amount' => $invoice->total * $exchangeRate,
|
||||
'currency_id' => $invoice->currency_id,
|
||||
'sales_tax_type' => $invoice->sales_tax_type,
|
||||
'sales_tax_address_type' => $invoice->sales_tax_address_type,
|
||||
]);
|
||||
|
||||
$newInvoice->unique_hash = Hashids::connection(Invoice::class)->encode($newInvoice->id);
|
||||
$newInvoice->save();
|
||||
|
||||
$invoice->load('items.taxes');
|
||||
$this->documentItemService->createItems($newInvoice, $invoice->items->toArray());
|
||||
|
||||
if ($invoice->taxes) {
|
||||
$this->documentItemService->createTaxes($newInvoice, $invoice->taxes->toArray());
|
||||
}
|
||||
|
||||
if ($invoice->fields()->exists()) {
|
||||
$customFields = [];
|
||||
|
||||
foreach ($invoice->fields as $data) {
|
||||
$customFields[] = [
|
||||
'id' => $data->custom_field_id,
|
||||
'value' => $data->defaultAnswer,
|
||||
];
|
||||
}
|
||||
|
||||
$newInvoice->addCustomFields($customFields);
|
||||
}
|
||||
|
||||
return $newInvoice;
|
||||
}
|
||||
|
||||
public function changeStatus(Invoice $invoice, string $status): void
|
||||
{
|
||||
if ($status == Invoice::STATUS_SENT) {
|
||||
$invoice->status = Invoice::STATUS_SENT;
|
||||
$invoice->sent = true;
|
||||
$invoice->save();
|
||||
} elseif ($status == Invoice::STATUS_COMPLETED) {
|
||||
$invoice->status = Invoice::STATUS_COMPLETED;
|
||||
$invoice->paid_status = Invoice::STATUS_PAID;
|
||||
$invoice->due_amount = 0;
|
||||
$invoice->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,8 @@ use App\Http\Controllers\V1\Admin\Customer\CustomersController;
|
||||
use App\Http\Controllers\V1\Admin\Customer\CustomerStatsController;
|
||||
use App\Http\Controllers\V1\Admin\CustomField\CustomFieldsController;
|
||||
use App\Http\Controllers\V1\Admin\Dashboard\DashboardController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\ChangeEstimateStatusController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\CloneEstimateController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\ConvertEstimateController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\EstimatesController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\EstimateTemplatesController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\SendEstimateController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\SendEstimatePreviewController;
|
||||
use App\Http\Controllers\V1\Admin\ExchangeRate\ExchangeRateProviderController;
|
||||
use App\Http\Controllers\V1\Admin\ExchangeRate\GetActiveProviderController;
|
||||
use App\Http\Controllers\V1\Admin\ExchangeRate\GetExchangeRateController;
|
||||
@@ -38,19 +33,13 @@ use App\Http\Controllers\V1\Admin\General\SearchController;
|
||||
use App\Http\Controllers\V1\Admin\General\SearchUsersController;
|
||||
use App\Http\Controllers\V1\Admin\General\TimeFormatsController;
|
||||
use App\Http\Controllers\V1\Admin\General\TimezonesController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\ChangeInvoiceStatusController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\CloneInvoiceController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\InvoicesController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\InvoiceTemplatesController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\SendInvoiceController;
|
||||
use App\Http\Controllers\V1\Admin\Invoice\SendInvoicePreviewController;
|
||||
use App\Http\Controllers\V1\Admin\Item\ItemsController;
|
||||
use App\Http\Controllers\V1\Admin\Item\UnitsController;
|
||||
use App\Http\Controllers\V1\Admin\Mobile\AuthController;
|
||||
use App\Http\Controllers\V1\Admin\Payment\PaymentMethodsController;
|
||||
use App\Http\Controllers\V1\Admin\Payment\PaymentsController;
|
||||
use App\Http\Controllers\V1\Admin\Payment\SendPaymentController;
|
||||
use App\Http\Controllers\V1\Admin\Payment\SendPaymentPreviewController;
|
||||
use App\Http\Controllers\V1\Admin\RecurringInvoice\RecurringInvoiceController;
|
||||
use App\Http\Controllers\V1\Admin\RecurringInvoice\RecurringInvoiceFrequencyController;
|
||||
use App\Http\Controllers\V1\Admin\Role\AbilitiesController;
|
||||
@@ -278,13 +267,13 @@ Route::prefix('/v1')->group(function () {
|
||||
// Invoices
|
||||
// -------------------------------------------------
|
||||
|
||||
Route::get('/invoices/{invoice}/send/preview', SendInvoicePreviewController::class);
|
||||
Route::get('/invoices/{invoice}/send/preview', [InvoicesController::class, 'sendPreview']);
|
||||
|
||||
Route::post('/invoices/{invoice}/send', SendInvoiceController::class);
|
||||
Route::post('/invoices/{invoice}/send', [InvoicesController::class, 'send']);
|
||||
|
||||
Route::post('/invoices/{invoice}/clone', CloneInvoiceController::class);
|
||||
Route::post('/invoices/{invoice}/clone', [InvoicesController::class, 'clone']);
|
||||
|
||||
Route::post('/invoices/{invoice}/status', ChangeInvoiceStatusController::class);
|
||||
Route::post('/invoices/{invoice}/status', [InvoicesController::class, 'changeStatus']);
|
||||
|
||||
Route::post('/invoices/delete', [InvoicesController::class, 'delete']);
|
||||
|
||||
@@ -304,15 +293,15 @@ Route::prefix('/v1')->group(function () {
|
||||
// Estimates
|
||||
// -------------------------------------------------
|
||||
|
||||
Route::get('/estimates/{estimate}/send/preview', SendEstimatePreviewController::class);
|
||||
Route::get('/estimates/{estimate}/send/preview', [EstimatesController::class, 'sendPreview']);
|
||||
|
||||
Route::post('/estimates/{estimate}/send', SendEstimateController::class);
|
||||
Route::post('/estimates/{estimate}/send', [EstimatesController::class, 'send']);
|
||||
|
||||
Route::post('/estimates/{estimate}/clone', CloneEstimateController::class);
|
||||
Route::post('/estimates/{estimate}/clone', [EstimatesController::class, 'clone']);
|
||||
|
||||
Route::post('/estimates/{estimate}/status', ChangeEstimateStatusController::class);
|
||||
Route::post('/estimates/{estimate}/status', [EstimatesController::class, 'changeStatus']);
|
||||
|
||||
Route::post('/estimates/{estimate}/convert-to-invoice', ConvertEstimateController::class);
|
||||
Route::post('/estimates/{estimate}/convert-to-invoice', [EstimatesController::class, 'convertToInvoice']);
|
||||
|
||||
Route::get('/estimates/templates', EstimateTemplatesController::class);
|
||||
|
||||
@@ -336,9 +325,9 @@ Route::prefix('/v1')->group(function () {
|
||||
// Payments
|
||||
// ----------------------------------
|
||||
|
||||
Route::get('/payments/{payment}/send/preview', SendPaymentPreviewController::class);
|
||||
Route::get('/payments/{payment}/send/preview', [PaymentsController::class, 'sendPreview']);
|
||||
|
||||
Route::post('/payments/{payment}/send', SendPaymentController::class);
|
||||
Route::post('/payments/{payment}/send', [PaymentsController::class, 'send']);
|
||||
|
||||
Route::post('/payments/delete', [PaymentsController::class, 'delete']);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\V1\Admin\Estimate\EstimatesController;
|
||||
use App\Http\Controllers\V1\Admin\Estimate\SendEstimateController;
|
||||
use App\Http\Requests\DeleteEstimatesRequest;
|
||||
use App\Http\Requests\EstimatesRequest;
|
||||
use App\Http\Requests\SendEstimatesRequest;
|
||||
@@ -156,8 +155,8 @@ test('search estimates', function () {
|
||||
|
||||
test('send estimate using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
SendEstimateController::class,
|
||||
'__invoke',
|
||||
EstimatesController::class,
|
||||
'send',
|
||||
SendEstimatesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user