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

(-)a/C4/Circulation.pm (-25 / +8 lines)
Lines 2700-2730 sub GetUpcomingDueIssues { Link Here
2700
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2700
    $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
2701
    my $dbh = C4::Context->dbh;
2701
    my $dbh = C4::Context->dbh;
2702
    my $statement;
2702
    my $statement;
2703
    if($params->{'owning_library'}) {
2703
    $statement = q{
2704
    $statement = <<"END_SQL";
2704
        SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2705
SELECT *
2705
        FROM issues
2706
FROM (
2706
        LEFT JOIN items USING (itemnumber)
2707
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2707
        LEFT JOIN branches ON branches.branchcode =
2708
    FROM issues
2708
    };
2709
    LEFT JOIN items USING (itemnumber)
2709
    $statement .= $params->{'owning_library'} ? " items.homebranch " : " issues.branchcode ";
2710
    LEFT OUTER JOIN branches ON (branches.branchcode = items.homebranch)
2710
    $statement .= " WHERE returndate is NULL AND TO_DAYS( date_due )-TO_DAYS( NOW() ) BETWEEN 0 AND ?";
2711
    WHERE returndate is NULL
2712
) tmp
2713
WHERE days_until_due >= 0 AND days_until_due <= ?
2714
END_SQL
2715
    } else {
2716
    $statement = <<"END_SQL";
2717
SELECT *
2718
FROM (
2719
    SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2720
    FROM issues
2721
    LEFT JOIN items USING (itemnumber)
2722
    LEFT OUTER JOIN branches USING (branchcode)
2723
    WHERE returndate is NULL
2724
) tmp
2725
WHERE days_until_due >= 0 AND days_until_due <= ?
2726
END_SQL
2727
    }
2728
    my @bind_parameters = ( $params->{'days_in_advance'} );
2711
    my @bind_parameters = ( $params->{'days_in_advance'} );
2729
    
2712
    
2730
    my $sth = $dbh->prepare( $statement );
2713
    my $sth = $dbh->prepare( $statement );
(-)a/misc/cronjobs/advance_notices.pl (-19 / +19 lines)
Lines 214-220 GetOptions( Link Here
214
            'help|?'         => \$help,
214
            'help|?'         => \$help,
215
            'man'            => \$man,
215
            'man'            => \$man,
216
            'library=s'      => \@branchcodes,
216
            'library=s'      => \@branchcodes,
217
            'frombranch'     => \$frombranch,
217
            'frombranch=s'   => \$frombranch,
218
            'c'              => \$confirm,
218
            'c'              => \$confirm,
219
            'n'              => \$nomail,
219
            'n'              => \$nomail,
220
            'm:i'            => \$maxdays,
220
            'm:i'            => \$maxdays,
Lines 242-248 unless ($confirm) { Link Here
242
}
242
}
243
cronlogaction();
243
cronlogaction();
244
244
245
my %branches = {};
245
my %branches = ();
246
if (@branchcodes) {
246
if (@branchcodes) {
247
    %branches = map { $_ => 1 } @branchcodes;
247
    %branches = map { $_ => 1 } @branchcodes;
248
}
248
}
Lines 304-317 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
304
                $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
304
                $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
305
            }
305
            }
306
        } else {
306
        } else {
307
        my $branchcode;
307
            my $branchcode;
308
        if($owning_library) {
308
            if($owning_library) {
309
        $branchcode = $upcoming->{'homebranch'};
309
                $branchcode = $upcoming->{'homebranch'};
310
        } else {
310
            } else {
311
        $branchcode = $upcoming->{'branchcode'};
311
                $branchcode = $upcoming->{'branchcode'};
312
        }
312
            }
313
        # Skip this DUE if we specify list of libraries and this one is not part of it
313
            # Skip this DUE if we specify list of libraries and this one is not part of it
314
        next if (@branchcodes && !$branches{$branchcode});
314
            next if (@branchcodes && !$branches{$branchcode});
315
315
316
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
316
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
317
            my $letter_type = 'DUE';
317
            my $letter_type = 'DUE';
Lines 351-364 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
351
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
351
                $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
352
            }
352
            }
353
        } else {
353
        } else {
354
        my $branchcode;
354
            my $branchcode;
355
        if($owning_library) {
355
            if($owning_library) {
356
        $branchcode = $upcoming->{'homebranch'};
356
            $branchcode = $upcoming->{'homebranch'};
357
        } else {
357
            } else {
358
        $branchcode = $upcoming->{'branchcode'};
358
            $branchcode = $upcoming->{'branchcode'};
359
        }
359
            }
360
        # Skip this PREDUE if we specify list of libraries and this one is not part of it
360
            # Skip this PREDUE if we specify list of libraries and this one is not part of it
361
        next if (@branchcodes && !$branches{$branchcode});
361
            next if (@branchcodes && !$branches{$branchcode});
362
362
363
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
363
            my $item = Koha::Items->find( $upcoming->{itemnumber} );
364
            my $letter_type = 'PREDUE';
364
            my $letter_type = 'PREDUE';
Lines 389-395 UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { Link Here
389
      if ($nomail) {
389
      if ($nomail) {
390
        for my $letter ( @letters ) {
390
        for my $letter ( @letters ) {
391
            local $, = "\f";
391
            local $, = "\f";
392
            print $letter->{'content'};
392
            print $letter->{'content'}."\n";
393
        }
393
        }
394
      }
394
      }
395
      else {
395
      else {
(-)a/misc/cronjobs/overdue_notices.pl (-5 / +11 lines)
Lines 75-81 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
   --frombranch                   Set the from address for the notice to one of 'item-homebranch' or 'item-issuebranch'.
79
79
80
=head1 OPTIONS
80
=head1 OPTIONS
81
81
Lines 184-193 use it in order to send overdues on a specific date and not Now. Format: YYYY-MM Link Here
184
184
185
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.
186
186
187
=item B<--owning>
187
=item B<--frombranch>
188
188
189
Use the address information from the item homebranch library instead of the issuing library.
189
Use the address information from the item homebranch library instead of the issuing library.
190
190
191
Defaults to 'item-issuebranch'
192
191
=back
193
=back
192
194
193
=head1 DESCRIPTION
195
=head1 DESCRIPTION
Lines 297-303 my $verbose = 0; Link Here
297
my $nomail  = 0;
299
my $nomail  = 0;
298
my $MAX     = 90;
300
my $MAX     = 90;
299
my $test_mode = 0;
301
my $test_mode = 0;
300
my $owning_library = 0;
302
my $frombranch = 'item-issuebranch';
301
my @branchcodes; # Branch(es) passed as parameter
303
my @branchcodes; # Branch(es) passed as parameter
302
my @emails_to_use;    # Emails to use for messaging
304
my @emails_to_use;    # Emails to use for messaging
303
my @emails;           # Emails given in command-line parameters
305
my @emails;           # Emails given in command-line parameters
Lines 329-335 GetOptions( Link Here
329
    'borcat=s'       => \@myborcat,
331
    'borcat=s'       => \@myborcat,
330
    'borcatout=s'    => \@myborcatout,
332
    'borcatout=s'    => \@myborcatout,
331
    'email=s'        => \@emails,
333
    'email=s'        => \@emails,
332
    'owning'         => \$owning_library,
334
    'frombranch=s'   => \$frombranch,
333
) or pod2usage(2);
335
) or pod2usage(2);
334
pod2usage(1) if $help;
336
pod2usage(1) if $help;
335
pod2usage( -verbose => 2 ) if $man;
337
pod2usage( -verbose => 2 ) if $man;
Lines 339-344 if ( defined $csvfilename && $csvfilename =~ /^-/ ) { Link Here
339
    warn qq(using "$csvfilename" as filename, that seems odd);
341
    warn qq(using "$csvfilename" as filename, that seems odd);
340
}
342
}
341
343
344
die "--frombranch takes item-homebranch or item-issuebranch only"
345
    unless ( $frombranch eq 'item-issuebranch'
346
        || $frombranch eq 'item-homebranch' );
347
my $owning_library = ( $frombranch eq 'item-homebranch' ) ? 1 : 0;
348
342
my @overduebranches    = C4::Overdues::GetBranchcodesWithOverdueRules();    # Branches with overdue rules
349
my @overduebranches    = C4::Overdues::GetBranchcodesWithOverdueRules();    # Branches with overdue rules
343
my @branches;                                    # Branches passed as parameter with overdue rules
350
my @branches;                                    # Branches passed as parameter with overdue rules
344
my $branchcount = scalar(@overduebranches);
351
my $branchcount = scalar(@overduebranches);
345
- 

Return to bug 21886