3 use Test::More tests => 13;
5 use_ok('C4::Acquisition');
7 use_ok('C4::Bookseller');
11 use Koha::Acquisition::Order;
15 my $schema = Koha::Database->new()->schema();
16 $schema->storage->txn_begin();
17 my $dbh = C4::Context->dbh;
18 $dbh->{RaiseError} = 1;
20 my $booksellerid = C4::Bookseller::AddBookseller(
23 address1 => "bookseller's address",
29 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
31 my $bpid = AddBudgetPeriod({
32 budget_period_startdate => '01-01-2015',
33 budget_period_enddate => '12-31-2015',
34 budget_period_description => "budget desc"
37 my $budget_id = AddBudget({
38 budget_code => "ABCD",
39 budget_amount => "123.132",
40 budget_name => "Périodiques",
41 budget_notes => "This is a note",
42 budget_period_id => $bpid
45 my $subscriptionid = NewSubscription(
46 undef, "", undef, undef, $budget_id, $biblionumber,
47 '01-01-2013',undef, undef, undef, undef,
48 undef, undef, undef, undef, undef, undef,
49 1, "notes",undef, '01-01-2013', undef, undef,
50 undef, undef, 0, "intnotes", 0,
51 undef, undef, 0, undef, '31-12-2013', 0
53 die unless $subscriptionid;
55 my ($basket, $basketno);
56 ok($basketno = NewBasket($booksellerid, 1), "NewBasket( $booksellerid , 1 ) returns $basketno");
59 my $subscription = GetSubscription( $subscriptionid );
61 my $order = Koha::Acquisition::Order->new({
62 biblionumber => $subscription->{biblionumber},
63 entrydate => '01-01-2013',
67 notes => "This is a note",
68 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 = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
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 => $booksellerid, unknown => "unknown");
88 my $invoice = GetInvoice( $invoiceid );
89 $invoice->{datereceived} = '02-01-2013';
91 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
93 biblionumber => $biblionumber,
95 quantityreceived => 1,
96 budget_id => $budget_id,
101 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
102 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
103 ok( $order->{ecost} == $cost, "test cost for the last order received");
105 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
106 is ( $order, undef, "test no not received order for a received order");
108 my @invoices = GetInvoices();
109 my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
110 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
113 $schema->storage->txn_rollback();