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;
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, '');
34 my $bpid = AddBudgetPeriod({
35 budget_period_startdate => '2015-01-01',
36 budget_period_enddate => '2015-12-31',
37 budget_period_description => "budget desc"
40 my $budget_id = AddBudget({
41 budget_code => "ABCD",
42 budget_amount => "123.132",
43 budget_name => "Périodiques",
44 budget_notes => "This is a note",
45 budget_period_id => $bpid
48 my $subscriptionid = NewSubscription(
49 undef, "", undef, undef, $budget_id, $biblionumber,
50 '2013-01-01',undef, undef, undef, undef,
51 undef, undef, undef, undef, undef, undef,
52 1, "notes",undef, '2013-01-01', undef, undef,
53 undef, undef, 0, "intnotes", 0,
54 undef, undef, 0, undef, '2013-12-31', 0
56 die unless $subscriptionid;
58 my ($basket, $basketno);
59 ok($basketno = NewBasket($bookseller->id, 1), "NewBasket( " . $bookseller->id . ", 1 ) returns $basketno");
62 my $subscription = GetSubscription( $subscriptionid );
64 my $order = Koha::Acquisition::Order->new({
65 biblionumber => $subscription->{biblionumber},
66 entrydate => '2013-01-01',
70 basketno => $basketno,
74 subscriptionid => $subscription->{subscriptionid},
75 budget_id => $budget_id,
77 my $ordernumber = $order->ordernumber;
79 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
80 is ( $is_currently_on_order, 1, "The subscription is currently on order");
82 $order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef })->next->unblessed;
83 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
84 ok( $order->{ecost} == $cost, "test cost for the last order not received");
86 $dbh->do(q{DELETE FROM aqinvoices});
87 my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown");
89 my $invoice = GetInvoice( $invoiceid );
90 $invoice->{datereceived} = '2013-01-02';
92 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
94 biblionumber => $biblionumber,
96 quantityreceived => 1,
97 budget_id => $budget_id,
102 $order = Koha::Acquisition::Orders->search(
104 subscriptionid => $subscriptionid,
105 datereceived => { '!=' => undef }
108 order_by => [ { -desc => 'datereceived' }, { -desc => 'ordernumber' } ]
112 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
113 ok( $order->{ecost} == $cost, "test cost for the last order received");
115 $order = Koha::Acquisition::Orders->search({ subscriptionid => $subscription->{subscriptionid}, datereceived => undef });
116 is ( $order->count, 0, "test no not received order for a received order");
118 my @invoices = GetInvoices();
119 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
120 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
123 $schema->storage->txn_rollback();