Bugzilla – Attachment 41612 Details for
Bug 14672
Payment is not able to done, when the patron has credit balance
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14672 - Payment is not able to done, when the patron has credit balance
Bug-14672---Payment-is-not-able-to-done-when-the-p.patch (text/plain), 6.10 KB, created by
Joonas Kylmälä
on 2015-08-18 15:14:12 UTC
(
hide
)
Description:
Bug 14672 - Payment is not able to done, when the patron has credit balance
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2015-08-18 15:14:12 UTC
Size:
6.10 KB
patch
obsolete
>From db44c6b939c196af2c8fa982a5b6bd6e8918b870 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <j.kylmala@gmail.com> >Date: Tue, 18 Aug 2015 09:25:33 +0000 >Subject: [PATCH] Bug 14672 - Payment is not able to done, when the patron has > credit balance > >Enables paying with credit, at least when using C4::Accounts::recordpayment >function. The code is still buggy and needs more work. > >Sponsored-by Vaara-kirjastot >--- > C4/Accounts.pm | 36 ++++++++++++++++++++++++------------ > C4/Members.pm | 17 ++++++++++++++--- > members/paycollect.pl | 8 ++++++-- > 3 files changed, 44 insertions(+), 17 deletions(-) > >diff --git a/C4/Accounts.pm b/C4/Accounts.pm >index d0709d0..a0cc181 100644 >--- a/C4/Accounts.pm >+++ b/C4/Accounts.pm >@@ -22,7 +22,7 @@ use strict; > #use warnings; FIXME - Bug 2505 > use C4::Context; > use C4::Stats; >-use C4::Members; >+use C4::Members qw(GetMemberAccountRecords); > use C4::Circulation qw(ReturnLostItem); > use C4::Log qw(logaction); > >@@ -107,21 +107,32 @@ sub recordpayment { > my $sth = $dbh->prepare( > "SELECT * FROM accountlines > WHERE (borrowernumber = ?) AND (amountoutstanding<>0) >- ORDER BY date" >+ ORDER BY accountlines_id" > ); > $sth->execute($borrowernumber); >+ >+ my ( $total, undef, undef, $original_credit ) = C4::Members::GetMemberAccountRecords( $borrowernumber ); >+ my $amount_to_pay = $total - $original_credit; >+ my $amount_paid = $amount_to_pay; >+ > > # offset transactions > my @ids; >- while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { >- if ( $accdata->{'amountoutstanding'} < $amountleft ) { >- $newamtos = 0; >- $amountleft -= $accdata->{'amountoutstanding'}; >+ while ( ( $accdata = $sth->fetchrow_hashref ) ) { >+ if ( $accdata->{'amountoutstanding'} < 0 ) { >+ if ( $amount_to_pay <= ( 0 - $accdata->{'amountoutstanding'} ) ) { >+ $newamtos = $accdata->{'amountoutstanding'} + $amount_to_pay; >+ $amount_to_pay = 0; >+ } >+ else { >+ $newamtos = 0; >+ $amount_to_pay += $accdata->{'amountoutstanding'}; >+ } > } > else { >- $newamtos = $accdata->{'amountoutstanding'} - $amountleft; >- $amountleft = 0; >+ $newamtos = 0; > } >+ > my $thisacct = $accdata->{accountlines_id}; > my $usth = $dbh->prepare( > "UPDATE accountlines SET amountoutstanding= ? >@@ -146,6 +157,7 @@ sub recordpayment { > } > } > >+ > # create new line > my $usth = $dbh->prepare( > "INSERT INTO accountlines >@@ -155,13 +167,13 @@ sub recordpayment { > > my $paytype = "Pay"; > $paytype .= $sip_paytype if defined $sip_paytype; >- $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note ); >+ $usth->execute( $borrowernumber, $nextaccntno, 0 - $amount_paid, $paytype, 0 - $amount_to_pay, $manager_id, $payment_note ); > $usth->finish; > > UpdateStats({ > branch => $branch, > type =>'payment', >- amount => $data, >+ amount => $amount_paid, > borrowernumber => $borrowernumber, > accountno => $nextaccntno } > ); >@@ -172,8 +184,8 @@ sub recordpayment { > action => 'create_payment', > borrowernumber => $borrowernumber, > accountno => $nextaccntno, >- amount => $data * -1, >- amountoutstanding => $amountleft * -1, >+ amount => $amount_paid * -1, >+ amountoutstanding => $amount_to_pay * -1, > accounttype => 'Pay', > accountlines_paid => \@ids, > manager_id => $manager_id, >diff --git a/C4/Members.pm b/C4/Members.pm >index 95fb4e7..c0345fe 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -1167,11 +1167,12 @@ sub GetMemberAccountRecords { > SELECT * > FROM accountlines > WHERE borrowernumber=?); >- $strsth.=" ORDER BY date desc,timestamp DESC"; >+ $strsth.=" ORDER BY accountlines_id DESC"; > my $sth= $dbh->prepare( $strsth ); > $sth->execute( $borrowernumber ); > > my $total = 0; >+ my $credit = 0; > while ( my $data = $sth->fetchrow_hashref ) { > if ( $data->{itemnumber} ) { > my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} ); >@@ -1180,10 +1181,20 @@ sub GetMemberAccountRecords { > } > $acctlines[$numlines] = $data; > $numlines++; >- $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors >+ >+ my $amountoustanding = \$data->{'amountoutstanding'}; >+ >+ $total += int(1000 * $$amountoustanding); # convert float to integer to avoid round-off errors >+ >+ if ( $$amountoustanding < 0 and $$amountoustanding != 0 and >+ $$amountoustanding <= $data->{'amount'} ) { >+ $credit += int(1000 * $$amountoustanding); >+ } >+ > } > $total /= 1000; >- return ( $total, \@acctlines,$numlines); >+ $credit /= 1000; >+ return ( $total, \@acctlines,$numlines, $credit); > } > > =head2 GetMemberAccountBalance >diff --git a/members/paycollect.pl b/members/paycollect.pl >index 35b9121..c6d7060 100755 >--- a/members/paycollect.pl >+++ b/members/paycollect.pl >@@ -51,7 +51,7 @@ my $user = $input->remote_user; > # get account details > my $branch = GetBranch( $input, GetBranches() ); > >-my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber); >+my ( $total_due, $accts, $numaccts, $credit ) = GetMemberAccountRecords($borrowernumber); > my $total_paid = $input->param('paid'); > > my $individual = $input->param('pay_individual'); >@@ -100,7 +100,11 @@ if ( $individual || $writeoff ) { > ); > } > >-if ( $total_paid and $total_paid ne '0.00' ) { >+if ( $total_due - $credit + $credit <= 0) { >+ $total_due = 0; >+} >+ >+if ( $total_paid ) { > if ( $total_paid < 0 or $total_paid > $total_due ) { > $template->param( > error_over => 1, >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14672
:
41446
|
41612
|
41647
|
47877