- # CircControl must be PickupLibrary. (branchcode comes from issues table here).
- $branchcode = $data->[$i]->{'branchcode'};
- }
- my $calendar = C4::Calendar->new( branchcode => $branchcode );
-
- my $isHoliday = $calendar->isHoliday( split( '/', C4::Dates->new()->output('metric') ) );
+ $fldir = $ENV{TMPDIR} || "/tmp";
+}
+if (!-d $fldir) {
+ warn "Could not write to $fldir ... does not exist!";
+}
+$filename = $dbname;
+$filename =~ s/\W//;
+$filename = $fldir . '/'. $filename . '_' . $today_iso . ".log";
+print "writing to $filename\n" if $verbose;
+open (FILE, ">$filename") or die "Cannot write file $filename: $!";
+print FILE join $delim, (@borrower_fields, @item_fields, @other_fields);
+print FILE "\n";
+
+for (my $i=0; $i<scalar(@$data); $i++) {
+ my $datedue = C4::Dates->new($data->[$i]->{'date_due'},'iso');
+ my $datedue_days = Date_to_Days(split(/-/,$datedue->output('iso')));
+ my $due_str = $datedue->output();
+ unless (defined $data->[$i]->{'borrowernumber'}) {
+ print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL. Repair 'issues' table now! Skipping record.\n";
+ next; # Note: this doesn't solve everything. After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
+ }
+ my $borrower = BorType($data->[$i]->{'borrowernumber'});
+ my $branchcode = ($control eq 'ItemHomeLibrary') ? $data->[$i]->{homebranch} :
+ ($control eq 'PatronLibrary' ) ? $borrower->{branchcode} :
+ $data->[$i]->{branchcode} ;
+ # In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
+ my $calendar;
+ unless (defined ($calendars{$branchcode})) {
+ $calendars{$branchcode} = C4::Calendar->new(branchcode => $branchcode);
+ }
+ $calendar = $calendars{$branchcode};
+ my $isHoliday = $calendar->isHoliday(split '/', $today->output('metric'));