Passed
Pull Request — developer (#16692)
by Arkadiusz
20:31
created

getConfigFieldsData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
	/** @var array List of shared fields */
27
	public $shared = ['taxparam' => 'tax'];
28
29
	/** {@inheritdoc} */
30
	public function getDisplayValue($value, array $rowData = [], bool $rawText = false)
31
	{
32
		return App\Fields\Double::formatToDisplay($value);
33
	}
34
35
	/** {@inheritdoc} */
36
	public function getValueForSave(array $item, bool $userFormat = false, string $column = null)
37
	{
38
		if ($column === $this->getColumnName() || null === $column) {
39
			$value = 0.0;
40
			if (!\App\Json::isEmpty($item['taxparam'] ?? '')) {
41
				$taxParam = \App\Json::decode($item['taxparam']);
42
				$types = (array) $taxParam['aggregationType'];
43
				foreach ($types as $type) {
44
					$value += $taxParam["{$type}Tax"];
45
				}
46
			}
47
		} else {
48
			$value = $userFormat ? $this->getDBValue($item[$column]) : $item[$column];
49
		}
50
		return $value;
51
	}
52
53
	/** {@inheritdoc} */
54
	public function compare($value, $prevValue, string $column): bool
55
	{
56
		return \App\Validator::floatIsEqual((float) $value, (float) $prevValue, 8);
57
	}
58
59
	/** {@inheritdoc} */
60
	public function getConfigFieldsData(): array
61
	{
62
		$data = parent::getConfigFieldsData();
63
		$data['summary_enabled'] = [
64
			'name' => 'summary_enabled',
65
			'label' => 'LBL_INV_SUMMARY_ENABLED',
66
			'uitype' => 56,
67
			'maximumlength' => '1',
68
			'typeofdata' => 'C~O',
69
			'purifyType' => \App\Purifier::INTEGER,
70
			'defaultvalue' => 1
71
		];
72
73
		return $data;
74
	}
75
}
76