From 70758975377daa308855ccc03cd43b5bfde2d3f4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Jul 2025 13:55:42 +0100 Subject: [PATCH] Bug 40387: Fix undefined tax rate warnings in EDI invoice processing When processing EDI invoices without TAX segments, warnings were generated due to undefined tax rates in multiplication operations. The tax_rate() method in Koha::Edifact::Line correctly returns undef when no TAX segments are present in the EDI message. However, the invoice processing code in Koha::EDI didn't handle this case properly. This patch fixes the issue by: - Adding checks for undefined tax rates before using them in calculations - Defaulting to 0 tax rate when no tax information is present - Ensuring tax_value calculations use 0 instead of undefined values This eliminates "Use of uninitialized value in multiplication" warnings while maintaining correct processing of invoices without tax information. Signed-off-by: David Nind --- Koha/EDI.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 6b485bf864c..4a36f15b384 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -414,8 +414,10 @@ sub process_invoice { unitprice_tax_excluded => $price_excl_tax, invoiceid => $invoiceid, datereceived => $msg_date, - tax_rate_on_receiving => $tax_rate->{rate}, - tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, + tax_rate_on_receiving => $tax_rate ? $tax_rate->{rate} : 0, + tax_value_on_receiving => $quantity * + $price_excl_tax * + ( $tax_rate ? $tax_rate->{rate} : 0 ), } ); transfer_items( $schema, $line, $order, $received_order, $quantity ); @@ -430,8 +432,9 @@ sub process_invoice { $order->unitprice($price); $order->unitprice_tax_excluded($price_excl_tax); $order->unitprice_tax_included($price); - $order->tax_rate_on_receiving( $tax_rate->{rate} ); - $order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate} ); + $order->tax_rate_on_receiving( $tax_rate ? $tax_rate->{rate} : 0 ); + $order->tax_value_on_receiving( + $quantity * $price_excl_tax * ( $tax_rate ? $tax_rate->{rate} : 0 ) ); $order->orderstatus('complete'); $order->update; receipt_items( $schema, $line, $ordernumber, $quantity, $invoice_message ); -- 2.39.5