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
<?php
/**
* This file contains package_quiqqer_products_ajax_products_calcNettoPrice
*/
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_calcBruttoPrice',
function ($price, $formatted, $vat) {
$price = QUI\ERP\Money\Price::validatePrice($price);
$Currency = QUI\ERP\Defaults::getCurrency();
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 $Currency->format($price);
}
return $price;
}
$vat = $TaxEntry->getValue();
}
$vat = (100 + $vat) / 100;
$price = $price * $vat;
$price = round($price, $Currency->getPrecision());