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

(-)a/misc/cronjobs/writeoff_debts.pl (-22 / +16 lines)
Lines 4-10 use Modern::Perl; Link Here
4
use feature 'say';
4
use feature 'say';
5
5
6
use Getopt::Long qw( GetOptions );
6
use Getopt::Long qw( GetOptions );
7
use Pod::Usage qw( pod2usage );
7
use Pod::Usage   qw( pod2usage );
8
8
9
use Koha::Account::Lines;
9
use Koha::Account::Lines;
10
use Koha::DateUtils qw( dt_from_string );
10
use Koha::DateUtils qw( dt_from_string );
Lines 27-38 GetOptions( Link Here
27
pod2usage(1) if ( $help || !$file && !@type && !$before && !$after && !@category_code );
27
pod2usage(1) if ( $help || !$file && !@type && !$before && !$after && !@category_code );
28
28
29
my $where = { 'amountoutstanding' => { '>' => 0 } };
29
my $where = { 'amountoutstanding' => { '>' => 0 } };
30
my $attr = {};
30
my $attr  = {};
31
31
32
if ($file) {
32
if ($file) {
33
    my @accounts_from_file;
33
    my @accounts_from_file;
34
    open( my $fh, '<:encoding(UTF-8)', $file )
34
    open( my $fh, '<:encoding(UTF-8)', $file )
35
      or die "Could not open file '$file' $!";
35
        or die "Could not open file '$file' $!";
36
    while ( my $line = <$fh> ) {
36
    while ( my $line = <$fh> ) {
37
        chomp($line);
37
        chomp($line);
38
        push @accounts_from_file, $line;
38
        push @accounts_from_file, $line;
Lines 46-52 if (@type) { Link Here
46
}
46
}
47
47
48
my $dtf;
48
my $dtf;
49
if ($before||$after) {
49
if ( $before || $after ) {
50
    $dtf = Koha::Database->new->schema->storage->datetime_parser;
50
    $dtf = Koha::Database->new->schema->storage->datetime_parser;
51
}
51
}
52
52
Lines 67-88 if (@category_code) { Link Here
67
67
68
my $lines = Koha::Account::Lines->search( $where, $attr );
68
my $lines = Koha::Account::Lines->search( $where, $attr );
69
69
70
if ( $verbose ) {
70
if ($verbose) {
71
    print "Attempting to write off " . $lines->count . " debts" if $confirm;
71
    print "Attempting to write off " . $lines->count . " debts"           if $confirm;
72
    print "With --confirm we would write off " . $lines->count . " debts" if !$confirm;
72
    print "With --confirm we would write off " . $lines->count . " debts" if !$confirm;
73
    print " of type " . join(',',@type) if @type;
73
    print " of type " . join( ',', @type )                                if @type;
74
    print " for patron categories " . join(', ', @category_code) if @category_code;
74
    print " for patron categories " . join( ', ', @category_code )        if @category_code;
75
    print " added before " . $before if $before;
75
    print " added before " . $before                                      if $before;
76
    print " added after " . $after if $after;
76
    print " added after " . $after                                        if $after;
77
    print " from the passed list" if $file;
77
    print " from the passed list"                                         if $file;
78
    print "\n";
78
    print "\n";
79
}
79
}
80
80
81
while ( my $line = $lines->next ) {
81
while ( my $line = $lines->next ) {
82
    say "Skipping " . $line->accountlines_id . "; Not a debt" and next
82
    say "Skipping " . $line->accountlines_id . "; Not a debt" and next
83
      if $line->is_credit && $verbose > 1;
83
        if $line->is_credit && $verbose > 1;
84
    say "Skipping " . $line->accountlines_id . "; Is a PAYOUT" and next
84
    say "Skipping " . $line->accountlines_id . "; Is a PAYOUT" and next
85
      if $line->debit_type_code eq 'PAYOUT' && $verbose > 1;
85
        if $line->debit_type_code eq 'PAYOUT' && $verbose > 1;
86
86
87
    if ($confirm) {
87
    if ($confirm) {
88
        $line->_result->result_source->schema->txn_do(
88
        $line->_result->result_source->schema->txn_do(
Lines 112-122 while ( my $line = $lines->next ) { Link Here
112
                )->store();
112
                )->store();
113
113
114
                # Link writeoff to charge
114
                # Link writeoff to charge
115
                $writeoff->apply(
115
                $writeoff->apply( { debits => [$line] } );
116
                    {
117
                        debits => [$line]
118
                    }
119
                );
120
                $writeoff->status('APPLIED')->store();
116
                $writeoff->status('APPLIED')->store();
121
117
122
                # Update status of original debit
118
                # Update status of original debit
Lines 128-135 while ( my $line = $lines->next ) { Link Here
128
    if ($verbose) {
124
    if ($verbose) {
129
        if ($confirm) {
125
        if ($confirm) {
130
            say "Accountline " . $line->accountlines_id . " written off";
126
            say "Accountline " . $line->accountlines_id . " written off";
131
        }
127
        } else {
132
        else {
133
            say "Accountline " . $line->accountlines_id . " will be written off";
128
            say "Accountline " . $line->accountlines_id . " will be written off";
134
        }
129
        }
135
    }
130
    }
Lines 201-207 This flag set the script to output logging for the actions it will perform. Link Here
201
=item B<-c|--confirm>
196
=item B<-c|--confirm>
202
197
203
This flag must be provided in order for the script to actually
198
This flag must be provided in order for the script to actually
204
writeoff debts.  
199
writeoff debts.
205
200
206
=back
201
=back
207
202
208
- 

Return to bug 34077