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

(-)a/C4/Circulation.pm (-3 / +16 lines)
Lines 2598-2605 sub GetUpcomingDueIssues { Link Here
2598
2598
2599
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2599
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2600
    my $dbh = C4::Context->dbh;
2600
    my $dbh = C4::Context->dbh;
2601
2601
    my $statement;
2602
    my $statement = <<END_SQL;
2602
    if($params->{'owning_library'}) {
2603
	$statement = <<"END_SQL";
2604
SELECT *
2605
FROM (
2606
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2607
    FROM issues
2608
    LEFT JOIN items USING (itemnumber)
2609
    LEFT OUTER JOIN branches ON (branches.branchcode = items.homebranch)
2610
    WHERE returndate is NULL
2611
) tmp
2612
WHERE days_until_due >= 0 AND days_until_due <= ?
2613
END_SQL
2614
    } else {
2615
	$statement = <<"END_SQL";
2603
SELECT *
2616
SELECT *
2604
FROM (
2617
FROM (
2605
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2618
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
Lines 2610-2616 FROM ( Link Here
2610
) tmp
2623
) tmp
2611
WHERE days_until_due >= 0 AND days_until_due <= ?
2624
WHERE days_until_due >= 0 AND days_until_due <= ?
2612
END_SQL
2625
END_SQL
2613
2626
    }
2614
    my @bind_parameters = ( $params->{'days_in_advance'} );
2627
    my @bind_parameters = ( $params->{'days_in_advance'} );
2615
    
2628
    
2616
    my $sth = $dbh->prepare( $statement );
2629
    my $sth = $dbh->prepare( $statement );
(-)a/misc/cronjobs/advance_notices.pl (-3 / +40 lines)
Lines 109-114 defaults to date_due,title,author,barcode Link Here
109
Other possible values come from fields in the biblios, items and
109
Other possible values come from fields in the biblios, items and
110
issues tables.
110
issues tables.
111
111
112
=item B<-library>
113
114
select notices for one specific library. Use the value in the
115
branches.branchcode table. This option can be repeated in order
116
to select notices for a group of libraries.
117
118
=item B<-owning>
119
120
Use the address information from the item homebranch library instead of the issuing library.
121
112
=back
122
=back
113
123
114
=head1 DESCRIPTION
124
=head1 DESCRIPTION
Lines 174-179 my $nomail; # -n: No mai Link Here
174
my $mindays     = 0;                                                # -m: Maximum number of days in advance to send notices
184
my $mindays     = 0;                                                # -m: Maximum number of days in advance to send notices
175
my $maxdays     = 30;                                               # -e: the End of the time period
185
my $maxdays     = 30;                                               # -e: the End of the time period
176
my $verbose     = 0;                                                # -v: verbose
186
my $verbose     = 0;                                                # -v: verbose
187
my @branchcodes; # Branch(es) passed as parameter
188
my $owning_library = 0;
177
my $itemscontent = join(',',qw( date_due title author barcode ));
189
my $itemscontent = join(',',qw( date_due title author barcode ));
178
190
179
my $help    = 0;
191
my $help    = 0;
Lines 182-187 my $man = 0; Link Here
182
GetOptions(
194
GetOptions(
183
            'help|?'         => \$help,
195
            'help|?'         => \$help,
184
            'man'            => \$man,
196
            'man'            => \$man,
197
            'library=s'      => \@branchcodes,
198
            'owning'         => \$owning_library,
185
            'c'              => \$confirm,
199
            'c'              => \$confirm,
186
            'n'              => \$nomail,
200
            'n'              => \$nomail,
187
            'm:i'            => \$maxdays,
201
            'm:i'            => \$maxdays,
Lines 209-219 unless ($confirm) { Link Here
209
223
210
cronlogaction();
224
cronlogaction();
211
225
226
my %branches = map { $_ => 1 } @branchcodes if @branchcodes;
227
212
# The fields that will be substituted into <<items.content>>
228
# The fields that will be substituted into <<items.content>>
213
my @item_content_fields = split(/,/,$itemscontent);
229
my @item_content_fields = split(/,/,$itemscontent);
214
230
215
warn 'getting upcoming due issues' if $verbose;
231
warn 'getting upcoming due issues' if $verbose;
216
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $maxdays } );
232
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( {
233
    days_in_advance => $maxdays,
234
    owning_library => $owning_library
235
 } );
217
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
236
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
218
237
219
# hash of borrowernumber to number of items upcoming
238
# hash of borrowernumber to number of items upcoming
Lines 253-258 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
253
            $due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
272
            $due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
254
            $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
273
            $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
255
        } else {
274
        } else {
275
	    my $branchcode;
276
	    if($owning_library) {
277
		$branchcode = $upcoming->{'homebranch'};
278
	    } else {
279
		$branchcode = $upcoming->{'branchcode'};
280
	    }
281
	    # Skip this DUE if we specify list of libraries and this one is not part of it
282
	    next if (@branchcodes && !$branches{$branchcode});
283
256
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
284
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
257
            my $letter_type = 'DUE';
285
            my $letter_type = 'DUE';
258
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
286
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
Lines 265-271 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
265
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
293
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
266
                my $letter = parse_letter( { letter_code    => $letter_type,
294
                my $letter = parse_letter( { letter_code    => $letter_type,
267
                                      borrowernumber => $upcoming->{'borrowernumber'},
295
                                      borrowernumber => $upcoming->{'borrowernumber'},
268
                                      branchcode     => $upcoming->{'branchcode'},
296
                                      branchcode     => $branchcode,
269
                                      biblionumber   => $item->biblionumber,
297
                                      biblionumber   => $item->biblionumber,
270
                                      itemnumber     => $upcoming->{'itemnumber'},
298
                                      itemnumber     => $upcoming->{'itemnumber'},
271
                                      substitute     => { 'items.content' => $titles },
299
                                      substitute     => { 'items.content' => $titles },
Lines 286-291 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
286
            $upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
314
            $upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
287
            $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
315
            $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
288
        } else {
316
        } else {
317
	    my $branchcode;
318
	    if($owning_library) {
319
		$branchcode = $upcoming->{'homebranch'};
320
	    } else {
321
		$branchcode = $upcoming->{'branchcode'};
322
	    }
323
	    # Skip this PREDUE if we specify list of libraries and this one is not part of it
324
	    next if (@branchcodes && !$branches{$branchcode});
325
289
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
326
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
290
            my $letter_type = 'PREDUE';
327
            my $letter_type = 'PREDUE';
291
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
328
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
Lines 298-304 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
298
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
335
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
299
                my $letter = parse_letter( { letter_code    => $letter_type,
336
                my $letter = parse_letter( { letter_code    => $letter_type,
300
                                      borrowernumber => $upcoming->{'borrowernumber'},
337
                                      borrowernumber => $upcoming->{'borrowernumber'},
301
                                      branchcode     => $upcoming->{'branchcode'},
338
                                      branchcode     => $branchcode,
302
                                      biblionumber   => $item->biblionumber,
339
                                      biblionumber   => $item->biblionumber,
303
                                      itemnumber     => $upcoming->{'itemnumber'},
340
                                      itemnumber     => $upcoming->{'itemnumber'},
304
                                      substitute     => { 'items.content' => $titles },
341
                                      substitute     => { 'items.content' => $titles },
(-)a/misc/cronjobs/overdue_notices.pl (-2 / +12 lines)
Lines 74-79 overdue_notices.pl Link Here
74
   -list-all                      list all overdues
74
   -list-all                      list all overdues
75
   -date         <yyyy-mm-dd>     emulate overdues run for this date
75
   -date         <yyyy-mm-dd>     emulate overdues run for this date
76
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
76
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
77
   -owning                        Send notices from item homebranch library instead of issuing library
77
78
78
=head1 OPTIONS
79
=head1 OPTIONS
79
80
Lines 182-187 use it in order to send overdues on a specific date and not Now. Format: YYYY-MM Link Here
182
183
183
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
184
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
184
185
186
=item B<-owning>
187
188
Use the address information from the item homebranch library instead of the issuing library.
189
185
=back
190
=back
186
191
187
=head1 DESCRIPTION
192
=head1 DESCRIPTION
Lines 291-296 my $verbose = 0; Link Here
291
my $nomail  = 0;
296
my $nomail  = 0;
292
my $MAX     = 90;
297
my $MAX     = 90;
293
my $test_mode = 0;
298
my $test_mode = 0;
299
my $owning_library = 0;
294
my @branchcodes; # Branch(es) passed as parameter
300
my @branchcodes; # Branch(es) passed as parameter
295
my @emails_to_use;    # Emails to use for messaging
301
my @emails_to_use;    # Emails to use for messaging
296
my @emails;           # Emails given in command-line parameters
302
my @emails;           # Emails given in command-line parameters
Lines 322-327 GetOptions( Link Here
322
    'borcat=s'       => \@myborcat,
328
    'borcat=s'       => \@myborcat,
323
    'borcatout=s'    => \@myborcatout,
329
    'borcatout=s'    => \@myborcatout,
324
    'email=s'        => \@emails,
330
    'email=s'        => \@emails,
331
    'owning'         => \$owning_library,
325
) or pod2usage(2);
332
) or pod2usage(2);
326
pod2usage(1) if $help;
333
pod2usage(1) if $help;
327
pod2usage( -verbose => 2 ) if $man;
334
pod2usage( -verbose => 2 ) if $man;
Lines 526-532 AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 Link Here
526
END_SQL
533
END_SQL
527
            my @borrower_parameters;
534
            my @borrower_parameters;
528
            if ($branchcode) {
535
            if ($branchcode) {
529
                $borrower_sql .= ' AND issues.branchcode=? ';
536
		if($owning_library) {
537
		    $borrower_sql .= ' AND items.homebranch=? ';
538
		} else {
539
		    $borrower_sql .= ' AND issues.branchcode=? ';
540
		}
530
                push @borrower_parameters, $branchcode;
541
                push @borrower_parameters, $branchcode;
531
            }
542
            }
532
            if ( $overdue_rules->{categorycode} ) {
543
            if ( $overdue_rules->{categorycode} ) {
533
- 

Return to bug 21886