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::Order;
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 => '01-01-2015',
37 budget_period_enddate => '12-31-2015',
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 '01-01-2013',undef, undef, undef, undef,
52 undef, undef, undef, undef, undef, undef,
53 1, "notes",undef, '01-01-2013', undef, undef,
54 undef, undef, 0, "intnotes", 0,
55 undef, undef, 0, undef, '31-12-2013', 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 => '01-01-2013',
71 notes => "This is a note",
72 basketno => $basketno,
77 subscriptionid => $subscription->{subscriptionid},
78 budget_id => $budget_id,
80 my $ordernumber = $order->{ordernumber};
82 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
83 is ( $is_currently_on_order, 1, "The subscription is currently on order");
85 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
86 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
87 ok( $order->{ecost} == $cost, "test cost for the last order not received");
89 $dbh->do(q{DELETE FROM aqinvoices});
90 my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $bookseller->id, unknown => "unknown");
92 my $invoice = GetInvoice( $invoiceid );
93 $invoice->{datereceived} = '02-01-2013';
95 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
97 biblionumber => $biblionumber,
99 quantityreceived => 1,
100 budget_id => $budget_id,
105 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
106 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
107 ok( $order->{ecost} == $cost, "test cost for the last order received");
109 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
110 is ( $order, undef, "test no not received order for a received order");
112 my @invoices = GetInvoices();
113 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
114 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
117 $schema->storage->txn_rollback();