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

(-)a/misc/cronjobs/writeoff_debts.pl (-9 / +18 lines)
Lines 11-28 use Koha::DateUtils qw( dt_from_string ); Link Here
11
11
12
use Koha::Script -cron;
12
use Koha::Script -cron;
13
13
14
my ( $help, $verbose, @type, $added, $file, $confirm );
14
my ( $help, $verbose, @type, $before, $after, $file, $confirm );
15
GetOptions(
15
GetOptions(
16
    'h|help'            => \$help,
16
    'h|help'            => \$help,
17
    'v|verbose+'        => \$verbose,
17
    'v|verbose+'        => \$verbose,
18
    't|type:s'          => \@type,
18
    't|type:s'          => \@type,
19
    'ab|added_before:s' => \$added,
19
    'ab|added_before:s' => \$before,
20
    'aa|added_after:s'  => \$after,
20
    'f|file:s'          => \$file,
21
    'f|file:s'          => \$file,
21
    'c|confirm'         => \$confirm,
22
    'c|confirm'         => \$confirm,
22
);
23
);
23
@type = split( /,/, join( ',', @type ) );
24
@type = split( /,/, join( ',', @type ) );
24
25
25
pod2usage(1) if ( $help || !$confirm && !$verbose || !$file && !@type && !$added );
26
pod2usage(1) if ( $help || !$confirm && !$verbose || !$file && !@type && !$before && !$after );
26
27
27
my $where = { 'amountoutstanding' => { '>' => 0 } };
28
my $where = { 'amountoutstanding' => { '>' => 0 } };
28
my $attr = {};
29
my $attr = {};
Lines 43-59 if (@type) { Link Here
43
    $where->{debit_type_code} = \@type;
44
    $where->{debit_type_code} = \@type;
44
}
45
}
45
46
46
if ($added) {
47
my $dtf;
47
    my $added_before = dt_from_string( $added, 'iso' );
48
if ($before||$after) {
48
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
49
    $dtf = Koha::Database->new->schema->storage->datetime_parser;
49
    $where->{date} = { '<' => $dtf->format_datetime($added_before) };
50
}
51
52
if ($before) {
53
    my $added_before = dt_from_string( $before, 'iso' );
54
    $where->{date}->{'<'} = $dtf->format_datetime($added_before);
55
}
56
57
if ($after) {
58
    my $added_after = dt_from_string( $after, 'iso' );
59
    $where->{date}->{'>'} = $dtf->format_datetime($added_after);
50
}
60
}
51
61
52
my $lines = Koha::Account::Lines->search( $where, $attr );
62
my $lines = Koha::Account::Lines->search( $where, $attr );
53
if ( $verbose ) {
63
if ( $verbose ) {
54
    print "Attempting to write off " . $lines->count . " debts";
64
    print "Attempting to write off " . $lines->count . " debts";
55
    print " of type " . join(',',@type) if @type;
65
    print " of type " . join(',',@type) if @type;
56
    print " added before " . $added if $added;
66
    print " added before " . $before if $before;
57
    print " from the passed list" if $file;
67
    print " from the passed list" if $file;
58
    print "\n";
68
    print "\n";
59
}
69
}
60
- 

Return to bug 28995