Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
use QUI\ERP\Products\Utils\Calc;
use QUI\ERP\Tax\TaxEntry;
use QUI\ERP\Tax\TaxType;
use QUI\ERP\Tax\Utils as TaxUtils;
/**
* Calculate the netto price
*
* @param integer|float $price - Price to calc (brutto price)
* @param bool $formatted - output formatted?
* @param integer $vat - optional
*
* @return float
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_calcNettoPrice',
function ($price, $formatted, $vat) {
$price = QUI\ERP\Money\Price::validatePrice($price);
if (empty($vat)) {
$Area = QUI\ERP\Defaults::getArea();
$TaxType = TaxUtils::getTaxTypeByArea($Area);
if ($TaxType instanceof TaxType) {
$TaxEntry = TaxUtils::getTaxEntry($TaxType, $Area);
} elseif ($TaxType instanceof TaxEntry) {
$TaxEntry = $TaxType;
} else {
if (isset($formatted) && $formatted) {
return QUI\ERP\Defaults::getCurrency()->format($price);
}
return $price;
}
$vat = $TaxEntry->getValue();
}
$vat = ($vat / 100) + 1;
$price = $price / $vat;
if (isset($formatted) && $formatted) {
return QUI\ERP\Defaults::getCurrency()->format($price);
}
return $price;
},
['price', 'formatted', 'vat']
);