|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Inventory DiscountMode Field Class. |
|
5
|
|
|
* |
|
6
|
|
|
* @package InventoryField |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright YetiForce S.A. |
|
9
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
10
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
11
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Vtiger_DiscountMode_InventoryField extends Vtiger_Basic_InventoryField |
|
14
|
|
|
{ |
|
15
|
|
|
protected $type = 'DiscountMode'; |
|
16
|
|
|
protected $defaultLabel = 'LBL_DISCOUNT_MODE'; |
|
17
|
|
|
protected $defaultValue = '0'; |
|
18
|
|
|
protected $columnName = 'discountmode'; |
|
19
|
|
|
protected $dbType = 'smallint(1) DEFAULT 0'; |
|
20
|
|
|
protected $modes = [ |
|
21
|
|
|
\Vtiger_Inventory_Model::DISCOUT_MODE_GLOBAL => 'LBL_INV_DISCOUNT_MODE_GLOBAL', |
|
22
|
|
|
\Vtiger_Inventory_Model::DISCOUT_MODE_INDIVIDUAL => 'LBL_INDIVIDUAL', |
|
23
|
|
|
\Vtiger_Inventory_Model::DISCOUT_MODE_GROUP => 'LBL_INV_DISCOUNT_MODE_GROUP' |
|
24
|
|
|
]; |
|
25
|
|
|
protected $blocks = [0]; |
|
26
|
|
|
protected $maximumLength = '-32768,32767'; |
|
27
|
|
|
protected $purifyType = \App\Purifier::INTEGER; |
|
28
|
|
|
|
|
29
|
|
|
/** {@inheritdoc} */ |
|
30
|
|
|
public function getDisplayValue($value, array $rowData = [], bool $rawText = false) |
|
31
|
|
|
{ |
|
32
|
|
|
return '' !== $value && null !== $value ? \App\Language::translate($this->modes[$value], $this->getModuleName()) : ''; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** {@inheritdoc} */ |
|
36
|
2 |
|
public function getDBValue($value, ?string $name = '') |
|
37
|
|
|
{ |
|
38
|
2 |
|
return (int) $value; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** {@inheritdoc} */ |
|
42
|
|
|
public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null) |
|
43
|
|
|
{ |
|
44
|
2 |
|
if (!is_numeric($value) || !isset($this->modes[$value])) { |
|
45
|
|
|
throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||$value", 406); |
|
46
|
2 |
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
/** {@inheritdoc} */ |
|
50
|
|
|
public function getEditValue(array $itemData, string $column = '') |
|
51
|
|
|
{ |
|
52
|
|
|
$value = parent::getEditValue($itemData, $column); |
|
53
|
|
|
return is_numeric($value) ? (int) $value : Vtiger_Inventory_Model::getDiscountsConfig('default_mode'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** {@inheritdoc} */ |
|
57
|
|
|
public function compare($value, $prevValue, string $column): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return (int) $value === (int) $prevValue; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** {@inheritdoc} */ |
|
63
|
|
|
public function getConfigFieldsData(): array |
|
64
|
|
|
{ |
|
65
|
|
|
$data = parent::getConfigFieldsData(); |
|
66
|
|
|
$data['defaultvalue'] = [ |
|
67
|
|
|
'name' => 'defaultvalue', |
|
68
|
|
|
'label' => 'LBL_INV_DEFAULT_VALUE', |
|
69
|
|
|
'uitype' => 16, |
|
70
|
|
|
'maximumlength' => '1', |
|
71
|
|
|
'typeofdata' => 'V~M', |
|
72
|
|
|
'purifyType' => \App\Purifier::INTEGER, |
|
73
|
|
|
'defaultvalue' => \Vtiger_Inventory_Model::DISCOUT_MODE_INDIVIDUAL, |
|
74
|
|
|
'picklistValues' => array_map(fn ($label) => \App\Language::translate($label, $this->getModuleName()), $this->modes) |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
return $data; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get available modes. |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getModes(): array |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->modes; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|