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

(-)a/C4/Circulation.pm (-3 / +16 lines)
Lines 2601-2608 sub GetUpcomingDueIssues { Link Here
2601
2601
2602
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2602
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2603
    my $dbh = C4::Context->dbh;
2603
    my $dbh = C4::Context->dbh;
2604
2604
    my $statement;
2605
    my $statement = <<END_SQL;
2605
    if($params->{'owning_library'}) {
2606
	$statement = <<"END_SQL";
2607
SELECT *
2608
FROM (
2609
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2610
    FROM issues
2611
    LEFT JOIN items USING (itemnumber)
2612
    LEFT OUTER JOIN branches ON (branches.branchcode = items.homebranch)
2613
    WHERE returndate is NULL
2614
) tmp
2615
WHERE days_until_due >= 0 AND days_until_due <= ?
2616
END_SQL
2617
    } else {
2618
	$statement = <<"END_SQL";
2606
SELECT *
2619
SELECT *
2607
FROM (
2620
FROM (
2608
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2621
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
Lines 2613-2619 FROM ( Link Here
2613
) tmp
2626
) tmp
2614
WHERE days_until_due >= 0 AND days_until_due <= ?
2627
WHERE days_until_due >= 0 AND days_until_due <= ?
2615
END_SQL
2628
END_SQL
2616
2629
    }
2617
    my @bind_parameters = ( $params->{'days_in_advance'} );
2630
    my @bind_parameters = ( $params->{'days_in_advance'} );
2618
    
2631
    
2619
    my $sth = $dbh->prepare( $statement );
2632
    my $sth = $dbh->prepare( $statement );
(-)a/misc/cronjobs/advance_notices.pl (-4 / +44 lines)
Lines 101-109 Defines the maximum number of days in advance to send advance notices. Link Here
101
Confirm flag: Add this option. The script will only print a usage
101
Confirm flag: Add this option. The script will only print a usage
102
statement otherwise.
102
statement otherwise.
103
103
104
=item B<-library>
105
106
Select notices for one specific library. Use the value in the
107
branches.branchcode table. This option can be repeated in order
108
to select notices for a group of libraries.
109
104
=item B<--itemscontent>
110
=item B<--itemscontent>
105
111
106
comma separated list of fields that get substituted into templates in
112
Comma separated list of fields that get substituted into templates in
107
places of the E<lt>E<lt>items.contentE<gt>E<gt> placeholder. This
113
places of the E<lt>E<lt>items.contentE<gt>E<gt> placeholder. This
108
defaults to date_due,title,author,barcode
114
defaults to date_due,title,author,barcode
109
115
Lines 125-130 Enabling this flag ensures that the issuing library is the sender of Link Here
125
the digested message.  It has no effect unless the borrower has
131
the digested message.  It has no effect unless the borrower has
126
chosen 'Digests only' on the advance messages.
132
chosen 'Digests only' on the advance messages.
127
133
134
=item B<--owning>
135
136
Use the address information from the item homebranch library instead of the issuing library.
137
128
=back
138
=back
129
139
130
=head1 DESCRIPTION
140
=head1 DESCRIPTION
Lines 190-196 my $nomail; # -n: No mai Link Here
190
my $mindays     = 0;                                                # -m: Maximum number of days in advance to send notices
200
my $mindays     = 0;                                                # -m: Maximum number of days in advance to send notices
191
my $maxdays     = 30;                                               # -e: the End of the time period
201
my $maxdays     = 30;                                               # -e: the End of the time period
192
my $verbose     = 0;                                                # -v: verbose
202
my $verbose     = 0;                                                # -v: verbose
203
<<<<<<< HEAD
193
my $digest_per_branch = 0;                                          # -digest-per-branch: Prepare and send digests per branch
204
my $digest_per_branch = 0;                                          # -digest-per-branch: Prepare and send digests per branch
205
=======
206
my @branchcodes; # Branch(es) passed as parameter
207
my $owning_library = 0;
208
>>>>>>> Bug 21886: Add option to send notices from owning library instead of issuing library
194
my $itemscontent = join(',',qw( date_due title author barcode ));
209
my $itemscontent = join(',',qw( date_due title author barcode ));
195
210
196
my $help    = 0;
211
my $help    = 0;
Lines 199-204 my $man = 0; Link Here
199
GetOptions(
214
GetOptions(
200
            'help|?'         => \$help,
215
            'help|?'         => \$help,
201
            'man'            => \$man,
216
            'man'            => \$man,
217
            'library=s'      => \@branchcodes,
218
            'owning'         => \$owning_library,
202
            'c'              => \$confirm,
219
            'c'              => \$confirm,
203
            'n'              => \$nomail,
220
            'n'              => \$nomail,
204
            'm:i'            => \$maxdays,
221
            'm:i'            => \$maxdays,
Lines 226-236 unless ($confirm) { Link Here
226
}
243
}
227
cronlogaction();
244
cronlogaction();
228
245
246
my %branches = map { $_ => 1 } @branchcodes if @branchcodes;
247
229
# The fields that will be substituted into <<items.content>>
248
# The fields that will be substituted into <<items.content>>
230
my @item_content_fields = split(/,/,$itemscontent);
249
my @item_content_fields = split(/,/,$itemscontent);
231
250
232
warn 'getting upcoming due issues' if $verbose;
251
warn 'getting upcoming due issues' if $verbose;
233
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $maxdays } );
252
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( {
253
    days_in_advance => $maxdays,
254
    owning_library => $owning_library
255
 } );
234
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
256
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
235
257
236
# hash of borrowernumber to number of items upcoming
258
# hash of borrowernumber to number of items upcoming
Lines 275-280 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
275
                $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
297
                $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
276
            }
298
            }
277
        } else {
299
        } else {
300
	    my $branchcode;
301
	    if($owning_library) {
302
		$branchcode = $upcoming->{'homebranch'};
303
	    } else {
304
		$branchcode = $upcoming->{'branchcode'};
305
	    }
306
	    # Skip this DUE if we specify list of libraries and this one is not part of it
307
	    next if (@branchcodes && !$branches{$branchcode});
308
278
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
309
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
279
            my $letter_type = 'DUE';
310
            my $letter_type = 'DUE';
280
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
311
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
Lines 287-293 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
287
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
318
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
288
                my $letter = parse_letter( { letter_code    => $letter_type,
319
                my $letter = parse_letter( { letter_code    => $letter_type,
289
                                      borrowernumber => $upcoming->{'borrowernumber'},
320
                                      borrowernumber => $upcoming->{'borrowernumber'},
290
                                      branchcode     => $upcoming->{'branchcode'},
321
                                      branchcode     => $branchcode,
291
                                      biblionumber   => $item->biblionumber,
322
                                      biblionumber   => $item->biblionumber,
292
                                      itemnumber     => $upcoming->{'itemnumber'},
323
                                      itemnumber     => $upcoming->{'itemnumber'},
293
                                      substitute     => { 'items.content' => $titles },
324
                                      substitute     => { 'items.content' => $titles },
Lines 313-318 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
313
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
344
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
314
            }
345
            }
315
        } else {
346
        } else {
347
	    my $branchcode;
348
	    if($owning_library) {
349
		$branchcode = $upcoming->{'homebranch'};
350
	    } else {
351
		$branchcode = $upcoming->{'branchcode'};
352
	    }
353
	    # Skip this PREDUE if we specify list of libraries and this one is not part of it
354
	    next if (@branchcodes && !$branches{$branchcode});
355
316
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
356
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
317
            my $letter_type = 'PREDUE';
357
            my $letter_type = 'PREDUE';
318
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
358
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
Lines 325-331 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
325
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
365
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
326
                my $letter = parse_letter( { letter_code    => $letter_type,
366
                my $letter = parse_letter( { letter_code    => $letter_type,
327
                                      borrowernumber => $upcoming->{'borrowernumber'},
367
                                      borrowernumber => $upcoming->{'borrowernumber'},
328
                                      branchcode     => $upcoming->{'branchcode'},
368
                                      branchcode     => $branchcode,
329
                                      biblionumber   => $item->biblionumber,
369
                                      biblionumber   => $item->biblionumber,
330
                                      itemnumber     => $upcoming->{'itemnumber'},
370
                                      itemnumber     => $upcoming->{'itemnumber'},
331
                                      substitute     => { 'items.content' => $titles },
371
                                      substitute     => { 'items.content' => $titles },
(-)a/misc/cronjobs/overdue_notices.pl (-2 / +12 lines)
Lines 75-80 overdue_notices.pl Link Here
75
   -list-all                      list all overdues
75
   -list-all                      list all overdues
76
   -date         <yyyy-mm-dd>     emulate overdues run for this date
76
   -date         <yyyy-mm-dd>     emulate overdues run for this date
77
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
77
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
78
   --owning                        Send notices from item homebranch library instead of issuing library
78
79
79
=head1 OPTIONS
80
=head1 OPTIONS
80
81
Lines 183-188 use it in order to send overdues on a specific date and not Now. Format: YYYY-MM Link Here
183
184
184
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
185
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
185
186
187
=item B<-owning>
188
189
Use the address information from the item homebranch library instead of the issuing library.
190
186
=back
191
=back
187
192
188
=head1 DESCRIPTION
193
=head1 DESCRIPTION
Lines 292-297 my $verbose = 0; Link Here
292
my $nomail  = 0;
297
my $nomail  = 0;
293
my $MAX     = 90;
298
my $MAX     = 90;
294
my $test_mode = 0;
299
my $test_mode = 0;
300
my $owning_library = 0;
295
my @branchcodes; # Branch(es) passed as parameter
301
my @branchcodes; # Branch(es) passed as parameter
296
my @emails_to_use;    # Emails to use for messaging
302
my @emails_to_use;    # Emails to use for messaging
297
my @emails;           # Emails given in command-line parameters
303
my @emails;           # Emails given in command-line parameters
Lines 323-328 GetOptions( Link Here
323
    'borcat=s'       => \@myborcat,
329
    'borcat=s'       => \@myborcat,
324
    'borcatout=s'    => \@myborcatout,
330
    'borcatout=s'    => \@myborcatout,
325
    'email=s'        => \@emails,
331
    'email=s'        => \@emails,
332
    'owning'         => \$owning_library,
326
) or pod2usage(2);
333
) or pod2usage(2);
327
pod2usage(1) if $help;
334
pod2usage(1) if $help;
328
pod2usage( -verbose => 2 ) if $man;
335
pod2usage( -verbose => 2 ) if $man;
Lines 528-534 AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 Link Here
528
END_SQL
535
END_SQL
529
            my @borrower_parameters;
536
            my @borrower_parameters;
530
            if ($branchcode) {
537
            if ($branchcode) {
531
                $borrower_sql .= ' AND issues.branchcode=? ';
538
		if($owning_library) {
539
		    $borrower_sql .= ' AND items.homebranch=? ';
540
		} else {
541
		    $borrower_sql .= ' AND issues.branchcode=? ';
542
		}
532
                push @borrower_parameters, $branchcode;
543
                push @borrower_parameters, $branchcode;
533
            }
544
            }
534
            if ( $overdue_rules->{categorycode} ) {
545
            if ( $overdue_rules->{categorycode} ) {
535
- 

Return to bug 21886