| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services; |
| 4 |
|
| 5 |
use FluentCart\Api\Resource\OrderResource; |
| 6 |
use FluentCart\App\Models\Meta; |
| 7 |
use FluentCart\App\Services\ShortCodeParser\ShortcodeTemplateBuilder; |
| 8 |
use FluentCart\Framework\Support\Arr; |
| 9 |
use FluentCart\Framework\Support\Str; |
| 10 |
|
| 11 |
class PrintService |
| 12 |
{ |
| 13 |
public static function invoice($order) |
| 14 |
{ |
| 15 |
return static::print('invoice_template', $order); |
| 16 |
} |
| 17 |
|
| 18 |
public static function packingSlip($order) |
| 19 |
{ |
| 20 |
return static::print('packing_slip', $order); |
| 21 |
} |
| 22 |
|
| 23 |
public static function deliverySlip($order) |
| 24 |
{ |
| 25 |
return static::print('delivery_slip', $order); |
| 26 |
} |
| 27 |
|
| 28 |
public static function shippingSlip($order) |
| 29 |
{ |
| 30 |
return static::print('shipping_slip', $order); |
| 31 |
} |
| 32 |
|
| 33 |
public static function dispatchSlip($order) |
| 34 |
{ |
| 35 |
return static::print('dispatch_slip', $order); |
| 36 |
} |
| 37 |
|
| 38 |
public static function print($key, $orderId) |
| 39 |
{ |
| 40 |
$template = Meta::query()->where('meta_key', $key)->first(); |
| 41 |
if ($template) { |
| 42 |
$template = $template->meta_value; |
| 43 |
} else { |
| 44 |
$template = TemplateService::getInvoicePackingTemplateByPathName($key); |
| 45 |
} |
| 46 |
$order = OrderResource::view($orderId)['order']; |
| 47 |
|
| 48 |
$renderedTemplate = ShortcodeTemplateBuilder::make($template ?? '', [ |
| 49 |
'order' => $order |
| 50 |
]); |
| 51 |
|
| 52 |
if (has_action('fluent_pdf_download')) { |
| 53 |
do_action('fluent_pdf_download', [ |
| 54 |
'body' => $renderedTemplate, |
| 55 |
], |
| 56 |
Str::of($key)->headline() . '-InvoiceNO-' . Arr::get($order, 'order.invoice_no') |
| 57 |
); |
| 58 |
die(); |
| 59 |
} |
| 60 |
return FrontendView::renderForPrint($renderedTemplate); |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|