3 use Test::More tests => 12;
5 use t::lib::TestBuilder;
7 use_ok('C4::Acquisition', qw( NewBasket AddInvoice GetInvoice ModReceiveOrder GetInvoices ));
8 use_ok('C4::Biblio', qw( AddBiblio ));
9 use_ok('C4::Budgets', qw( AddBudgetPeriod AddBudget ));
10 use_ok('C4::Serials', qw( NewSubscription GetSubscription subscriptionCurrentlyOnOrder ));
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;
21 my $curcode = $builder->build({ source => 'Currency' })->{currencycode};
23 my $bookseller = Koha::Acquisition::Bookseller->new(
26 address1 => "bookseller's address",
32 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
33 my $bpid = AddBudgetPeriod({
34 budget_period_startdate => '2015-01-01',
35 budget_period_enddate => '2015-12-31',
36 budget_period_description => "budget desc"
39 my $budget_id = AddBudget({
40 budget_code => "ABCD",
41 budget_amount => "123.132",
42 budget_name => "Périodiques",
43 budget_notes => "This is a note",
44 budget_period_id => $bpid
47 my $subscriptionid = NewSubscription(
48 undef, "", undef, undef, $budget_id, $biblionumber,
49 '2013-01-01',undef, undef, undef, undef,
50 undef, undef, undef, undef, undef, undef,
51 1, "notes",undef, '2013-01-01', undef, undef,
52 undef, undef, 0, "intnotes", 0,
53 undef, undef, 0, undef, '2013-12-31', 0
55 die unless $subscriptionid;
58 ok($basketno = NewBasket($bookseller->id, 1), "NewBasket( " . $bookseller->id . ", 1 ) returns $basketno");
61 my $subscription = GetSubscription( $subscriptionid );
63 my $order = Koha::Acquisition::Order->new({
64 biblionumber => $subscription->{biblionumber},
65 entrydate => '2013-01-01',
69 basketno => $basketno,
73 subscriptionid => $subscription->{subscriptionid},
74 budget_id => $budget_id,
76 my $ordernumber = $order->ordernumber;
78 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
79 is ( $is_currently_on_order, 1, "The subscription is currently on order");
81 $order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef })->next->unblessed;
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");
85 $dbh->do(q{DELETE FROM aqinvoices});
86 my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown");
88 my $invoice = GetInvoice( $invoiceid );
89 $invoice->{datereceived} = '2013-01-02';
91 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
93 biblionumber => $biblionumber,
95 quantityreceived => 1,
96 budget_id => $budget_id,
101 $order = Koha::Acquisition::Orders->search(
103 subscriptionid => $subscriptionid,
104 datereceived => { '!=' => undef }
107 order_by => [ { -desc => 'datereceived' }, { -desc => 'ordernumber' } ]
111 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
112 ok( $order->{ecost} == $cost, "test cost for the last order received");
114 $order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef });
115 is ( $order->count, 0, "test no not received order for a received order");
117 my @invoices = GetInvoices();
118 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
119 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
122 $schema->storage->txn_rollback();