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

(-)a/C4/Accounts.pm (-54 / +10 lines)
Lines 26-31 use C4::Members; Link Here
26
use C4::Circulation qw(ReturnLostItem);
26
use C4::Circulation qw(ReturnLostItem);
27
use C4::Log qw(logaction);
27
use C4::Log qw(logaction);
28
use Koha::Account;
28
use Koha::Account;
29
use Koha::Account::Lines;
29
30
30
use Data::Dumper qw(Dumper);
31
use Data::Dumper qw(Dumper);
31
32
Lines 366-427 C<$payment_note> is the note to attach to this payment Link Here
366
367
367
sub WriteOffFee {
368
sub WriteOffFee {
368
    my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_;
369
    my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_;
369
    $payment_note //= "";
370
    $branch ||= C4::Context->userenv->{branch};
371
    my $manager_id = 0;
372
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
373
374
    # if no item is attached to fine, make sure to store it as a NULL
375
    $itemnum ||= undef;
376
377
    my ( $sth, $query );
378
    my $dbh = C4::Context->dbh();
379
380
    $query = "
381
        UPDATE accountlines SET amountoutstanding = 0
382
        WHERE accountlines_id = ? AND borrowernumber = ?
383
    ";
384
    $sth = $dbh->prepare( $query );
385
    $sth->execute( $accountlines_id, $borrowernumber );
386
387
    if ( C4::Context->preference("FinesLog") ) {
388
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
389
            action                => 'fee_writeoff',
390
            borrowernumber        => $borrowernumber,
391
            accountlines_id       => $accountlines_id,
392
            manager_id            => $manager_id,
393
        }));
394
    }
395
370
396
    $query ="
371
    my $line = Koha::Account::Lines->find($accountlines_id);
397
        INSERT INTO accountlines
372
    return Koha::Account->new( { patron_id => $borrowernumber } )->pay(
398
        ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id, note )
373
        {
399
        VALUES ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W', ?, ? )
374
            amount     => $amount,
400
    ";
375
            lines      => [$line],
401
    $sth = $dbh->prepare( $query );
376
            type       => 'writeoff',
402
    my $acct = getnextacctno($borrowernumber);
377
            note       => $payment_note,
403
    $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id, $payment_note );
378
            library_id => $branch,
404
379
        }
405
    if ( C4::Context->preference("FinesLog") ) {
406
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
407
            action            => 'create_writeoff',
408
            borrowernumber    => $borrowernumber,
409
            accountno         => $acct,
410
            amount            => 0 - $amount,
411
            accounttype       => 'W',
412
            itemnumber        => $itemnum,
413
            accountlines_paid => [ $accountlines_id ],
414
            manager_id        => $manager_id,
415
        }));
416
    }
417
418
    UpdateStats({
419
                branch => $branch,
420
                type => 'writeoff',
421
                amount => $amount,
422
                borrowernumber => $borrowernumber}
423
    );
380
    );
424
425
}
381
}
426
382
427
=head2 purge_zero_balance_fees
383
=head2 purge_zero_balance_fees
(-)a/Koha/Account.pm (-7 / +12 lines)
Lines 67-72 sub pay { Link Here
67
    my $note            = $params->{note} || q{};
67
    my $note            = $params->{note} || q{};
68
    my $library_id      = $params->{library_id};
68
    my $library_id      = $params->{library_id};
69
    my $lines           = $params->{lines};
69
    my $lines           = $params->{lines};
70
    my $type            = $params->{type} || 'payment';
70
71
71
    my $userenv = C4::Context->userenv;
72
    my $userenv = C4::Context->userenv;
72
73
Lines 154-160 sub pay { Link Here
154
                $self->{patron_id},
155
                $self->{patron_id},
155
                Dumper(
156
                Dumper(
156
                    {
157
                    {
157
                        action                => 'fee_payment',
158
                        action                => "fee_$type",
158
                        borrowernumber        => $fine->borrowernumber,
159
                        borrowernumber        => $fine->borrowernumber,
159
                        old_amountoutstanding => $old_amountoutstanding,
160
                        old_amountoutstanding => $old_amountoutstanding,
160
                        new_amountoutstanding => $fine->amountoutstanding,
161
                        new_amountoutstanding => $fine->amountoutstanding,
Lines 173-179 sub pay { Link Here
173
        last unless $balance_remaining > 0;
174
        last unless $balance_remaining > 0;
174
    }
175
    }
175
176
176
    my $account_type = defined($sip) ? "Pay$sip" : 'Pay';
177
    my $account_type =
178
        $type eq 'writeoff' ? 'W'
179
      : defined($sip)       ? "Pay$sip"
180
      :                       'Pay';
181
182
    my $description = $type eq 'writeoff' ? 'Writeoff' : q{};
177
183
178
    my $payment = Koha::Account::Line->new(
184
    my $payment = Koha::Account::Line->new(
179
        {
185
        {
Lines 181-187 sub pay { Link Here
181
            accountno         => $accountno,
187
            accountno         => $accountno,
182
            date              => dt_from_string(),
188
            date              => dt_from_string(),
183
            amount            => 0 - $amount,
189
            amount            => 0 - $amount,
184
            description       => q{},
190
            description       => $description,
185
            accounttype       => $account_type,
191
            accounttype       => $account_type,
186
            amountoutstanding => 0 - $balance_remaining,
192
            amountoutstanding => 0 - $balance_remaining,
187
            manager_id        => $manager_id,
193
            manager_id        => $manager_id,
Lines 194-200 sub pay { Link Here
194
    UpdateStats(
200
    UpdateStats(
195
        {
201
        {
196
            branch         => $library_id,
202
            branch         => $library_id,
197
            type           => 'payment',
203
            type           => $type,
198
            amount         => $amount,
204
            amount         => $amount,
199
            borrowernumber => $self->{patron_id},
205
            borrowernumber => $self->{patron_id},
200
            accountno      => $accountno,
206
            accountno      => $accountno,
Lines 207-218 sub pay { Link Here
207
            $self->{patron_id},
213
            $self->{patron_id},
208
            Dumper(
214
            Dumper(
209
                {
215
                {
210
                    action            => 'create_payment',
216
                    action            => "create_$type",
211
                    borrowernumber    => $self->{patron_id},
217
                    borrowernumber    => $self->{patron_id},
212
                    accountno         => $accountno,
218
                    accountno         => $accountno,
213
                    amount            => 0 - $amount,
219
                    amount            => 0 - $amount,
214
                    amountoutstanding => 0 - $balance_remaining,
220
                    amountoutstanding => 0 - $balance_remaining,
215
                    accounttype       => 'Pay',
221
                    accounttype       => $account_type,
216
                    accountlines_paid => \@fines_paid,
222
                    accountlines_paid => \@fines_paid,
217
                    manager_id        => $manager_id,
223
                    manager_id        => $manager_id,
218
                }
224
                }
219
- 

Return to bug 17894