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

(-)a/C4/Acquisition.pm (-134 lines)
Lines 67-73 BEGIN { Link Here
67
      GetOrderFromItemnumber
67
      GetOrderFromItemnumber
68
      SearchOrders GetHistory GetRecentAcqui
68
      SearchOrders GetHistory GetRecentAcqui
69
      ModReceiveOrder CancelReceipt
69
      ModReceiveOrder CancelReceipt
70
      populate_order_with_prices
71
      TransferOrder
70
      TransferOrder
72
      ModItemOrder
71
      ModItemOrder
73
72
Lines 2825-2963 sub GetBiblioCountByBasketno { Link Here
2825
    return $sth->fetchrow;
2824
    return $sth->fetchrow;
2826
}
2825
}
2827
2826
2828
=head3 populate_order_with_prices
2829
2830
$order = populate_order_with_prices({
2831
    order        => $order #a hashref with the order values
2832
    booksellerid => $booksellerid #FIXME - should obtain from order basket
2833
    receiving    => 1 # boolean representing order stage, should pass only this or ordering
2834
    ordering     => 1 # boolean representing order stage
2835
});
2836
2837
2838
Sets calculated values for an order - all values are stored with full precision
2839
regardless of rounding preference except for tax value which is calculated
2840
on rounded values if requested
2841
2842
For ordering the values set are:
2843
    rrp_tax_included
2844
    rrp_tax_excluded
2845
    ecost_tax_included
2846
    ecost_tax_excluded
2847
    tax_value_on_ordering
2848
For receiving the value set are:
2849
    unitprice_tax_included
2850
    unitprice_tax_excluded
2851
    tax_value_on_receiving
2852
2853
Note: When receiving, if the rounded value of the unitprice matches the rounded
2854
value of the ecost then then ecost (full precision) is used.
2855
2856
Returns a hashref of the order
2857
2858
FIXME: Move this to Koha::Acquisition::Order.pm
2859
2860
=cut
2861
2862
sub populate_order_with_prices {
2863
    my ($params) = @_;
2864
2865
    my $order        = $params->{order};
2866
    my $booksellerid = $params->{booksellerid};
2867
    return unless $booksellerid;
2868
2869
    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
2870
2871
    my $receiving = $params->{receiving};
2872
    my $ordering  = $params->{ordering};
2873
    my $discount  = $order->{discount};
2874
    $discount /= 100 if $discount > 1;
2875
2876
    if ($ordering) {
2877
        $order->{tax_rate_on_ordering} //= $order->{tax_rate};
2878
        if ( $bookseller->listincgst ) {
2879
2880
            # The user entered the prices tax included
2881
            $order->{unitprice} += 0;
2882
            $order->{unitprice_tax_included} = $order->{unitprice};
2883
            $order->{rrp_tax_included} = $order->{rrp};
2884
2885
            # price tax excluded = price tax included / ( 1 + tax rate )
2886
            $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
2887
            $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
2888
2889
            # ecost tax included = rrp tax included  ( 1 - discount )
2890
            $order->{ecost_tax_included} = $order->{rrp_tax_included} * ( 1 - $discount );
2891
2892
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
2893
            $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
2894
2895
            # tax value = quantity * ecost tax excluded * tax rate
2896
            # we should use the unitprice if included
2897
            my $cost_tax_included = $order->{unitprice_tax_included} == 0 ? $order->{ecost_tax_included} : $order->{unitprice_tax_included};
2898
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} == 0 ? $order->{ecost_tax_excluded} : $order->{unitprice_tax_excluded};
2899
            $order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity};
2900
2901
        }
2902
        else {
2903
            # The user entered the prices tax excluded
2904
            $order->{unitprice_tax_excluded} = $order->{unitprice};
2905
            $order->{rrp_tax_excluded} = $order->{rrp};
2906
2907
            # price tax included = price tax excluded * ( 1 - tax rate )
2908
            $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
2909
            $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
2910
2911
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
2912
            $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
2913
2914
            # ecost tax included = rrp tax excluded * ( 1 + tax rate ) * ( 1 - discount ) = ecost tax excluded * ( 1 + tax rate )
2915
            $order->{ecost_tax_included} = $order->{ecost_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
2916
2917
            # tax value = quantity * ecost tax included * tax rate
2918
            # we should use the unitprice if included
2919
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} == 0 ?  $order->{ecost_tax_excluded} : $order->{unitprice_tax_excluded};
2920
            $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering};
2921
        }
2922
    }
2923
2924
    if ($receiving) {
2925
        $order->{tax_rate_on_receiving} //= $order->{tax_rate};
2926
        if ( $bookseller->invoiceincgst ) {
2927
            # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
2928
            # we need to keep the exact ecost value
2929
            if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) {
2930
                $order->{unitprice} = $order->{ecost_tax_included};
2931
            }
2932
2933
            # The user entered the unit price tax included
2934
            $order->{unitprice_tax_included} = $order->{unitprice};
2935
2936
            # unit price tax excluded = unit price tax included / ( 1 + tax rate )
2937
            $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_receiving} );
2938
        }
2939
        else {
2940
            # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
2941
            # we need to keep the exact ecost value
2942
            if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_excluded} )->round ) {
2943
                $order->{unitprice} = $order->{ecost_tax_excluded};
2944
            }
2945
2946
            # The user entered the unit price tax excluded
2947
            $order->{unitprice_tax_excluded} = $order->{unitprice};
2948
2949
2950
            # unit price tax included = unit price tax included * ( 1 + tax rate )
2951
            $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_receiving} );
2952
        }
2953
2954
        # tax value = quantity * unit price tax excluded * tax rate
2955
        $order->{tax_value_on_receiving} = $order->{quantity} * get_rounded_price($order->{unitprice_tax_excluded}) * $order->{tax_rate_on_receiving};
2956
    }
2957
2958
    return $order;
2959
}
2960
2961
=head3 GetOrderUsers
2827
=head3 GetOrderUsers
2962
2828
2963
    $order_users_ids = &GetOrderUsers($ordernumber);
2829
    $order_users_ids = &GetOrderUsers($ordernumber);
(-)a/Koha/Acquisition/Order.pm (+129 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp qw( croak );
20
use Carp qw( croak );
21
21
22
use C4::Biblio qw( DelBiblio );
22
use C4::Biblio qw( DelBiblio );
23
use C4::Acquisition;
23
24
24
use Koha::Acquisition::Baskets;
25
use Koha::Acquisition::Baskets;
25
use Koha::Acquisition::Funds;
26
use Koha::Acquisition::Funds;
Lines 31-36 use Koha::Exceptions::Object; Link Here
31
use Koha::Biblios;
32
use Koha::Biblios;
32
use Koha::Holds;
33
use Koha::Holds;
33
use Koha::Items;
34
use Koha::Items;
35
use Koha::Number::Price;
34
use Koha::Subscriptions;
36
use Koha::Subscriptions;
35
37
36
use base qw(Koha::Object);
38
use base qw(Koha::Object);
Lines 457-462 sub duplicate_to { Link Here
457
    return $new_order;
459
    return $new_order;
458
}
460
}
459
461
462
=head3 populate_with_prices_for_ordering
463
464
Sets calculated values for an order - all values are stored with full precision
465
regardless of rounding preference except for tax value which is calculated on
466
rounded values if requested
467
468
    $order->populate_with_prices_for_ordering()
469
470
The values set are:
471
    rrp_tax_included
472
    rrp_tax_excluded
473
    ecost_tax_included
474
    ecost_tax_excluded
475
    tax_value_on_ordering
476
477
=cut
478
479
sub populate_with_prices_for_ordering {
480
    my ($self) = @_;
481
482
    my $bookseller = $self->basket->bookseller;
483
    return unless $bookseller;
484
485
    my $discount = $self->discount || 0;
486
    $discount /= 100 if $discount > 1;
487
488
    if ( $bookseller->listincgst ) {
489
        # The user entered the prices tax included
490
        $self->unitprice($self->unitprice + 0);
491
        $self->unitprice_tax_included($self->unitprice);
492
        $self->rrp_tax_included($self->rrp);
493
494
        # price tax excluded = price tax included / ( 1 + tax rate )
495
        $self->unitprice_tax_excluded( $self->unitprice_tax_included / ( 1 + $self->tax_rate_on_ordering ) );
496
        $self->rrp_tax_excluded( $self->rrp_tax_included / ( 1 + $self->tax_rate_on_ordering ) );
497
498
        # ecost tax included = rrp tax included  ( 1 - discount )
499
        $self->ecost_tax_included($self->rrp_tax_included * ( 1 - $discount ));
500
501
        # ecost tax excluded = rrp tax excluded * ( 1 - discount )
502
        $self->ecost_tax_excluded($self->rrp_tax_excluded * ( 1 - $discount ));
503
504
        # tax value = quantity * ecost tax excluded * tax rate
505
        # we should use the unitprice if included
506
        my $cost_tax_included = $self->unitprice_tax_included == 0 ? $self->ecost_tax_included : $self->unitprice_tax_included;
507
        my $cost_tax_excluded = $self->unitprice_tax_excluded == 0 ? $self->ecost_tax_excluded : $self->unitprice_tax_excluded;
508
        $self->tax_value_on_ordering( ( C4::Acquisition::get_rounded_price($cost_tax_included) - C4::Acquisition::get_rounded_price($cost_tax_excluded) ) * $self->quantity );
509
    } else {
510
        # The user entered the prices tax excluded
511
        $self->unitprice_tax_excluded($self->unitprice);
512
        $self->rrp_tax_excluded($self->rrp);
513
514
        # price tax included = price tax excluded * ( 1 - tax rate )
515
        $self->unitprice_tax_included($self->unitprice_tax_excluded * ( 1 + $self->tax_rate_on_ordering ));
516
        $self->rrp_tax_included($self->rrp_tax_excluded * ( 1 + $self->tax_rate_on_ordering ));
517
518
        # ecost tax excluded = rrp tax excluded * ( 1 - discount )
519
        $self->ecost_tax_excluded($self->rrp_tax_excluded * ( 1 - $discount ));
520
521
        # ecost tax included = rrp tax excluded * ( 1 + tax rate ) * ( 1 - discount ) = ecost tax excluded * ( 1 + tax rate )
522
        $self->ecost_tax_included($self->ecost_tax_excluded * ( 1 + $self->tax_rate_on_ordering ));
523
524
        # tax value = quantity * ecost tax included * tax rate
525
        # we should use the unitprice if included
526
        my $cost_tax_excluded = $self->unitprice_tax_excluded == 0 ? $self->ecost_tax_excluded : $self->unitprice_tax_excluded;
527
        $self->tax_value_on_ordering($self->quantity * C4::Acquisition::get_rounded_price($cost_tax_excluded) * $self->tax_rate_on_ordering);
528
    }
529
}
530
531
=head3 populate_with_prices_for_receiving
532
533
Sets calculated values for an order - all values are stored with full precision
534
regardless of rounding preference except for tax value which is calculated on
535
rounded values if requested
536
537
    $order->populate_with_prices_for_receiving()
538
539
The values set are:
540
    unitprice_tax_included
541
    unitprice_tax_excluded
542
    tax_value_on_receiving
543
544
Note: When receiving, if the rounded value of the unitprice matches the rounded
545
value of the ecost then then ecost (full precision) is used.
546
547
=cut
548
549
sub populate_with_prices_for_receiving {
550
    my ($self) = @_;
551
552
    my $bookseller = $self->basket->bookseller;
553
    return unless $bookseller;
554
555
    my $discount = $self->discount || 0;
556
    $discount /= 100 if $discount > 1;
557
558
    if ($bookseller->invoiceincgst) {
559
        # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
560
        # we need to keep the exact ecost value
561
        if ( Koha::Number::Price->new( $self->unitprice )->round == Koha::Number::Price->new( $self->ecost_tax_included )->round ) {
562
            $self->unitprice($self->ecost_tax_included);
563
        }
564
565
        # The user entered the unit price tax included
566
        $self->unitprice_tax_included($self->unitprice);
567
568
        # unit price tax excluded = unit price tax included / ( 1 + tax rate )
569
        $self->unitprice_tax_excluded($self->unitprice_tax_included / ( 1 + $self->tax_rate_on_receiving ));
570
    } else {
571
        # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
572
        # we need to keep the exact ecost value
573
        if ( Koha::Number::Price->new($self->unitprice)->round == Koha::Number::Price->new($self->ecost_tax_excluded)->round ) {
574
            $self->unitprice($self->ecost_tax_excluded);
575
        }
576
577
        # The user entered the unit price tax excluded
578
        $self->unitprice_tax_excluded($self->unitprice);
579
580
581
        # unit price tax included = unit price tax included * ( 1 + tax rate )
582
        $self->unitprice_tax_included($self->unitprice_tax_excluded * ( 1 + $self->tax_rate_on_receiving ));
583
    }
584
585
    # tax value = quantity * unit price tax excluded * tax rate
586
    $self->tax_value_on_receiving($self->quantity * C4::Acquisition::get_rounded_price($self->unitprice_tax_excluded) * $self->tax_rate_on_receiving);
587
}
588
460
=head3 to_api_mapping
589
=head3 to_api_mapping
461
590
462
This method returns the mapping for representing a Koha::Acquisition::Order object
591
This method returns the mapping for representing a Koha::Acquisition::Order object
(-)a/acqui/addorder.pl (-58 / +63 lines)
Lines 72-78 the ISBN of the record ordered. Link Here
72
=item C<quantity>
72
=item C<quantity>
73
the quantity to order.
73
the quantity to order.
74
74
75
=item C<list_price>
75
=item C<listprice>
76
the price of this order.
76
the price of this order.
77
77
78
=item C<uncertainprice>
78
=item C<uncertainprice>
Lines 121-127 use Modern::Perl; Link Here
121
use CGI qw ( -utf8 );
121
use CGI qw ( -utf8 );
122
use JSON qw ( to_json encode_json );
122
use JSON qw ( to_json encode_json );
123
use C4::Auth qw( get_template_and_user );
123
use C4::Auth qw( get_template_and_user );
124
use C4::Acquisition qw( FillWithDefaultValues populate_order_with_prices ModOrder ModOrderUsers );
124
use C4::Acquisition qw( FillWithDefaultValues ModOrderUsers );
125
use C4::Suggestions qw( ModSuggestion );
125
use C4::Suggestions qw( ModSuggestion );
126
use C4::Biblio qw(
126
use C4::Biblio qw(
127
    AddBiblio
127
    AddBiblio
Lines 228-236 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
228
);
228
);
229
229
230
# get CGI parameters
230
# get CGI parameters
231
my $orderinfo = $input->Vars;
231
my $orderinfo = {
232
$orderinfo->{'list_price'}    ||=  0;
232
    ordernumber => scalar $input->param('ordernumber'),
233
$orderinfo->{'uncertainprice'} ||= 0;
233
    basketno => scalar $input->param('basketno'),
234
    biblionumber => scalar $input->param('biblionumber'),
235
    invoiceid => scalar $input->param('invoiceid'),
236
    quantity => scalar $input->param('quantity'),
237
    budget_id => scalar $input->param('budget_id'),
238
    currency => scalar $input->param('currency'),
239
    listprice => scalar $input->param('listprice'),
240
    uncertainprice => scalar $input->param('uncertainprice'),
241
    tax_rate_on_ordering => scalar $input->param('tax_rate'),
242
    discount => scalar $input->param('discount'),
243
    rrp => scalar $input->param('rrp'),
244
    replacementprice => scalar $input->param('replacementprice'),
245
    ecost => scalar $input->param('ecost'),
246
    unitprice => scalar $input->param('unitprice'),
247
    order_internalnote => scalar $input->param('order_internalnote'),
248
    order_vendornote => scalar $input->param('order_vendornote'),
249
    sort1 => scalar $input->param('sort1'),
250
    sort2 => scalar $input->param('sort2'),
251
    subscriptionid => scalar $input->param('subscriptionid'),
252
};
253
254
$orderinfo->{uncertainprice} ||= 0;
234
$orderinfo->{subscriptionid} ||= undef;
255
$orderinfo->{subscriptionid} ||= undef;
235
256
236
my $user     = $input->remote_user;
257
my $user     = $input->remote_user;
Lines 272-289 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
272
            #if it doesn't create it
293
            #if it doesn't create it
273
            $record = TransformKohaToMarc(
294
            $record = TransformKohaToMarc(
274
                {
295
                {
275
                    "biblio.title"                => "$$orderinfo{title}",
296
                    "biblio.title"                => $input->param('title') || '',
276
                    "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}        : "",
297
                    "biblio.author"               => $input->param('author') || '',
277
                    "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}        : "",
298
                    "biblio.seriestitle"          => $input->param('series') || '',
278
                    "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}          : "",
299
                    "biblioitems.isbn"            => $input->param('isbn') || '',
279
                    "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}           : "",
300
                    "biblioitems.ean"             => $input->param('ean') || '',
280
                    "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode} : "",
301
                    "biblioitems.publishercode"   => $input->param('publishercode') || '',
281
                    "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
302
                    "biblioitems.publicationyear" => $input->param('publicationyear') || '',
282
                    "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
303
                    "biblio.copyrightdate"        => $input->param('publicationyear') || '',
283
                    "biblioitems.itemtype"        => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
304
                    "biblioitems.itemtype"        => $input->param('itemtype') || '',
284
                    "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
305
                    "biblioitems.editionstatement"=> $input->param('editionstatement') || '',
285
                });
306
                }
286
307
            );
287
        }
308
        }
288
        C4::Acquisition::FillWithDefaultValues( $record );
309
        C4::Acquisition::FillWithDefaultValues( $record );
289
310
Lines 294-303 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
294
    }
315
    }
295
316
296
    # change suggestion status if applicable
317
    # change suggestion status if applicable
297
    if ( $orderinfo->{suggestionid} ) {
318
    if ( my $suggestionid = $input->param('suggestionid') ) {
298
        ModSuggestion(
319
        ModSuggestion(
299
            {
320
            {
300
                suggestionid => $orderinfo->{suggestionid},
321
                suggestionid => $suggestionid,
301
                biblionumber => $orderinfo->{biblionumber},
322
                biblionumber => $orderinfo->{biblionumber},
302
                STATUS       => 'ORDERED',
323
                STATUS       => 'ORDERED',
303
            }
324
            }
Lines 306-352 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
306
327
307
    $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
328
    $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
308
329
309
    $orderinfo = C4::Acquisition::populate_order_with_prices(
330
    my $order;
310
        {
331
    my $log_action_name;
311
            order        => $orderinfo,
312
            booksellerid => $orderinfo->{booksellerid},
313
            ordering     => 1,
314
        }
315
    );
316
317
    # if we already have $ordernumber, then it's an ordermodif
318
    my $order = Koha::Acquisition::Order->new($orderinfo);
319
    if ( $orderinfo->{ordernumber} ) {
332
    if ( $orderinfo->{ordernumber} ) {
320
        ModOrder($orderinfo);
333
        $order = Koha::Acquisition::Orders->find($orderinfo->{ordernumber});
321
        # Log the order modification
334
        $order->set($orderinfo);
322
        if (C4::Context->preference("AcquisitionLog")) {
335
        $log_action_name = 'MODIFY_ORDER';
323
            my $infos = {};
336
    } else {
324
            foreach my $field(@log_order_fields) {
337
        $order = Koha::Acquisition::Order->new($orderinfo);
325
                $infos->{$field} = $orderinfo->{$field};
338
        $log_action_name = 'CREATE_ORDER';
326
            }
327
            logaction(
328
                'ACQUISITIONS',
329
                'MODIFY_ORDER',
330
                $orderinfo->{ordernumber},
331
                encode_json($infos)
332
            );
333
        }
334
    }
339
    }
335
    else { # else, it's a new line
340
    $order->populate_with_prices_for_ordering();
336
        $order->store;
341
    $order->store;
337
        # Log the order creation
342
338
        if (C4::Context->preference("AcquisitionLog")) {
343
    # Log the order creation
339
            my $infos = {};
344
    if (C4::Context->preference("AcquisitionLog")) {
340
            foreach my $field(@log_order_fields) {
345
        my $infos = {};
341
                $infos->{$field} = $orderinfo->{$field};
346
        foreach my $field(@log_order_fields) {
342
            }
347
            $infos->{$field} = $order->$field;
343
            logaction(
344
                'ACQUISITIONS',
345
                'CREATE_ORDER',
346
                $order->ordernumber,
347
                encode_json($infos)
348
            );
349
        }
348
        }
349
        logaction(
350
            'ACQUISITIONS',
351
            $log_action_name,
352
            $order->ordernumber,
353
            encode_json($infos)
354
        );
350
    }
355
    }
351
    my $order_users_ids = $input->param('users_ids');
356
    my $order_users_ids = $input->param('users_ids');
352
    my @order_users = split( /:/, $order_users_ids );
357
    my @order_users = split( /:/, $order_users_ids );
Lines 417-423 if (C4::Context->preference("AcquisitionLog") && $basketno) { Link Here
417
}
422
}
418
423
419
my $booksellerid=$$orderinfo{booksellerid};
424
my $booksellerid=$$orderinfo{booksellerid};
420
if (my $import_batch_id=$$orderinfo{import_batch_id}) {
425
if (my $import_batch_id = $input->param('import_batch_id')) {
421
    print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=$basketno&booksellerid=$booksellerid");
426
    print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=$basketno&booksellerid=$booksellerid");
422
} elsif ( defined $orderinfo->{invoiceid} ) {
427
} elsif ( defined $orderinfo->{invoiceid} ) {
423
    print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=" . $orderinfo->{invoiceid});
428
    print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=" . $orderinfo->{invoiceid});
(-)a/acqui/addorderiso2709.pl (-29 / +10 lines)
Lines 33-39 use C4::Output qw( output_html_with_http_headers ); Link Here
33
use C4::ImportBatch qw( GetImportRecordsRange GetImportRecordMarc GetImportRecordMatches SetImportRecordStatus SetMatchedBiblionumber SetImportBatchStatus GetImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction );
33
use C4::ImportBatch qw( GetImportRecordsRange GetImportRecordMarc GetImportRecordMatches SetImportRecordStatus SetMatchedBiblionumber SetImportBatchStatus GetImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction );
34
use C4::Matcher;
34
use C4::Matcher;
35
use C4::Search qw( FindDuplicate );
35
use C4::Search qw( FindDuplicate );
36
use C4::Acquisition qw( populate_order_with_prices );
37
use C4::Biblio qw(
36
use C4::Biblio qw(
38
    AddBiblio
37
    AddBiblio
39
    GetMarcFromKohaField
38
    GetMarcFromKohaField
Lines 43-49 use C4::Biblio qw( Link Here
43
);
42
);
44
use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc );
43
use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc );
45
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode );
44
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode );
46
use C4::Acquisition qw( populate_order_with_prices );
47
use C4::Suggestions;    # GetSuggestion
45
use C4::Suggestions;    # GetSuggestion
48
use C4::Members;
46
use C4::Members;
49
47
Lines 273-279 if ($op eq ""){ Link Here
273
                        # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
271
                        # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
274
                        $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
272
                        $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
275
                        $price = Koha::Number::Price->new($price)->unformat;
273
                        $price = Koha::Number::Price->new($price)->unformat;
276
                        $orderinfo{tax_rate} = $bookseller->tax_rate;
274
                        $orderinfo{tax_rate_on_ordering} = $bookseller->tax_rate;
275
                        $orderinfo{tax_rate_on_receiving} = $bookseller->tax_rate;
277
                        my $c = $c_discount ? $c_discount : $bookseller->discount;
276
                        my $c = $c_discount ? $c_discount : $bookseller->discount;
278
                        $orderinfo{discount} = $c;
277
                        $orderinfo{discount} = $c;
279
                        if ( $c ) {
278
                        if ( $c ) {
Lines 282-288 if ($op eq ""){ Link Here
282
                        }
281
                        }
283
                        $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
282
                        $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
284
                        $orderinfo{unitprice} = $orderinfo{ecost};
283
                        $orderinfo{unitprice} = $orderinfo{ecost};
285
                        $orderinfo{total} = $orderinfo{ecost} * $infos->{quantity};
286
                    } else {
284
                    } else {
287
                        $orderinfo{listprice} = 0;
285
                        $orderinfo{listprice} = 0;
288
                    }
286
                    }
Lines 291-308 if ($op eq ""){ Link Here
291
                    # remove uncertainprice flag if we have found a price in the MARC record
289
                    # remove uncertainprice flag if we have found a price in the MARC record
292
                    $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
290
                    $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
293
291
294
                    %orderinfo = %{
295
                        C4::Acquisition::populate_order_with_prices(
296
                            {
297
                                order        => \%orderinfo,
298
                                booksellerid => $booksellerid,
299
                                ordering     => 1,
300
                                receiving    => 1,
301
                            }
302
                        )
303
                    };
304
305
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->store;
292
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->store;
293
                    $order->populate_with_prices_for_ordering();
294
                    $order->populate_with_prices_for_receiving();
306
                    $order->add_item( $_ ) for @{ $budget_hash->{$budget_id}->{itemnumbers} };
295
                    $order->add_item( $_ ) for @{ $budget_hash->{$budget_id}->{itemnumbers} };
307
                }
296
                }
308
            }
297
            }
Lines 331-337 if ($op eq ""){ Link Here
331
                # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
320
                # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
332
                $c_price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
321
                $c_price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
333
                $c_price = Koha::Number::Price->new($c_price)->unformat;
322
                $c_price = Koha::Number::Price->new($c_price)->unformat;
334
                $orderinfo{tax_rate} = $bookseller->tax_rate;
323
                $orderinfo{tax_rate_on_ordering} = $bookseller->tax_rate;
324
                $orderinfo{tax_rate_on_receiving} = $bookseller->tax_rate;
335
                my $c = $c_discount ? $c_discount : $bookseller->discount;
325
                my $c = $c_discount ? $c_discount : $bookseller->discount;
336
                $orderinfo{discount} = $c;
326
                $orderinfo{discount} = $c;
337
                if ( $c ) {
327
                if ( $c ) {
Lines 340-346 if ($op eq ""){ Link Here
340
                }
330
                }
341
                $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
331
                $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
342
                $orderinfo{unitprice} = $orderinfo{ecost};
332
                $orderinfo{unitprice} = $orderinfo{ecost};
343
                $orderinfo{total} = $orderinfo{ecost} * $c_quantity;
344
            } else {
333
            } else {
345
                $orderinfo{listprice} = 0;
334
                $orderinfo{listprice} = 0;
346
            }
335
            }
Lines 348-365 if ($op eq ""){ Link Here
348
        # remove uncertainprice flag if we have found a price in the MARC record
337
        # remove uncertainprice flag if we have found a price in the MARC record
349
        $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
338
        $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
350
339
351
        %orderinfo = %{
340
        my $order = Koha::Acquisition::Order->new( \%orderinfo );
352
            C4::Acquisition::populate_order_with_prices(
341
        $order->populate_with_prices_for_ordering();
353
                {
342
        $order->populate_with_prices_for_receiving();
354
                    order        => \%orderinfo,
343
        $order->store;
355
                    booksellerid => $booksellerid,
356
                    ordering     => 1,
357
                    receiving    => 1,
358
                }
359
            )
360
        };
361
362
        my $order = Koha::Acquisition::Order->new( \%orderinfo )->store;
363
344
364
        # 4th, add items if applicable
345
        # 4th, add items if applicable
365
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
346
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
(-)a/acqui/finishreceive.pl (-14 / +8 lines)
Lines 26-32 use C4::Auth qw( checkauth ); Link Here
26
use JSON qw( encode_json );
26
use JSON qw( encode_json );
27
use C4::Output;
27
use C4::Output;
28
use C4::Context;
28
use C4::Context;
29
use C4::Acquisition qw( GetInvoice GetOrder populate_order_with_prices ModReceiveOrder );
29
use C4::Acquisition qw( GetInvoice GetOrder ModReceiveOrder );
30
use C4::Biblio qw( GetFrameworkCode GetMarcFromKohaField TransformHtmlToXml );
30
use C4::Biblio qw( GetFrameworkCode GetMarcFromKohaField TransformHtmlToXml );
31
use C4::Items qw( GetMarcItem ModItemFromMarc AddItemFromMarc );
31
use C4::Items qw( GetMarcItem ModItemFromMarc AddItemFromMarc );
32
use C4::Log qw(logaction);
32
use C4::Log qw(logaction);
Lines 98-126 if ($quantityrec > $origquantityrec ) { Link Here
98
        }
98
        }
99
    }
99
    }
100
100
101
    $order->{order_internalnote} = $input->param("order_internalnote");
101
    $order_obj->order_internalnote(scalar $input->param("order_internalnote"));
102
    $order->{tax_rate_on_receiving} = $input->param("tax_rate");
102
    $order_obj->tax_rate_on_receiving(scalar $input->param("tax_rate"));
103
    $order->{replacementprice} = $replacementprice;
103
    $order_obj->replacementprice($replacementprice);
104
    $order->{unitprice} = $unitprice;
104
    $order_obj->unitprice($unitprice);
105
105
106
    $order = C4::Acquisition::populate_order_with_prices(
106
    $order_obj->populate_with_prices_for_receiving();
107
        {
108
            order => $order,
109
            booksellerid => $booksellerid,
110
            receiving => 1
111
        }
112
    );
113
107
114
    # save the quantity received.
108
    # save the quantity received.
115
    if ( $quantityrec > 0 ) {
109
    if ( $quantityrec > 0 ) {
116
        if ( $order_obj->subscriptionid ) {
110
        if ( $order_obj->subscriptionid ) {
117
            # Quantity can only be modified if linked to a subscription
111
            # Quantity can only be modified if linked to a subscription
118
            $order->{quantity} = $quantity; # quantityrec will be deduced from this value in ModReceiveOrder
112
            $order_obj->quantity($quantity); # quantityrec will be deduced from this value in ModReceiveOrder
119
        }
113
        }
120
        ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
114
        ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
121
            {
115
            {
122
                biblionumber     => $biblionumber,
116
                biblionumber     => $biblionumber,
123
                order            => $order,
117
                order            => $order_obj->unblessed,
124
                quantityreceived => $quantityrec,
118
                quantityreceived => $quantityrec,
125
                user             => $user,
119
                user             => $user,
126
                invoice          => $invoice,
120
                invoice          => $invoice,
(-)a/t/Prices.t (-138 / +86 lines)
Lines 8-20 use Module::Load::Conditional qw/check_install/; Link Here
8
8
9
BEGIN {
9
BEGIN {
10
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
10
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
11
        plan tests => 16;
11
        plan tests => 15;
12
    } else {
12
    } else {
13
        plan skip_all => "Need Test::DBIx::Class"
13
        plan skip_all => "Need Test::DBIx::Class"
14
    }
14
    }
15
}
15
}
16
16
17
use_ok('C4::Acquisition', qw( populate_order_with_prices ));
18
use_ok('C4::Context');
17
use_ok('C4::Context');
19
use_ok('Koha::Number::Price');
18
use_ok('Koha::Number::Price');
20
19
Lines 38-48 fixtures_ok [ Link Here
38
        [ 3, '1 0', 1, 0 ],
37
        [ 3, '1 0', 1, 0 ],
39
        [ 4, '1 1', 1, 1 ],
38
        [ 4, '1 1', 1, 1 ],
40
    ],
39
    ],
40
    Aqbasket => [
41
        [ qw/ basketno basketname booksellerid / ],
42
        [ 1, '0 0', 1 ],
43
        [ 2, '0 1', 2 ],
44
        [ 3, '1 0', 3 ],
45
        [ 4, '1 1', 4 ],
46
    ],
41
], 'add currency fixtures';
47
], 'add currency fixtures';
42
48
43
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
49
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
44
50
45
my ( $basketno_0_0,  $basketno_1_1 );
51
my ( $basketno_0_0, $basketno_0_1, $basketno_1_0, $basketno_1_1 ) = (1, 2, 3, 4);
46
my ( $invoiceid_0_0, $invoiceid_1_1 );
52
my ( $invoiceid_0_0, $invoiceid_1_1 );
47
my $today;
53
my $today;
48
54
Lines 53-59 for my $currency_format ( qw( US FR ) ) { Link Here
53
59
54
        my $biblionumber_0_0 = 42;
60
        my $biblionumber_0_0 = 42;
55
61
56
        my $order_0_0 = {
62
        my $order_0_0 = Koha::Acquisition::Order->new({
57
            biblionumber     => $biblionumber_0_0,
63
            biblionumber     => $biblionumber_0_0,
58
            quantity         => 2,
64
            quantity         => 2,
59
            listprice        => 82,
65
            listprice        => 82,
Lines 63-83 for my $currency_format ( qw( US FR ) ) { Link Here
63
            invoiceid        => $invoiceid_0_0,
69
            invoiceid        => $invoiceid_0_0,
64
            rrp              => 82.00,
70
            rrp              => 82.00,
65
            ecost            => 73.80,
71
            ecost            => 73.80,
66
            tax_rate         => 0.0500,
72
            tax_rate_on_ordering  => 0.0500,
73
            tax_rate_on_receiving => 0.0500,
67
            discount         => 10,
74
            discount         => 10,
68
            datereceived     => $today
75
            datereceived     => $today
69
        };
76
        });
70
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
77
        $order_0_0->populate_with_prices_for_ordering();
71
            {
72
                order        => $order_0_0,
73
                booksellerid => 1,
74
                ordering     => 1,
75
            }
76
        );
77
78
78
        compare(
79
        compare(
79
            {
80
            {
80
                got      => $order_0_0->{rrp_tax_included},
81
                got      => $order_0_0->rrp_tax_included,
81
                expected => 86.10,
82
                expected => 86.10,
82
                conf     => '0 0',
83
                conf     => '0 0',
83
                field    => 'rrp_tax_included'
84
                field    => 'rrp_tax_included'
Lines 85-91 for my $currency_format ( qw( US FR ) ) { Link Here
85
        );
86
        );
86
        compare(
87
        compare(
87
            {
88
            {
88
                got      => $order_0_0->{rrp_tax_excluded},
89
                got      => $order_0_0->rrp_tax_excluded,
89
                expected => 82.00,
90
                expected => 82.00,
90
                conf     => '0 0',
91
                conf     => '0 0',
91
                field    => 'rrp_tax_excluded'
92
                field    => 'rrp_tax_excluded'
Lines 93-99 for my $currency_format ( qw( US FR ) ) { Link Here
93
        );
94
        );
94
        compare(
95
        compare(
95
            {
96
            {
96
                got      => $order_0_0->{ecost_tax_included},
97
                got      => $order_0_0->ecost_tax_included,
97
                expected => 77.49,
98
                expected => 77.49,
98
                conf     => '0 0',
99
                conf     => '0 0',
99
                field    => 'ecost_tax_included'
100
                field    => 'ecost_tax_included'
Lines 101-107 for my $currency_format ( qw( US FR ) ) { Link Here
101
        );
102
        );
102
        compare(
103
        compare(
103
            {
104
            {
104
                got      => $order_0_0->{ecost_tax_excluded},
105
                got      => $order_0_0->ecost_tax_excluded,
105
                expected => 73.80,
106
                expected => 73.80,
106
                conf     => '0 0',
107
                conf     => '0 0',
107
                field    => 'ecost_tax_excluded'
108
                field    => 'ecost_tax_excluded'
Lines 109-132 for my $currency_format ( qw( US FR ) ) { Link Here
109
        );
110
        );
110
        compare(
111
        compare(
111
            {
112
            {
112
                got      => $order_0_0->{tax_value_on_ordering},
113
                got      => $order_0_0->tax_value_on_ordering,
113
                expected => 7.38,
114
                expected => 7.38,
114
                conf     => '0 0',
115
                conf     => '0 0',
115
                field    => 'tax_value'
116
                field    => 'tax_value'
116
            }
117
            }
117
        );
118
        );
118
119
119
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
120
        $order_0_0->populate_with_prices_for_receiving();
120
            {
121
                order        => $order_0_0,
122
                booksellerid => 1,
123
                receiving    => 1,
124
            }
125
        );
126
121
127
        compare(
122
        compare(
128
            {
123
            {
129
                got      => $order_0_0->{unitprice_tax_included},
124
                got      => $order_0_0->unitprice_tax_included,
130
                expected => 77.49,
125
                expected => 77.49,
131
                conf     => '0 0',
126
                conf     => '0 0',
132
                field    => 'unitprice_tax_included'
127
                field    => 'unitprice_tax_included'
Lines 134-140 for my $currency_format ( qw( US FR ) ) { Link Here
134
        );
129
        );
135
        compare(
130
        compare(
136
            {
131
            {
137
                got      => $order_0_0->{unitprice_tax_excluded},
132
                got      => $order_0_0->unitprice_tax_excluded,
138
                expected => 73.80,
133
                expected => 73.80,
139
                conf     => '0 0',
134
                conf     => '0 0',
140
                field    => 'unitprice_tax_excluded'
135
                field    => 'unitprice_tax_excluded'
Lines 142-148 for my $currency_format ( qw( US FR ) ) { Link Here
142
        );
137
        );
143
        compare(
138
        compare(
144
            {
139
            {
145
                got      => $order_0_0->{tax_value_on_receiving},
140
                got      => $order_0_0->tax_value_on_receiving,
146
                expected => 7.38,
141
                expected => 7.38,
147
                conf     => '0 0',
142
                conf     => '0 0',
148
                field    => 'tax_value'
143
                field    => 'tax_value'
Lines 154-160 for my $currency_format ( qw( US FR ) ) { Link Here
154
        plan tests => 11;
149
        plan tests => 11;
155
150
156
        my $biblionumber_1_1 = 43;
151
        my $biblionumber_1_1 = 43;
157
        my $order_1_1        = {
152
        my $order_1_1        = Koha::Acquisition::Order->new({
158
            biblionumber     => $biblionumber_1_1,
153
            biblionumber     => $biblionumber_1_1,
159
            quantity         => 2,
154
            quantity         => 2,
160
            listprice        => 82,
155
            listprice        => 82,
Lines 164-185 for my $currency_format ( qw( US FR ) ) { Link Here
164
            invoiceid        => $invoiceid_1_1,
159
            invoiceid        => $invoiceid_1_1,
165
            rrp              => 82.00,
160
            rrp              => 82.00,
166
            ecost            => 73.80,
161
            ecost            => 73.80,
167
            tax_rate         => 0.0500,
162
            tax_rate_on_ordering  => 0.0500,
163
            tax_rate_on_receiving => 0.0500,
168
            discount         => 10,
164
            discount         => 10,
169
            datereceived     => $today
165
            datereceived     => $today
170
        };
166
        });
171
167
172
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
168
        $order_1_1->populate_with_prices_for_ordering();
173
            {
174
                order        => $order_1_1,
175
                booksellerid => 4,
176
                ordering     => 1,
177
            }
178
        );
179
169
180
        compare(
170
        compare(
181
            {
171
            {
182
                got      => $order_1_1->{rrp_tax_included},
172
                got      => $order_1_1->rrp_tax_included,
183
                expected => 82.00,
173
                expected => 82.00,
184
                conf     => '1 1',
174
                conf     => '1 1',
185
                field    => 'rrp_tax_included'
175
                field    => 'rrp_tax_included'
Lines 187-193 for my $currency_format ( qw( US FR ) ) { Link Here
187
        );
177
        );
188
        compare(
178
        compare(
189
            {
179
            {
190
                got      => $order_1_1->{rrp_tax_excluded},
180
                got      => $order_1_1->rrp_tax_excluded,
191
                expected => 78.10,
181
                expected => 78.10,
192
                conf     => '1 1',
182
                conf     => '1 1',
193
                field    => 'rrp_tax_excluded'
183
                field    => 'rrp_tax_excluded'
Lines 195-201 for my $currency_format ( qw( US FR ) ) { Link Here
195
        );
185
        );
196
        compare(
186
        compare(
197
            {
187
            {
198
                got      => $order_1_1->{ecost_tax_included},
188
                got      => $order_1_1->ecost_tax_included,
199
                expected => 73.80,
189
                expected => 73.80,
200
                conf     => '1 1',
190
                conf     => '1 1',
201
                field    => 'ecost_tax_included'
191
                field    => 'ecost_tax_included'
Lines 203-209 for my $currency_format ( qw( US FR ) ) { Link Here
203
        );
193
        );
204
        compare(
194
        compare(
205
            {
195
            {
206
                got      => $order_1_1->{ecost_tax_excluded},
196
                got      => $order_1_1->ecost_tax_excluded,
207
                expected => 70.29,
197
                expected => 70.29,
208
                conf     => '1 1',
198
                conf     => '1 1',
209
                field    => 'ecost_tax_excluded'
199
                field    => 'ecost_tax_excluded'
Lines 211-234 for my $currency_format ( qw( US FR ) ) { Link Here
211
        );
201
        );
212
        compare(
202
        compare(
213
            {
203
            {
214
                got      => $order_1_1->{tax_value_on_ordering},
204
                got      => $order_1_1->tax_value_on_ordering,
215
                expected => 7.03,
205
                expected => 7.03,
216
                conf     => '1 1',
206
                conf     => '1 1',
217
                field    => 'tax_value'
207
                field    => 'tax_value'
218
            }
208
            }
219
        );
209
        );
220
210
221
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
211
        $order_1_1->populate_with_prices_for_receiving();
222
            {
223
                order        => $order_1_1,
224
                booksellerid => 4,
225
                receiving    => 1,
226
            }
227
        );
228
212
229
        compare(
213
        compare(
230
            {
214
            {
231
                got      => $order_1_1->{unitprice_tax_included},
215
                got      => $order_1_1->unitprice_tax_included,
232
                expected => 73.80,
216
                expected => 73.80,
233
                conf     => '1 1',
217
                conf     => '1 1',
234
                field    => 'unitprice_tax_included'
218
                field    => 'unitprice_tax_included'
Lines 236-242 for my $currency_format ( qw( US FR ) ) { Link Here
236
        );
220
        );
237
        compare(
221
        compare(
238
            {
222
            {
239
                got      => $order_1_1->{unitprice_tax_excluded},
223
                got      => $order_1_1->unitprice_tax_excluded,
240
                expected => 70.29,
224
                expected => 70.29,
241
                conf     => '1 1',
225
                conf     => '1 1',
242
                field    => 'unitprice_tax_excluded'
226
                field    => 'unitprice_tax_excluded'
Lines 244-258 for my $currency_format ( qw( US FR ) ) { Link Here
244
        );
228
        );
245
        compare(
229
        compare(
246
            {
230
            {
247
                got      => $order_1_1->{tax_value_on_receiving},
231
                got      => $order_1_1->tax_value_on_receiving,
248
                expected => 7.03,
232
                expected => 7.03,
249
                conf     => '1 1',
233
                conf     => '1 1',
250
                field    => 'tax_value'
234
                field    => 'tax_value'
251
            }
235
            }
252
        );
236
        );
253
237
254
        # When unitprice is 0.00 C4::Acquisition->populate_order_with_prices() falls back to using ecost_tax_included and ecost_tax_excluded
238
        # When unitprice is 0.00
255
        $order_1_1        = {
239
        # Koha::Acquisition::Order::populate_with_prices_for_ordering() falls
240
        # back to using ecost_tax_included and ecost_tax_excluded
241
        $order_1_1        = Koha::Acquisition::Order->new({
256
            biblionumber     => $biblionumber_1_1,
242
            biblionumber     => $biblionumber_1_1,
257
            quantity         => 1,
243
            quantity         => 1,
258
            listprice        => 10,
244
            listprice        => 10,
Lines 262-283 for my $currency_format ( qw( US FR ) ) { Link Here
262
            invoiceid        => $invoiceid_1_1,
248
            invoiceid        => $invoiceid_1_1,
263
            rrp              => 10.00,
249
            rrp              => 10.00,
264
            ecost            => 10.00,
250
            ecost            => 10.00,
265
            tax_rate         => 0.1500,
251
            tax_rate_on_ordering  => 0.1500,
252
            tax_rate_on_receiving => 0.1500,
266
            discount         => 0,
253
            discount         => 0,
267
            datereceived     => $today
254
            datereceived     => $today
268
        };
255
        });
269
256
270
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
257
        $order_1_1->populate_with_prices_for_ordering();
271
            {
272
                order        => $order_1_1,
273
                booksellerid => 4,
274
                ordering     => 1,
275
            }
276
        );
277
258
278
        compare(
259
        compare(
279
            {
260
            {
280
                got      => $order_1_1->{ecost_tax_included},
261
                got      => $order_1_1->ecost_tax_included,
281
                expected => 10.00,
262
                expected => 10.00,
282
                conf     => '1 1',
263
                conf     => '1 1',
283
                field    => 'ecost_tax_included'
264
                field    => 'ecost_tax_included'
Lines 285-291 for my $currency_format ( qw( US FR ) ) { Link Here
285
        );
266
        );
286
        compare(
267
        compare(
287
            {
268
            {
288
                got      => $order_1_1->{ecost_tax_excluded},
269
                got      => $order_1_1->ecost_tax_excluded,
289
                expected => 8.70,
270
                expected => 8.70,
290
                conf     => '1 1',
271
                conf     => '1 1',
291
                field    => 'ecost_tax_excluded'
272
                field    => 'ecost_tax_excluded'
Lines 293-299 for my $currency_format ( qw( US FR ) ) { Link Here
293
        );
274
        );
294
        compare(
275
        compare(
295
            {
276
            {
296
                got      => $order_1_1->{tax_value_on_ordering},
277
                got      => $order_1_1->tax_value_on_ordering,
297
                expected => 1.30,
278
                expected => 1.30,
298
                conf     => '1 1',
279
                conf     => '1 1',
299
                field    => 'tax_value'
280
                field    => 'tax_value'
Lines 305-336 for my $currency_format ( qw( US FR ) ) { Link Here
305
        plan tests => 9;
286
        plan tests => 9;
306
287
307
        my $biblionumber_1_0 = 44;
288
        my $biblionumber_1_0 = 44;
308
        my $order_1_0        = {
289
        my $order_1_0 = Koha::Acquisition::Order->new({
309
            biblionumber     => $biblionumber_1_0,
290
            biblionumber     => $biblionumber_1_0,
310
            quantity         => 2,
291
            quantity         => 2,
311
            listprice        => 82,
292
            listprice        => 82,
312
            unitprice        => 0,
293
            unitprice        => 0,
313
            quantityreceived => 2,
294
            quantityreceived => 2,
314
            basketno         => $basketno_1_1,
295
            basketno         => $basketno_1_0,
315
            invoiceid        => $invoiceid_1_1,
296
            invoiceid        => $invoiceid_1_1,
316
            rrp              => 82.00,
297
            rrp              => 82.00,
317
            ecost            => 73.80,
298
            ecost            => 73.80,
318
            tax_rate         => 0.0500,
299
            tax_rate_on_ordering  => 0.0500,
300
            tax_rate_on_receiving => 0.0500,
319
            discount         => 10,
301
            discount         => 10,
320
            datereceived     => $today
302
            datereceived     => $today
321
        };
303
        });
322
304
323
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
305
        $order_1_0->populate_with_prices_for_ordering();
324
            {
325
                order        => $order_1_0,
326
                booksellerid => 3,
327
                ordering     => 1,
328
            }
329
        );
330
306
331
        compare(
307
        compare(
332
            {
308
            {
333
                got      => $order_1_0->{rrp_tax_included},
309
                got      => $order_1_0->rrp_tax_included,
334
                expected => 82,
310
                expected => 82,
335
                conf     => '1 0',
311
                conf     => '1 0',
336
                field    => 'rrp_tax_included'
312
                field    => 'rrp_tax_included'
Lines 338-344 for my $currency_format ( qw( US FR ) ) { Link Here
338
        );
314
        );
339
        compare(
315
        compare(
340
            {
316
            {
341
                got      => $order_1_0->{rrp_tax_excluded},
317
                got      => $order_1_0->rrp_tax_excluded,
342
                expected => 78.10,
318
                expected => 78.10,
343
                conf     => '1 0',
319
                conf     => '1 0',
344
                field    => 'rrp_tax_excluded'
320
                field    => 'rrp_tax_excluded'
Lines 346-352 for my $currency_format ( qw( US FR ) ) { Link Here
346
        );
322
        );
347
        compare(
323
        compare(
348
            {
324
            {
349
                got      => $order_1_0->{ecost_tax_included},
325
                got      => $order_1_0->ecost_tax_included,
350
                expected => 73.80,
326
                expected => 73.80,
351
                conf     => '1 0',
327
                conf     => '1 0',
352
                field    => 'ecost_tax_included'
328
                field    => 'ecost_tax_included'
Lines 354-360 for my $currency_format ( qw( US FR ) ) { Link Here
354
        );
330
        );
355
        compare(
331
        compare(
356
            {
332
            {
357
                got      => $order_1_0->{ecost_tax_excluded},
333
                got      => $order_1_0->ecost_tax_excluded,
358
                expected => 70.29,
334
                expected => 70.29,
359
                conf     => '1 0',
335
                conf     => '1 0',
360
                field    => 'ecost_tax_excluded'
336
                field    => 'ecost_tax_excluded'
Lines 364-404 for my $currency_format ( qw( US FR ) ) { Link Here
364
        # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
340
        # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
365
        compare(
341
        compare(
366
            {
342
            {
367
                got      => $order_1_0->{tax_value_on_ordering},
343
                got      => $order_1_0->tax_value_on_ordering,
368
                expected => 7.03,
344
                expected => 7.03,
369
                conf     => '1 0',
345
                conf     => '1 0',
370
                field    => 'tax_value'
346
                field    => 'tax_value'
371
            }
347
            }
372
        );
348
        );
373
        $order_1_0->{unitprice} = 70.29;
349
        $order_1_0->unitprice(70.29);
374
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
350
        $order_1_0->populate_with_prices_for_ordering();
375
            {
351
376
                order        => $order_1_0,
377
                booksellerid => 3,
378
                ordering    => 1,
379
            }
380
        );
381
        # If a unitprice is provided at ordering, we calculate the tax from that
352
        # If a unitprice is provided at ordering, we calculate the tax from that
382
        compare(
353
        compare(
383
            {
354
            {
384
                got      => $order_1_0->{tax_value_on_ordering},
355
                got      => $order_1_0->tax_value_on_ordering,
385
                expected => 6.69,
356
                expected => 6.69,
386
                conf     => '1 0',
357
                conf     => '1 0',
387
                field    => 'tax_value'
358
                field    => 'tax_value'
388
            }
359
            }
389
        );
360
        );
390
361
391
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
362
        $order_1_0->populate_with_prices_for_receiving();
392
            {
393
                order        => $order_1_0,
394
                booksellerid => 3,
395
                receiving    => 1,
396
            }
397
        );
398
363
399
        compare(
364
        compare(
400
            {
365
            {
401
                got      => $order_1_0->{unitprice_tax_included},
366
                got      => $order_1_0->unitprice_tax_included,
402
                expected => 73.80,
367
                expected => 73.80,
403
                conf     => '1 0',
368
                conf     => '1 0',
404
                field    => 'unitprice_tax_included'
369
                field    => 'unitprice_tax_included'
Lines 406-412 for my $currency_format ( qw( US FR ) ) { Link Here
406
        );
371
        );
407
        compare(
372
        compare(
408
            {
373
            {
409
                got      => $order_1_0->{unitprice_tax_excluded},
374
                got      => $order_1_0->unitprice_tax_excluded,
410
                expected => 70.29,
375
                expected => 70.29,
411
                conf     => '1 0',
376
                conf     => '1 0',
412
                field    => 'unitprice_tax_excluded'
377
                field    => 'unitprice_tax_excluded'
Lines 414-420 for my $currency_format ( qw( US FR ) ) { Link Here
414
        );
379
        );
415
        compare(
380
        compare(
416
            {
381
            {
417
                got      => $order_1_0->{tax_value_on_receiving},
382
                got      => $order_1_0->tax_value_on_receiving,
418
                expected => 7.03,
383
                expected => 7.03,
419
                conf     => '1 0',
384
                conf     => '1 0',
420
                field    => 'tax_value'
385
                field    => 'tax_value'
Lines 426-457 for my $currency_format ( qw( US FR ) ) { Link Here
426
        plan tests => 9;
391
        plan tests => 9;
427
392
428
        my $biblionumber_0_1 = 45;
393
        my $biblionumber_0_1 = 45;
429
        my $order_0_1        = {
394
        my $order_0_1 = Koha::Acquisition::Order->new({
430
            biblionumber     => $biblionumber_0_1,
395
            biblionumber     => $biblionumber_0_1,
431
            quantity         => 2,
396
            quantity         => 2,
432
            listprice        => 82,
397
            listprice        => 82,
433
            unitprice        => 0,
398
            unitprice        => 0,
434
            quantityreceived => 2,
399
            quantityreceived => 2,
435
            basketno         => $basketno_1_1,
400
            basketno         => $basketno_0_1,
436
            invoiceid        => $invoiceid_1_1,
401
            invoiceid        => $invoiceid_1_1,
437
            rrp              => 82.00,
402
            rrp              => 82.00,
438
            ecost            => 73.80,
403
            ecost            => 73.80,
439
            tax_rate         => 0.0500,
404
            tax_rate_on_ordering  => 0.0500,
405
            tax_rate_on_receiving => 0.0500,
440
            discount         => 10,
406
            discount         => 10,
441
            datereceived     => $today
407
            datereceived     => $today
442
        };
408
        });
443
409
444
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
410
        $order_0_1->populate_with_prices_for_ordering();
445
            {
446
                order        => $order_0_1,
447
                booksellerid => 2,
448
                ordering     => 1,
449
            }
450
        );
451
411
452
        compare(
412
        compare(
453
            {
413
            {
454
                got      => $order_0_1->{rrp_tax_included},
414
                got      => $order_0_1->rrp_tax_included,
455
                expected => 86.10,
415
                expected => 86.10,
456
                conf     => '0 1',
416
                conf     => '0 1',
457
                field    => 'rrp_tax_included'
417
                field    => 'rrp_tax_included'
Lines 459-465 for my $currency_format ( qw( US FR ) ) { Link Here
459
        );
419
        );
460
        compare(
420
        compare(
461
            {
421
            {
462
                got      => $order_0_1->{rrp_tax_excluded},
422
                got      => $order_0_1->rrp_tax_excluded,
463
                expected => 82.00,
423
                expected => 82.00,
464
                conf     => '0 1',
424
                conf     => '0 1',
465
                field    => 'rrp_tax_excluded'
425
                field    => 'rrp_tax_excluded'
Lines 467-473 for my $currency_format ( qw( US FR ) ) { Link Here
467
        );
427
        );
468
        compare(
428
        compare(
469
            {
429
            {
470
                got      => $order_0_1->{ecost_tax_included},
430
                got      => $order_0_1->ecost_tax_included,
471
                expected => 77.49,
431
                expected => 77.49,
472
                conf     => '0 1',
432
                conf     => '0 1',
473
                field    => 'ecost_tax_included'
433
                field    => 'ecost_tax_included'
Lines 475-481 for my $currency_format ( qw( US FR ) ) { Link Here
475
        );
435
        );
476
        compare(
436
        compare(
477
            {
437
            {
478
                got      => $order_0_1->{ecost_tax_excluded},
438
                got      => $order_0_1->ecost_tax_excluded,
479
                expected => 73.80,
439
                expected => 73.80,
480
                conf     => '0 1',
440
                conf     => '0 1',
481
                field    => 'ecost_tax_excluded'
441
                field    => 'ecost_tax_excluded'
Lines 485-524 for my $currency_format ( qw( US FR ) ) { Link Here
485
        # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
445
        # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
486
        compare(
446
        compare(
487
            {
447
            {
488
                got      => $order_0_1->{tax_value_on_ordering},
448
                got      => $order_0_1->tax_value_on_ordering,
489
                expected => 7.38,
449
                expected => 7.38,
490
                conf     => '0 1',
450
                conf     => '0 1',
491
                field    => 'tax_value'
451
                field    => 'tax_value'
492
            }
452
            }
493
        );
453
        );
494
        $order_0_1->{unitprice} = 77.490000;
454
        $order_0_1->unitprice(77.490000);
495
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
455
        $order_0_1->populate_with_prices_for_ordering();
496
            {
456
497
                order        => $order_0_1,
498
                booksellerid => 2,
499
                ordering     => 1,
500
            }
501
        );
502
        # If a unitprice is provided at ordering, we calculate the tax from that
457
        # If a unitprice is provided at ordering, we calculate the tax from that
503
        compare(
458
        compare(
504
            {
459
            {
505
                got      => $order_0_1->{tax_value_on_ordering},
460
                got      => $order_0_1->tax_value_on_ordering,
506
                expected => 7.75,
461
                expected => 7.75,
507
                conf     => '0 1',
462
                conf     => '0 1',
508
                field    => 'tax_value'
463
                field    => 'tax_value'
509
            }
464
            }
510
        );
465
        );
511
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
466
        $order_0_1->populate_with_prices_for_receiving();
512
            {
513
                order        => $order_0_1,
514
                booksellerid => 2,
515
                receiving    => 1,
516
            }
517
        );
518
467
519
        compare(
468
        compare(
520
            {
469
            {
521
                got      => $order_0_1->{unitprice_tax_included},
470
                got      => $order_0_1->unitprice_tax_included,
522
                expected => 77.49,
471
                expected => 77.49,
523
                conf     => '0 1',
472
                conf     => '0 1',
524
                field    => 'unitprice_tax_included'
473
                field    => 'unitprice_tax_included'
Lines 526-532 for my $currency_format ( qw( US FR ) ) { Link Here
526
        );
475
        );
527
        compare(
476
        compare(
528
            {
477
            {
529
                got      => $order_0_1->{unitprice_tax_excluded},
478
                got      => $order_0_1->unitprice_tax_excluded,
530
                expected => 73.80,
479
                expected => 73.80,
531
                conf     => '0 1',
480
                conf     => '0 1',
532
                field    => 'unitprice_tax_excluded'
481
                field    => 'unitprice_tax_excluded'
Lines 534-547 for my $currency_format ( qw( US FR ) ) { Link Here
534
        );
483
        );
535
        compare(
484
        compare(
536
            {
485
            {
537
                got      => $order_0_1->{tax_value_on_receiving},
486
                got      => $order_0_1->tax_value_on_receiving,
538
                expected => 7.38,
487
                expected => 7.38,
539
                conf     => '0 1',
488
                conf     => '0 1',
540
                field    => 'tax_value'
489
                field    => 'tax_value'
541
            }
490
            }
542
        );
491
        );
543
    };
492
    };
544
545
}
493
}
546
494
547
sub compare {
495
sub compare {
(-)a/t/db_dependent/Acquisition/populate_order_with_prices.t (-106 / +84 lines)
Lines 3-11 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 44;
5
use Test::More tests => 44;
6
use C4::Acquisition qw( populate_order_with_prices );
7
use C4::Context;
6
use C4::Context;
8
use Koha::Database;
7
use Koha::Database;
8
use Koha::Acquisition::Bookseller;
9
use Koha::Acquisition::Order;
9
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
10
use t::lib::Mocks;
11
use t::lib::Mocks;
11
12
Lines 37-194 my $bookseller_exc_tax = Koha::Acquisition::Bookseller->new( Link Here
37
    }
38
    }
38
)->store;
39
)->store;
39
40
40
my $order_exc_tax = {
41
my $basket_exc_tax = Koha::Acquisition::Basket->new(
41
    tax_rate  => .1965,
42
    {
43
        basketname => 'Basket tax excluded',
44
        booksellerid => $bookseller_exc_tax->id,
45
    }
46
)->store;
47
48
my $order_exc_tax = Koha::Acquisition::Order->new({
49
    tax_rate_on_ordering  => .1965,
50
    tax_rate_on_receiving => .1965,
42
    discount  => .42,
51
    discount  => .42,
43
    rrp       => 16.99,
52
    rrp       => 16.99,
44
    unitprice => "0.00",
53
    unitprice => "0.00",
45
    quantity  => 8,
54
    quantity  => 8,
46
};
55
    basketno => $basket_exc_tax->basketno,
56
});
47
57
48
#Vendor prices exclude tax, no rounding, ordering
58
#Vendor prices exclude tax, no rounding, ordering
49
t::lib::Mocks::mock_preference('OrderPriceRounding', '');
59
t::lib::Mocks::mock_preference('OrderPriceRounding', '');
50
my $order_with_prices = C4::Acquisition::populate_order_with_prices({
60
$order_exc_tax->populate_with_prices_for_ordering();
51
    ordering     => 1,
52
    booksellerid => $bookseller_exc_tax->id,
53
    order        => $order_exc_tax,
54
});
55
61
56
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.99      ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
62
is( $order_exc_tax->rrp_tax_excluded+0      ,16.99      ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
57
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
63
is( $order_exc_tax->rrp_tax_included+0      ,20.328535  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
58
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
64
is( $order_exc_tax->ecost_tax_excluded+0    ,9.8542     ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
59
is( $order_with_prices->{ecost_tax_included}+0    ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
65
is( $order_exc_tax->ecost_tax_included+0    ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
60
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4908024 ,"Ordering tax excluded, no round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering if no unitprice");
66
is( $order_exc_tax->tax_value_on_ordering+0 ,15.4908024 ,"Ordering tax excluded, no round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering if no unitprice");
61
67
62
$order_exc_tax->{unitprice} = 9.85;
68
$order_exc_tax->unitprice(9.85);
63
69
64
$order_with_prices = C4::Acquisition::populate_order_with_prices({
70
$order_exc_tax->populate_with_prices_for_ordering();
65
    ordering     => 1,
66
    booksellerid => $bookseller_exc_tax->id,
67
    order        => $order_exc_tax,
68
});
69
71
70
is( $order_with_prices->{unitprice_tax_excluded}+0      ,9.85      ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
72
is( $order_exc_tax->unitprice_tax_excluded+0      ,9.85      ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
71
is( $order_with_prices->{unitprice_tax_included}+0      ,11.785525  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
73
is( $order_exc_tax->unitprice_tax_included+0      ,11.785525  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
72
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4842 ,"Ordering tax excluded, no round: tax value on ordering is quantity * unitprice_tax_excluded * tax rate on ordering if unitprice");
74
is( $order_exc_tax->tax_value_on_ordering+0 ,15.4842 ,"Ordering tax excluded, no round: tax value on ordering is quantity * unitprice_tax_excluded * tax rate on ordering if unitprice");
73
75
74
#Vendor prices exclude tax, no rounding, receiving
76
#Vendor prices exclude tax, no rounding, receiving
75
$order_with_prices = C4::Acquisition::populate_order_with_prices({
77
$order_exc_tax->populate_with_prices_for_receiving();
76
    receiving     => 1,
77
    booksellerid => $bookseller_exc_tax->id,
78
    order        => $order_exc_tax,
79
});
80
78
81
is( $order_with_prices->{unitprice}+0              ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
79
is( $order_exc_tax->unitprice+0              ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
82
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
80
is( $order_exc_tax->unitprice_tax_excluded+0 ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
83
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
81
is( $order_exc_tax->unitprice_tax_included+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
84
is( $order_with_prices->{tax_value_on_receiving}+0  ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
82
is( $order_exc_tax->tax_value_on_receiving+0  ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
85
83
86
84
87
$order_exc_tax->{unitprice} = 9.85;
85
$order_exc_tax->unitprice(9.85);
88
#populate order with prices updates the passed in order hashref
86
#populate order with prices updates the passed in order hashref
89
#we need to reset after additional tests and changes
87
#we need to reset after additional tests and changes
90
88
91
#Vendor prices exclude tax, rounding to nearest cent, ordering
89
#Vendor prices exclude tax, rounding to nearest cent, ordering
92
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
90
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
93
$order_with_prices = C4::Acquisition::populate_order_with_prices({
91
$order_exc_tax->populate_with_prices_for_ordering();
94
    ordering     => 1,
95
    booksellerid => $bookseller_exc_tax->id,
96
    order        => $order_exc_tax,
97
});
98
92
99
is( $order_with_prices->{unitprice_tax_excluded}+0      ,9.85      ,"Ordering tax excluded, round: unitprice tax excluded is unitprice");
93
is( $order_exc_tax->unitprice_tax_excluded+0      ,9.85      ,"Ordering tax excluded, round: unitprice tax excluded is unitprice");
100
is( $order_with_prices->{unitprice_tax_included}+0      ,11.785525  ,"Ordering tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
94
is( $order_exc_tax->unitprice_tax_included+0      ,11.785525  ,"Ordering tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
101
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.99      ,"Ordering tax excluded, round: rrp tax excluded is rrp");
95
is( $order_exc_tax->rrp_tax_excluded+0      ,16.99      ,"Ordering tax excluded, round: rrp tax excluded is rrp");
102
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
96
is( $order_exc_tax->rrp_tax_included+0      ,20.328535  ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
103
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
97
is( $order_exc_tax->ecost_tax_excluded+0    ,9.8542     ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
104
is( $order_with_prices->{ecost_tax_included}+0    ,11.7905503 ,"Ordering tax excluded, round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
98
is( $order_exc_tax->ecost_tax_included+0    ,11.7905503 ,"Ordering tax excluded, round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
105
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4842    ,"Ordering tax excluded, round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
99
is( $order_exc_tax->tax_value_on_ordering+0 ,15.4842    ,"Ordering tax excluded, round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
106
100
107
#Vendor prices exclude tax, no rounding, receiving
101
#Vendor prices exclude tax, no rounding, receiving
108
$order_with_prices = C4::Acquisition::populate_order_with_prices({
102
$order_exc_tax->populate_with_prices_for_receiving();
109
    receiving     => 1,
110
    booksellerid => $bookseller_exc_tax->id,
111
    order        => $order_exc_tax,
112
});
113
103
114
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.8542     ,"Receiving tax excluded, round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
104
is( $order_exc_tax->unitprice_tax_excluded+0 ,9.8542     ,"Receiving tax excluded, round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
115
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7905503 ,"Receiving tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
105
is( $order_exc_tax->unitprice_tax_included+0 ,11.7905503 ,"Receiving tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
116
is( $order_with_prices->{tax_value_on_receiving}+0  ,15.4842   ,"Receiving tax excluded, round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
106
is( $order_exc_tax->tax_value_on_receiving+0  ,15.4842   ,"Receiving tax excluded, round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
117
107
118
108
109
my $basket_inc_tax = Koha::Acquisition::Basket->new(
110
    {
111
        basketname => 'Basket tax included',
112
        booksellerid => $bookseller_inc_tax->id,
113
    }
114
)->store;
119
115
120
my $order_inc_tax = {
116
my $order_inc_tax = Koha::Acquisition::Order->new({
121
    tax_rate  => .1965,
117
    tax_rate_on_ordering  => .1965,
118
    tax_rate_on_receiving => .1965,
122
    discount  => .42,
119
    discount  => .42,
123
    rrp       => 20.33,
120
    rrp       => 20.33,
124
    unitprice => 0.00,
121
    unitprice => 0.00,
125
    quantity  => 8,
122
    quantity  => 8,
126
};
123
    basketno => $basket_inc_tax->basketno,
124
});
127
125
128
#Vendor prices include tax, no rounding, ordering
126
#Vendor prices include tax, no rounding, ordering
129
t::lib::Mocks::mock_preference('OrderPriceRounding', '');
127
t::lib::Mocks::mock_preference('OrderPriceRounding', '');
130
$order_with_prices = C4::Acquisition::populate_order_with_prices({
128
$order_inc_tax->populate_with_prices_for_ordering();
131
    ordering     => 1,
132
    booksellerid => $bookseller_inc_tax->id,
133
    order        => $order_inc_tax,
134
});
135
129
136
is( $order_with_prices->{rrp_tax_included}+0      ,20.33            ,"Ordering tax included, no round: rrp tax included is rrp");
130
is( $order_inc_tax->rrp_tax_included+0      ,20.33            ,"Ordering tax included, no round: rrp tax included is rrp");
137
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
131
is( $order_inc_tax->rrp_tax_excluded+0      ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
138
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
132
is( $order_inc_tax->ecost_tax_included+0    ,11.7914          ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
139
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
133
is( $order_inc_tax->ecost_tax_excluded+0    ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
140
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4919187630589 ,"Ordering tax included, no round: tax value on ordering is ( ecost tax included - ecost tax excluded ) * quantity if no unitprice");
134
is( $order_inc_tax->tax_value_on_ordering+0 ,15.4919187630589 ,"Ordering tax included, no round: tax value on ordering is ( ecost tax included - ecost tax excluded ) * quantity if no unitprice");
141
135
142
$order_inc_tax->{unitprice} = 11.79;
136
$order_inc_tax->unitprice(11.79);
143
$order_with_prices = C4::Acquisition::populate_order_with_prices({
137
$order_inc_tax->populate_with_prices_for_ordering();
144
    ordering     => 1,
145
    booksellerid => $bookseller_inc_tax->id,
146
    order        => $order_inc_tax,
147
});
148
138
149
is( $order_with_prices->{unitprice_tax_included}+0 ,11.79             ,"Ordering tax included, no round: unitprice tax included is unitprice");
139
is( $order_inc_tax->unitprice_tax_included+0 ,11.79             ,"Ordering tax included, no round: unitprice tax included is unitprice");
150
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85374007521939  ,"Ordering tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
140
is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85374007521939  ,"Ordering tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
151
is( $order_with_prices->{tax_value_on_ordering}+0  ,15.4900793982449  ,"Ordering tax included, no round: tax value on ordering is ( unitprice tax included - unitprice tax excluded ) * quantity if unitprice");
141
is( $order_inc_tax->tax_value_on_ordering+0  ,15.4900793982449  ,"Ordering tax included, no round: tax value on ordering is ( unitprice tax included - unitprice tax excluded ) * quantity if unitprice");
152
142
153
#Vendor prices include tax, no rounding, receiving
143
#Vendor prices include tax, no rounding, receiving
154
$order_with_prices = C4::Acquisition::populate_order_with_prices({
144
$order_inc_tax->populate_with_prices_for_receiving();
155
    receiving     => 1,
156
    booksellerid => $bookseller_inc_tax->id,
157
    order        => $order_inc_tax,
158
});
159
145
160
is( $order_with_prices->{unitprice}+0              ,11.7914          ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
146
is( $order_inc_tax->unitprice+0              ,11.7914          ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
161
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7914          ,"Receiving tax included, no round: unitprice tax included is unitprice");
147
is( $order_inc_tax->unitprice_tax_included+0 ,11.7914          ,"Receiving tax included, no round: unitprice tax included is unitprice");
162
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
148
is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
163
is( $order_with_prices->{tax_value_on_receiving}+0 ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
149
is( $order_inc_tax->tax_value_on_receiving+0 ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
164
150
165
#Vendor prices include tax, rounding to nearest cent, ordering
151
#Vendor prices include tax, rounding to nearest cent, ordering
166
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
152
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
167
$order_inc_tax->{unitprice} = 11.79;
153
$order_inc_tax->unitprice(11.79);
168
$order_with_prices = C4::Acquisition::populate_order_with_prices({
154
$order_inc_tax->populate_with_prices_for_ordering();
169
    ordering     => 1,
170
    booksellerid => $bookseller_inc_tax->id,
171
    order        => $order_inc_tax,
172
});
173
155
174
is( $order_with_prices->{unitprice_tax_included}+0      ,11.79      ,"Ordering tax included, round: unitprice tax included is unitprice");
156
is( $order_inc_tax->unitprice_tax_included+0      ,11.79      ,"Ordering tax included, round: unitprice tax included is unitprice");
175
is( $order_with_prices->{unitprice_tax_excluded}+0,9.85374007521939 ,"Ordering tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
157
is( $order_inc_tax->unitprice_tax_excluded+0,9.85374007521939 ,"Ordering tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
176
is( $order_with_prices->{rrp_tax_included}+0      ,20.33            ,"Ordering tax included, round: rrp tax included is rrp");
158
is( $order_inc_tax->rrp_tax_included+0      ,20.33            ,"Ordering tax included, round: rrp tax included is rrp");
177
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
159
is( $order_inc_tax->rrp_tax_excluded+0      ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
178
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
160
is( $order_inc_tax->ecost_tax_included+0    ,11.7914          ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
179
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.85491015461764 ,"Ordering tax included, round: ecost tax excluded is rounded ecost tax excluded * (1 - discount)");
161
is( $order_inc_tax->ecost_tax_excluded+0    ,9.85491015461764 ,"Ordering tax included, round: ecost tax excluded is rounded ecost tax excluded * (1 - discount)");
180
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.52            ,"Ordering tax included, round: tax value on ordering is (ecost_tax_included - ecost_tax_excluded) * quantity");
162
is( $order_inc_tax->tax_value_on_ordering+0 ,15.52            ,"Ordering tax included, round: tax value on ordering is (ecost_tax_included - ecost_tax_excluded) * quantity");
181
163
182
#Vendor prices include tax, no rounding, receiving
164
#Vendor prices include tax, no rounding, receiving
183
$order_with_prices = C4::Acquisition::populate_order_with_prices({
165
$order_inc_tax->populate_with_prices_for_receiving();
184
    receiving     => 1,
185
    booksellerid => $bookseller_inc_tax->id,
186
    order        => $order_inc_tax,
187
});
188
166
189
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7914          ,"Receiving tax included, round: rounded ecost tax included = rounded unitprice : unitprice tax excluded is ecost tax included");
167
is( $order_inc_tax->unitprice_tax_included+0 ,11.7914          ,"Receiving tax included, round: rounded ecost tax included = rounded unitprice : unitprice tax excluded is ecost tax included");
190
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85491015461764 ,"Receiving tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax rate on ordering)");
168
is( $order_inc_tax->unitprice_tax_excluded+0 ,9.85491015461764 ,"Receiving tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax rate on ordering)");
191
is( $order_with_prices->{tax_value_on_receiving}+0  ,15.4842         ,"Receiving tax included, round: tax value on receiving is quantity * (rounded unitprice_tax_excluded) * tax rate on receiving");
169
is( $order_inc_tax->tax_value_on_receiving+0  ,15.4842         ,"Receiving tax included, round: tax value on receiving is quantity * (rounded unitprice_tax_excluded) * tax rate on receiving");
192
170
193
171
194
$schema->storage->txn_rollback();
172
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Budgets.t (-13 / +12 lines)
Lines 8-14 BEGIN { Link Here
8
}
8
}
9
use C4::Context;
9
use C4::Context;
10
use C4::Biblio qw( AddBiblio );
10
use C4::Biblio qw( AddBiblio );
11
use C4::Acquisition qw( NewBasket AddInvoice GetInvoice ModReceiveOrder populate_order_with_prices );
11
use C4::Acquisition qw( NewBasket AddInvoice GetInvoice ModReceiveOrder );
12
12
13
use Koha::ActionLogs;
13
use Koha::ActionLogs;
14
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Booksellers;
Lines 37-46 my $library = $builder->build({ Link Here
37
    source => 'Branch',
37
    source => 'Branch',
38
});
38
});
39
39
40
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
41
$patron->store;
42
40
t::lib::Mocks::mock_userenv(
43
t::lib::Mocks::mock_userenv(
41
    {
44
    {
42
        flags => 1,
45
        flags => 1,
43
        userid => 'my_userid',
46
        userid => $patron->userid,
47
        borrowernumber => $patron->borrowernumber,
44
        branch => $library->{branchcode},
48
        branch => $library->{branchcode},
45
    }
49
    }
46
);
50
);
Lines 1073-1083 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
1073
1077
1074
#Okay we have basically what the user would enter, now we do some maths
1078
#Okay we have basically what the user would enter, now we do some maths
1075
1079
1076
    $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
1080
    my $spent_order_obj = Koha::Acquisition::Order->new($spent_orderinfo);
1077
            order        => $spent_orderinfo,
1081
    $spent_order_obj->populate_with_prices_for_ordering();
1078
            booksellerid => $spent_orderinfo->{booksellerid},
1082
    $spent_orderinfo = $spent_order_obj->unblessed();
1079
            ordering     => 1,
1080
    });
1081
1083
1082
#And let's place the order
1084
#And let's place the order
1083
1085
Lines 1160-1170 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
1160
1162
1161
#Do our maths
1163
#Do our maths
1162
1164
1163
    $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
1165
    $spent_order_obj = Koha::Acquisition::Order->new($spent_orderinfo);
1164
            order        => $spent_orderinfo,
1166
    $spent_order_obj->populate_with_prices_for_receiving();
1165
            booksellerid => $spent_orderinfo->{booksellerid},
1167
    $spent_orderinfo = $spent_order_obj->unblessed();
1166
            receiving    => 1,
1167
    });
1168
    my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
1168
    my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
1169
1169
1170
#And receive a copy of the order so we have both spent and ordered values
1170
#And receive a copy of the order so we have both spent and ordered values
1171
- 

Return to bug 29955