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

(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-11 / +40 lines)
Lines 37-42 use C4::Letters; Link Here
37
use C4::Overdues;
37
use C4::Overdues;
38
use Koha::Calendar;
38
use Koha::Calendar;
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Libraries;
40
41
41
sub usage {
42
sub usage {
42
    pod2usage( -verbose => 2 );
43
    pod2usage( -verbose => 2 );
Lines 57-62 my @holds_waiting_days_to_call; Link Here
57
my $library_code;
58
my $library_code;
58
my $help;
59
my $help;
59
my $outfile;
60
my $outfile;
61
my $patron_branchcode;
60
62
61
# maps to convert I-tiva terms to Koha terms
63
# maps to convert I-tiva terms to Koha terms
62
my $type_module_map = {
64
my $type_module_map = {
Lines 72-84 my $type_notice_map = { Link Here
72
};
74
};
73
75
74
GetOptions(
76
GetOptions(
75
    'o|output:s'            => \$outfile,
77
    'o|output:s'             => \$outfile,
76
    'v'                     => \$verbose,
78
    'v'                      => \$verbose,
77
    'lang:s'                => \$language,
79
    'lang:s'                 => \$language,
78
    'type:s'                => \@types,
80
    'type:s'                 => \@types,
79
    'w|waiting-hold-day:s'  => \@holds_waiting_days_to_call,
81
    'w|waiting-hold-day:s'   => \@holds_waiting_days_to_call,
80
    'c|code|library-code:s' => \$library_code,
82
    'c|code|library-code:s'  => \$library_code,
81
    'help|h'                => \$help,
83
    'pb|patron-branchcode:s' => \$patron_branchcode,
84
    'h|help'                 => \$help,
82
);
85
);
83
86
84
$language = uc($language);
87
$language = uc($language);
Lines 86-91 $library_code ||= ''; Link Here
86
89
87
pod2usage( -verbose => 1 ) if $help;
90
pod2usage( -verbose => 1 ) if $help;
88
91
92
if ($patron_branchcode) {
93
    die("Invalid branchcode '$patron_branchcode' passed in -pb --patron-branchcode parameter")
94
      unless Koha::Libraries->search( { branchcode => $patron_branchcode } )->count;
95
}
96
89
# output log or STDOUT
97
# output log or STDOUT
90
my $OUT;
98
my $OUT;
91
if ( defined $outfile ) {
99
if ( defined $outfile ) {
Lines 105-115 foreach my $type (@types) { Link Here
105
113
106
    my @loop;
114
    my @loop;
107
    if ( $type eq 'OVERDUE' ) {
115
    if ( $type eq 'OVERDUE' ) {
108
        @loop = GetOverdueIssues();
116
        @loop = GetOverdueIssues( $patron_branchcode );
109
    } elsif ( $type eq 'PREOVERDUE' ) {
117
    } elsif ( $type eq 'PREOVERDUE' ) {
110
        @loop = GetPredueIssues();
118
        @loop = GetPredueIssues( $patron_branchcode );
111
    } elsif ( $type eq 'RESERVE' ) {
119
    } elsif ( $type eq 'RESERVE' ) {
112
        @loop = GetWaitingHolds();
120
        @loop = GetWaitingHolds( $patron_branchcode );
113
    } else {
121
    } else {
114
        print "Unknown or unsupported message type $type; skipping...\n"
122
        print "Unknown or unsupported message type $type; skipping...\n"
115
          if ( defined $verbose );
123
          if ( defined $verbose );
Lines 207-217 consortium purposes and apply library specific settings, such as Link Here
207
prompts, to those notices.
215
prompts, to those notices.
208
This field can be blank if all messages are from a single library.
216
This field can be blank if all messages are from a single library.
209
217
218
=item B<--patron-branchcode> B<--pb>
219
220
OPTIONAL
221
222
Limits the the patrons to generate notices for based on the patron's home library.
223
Items and holds from other libraries will still be included for the given patron.
224
210
=back
225
=back
211
226
212
=cut
227
=cut
213
228
214
sub GetOverdueIssues {
229
sub GetOverdueIssues {
230
    my ( $patron_branchcode ) = @_;
231
232
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = $patron_branchcode" : q{};
233
215
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
234
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
216
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
235
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
217
                max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3,
236
                max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3,
Lines 227-232 sub GetOverdueIssues { Link Here
227
                AND ( (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay1
246
                AND ( (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay1
228
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay2
247
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay2
229
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay3 )
248
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay3 )
249
                $patron_branchcode_filter
230
                GROUP BY items.itemnumber
250
                GROUP BY items.itemnumber
231
                ";
251
                ";
232
    my $sth = $dbh->prepare($query);
252
    my $sth = $dbh->prepare($query);
Lines 249-254 sub GetOverdueIssues { Link Here
249
}
269
}
250
270
251
sub GetPredueIssues {
271
sub GetPredueIssues {
272
    my ( $patron_branchcode ) = @_;
273
274
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = $patron_branchcode" : q{};
275
252
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
276
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
253
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
277
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
254
                issues.branchcode as site, branches.branchname as site_name
278
                issues.branchcode as site, branches.branchname as site_name
Lines 262-267 sub GetPredueIssues { Link Here
262
                WHERE ( TO_DAYS( date_due ) - TO_DAYS( NOW() ) ) = days_in_advance
286
                WHERE ( TO_DAYS( date_due ) - TO_DAYS( NOW() ) ) = days_in_advance
263
                AND message_transport_type = 'phone'
287
                AND message_transport_type = 'phone'
264
                AND message_name = 'Advance_Notice'
288
                AND message_name = 'Advance_Notice'
289
                $patron_branchcode_filter
265
                ";
290
                ";
266
    my $sth = $dbh->prepare($query);
291
    my $sth = $dbh->prepare($query);
267
    $sth->execute();
292
    $sth->execute();
Lines 274-279 sub GetPredueIssues { Link Here
274
}
299
}
275
300
276
sub GetWaitingHolds {
301
sub GetWaitingHolds {
302
    my ( $patron_branchcode ) = @_;
303
304
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = $patron_branchcode" : q{};
305
277
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
306
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
278
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate,
307
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, reserves.waitingdate,
279
                reserves.branchcode AS site, branches.branchname AS site_name,
308
                reserves.branchcode AS site, branches.branchname AS site_name,
Lines 288-293 sub GetWaitingHolds { Link Here
288
                WHERE ( reserves.found = 'W' )
317
                WHERE ( reserves.found = 'W' )
289
                AND message_transport_type = 'phone'
318
                AND message_transport_type = 'phone'
290
                AND message_name = 'Hold_Filled'
319
                AND message_name = 'Hold_Filled'
320
                $patron_branchcode_filter
291
                ";
321
                ";
292
    my $pickupdelay = C4::Context->preference("ReservesMaxPickUpDelay");
322
    my $pickupdelay = C4::Context->preference("ReservesMaxPickUpDelay");
293
    my $sth         = $dbh->prepare($query);
323
    my $sth         = $dbh->prepare($query);
294
- 

Return to bug 21180