render invoice in pdf
This commit is contained in:
@@ -23,6 +23,7 @@ class InvoiceController extends Controller
|
||||
public function pdf($uuid)
|
||||
{
|
||||
\Debugbar::disable();
|
||||
|
||||
$data = [
|
||||
'invoice' => Invoices::getByUUID($uuid),
|
||||
];
|
||||
|
||||
@@ -82,4 +82,9 @@ class OrderController extends Controller
|
||||
|
||||
return view('Shop.Orders.confirmed');
|
||||
}
|
||||
|
||||
public function getPdf($uuid)
|
||||
{
|
||||
return Orders::getPdfByUUID($uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,11 @@ class Order extends Model
|
||||
return $this->belongsTo(SaleChannel::class);
|
||||
}
|
||||
|
||||
public function scopeByID($query, $id)
|
||||
{
|
||||
return $query->where('id', $id);
|
||||
}
|
||||
|
||||
public function scopeByUUID($query, $uuid)
|
||||
{
|
||||
return $query->where('uuid', $uuid);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use App\Repositories\Core\PDF;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -12,15 +14,34 @@ class Orders
|
||||
{
|
||||
use Basic, DateStats;
|
||||
|
||||
public static function getByUUID($uuid)
|
||||
public static function getPdfByUUID($uuid)
|
||||
{
|
||||
return Order::byUUID($uuid)->first();
|
||||
return self::getPdf(self::getIdByUUID($uuid), 'commande-' . $uuid . '.pdf');
|
||||
}
|
||||
|
||||
public static function getPdf($id, $file = 'order.pdf')
|
||||
{
|
||||
$data = [
|
||||
'order' => Orders::getFull($id),
|
||||
];
|
||||
|
||||
$customerId = Customers::getId();
|
||||
if ($customerId !== $data['order']['customer_id']) {
|
||||
return response()->view('errors.403');
|
||||
}
|
||||
|
||||
return PDF::view('Shop.Orders.view', $data, $file);
|
||||
}
|
||||
|
||||
public static function getFullByUUID($uuid)
|
||||
{
|
||||
return self::getFull(self::getIdByUUID($uuid));
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return Order::with(['customer', 'delivery', 'delivery_address', 'detail', 'invoice.address', 'sale_channel'])
|
||||
->byUUID($uuid)->first();
|
||||
->byID($id)->first();
|
||||
}
|
||||
|
||||
public static function view($uuid)
|
||||
|
||||
Reference in New Issue
Block a user