HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }
}