mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Edit invoice
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use App\Http\Resources\Oasis\OasisInvoiceResource;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Storage;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -20,7 +22,7 @@ use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_all_regular_invoices()
|
||||
{
|
||||
@@ -31,7 +33,7 @@ class InvoiceController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_all_advance_invoices()
|
||||
{
|
||||
@@ -41,11 +43,23 @@ class InvoiceController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function get_single_invoice(Invoice $invoice)
|
||||
{
|
||||
return response(
|
||||
new OasisInvoiceResource($invoice),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
public function get_invoice(Invoice $invoice)
|
||||
public function download_invoice(Invoice $invoice)
|
||||
{
|
||||
if (! Storage::exists(invoice_path($invoice))) {
|
||||
abort(404, 'Not Found');
|
||||
@@ -55,7 +69,7 @@ class InvoiceController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
@@ -130,6 +144,51 @@ class InvoiceController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store and generate new invoice
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Invoice $invoice
|
||||
* @return Application|ResponseFactory|Response
|
||||
*/
|
||||
public function update(StoreInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$invoice->update([
|
||||
'invoice_number' => $request->invoice_number,
|
||||
'variable_number' => $request->variable_number,
|
||||
'delivery_at' => $request->delivery_at,
|
||||
'discount_type' => $request->discount_type ?? null,
|
||||
'discount_rate' => $request->discount_rate ?? null,
|
||||
'items' => json_decode($request->items),
|
||||
]);
|
||||
|
||||
Storage::delete(invoice_path($invoice));
|
||||
|
||||
// Generate PDF
|
||||
\PDF::loadView('oasis.invoices.invoice', [
|
||||
'invoice' => Invoice::find($invoice->id),
|
||||
'user' => $user,
|
||||
])
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("app/files/{$user->id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
if ($request->send_invoice && $invoice->client['email']) {
|
||||
Notification::route('mail', $invoice->client['email'])->notify(
|
||||
new InvoiceDeliveryNotification($user, $invoice)
|
||||
);
|
||||
}
|
||||
|
||||
return response(
|
||||
'Done',
|
||||
204
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @throws \Exception
|
||||
|
||||
@@ -23,10 +23,10 @@ class StoreInvoiceRequest extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'invoice_type' => 'required|string',
|
||||
'invoice_type' => 'sometimes|string',
|
||||
'invoice_number' => 'required|string',
|
||||
'variable_number' => 'required|string',
|
||||
'client' => 'required',
|
||||
'client' => 'sometimes|required',
|
||||
'items' => 'required|string',
|
||||
'discount_type' => 'sometimes|string',
|
||||
'discount_rate' => 'sometimes|integer',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Oasis;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@@ -15,15 +16,22 @@ class OasisInvoiceResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'type' => 'invoice',
|
||||
'id' => $this->id,
|
||||
'type' => 'invoice',
|
||||
'attributes' => [
|
||||
'name' => $this->client['name'] . ' ' . format_to_currency($this->total_net, $this->currency),
|
||||
'invoiceNumber' => $this->invoice_number,
|
||||
'total' => format_to_currency($this->total_net, $this->currency),
|
||||
'file_url' => "/oasis/invoice/$this->id",
|
||||
'mimetype' => 'pdf',
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
'name' => $this->client['name'] . ' ' . format_to_currency($this->total_net, $this->currency),
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'variable_number' => $this->variable_number,
|
||||
'invoice_type' => $this->invoice_type,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
'items' => $this->items,
|
||||
'discount_type' => $this->discount_type,
|
||||
'discount_rate' => $this->discount_rate,
|
||||
'client' => $this->client,
|
||||
'total' => format_to_currency($this->total_net, $this->currency),
|
||||
'file_url' => "/oasis/invoice/$this->id",
|
||||
'mimetype' => 'pdf',
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -17,10 +17,10 @@ class OasisViewInvoiceResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'client_id' => $this->client_id,
|
||||
'name' => $this->client['name'] . ' ' . format_to_currency($this->total_net, $this->currency),
|
||||
'invoiceNumber' => $this->invoice_number,
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'total' => format_to_currency($this->total_net, $this->currency),
|
||||
'file_url' => "/oasis/invoice/$this->id",
|
||||
'clientName' => $this->client['name'],
|
||||
'client_name' => $this->client['name'],
|
||||
'mimetype' => 'pdf',
|
||||
'type' => 'invoice',
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
|
||||
@@ -161,7 +161,7 @@ function invoice_total($invoice)
|
||||
foreach ($invoice['items'] as $item) {
|
||||
$total_without_tax = $item['amount'] * $item['price'];
|
||||
|
||||
if ($item['tax_rate']) {
|
||||
if ($invoice['user']['ic_dph'] && $item['tax_rate']) {
|
||||
$total_without_tax += $total_without_tax * ($item['tax_rate'] / 100);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user