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

(-)a/misc/cronjobs/batch_anonymise.pl (-1 lines)
Lines 31-37 BEGIN { Link Here
31
31
32
use C4::Context;
32
use C4::Context;
33
use C4::Circulation;
33
use C4::Circulation;
34
use C4::Dates;
35
use Date::Calc qw(
34
use Date::Calc qw(
36
  Today
35
  Today
37
  Add_Delta_Days
36
  Add_Delta_Days
(-)a/misc/cronjobs/cleanup_database.pl (-1 lines)
Lines 35-41 BEGIN { Link Here
35
}
35
}
36
36
37
use C4::Context;
37
use C4::Context;
38
use C4::Dates;
39
use C4::Search;
38
use C4::Search;
40
use C4::Search::History;
39
use C4::Search::History;
41
use Getopt::Long;
40
use Getopt::Long;
(-)a/misc/cronjobs/gather_print_notices.pl (-1 lines)
Lines 11-17 BEGIN { Link Here
11
11
12
use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
12
use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
13
use C4::Context;
13
use C4::Context;
14
use C4::Dates;
15
use C4::Debug;
14
use C4::Debug;
16
use C4::Letters;
15
use C4::Letters;
17
use C4::Templates;
16
use C4::Templates;
(-)a/misc/cronjobs/overdue_notices.pl (-5 / +76 lines)
Lines 38-44 use DateTime; Link Here
38
use DateTime::Duration;
38
use DateTime::Duration;
39
39
40
use C4::Context;
40
use C4::Context;
41
use C4::Dates qw/format_date/;
42
use C4::Debug;
41
use C4::Debug;
43
use C4::Letters;
42
use C4::Letters;
44
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
43
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
Lines 527-533 END_SQL Link Here
527
            my $borrowernumber;
526
            my $borrowernumber;
528
            while ( my $data = $sth->fetchrow_hashref ) {
527
            while ( my $data = $sth->fetchrow_hashref ) {
529
528
530
                next unless ( DateTime->compare( $date_to_run,  dt_from_string($data->{date_due})) ) == 1;
529
                next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1;
531
530
532
                # check the borrower has at least one item that matches
531
                # check the borrower has at least one item that matches
533
                my $days_between;
532
                my $days_between;
Lines 536-547 END_SQL Link Here
536
                    my $calendar =
535
                    my $calendar =
537
                      Koha::Calendar->new( branchcode => $branchcode );
536
                      Koha::Calendar->new( branchcode => $branchcode );
538
                    $days_between =
537
                    $days_between =
539
                      $calendar->days_between(  dt_from_string($data->{date_due}),
538
                      $calendar->days_between( dt_from_string($data->{date_due}),
540
                        $date_to_run );
539
                        $date_to_run );
541
                }
540
                }
542
                else {
541
                else {
543
                    $days_between =
542
                    $days_between =
544
                      $date_to_run->delta_days(  dt_from_string($data->{date_due}) );
543
                      $date_to_run->delta_days( dt_from_string($data->{date_due}) );
545
                }
544
                }
546
                $days_between = $days_between->in_units('days');
545
                $days_between = $days_between->in_units('days');
547
                if ($triggered) {
546
                if ($triggered) {
Lines 657-663 END_SQL Link Here
657
                      last;
656
                      last;
658
                    }
657
                    }
659
                    $j++;
658
                    $j++;
660
                    my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields;
659
                    my @item_info = map { $_ =~ /^date|date$/ ?
660
                                           eval { output_pref( { dt => dt_from_string( $item_info->{$_} ), dateonly => 1 } ); }
661
                                           :
662
                                           $item_info->{$_} || '' } @item_content_fields;
661
                    $titles .= join("\t", @item_info) . "\n";
663
                    $titles .= join("\t", @item_info) . "\n";
662
                    $itemcount++;
664
                    $itemcount++;
663
                    push @items, $item_info;
665
                    push @items, $item_info;
Lines 829-834 if ( defined $htmlfilename ) { Link Here
829
831
830
These methods are internal to the operation of overdue_notices.pl.
832
These methods are internal to the operation of overdue_notices.pl.
831
833
834
=head2 parse_letter
835
836
parses the letter template, replacing the placeholders with data
837
specific to this patron, biblio, or item
838
839
named parameters:
840
  letter - required hashref
841
  borrowernumber - required integer
842
  substitute - optional hashref of other key/value pairs that should
843
    be substituted in the letter content
844
845
returns the C<letter> hashref, with the content updated to reflect the
846
substituted keys and values.
847
848
849
=cut
850
851
sub parse_letter {
852
    my $params = shift;
853
    foreach my $required (qw( letter_code borrowernumber )) {
854
        return unless ( exists $params->{$required} && $params->{$required} );
855
    }
856
857
    my $substitute = $params->{'substitute'} || {};
858
    $substitute->{today} ||= output_pref( { dt => dt_from_string , dateonly => 1 } );
859
860
    my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
861
    if ( my $p = $params->{'branchcode'} ) {
862
        $tables{'branches'} = $p;
863
    }
864
865
    my $currencies = GetCurrency();
866
    my $currency_format;
867
    $currency_format = $currencies->{currency} if defined($currencies);
868
869
    my @item_tables;
870
    if ( my $i = $params->{'items'} ) {
871
        my $item_format = '';
872
        foreach my $item (@$i) {
873
            my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
874
            if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
875
                $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
876
                $item_format = $1;
877
            }
878
879
            $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
880
            # if active currency isn't correct ISO code fallback to sprintf
881
            $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
882
883
            push @item_tables, {
884
                'biblio' => $item->{'biblionumber'},
885
                'biblioitems' => $item->{'biblionumber'},
886
                'items' => $item,
887
                'issues' => $item->{'itemnumber'},
888
            };
889
        }
890
    }
891
892
    return C4::Letters::GetPreparedLetter (
893
        module => 'circulation',
894
        letter_code => $params->{'letter_code'},
895
        branchcode => $params->{'branchcode'},
896
        tables => \%tables,
897
        substitute => $substitute,
898
        repeat => { item => \@item_tables },
899
        message_transport_type => $params->{message_transport_type},
900
    );
901
}
902
832
=head2 prepare_letter_for_printing
903
=head2 prepare_letter_for_printing
833
904
834
returns a string of text appropriate for printing in the event that an
905
returns a string of text appropriate for printing in the event that an
(-)a/misc/cronjobs/serialsUpdate.pl (-2 / +2 lines)
Lines 29-38 BEGIN { Link Here
29
}
29
}
30
30
31
use C4::Context;
31
use C4::Context;
32
use C4::Dates qw/format_date format_date_in_iso/;
33
use C4::Debug;
32
use C4::Debug;
34
use C4::Serials;
33
use C4::Serials;
35
use C4::Log;
34
use C4::Log;
35
use Koha::DateUtils;
36
36
37
use Date::Calc qw/Date_to_Days check_date/;
37
use Date::Calc qw/Date_to_Days check_date/;
38
use Getopt::Long;
38
use Getopt::Long;
Lines 119-125 while ( my $issue = $sth->fetchrow_hashref ) { Link Here
119
119
120
    if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) {
120
    if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) {
121
        my $nextpublisheddate = GetNextDate( $subscription, $publisheddate );
121
        my $nextpublisheddate = GetNextDate( $subscription, $publisheddate );
122
        my $today = format_date_in_iso( C4::Dates->new()->output() );
122
        my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
123
123
124
        if ( $nextpublisheddate && $today ) {
124
        if ( $nextpublisheddate && $today ) {
125
            my ( $year,  $month,  $day )  = split( /-/, $nextpublisheddate );
125
            my ( $year,  $month,  $day )  = split( /-/, $nextpublisheddate );
(-)a/misc/cronjobs/staticfines.pl (-8 / +7 lines)
Lines 103-109 foreach (@pcategories) { Link Here
103
}
103
}
104
104
105
use vars qw(@borrower_fields @item_fields @other_fields);
105
use vars qw(@borrower_fields @item_fields @other_fields);
106
use vars qw($fldir $libname $control $mode $delim $dbname $today $today_iso $today_days);
106
use vars qw($fldir $libname $control $mode $delim $dbname $today_iso $today_days);
107
use vars qw($filename);
107
use vars qw($filename);
108
108
109
CHECK {
109
CHECK {
Lines 135-142 if (defined $borrowernumberlimit) { Link Here
135
}
135
}
136
my $overdueItemsCounted = 0;
136
my $overdueItemsCounted = 0;
137
my %calendars           = ();
137
my %calendars           = ();
138
$today      = C4::Dates->new();
138
$today_iso  = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } );
139
$today_iso  = $today->output('iso');
140
my ($tyear, $tmonth, $tday) = split( /-/, $today_iso );
139
my ($tyear, $tmonth, $tday) = split( /-/, $today_iso );
141
$today_days = Date_to_Days( $tyear, $tmonth, $tday );
140
$today_days = Date_to_Days( $tyear, $tmonth, $tday );
142
141
Lines 145-158 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
145
    my $datedue;
144
    my $datedue;
146
    my $datedue_days;
145
    my $datedue_days;
147
    eval {
146
    eval {
148
    $datedue = C4::Dates->new( $data->[$i]->{'date_due'}, 'iso' );
147
    $datedue = eval { output_pref( { dt => dt_from_string( $data->[$i]->{'date_due'} ), dateonly => 1, dateformat => 'iso' } ); };
149
    $datedue_days = Date_to_Days( split( /-/, $datedue->output('iso') ) );
148
    $datedue_days = Date_to_Days( split( /-/, $datedue ) );
150
    };
149
    };
151
    if ($@) {
150
    if ($@) {
152
    warn "Error on date for borrower " . $data->[$i]->{'borrowernumber'} .  ": $@date_due: " . $data->[$i]->{'date_due'} . "\ndatedue_days: " . $datedue_days . "\nSkipping";
151
    warn "Error on date for borrower " . $data->[$i]->{'borrowernumber'} .  ": $@date_due: " . $data->[$i]->{'date_due'} . "\ndatedue_days: " . $datedue_days . "\nSkipping";
153
    next;
152
    next;
154
    }
153
    }
155
    my $due_str = $datedue->output();
154
    my $due_str = eval { output_pref( { dt => dt_from_string( $datedue ), dateonly => 1 } ); };
156
    unless ( defined $data->[$i]->{'borrowernumber'} ) {
155
    unless ( defined $data->[$i]->{'borrowernumber'} ) {
157
        print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
156
        print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
158
        next;    # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
157
        next;    # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
Lines 192-199 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
192
        $data->[$i],
191
        $data->[$i],
193
        $borrower->{'categorycode'},
192
        $borrower->{'categorycode'},
194
        $branchcode,
193
        $branchcode,
195
        dt_from_string($datedue->output('iso')),
194
        dt_from_string( $datedue ),
196
        dt_from_string($today->output('iso')),
195
        dt_from_string( $today_iso ),
197
    );
196
    );
198
197
199
    # Reassign fine's amount if specified in command-line
198
    # Reassign fine's amount if specified in command-line
(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-4 / +3 lines)
Lines 36-43 use C4::Context; Link Here
36
use C4::Items;
36
use C4::Items;
37
use C4::Letters;
37
use C4::Letters;
38
use C4::Overdues;
38
use C4::Overdues;
39
use C4::Dates;
40
use C4::Calendar;
39
use C4::Calendar;
40
use Koha::DateUtils;
41
41
42
sub usage {
42
sub usage {
43
    pod2usage( -verbose => 2 );
43
    pod2usage( -verbose => 2 );
Lines 124-131 foreach my $type (@types) { Link Here
124
    }
124
    }
125
125
126
    foreach my $issues (@loop) {
126
    foreach my $issues (@loop) {
127
        my $date = C4::Dates->new( $issues->{'date_due'}, 'iso' );
127
        my $date_dt = dt_from_string ( $issues->{'date_due'} );
128
        my $due_date = $date->output('metric');
128
        my $due_date = output_pref( { dt => $date_dt, dateonly => 1, dateformat =>'metric' } );
129
129
130
        my $letter = C4::Letters::GetPreparedLetter(
130
        my $letter = C4::Letters::GetPreparedLetter(
131
            module      => $module,
131
            module      => $module,
132
- 

Return to bug 14960