Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
6 / 8 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| InvoiceController | |
75.00% |
6 / 8 |
|
66.67% |
2 / 3 |
3.14 | |
0.00% |
0 / 1 |
| download | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| view | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| data | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\Order; |
| 6 | use App\Service\OrderService; |
| 7 | use Barryvdh\DomPDF\Facade\Pdf; |
| 8 | |
| 9 | /** |
| 10 | * Customer-facing invoice PDF for a storefront checkout Order (Phase 8) — |
| 11 | * separate from PdfController, which handles the older POS-side |
| 12 | * Purchase/Sale invoices. Reused by both the admin order workspace and the |
| 13 | * customer's own order page; each caller is responsible for its own |
| 14 | * authorization before calling these (admin routes sit behind the admin |
| 15 | * middleware group already; the customer route checks order ownership). |
| 16 | */ |
| 17 | class InvoiceController extends Controller |
| 18 | { |
| 19 | public function download(Order $order) |
| 20 | { |
| 21 | $pdf = Pdf::loadView('website.invoice', $this->data($order)); |
| 22 | |
| 23 | return $pdf->download($order->invoiceNumber() . '.pdf'); |
| 24 | } |
| 25 | |
| 26 | /** Same document, opened inline in the browser instead of downloaded. */ |
| 27 | public function view(Order $order) |
| 28 | { |
| 29 | $pdf = Pdf::loadView('website.invoice', $this->data($order)); |
| 30 | |
| 31 | return $pdf->stream($order->invoiceNumber() . '.pdf'); |
| 32 | } |
| 33 | |
| 34 | private function data(Order $order): array |
| 35 | { |
| 36 | return [ |
| 37 | 'order' => $order->load('customer'), |
| 38 | 'details' => OrderService::getDetails($order->id), |
| 39 | ]; |
| 40 | } |
| 41 | } |