From 07d9e0b1f6085128ec8fa67ff70c2195448a2c5a Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 10 Jul 2017 16:16:17 +0100 Subject: [PATCH 4/7] Bug 18267 - Record tax rate on receipt from EDI Invoice As part of the newly introduced price fields there is also a tax_rate_on_receiving that needs setting. This records the main tax rate on receipting. Edifact has the potential to be more complex than Koha allows i.e. the line amount may be made of different amounts (incorporating servicing, etc) at different tax rates. This concentrates on the main tax rate. The tax rate will be receiced as a percentage value e.g. 20.00 need to convert to a decimal fraction 0.20 as assumed in Koha calculations --- Koha/EDI.pm | 6 ++++++ Koha/Edifact/Line.pm | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 75db70770e..d1e0d452ee 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -288,6 +288,10 @@ sub process_invoice { } my $price = _get_invoiced_price($line); + my $tax_rate = $line->tax_rate; + if ($tax_rate && $tax_rate->{rate} != 0) { + $tax_rate->{rate} /= 100; + } if ( $order->quantity > $line->quantity ) { my $ordered = $order->quantity; @@ -305,6 +309,7 @@ sub process_invoice { unitprice => $price, invoiceid => $invoiceid, datereceived => $msg_date, + tax_rate_on_receiving => $tax_rate->{rate}, } ); my $p_updates = @@ -324,6 +329,7 @@ sub process_invoice { $order->datereceived($msg_date); $order->invoiceid($invoiceid); $order->unitprice($price); + $order->tax_rate_on_receiving($tax_rate->{rate}); $order->orderstatus('complete'); my $p_updates = update_price_from_invoice( $order, $invoice_message->vendor_id ); diff --git a/Koha/Edifact/Line.pm b/Koha/Edifact/Line.pm index 05abfeeb13..ccb975cfa7 100644 --- a/Koha/Edifact/Line.pm +++ b/Koha/Edifact/Line.pm @@ -801,6 +801,30 @@ sub tax { return $self->moa_amt('124'); } +sub tax_rate { + my $self = shift; + my $tr = {}; + foreach my $s ( @{ $self->{segs} } ) { + if ( $s->tag eq 'TAX' && $s->elem( 0, 0 ) == 7 ) { + $tr->{type} = $s->elem( 1, 0 ); # VAT, GST or IMP + $tr->{rate} = $s->elem( 4, 3 ); # percentage + # category values may be: + # E = exempt from tax + # G = export item, tax not charged + # H = higher rate + # L = lower rate + # S = standard rate + # Z = zero-rated + $tr->{category} = $s->elem( 5, 0 ); + if (!defined $tr->{rate} && $tr->{category} eq 'Z') { + $tr->{rate} = 0; + } + return $tr; + } + } + return; +} + sub availability_date { my $self = shift; if ( exists $self->{availability_date} ) { -- 2.13.3