From c9f7b72426b8af225a2dc3c3f94a0fa7a1aa0fbc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jan 2023 21:59:38 +0100 Subject: [PATCH] Bug 25655: Store actual cost in foreign currency and currency from the invoice Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency. This new enhancement is storing the price and the currency in database, into two new columns invoice_unitprice an invoice_currency Test plan: Create a new order with several items to receive Receive one or more items, and tick "change currency" on the order receive page Select a currency and finish the receiving In DB notice that the price and the currency have been stored. Receive remaining items and confirm that the form is prefilled with previous price and currency Sponsored-by: The Research University in the Helmholtz Association (KIT) Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Order.pm | 3 +- acqui/finishreceive.pl | 32 ++++++++++++++++--- .../prog/en/modules/acqui/orderreceive.tt | 18 +++++------ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index b9059b0132..c73f977791 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -635,7 +635,8 @@ sub to_api_mapping { uncertainprice => 'uncertain_price', unitprice => 'unit_price', unitprice_tax_excluded => 'unit_price_tax_excluded', - unitprice_tax_included => 'unit_price_tax_included' + unitprice_tax_included => 'unit_price_tax_included', + invoice_unitprice => 'invoice_unit_price', }; } diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index b0dd1b7fae..3c9e87ca78 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -51,6 +51,8 @@ my $quantity = $input->param('quantity'); my $unitprice = $input->param('unitprice'); my $replacementprice = $input->param('replacementprice'); my $datereceived = $input->param('datereceived'); +my $invoice_unitprice = $input->param('invoice_unitprice'); +my $invoice_currency = $input->param('invoice_currency'); my $invoiceid = $input->param('invoiceid'); my $invoice = GetInvoice($invoiceid); my $invoiceno = $invoice->{invoicenumber}; @@ -98,10 +100,22 @@ if ($quantityrec > $origquantityrec ) { } } - $order_obj->order_internalnote(scalar $input->param("order_internalnote")); - $order_obj->tax_rate_on_receiving(scalar $input->param("tax_rate")); - $order_obj->replacementprice($replacementprice); - $order_obj->unitprice($unitprice); + $order_obj->set( + { + order_internalnote => scalar $input->param("order_internalnote"), + tax_rate_on_receiving => scalar $input->param("tax_rate"), + replacementprice => $replacementprice, + unitprice => $unitprice, + ( + defined $invoice_unitprice && $invoice_unitprice ne '' + ? ( + invoice_unitprice => $invoice_unitprice, + invoice_currency => $invoice_currency, + ) + : () + ), + } + ); $order_obj->populate_with_prices_for_receiving(); @@ -189,7 +203,15 @@ if (C4::Context->preference("AcquisitionLog")) { bookfund => $bookfund || 'unchanged', tax_rate => $input->param("tax_rate"), replacementprice => $replacementprice, - unitprice => $unitprice + unitprice => $unitprice, + ( + defined $invoice_unitprice && $invoice_unitprice ne '' + ? ( + invoice_unitprice => $invoice_unitprice, + invoice_currency => $invoice_currency, + ) + : () + ), }; logaction( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 894af69294..d06b3e3e37 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -428,13 +428,13 @@
  • - - + + [% IF currencies.count %] - + [% FOR currency IN currencies %] - + [% END %] [% END %] @@ -608,13 +608,13 @@ }).change(); function update_unitprice() { - var rate = Number($("select[name='currency'] option:selected").val()); - var unitprice = $("#unitprice_currency").val(); + var rate = Number($("select[name='invoice_currency'] option:selected").data('rate')); + var unitprice = $("#invoice_unitprice").val(); var new_unitprice = Number( unitprice * rate ).toFixed(2); $("#unitprice").val(new_unitprice); } - $("select[name='currency']").on("change", function(){update_unitprice()} ); - $("#unitprice_currency").on("change", function(){update_unitprice()} ); + $("select[name='invoice_currency']").on("change", function(){update_unitprice()} ); + $("#invoice_unitprice").on("change", function(){update_unitprice()} ); [% IF other_reason %] $(".select-reason").hide(); -- 2.39.5