4 use FindBin qw( $Bin );
6 use Test::More tests => 26;
9 BEGIN { use_ok('Koha::Edifact') }
11 my $invoice_file = "$Bin/edi_testfiles/BLSINV337023.CEI";
13 my $invoice = Koha::Edifact->new( { filename => $invoice_file, } );
15 isa_ok( $invoice, 'Koha::Edifact' );
16 my $x = $invoice->interchange_header('sender');
17 my $control_reference = '337023';
18 is( $x, '5013546025078', "sender returned" );
20 $x = $invoice->interchange_header('recipient');
21 is( $x, '5013546121974', "recipient returned" );
22 $x = $invoice->interchange_header('datetime');
23 is( $x->[0], '140729', "datetime returned" );
24 $x = $invoice->interchange_header('interchange_control_reference');
25 is( $x, $control_reference, "interchange_control_reference returned" );
27 $x = $invoice->interchange_header('application_reference');
28 is( $x, 'INVOIC', "application_reference returned" );
29 $x = $invoice->interchange_trailer('interchange_control_count');
30 is( $x, 6, "interchange_control_count returned" );
32 my $messages = $invoice->message_array();
34 # check inv number from BGM
36 my $msg_count = @{$messages};
37 is( $msg_count, 6, 'correct message count returned' );
39 is( $messages->[0]->message_type, 'INVOIC', 'Message shows correct type' );
41 my $expected_date = '20140729';
42 is( $messages->[0]->message_date,
43 $expected_date, 'Message date correctly returned' );
44 is( $messages->[0]->tax_point_date,
45 $expected_date, 'Tax point date correctly returned' );
47 my $expected_invoicenumber = '01975490';
49 my $invoicenumber = $messages->[1]->docmsg_number();
51 is( $messages->[0]->buyer_ean, '5013546121974', 'Buyer ean correct' );
52 is( $messages->[0]->supplier_ean, '5013546025078', 'Supplier ean correct' );
54 is( $invoicenumber, $expected_invoicenumber,
55 'correct invoicenumber extracted' );
57 my $lines = $messages->[1]->lineitems();
59 my $num_lines = @{$lines};
61 is( $num_lines, 8, "Correct number of lineitems returned" );
63 # sample invoice was from an early version where order was formatted basketno/ordernumber
64 my $expected_ordernumber = '2818/74593';
66 my $ordernumber = $lines->[7]->ordernumber;
68 is( $ordernumber, $expected_ordernumber, 'correct ordernumber returned' );
70 my $lineprice = $lines->[7]->price_net;
72 is( $lineprice, 4.55, 'correct net line price returned' );
74 $lineprice = $lines->[7]->price_gross;
76 is( $lineprice, 7.99, 'correct gross line price returned' );
78 my $tax = $lines->[7]->tax;
80 is( $tax, 0, 'correct tax amount returned' );
82 my $tax_rate = $lines->[7]->tax_rate;
84 is( $tax_rate->{rate}, 0.0, 'correct tax rate returned' );
86 my $tax_on_charge = $lines->[7]->amt_taxoncharge;
88 is( $tax_on_charge, 0, 'correct tax on charge value returned' );
90 my $qty_invoiced = $lines->[7]->quantity_invoiced;
92 is( $qty_invoiced, 1, 'quantity_invoiced returns correct value' );
94 my ($lt, $excl) = Koha::EDI::_get_invoiced_price($lines->[7], 1);
95 is( $lt, 4.55, 'invoiced price calculated');
96 is($excl, 4.55, 'Price excluding tax returned correctly');
98 ($lt, $excl) = Koha::EDI::_get_invoiced_price($lines->[7], 2);
99 is( $lt, 4.55 / 2, 'invoiced pricei calculated for copies > 1');