orders
Nisse Lommerde 3 weeks ago
parent 562e499d12
commit 7e2a22e016

@ -6,11 +6,11 @@ use Filament\Support\Contracts\HasLabel;
enum OrderType: string implements HasLabel
{
case EMBROIDERY = 'Embroidery';
case SCREEN = 'Screen printing';
case DTG = 'Direct-to-garment';
case VINYL = 'Vinyl';
case MISC = 'Misc';
case EMB = 'Embroidery';
case SCP = 'Screen printing';
case DTG = 'Direct-to-garment';
case VINYL = 'Vinyl';
case MISC = 'Misc';
public function getLabel(): ?string
{

@ -4,7 +4,6 @@ namespace App\Filament\Resources\InvoiceResource\Pages;
use App\Filament\Resources\InvoiceResource;
use App\Models\Invoice;
use App\Models\Order;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
@ -15,7 +14,6 @@ class CreateInvoice extends CreateRecord
protected function handleRecordCreation(array $data): Model
{
$invoice = Invoice::create($data);
$invoice->orders()->saveMany(Order::findMany($data['orders']));
$invoice->calculateTotals();
return $invoice;

@ -3,7 +3,9 @@
namespace App\Filament\Resources\InvoiceResource\Pages;
use App\Filament\Resources\InvoiceResource;
use App\Models\Invoice;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;
class EditInvoice extends EditRecord
@ -13,7 +15,12 @@ class EditInvoice extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Action::make('print')
->icon('lucide-printer')
->url(fn (Invoice $record) => route('invoice.pdf', $record))
->openUrlInNewTab(),
Actions\DeleteAction::make()
->icon('lucide-trash-2'),
];
}
}

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers;
use App\Models\Invoice;
use Spatie\Browsershot\Browsershot;
use Spatie\LaravelPdf\Facades\Pdf;
class InvoiceController extends Controller
{
public function pdf(int $id)
{
$invoice = Invoice::find($id);
$url = strtolower('invoice-'.$invoice->internal_id.'.pdf');
Pdf::view('pdf.invoice', ['invoice' => $invoice])
->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->noSandbox();
})
->margins(8, 8, 15, 8)
->footerView('pdf.invoice-footer', ['invoice' => $invoice])
->save($url);
return redirect($url);
}
}

@ -124,6 +124,7 @@ class OrderController extends Controller
public function pdf(int $id)
{
$order = Order::find($id);
$url = strtolower('order-'.$order->internal_po.'.pdf');
Pdf::view('pdf.order', ['order' => $order])
->withBrowsershot(function (Browsershot $browsershot) {
@ -131,8 +132,8 @@ class OrderController extends Controller
})
->margins(8, 8, 15, 8)
->footerView('pdf.order-footer', ['order' => $order])
->save('order.pdf');
->save($url);
return redirect('order.pdf');
return redirect($url);
}
}

@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\OrderStatus;
use App\Enums\OrderType;
use Database\Factories\OrderFactory;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;
@ -13,8 +14,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Spatie\Browsershot\Browsershot;
use Spatie\LaravelPdf\Facades\Pdf;
class Order extends Model
{
@ -49,7 +48,8 @@ class Order extends Model
];
protected $casts = [
'status' => OrderStatus::class,
'status' => OrderStatus::class,
'order_type' => OrderType::class,
];
public static function boot(): void
@ -112,18 +112,18 @@ class Order extends Model
return false;
}
public function generatePdf(): \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
{
Pdf::view('pdf.order', ['order' => $this])
->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->noSandbox();
})
->margins(8, 8, 15, 8)
->footerView('pdf.order-footer', ['order' => $this])
->save('order.pdf');
return redirect('order.pdf');
}
// public function generatePdf(): \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
// {
// Pdf::view('pdf.order', ['order' => $this])
// ->withBrowsershot(function (Browsershot $browsershot) {
// $browsershot->noSandbox();
// })
// ->margins(8, 8, 15, 8)
// ->footerView('pdf.order-footer', ['order' => $this])
// ->save('order.pdf');
//
// return redirect('order.pdf');
// }
/**
* @param Builder<Order> $query

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,10 @@
<style>
* {
font-size: 12px;
margin: 10px 5px;
}
</style>
<footer>
{{$invoice->internal_id}}, page @pageNumber of @totalPages
</footer>'

@ -0,0 +1,88 @@
@extends('layouts.pdf')
<div class="container-fluid ">
<div class="fw-bold">
TOP NOTCH EMBROIDERY & DIGITIZING LTD
</div>
<div>
108-618 EAST KENT AVE. SOUTH <br>
VANCOUVER BC <br>
(604) 871-9991 <br>
info@sewtopnotch.com <br>
GST# 846025062RT0001 <br>
</div>
<div class="fs-3">
INVOICE
</div>
<div class="fw-bold">
BILL TO
</div>
<div>
{{$invoice->customer->company_name}} <br>
{{$invoice->customer->billing_address}} <br>
</div>
{{-- split right--}}
<div>
<span class="fw-bold">
INVOICE#
</span>
{{$invoice->internal_id}}
</div>
<div>
<span class="fw-bold">
DATE
</span>
{{$invoice->date}}
</div>
<div>
<span class="fw-bold">
DUE DATE
</span>
{{$invoice->due_date}}
</div>
<div>
<span class="fw-bold">
TERMS
</span>
</div>
<hr>
<table>
<tr>
<th>WO#</th>
<th>PO#</th>
<th>PRODUCT SERVICES</th>
<th>QTY</th>
<th>RATE</th>
<th>AMOUNT</th>
</tr>
@foreach($invoice->productServices as $service)
<tr>
<td>
{{$service->order->internal_po}}
</td>
<td>
{{$service->order->customer_po}}
</td>
<td>
{{$service->order->order_type->name}} <br>
{{$service->service_details}}
</td>
<td>
{{$service->amount}}
</td>
<td>
{{$service->amount_price}}
</td>
<td>
${{$service->price}}
</td>
</tr>
@endforeach
</table>
</div>

@ -12,7 +12,7 @@
<div class="col-4 text-center">
<div class="bg-info text-white">
<div class="fs-3 fw-bold">{{$order->order_type}}</div>
<div class="fs-4 fw-bold">{{$order->order_type->name}}</div>
</div>
</div>

@ -3,6 +3,7 @@
use App\Http\Controllers\ContactController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\ManagementController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\OrderProductController;
@ -38,3 +39,5 @@ Route::resource('shipping-entries', ShippingEntryController::class);
Route::resource('orders', OrderController::class);
Route::get('orders/{order}/pdf', [OrderController::class, 'pdf'])->name('orders.pdf');
Route::get('invoices/{invoice}/pdf', [InvoiceController::class, 'pdf'])->name('invoice.pdf');

Loading…
Cancel
Save