From 8e2b00143a891d99ae48bbeb84aa8587af25d641 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Tue, 21 Mar 2017 13:49:12 +0000 Subject: [PATCH 3/3] Bug 18267 - Record tax rate on receipt from EDI Invoice 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. --- Koha/EDI.pm | 3 +++ Koha/Edifact/Line.pm | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 6f0680c..f68cf7f 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -288,6 +288,7 @@ sub process_invoice { } my $price = _get_invoiced_price($line); + my $tax_rate = $line->tax_rate; if ( $order->quantity > $line->quantity ) { my $ordered = $order->quantity; @@ -305,6 +306,7 @@ sub process_invoice { unitprice => $price, invoiceid => $invoiceid, datereceived => $msg_date, + tax_rate_on_receiving => $trax_rate->{rate}, } ); my $p_updates = @@ -324,6 +326,7 @@ sub process_invoice { $order->datereceived($msg_date); $order->invoiceid($invoiceid); $order->unitprice($price); + $order->tax_rate_on_receiving($trax_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 5f51284..3205608 100644 --- a/Koha/Edifact/Line.pm +++ b/Koha/Edifact/Line.pm @@ -804,6 +804,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.9.3