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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+1 lines)
Lines 397-402 Circulation: Link Here
397
                  cron: "command-line option"
397
                  cron: "command-line option"
398
                  item-issuebranch: "checkout library"
398
                  item-issuebranch: "checkout library"
399
                  item-homebranch: "item home library"
399
                  item-homebranch: "item home library"
400
                  patron-homebranch: "patron home library"
400
            - .
401
            - .
401
        -
402
        -
402
            - Include up to
403
            - Include up to
(-)a/misc/cronjobs/overdue_notices.pl (-11 / +25 lines)
Lines 21-27 Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use Getopt::Long qw( GetOptions );
23
use Getopt::Long qw( GetOptions );
24
use Pod::Usage qw( pod2usage );
24
use Pod::Usage   qw( pod2usage );
25
use Text::CSV_XS;
25
use Text::CSV_XS;
26
use DateTime;
26
use DateTime;
27
use DateTime::Duration;
27
use DateTime::Duration;
Lines 69-75 overdue_notices.pl Link Here
69
   --date         <yyyy-mm-dd>     Emulate overdues run for this date.
69
   --date         <yyyy-mm-dd>     Emulate overdues run for this date.
70
   --email        <email_type>     Type of email that will be used.
70
   --email        <email_type>     Type of email that will be used.
71
                                   Can be 'email', 'emailpro' or 'B_email'. Repeatable.
71
                                   Can be 'email', 'emailpro' or 'B_email'. Repeatable.
72
   --frombranch                    Organize and send overdue notices by home library (item-homebranch) or checkout library (item-issuebranch).
72
   --frombranch                    Organize and send overdue notices by home library (item-homebranch) or checkout library (item-issuebranch) or patron home library (patron-homebranch).
73
                                   This option is only used, if the OverdueNoticeFrom system preference is set to 'command-line option'.
73
                                   This option is only used, if the OverdueNoticeFrom system preference is set to 'command-line option'.
74
                                   Defaults to item-issuebranch.
74
                                   Defaults to item-issuebranch.
75
75
Lines 184-190 Allows to specify which type of email will be used. Can be email, emailpro or B_ Link Here
184
184
185
=item B<--frombranch>
185
=item B<--frombranch>
186
186
187
Organize overdue notices either by checkout library (item-issuebranch) or item home library (item-homebranch).
187
Organize overdue notices either by checkout library (item-issuebranch) or item home library (item-homebranch)  or patron home library (patron-homebranch).
188
This option is only used, if the OverdueNoticeFrom system preference is set to use 'command-line option'.
188
This option is only used, if the OverdueNoticeFrom system preference is set to use 'command-line option'.
189
Defaults to checkout library (item-issuebranch).
189
Defaults to checkout library (item-issuebranch).
190
190
Lines 341-351 if ( defined $csvfilename && $csvfilename =~ /^-/ ) { Link Here
341
    warn qq(using "$csvfilename" as filename, that seems odd);
341
    warn qq(using "$csvfilename" as filename, that seems odd);
342
}
342
}
343
343
344
die "--frombranch takes item-homebranch or item-issuebranch only"
344
die "--frombranch takes item-homebranch or item-issuebranch or patron-homebranch only"
345
    unless ( $frombranch eq 'item-issuebranch'
345
    unless ( $frombranch eq 'item-issuebranch'
346
        || $frombranch eq 'item-homebranch' );
346
    || $frombranch eq 'item-homebranch'
347
$frombranch = C4::Context->preference('OverdueNoticeFrom') ne 'cron' ? C4::Context->preference('OverdueNoticeFrom') : $frombranch;
347
    || $frombranch eq 'patron-homebranch' );
348
$frombranch =
349
    C4::Context->preference('OverdueNoticeFrom') ne 'cron' ? C4::Context->preference('OverdueNoticeFrom') : $frombranch;
348
my $owning_library = ( $frombranch eq 'item-homebranch' ) ? 1 : 0;
350
my $owning_library = ( $frombranch eq 'item-homebranch' ) ? 1 : 0;
351
my $patron_homelibrary = ( $frombranch eq 'patron-homebranch' ) ? 1 : 0;
349
352
350
my @overduebranches    = C4::Overdues::GetBranchcodesWithOverdueRules();    # Branches with overdue rules
353
my @overduebranches    = C4::Overdues::GetBranchcodesWithOverdueRules();    # Branches with overdue rules
351
my @branches;                                    # Branches passed as parameter with overdue rules
354
my @branches;                                    # Branches passed as parameter with overdue rules
Lines 446-451 elsif ( defined $text_filename ) { Link Here
446
  }
449
  }
447
}
450
}
448
451
452
my %already_queued;
453
my %seen = map { $_ => 1 } @branches;
449
foreach my $branchcode (@branches) {
454
foreach my $branchcode (@branches) {
450
    my $calendar;
455
    my $calendar;
451
    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
456
    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
Lines 476-485 SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname Link Here
476
    AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
481
    AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
477
END_SQL
482
END_SQL
478
483
479
    if($owning_library) {
484
    if ($owning_library) {
480
      $sql2 .= ' AND items.homebranch = ? ';
485
        $sql2 .= ' AND items.homebranch = ? ' unless ($patron_homelibrary);
481
    } else {
486
    } else {
482
      $sql2 .= ' AND issues.branchcode = ? ';
487
        $sql2 .= ' AND issues.branchcode = ? ' unless ($patron_homelibrary);
483
    }
488
    }
484
    my $sth2 = $dbh->prepare($sql2);
489
    my $sth2 = $dbh->prepare($sql2);
485
490
Lines 595-600 END_SQL Link Here
595
                    next;
600
                    next;
596
                }
601
                }
597
                $borrowernumber = $data->{'borrowernumber'};
602
                $borrowernumber = $data->{'borrowernumber'};
603
                next if ( $patron_homelibrary && $already_queued{"$borrowernumber$i"} );
598
                my $borr = sprintf( "%s%s%s (%s)",
604
                my $borr = sprintf( "%s%s%s (%s)",
599
                    $data->{'surname'} || '',
605
                    $data->{'surname'} || '',
600
                    $data->{'firstname'} && $data->{'surname'} ? ', ' : '',
606
                    $data->{'firstname'} && $data->{'surname'} ? ', ' : '',
Lines 603-608 END_SQL Link Here
603
                $verbose and warn "borrower $borr has items triggering level $i.\n";
609
                $verbose and warn "borrower $borr has items triggering level $i.\n";
604
610
605
                my $patron = Koha::Patrons->find( $borrowernumber );
611
                my $patron = Koha::Patrons->find( $borrowernumber );
612
                if ($patron_homelibrary) {
613
                    $branchcode           = $patron->branchcode;
614
                    $library              = Koha::Libraries->find($branchcode);
615
                    $admin_email_address  = $library->from_email_address;
616
                    $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices')
617
                        || $library->inbound_email_address;
618
                }
606
                @emails_to_use = ();
619
                @emails_to_use = ();
607
                my $notice_email = $patron->notice_email_address;
620
                my $notice_email = $patron->notice_email_address;
608
                unless ($nomail) {
621
                unless ($nomail) {
Lines 645-651 END_SQL Link Here
645
                    ) unless $test_mode;
658
                    ) unless $test_mode;
646
                    $verbose and warn "debarring $borr\n";
659
                    $verbose and warn "debarring $borr\n";
647
                }
660
                }
648
                my @params = ($borrowernumber,$branchcode);
661
                my @params = $patron_homelibrary ? ($borrowernumber) : ( $borrowernumber, $branchcode );
649
662
650
                $sth2->execute(@params);
663
                $sth2->execute(@params);
651
                my $itemcount = 0;
664
                my $itemcount = 0;
Lines 690-695 END_SQL Link Here
690
                      $exceededPrintNoticesMaxLines = 1;
703
                      $exceededPrintNoticesMaxLines = 1;
691
                      last;
704
                      last;
692
                    }
705
                    }
706
                    next if $patron_homelibrary and !grep { $seen{ $item_info->{branchcode} } } @branches;
693
                    $j++;
707
                    $j++;
694
708
695
                    $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields, dateonly => 1 } );
709
                    $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields, dateonly => 1 } );
Lines 813-818 END_SQL Link Here
813
                        }
827
                        }
814
                    }
828
                    }
815
                }
829
                }
830
                $already_queued{"$borrowernumber$i"} = 1;
816
            }
831
            }
817
            $sth->finish;
832
            $sth->finish;
818
        }
833
        }
819
- 

Return to bug 32740