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

(-)a/C4/Accounts.pm (-81 / +20 lines)
Lines 118-125 was made. Link Here
118
sub makepayment {
118
sub makepayment {
119
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
119
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
120
120
121
    my $line = Koha::Account::Lines->find( $accountlines_id );
122
121
    return Koha::Account->new( { patron_id => $borrowernumber } )
123
    return Koha::Account->new( { patron_id => $borrowernumber } )
122
      ->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } );
124
      ->pay( { lines => [ $line ], amount => $amount, library_id => $branch, note => $payment_note } );
123
}
125
}
124
126
125
=head2 getnextacctno
127
=head2 getnextacctno
Lines 426-514 will be credited to the next one. Link Here
426
sub recordpayment_selectaccts {
428
sub recordpayment_selectaccts {
427
    my ( $borrowernumber, $amount, $accts, $note ) = @_;
429
    my ( $borrowernumber, $amount, $accts, $note ) = @_;
428
430
429
    my $dbh        = C4::Context->dbh;
431
    my @lines = Koha::Account::Lines->search(
430
    my $newamtos   = 0;
432
        {
431
    my $accdata    = q{};
433
            borrowernumber    => $borrowernumber,
432
    my $branch     = C4::Context->userenv->{branch};
434
            amountoutstanding => { '<>' => 0 },
433
    my $amountleft = $amount;
435
            accountno         => { 'IN' => $accts },
434
    my $manager_id = 0;
436
        },
435
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
437
        { order_by => 'date' }
436
    my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' .
438
    );
437
    'AND (amountoutstanding<>0) ';
438
    if (@{$accts} ) {
439
        $sql .= ' AND accountno IN ( ' .  join ',', @{$accts};
440
        $sql .= ' ) ';
441
    }
442
    $sql .= ' ORDER BY date';
443
    # begin transaction
444
    my $nextaccntno = getnextacctno($borrowernumber);
445
446
    # get lines with outstanding amounts to offset
447
    my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber);
448
449
    # offset transactions
450
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
451
        'WHERE accountlines_id=?');
452
439
453
    my @ids;
440
    return Koha::Account->new(
454
    for my $accdata ( @{$rows} ) {
441
        {
455
        if ($amountleft == 0) {
442
            patron_id => $borrowernumber,
456
            last;
457
        }
458
        if ( $accdata->{amountoutstanding} < $amountleft ) {
459
            $newamtos = 0;
460
            $amountleft -= $accdata->{amountoutstanding};
461
        }
443
        }
462
        else {
444
      )->pay(
463
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
445
        {
464
            $amountleft = 0;
446
            amount => $amount,
447
            lines  => \@lines,
448
            note   => $note
465
        }
449
        }
466
        my $thisacct = $accdata->{accountlines_id};
450
      );
467
        $sth->execute( $newamtos, $thisacct );
468
469
        if ( C4::Context->preference("FinesLog") ) {
470
            logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
471
                action                => 'fee_payment',
472
                borrowernumber        => $borrowernumber,
473
                old_amountoutstanding => $accdata->{'amountoutstanding'},
474
                new_amountoutstanding => $newamtos,
475
                amount_paid           => $accdata->{'amountoutstanding'} - $newamtos,
476
                accountlines_id       => $accdata->{'accountlines_id'},
477
                accountno             => $accdata->{'accountno'},
478
                manager_id            => $manager_id,
479
            }));
480
            push( @ids, $accdata->{'accountlines_id'} );
481
        }
482
483
    }
484
485
    # create new line
486
    $sql = 'INSERT INTO accountlines ' .
487
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
488
    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
489
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
490
    UpdateStats({
491
                branch => $branch,
492
                type => 'payment',
493
                amount => $amount,
494
                borrowernumber => $borrowernumber,
495
                accountno => $nextaccntno}
496
    );
497
498
    if ( C4::Context->preference("FinesLog") ) {
499
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
500
            action            => 'create_payment',
501
            borrowernumber    => $borrowernumber,
502
            accountno         => $nextaccntno,
503
            amount            => 0 - $amount,
504
            amountoutstanding => 0 - $amountleft,
505
            accounttype       => 'Pay',
506
            accountlines_paid => \@ids,
507
            manager_id        => $manager_id,
508
        }));
509
    }
510
511
    return;
512
}
451
}
513
452
514
# makepayment needs to be fixed to handle partials till then this separate subroutine
453
# makepayment needs to be fixed to handle partials till then this separate subroutine
(-)a/Koha/Account.pm (-5 / +3 lines)
Lines 54-59 Koha::Account->new( { patron_id => $borrowernumber } )->pay( Link Here
54
        note       => $note,
54
        note       => $note,
55
        id         => $accountlines_id,
55
        id         => $accountlines_id,
56
        library_id => $branchcode,
56
        library_id => $branchcode,
57
        lines      => $lines, # Arrayref of Koha::Account::Line objects to pay
57
    }
58
    }
58
);
59
);
59
60
Lines 65-72 sub pay { Link Here
65
    my $amount          = $params->{amount};
66
    my $amount          = $params->{amount};
66
    my $sip             = $params->{sip};
67
    my $sip             = $params->{sip};
67
    my $note            = $params->{note} || q{};
68
    my $note            = $params->{note} || q{};
68
    my $accountlines_id = $params->{accountlines_id};
69
    my $library_id      = $params->{library_id};
69
    my $library_id      = $params->{library_id};
70
    my $lines           = $params->{lines},
70
71
71
    my $userenv = C4::Context->userenv;
72
    my $userenv = C4::Context->userenv;
72
73
Lines 89-97 sub pay { Link Here
89
    $balance_remaining ||= 0;
90
    $balance_remaining ||= 0;
90
91
91
    # We were passed a specific line to pay
92
    # We were passed a specific line to pay
92
    if ( $accountlines_id ) {
93
    foreach my $fine ( @$lines ) {
93
        my $fine = Koha::Account::Lines->find( $accountlines_id );
94
95
        # If accountline id is passed but no amount, we pay that line in full
94
        # If accountline id is passed but no amount, we pay that line in full
96
        $amount = $fine->amountoutstanding unless defined($amount);
95
        $amount = $fine->amountoutstanding unless defined($amount);
97
96
98
- 

Return to bug 15897