File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Shop/Invoicing/InvoiceService.php
<?php
declare(strict_types=1);
namespace App\Komma\Shop\Invoicing;
use App\Komma\Globalization\RegionInfoInterface;
use App\Komma\Shop\Orders\Models\Order;
/**
* Class InvoiceService
*/
class InvoiceService extends AbstractInvoicingService
{
/** @var string the filesystem disk we use for storing invoices */
protected const DISK = 'local';
/** @var string the directory on the disk that contains the invoices */
protected const DIRECTORY = 'order_documents'.DIRECTORY_SEPARATOR.'invoices'.DIRECTORY_SEPARATOR;
/** @var string The name of the view that represents an invoice */
protected const VIEWNAME = 'shop.pages.invoice.invoiceShow';
/** @var string The column on an order that holds the number of the invoice */
protected const NUMBER_COLUMN = 'invoice_number';
/**
* Returns the path to an invoice's pdf, that is relative to the disks directory
*
* @param Order $order
* @param bool $generatePdfIfNeeded
* @return string
*/
public function getPDFPathFromOrder(Order $order, $generatePdfIfNeeded = false): string
{
if ($generatePdfIfNeeded && ! $this->getDisk()->exists($this->getPDFPathFromOrder($order))) {
$this->generatePdfForOrder($order);
}
return self::DIRECTORY.$order->invoice_number.'_'.$order->updated_at->timestamp.'.pdf';
}
/**
* @param Order $order
* @return array
*/
protected function getViewData(Order $order):array
{
//Make sure everything is loaded for what we'd like to display in the view
$order->load([
'customer',
'orderedProducts.product.translations',
'orderedGroups.productGroup.translations',
'orderedProductComposites.orderedGroups.productGroup.translations',
'orderedProductComposites.productComposite.translations',
]);
$viewData = [];
$viewData['rootUrl'] = request()->root();
$viewData['order'] = $order;
$viewData['showTotal'] = true;
$viewData['regionInfo'] = app(RegionInfoInterface::class);
return $viewData;
}
}