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

(-)a/C4/Accounts.pm (-81 / +20 lines)
Lines 88-95 was made. Link Here
88
sub makepayment {
88
sub makepayment {
89
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
89
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
90
90
91
    my $line = Koha::Account::Lines->find( $accountlines_id );
92
91
    return Koha::Account->new( { patron_id => $borrowernumber } )
93
    return Koha::Account->new( { patron_id => $borrowernumber } )
92
      ->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } );
94
      ->pay( { lines => [ $line ], amount => $amount, library_id => $branch, note => $payment_note } );
93
}
95
}
94
96
95
=head2 getnextacctno
97
=head2 getnextacctno
Lines 396-484 will be credited to the next one. Link Here
396
sub recordpayment_selectaccts {
398
sub recordpayment_selectaccts {
397
    my ( $borrowernumber, $amount, $accts, $note ) = @_;
399
    my ( $borrowernumber, $amount, $accts, $note ) = @_;
398
400
399
    my $dbh        = C4::Context->dbh;
401
    my @lines = Koha::Account::Lines->search(
400
    my $newamtos   = 0;
402
        {
401
    my $accdata    = q{};
403
            borrowernumber    => $borrowernumber,
402
    my $branch     = C4::Context->userenv->{branch};
404
            amountoutstanding => { '<>' => 0 },
403
    my $amountleft = $amount;
405
            accountno         => { 'IN' => $accts },
404
    my $manager_id = 0;
406
        },
405
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
407
        { order_by => 'date' }
406
    my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' .
408
    );
407
    'AND (amountoutstanding<>0) ';
408
    if (@{$accts} ) {
409
        $sql .= ' AND accountlines_id IN ( ' .  join ',', @{$accts};
410
        $sql .= ' ) ';
411
    }
412
    $sql .= ' ORDER BY date';
413
    # begin transaction
414
    my $nextaccntno = getnextacctno($borrowernumber);
415
416
    # get lines with outstanding amounts to offset
417
    my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber);
418
419
    # offset transactions
420
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
421
        'WHERE accountlines_id=?');
422
409
423
    my @ids;
410
    return Koha::Account->new(
424
    for my $accdata ( @{$rows} ) {
411
        {
425
        if ($amountleft == 0) {
412
            patron_id => $borrowernumber,
426
            last;
427
        }
428
        if ( $accdata->{amountoutstanding} < $amountleft ) {
429
            $newamtos = 0;
430
            $amountleft -= $accdata->{amountoutstanding};
431
        }
413
        }
432
        else {
414
      )->pay(
433
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
415
        {
434
            $amountleft = 0;
416
            amount => $amount,
417
            lines  => \@lines,
418
            note   => $note
435
        }
419
        }
436
        my $thisacct = $accdata->{accountlines_id};
420
      );
437
        $sth->execute( $newamtos, $thisacct );
438
439
        if ( C4::Context->preference("FinesLog") ) {
440
            logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
441
                action                => 'fee_payment',
442
                borrowernumber        => $borrowernumber,
443
                old_amountoutstanding => $accdata->{'amountoutstanding'},
444
                new_amountoutstanding => $newamtos,
445
                amount_paid           => $accdata->{'amountoutstanding'} - $newamtos,
446
                accountlines_id       => $accdata->{'accountlines_id'},
447
                accountno             => $accdata->{'accountno'},
448
                manager_id            => $manager_id,
449
            }));
450
            push( @ids, $accdata->{'accountlines_id'} );
451
        }
452
453
    }
454
455
    # create new line
456
    $sql = 'INSERT INTO accountlines ' .
457
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
458
    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
459
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
460
    UpdateStats({
461
                branch => $branch,
462
                type => 'payment',
463
                amount => $amount,
464
                borrowernumber => $borrowernumber,
465
                accountno => $nextaccntno}
466
    );
467
468
    if ( C4::Context->preference("FinesLog") ) {
469
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
470
            action            => 'create_payment',
471
            borrowernumber    => $borrowernumber,
472
            accountno         => $nextaccntno,
473
            amount            => 0 - $amount,
474
            amountoutstanding => 0 - $amountleft,
475
            accounttype       => 'Pay',
476
            accountlines_paid => \@ids,
477
            manager_id        => $manager_id,
478
        }));
479
    }
480
481
    return;
482
}
421
}
483
422
484
# makepayment needs to be fixed to handle partials till then this separate subroutine
423
# 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
        accountlines_id => $accountlines_id,
55
        accountlines_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