1 package Koha
::Edifact
::Message
;
3 # Copyright 2014,2015 PTFS-Europe Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use Koha
::Edifact
::Line
;
27 my ( $class, $data_array_ref ) = @_;
28 my $header = shift @
{$data_array_ref};
29 my $bgm = shift @
{$data_array_ref};
30 my $msg_function = $bgm->elem(2);
32 while ( $data_array_ref->[0]->tag eq 'DTM' ) {
33 push @
{$dtm}, shift @
{$data_array_ref};
37 function
=> $msg_function,
40 message_reference_number
=> $header->elem(0),
42 datasegs
=> $data_array_ref,
51 return $self->{message_reference_number
};
56 my $msg_function = $self->{bgm
}->elem(2);
57 if ( $msg_function == 9 ) {
60 elsif ( $msg_function == 7 ) {
61 return 'retransmission';
66 sub message_reference_number
{
68 return $self->{header
}->elem(0);
73 return $self->{header
}->elem( 1, 0 );
78 return $self->{bgm
}->elem( 0, 0 );
83 return $self->{bgm
}->elem(1);
89 # usually the first if not only dtm
90 foreach my $d ( @
{ $self->{dtm
} } ) {
91 if ( $d->elem( 0, 0 ) eq '137' ) {
92 return $d->elem( 0, 1 );
95 return; # this should not happen
100 if ( $self->message_type eq 'INVOIC' ) {
101 foreach my $d ( @
{ $self->{dtm
} } ) {
102 if ( $d->elem( 0, 0 ) eq '131' ) {
103 return $d->elem( 0, 1 );
112 if ( $self->message_type eq 'QUOTES' ) {
113 foreach my $d ( @
{ $self->{dtm
} } ) {
114 if ( $d->elem( 0, 0 ) eq '36' ) {
115 return $d->elem( 0, 1 );
122 sub shipment_charge
{
125 # A large number of different charges can be expressed at invoice and
126 # item level but the only one koha takes cognizance of is shipment
127 # should we wrap all invoice level charges into it??
128 if ( $self->message_type eq 'INVOIC' ) {
131 foreach my $s ( @
{ $self->{datasegs
} } ) {
132 if ( $s->tag eq 'LIN' ) {
135 if ( $s->tag eq 'ALC' ) {
136 if ( $s->elem(0) eq 'C' ) { # Its a charge
137 if ( $s->elem( 4, 0 ) eq 'DL' ) { # delivery charge
143 if ( $s->tag eq 'MOA' ) {
144 $amt += $s->elem( 0, 1 );
156 foreach my $s ( @
{ $self->{datasegs
} } ) {
157 if ( $s->tag eq 'LIN' ) {
160 if ( $s->tag eq 'NAD' ) {
161 my $qualifier = $s->elem(0);
162 if ( $qualifier eq 'BY' ) {
163 return $s->elem( 1, 0 );
172 foreach my $s ( @
{ $self->{datasegs
} } ) {
173 if ( $s->tag eq 'LIN' ) {
176 if ( $s->tag eq 'NAD' ) {
177 my $qualifier = $s->elem(0);
178 if ( $qualifier eq 'SU' ) {
179 return $s->elem( 1, 0 );
189 if ( $self->{quotation_lines
} ) {
190 return $self->{quotation_lines
};
195 foreach my $seg ( @
{ $self->{datasegs
} } ) {
197 if ( $tag eq 'LIN' ) {
198 if ( @
{$item_arr} ) {
199 push @
{$items}, Koha
::Edifact
::Line
->new($item_arr);
204 elsif ( $tag =~ m/^(UNS|CNT|UNT)$/sxm ) {
205 if ( @
{$item_arr} ) {
206 push @
{$items}, Koha
::Edifact
::Line
->new($item_arr);
211 if ( @
{$item_arr} ) {
212 push @
{$item_arr}, $seg;
216 $self->{quotation_lines
} = $items;
226 Koha::Edifact::Message
230 Class modelling an Edifact Message for parsing
236 Passed an array of segments extracts message level info
237 and parses lineitems as Line objects
241 Colin Campbell <colin.campbell@ptfs-europe.com>
245 Copyright 2014,2015 PTFS-Europe Ltd
246 This program is free software, You may redistribute it under
247 under the terms of the GNU General Public License