|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Inventory TaxMode 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_TaxMode_InventoryField extends Vtiger_Basic_InventoryField |
|
14
|
|
|
{ |
|
15
|
|
|
protected $type = 'TaxMode'; |
|
16
|
|
|
protected $defaultLabel = 'LBL_TAX_MODE'; |
|
17
|
|
|
protected $defaultValue = '0'; |
|
18
|
|
|
protected $columnName = 'taxmode'; |
|
19
|
|
|
protected $dbType = 'smallint(1) DEFAULT 0'; |
|
20
|
|
|
protected $modes = [0 => 'LBL_INV_TAX_MODE_GLOBAL', 1 => 'LBL_INDIVIDUAL']; |
|
21
|
|
|
protected $blocks = [0]; |
|
22
|
|
|
protected $maximumLength = '-32768,32767'; |
|
23
|
|
|
protected $purifyType = \App\Purifier::INTEGER; |
|
24
|
|
|
|
|
25
|
|
|
/** {@inheritdoc} */ |
|
26
|
|
|
public function getDisplayValue($value, array $rowData = [], bool $rawText = false) |
|
27
|
|
|
{ |
|
28
|
|
|
return '' !== $value && null !== $value ? \App\Language::translate($this->modes[$value], $this->getModuleName()) : ''; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** {@inheritdoc} */ |
|
32
|
|
|
public function getDBValue($value, ?string $name = '') |
|
33
|
|
|
{ |
|
34
|
|
|
return (int) $value; |
|
35
|
|
|
} |
|
36
|
2 |
|
|
|
37
|
|
|
/** {@inheritdoc} */ |
|
38
|
2 |
|
public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null) |
|
39
|
|
|
{ |
|
40
|
|
|
if (!is_numeric($value) || !isset($this->modes[$value])) { |
|
41
|
|
|
throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||$value", 406); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
2 |
|
|
|
45
|
|
|
/** {@inheritdoc} */ |
|
46
|
2 |
|
public function getEditValue(array $itemData, string $column = '') |
|
47
|
|
|
{ |
|
48
|
|
|
$value = parent::getEditValue($itemData, $column); |
|
49
|
2 |
|
return is_numeric($value) ? $value : Vtiger_Inventory_Model::getTaxesConfig('default_mode'); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** {@inheritdoc} */ |
|
53
|
|
|
public function compare($value, $prevValue, string $column): bool |
|
54
|
|
|
{ |
|
55
|
|
|
return (int) $value === (int) $prevValue; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get available modes. |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getModes(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->modes; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.