View | Details | Raw Unified | Return to bug 17279
Collapse All | Expand All

(-)a/Koha/EDI.pm (-10 / +10 lines)
Lines 264-270 sub process_invoice { Link Here
264
            foreach my $line ( @{$lines} ) {
264
            foreach my $line ( @{$lines} ) {
265
                my $ordernumber = $line->ordernumber;
265
                my $ordernumber = $line->ordernumber;
266
                $logger->trace( "Receipting order:$ordernumber Qty: ",
266
                $logger->trace( "Receipting order:$ordernumber Qty: ",
267
                    $line->quantity );
267
                    $line->quantity_invoiced );
268
268
269
                my $order = $schema->resultset('Aqorder')->find($ordernumber);
269
                my $order = $schema->resultset('Aqorder')->find($ordernumber);
270
270
Lines 288-305 sub process_invoice { Link Here
288
288
289
                    my $price = _get_invoiced_price($line);
289
                    my $price = _get_invoiced_price($line);
290
290
291
                    if ( $order->quantity > $line->quantity ) {
291
                    if ( $order->quantity > $line->quantity_invoiced ) {
292
                        my $ordered = $order->quantity;
292
                        my $ordered = $order->quantity;
293
293
294
                        # part receipt
294
                        # part receipt
295
                        $order->orderstatus('partial');
295
                        $order->orderstatus('partial');
296
                        $order->quantity( $ordered - $line->quantity );
296
                        $order->quantity( $ordered - $line->quantity_invoiced );
297
                        $order->update;
297
                        $order->update;
298
                        my $received_order = $order->copy(
298
                        my $received_order = $order->copy(
299
                            {
299
                            {
300
                                ordernumber      => undef,
300
                                ordernumber      => undef,
301
                                quantity         => $line->quantity,
301
                                quantity         => $line->quantity_invoiced,
302
                                quantityreceived => $line->quantity,
302
                                quantityreceived => $line->quantity_invoiced,
303
                                orderstatus      => 'complete',
303
                                orderstatus      => 'complete',
304
                                unitprice        => $price,
304
                                unitprice        => $price,
305
                                invoiceid        => $invoiceid,
305
                                invoiceid        => $invoiceid,
Lines 312-318 sub process_invoice { Link Here
312
                            $received_order->ordernumber );
312
                            $received_order->ordernumber );
313
                    }
313
                    }
314
                    else {    # simple receipt all copies on order
314
                    else {    # simple receipt all copies on order
315
                        $order->quantityreceived( $line->quantity );
315
                        $order->quantityreceived( $line->quantity_invoiced );
316
                        $order->datereceived($msg_date);
316
                        $order->datereceived($msg_date);
317
                        $order->invoiceid($invoiceid);
317
                        $order->invoiceid($invoiceid);
318
                        $order->unitprice($price);
318
                        $order->unitprice($price);
Lines 343-350 sub _get_invoiced_price { Link Here
343
    my $price = $line->price_net;
343
    my $price = $line->price_net;
344
    if ( !defined $price ) {  # no net price so generate it from lineitem amount
344
    if ( !defined $price ) {  # no net price so generate it from lineitem amount
345
        $price = $line->amt_lineitem;
345
        $price = $line->amt_lineitem;
346
        if ( $price and $line->quantity > 1 ) {
346
        if ( $price and $line->quantity_invoiced > 1 ) {
347
            $price /= $line->quantity;    # div line cost by qty
347
            $price /= $line->quantity_invoiced;    # div line cost by qty
348
        }
348
        }
349
    }
349
    }
350
    return $price;
350
    return $price;
Lines 353-359 sub _get_invoiced_price { Link Here
353
sub receipt_items {
353
sub receipt_items {
354
    my ( $schema, $inv_line, $ordernumber ) = @_;
354
    my ( $schema, $inv_line, $ordernumber ) = @_;
355
    my $logger   = Log::Log4perl->get_logger();
355
    my $logger   = Log::Log4perl->get_logger();
356
    my $quantity = $inv_line->quantity;
356
    my $quantity = $inv_line->quantity_invoiced;
357
357
358
    # itemnumber is not a foreign key ??? makes this a bit cumbersome
358
    # itemnumber is not a foreign key ??? makes this a bit cumbersome
359
    my @item_links = $schema->resultset('AqordersItem')->search(
359
    my @item_links = $schema->resultset('AqordersItem')->search(
Lines 413-419 sub transfer_items { Link Here
413
    my ( $schema, $inv_line, $order_from, $order_to ) = @_;
413
    my ( $schema, $inv_line, $order_from, $order_to ) = @_;
414
414
415
    # Transfer x items from the orig order to a completed partial order
415
    # Transfer x items from the orig order to a completed partial order
416
    my $quantity = $inv_line->quantity;
416
    my $quantity = $inv_line->quantity_invoiced;
417
    my $gocc     = 0;
417
    my $gocc     = 0;
418
    my %mapped_by_branch;
418
    my %mapped_by_branch;
419
    while ( $gocc < $quantity ) {
419
    while ( $gocc < $quantity ) {
(-)a/Koha/Edifact/Line.pm (-2 / +14 lines)
Lines 64-70 sub _parse_lines { Link Here
64
            push @item_description, $s;
64
            push @item_description, $s;
65
        }
65
        }
66
        elsif ( $s->tag eq 'QTY' ) {
66
        elsif ( $s->tag eq 'QTY' ) {
67
            $d->{quantity} = $s->elem( 0, 1 );
67
            if ( $s->elem( 0, 0 ) eq '47' ) {
68
                $d->{quantity_invoiced} = $s->elem( 0, 1 );
69
            }
70
            elsif ( $s->elem( 0, 0 ) eq '1' )
71
            {    # In quotes used for copies quoted
72
                # Used elsewhere as well  (e.g. credit notes )
73
                $d->{discrete_quantity} = $s->elem( 0, 1 );
74
            }
68
        }
75
        }
69
        elsif ( $s->tag eq 'DTM' ) {
76
        elsif ( $s->tag eq 'DTM' ) {
70
            if ( $s->elem( 0, 0 ) eq '44' ) {
77
            if ( $s->elem( 0, 0 ) eq '44' ) {
Lines 374-382 sub monetary_amount { Link Here
374
    return $self->{monetary_amount};
381
    return $self->{monetary_amount};
375
}
382
}
376
383
384
sub quantity_invoiced {
385
    my $self = shift;
386
    return $self->{quantity_invoiced};
387
}
388
377
sub quantity {
389
sub quantity {
378
    my $self = shift;
390
    my $self = shift;
379
    return $self->{quantity};
391
    return $self->{discrete_quantity};
380
}
392
}
381
393
382
sub price {
394
sub price {
(-)a/t/EdiInvoice.t (-1 / +3 lines)
Lines 3-9 use strict; Link Here
3
use warnings;
3
use warnings;
4
use FindBin qw( $Bin );
4
use FindBin qw( $Bin );
5
5
6
use Test::More tests => 19;
6
use Test::More tests => 20;
7
7
8
BEGIN { use_ok('Koha::Edifact') }
8
BEGIN { use_ok('Koha::Edifact') }
9
9
Lines 73-75 is( $lineprice, 4.55, 'correct net line price returned' ); Link Here
73
my $tax = $lines->[7]->tax;
73
my $tax = $lines->[7]->tax;
74
74
75
is( $tax, 0, 'correct tax amount returned' );
75
is( $tax, 0, 'correct tax amount returned' );
76
77
is( $lines->[7]->quantity_invoiced, 1, 'line quantity invoiced returned' );
(-)a/t/Edifact.t (-3 / +3 lines)
Lines 3-9 use strict; Link Here
3
use warnings;
3
use warnings;
4
use FindBin qw( $Bin );
4
use FindBin qw( $Bin );
5
5
6
use Test::More tests => 34;
6
use Test::More tests => 35;
7
7
8
BEGIN { use_ok('Koha::Edifact') }
8
BEGIN { use_ok('Koha::Edifact') }
9
9
Lines 50-56 my $test_line = $lin->[-1]; Link Here
50
50
51
is( $test_line->line_item_number, 18, 'correct line number returned' );
51
is( $test_line->line_item_number, 18, 'correct line number returned' );
52
is( $test_line->item_number_id, '9780273761006', 'correct ean returned' );
52
is( $test_line->item_number_id, '9780273761006', 'correct ean returned' );
53
is( $test_line->quantity, 1, 'quantity returned' );
53
is( $test_line->quantity_invoiced, undef, 'quantity invoiced not returned as expected' );
54
is( $test_line->quantity, 1, 'discrete quantity returned' );
54
55
55
my $test_title = 'International business [electronic resource]';
56
my $test_title = 'International business [electronic resource]';
56
my $marcrec    = $test_line->marc_record;
57
my $marcrec    = $test_line->marc_record;
57
- 

Return to bug 17279