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

(-)a/installer/data/mysql/atomicupdate/bug_18064-add_LongOverdueNoticeCalendar_syspref.pl (+15 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "BUG_18064",
5
    description => "Add new system preference LongOverdueNoticeCalendar",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(
11
            q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('LongOverdueNoticeCalendar', '0', NULL, 'Take the calendar into consideration when generating long overdue notices', 'Yes/No') }
12
        );
13
        say $out "Added new system preference 'LongOverdueNoticeCalendar'";
14
    },
15
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 373-378 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
373
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
373
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
374
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
374
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
375
('LockExpiredDelay','','','Delay for locking expired patrons (empty means no locking)','Integer'),
375
('LockExpiredDelay','','','Delay for locking expired patrons (empty means no locking)','Integer'),
376
('LongOverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating long overdue notices','YesNo'),
376
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
377
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
377
('Mana','2',NULL,'request to Mana Webservice. Mana centralize common information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','Choice'),
378
('Mana','2',NULL,'request to Mana Webservice. Mana centralize common information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','Choice'),
378
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
379
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+6 lines)
Lines 384-389 Circulation: Link Here
384
            - "Send all notices as a BCC to this email address:"
384
            - "Send all notices as a BCC to this email address:"
385
            - pref: NoticeBcc
385
            - pref: NoticeBcc
386
              class: email
386
              class: email
387
        -
388
            - pref: LongOverdueNoticeCalendar
389
              choices:
390
                  1: Use calendar
391
                  0: Ignore calendar
392
            - "when working out the period for long overdue notices."
387
        -
393
        -
388
            - pref: OverdueNoticeCalendar
394
            - pref: OverdueNoticeCalendar
389
              choices:
395
              choices:
(-)a/misc/cronjobs/longoverdue.pl (-6 / +61 lines)
Lines 30-35 use warnings; Link Here
30
30
31
use Getopt::Long qw( GetOptions );
31
use Getopt::Long qw( GetOptions );
32
use Pod::Usage qw( pod2usage );
32
use Pod::Usage qw( pod2usage );
33
use DateTime;
34
use DateTime::Duration;
33
35
34
use C4::Circulation qw( LostItem MarkIssueReturned );
36
use C4::Circulation qw( LostItem MarkIssueReturned );
35
use C4::Context;
37
use C4::Context;
Lines 38-43 use Koha::ItemTypes; Link Here
38
use Koha::Patron::Categories;
40
use Koha::Patron::Categories;
39
use Koha::Patrons;
41
use Koha::Patrons;
40
use Koha::Script -cron;
42
use Koha::Script -cron;
43
use Koha::Calendar;
44
use Koha::DateUtils qw( dt_from_string );
45
41
46
42
my  $lost;  #  key=lost value,  value=num days.
47
my  $lost;  #  key=lost value,  value=num days.
43
my ($charge, $verbose, $confirm, $quiet);
48
my ($charge, $verbose, $confirm, $quiet);
Lines 314-319 sub longoverdue_sth { Link Here
314
    return C4::Context->dbh->prepare($query);
319
    return C4::Context->dbh->prepare($query);
315
}
320
}
316
321
322
sub get_number_of_holidays {
323
    my ( $start_date, $end_date ) = @_;
324
325
    my @holidays_by_branch;
326
327
    $start_date = dt_from_string($start_date);
328
    $end_date   = dt_from_string($end_date);
329
330
    my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } )->as_list;
331
    my $calendar;
332
333
    foreach my $branch (@branches) {
334
        my $date_to_run = $start_date->clone();
335
        my $branchcode  = $branch->branchcode;
336
        my $i           = 0;
337
338
        $calendar = Koha::Calendar->new( branchcode => $branchcode );
339
340
        while ( $date_to_run ne $end_date ) {
341
342
            # printf "\n Treatment of the day : %s \n", $date_to_run;
343
            if ( $calendar->is_holiday($date_to_run) ) {
344
                $i++;
345
            }
346
            $date_to_run->add( days => 1 );
347
        }
348
        push @holidays_by_branch, { 'branchcode' => $branchcode, 'nb_holidays' => $i };
349
    }
350
    return @holidays_by_branch;
351
}
352
317
my $dbh = C4::Context->dbh;
353
my $dbh = C4::Context->dbh;
318
354
319
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode');
355
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode');
Lines 386-396 foreach my $startrange (sort keys %$lost) { Link Here
386
    if( my $lostvalue = $lost->{$startrange} ) {
422
    if( my $lostvalue = $lost->{$startrange} ) {
387
        my ($date1) = bounds($startrange);
423
        my ($date1) = bounds($startrange);
388
        my ($date2) = bounds(  $endrange);
424
        my ($date2) = bounds(  $endrange);
389
        # print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose);
425
390
        $verbose and
426
        if ( C4::Context->preference('LongOverdueNoticeCalendar') ) {
391
            printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i,
427
            my @holidays_by_branch = get_number_of_holidays( $date2, $date1 );
392
            $startrange, $endrange, $date2, $date1, $lostvalue;
428
393
        $sth_items->execute($startrange, $endrange, $lostvalue);
429
            foreach my $branch (@holidays_by_branch) {
430
431
                my $date2_with_holidays    = dt_from_string($date2)->subtract( days => $branch->{'nb_holidays'} )->ymd;
432
                my $endrange_with_holidays = $endrange + $branch->{'nb_holidays'};
433
434
                $verbose
435
                    and printf "\nBranchcode %s\nDue %3s - %3s days ago (%s to %s) - with %s holiday(s), lost => %s\n",
436
                    $branch->{'branchcode'},
437
                    $startrange, $endrange_with_holidays, $date2_with_holidays, $date1, $branch->{'nb_holidays'},
438
                    $lostvalue;
439
                $sth_items->execute( $startrange, $endrange_with_holidays, $lostvalue );
440
            }
441
        } else {
442
            # print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose);
443
            $verbose
444
                and printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i,
445
                $startrange, $endrange, $date2, $date1, $lostvalue;
446
            $sth_items->execute( $startrange, $endrange, $lostvalue );
447
        }
448
394
        $count=0;
449
        $count=0;
395
        ITEM: while (my $row=$sth_items->fetchrow_hashref) {
450
        ITEM: while (my $row=$sth_items->fetchrow_hashref) {
396
            if( $filter_borrower_categories ) {
451
            if( $filter_borrower_categories ) {
Lines 414-419 foreach my $startrange (sort keys %$lost) { Link Here
414
            }
469
            }
415
            $count++;
470
            $count++;
416
        }
471
        }
472
417
        push @report, {
473
        push @report, {
418
           startrange => $startrange,
474
           startrange => $startrange,
419
             endrange => $endrange,
475
             endrange => $endrange,
420
- 

Return to bug 18064