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

(-)a/C4/Accounts.pm (-12 / +24 lines)
Lines 22-28 use strict; Link Here
22
#use warnings; FIXME - Bug 2505
22
#use warnings; FIXME - Bug 2505
23
use C4::Context;
23
use C4::Context;
24
use C4::Stats;
24
use C4::Stats;
25
use C4::Members;
25
use C4::Members qw(GetMemberAccountRecords);
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
28
Lines 107-127 sub recordpayment { Link Here
107
    my $sth = $dbh->prepare(
107
    my $sth = $dbh->prepare(
108
        "SELECT * FROM accountlines
108
        "SELECT * FROM accountlines
109
  WHERE (borrowernumber = ?) AND (amountoutstanding<>0)
109
  WHERE (borrowernumber = ?) AND (amountoutstanding<>0)
110
  ORDER BY date"
110
  ORDER BY accountlines_id"
111
    );
111
    );
112
    $sth->execute($borrowernumber);
112
    $sth->execute($borrowernumber);
113
    
114
    my ( $total, undef, undef, $original_credit ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
115
    my $amount_to_pay = $total - $original_credit;
116
    my $amount_paid = $amount_to_pay;
117
113
118
114
    # offset transactions
119
    # offset transactions
115
    my @ids;
120
    my @ids;
116
    while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) {
121
    while ( ( $accdata = $sth->fetchrow_hashref ) ) {
117
        if ( $accdata->{'amountoutstanding'} < $amountleft ) {
122
        if ( $accdata->{'amountoutstanding'} < 0 ) {
118
            $newamtos = 0;
123
            if ( $amount_to_pay <= ( 0 - $accdata->{'amountoutstanding'} ) ) {
119
            $amountleft -= $accdata->{'amountoutstanding'};
124
                $newamtos = $accdata->{'amountoutstanding'} + $amount_to_pay;
125
                $amount_to_pay = 0;
126
            }
127
            else {
128
                $newamtos = 0;
129
                $amount_to_pay += $accdata->{'amountoutstanding'};
130
            }
120
        }
131
        }
121
        else {
132
        else {
122
            $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
133
            $newamtos = 0;
123
            $amountleft = 0;
124
        }
134
        }
135
125
        my $thisacct = $accdata->{accountlines_id};
136
        my $thisacct = $accdata->{accountlines_id};
126
        my $usth     = $dbh->prepare(
137
        my $usth     = $dbh->prepare(
127
            "UPDATE accountlines SET amountoutstanding= ?
138
            "UPDATE accountlines SET amountoutstanding= ?
Lines 146-151 sub recordpayment { Link Here
146
        }
157
        }
147
    }
158
    }
148
159
160
    
149
    # create new line
161
    # create new line
150
    my $usth = $dbh->prepare(
162
    my $usth = $dbh->prepare(
151
        "INSERT INTO accountlines
163
        "INSERT INTO accountlines
Lines 155-167 sub recordpayment { Link Here
155
167
156
    my $paytype = "Pay";
168
    my $paytype = "Pay";
157
    $paytype .= $sip_paytype if defined $sip_paytype;
169
    $paytype .= $sip_paytype if defined $sip_paytype;
158
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note );
170
    $usth->execute( $borrowernumber, $nextaccntno, 0 - $amount_paid, $paytype, 0, $manager_id, $payment_note );
159
    $usth->finish;
171
    $usth->finish;
160
172
161
    UpdateStats({
173
    UpdateStats({
162
                branch => $branch,
174
                branch => $branch,
163
                type =>'payment',
175
                type =>'payment',
164
                amount => $data,
176
                amount => $amount_paid,
165
                borrowernumber => $borrowernumber,
177
                borrowernumber => $borrowernumber,
166
                accountno => $nextaccntno }
178
                accountno => $nextaccntno }
167
    );
179
    );
Lines 172-179 sub recordpayment { Link Here
172
            action            => 'create_payment',
184
            action            => 'create_payment',
173
            borrowernumber    => $borrowernumber,
185
            borrowernumber    => $borrowernumber,
174
            accountno         => $nextaccntno,
186
            accountno         => $nextaccntno,
175
            amount            => $data * -1,
187
            amount            => $amount_paid * -1,
176
            amountoutstanding => $amountleft * -1,
188
            amountoutstanding => $amount_to_pay * -1,
177
            accounttype       => 'Pay',
189
            accounttype       => 'Pay',
178
            accountlines_paid => \@ids,
190
            accountlines_paid => \@ids,
179
            manager_id        => $manager_id,
191
            manager_id        => $manager_id,
(-)a/C4/Members.pm (-3 / +13 lines)
Lines 1167-1177 sub GetMemberAccountRecords { Link Here
1167
                        SELECT * 
1167
                        SELECT * 
1168
                        FROM accountlines 
1168
                        FROM accountlines 
1169
                        WHERE borrowernumber=?);
1169
                        WHERE borrowernumber=?);
1170
    $strsth.=" ORDER BY date desc,timestamp DESC";
1170
    $strsth.=" ORDER BY accountlines_id DESC";
1171
    my $sth= $dbh->prepare( $strsth );
1171
    my $sth= $dbh->prepare( $strsth );
1172
    $sth->execute( $borrowernumber );
1172
    $sth->execute( $borrowernumber );
1173
1173
1174
    my $total = 0;
1174
    my $total = 0;
1175
    my $credit = 0;
1175
    while ( my $data = $sth->fetchrow_hashref ) {
1176
    while ( my $data = $sth->fetchrow_hashref ) {
1176
        if ( $data->{itemnumber} ) {
1177
        if ( $data->{itemnumber} ) {
1177
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
1178
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
Lines 1180-1189 sub GetMemberAccountRecords { Link Here
1180
        }
1181
        }
1181
        $acctlines[$numlines] = $data;
1182
        $acctlines[$numlines] = $data;
1182
        $numlines++;
1183
        $numlines++;
1183
        $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
1184
        
1185
        my $amountoustanding = \$data->{'amountoutstanding'};
1186
        
1187
        $total += int(1000 * $$amountoustanding); # convert float to integer to avoid round-off errors
1188
        
1189
        if ( $$amountoustanding < 0 ) {
1190
                $credit += int(1000 * $$amountoustanding);
1191
        }
1192
        
1184
    }
1193
    }
1185
    $total /= 1000;
1194
    $total /= 1000;
1186
    return ( $total, \@acctlines,$numlines);
1195
    $credit /= 1000;
1196
    return ( $total, \@acctlines,$numlines, $credit);
1187
}
1197
}
1188
1198
1189
=head2 GetMemberAccountBalance
1199
=head2 GetMemberAccountBalance
(-)a/members/paycollect.pl (-3 / +6 lines)
Lines 51-57 my $user = $input->remote_user; Link Here
51
# get account details
51
# get account details
52
my $branch = GetBranch( $input, GetBranches() );
52
my $branch = GetBranch( $input, GetBranches() );
53
53
54
my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
54
my ( $total_due, $accts, $numaccts, $credit ) = GetMemberAccountRecords($borrowernumber);
55
my $total_paid = $input->param('paid');
55
my $total_paid = $input->param('paid');
56
56
57
my $individual   = $input->param('pay_individual');
57
my $individual   = $input->param('pay_individual');
Lines 100-106 if ( $individual || $writeoff ) { Link Here
100
    );
100
    );
101
}
101
}
102
102
103
if ( $total_paid and $total_paid ne '0.00' ) {
103
if ( $total_due - $credit + $credit <= 0) {
104
    $total_due = 0;
105
}
106
107
if ( $total_paid ) {
104
    if ( $total_paid < 0 or $total_paid > $total_due ) {
108
    if ( $total_paid < 0 or $total_paid > $total_due ) {
105
        $template->param(
109
        $template->param(
106
            error_over => 1,
110
            error_over => 1,
107
- 

Return to bug 14672