Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
PriceMapper
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 findClientPrice
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   Modules\Billing\Models\Price
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace Modules\Billing\Models\Price;
16
17use Modules\ClientManagement\Models\Attribute\ClientAttributeValueMapper;
18use Modules\ClientManagement\Models\ClientMapper;
19use Modules\ItemManagement\Models\Attribute\ItemAttributeValueMapper;
20use Modules\ItemManagement\Models\ItemMapper;
21use Modules\SupplierManagement\Models\SupplierMapper;
22use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
23use phpOMS\Localization\Defaults\CountryMapper;
24
25/**
26 * Billing mapper class.
27 *
28 * @package Modules\Billing\Models\Price
29 * @license OMS License 2.0
30 * @link    https://jingga.app
31 * @since   1.0.0
32 *
33 * @template T of Price
34 * @extends DataMapperFactory<T>
35 */
36final class PriceMapper extends DataMapperFactory
37{
38    /**
39     * Columns.
40     *
41     * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
42     * @since 1.0.0
43     */
44    public const COLUMNS = [
45        'billing_price_id'                => ['name' => 'billing_price_id',               'type' => 'int',      'internal' => 'id'],
46        'billing_price_name'              => ['name' => 'billing_price_name',          'type' => 'string',   'internal' => 'name'],
47        'billing_price_promocode'         => ['name' => 'billing_price_promocode',     'type' => 'string',   'internal' => 'promocode'],
48        'billing_price_item'              => ['name' => 'billing_price_item',          'type' => 'int',      'internal' => 'item'],
49        'billing_price_itemgroup'         => ['name' => 'billing_price_itemgroup',     'type' => 'int',      'internal' => 'itemgroup'],
50        'billing_price_itemsegment'       => ['name' => 'billing_price_itemsegment',   'type' => 'int',      'internal' => 'itemsegment'],
51        'billing_price_itemsection'       => ['name' => 'billing_price_itemsection',   'type' => 'int',      'internal' => 'itemsection'],
52        'billing_price_itemtype'          => ['name' => 'billing_price_itemtype',      'type' => 'int',      'internal' => 'itemtype'],
53        'billing_price_client'            => ['name' => 'billing_price_client',        'type' => 'int',      'internal' => 'client'],
54        'billing_price_clientgroup'       => ['name' => 'billing_price_clientgroup',   'type' => 'int',      'internal' => 'clientgroup'],
55        'billing_price_clientsegment'     => ['name' => 'billing_price_clientsegment', 'type' => 'int',      'internal' => 'clientsegment'],
56        'billing_price_clientsection'     => ['name' => 'billing_price_clientsection', 'type' => 'int',      'internal' => 'clientsection'],
57        'billing_price_clienttype'        => ['name' => 'billing_price_clienttype',    'type' => 'int',      'internal' => 'clienttype'],
58        'billing_price_clientcountry'     => ['name' => 'billing_price_clientcountry', 'type' => 'string',   'internal' => 'clientcountry'],
59        'billing_price_supplier'          => ['name' => 'billing_price_supplier',      'type' => 'int',      'internal' => 'supplier'],
60        'billing_price_unit'              => ['name' => 'billing_price_unit',          'type' => 'int',      'internal' => 'unit'],
61        'billing_price_type'              => ['name' => 'billing_price_type',          'type' => 'int',      'internal' => 'type'],
62        'billing_price_quantity'          => ['name' => 'billing_price_quantity',      'type' => 'int',      'internal' => 'quantity'],
63        'billing_price_price'             => ['name' => 'billing_price_price',         'type' => 'Serializable',      'internal' => 'price'],
64        'billing_price_price_new'         => ['name' => 'billing_price_price_new',         'type' => 'int',      'internal' => 'priceNew'],
65        'billing_price_discount'          => ['name' => 'billing_price_discount',      'type' => 'int',      'internal' => 'discount'],
66        'billing_price_discountp'         => ['name' => 'billing_price_discountp',     'type' => 'int',      'internal' => 'discountPercentage'],
67        'billing_price_bonus'             => ['name' => 'billing_price_bonus',         'type' => 'int',      'internal' => 'bonus'],
68        'billing_price_multiply'          => ['name' => 'billing_price_multiply',      'type' => 'bool',     'internal' => 'multiply'],
69        'billing_price_currency'          => ['name' => 'billing_price_currency',      'type' => 'string',   'internal' => 'currency'],
70        'billing_price_start'             => ['name' => 'billing_price_start',         'type' => 'DateTime', 'internal' => 'start'],
71        'billing_price_end'               => ['name' => 'billing_price_end',           'type' => 'DateTime', 'internal' => 'end'],
72    ];
73
74    /**
75     * Has one relation.
76     *
77     * @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
78     * @since 1.0.0
79     */
80    public const OWNS_ONE = [
81        'item' => [
82            'mapper'   => ItemMapper::class,
83            'external' => 'billing_price_item',
84        ],
85        'itemgroup' => [
86            'mapper'   => ItemAttributeValueMapper::class,
87            'external' => 'billing_price_itemgroup',
88        ],
89        'itemsegment' => [
90            'mapper'   => ItemAttributeValueMapper::class,
91            'external' => 'billing_price_itemsegment',
92        ],
93        'itemsection' => [
94            'mapper'   => ItemAttributeValueMapper::class,
95            'external' => 'billing_price_itemsection',
96        ],
97        'itemtype' => [
98            'mapper'   => ItemAttributeValueMapper::class,
99            'external' => 'billing_price_itemtype',
100        ],
101        'client' => [
102            'mapper'   => ClientMapper::class,
103            'external' => 'billing_price_client',
104        ],
105        'clientgroup' => [
106            'mapper'   => ClientAttributeValueMapper::class,
107            'external' => 'billing_price_clientgroup',
108        ],
109        'clientsegment' => [
110            'mapper'   => ClientAttributeValueMapper::class,
111            'external' => 'billing_price_clientsegment',
112        ],
113        'clientsection' => [
114            'mapper'   => ClientAttributeValueMapper::class,
115            'external' => 'billing_price_clientsection',
116        ],
117        'clienttype' => [
118            'mapper'   => ClientAttributeValueMapper::class,
119            'external' => 'billing_price_clienttype',
120        ],
121        'clientcountry' => [
122            'mapper'      => CountryMapper::class,
123            'external'    => 'billing_price_clientcountry',
124            'by'          => 'code2',
125            'column'      => 'code2',
126            'conditional' => true,
127        ],
128        'supplier' => [
129            'mapper'   => SupplierMapper::class,
130            'external' => 'billing_price_supplier',
131        ],
132    ];
133
134    /**
135     * Model to use by the mapper.
136     *
137     * @var class-string<T>
138     * @since 1.0.0
139     */
140    public const MODEL = Price::class;
141
142    /**
143     * Primary table.
144     *
145     * @var string
146     * @since 1.0.0
147     */
148    public const TABLE = 'billing_price';
149
150    /**
151     * Primary field name.
152     *
153     * @var string
154     * @since 1.0.0
155     */
156    public const PRIMARYFIELD = 'billing_price_id';
157
158    /**
159     * Find price for a client
160     *
161     * @return Price[]
162     *
163     * @since 1.0.0
164     */
165    public static function findClientPrice() : array
166    {
167        /*
168        select * from prices
169            where
170                (promoID = ? OR promoID = null)
171                AND (itemID = ? OR itemID = null)
172                AND (itemGroup = IN (?) OR itemGroup = null)
173                AND (itemSegment = ? OR itemSegment = null)
174                AND (itemSection = ? OR itemSection = null)
175                AND (productType = ? OR productType = null)
176                AND (customerID = ? OR customerID = null)
177                AND (customerGroup IN (?) OR customerGroup = null)
178                AND (customerCountry = IN (?) OR customerCountry = null)
179                AND (quantity < ? OR quantity = null)
180                AND (start <= ? OR start = null)
181                AND (end >= ? OR start = null)
182                AND (unit = ? OR unit = null)
183        */
184
185        // @todo: allow nested where clause (already possible with the query builder, but not with the mappers)
186
187        return [];
188    }
189}