From f39943e2ea7dc4c15fc815e5ff7d245296358a7a Mon Sep 17 00:00:00 2001 From: Henning <leutz@pcsg.de> Date: Fri, 7 Mar 2025 08:00:38 +0100 Subject: [PATCH] fix: improve invoice handling for the electronic invoice This commit offers a more detailed pricing calculation, including Net and Gross pricing for the electronic invoice export. It adds essential support for VAT calculation for invoice articles. It also includes the quantity into the gross price calculation which was previously based only on the net price. This could help in maintaining proper financial records. We also replaced the implicit variable declaration with explicit variable assignment for better code readability. --- .../ERP/Accounting/Invoice/Utils/Invoice.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php b/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php index b925673..d75835a 100644 --- a/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php +++ b/src/QUI/ERP/Accounting/Invoice/Utils/Invoice.php @@ -663,6 +663,11 @@ public static function addressRequirementThreshold(): float return floatval($threshold); } + /** + * @throws QUI\ERP\Exception + * @throws QUI\Exception + * @throws QUI\Users\Exception + */ public static function getElectronicInvoice( InvoiceTemporary | QUI\ERP\Accounting\Invoice\Invoice $Invoice, $type = ZugferdProfiles::PROFILE_EN16931 @@ -828,9 +833,17 @@ public static function getElectronicInvoice( // products foreach ($Invoice->getArticles() as $Article) { - /* @var $Article QUI\ERP\Accounting\Article */ $article = $Article->toArray(); + $nettoPreis = $article['calculated']['nettoPrice']; // Netto-Einzelpreis + $vatSum = $article['calculated']['vatArray']['sum']; + $bruttoPreis = $nettoPreis; + + if ($vatSum) { + $bruttoPreis = $nettoPreis + ($vatSum / $article['quantity']); + } + + $document ->addNewPosition($article['position']) ->setDocumentPositionProductDetails( @@ -841,9 +854,10 @@ public static function getElectronicInvoice( null, null ) - ->setDocumentPositionNetPrice($article['calculated']['nettoPrice']) + ->setDocumentPositionNetPrice($article['calculated']['nettoPrice'], 1, "C62") // C62 = Stück + ->setDocumentPositionGrossPrice($bruttoPreis, 1, "C62") // C62 = Stück ->setDocumentPositionQuantity($article['quantity'], "H87") - ->addDocumentPositionTax('S', 'VAT', $article['vat']) + ->addDocumentPositionTax('S', 'VAT', $article['vat'], $article['calculated']['vatArray']['sum']) ->setDocumentPositionLineSummation($article['sum']); } -- GitLab