diff --git a/src/QUI/ERP/Accounting/Calc.php b/src/QUI/ERP/Accounting/Calc.php index 7136d529bac1c62562af23474d701f151155e26d..7484fc34e167efbedabd64c0ebf68b6da3ad4c30 100644 --- a/src/QUI/ERP/Accounting/Calc.php +++ b/src/QUI/ERP/Accounting/Calc.php @@ -6,13 +6,32 @@ namespace QUI\ERP\Accounting; +use DateTime; +use Exception; use QUI; -use QUI\ERP\Accounting\Calc as ErpCalc; -use QUI\ERP\Money\Price; -use QUI\Interfaces\Users\User as UserInterface; +use QUI\ERP\Accounting\Invoice\Handler; use QUI\ERP\Accounting\Invoice\Invoice; use QUI\ERP\Accounting\Invoice\InvoiceTemporary; -use QUI\ERP\Accounting\Invoice\Handler; +use QUI\ERP\Money\Price; +use QUI\Interfaces\Users\User as UserInterface; + +use function array_map; +use function array_sum; +use function count; +use function floatval; +use function get_class; +use function is_array; +use function is_callable; +use function is_null; +use function is_string; +use function json_decode; +use function json_encode; +use function key; +use function round; +use function str_replace; +use function strpos; +use function strtotime; +use function time; /** * Class Calc @@ -78,7 +97,7 @@ class Calc /** * @var null|QUI\ERP\Currency\Currency */ - protected $Currency = null; + protected ?QUI\ERP\Currency\Currency $Currency = null; /** * Calc constructor. @@ -100,7 +119,7 @@ public function __construct($User = false) * @param UserInterface|null $User - optional * @return Calc */ - public static function getInstance($User = null): Calc + public static function getInstance(UserInterface $User = null): Calc { if (!$User && QUI::isBackend()) { $User = QUI::getUsers()->getSystemUser(); @@ -141,7 +160,7 @@ public function getUser() */ public function getCurrency(): ?QUI\ERP\Currency\Currency { - if (\is_null($this->Currency)) { + if (is_null($this->Currency)) { $this->Currency = QUI\ERP\Currency\Handler::getDefaultCurrency(); } @@ -158,7 +177,7 @@ public function getCurrency(): ?QUI\ERP\Currency\Currency public function calcArticleList(ArticleList $List, $callback = false): ArticleList { // calc data - if (!\is_callable($callback)) { + if (!is_callable($callback)) { return $List->calc(); } @@ -171,14 +190,14 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi $this->Currency = $List->getCurrency(); - $articles = $List->getArticles(); - $isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser()); + $articles = $List->getArticles(); + $isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser()); $isEuVatUser = QUI\ERP\Tax\Utils::isUserEuVatUser($this->getUser()); - $Currency = $this->getCurrency(); + $Currency = $this->getCurrency(); $precision = $Currency->getPrecision(); - $subSum = 0; + $subSum = 0; $nettoSum = 0; $vatArray = []; @@ -196,20 +215,20 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi $this->calcArticlePrice($Article); $articleAttributes = $Article->toArray(); - $calculated = $articleAttributes['calculated']; + $calculated = $articleAttributes['calculated']; - $subSum = $subSum + $calculated['sum']; + $subSum = $subSum + $calculated['sum']; $nettoSum = $nettoSum + $calculated['nettoSum']; $articleVatArray = $calculated['vatArray']; - $vat = $articleAttributes['vat']; + $vat = $articleAttributes['vat']; if ($articleVatArray['text'] === '') { continue; } if (!isset($vatArray[$vat])) { - $vatArray[$vat] = $articleVatArray; + $vatArray[$vat] = $articleVatArray; $vatArray[$vat]['sum'] = 0; } @@ -231,7 +250,7 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi /** * Calc price factors */ - $priceFactors = $List->getPriceFactors(); + $priceFactors = $List->getPriceFactors(); $priceFactorSum = 0; // nur wenn wir welche benötigen, für ERP Artikel ist dies im Moment nicht wirklich nötig @@ -247,9 +266,9 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi // percent - Prozent Angabe if ($PriceFactor->getCalculation() === self::CALCULATION_PERCENTAGE) { - $calcBasis = $PriceFactor->getCalculationBasis(); + $calcBasis = $PriceFactor->getCalculationBasis(); $priceFactorValue = $PriceFactor->getValue(); - $vatValue = $PriceFactor->getVat(); + $vatValue = $PriceFactor->getVat(); if ($vatValue === null) { $vatValue = QUI\ERP\Tax\Utils::getTaxByUser($this->getUser())->getValue(); @@ -269,7 +288,7 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi case self::CALCULATION_BASIS_VAT_BRUTTO: if ($isNetto) { $bruttoSubSum = $subSum * ($vatValue / 100 + 1); - $percentage = $priceFactorValue / 100 * $bruttoSubSum; + $percentage = $priceFactorValue / 100 * $bruttoSubSum; } else { $percentage = $priceFactorValue / 100 * $subSum; } @@ -280,8 +299,8 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi continue 2; } - $percentage = \round($percentage, $precision); - $vatSum = \round($PriceFactor->getVatSum(), $precision); + $percentage = round($percentage, $precision); + $vatSum = round($PriceFactor->getVatSum(), $precision); // set netto sum $PriceFactor->setNettoSum($percentage); @@ -300,15 +319,15 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi $PriceFactor->setSumFormatted($Currency->format($PriceFactor->getSum())); } - $nettoSum = $nettoSum + $PriceFactor->getNettoSum(); + $nettoSum = $nettoSum + $PriceFactor->getNettoSum(); $priceFactorSum = $priceFactorSum + $PriceFactor->getNettoSum(); if ($isEuVatUser) { $PriceFactor->setEuVatStatus(true); } - $vat = $PriceFactor->getVat(); - $vatSum = \round($PriceFactor->getVatSum(), $precision); + $vat = $PriceFactor->getVat(); + $vatSum = round($PriceFactor->getVatSum(), $precision); if (!isset($vatArray[$vat])) { $vatArray[$vat] = [ @@ -328,23 +347,23 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi // vat text $vatLists = []; - $vatText = []; + $vatText = []; - $nettoSum = \round($nettoSum, $precision); - $nettoSubSum = \round($nettoSubSum, $precision); - $subSum = \round($subSum, $precision); - $bruttoSum = $nettoSum; + $nettoSum = round($nettoSum, $precision); + $nettoSubSum = round($nettoSubSum, $precision); + $subSum = round($subSum, $precision); + $bruttoSum = $nettoSum; foreach ($vatArray as $vatEntry) { $vat = $vatEntry['vat']; - $vatLists[$vat] = true; // liste für MWST texte - $vatArray[$vat]['sum'] = \round($vatEntry['sum'], $precision); + $vatLists[$vat] = true; // liste für MWST texte + $vatArray[$vat]['sum'] = round($vatEntry['sum'], $precision); $bruttoSum = $bruttoSum + $vatArray[$vat]['sum']; } - $bruttoSum = \round($bruttoSum, $precision); + $bruttoSum = round($bruttoSum, $precision); foreach ($vatLists as $vat => $bool) { $vatText[$vat] = self::getVatText($vat, $this->getUser()); @@ -367,15 +386,15 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi foreach ($priceFactors as $Factor) { if ($Factor->getCalculationBasis() !== self::CALCULATION_GRAND_TOTAL) { /* @var $Factor QUI\ERP\Products\Utils\PriceFactor */ - $priceFactorBruttoSums = $priceFactorBruttoSums + \round($Factor->getSum(), $precision); + $priceFactorBruttoSums = $priceFactorBruttoSums + round($Factor->getSum(), $precision); } } $priceFactorBruttoSum = $subSum + $priceFactorBruttoSums; - $priceFactorBruttoSum = \round($priceFactorBruttoSum, $precision); + $priceFactorBruttoSum = round($priceFactorBruttoSum, $precision); - if ($priceFactorBruttoSum !== \round($bruttoSum, $precision)) { - $diff = $priceFactorBruttoSum - \round($bruttoSum, $precision); + if ($priceFactorBruttoSum !== round($bruttoSum, $precision)) { + $diff = $priceFactorBruttoSum - round($bruttoSum, $precision); // if we have a diff, we change the first vat price factor $added = false; @@ -386,9 +405,9 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi } if ($Factor instanceof QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface) { - $Factor->setSum(\round($Factor->getSum() - $diff, $precision)); - $bruttoSum = \round($bruttoSum, $precision); - $added = true; + $Factor->setSum(round($Factor->getSum() - $diff, $precision)); + $bruttoSum = round($bruttoSum, $precision); + $added = true; break; } } @@ -401,13 +420,13 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi // counterbalance - gegenrechnung // works only for one vat entry - if (\count($vatArray) === 1) { - $vat = \key($vatArray); + if (count($vatArray) === 1) { + $vat = key($vatArray); $netto = $bruttoSum / ($vat / 100 + 1); $vatSum = $bruttoSum - $netto; - $vatSum = \round($vatSum, $Currency->getPrecision()); - $diff = abs($vatArray[$vat]['sum'] - $vatSum); + $vatSum = round($vatSum, $Currency->getPrecision()); + $diff = abs($vatArray[$vat]['sum'] - $vatSum); if ($diff <= 0.019) { $vatArray[$vat]['sum'] = $vatSum; @@ -417,7 +436,7 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi if ($bruttoSum === 0 || $nettoSum === 0) { $bruttoSum = 0; - $nettoSum = 0; + $nettoSum = 0; foreach ($vatArray as $vat => $entry) { $vatArray[$vat]['sum'] = 0; @@ -429,7 +448,7 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi foreach ($priceFactors as $Factor) { if ($Factor->getCalculationBasis() === self::CALCULATION_GRAND_TOTAL) { - $value = $Factor->getValue(); + $value = $Factor->getValue(); $bruttoSum = $bruttoSum + $value; if ($bruttoSum < 0) { @@ -464,69 +483,69 @@ public function calcArticleList(ArticleList $List, $callback = false): ArticleLi public function calcArticlePrice(Article $Article, $callback = false) { // calc data - if (!\is_callable($callback)) { + if (!is_callable($callback)) { $Article->calc($this); return $Article->getPrice(); } - $isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser()); + $isNetto = QUI\ERP\Utils\User::isNettoUser($this->getUser()); $isEuVatUser = QUI\ERP\Tax\Utils::isUserEuVatUser($this->getUser()); - $Currency = $Article->getCurrency(); + $Currency = $Article->getCurrency(); if (!$Currency) { $Currency = $this->getCurrency(); } - $nettoPrice = $Article->getUnitPrice()->value(); - $vat = $Article->getVat(); + $nettoPrice = $Article->getUnitPrice()->value(); + $vat = $Article->getVat(); $basisNettoPrice = $nettoPrice; - $nettoSubSum = $this->round($nettoPrice * $Article->getQuantity()); + $nettoSubSum = $this->round($nettoPrice * $Article->getQuantity()); if ($isEuVatUser) { $vat = 0; } // discounts - $Discount = $Article->getDiscount(); + $Discount = $Article->getDiscount(); $nettoPriceNotRounded = $Article->getUnitPriceUnRounded()->getValue(); if ($Discount) { switch ($Discount->getCalculation()) { // einfache Zahl, Währung --- kein Prozent case Calc::CALCULATION_COMPLEMENT: - $nettoPrice = $nettoPrice - ($Discount->getValue() / $Article->getQuantity()); + $nettoPrice = $nettoPrice - ($Discount->getValue() / $Article->getQuantity()); $nettoPriceNotRounded = $nettoPriceNotRounded - ($Discount->getValue() / $Article->getQuantity()); break; // Prozent Angabe case Calc::CALCULATION_PERCENTAGE: - $percentage = $Discount->getValue() / 100 * $nettoPrice; - $nettoPrice = $nettoPrice - $percentage; + $percentage = $Discount->getValue() / 100 * $nettoPrice; + $nettoPrice = $nettoPrice - $percentage; $nettoPriceNotRounded = $nettoPriceNotRounded - $percentage; break; } } - $vatSum = $nettoPrice * ($vat / 100); - $bruttoPrice = \round($nettoPrice + $vatSum, $Currency->getPrecision()); + $vatSum = $nettoPrice * ($vat / 100); + $bruttoPrice = round($nettoPrice + $vatSum, $Currency->getPrecision()); if (!$isNetto) { // korrektur rechnung / 1 cent problem $checkBrutto = $nettoPriceNotRounded * ($vat / 100 + 1); - $checkBrutto = \round($checkBrutto, $Currency->getPrecision()); + $checkBrutto = round($checkBrutto, $Currency->getPrecision()); $checkVat = $checkBrutto - $nettoPriceNotRounded; - $checkVat = \round($checkVat * $Article->getQuantity(), $Currency->getPrecision()); + $checkVat = round($checkVat * $Article->getQuantity(), $Currency->getPrecision()); // sum $nettoSum = $this->round($nettoPrice * $Article->getQuantity()); - $vatSum = $nettoSum * ($vat / 100); + $vatSum = $nettoSum * ($vat / 100); // korrektur rechnung / 1 cent problem if ($checkBrutto !== $bruttoPrice) { $bruttoPrice = $checkBrutto; - $vatSum = $checkVat; + $vatSum = $checkVat; } // if the user is brutto @@ -537,13 +556,13 @@ public function calcArticlePrice(Article $Article, $callback = false) } else { // sum $nettoSum = $this->round($nettoPrice * $Article->getQuantity()); - $vatSum = $nettoSum * ($vat / 100); + $vatSum = $nettoSum * ($vat / 100); $bruttoSum = $this->round($nettoSum + $vatSum); } - $price = $isNetto ? $nettoPrice : $bruttoPrice; - $sum = $isNetto ? $nettoSum : $bruttoSum; + $price = $isNetto ? $nettoPrice : $bruttoPrice; + $sum = $isNetto ? $nettoSum : $bruttoSum; $basisPrice = $isNetto ? $basisNettoPrice : $basisNettoPrice + ($basisNettoPrice * $vat / 100); $vatArray = [ @@ -589,17 +608,17 @@ public function calcArticlePrice(Article $Article, $callback = false) */ public function round($value): float { - $decimalSeparator = $this->getUser()->getLocale()->getDecimalSeparator(); + $decimalSeparator = $this->getUser()->getLocale()->getDecimalSeparator(); $groupingSeparator = $this->getUser()->getLocale()->getGroupingSeparator(); - $precision = QUI\ERP\Defaults::getPrecision(); + $precision = QUI\ERP\Defaults::getPrecision(); - if (\strpos($value, $decimalSeparator) && $decimalSeparator != '.') { - $value = \str_replace($groupingSeparator, '', $value); + if (strpos($value, $decimalSeparator) && $decimalSeparator != '.') { + $value = str_replace($groupingSeparator, '', $value); } - $value = \str_replace(',', '.', $value); - $value = \floatval($value); - $value = \round($value, $precision); + $value = str_replace(',', '.', $value); + $value = floatval($value); + $value = round($value, $precision); return $value; } @@ -630,7 +649,7 @@ public function getVatTextByUser() * * @return array|string */ - public static function getVatText($vat, UserInterface $User, $Locale = null) + public static function getVatText(int $vat, UserInterface $User, QUI\Locale $Locale = null) { if ($Locale === null) { $Locale = $User->getLocale(); @@ -687,7 +706,7 @@ public static function getVatText($vat, UserInterface $User, $Locale = null) * * @deprecated use calculatePayments */ - public static function calculateInvoicePayments(Invoice $Invoice) + public static function calculateInvoicePayments(Invoice $Invoice): array { return self::calculatePayments($Invoice); } @@ -704,7 +723,7 @@ public static function calculatePayments($ToCalculate): array { if (self::isAllowedForCalculation($ToCalculate) === false) { QUI\ERP\Debug::getInstance()->log( - 'Calc->calculatePayments(); Object is not allowed to calculate ' . \get_class($ToCalculate) + 'Calc->calculatePayments(); Object is not allowed to calculate ' . get_class($ToCalculate) ); throw new QUI\ERP\Exception('Object is not allowed to calculate'); @@ -717,19 +736,19 @@ public static function calculatePayments($ToCalculate): array // if payment status is paid, take it immediately and do not query any transactions if ($ToCalculate->getAttribute('paid_status') === QUI\ERP\Constants::PAYMENT_STATUS_PAID) { $paidData = $ToCalculate->getAttribute('paid_data'); - $paid = 0; + $paid = 0; - if (!\is_array($paidData)) { - $paidData = \json_decode($paidData, true); + if (!is_array($paidData)) { + $paidData = json_decode($paidData, true); } - if (!\is_array($paidData)) { + if (!is_array($paidData)) { $paidData = []; } foreach ($paidData as $entry) { if (isset($entry['amount'])) { - $paid = $paid + \floatval($entry['amount']); + $paid = $paid + floatval($entry['amount']); } } @@ -765,8 +784,8 @@ public static function calculatePayments($ToCalculate): array $paidData = []; $paidDate = 0; - $sum = 0; - $total = $calculations['sum']; + $sum = 0; + $total = $calculations['sum']; QUI\ERP\Debug::getInstance()->log( 'Calc->calculatePayments(); total: ' . $total @@ -774,8 +793,8 @@ public static function calculatePayments($ToCalculate): array $isValidTimeStamp = function ($timestamp) { try { - new \DateTime('@' . $timestamp); - } catch (\Exception $e) { + new DateTime('@' . $timestamp); + } catch (Exception $e) { return false; } @@ -796,10 +815,10 @@ public static function calculatePayments($ToCalculate): array $date = $Transaction->getDate(); if ($isValidTimeStamp($date) === false) { - $date = \strtotime($date); + $date = strtotime($date); if ($isValidTimeStamp($date) === false) { - $date = \time(); + $date = time(); } } else { $date = (int)$date; @@ -827,7 +846,7 @@ public static function calculatePayments($ToCalculate): array ]; } - $paid = Price::validatePrice($sum); + $paid = Price::validatePrice($sum); $toPay = Price::validatePrice($calculations['sum']); // workaround fix @@ -848,7 +867,7 @@ public static function calculatePayments($ToCalculate): array } } - $ToCalculate->setAttribute('paid_data', \json_encode($paidData)); + $ToCalculate->setAttribute('paid_data', json_encode($paidData)); $ToCalculate->setAttribute('paid_date', $paidDate); $ToCalculate->setAttribute('paid', $sum); $ToCalculate->setAttribute('toPay', $toPay - $paid); @@ -927,14 +946,14 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr { if ($Currency === null) { try { - $currency = \json_decode($invoiceList[0]['currency_data'], true); + $currency = json_decode($invoiceList[0]['currency_data'], true); $Currency = QUI\ERP\Currency\Handler::getCurrency($currency['code']); } catch (QUI\Exception $Exception) { $Currency = QUI\ERP\Defaults::getCurrency(); } } - if (!\count($invoiceList)) { + if (!count($invoiceList)) { $display = $Currency->format(0); return [ @@ -962,13 +981,13 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr } $nettoTotal = 0; - $vatTotal = 0; + $vatTotal = 0; $bruttoToPay = 0; - $bruttoPaid = 0; + $bruttoPaid = 0; $bruttoTotal = 0; - $vatPaid = 0; - $nettoToPay = 0; + $vatPaid = 0; + $nettoToPay = 0; foreach ($invoiceList as $invoice) { // if (isset($invoice['type']) && (int)$invoice['type'] === Handler::TYPE_INVOICE_CANCEL || @@ -978,12 +997,12 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr // } // soll doch mit berechnet werden - $invBruttoSum = floatval($invoice['calculated_sum']); - $invVatSum = floatval($invoice['calculated_vatsum']); - $invPaid = floatval($invoice['calculated_paid']); - $invToPay = floatval($invoice['calculated_toPay']); + $invBruttoSum = floatval($invoice['calculated_sum']); + $invVatSum = floatval($invoice['calculated_vatsum']); + $invPaid = floatval($invoice['calculated_paid']); + $invToPay = floatval($invoice['calculated_toPay']); $invNettoTotal = floatval($invoice['calculated_nettosum']); - $invVatSumPC = QUI\Utils\Math::percent($invVatSum, $invBruttoSum); + $invVatSumPC = QUI\Utils\Math::percent($invVatSum, $invBruttoSum); if ($invVatSumPC) { if ($invToPay === 0.0) { @@ -995,16 +1014,16 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr $invVatPaid = 0; } - $invNettoPaid = $invPaid - $invVatPaid; + $invNettoPaid = $invPaid - $invVatPaid; $invNettoToPay = $invNettoTotal - $invNettoPaid; // complete + addition - $vatPaid = $vatPaid + $invVatPaid; + $vatPaid = $vatPaid + $invVatPaid; $bruttoTotal = $bruttoTotal + $invBruttoSum; - $bruttoPaid = $bruttoPaid + $invPaid; + $bruttoPaid = $bruttoPaid + $invPaid; //$bruttoToPay = $bruttoToPay + $invToPay; $nettoToPay = $nettoToPay + $invNettoToPay; - $vatTotal = $vatTotal + $invVatSum; + $vatTotal = $vatTotal + $invVatSum; $nettoTotal = $nettoTotal + $invNettoTotal; } @@ -1014,7 +1033,7 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr $nettoPaid = $bruttoPaid - $vatPaid; // vat calculation - $vatToPay = $vatTotal - $vatPaid; + $vatToPay = $vatTotal - $vatPaid; $bruttoToPay = $bruttoTotal - $bruttoPaid; return [ @@ -1049,16 +1068,16 @@ public static function calculateTotal(array $invoiceList, $Currency = null): arr */ public static function calculateTotalVatOfInvoice($vatArray) { - if (\is_string($vatArray)) { - $vatArray = \json_decode($vatArray, true); + if (is_string($vatArray)) { + $vatArray = json_decode($vatArray, true); } - if (!\is_array($vatArray)) { + if (!is_array($vatArray)) { return 0; } - return \array_sum( - \array_map(function ($vat) { + return array_sum( + array_map(function ($vat) { return $vat['sum']; }, $vatArray) ); diff --git a/src/QUI/ERP/Accounting/CalculationValue.php b/src/QUI/ERP/Accounting/CalculationValue.php index 3fbcd48b13af9c65f45d7d742d0d8a79710b3854..ff8dc1082cfaf85cbef345da0cb34d1bc8f62b8f 100644 --- a/src/QUI/ERP/Accounting/CalculationValue.php +++ b/src/QUI/ERP/Accounting/CalculationValue.php @@ -8,6 +8,9 @@ use QUI; +use function is_numeric; +use function round; + /** * Class CalculationValue * - represent a number for the calculations @@ -19,7 +22,7 @@ class CalculationValue /** * @var QUI\ERP\Currency\Currency */ - protected $Currency; + protected QUI\ERP\Currency\Currency $Currency; /** * @var int|string @@ -35,19 +38,19 @@ class CalculationValue * CalculationValue constructor. * * @param $number - * @param QUI\ERP\Currency\Currency $Currency + * @param QUI\ERP\Currency\Currency|null $Currency * @param int|bool $precision - The optional number of decimal digits to round to. */ - public function __construct($number, $Currency = null, $precision = false) + public function __construct($number, QUI\ERP\Currency\Currency $Currency = null, $precision = false) { - if (!\is_numeric($number)) { + if (!is_numeric($number)) { return; } $this->number = $number; // precision - if (\is_numeric($precision)) { + if (is_numeric($precision)) { $this->precision = $precision; } else { $this->precision = QUI\ERP\Defaults::getPrecision(); @@ -69,7 +72,7 @@ public function __construct($number, $Currency = null, $precision = false) * @param bool $precision * @return CalculationValue */ - public function precision($precision = false) + public function precision(bool $precision = false): CalculationValue { if ($precision === false) { return $this; @@ -88,7 +91,7 @@ public function precision($precision = false) * @param null|QUI\Locale $Locale - optional, Locale object for the formatting * @return string */ - public function formatted($Locale = null) + public function formatted(QUI\Locale $Locale = null): string { return $this->Currency->format($this->number, $Locale); } @@ -96,10 +99,10 @@ public function formatted($Locale = null) /** * Return the un-formatted number * - * @return int|string + * @return float */ - public function get() + public function get(): float { - return \round($this->number, $this->precision); + return round($this->number, $this->precision); } } diff --git a/src/QUI/ERP/Accounting/CalculationVatValue.php b/src/QUI/ERP/Accounting/CalculationVatValue.php index d339542fed23d616cee4ba2efb36645e5d150b03..86c6b815d036da482111b956313b89970230970a 100644 --- a/src/QUI/ERP/Accounting/CalculationVatValue.php +++ b/src/QUI/ERP/Accounting/CalculationVatValue.php @@ -20,23 +20,23 @@ class CalculationVatValue extends CalculationValue /** * @var string */ - protected $text = ''; + protected string $text = ''; /** * @var int */ - protected $vat; + protected int $vat; /** * CalculationValue constructor. * - * @param int|float|double $number + * @param int|float $number * @param string $text * @param int $vat - * @param QUI\ERP\Currency\Currency $Currency + * @param QUI\ERP\Currency\Currency|null $Currency * @param int|bool $precision - The optional number of decimal digits to round to. */ - public function __construct($number, $text, $vat, $Currency = null, $precision = false) + public function __construct($number, $text, $vat, QUI\ERP\Currency\Currency $Currency = null, $precision = false) { parent::__construct($number, $Currency, $precision); @@ -49,7 +49,7 @@ public function __construct($number, $text, $vat, $Currency = null, $precision = * * @return string */ - public function getTitle() + public function getTitle(): string { return $this->text; } @@ -59,7 +59,7 @@ public function getTitle() * * @return int */ - public function getVat() + public function getVat(): int { return $this->vat; } diff --git a/src/QUI/ERP/Accounting/Calculations.php b/src/QUI/ERP/Accounting/Calculations.php index 6c38d4f0644365b240b7aed2d5bf08e9baa1697a..99e14319c4282d60ffc8be0c5f4946de3a5030d7 100644 --- a/src/QUI/ERP/Accounting/Calculations.php +++ b/src/QUI/ERP/Accounting/Calculations.php @@ -9,6 +9,8 @@ use QUI; use QUI\ERP\Exception; +use function is_array; + /** * Class Calculations * @@ -19,17 +21,17 @@ class Calculations /** * @var array */ - protected $attributes = []; + protected array $attributes = []; /** * @var Article[] */ - protected $articles = []; + protected array $articles = []; /** * @var QUI\ERP\Currency\Currency */ - protected $Currency; + protected QUI\ERP\Currency\Currency $Currency; /** * Calculations constructor. @@ -37,7 +39,7 @@ class Calculations * @param array $attributes - calculation array * @param array $articles - list of articles * - * @throws \QUI\ERP\Exception + * @throws Exception */ public function __construct($attributes, $articles = []) { @@ -69,7 +71,7 @@ public function __construct($attributes, $articles = []) $this->Currency = QUI\ERP\Defaults::getCurrency(); } - if (\is_array($articles)) { + if (is_array($articles)) { foreach ($articles as $Article) { if ($Article instanceof Article) { $this->articles[] = $Article; @@ -83,7 +85,7 @@ public function __construct($attributes, $articles = []) * * @return CalculationValue */ - public function getSum() + public function getSum(): CalculationValue { return new CalculationValue( $this->attributes['sum'], @@ -97,7 +99,7 @@ public function getSum() * * @return CalculationValue */ - public function getSubSum() + public function getSubSum(): CalculationValue { return new CalculationValue( $this->attributes['subSum'], @@ -111,7 +113,7 @@ public function getSubSum() * * @return CalculationValue */ - public function getNettoSum() + public function getNettoSum(): CalculationValue { return new CalculationValue( $this->attributes['nettoSum'], @@ -125,7 +127,7 @@ public function getNettoSum() * * @return CalculationValue */ - public function getNettoSubSum() + public function getNettoSubSum(): CalculationValue { return new CalculationValue( $this->attributes['nettoSubSum'], @@ -141,12 +143,12 @@ public function getNettoSubSum() * * @return CalculationValue */ - public function getVatSum() + public function getVatSum(): CalculationValue { $sum = 0; $vat = $this->attributes['vatArray']; - foreach ($vat as $pc => $data) { + foreach ($vat as $data) { $sum = $sum + $data['sum']; } @@ -172,7 +174,7 @@ public function getVatArray() * * @return CalculationVatValue[] */ - public function getVat() + public function getVat(): array { $result = []; @@ -194,7 +196,7 @@ public function getVat() /** * @return Article[] */ - public function getArticles() + public function getArticles(): array { return $this->articles; }