Bug 5336: (follow-up) use understandable codes rather than magic numbers for orderstatus
[koha.git] / t / db_dependent / Acquisition / OrderFromSubscription.t
1 use Modern::Perl;
2
3 use Test::More tests => 12;
4 use Data::Dumper;
5
6 use_ok('C4::Acquisition');
7 use_ok('C4::Biblio');
8 use_ok('C4::Budgets');
9 use_ok('C4::Serials');
10
11 # Start transaction
12 my $dbh = C4::Context->dbh;
13 $dbh->{AutoCommit} = 0;
14 $dbh->{RaiseError} = 1;
15
16 my $supplierlist=eval{GetSuppliersWithLateIssues()};
17 ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
18
19 my $booksellerid = C4::Bookseller::AddBookseller(
20     {
21         name => "my vendor",
22         address1 => "bookseller's address",
23         phone => "0123456",
24         active => 1
25     }
26 );
27
28 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
29 my $budgetid;
30 my $bpid = AddBudgetPeriod({
31     budget_period_startdate => '01-01-2015',
32     budget_period_enddate   => '12-31-2015',
33     budget_description      => "budget desc"
34 });
35
36 my $budget_id = AddBudget({
37     budget_code        => "ABCD",
38     budget_amount      => "123.132",
39     budget_name        => "Périodiques",
40     budget_notes       => "This is a note",
41     budget_description => "Serials",
42     budget_active      => 1,
43     budget_period_id   => $bpid
44 });
45
46 my $subscriptionid = NewSubscription(
47     undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
48     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
49     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
50     undef,      undef,  undef, undef, undef,      undef,         undef,  1,
51     "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
52     "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
53 );
54 die unless $subscriptionid;
55
56 my ($basket, $basketno);
57 ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
58
59 my $cost = 42.00;
60 my $subscription = GetSubscription( $subscriptionid );
61 my $ordernumber;
62 ( $basketno, $ordernumber ) = NewOrder({
63     biblionumber => $subscription->{biblionumber},
64     entrydate => '01-01-2013',
65     quantity => 1,
66     currency => 'USD',
67     listprice => $cost,
68     notes => "This is a note",
69     basketno => $basketno,
70     rrp => $cost,
71     ecost => $cost,
72     gstrate => 0.0500,
73     orderstatus => 'new',
74     subscriptionid => $subscription->{subscriptionid},
75     budget_id => $budget_id,
76 });
77
78 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
79 is ( $is_currently_on_order, 1, "The subscription is currently on order");
80
81 my $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
82 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
83 ok( $order->{ecost} == $cost, "test cost for the last order not received");
84
85 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
86     $biblionumber, $ordernumber, 1, undef, $cost, $cost,
87     undef, $cost, $budget_id, '02-01-2013', undef);
88
89 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
90 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
91 ok( $order->{ecost} == $cost, "test cost for the last order received");
92
93 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
94 is ( $order, undef, "test no not received order for a received order");
95
96 # Cleanup
97 $dbh->rollback;