3 use Test::More tests => 12;
6 use_ok('C4::Acquisition');
12 my $dbh = C4::Context->dbh;
13 $dbh->{AutoCommit} = 0;
14 $dbh->{RaiseError} = 1;
16 my $booksellerid = C4::Bookseller::AddBookseller(
19 address1 => "bookseller's address",
25 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
27 my $bpid = AddBudgetPeriod({
28 budget_period_startdate => '01-01-2015',
29 budget_period_enddate => '12-31-2015',
30 budget_period_description => "budget desc"
33 my $budget_id = AddBudget({
34 budget_code => "ABCD",
35 budget_amount => "123.132",
36 budget_name => "Périodiques",
37 budget_notes => "This is a note",
38 budget_period_id => $bpid
41 my $subscriptionid = NewSubscription(
42 undef, "", undef, undef, $budget_id, $biblionumber,
43 '01-01-2013',undef, undef, undef, undef,
44 undef, undef, undef, undef, undef, undef,
45 1, "notes",undef, '01-01-2013', undef, undef,
46 undef, undef, 0, "intnotes", 0,
47 undef, undef, 0, undef, '31-12-2013', 0
49 die unless $subscriptionid;
51 my ($basket, $basketno);
52 ok($basketno = NewBasket($booksellerid, 1), "NewBasket( $booksellerid , 1 ) returns $basketno");
55 my $subscription = GetSubscription( $subscriptionid );
57 $ordernumber = NewOrder({
58 biblionumber => $subscription->{biblionumber},
59 entrydate => '01-01-2013',
63 notes => "This is a note",
64 basketno => $basketno,
69 subscriptionid => $subscription->{subscriptionid},
70 budget_id => $budget_id,
73 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
74 is ( $is_currently_on_order, 1, "The subscription is currently on order");
76 my $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
77 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
78 ok( $order->{ecost} == $cost, "test cost for the last order not received");
80 $dbh->do(q{DELETE FROM aqinvoices});
81 my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
83 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
85 biblionumber => $biblionumber,
86 ordernumber => $ordernumber,
87 quantityreceived => 1,
91 budget_id => $budget_id,
92 datereceived => '02-01-2013',
93 invoiceid => $invoiceid,
97 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
98 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
99 ok( $order->{ecost} == $cost, "test cost for the last order received");
101 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
102 is ( $order, undef, "test no not received order for a received order");
104 my @invoices = GetInvoices();
105 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
106 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');