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

(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-11 / +40 lines)
Lines 38-43 use C4::Overdues; Link Here
38
use Koha::Calendar;
38
use Koha::Calendar;
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Patrons;
40
use Koha::Patrons;
41
use Koha::Libraries;
41
42
42
sub usage {
43
sub usage {
43
    pod2usage( -verbose => 2 );
44
    pod2usage( -verbose => 2 );
Lines 59-64 my $library_code; Link Here
59
my $help;
60
my $help;
60
my $outfile;
61
my $outfile;
61
my $skip_patrons_with_email;
62
my $skip_patrons_with_email;
63
my $patron_branchcode;
62
64
63
# maps to convert I-tiva terms to Koha terms
65
# maps to convert I-tiva terms to Koha terms
64
my $type_module_map = {
66
my $type_module_map = {
Lines 74-87 my $type_notice_map = { Link Here
74
};
76
};
75
77
76
GetOptions(
78
GetOptions(
77
    'o|output:s'            => \$outfile,
79
    'o|output:s'             => \$outfile,
78
    'v'                     => \$verbose,
80
    'v'                      => \$verbose,
79
    'lang:s'                => \$language,
81
    'lang:s'                 => \$language,
80
    'type:s'                => \@types,
82
    'type:s'                 => \@types,
81
    'w|waiting-hold-day:s'  => \@holds_waiting_days_to_call,
83
    'w|waiting-hold-day:s'   => \@holds_waiting_days_to_call,
82
    'c|code|library-code:s' => \$library_code,
84
    'c|code|library-code:s'  => \$library_code,
83
    's|skip-patrons-with-email' => \$skip_patrons_with_email,
85
    's|skip-patrons-with-email' => \$skip_patrons_with_email,
84
    'help|h'                => \$help,
86
    'pb|patron-branchcode:s' => \$patron_branchcode,
87
    'h|help'                 => \$help,
85
);
88
);
86
89
87
$language = uc($language);
90
$language = uc($language);
Lines 89-94 $library_code ||= ''; Link Here
89
92
90
pod2usage( -verbose => 1 ) if $help;
93
pod2usage( -verbose => 1 ) if $help;
91
94
95
if ($patron_branchcode) {
96
    die("Invalid branchcode '$patron_branchcode' passed in -pb --patron-branchcode parameter")
97
      unless Koha::Libraries->search( { branchcode => $patron_branchcode } )->count;
98
}
99
92
# output log or STDOUT
100
# output log or STDOUT
93
my $OUT;
101
my $OUT;
94
if ( defined $outfile ) {
102
if ( defined $outfile ) {
Lines 108-118 foreach my $type (@types) { Link Here
108
116
109
    my @loop;
117
    my @loop;
110
    if ( $type eq 'OVERDUE' ) {
118
    if ( $type eq 'OVERDUE' ) {
111
        @loop = GetOverdueIssues();
119
        @loop = GetOverdueIssues( $patron_branchcode );
112
    } elsif ( $type eq 'PREOVERDUE' ) {
120
    } elsif ( $type eq 'PREOVERDUE' ) {
113
        @loop = GetPredueIssues();
121
        @loop = GetPredueIssues( $patron_branchcode );
114
    } elsif ( $type eq 'RESERVE' ) {
122
    } elsif ( $type eq 'RESERVE' ) {
115
        @loop = GetWaitingHolds();
123
        @loop = GetWaitingHolds( $patron_branchcode );
116
    } else {
124
    } else {
117
        print "Unknown or unsupported message type $type; skipping...\n"
125
        print "Unknown or unsupported message type $type; skipping...\n"
118
          if ( defined $verbose );
126
          if ( defined $verbose );
Lines 214-224 consortium purposes and apply library specific settings, such as Link Here
214
prompts, to those notices.
222
prompts, to those notices.
215
This field can be blank if all messages are from a single library.
223
This field can be blank if all messages are from a single library.
216
224
225
=item B<--patron-branchcode> B<--pb>
226
227
OPTIONAL
228
229
Limits the the patrons to generate notices for based on the patron's home library.
230
Items and holds from other libraries will still be included for the given patron.
231
217
=back
232
=back
218
233
219
=cut
234
=cut
220
235
221
sub GetOverdueIssues {
236
sub GetOverdueIssues {
237
    my ( $patron_branchcode ) = @_;
238
239
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = '$patron_branchcode'" : q{};
240
222
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
241
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
223
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
242
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
224
                max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3,
243
                max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3,
Lines 234-239 sub GetOverdueIssues { Link Here
234
                AND ( (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay1
253
                AND ( (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay1
235
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay2
254
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay2
236
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay3 )
255
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay3 )
256
                $patron_branchcode_filter
237
                GROUP BY items.itemnumber
257
                GROUP BY items.itemnumber
238
                ";
258
                ";
239
    my $sth = $dbh->prepare($query);
259
    my $sth = $dbh->prepare($query);
Lines 256-261 sub GetOverdueIssues { Link Here
256
}
276
}
257
277
258
sub GetPredueIssues {
278
sub GetPredueIssues {
279
    my ( $patron_branchcode ) = @_;
280
281
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = '$patron_branchcode'" : q{};
282
259
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
283
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
260
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
284
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
261
                issues.branchcode as site, branches.branchname as site_name
285
                issues.branchcode as site, branches.branchname as site_name
Lines 269-274 sub GetPredueIssues { Link Here
269
                WHERE ( TO_DAYS( date_due ) - TO_DAYS( NOW() ) ) = days_in_advance
293
                WHERE ( TO_DAYS( date_due ) - TO_DAYS( NOW() ) ) = days_in_advance
270
                AND message_transport_type = 'phone'
294
                AND message_transport_type = 'phone'
271
                AND message_name = 'Advance_Notice'
295
                AND message_name = 'Advance_Notice'
296
                $patron_branchcode_filter
272
                ";
297
                ";
273
    my $sth = $dbh->prepare($query);
298
    my $sth = $dbh->prepare($query);
274
    $sth->execute();
299
    $sth->execute();
Lines 281-286 sub GetPredueIssues { Link Here
281
}
306
}
282
307
283
sub GetWaitingHolds {
308
sub GetWaitingHolds {
309
    my ( $patron_branchcode ) = @_;
310
311
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = '$patron_branchcode'" : q{};
312
284
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
313
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
285
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate,
314
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate,
286
                reserves.branchcode AS site, branches.branchname AS site_name,
315
                reserves.branchcode AS site, branches.branchname AS site_name,
Lines 295-300 sub GetWaitingHolds { Link Here
295
                WHERE ( reserves.found = 'W' )
324
                WHERE ( reserves.found = 'W' )
296
                AND message_transport_type = 'phone'
325
                AND message_transport_type = 'phone'
297
                AND message_name = 'Hold_Filled'
326
                AND message_name = 'Hold_Filled'
327
                $patron_branchcode_filter
298
                ";
328
                ";
299
    my $pickupdelay = C4::Context->preference("ReservesMaxPickUpDelay");
329
    my $pickupdelay = C4::Context->preference("ReservesMaxPickUpDelay");
300
    my $sth         = $dbh->prepare($query);
330
    my $sth         = $dbh->prepare($query);
301
- 

Return to bug 21180