Skip to content
Code-Schnipsel Gruppen Projekte
Commit 511794c3 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix(phpstan): price calculation, logging, and file handling improvements

In this commit, several enhancements are made in the ajax price calculation PHP files including
more verbose error logging and minor refactoring of the calculation itself. Instead of adding an
error message in QUI, we now add detailed error handling using QUI\System\Log.

Additionally, we have improved file handling in `ajax/output/sendMail.php` by ensuring the file is
an instance of `QUI\Projects\Media\File` or `QUI\Projects\Media\Image` before attaching it.

Lastly, we added an option for parsing in method getCustomerFiles of the ErpEntityInterface. This
commit will make the scripts more efficient and robust against errors.
Übergeordneter dba1b6d6
No related branches found
No related tags found
2 Merge Requests!170Update 'next-4.x' with latest changes from 'main',!169fix(phpstan): added exception handling for missing html2pdf module in OutputTemplate
Pipeline #15503 mit Warnungen bestanden mit Phase
in 2 Minuten und 19 Sekunden
......@@ -7,6 +7,7 @@
use QUI\ERP\Tax\TaxEntry;
use QUI\ERP\Tax\TaxType;
use QUI\ERP\Tax\Utils as TaxUtils;
use QUI\System\Log;
/**
* Calculate the netto price
......@@ -20,18 +21,22 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_calcBruttoPrice',
function ($price, $formatted, $vat) {
$price = QUI\ERP\Money\Price::validatePrice($price);
$price = QUI\ERP\Money\Price::validatePrice($price);
$Currency = QUI\ERP\Defaults::getCurrency();
if (empty($vat)) {
$Area = QUI\ERP\Defaults::getArea();
$TaxType = TaxUtils::getTaxTypeByArea($Area);
$Area = QUI\ERP\Defaults::getArea();
if ($TaxType instanceof TaxType) {
try {
$TaxType = TaxUtils::getTaxTypeByArea($Area);
$TaxEntry = TaxUtils::getTaxEntry($TaxType, $Area);
} elseif ($TaxType instanceof TaxEntry) {
$TaxEntry = $TaxType;
} else {
} catch (QUI\Exception $e) {
Log::addError($e->getMessage(), [
'ajax' => 'package_quiqqer_erp_ajax_calcBruttoPrice',
'price' => $price,
'vat' => $vat
]);
if (isset($formatted) && $formatted) {
return $Currency->format($price);
}
......
......@@ -7,6 +7,7 @@
use QUI\ERP\Tax\TaxEntry;
use QUI\ERP\Tax\TaxType;
use QUI\ERP\Tax\Utils as TaxUtils;
use QUI\System\Log;
/**
* Calculate the netto price
......@@ -35,21 +36,15 @@ function ($price, $formatted, $vat) {
try {
$TaxType = TaxUtils::getTaxTypeByArea($Area);
$TaxEntry = TaxUtils::getTaxEntry($TaxType, $Area);
} catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addError($Exception->getMessage());
if (isset($formatted) && $formatted) {
return QUI\ERP\Defaults::getCurrency()->format($price);
}
Log::addError($Exception->getMessage(), [
'price' => $price,
'formatted' => $formatted,
'vat' => $vat,
'ajax' => 'package_quiqqer_erp_ajax_calcNettoPrice'
]);
return $price;
}
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);
}
......@@ -68,7 +63,7 @@ function ($price, $formatted, $vat) {
$precision = QUI\ERP\Defaults::getPrecision();
$bruttoInput = round($price, $precision);
$decimalParts = explode('.', $bruttoInput);
$decimalParts = explode('.', (string)$bruttoInput);
$inputPrecision = isset($decimalParts[1]) ? strlen($decimalParts[1]) : 0;
$brutto = round($netto, $precision) * $vat;
......@@ -80,7 +75,7 @@ function ($price, $formatted, $vat) {
if ($brutto != $bruttoInput) {
for ($i = 0; $i < 10; $i++) {
$nettoCheck = substr($netto, 0, -$precision);
$nettoCheck = (float)substr((string)$netto, 0, -$precision);
$bruttoCheck = round($nettoCheck * $vat, $inputPrecision);
if ($bruttoCheck == $bruttoInput) {
......
......@@ -16,6 +16,7 @@
'package_quiqqer_erp_ajax_customerFiles_getFiles',
function ($hash) {
$Entity = (new Processes())->getEntity($hash);
return $Entity->getCustomerFiles(true);
},
['hash']
......
......@@ -64,7 +64,11 @@ function (
}
try {
$attachedMediaFiles[] = $Media->get((int)$fileId);
$File = $Media->get((int)$fileId);
if ($File instanceof QUI\Projects\Media\File || $File instanceof QUI\Projects\Media\Image) {
$attachedMediaFiles[] = $File;
}
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
......
......@@ -117,5 +117,5 @@ public function addCustomerFile(string $fileHash, array $options = []): void;
public function clearCustomerFiles(): void;
public function getCustomerFiles(): array;
public function getCustomerFiles(bool $parsing = false): array;
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren