View | Details | Raw Unified | Return to bug 5878
Collapse All | Expand All

(-)a/misc/cronjobs/overdue_notices.pl (-49 / +84 lines)
Lines 40-45 use C4::Dates qw/format_date/; Link Here
40
use C4::Debug;
40
use C4::Debug;
41
use C4::Letters;
41
use C4::Letters;
42
use C4::Overdues qw(GetFine);
42
use C4::Overdues qw(GetFine);
43
use C4::Reports::Guided; #_get_column_defs
44
use open qw(:std :utf8);
45
use YAML;
43
46
44
=head1 NAME
47
=head1 NAME
45
48
Lines 256-262 my $csvfilename; Link Here
256
my $htmlfilename;
259
my $htmlfilename;
257
my $triggered = 0;
260
my $triggered = 0;
258
my $listall = 0;
261
my $listall = 0;
259
my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) );
262
my $itemscontent = join( ',', qw( issuedate title barcode author biblionumber date_due) );
260
my @myborcat;
263
my @myborcat;
261
my @myborcatout;
264
my @myborcatout;
262
265
Lines 267-283 GetOptions( Link Here
267
    'n'              => \$nomail,
270
    'n'              => \$nomail,
268
    'max=s'          => \$MAX,
271
    'max=s'          => \$MAX,
269
    'library=s'      => \@branchcodes,
272
    'library=s'      => \@branchcodes,
270
    'csv:s'          => \$csvfilename,    # this optional argument gets '' if not supplied.
273
    'csv:s'          => \$csvfilename,     # this optional argument gets '' if not supplied.
271
    'html:s'          => \$htmlfilename,    # this optional argument gets '' if not supplied.
274
    'html:s'         => \$htmlfilename,    # this optional argument gets '' if not supplied.
272
    'itemscontent=s' => \$itemscontent,
275
    'itemscontent=s' => \$itemscontent,
273
    'list-all'      => \$listall,
276
    'list-all'       => \$listall,
274
    't|triggered'             => \$triggered,
277
    't|triggered'    => \$triggered,
275
    'borcat=s'      => \@myborcat,
278
    'borcat=s'       => \@myborcat,
276
    'borcatout=s'   => \@myborcatout,
279
    'borcatout=s'    => \@myborcatout,
277
) or pod2usage(2);
280
) or pod2usage(2);
278
pod2usage(1) if $help;
281
pod2usage(1) if $help;
279
pod2usage( -verbose => 2 ) if $man;
282
pod2usage( -verbose => 2 ) if $man;
280
283
284
my $columns_def_hashref = C4::Reports::Guided::_get_column_defs();
285
286
foreach my $key ( keys %$columns_def_hashref ) {
287
    my $initkey = $key;
288
    $key =~ s/[^\.]*\.//;
289
    $columns_def_hashref->{$key} = $columns_def_hashref->{$initkey};
290
}
291
print Dump($columns_def_hashref);
281
if ( defined $csvfilename && $csvfilename =~ /^-/ ) {
292
if ( defined $csvfilename && $csvfilename =~ /^-/ ) {
282
    warn qq(using "$csvfilename" as filename, that seems odd);
293
    warn qq(using "$csvfilename" as filename, that seems odd);
283
}
294
}
Lines 313-319 if (@branchcodes) { Link Here
313
    } else {
324
    } else {
314
    
325
    
315
        $verbose and warn "No active overduerules for $branchcodes_word  '@branchcodes'\n";
326
        $verbose and warn "No active overduerules for $branchcodes_word  '@branchcodes'\n";
316
        ( scalar grep { '' eq $_ } @branches )
327
        ( scalar grep { $_ eq ""} @overduebranches )
317
          or die "No active overduerules for DEFAULT either!";
328
          or die "No active overduerules for DEFAULT either!";
318
        $verbose and warn "Falling back on default rules for @branchcodes\n";
329
        $verbose and warn "Falling back on default rules for @branchcodes\n";
319
        @branches = ('');
330
        @branches = ('');
Lines 353-374 if ( defined $htmlfilename ) { Link Here
353
    open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->output('iso').".html");
364
    open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->output('iso').".html");
354
  }
365
  }
355
  
366
  
356
  print $html_fh "<html>\n";
367
  print $html_fh <<HEAD;
357
  print $html_fh "<head>\n";
368
<?xml version="1.0" encoding="UTF-8"?>
358
  print $html_fh "<style type='text/css'>\n";
369
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
359
  print $html_fh "pre {page-break-after: always;}\n";
370
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
360
  print $html_fh "pre {white-space: pre-wrap;}\n";
371
<head>
361
  print $html_fh "pre {white-space: -moz-pre-wrap;}\n";
372
  <style type='text/css'>
362
  print $html_fh "pre {white-space: -o-pre-wrap;}\n";
373
    pre {page-break-after: always;}
363
  print $html_fh "pre {word-wrap: break-work;}\n";
374
    pre {white-space: pre-wrap;}
364
  print $html_fh "</style>\n";
375
    pre {white-space: -moz-pre-wrap;}
365
  print $html_fh "</head>\n";
376
    pre {white-space: -o-pre-wrap;}
366
  print $html_fh "<body>\n";
377
    pre {word-wrap: break-work;}
378
  </style>
379
</head>
380
<body>
381
HEAD
367
}
382
}
368
383
369
foreach my $branchcode (@branches) {
384
foreach my $branchcode (@branches) {
370
385
371
    my $branch_details = C4::Branch::GetBranchDetail($branchcode);
386
    my $branch_details = C4::Branch::GetBranchDetail($branchcode) unless ($branchcode eq "");
372
    my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
387
    my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
373
    my @output_chunks;    # may be sent to mail or stdout or csv file.
388
    my @output_chunks;    # may be sent to mail or stdout or csv file.
374
389
Lines 431-437 WHERE issues.borrowernumber=borrowers.borrowernumber Link Here
431
AND    borrowers.categorycode=categories.categorycode
446
AND    borrowers.categorycode=categories.categorycode
432
END_SQL
447
END_SQL
433
            my @borrower_parameters;
448
            my @borrower_parameters;
434
            if ($branchcode) {
449
            if ($branchcode && $branchcode ne "") {
435
                $borrower_sql .= ' AND issues.branchcode=? ';
450
                $borrower_sql .= ' AND issues.branchcode=? ';
436
                push @borrower_parameters, $branchcode;
451
                push @borrower_parameters, $branchcode;
437
            }
452
            }
Lines 458-463 END_SQL Link Here
458
                    $address1, $address2, $city, $postcode, $country, $email,
473
                    $address1, $address2, $city, $postcode, $country, $email,
459
                    $longest_issue ) = $sth->fetchrow )
474
                    $longest_issue ) = $sth->fetchrow )
460
            {
475
            {
476
                $email=C4::Members::GetFirstValidEmailAddress($borrowernumber);
461
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i.";
477
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i.";
462
    
478
    
463
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} );
479
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} );
Lines 473-501 END_SQL Link Here
473
                if ( $overdue_rules->{"debarred$i"} ) {
489
                if ( $overdue_rules->{"debarred$i"} ) {
474
    
490
    
475
                    #action taken is debarring
491
                    #action taken is debarring
476
                    C4::Members::DebarMember($borrowernumber);
492
                    C4::Members::DebarMember($borrowernumber, '9999-12-31');
477
                    $verbose and warn "debarring $borrowernumber $firstname $lastname\n";
493
                    $verbose and warn "debarring $borrowernumber $firstname $lastname\n";
478
                }
494
                }
479
                my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays ));
495
                my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays ));
480
                $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays";
496
                $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays";
481
                $sth2->execute(@params);
497
                $sth2->execute(@params);
482
                my $itemcount = 0;
498
                my $itemcount = 0;
483
                my $titles = "";
499
500
                my $titles;
501
                if ($htmlfilename) {
502
                    $titles = "<table id='itemscontent$borrowernumber'>";
503
                    $titles .= "<thead><tr><th>" . join( "</th><th>", @$columns_def_hashref{@item_content_fields} );
504
                    warn @item_content_fields;
505
                    warn map { "$columns_def_hashref->{$_};" } @item_content_fields;
506
                    $titles .= "</th></tr></thead><tbody>";
507
                }
484
                my @items = ();
508
                my @items = ();
485
                
509
486
                my $i = 0;
510
                my $i                            = 0;
487
                my $exceededPrintNoticesMaxLines = 0;
511
                my $exceededPrintNoticesMaxLines = 0;
488
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
512
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
489
                    if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $i >= $PrintNoticesMaxLines ) {
513
                    if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $i >= $PrintNoticesMaxLines ) {
490
                      $exceededPrintNoticesMaxLines = 1;
514
                        $exceededPrintNoticesMaxLines = 1;
491
                      last;
515
                        last;
492
                    }
516
                    }
493
                    $i++;
517
                    $i++;
494
                    my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields;
518
                    my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields;
495
                    $titles .= join("\t", @item_info) . "\n";
519
                    if ($htmlfilename) {
520
                        $titles .= "<tr><td>" . join( "</td><td>", @item_info ) . "</td></tr>";
521
                    } else {
522
                        $titles .= join( "\t", @item_info ) . "\n";
523
                    }
496
                    $itemcount++;
524
                    $itemcount++;
497
                    push @items, { itemnumber => $item_info->{'itemnumber'}, biblionumber => $item_info->{'biblionumber'} };
525
                    push @items, { itemnumber => $item_info->{'itemnumber'}, biblionumber => $item_info->{'biblionumber'} };
498
                }
526
                }
527
                $titles .= "</tbody></table>" if ($htmlfilename);
528
                $debug && warn $titles;
499
                $sth2->finish;
529
                $sth2->finish;
500
                $letter = parse_letter(
530
                $letter = parse_letter(
501
                    {   letter          => $letter,
531
                    {   letter          => $letter,
Lines 508-527 END_SQL Link Here
508
                                           }
538
                                           }
509
                    }
539
                    }
510
                );
540
                );
511
                
541
512
                if ( $exceededPrintNoticesMaxLines ) {
542
                if ($exceededPrintNoticesMaxLines) {
513
                  $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items.";
543
                    $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items.";
514
                }
544
                }
515
545
516
                my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'};
546
                my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\</, $letter->{'content'};
517
                if (@misses) {
547
                if (@misses) {
518
                    $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses;
548
                    $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses;
519
                }
549
                }
520
                $letter->{'content'} =~ s/\<[^<>]*?\>//g;    # Now that we've warned about them, remove them.
550
                $letter->{'content'} =~ s/\<\<[^<>]*?\>\>//g;    # Now that we've warned about them, remove them.
521
                $letter->{'content'} =~ s/\<[^<>]*?\>//g;    # 2nd pass for the double nesting.
551
522
    
552
                #                $letter->{'content'} =~ s/\<[^<>]*?\>//g;    # 2nd pass for the double nesting.
553
523
                if ($nomail) {
554
                if ($nomail) {
524
    
555
525
                    push @output_chunks,
556
                    push @output_chunks,
526
                      prepare_letter_for_printing(
557
                      prepare_letter_for_printing(
527
                        {   letter         => $letter,
558
                        {   letter         => $letter,
Lines 531-536 END_SQL Link Here
531
                            address1       => $address1,
562
                            address1       => $address1,
532
                            address2       => $address2,
563
                            address2       => $address2,
533
                            city           => $city,
564
                            city           => $city,
565
                            country        => $country,
534
                            postcode       => $postcode,
566
                            postcode       => $postcode,
535
                            email          => $email,
567
                            email          => $email,
536
                            itemcount      => $itemcount,
568
                            itemcount      => $itemcount,
Lines 548-554 END_SQL Link Here
548
                            }
580
                            }
549
                        );
581
                        );
550
                    } else {
582
                    } else {
551
    
583
552
                        # If we don't have an email address for this patron, send it to the admin to deal with.
584
                        # If we don't have an email address for this patron, send it to the admin to deal with.
553
                        push @output_chunks,
585
                        push @output_chunks,
554
                          prepare_letter_for_printing(
586
                          prepare_letter_for_printing(
Lines 559-564 END_SQL Link Here
559
                                address1       => $address1,
591
                                address1       => $address1,
560
                                address2       => $address2,
592
                                address2       => $address2,
561
                                city           => $city,
593
                                city           => $city,
594
                                country        => $country,
562
                                postcode       => $postcode,
595
                                postcode       => $postcode,
563
                                email          => $email,
596
                                email          => $email,
564
                                itemcount      => $itemcount,
597
                                itemcount      => $itemcount,
Lines 575-589 END_SQL Link Here
575
608
576
    if (@output_chunks) {
609
    if (@output_chunks) {
577
        if ( defined $csvfilename ) {
610
        if ( defined $csvfilename ) {
578
            print $csv_fh @output_chunks;        
611
            print $csv_fh @output_chunks;
579
        }
612
        } elsif ( defined $htmlfilename ) {
580
        elsif ( defined $htmlfilename ) {
613
            print $html_fh @output_chunks;
581
            print $html_fh @output_chunks;        
614
        } elsif ($nomail) {
582
        }
615
            local $, = "\f";    # pagebreak
583
        elsif ($nomail){
616
            print @output_chunks;
584
                local $, = "\f";    # pagebreak
585
                print @output_chunks;
586
        }
617
        }
618
        my $content = join(";", qw(title name surname address1 address2 zipcode city email itemcount itemsinfo due_date issue_date)) . "\n";
619
        $content .= join( "\n", @output_chunks );
620
587
        my $attachment = {
621
        my $attachment = {
588
            filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt',
622
            filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt',
589
            type => 'text/plain',
623
            type => 'text/plain',
Lines 612-620 if ($csvfilename) { Link Here
612
}
646
}
613
647
614
if ( defined $htmlfilename ) {
648
if ( defined $htmlfilename ) {
615
  print $html_fh "</body>\n";
649
    print $html_fh "</body>\n";
616
  print $html_fh "</html>\n";
650
    print $html_fh "</html>\n";
617
  close $html_fh;
651
    close $html_fh;
618
}
652
}
619
653
620
=head1 INTERNAL METHODS
654
=head1 INTERNAL METHODS
Lines 713-719 sub prepare_letter_for_printing { Link Here
713
    if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) {
747
    if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) {
714
        if ($csv->combine(
748
        if ($csv->combine(
715
                $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'},  $params->{'address2'}, $params->{'postcode'},
749
                $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'},  $params->{'address2'}, $params->{'postcode'},
716
                $params->{'city'},      $params->{'email'},    $params->{'itemcount'}, $params->{'titles'}
750
                $params->{'city'}, $params->{'country'},      $params->{'email'},    $params->{'itemcount'}, $params->{'titles'}
717
            )
751
            )
718
          ) {
752
          ) {
719
            return $csv->string, "\n";
753
            return $csv->string, "\n";
Lines 722-727 sub prepare_letter_for_printing { Link Here
722
        }
756
        }
723
    } elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) {
757
    } elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) {
724
      $return = "<pre>\n";
758
      $return = "<pre>\n";
759
      $params->{'letter'}->{'content'}=~s#
#<br/>#g;
725
      $return .= "$params->{'letter'}->{'content'}\n";
760
      $return .= "$params->{'letter'}->{'content'}\n";
726
      $return .= "\n</pre>\n";
761
      $return .= "\n</pre>\n";
727
    } else {
762
    } else {
(-)a/misc/cronjobs/printoverdues.sh (-5 / +5 lines)
Lines 39-46 then Link Here
39
fi
39
fi
40
for i in $1/*.html
40
for i in $1/*.html
41
do
41
do
42
    xhtml2pdf $optpisa  $i
42
    xhtml2pdf --encoding utf-8 $optpisa  $i
43
done
43
done
44
lp $optprinter  $1/*.pdf
44
45
tar cvfz $directory`date "+%Y%m%d"`.tar.gz  $directory
45
#lp $optprinter  $1/*.pdf
46
rm -rf $directory
46
#tar cvfz $directory`date "+%Y%m%d"`.tar.gz  $directory
47
#rm -rf $directory
47
- 

Return to bug 5878