Bug 22898: Fix failure since bug 19618
[koha.git] / t / EdiInvoice.t
blob14e759648660b22265f226943cbfb66a7543fe62
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
6 use Test::More tests => 19;
8 BEGIN { use_ok('Koha::Edifact') }
10 my $invoice_file = "$Bin/edi_testfiles/BLSINV337023.CEI";
12 my $invoice = Koha::Edifact->new( { filename => $invoice_file, } );
14 isa_ok( $invoice, 'Koha::Edifact' );
15 my $x = $invoice->interchange_header('sender');
16 my $control_reference = '337023';
17 is( $x, '5013546025078', "sender returned" );
19 $x = $invoice->interchange_header('recipient');
20 is( $x, '5013546121974', "recipient returned" );
21 $x = $invoice->interchange_header('datetime');
22 is( $x->[0], '140729', "datetime returned" );
23 $x = $invoice->interchange_header('interchange_control_reference');
24 is( $x, $control_reference, "interchange_control_reference returned" );
26 $x = $invoice->interchange_header('application_reference');
27 is( $x, 'INVOIC', "application_reference returned" );
28 $x = $invoice->interchange_trailer('interchange_control_count');
29 is( $x, 6, "interchange_control_count returned" );
31 my $messages = $invoice->message_array();
33 # check inv number from BGM
35 my $msg_count = @{$messages};
36 is( $msg_count, 6, 'correct message count returned' );
38 is( $messages->[0]->message_type, 'INVOIC', 'Message shows correct type' );
40 my $expected_date = '20140729';
41 is( $messages->[0]->message_date,
42 $expected_date, 'Message date correctly returned' );
43 is( $messages->[0]->tax_point_date,
44 $expected_date, 'Tax point date correctly returned' );
46 my $expected_invoicenumber = '01975490';
48 my $invoicenumber = $messages->[1]->docmsg_number();
50 is( $messages->[0]->buyer_ean, '5013546121974', 'Buyer ean correct' );
51 is( $messages->[0]->supplier_ean, '5013546025078', 'Supplier ean correct' );
53 is( $invoicenumber, $expected_invoicenumber,
54 'correct invoicenumber extracted' );
56 my $lines = $messages->[1]->lineitems();
58 my $num_lines = @{$lines};
60 is( $num_lines, 8, "Correct number of lineitems returned" );
62 # sample invoice was from an early version where order was formatted basketno/ordernumber
63 my $expected_ordernumber = '2818/74593';
65 my $ordernumber = $lines->[7]->ordernumber;
67 is( $ordernumber, $expected_ordernumber, 'correct ordernumber returned' );
69 my $lineprice = $lines->[7]->price_net;
71 is( $lineprice, 4.55, 'correct net line price returned' );
73 my $tax = $lines->[7]->tax;
75 is( $tax, 0, 'correct tax amount returned' );