Passed
Push — developer ( 5a7d78...6a35f4 )
by Radosław
17:06
created

Vtiger_TaxPercent_InventoryField::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * Tax percent field.
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    Radosław Skrzypczak <[email protected]>
11
 */
12
13
/**
14
 * Inventory TaxPercent Field Class.
15
 */
16
class Vtiger_TaxPercent_InventoryField extends Vtiger_Tax_InventoryField
17
{
18
	protected $type = 'TaxPercent';
19
	protected $defaultLabel = 'LBL_TAX_IN_PERCENT';
20
	protected $defaultValue = 0;
21
	protected $summationValue = false;
22
	protected $columnName = 'tax_percent';
23
	protected $dbType = 'decimal(12,8) DEFAULT 0';
24
	protected $maximumLength = '9999';
25
	protected $purifyType = \App\Purifier::NUMBER;
26
	/**
27
	 * @var array List of shared fields
28
	 */
29
	public $shared = ['taxparam' => 'tax'];
30
31
	/** {@inheritdoc} */
32
	public function getDisplayValue($value, array $rowData = [], bool $rawText = false)
33
	{
34
		return App\Fields\Double::formatToDisplay($value);
35
	}
36
37
	/** {@inheritdoc} */
38
	public function getValueForSave(array $item, bool $userFormat = false, string $column = null)
39
	{
40
		if ($column === $this->getColumnName() || null === $column) {
41
			$value = 0.0;
42
			if (!\App\Json::isEmpty($item['taxparam'] ?? '')) {
43
				$taxParam = \App\Json::decode($item['taxparam']);
44
				$types = (array) $taxParam['aggregationType'];
45
				foreach ($types as $type) {
46
					$value += $taxParam["{$type}Tax"];
47
				}
48
			}
49
		} else {
50
			$value = $userFormat ? $this->getDBValue($item[$column]) : $item[$column];
51
		}
52
		return $value;
53
	}
54
55
	/** {@inheritdoc} */
56
	public function compare($value, $prevValue, string $column): bool
57
	{
58
		return \App\Validator::floatIsEqual((float) $value, (float) $prevValue, 8);
59
	}
60
}
61