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/Attributes/VatScenarioPrice.php
<?php


namespace App\Attributes;

use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Models\SelectOptionInterface;
use Komma\KMS\Core\Attributes\Numeric;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\Traits\ExplanationTrait;
use Komma\KMS\Core\Attributes\Traits\LabelTrait;
use Komma\KMS\Core\Attributes\Traits\ReadOnlyTrait;

/**
 * Class VatScenarioPrice
 *
 * Represents a field in which a user can enter a product price.
 * And select the "kind" of price it is. Like if it includes vat or not, and if so, which rate (Vat Scenario).
 *
 * @package App\Attributes
 */
class VatScenarioPrice extends Attribute
{
    use LabelTrait;
    use ExplanationTrait;
    use ReadOnlyTrait;

    /**
     * @var string $exclude The option (value) that needs to excluded from the list. Usually because it represents something that you currently are in or are using
     */
    private $exclude;

    /** @var SelectOptionInterface[] $items */
    private $items;

    /** @var int The max amount of decimals allowed */
    private $fractionLength = 2;

    /** @var string A string that is put between the whole and max  */
    private $separator = ',';

    /** @var string A string that is put before the whole part */
    private $prefix = '';

    /** @var string A string that is put after the fraction part */
    private $suffix = '';

    /** @var int */
    private $wholeStep = 1;

    /** @var int */
    private $wholeMin = 0;

    /** @var int */
    private $wholeMax = null;

    /** @var int */
    private $fractionStep = 1;

    /** @var int */
    private $fractionMin = 0;

    /** @var int */
    private $fractionMax = null;

    /** @var bool */
    private $zeropadFraction = false;

    /**
     * @var Select
     */
    private $selectAttribute;

    public function __construct($labelText)
    {
        $this->setValueToDefault();
        $this->setLabelText($labelText);
        parent::__construct();
    }

    /**
     * Set the value to a default. Which is a price of 0 and the scenario as defined in shop.vat.default_scenario.
     */
    public function setValueToDefault(): VatScenarioPrice
    {
        $this->value = implode('|', ['0', config('shop.vat.default_scenario')]);
        return $this;
    }

    /**
     * Returns a view that visually represents this attribute
     */
    public function render(): string
    {
        $data = [
            'key' => (string) $this->getKey(),
            'valuePart' => $this->getKey()->getValuePart(),
            'styleClass' => $this->getStyleClass(),
            'defaultScenario' => config('shop.vat.default_scenario'),
            'attribute' => $this,
            'dataAttributes' => $this->getDataAttributes(),
            'price' => $this->getPrice(),
            'items' => $this->getItems(),
            'vatScenarioEnum' => $this->getVatScenarioEnum(),
            'fractionLength' => $this->fractionLength,
            'separator' => $this->separator,
            'prefix' => $this->prefix,
            'suffix' => $this->suffix,
            'wholeMin' => $this->wholeMin,
            'wholeMax' => $this->wholeMax,
            'wholeStep' => $this->wholeStep,
            'fractionMin' => $this->fractionMin,
            'fractionMax' => $this->fractionMax,
            'fractionStep' => $this->fractionStep,
            'zeroPadFraction' => $this->zeropadFraction,
            'explanation' => $this->getExplanation(),
            'readOnlyTrait' => $this->getReadOnly(),
            'currentId' => null,
        ];
        return view('kms.attributes.vatScenarioPrice', $data)->render();
    }

    /**
     * @return string The value associated with the attribute
     */
    public function getValue(): string
    {
        if($this->value == '') $this->setValueToDefault();
        return $this->value;
    }

    /**
     * @return int
     */
    private function getPrice(): int
    {
        return explode('|', $this->getValue())[0] ?? 0;
    }

    /**
     * @return int
     */
    private function getVatScenarioEnum(): string
    {
        return explode('|', $this->getValue())[1] ?? __('shop/vatrates.default');
    }

    /**
     * @param string $value The value associated with the attribute
     * @return $this
     */
    public function setValue(string $value)
    {
        $this->value = $value;
        return $this;
    }

    /**
     * @return SelectOptionInterface[]
     */
    public function getItems(): array
    {
        return $this->items;
    }

    /**
     * @param SelectOptionInterface[] $items
     * @return VatScenarioPrice|Attribute
     */
    public function setItems(array $items): VatScenarioPrice
    {
        $this->items = $items;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionLength(): int
    {
        return $this->fractionLength;
    }

    /**
     * @param int $fractionLength
     * @return Numeric
     */
    public function setFractionLength(int $fractionLength): VatScenarioPrice
    {
        $this->fractionLength = $fractionLength;
        return $this;
    }

    /**
     * @return string
     */
    public function getSeparator(): string
    {
        return $this->separator;
    }

    /**
     * @param string $separator
     * @return Numeric
     */
    public function setSeparator(string $separator): VatScenarioPrice
    {
        $this->separator = $separator;
        return $this;
    }

    /**
     * @return string
     */
    public function getPrefix(): string
    {
        return $this->prefix;
    }

    /**
     * @param string $prefix
     * @return Numeric
     */
    public function setPrefix(string $prefix): VatScenarioPrice
    {
        $this->prefix = $prefix;
        return $this;
    }

    /**
     * @return string
     */
    public function getSuffix(): string
    {
        return $this->suffix;
    }

    /**
     * @param string $suffix
     * @return Numeric
     */
    public function setSuffix(string $suffix): VatScenarioPrice
    {
        $this->suffix = $suffix;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeStep(): int
    {
        return $this->wholeStep;
    }

    /**
     * @param int $wholeStep
     * @return Numeric
     */
    public function setWholeStep(int $wholeStep): VatScenarioPrice
    {
        $this->wholeStep = $wholeStep;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeMin(): int
    {
        return $this->wholeMin;
    }

    /**
     * @param int $wholeMin
     * @return Numeric
     */
    public function setWholeMin(int $wholeMin): VatScenarioPrice
    {
        $this->wholeMin = $wholeMin;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeMax(): int
    {
        return $this->wholeMax;
    }

    /**
     * @param int $wholeMax
     * @return Numeric
     */
    public function setWholeMax(int $wholeMax): VatScenarioPrice
    {
        $this->wholeMax = $wholeMax;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionStep(): int
    {
        return $this->fractionStep;
    }

    /**
     * @param int $fractionStep
     * @return Numeric
     */
    public function setFractionStep(int $fractionStep): VatScenarioPrice
    {
        $this->fractionStep = $fractionStep;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionMin(): int
    {
        return $this->fractionMin;
    }

    /**
     * @param int $fractionMin
     * @return Numeric
     */
    public function setFractionMin(int $fractionMin): VatScenarioPrice
    {
        $this->fractionMin = $fractionMin;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionMax(): int
    {
        return $this->fractionMax;
    }

    /**
     * @param int $fractionMax
     * @return Numeric
     */
    public function setFractionMax(int $fractionMax): VatScenarioPrice
    {
        $this->fractionMax = $fractionMax;
        return $this;
    }
}