Files
opensem/app/Repositories/Shop/InvoicePDF.php
2024-01-07 23:16:29 +01:00

85 lines
2.5 KiB
PHP

<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Invoice;
use LaravelDaily\Invoices\Invoice;
use LaravelDaily\Invoices\Classes\Party;
use LaravelDaily\Invoices\Classes\InvoiceItem;
class InvoicePDF
{
public static function get($id)
{
$invoice = Invoices::getFull($id);
$client = new Party([
'name' => 'Roosevelt Lloyd',
'phone' => '(520) 318-9486',
'custom_fields' => [
'note' => 'IDDQD',
'business id' => '365#GG',
],
]);
$customer = new Party([
'name' => 'Ashley Medina',
'address' => 'The Green Street 12',
'code' => '#22663214',
'custom_fields' => [
'order number' => '> 654321 <',
],
]);
$items = self::makeItems($order->details);
$notes = [
'your multiline',
'additional notes',
'in regards of delivery or something else',
];
$notes = implode("<br>", $notes);
$invoice = Invoice::make('receipt')
->series('BIG')
// ability to include translated invoice status
// in case it was paid
->status(__('invoices::invoice.paid'))
->sequence(667)
->serialNumberFormat('{SEQUENCE}/{SERIES}')
->seller($client)
->buyer($customer)
->date(now()->subWeeks(3))
->dateFormat('m/d/Y')
->payUntilDays(14)
->currencySymbol('$')
->currencyCode('USD')
->currencyFormat('{SYMBOL}{VALUE}')
->currencyThousandsSeparator('.')
->currencyDecimalPoint(',')
->filename($client->name . ' ' . $customer->name)
->addItems($items)
->notes($notes)
->logo(public_path('vendor/invoices/sample-logo.png'))
// You can additionally save generated invoice to configured disk
->save('public');
$link = $invoice->url();
// Then send email to party with link
// And return invoice itself to browser or have a different view
return $invoice->stream();
}
public static function makeItems($details)
{
$items = [];
foreach ($details as $detail) {
$items[] = InvoiceItem::make($detail->name)->pricePerUnit($detail->price)->quantity($detail->quantity);
}
return $items;
}
}