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/shop.komma.nl/app/Vat/FinancialProperties.php
<?php declare(strict_types=1);


namespace App\Vat;

use App\Base\FormatsValuesTrait;
use Illuminate\Database\Eloquent\Model;

/**
 * Trait FinancialProperties
 *
 * Provides access to transient properties that are not saved / loaded to and from the database. Their function is to provide vat / price information.
 * And carry that information around the app. You must define the properties in the locations you use this trait
 *
 * @see HasFinancialPropertiesInterface
 * @see VatService::calculateVatForModelWithVatScenarioEnum()
 * @mixin Model|*
 * @package App\Vat
 */
trait FinancialProperties
{
    use FormatsValuesTrait;

    /** @var float $price_inc Transient property. The price including VAT in cents. Only available when it is passed trough the VatService::calculateVatForProductable method */
    protected $price_inc;

    /** @var float $price_ex Transient property. The price excluding VAT in cents. Only available when it is passed trough the VatService::calculateVatForProductable method */
    protected $price_ex;

    /** @var float $vat_amount Transient property. The vat amount in cents. Only available when it is passed trough the VatService::calculateVatForProductable method */
    protected $vat_amount;

    /**
     * @return float
     */
    public function getPriceInc(): float
    {
        return is_a($this, Model::class) ? $this->getAttribute('price_inc') ?? 0 : $this->price_inc ?? 0;
    }

    /**
     * @param float $price_inc
     */
    public function setPriceInc(float $price_inc): void
    {
        if(is_a($this, Model::class)) $this->setAttribute('price_inc', $price_inc);
        else $this->price_inc = $price_inc;
    }

    /**
     * @return float
     */
    public function getPriceEx(): float
    {
        return is_a($this, Model::class) ? $this->getAttribute('price_ex') ?? 0 : $this->price_ex ?? 0;
    }

    /**
     * @param float $price_ex
     */
    public function setPriceEx(float $price_ex): void
    {
        if(is_a($this, Model::class)) $this->setAttribute('price_ex', $price_ex);
        else $this->price_ex = $price_ex;
    }

    /**
     * @return float
     */
    public function getVatAmount(): float
    {
        return is_a($this, Model::class) ? $this->getAttribute('vat_amount') ?? 0 : $this->vat_amount ?? 0;
    }

    /**
     * @param float $vat_amount
     */
    public function setVatAmount(float $vat_amount): void
    {
        if(is_a($this, Model::class)) $this->setAttribute('vat_amount', $vat_amount);
        else $this->vat_amount = $vat_amount;
    }
}