render invoice in pdf
This commit is contained in:
84
app/Repositories/Shop/InvoicePDF.php
Normal file
84
app/Repositories/Shop/InvoicePDF.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user