File: D:/HostingSpaces/SBogers10/wingssprayer.komma.pro/app/Invoicing/CreditInvoiceService.php
<?php declare(strict_types=1);
namespace App\Invoicing;
use App\Orders\Models\Order;
use Komma\KMS\Globalization\RegionInfoInterface;
/**
* Class CreditInvoiceService
*
* @package App\Invoicing
*/
class CreditInvoiceService extends AbstractInvoicingService
{
/** @var string the filesystem disk we use for storing creditinvoices */
protected const DISK = 'local';
/** @var string the directory on the disk that contains the invoices */
protected const DIRECTORY = 'order_documents'.DIRECTORY_SEPARATOR.'credit_invoices'.DIRECTORY_SEPARATOR;
/** @var string The name of the view that represents an creditinvoices */
protected const VIEWNAME = 'shop.pages.credit_invoice.creditInvoiceShow';
/** @var string The column on an order that holds the number of the invoice */
protected const NUMBER_COLUMN = 'credit_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->credit_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;
}
}