Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.62% |
10 / 21 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
| BillType | |
47.62% |
10 / 21 |
|
14.29% |
1 / 7 |
32.70 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setL11n | |
77.78% |
7 / 9 |
|
0.00% |
0 / 1 |
4.18 | |||
| getL11n | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 | |||
| addTemplate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTemplates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package Modules\Billing\Models |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace Modules\Billing\Models; |
| 16 | |
| 17 | use Modules\Media\Models\Collection; |
| 18 | use phpOMS\Localization\BaseStringL11n; |
| 19 | use phpOMS\Localization\ISO639x1Enum; |
| 20 | |
| 21 | /** |
| 22 | * Bill type enum. |
| 23 | * |
| 24 | * @package Modules\Billing\Models |
| 25 | * @license OMS License 2.0 |
| 26 | * @link https://jingga.app |
| 27 | * @since 1.0.0 |
| 28 | */ |
| 29 | class BillType implements \JsonSerializable |
| 30 | { |
| 31 | /** |
| 32 | * Id |
| 33 | * |
| 34 | * @var int |
| 35 | * @since 1.0.0 |
| 36 | */ |
| 37 | public int $id = 0; |
| 38 | |
| 39 | public string $name = ''; |
| 40 | |
| 41 | public array $templates = []; |
| 42 | |
| 43 | public ?Collection $defaultTemplate = null; |
| 44 | |
| 45 | public string $numberFormat = ''; |
| 46 | |
| 47 | public string $accountFormat = ''; |
| 48 | |
| 49 | public int $transferType = BillTransferType::SALES; |
| 50 | |
| 51 | public bool $transferStock = true; |
| 52 | |
| 53 | public int $sign = 1; |
| 54 | |
| 55 | /** |
| 56 | * Localization |
| 57 | * |
| 58 | * @var string|BaseStringL11n |
| 59 | */ |
| 60 | protected string | BaseStringL11n $l11n; |
| 61 | |
| 62 | public bool $isTemplate = false; |
| 63 | |
| 64 | /** |
| 65 | * Constructor. |
| 66 | * |
| 67 | * @param string $name Name |
| 68 | * |
| 69 | * @since 1.0.0 |
| 70 | */ |
| 71 | public function __construct(string $name = '') |
| 72 | { |
| 73 | $this->name = $name; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Set l11n |
| 78 | * |
| 79 | * @param string|BaseStringL11n $l11n Tag article l11n |
| 80 | * @param string $lang Language |
| 81 | * |
| 82 | * @return void |
| 83 | * |
| 84 | * @since 1.0.0 |
| 85 | */ |
| 86 | public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void |
| 87 | { |
| 88 | if ($l11n instanceof BaseStringL11n) { |
| 89 | $this->l11n = $l11n; |
| 90 | } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { |
| 91 | $this->l11n->content = $l11n; |
| 92 | $this->l11n->setLanguage($lang); |
| 93 | } else { |
| 94 | $this->l11n = new BaseStringL11n(); |
| 95 | $this->l11n->content = $l11n; |
| 96 | $this->l11n->ref = $this->id; |
| 97 | $this->l11n->setLanguage($lang); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return string |
| 103 | * |
| 104 | * @since 1.0.0 |
| 105 | */ |
| 106 | public function getL11n() : string |
| 107 | { |
| 108 | if (!isset($this->l11n)) { |
| 109 | return ''; |
| 110 | } |
| 111 | |
| 112 | return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Add rendering template |
| 117 | * |
| 118 | * @param Collection $template Template |
| 119 | * |
| 120 | * @return void |
| 121 | * |
| 122 | * @since 1.0.0 |
| 123 | */ |
| 124 | public function addTemplate(Collection $template) : void |
| 125 | { |
| 126 | $this->templates[] = $template; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get templates |
| 131 | * |
| 132 | * @return Collection[] |
| 133 | * |
| 134 | * @since 1.0.0 |
| 135 | */ |
| 136 | public function getTemplates() : array |
| 137 | { |
| 138 | return $this->templates; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * {@inheritdoc} |
| 143 | */ |
| 144 | public function toArray() : array |
| 145 | { |
| 146 | return [ |
| 147 | 'id' => $this->id, |
| 148 | 'numberFormat' => $this->numberFormat, |
| 149 | 'transferType' => $this->transferType, |
| 150 | ]; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * {@inheritdoc} |
| 155 | */ |
| 156 | public function jsonSerialize() : mixed |
| 157 | { |
| 158 | return $this->toArray(); |
| 159 | } |
| 160 | } |