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

(-)a/C4/Circulation.pm (-3 / +16 lines)
Lines 2617-2624 sub GetUpcomingDueIssues { Link Here
2617
2617
2618
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2618
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2619
    my $dbh = C4::Context->dbh;
2619
    my $dbh = C4::Context->dbh;
2620
2620
    my $statement;
2621
    my $statement = <<END_SQL;
2621
    if($params->{'owning_library'}) {
2622
	$statement = <<"END_SQL";
2623
SELECT *
2624
FROM (
2625
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2626
    FROM issues
2627
    LEFT JOIN items USING (itemnumber)
2628
    LEFT OUTER JOIN branches ON (branches.branchcode = items.homebranch)
2629
    WHERE returndate is NULL
2630
) tmp
2631
WHERE days_until_due >= 0 AND days_until_due <= ?
2632
END_SQL
2633
    } else {
2634
	$statement = <<"END_SQL";
2622
SELECT *
2635
SELECT *
2623
FROM (
2636
FROM (
2624
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2637
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
Lines 2629-2635 FROM ( Link Here
2629
) tmp
2642
) tmp
2630
WHERE days_until_due >= 0 AND days_until_due <= ?
2643
WHERE days_until_due >= 0 AND days_until_due <= ?
2631
END_SQL
2644
END_SQL
2632
2645
    }
2633
    my @bind_parameters = ( $params->{'days_in_advance'} );
2646
    my @bind_parameters = ( $params->{'days_in_advance'} );
2634
    
2647
    
2635
    my $sth = $dbh->prepare( $statement );
2648
    my $sth = $dbh->prepare( $statement );
(-)a/misc/cronjobs/advance_notices.pl (-3 / +40 lines)
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
125
the digested message.  It has no effect unless the borrower has
126
chosen 'Digests only' on the advance messages.
126
chosen 'Digests only' on the advance messages.
127
127
128
=item B<-library>
129
130
select notices for one specific library. Use the value in the
131
branches.branchcode table. This option can be repeated in order
132
to select notices for a group of libraries.
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 191-196 my $mindays = 0; # -m: Maximu Link Here
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
193
my $digest_per_branch = 0;                                          # -digest-per-branch: Prepare and send digests per branch
203
my $digest_per_branch = 0;                                          # -digest-per-branch: Prepare and send digests per branch
204
my @branchcodes; # Branch(es) passed as parameter
205
my $owning_library = 0;
194
my $itemscontent = join(',',qw( date_due title author barcode ));
206
my $itemscontent = join(',',qw( date_due title author barcode ));
195
207
196
my $help    = 0;
208
my $help    = 0;
Lines 199-204 my $man = 0; Link Here
199
GetOptions(
211
GetOptions(
200
            'help|?'         => \$help,
212
            'help|?'         => \$help,
201
            'man'            => \$man,
213
            'man'            => \$man,
214
            'library=s'      => \@branchcodes,
215
            'owning'         => \$owning_library,
202
            'c'              => \$confirm,
216
            'c'              => \$confirm,
203
            'n'              => \$nomail,
217
            'n'              => \$nomail,
204
            'm:i'            => \$maxdays,
218
            'm:i'            => \$maxdays,
Lines 226-236 unless ($confirm) { Link Here
226
}
240
}
227
cronlogaction();
241
cronlogaction();
228
242
243
my %branches = map { $_ => 1 } @branchcodes if @branchcodes;
244
229
# The fields that will be substituted into <<items.content>>
245
# The fields that will be substituted into <<items.content>>
230
my @item_content_fields = split(/,/,$itemscontent);
246
my @item_content_fields = split(/,/,$itemscontent);
231
247
232
warn 'getting upcoming due issues' if $verbose;
248
warn 'getting upcoming due issues' if $verbose;
233
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $maxdays } );
249
my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( {
250
    days_in_advance => $maxdays,
251
    owning_library => $owning_library
252
 } );
234
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
253
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
235
254
236
# hash of borrowernumber to number of items upcoming
255
# 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}++;
294
                $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
276
            }
295
            }
277
        } else {
296
        } else {
297
	    my $branchcode;
298
	    if($owning_library) {
299
		$branchcode = $upcoming->{'homebranch'};
300
	    } else {
301
		$branchcode = $upcoming->{'branchcode'};
302
	    }
303
	    # Skip this DUE if we specify list of libraries and this one is not part of it
304
	    next if (@branchcodes && !$branches{$branchcode});
305
278
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
306
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
279
            my $letter_type = 'DUE';
307
            my $letter_type = 'DUE';
280
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
308
            $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'}} ) {
315
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
288
                my $letter = parse_letter( { letter_code    => $letter_type,
316
                my $letter = parse_letter( { letter_code    => $letter_type,
289
                                      borrowernumber => $upcoming->{'borrowernumber'},
317
                                      borrowernumber => $upcoming->{'borrowernumber'},
290
                                      branchcode     => $upcoming->{'branchcode'},
318
                                      branchcode     => $branchcode,
291
                                      biblionumber   => $item->biblionumber,
319
                                      biblionumber   => $item->biblionumber,
292
                                      itemnumber     => $upcoming->{'itemnumber'},
320
                                      itemnumber     => $upcoming->{'itemnumber'},
293
                                      substitute     => { 'items.content' => $titles },
321
                                      substitute     => { 'items.content' => $titles },
Lines 313-318 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
313
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
341
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
314
            }
342
            }
315
        } else {
343
        } else {
344
	    my $branchcode;
345
	    if($owning_library) {
346
		$branchcode = $upcoming->{'homebranch'};
347
	    } else {
348
		$branchcode = $upcoming->{'branchcode'};
349
	    }
350
	    # Skip this PREDUE if we specify list of libraries and this one is not part of it
351
	    next if (@branchcodes && !$branches{$branchcode});
352
316
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
353
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
317
            my $letter_type = 'PREDUE';
354
            my $letter_type = 'PREDUE';
318
            $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
355
            $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'}} ) {
362
            foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) {
326
                my $letter = parse_letter( { letter_code    => $letter_type,
363
                my $letter = parse_letter( { letter_code    => $letter_type,
327
                                      borrowernumber => $upcoming->{'borrowernumber'},
364
                                      borrowernumber => $upcoming->{'borrowernumber'},
328
                                      branchcode     => $upcoming->{'branchcode'},
365
                                      branchcode     => $branchcode,
329
                                      biblionumber   => $item->biblionumber,
366
                                      biblionumber   => $item->biblionumber,
330
                                      itemnumber     => $upcoming->{'itemnumber'},
367
                                      itemnumber     => $upcoming->{'itemnumber'},
331
                                      substitute     => { 'items.content' => $titles },
368
                                      substitute     => { 'items.content' => $titles },
(-)a/misc/cronjobs/overdue_notices.pl (-4 / +20 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 461-467 foreach my $branchcode (@branches) { Link Here
461
468
462
    $verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $branch_email_address;
469
    $verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $branch_email_address;
463
470
464
    my $sth2 = $dbh->prepare( <<"END_SQL" );
471
    my $sql2 = <<"END_SQL";
465
SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname
472
SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname
466
  FROM issues,items,biblio, biblioitems, branches b
473
  FROM issues,items,biblio, biblioitems, branches b
467
  WHERE items.itemnumber=issues.itemnumber
474
  WHERE items.itemnumber=issues.itemnumber
Lines 469-479 SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname Link Here
469
    AND b.branchcode = items.homebranch
476
    AND b.branchcode = items.homebranch
470
    AND biblio.biblionumber   = biblioitems.biblionumber
477
    AND biblio.biblionumber   = biblioitems.biblionumber
471
    AND issues.borrowernumber = ?
478
    AND issues.borrowernumber = ?
472
    AND issues.branchcode = ?
473
    AND items.itemlost = 0
479
    AND items.itemlost = 0
474
    AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
480
    AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
475
END_SQL
481
END_SQL
476
482
483
    if($owning_library) {
484
      $sql2 .= ' AND items.homebranch = ? ';
485
    } else {
486
      $sql2 .= ' AND issues.branchcode = ? ';
487
    }
488
    my $sth2 = $dbh->prepare($sql2);
489
477
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? ";
490
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? ";
478
    $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
491
    $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
479
    $query .= " AND categorycode NOT IN (".join( ',' , ('?') x @myborcatout ).") " if (@myborcatout);
492
    $query .= " AND categorycode NOT IN (".join( ',' , ('?') x @myborcatout ).") " if (@myborcatout);
Lines 528-534 AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 Link Here
528
END_SQL
541
END_SQL
529
            my @borrower_parameters;
542
            my @borrower_parameters;
530
            if ($branchcode) {
543
            if ($branchcode) {
531
                $borrower_sql .= ' AND issues.branchcode=? ';
544
		if($owning_library) {
545
		    $borrower_sql .= ' AND items.homebranch=? ';
546
		} else {
547
		    $borrower_sql .= ' AND issues.branchcode=? ';
548
		}
532
                push @borrower_parameters, $branchcode;
549
                push @borrower_parameters, $branchcode;
533
            }
550
            }
534
            if ( $overdue_rules->{categorycode} ) {
551
            if ( $overdue_rules->{categorycode} ) {
535
- 

Return to bug 21886