2 use Test::More tests => 13;
8 use Koha::DateUtils qw( dt_from_string output_pref );
10 my $dbh = C4::Context->dbh;
11 $dbh->{AutoCommit} = 0;
12 $dbh->{RaiseError} = 1;
14 $dbh->do(q|DELETE FROM issues|);
16 my $branchcode = 'CPL';
17 my $bpid = AddBudgetPeriod({
18 budget_period_startdate => '2015-01-01',
19 budget_period_enddate => '2015-12-31',
20 budget_period_description => "budget desc"
23 my $budget_id = AddBudget({
24 budget_code => "ABCD",
25 budget_amount => "123.132",
26 budget_name => "Périodiques",
27 budget_notes => "This is a note",
28 budget_period_id => $bpid
31 my $record = MARC::Record->new();
32 my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
34 my $sample_supplier1 = {
36 address1 => 'address1_1',
37 address2 => 'address1-2',
38 address3 => 'address1_2',
39 address4 => 'address1_2',
42 accountnumber => 'accountnumber1',
54 my $sample_supplier2 = {
56 address1 => 'address1_2',
57 address2 => 'address2-2',
58 address3 => 'address3_2',
59 address4 => 'address4_2',
62 accountnumber => 'accountnumber2',
75 my $supplier_id1 = C4::Bookseller::AddBookseller($sample_supplier1);
76 my $supplier_id2 = C4::Bookseller::AddBookseller($sample_supplier2);
78 my $supplierlist = eval { GetSuppliersWithLateIssues() };
79 is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" );
80 is ( scalar(@$supplierlist), 0, 'There is no late issues yet');
82 my $subscriptionid_not_late = NewSubscription(
83 undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
84 '2013-01-01', undef, undef, undef, undef,
85 undef, undef, undef, undef, undef, undef,
86 1, "notes",undef, '9999-01-01', undef, undef,
87 undef, undef, 0, "intnotes", 0,
88 undef, undef, 0, undef, '2013-12-31', 0
90 $supplierlist = GetSuppliersWithLateIssues();
91 is ( scalar(@$supplierlist), 0, 'There is still no late issues yet');
93 my $subscriptionid_inlate1 = NewSubscription(
94 undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
95 '2013-01-01', undef, undef, undef, undef,
96 undef, undef, undef, undef, undef, undef,
97 1, "notes",undef, '2013-01-01', undef, undef,
98 undef, undef, 0, "intnotes", 0,
99 undef, undef, 0, undef, '2013-12-31', 0
102 my $subscriptionid_inlate2 = NewSubscription(
103 undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
104 '2013-01-01', undef, undef, undef, undef,
105 undef, undef, undef, undef, undef, undef,
106 1, "notes",undef, '2013-01-01', undef, undef,
107 undef, undef, 0, "intnotes", 0,
108 undef, undef, 0, undef, '2013-12-31', 0
111 my $subscriptionid_inlate3 = NewSubscription(
112 undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
113 '2013-01-02', undef, undef, undef, undef,
114 undef, undef, undef, undef, undef, undef,
115 1, "notes",undef, '2013-01-02', undef, undef,
116 undef, undef, 0, "intnotes", 0,
117 undef, undef, 0, undef, '2013-12-31', 0
121 $supplierlist = GetSuppliersWithLateIssues();
122 is ( scalar(@$supplierlist), 2, '2 suppliers should have issues in late');
124 is( GetLateOrMissingIssues(), undef, 'GetLateOrMissingIssues should return undef without parameter' );
126 my @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id1 );
127 is( scalar(@late_or_missing_issues), 1, 'supplier 1 should have 1 issue in late' );
129 @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
130 is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late' );
132 is( exists $late_or_missing_issues[0]->{claimdate}, 1, 'GetLateOrMissingIssues returns claimdate' );
133 is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' );
134 is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' );
136 my $serialid_to_claim = $late_or_missing_issues[0]->{serialid};
137 updateClaim( $serialid_to_claim );
139 @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
140 is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late (already claimed issues are returns)' );
142 my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues;
143 is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
145 my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
146 # FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format!
147 #is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' );