3 use Test::More tests => 12;
5 use t::lib::TestBuilder;
7 use_ok('C4::Acquisition');
10 use_ok('C4::Serials');
12 use Koha::Acquisition::Orders;
16 my $schema = Koha::Database->new()->schema();
17 $schema->storage->txn_begin();
18 my $builder = t::lib::TestBuilder->new;
19 my $dbh = C4::Context->dbh;
20 $dbh->{RaiseError} = 1;
22 my $curcode = $builder->build({ source => 'Currency' })->{currencycode};
24 my $bookseller = Koha::Acquisition::Bookseller->new(
27 address1 => "bookseller's address",
33 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
35 my $bpid = AddBudgetPeriod({
36 budget_period_startdate => '2015-01-01',
37 budget_period_enddate => '2015-12-31',
38 budget_period_description => "budget desc"
41 my $budget_id = AddBudget({
42 budget_code => "ABCD",
43 budget_amount => "123.132",
44 budget_name => "Périodiques",
45 budget_notes => "This is a note",
46 budget_period_id => $bpid
49 my $subscriptionid = NewSubscription(
50 undef, "", undef, undef, $budget_id, $biblionumber,
51 '2013-01-01',undef, undef, undef, undef,
52 undef, undef, undef, undef, undef, undef,
53 1, "notes",undef, '2013-01-01', undef, undef,
54 undef, undef, 0, "intnotes", 0,
55 undef, undef, 0, undef, '2013-12-31', 0
57 die unless $subscriptionid;
59 my ($basket, $basketno);
60 ok($basketno = NewBasket($bookseller->id, 1), "NewBasket( " . $bookseller->id . ", 1 ) returns $basketno");
63 my $subscription = GetSubscription( $subscriptionid );
65 my $order = Koha::Acquisition::Order->new({
66 biblionumber => $subscription->{biblionumber},
67 entrydate => '2013-01-01',
71 basketno => $basketno,
75 subscriptionid => $subscription->{subscriptionid},
76 budget_id => $budget_id,
78 my $ordernumber = $order->ordernumber;
80 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
81 is ( $is_currently_on_order, 1, "The subscription is currently on order");
83 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
84 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
85 ok( $order->{ecost} == $cost, "test cost for the last order not received");
87 $dbh->do(q{DELETE FROM aqinvoices});
88 my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown");
90 my $invoice = GetInvoice( $invoiceid );
91 $invoice->{datereceived} = '2013-01-02';
93 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
95 biblionumber => $biblionumber,
97 quantityreceived => 1,
98 budget_id => $budget_id,
103 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
104 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
105 ok( $order->{ecost} == $cost, "test cost for the last order received");
107 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
108 is ( $order, undef, "test no not received order for a received order");
110 my @invoices = GetInvoices();
111 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
112 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
115 $schema->storage->txn_rollback();