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 my $branchcode = 'CPL';
15 my $bpid = AddBudgetPeriod({
16 budget_period_startdate => '2015-01-01',
17 budget_period_enddate => '2015-12-31',
18 budget_period_description => "budget desc"
21 my $budget_id = AddBudget({
22 budget_code => "ABCD",
23 budget_amount => "123.132",
24 budget_name => "Périodiques",
25 budget_notes => "This is a note",
26 budget_period_id => $bpid
29 my $record = MARC::Record->new();
30 my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
32 my $sample_supplier1 = {
34 address1 => 'address1_1',
35 address2 => 'address1-2',
36 address3 => 'address1_2',
37 address4 => 'address1_2',
40 accountnumber => 'accountnumber1',
52 my $sample_supplier2 = {
54 address1 => 'address1_2',
55 address2 => 'address2-2',
56 address3 => 'address3_2',
57 address4 => 'address4_2',
60 accountnumber => 'accountnumber2',
73 my $supplier_id1 = C4::Bookseller::AddBookseller($sample_supplier1);
74 my $supplier_id2 = C4::Bookseller::AddBookseller($sample_supplier2);
76 my $supplierlist = eval { GetSuppliersWithLateIssues() };
77 is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" );
78 is ( scalar(@$supplierlist), 0, 'There is no late issues yet');
80 my $subscriptionid_not_late = NewSubscription(
81 undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
82 '2013-01-01', undef, undef, undef, undef,
83 undef, undef, undef, undef, undef, undef,
84 1, "notes",undef, '9999-01-01', undef, undef,
85 undef, undef, 0, "intnotes", 0,
86 undef, undef, 0, undef, '2013-12-31', 0
88 $supplierlist = GetSuppliersWithLateIssues();
89 is ( scalar(@$supplierlist), 0, 'There is still no late issues yet');
91 my $subscriptionid_inlate1 = NewSubscription(
92 undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
93 '2013-01-01', undef, undef, undef, undef,
94 undef, undef, undef, undef, undef, undef,
95 1, "notes",undef, '2013-01-01', undef, undef,
96 undef, undef, 0, "intnotes", 0,
97 undef, undef, 0, undef, '2013-12-31', 0
100 my $subscriptionid_inlate2 = NewSubscription(
101 undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
102 '2013-01-01', undef, undef, undef, undef,
103 undef, undef, undef, undef, undef, undef,
104 1, "notes",undef, '2013-01-01', undef, undef,
105 undef, undef, 0, "intnotes", 0,
106 undef, undef, 0, undef, '2013-12-31', 0
109 my $subscriptionid_inlate3 = NewSubscription(
110 undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
111 '2013-01-02', undef, undef, undef, undef,
112 undef, undef, undef, undef, undef, undef,
113 1, "notes",undef, '2013-01-02', undef, undef,
114 undef, undef, 0, "intnotes", 0,
115 undef, undef, 0, undef, '2013-12-31', 0
119 $supplierlist = GetSuppliersWithLateIssues();
120 is ( scalar(@$supplierlist), 2, '2 suppliers should have issues in late');
122 is( GetLateOrMissingIssues(), undef, 'GetLateOrMissingIssues should return undef without parameter' );
124 my @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id1 );
125 is( scalar(@late_or_missing_issues), 1, 'supplier 1 should have 1 issue in late' );
127 @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
128 is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late' );
130 is( exists $late_or_missing_issues[0]->{claimdate}, 1, 'GetLateOrMissingIssues returns claimdate' );
131 is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' );
132 is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' );
134 my $serialid_to_claim = $late_or_missing_issues[0]->{serialid};
135 updateClaim( $serialid_to_claim );
137 @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
138 is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late (already claimed issues are returns)' );
140 my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues;
141 is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
143 my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
144 # FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format!
145 #is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' );