Bugzilla – Attachment 67313 Details for
Bug 16820
Add possibility to edit fines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16820 - Edit accountlines from borrower's profile
Bug-16820---Edit-accountlines-from-borrowers-profi.patch (text/plain), 18.26 KB, created by
David Bourgault
on 2017-09-22 14:29:49 UTC
(
hide
)
Description:
Bug 16820 - Edit accountlines from borrower's profile
Filename:
MIME Type:
Creator:
David Bourgault
Created:
2017-09-22 14:29:49 UTC
Size:
18.26 KB
patch
obsolete
>From f5aebaed66f2f367b10fd8845dbc232cd3e03fe1 Mon Sep 17 00:00:00 2001 >From: David Bourgault <david.bourgault@inlibro.com> >Date: Fri, 22 Sep 2017 10:22:42 -0400 >Subject: [PATCH] Bug 16820 - Edit accountlines from borrower's profile > >Adds the option to edit an accountline from a borrower's profile page in the intranet. > >Test plan : >0) Try to edit an accountline, you can't >1) Apply patch >2) Try to edit an accountline, you can > >Also solves Bug 2193 >--- > C4/Accounts.pm | 183 +++++++++++++++++++++ > .../prog/en/modules/members/boraccount.tt | 61 +++++++ > members/boraccount.pl | 100 +++++++++++ > 3 files changed, 344 insertions(+) > >diff --git a/C4/Accounts.pm b/C4/Accounts.pm >index 0a1e779..a197911 100644 >--- a/C4/Accounts.pm >+++ b/C4/Accounts.pm >@@ -45,6 +45,7 @@ BEGIN { > &chargelostitem > &ReversePayment > &purge_zero_balance_fees >+ &updatepayment > ); > } > >@@ -379,9 +380,191 @@ sub purge_zero_balance_fees { > $sth->execute($days) or die $dbh->errstr; > } > >+sub updatepayment { >+ my ( $borrowernumber, $account_id, $date, $itemnum, $desc, $type, $amount, $oldamount, $note ) = @_; >+ my $manager_id = 0; >+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ my $dbh = C4::Context->dbh; >+ my $notifyid = 0; >+ my $amountleft = $amount; >+ >+ if ( ( $type eq 'L' ) >+ or ( $type eq 'F' ) >+ or ( $type eq 'A' ) >+ or ( $type eq 'N' ) >+ or ( $type eq 'M' ) ) >+ { >+ $notifyid = 1; >+ } >+ >+ if ( $type eq 'Pay' ) { >+ $amountleft = 0.0; >+ my $amontdif = $amount - $oldamount; >+ >+ if ( $amontdif <= 0 ) { >+ my $debtamount = abs($amontdif); >+ $amountleft = addfinetoaccountlines( $borrowernumber, $debtamount ); >+ >+ } >+ else { >+ $amountleft = reducefinefromaccountlines( $borrowernumber, $amontdif ); >+ } >+ $amount = -$amount; >+ } >+ >+ my $sth = $dbh->prepare( >+ 'UPDATE accountlines >+ SET date=?, amount=?, description=?, accounttype=?, amountoutstanding=?, >+ itemnumber=?,notify_id=?, note=?, manager_id=? >+ WHERE accountlines_id=?' >+ ); >+ $sth->execute( $date, $amount, $desc, $type, $amountleft, $itemnum, $notifyid, $note, $manager_id, $account_id ) || return $sth->errstr; >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ logaction( >+ "FINES", 'MODIFY', >+ $borrowernumber, >+ Dumper( >+ { accountno => $account_id, >+ amount => $amount, >+ description => $desc, >+ accounttype => $type, >+ amountoutstanding => $amountleft, >+ notify_id => $notifyid, >+ note => $note, >+ itemnumber => $itemnum, >+ manager_id => $manager_id, >+ } >+ ) >+ ); >+ } >+ return 0; >+} >+ >+sub addfinetoaccountlines { >+ >+ #here we update the account lines >+ my ( $borrowernumber, $debtamount ) = @_; >+ my $newamtos = 0; >+ my $dbh = C4::Context->dbh; >+ my $accdata = ""; >+ >+ # get lines with outstanding amounts to offset >+ my $sth = $dbh->prepare( >+ "SELECT * FROM accountlines >+ WHERE (borrowernumber = ?) AND (amountoutstanding<>amount) and (amountoutstanding>=0) and (accounttype <> 'Pay') >+ ORDER BY date" >+ ); >+ $sth->execute($borrowernumber); >+ my @ids; >+ >+ # offset transactions >+ while ( ( $accdata = $sth->fetchrow_hashref ) and ( $debtamount > 0 ) ) { >+ if ( $accdata->{'amount'} - $accdata->{'amountoutstanding'} < $debtamount ) { >+ $debtamount = $debtamount - ( $accdata->{'amount'} - $accdata->{'amountoutstanding'} ); >+ $newamtos = $accdata->{'amount'}; >+ } >+ else { >+ $newamtos = $accdata->{'amountoutstanding'} + $debtamount; >+ $debtamount = 0; >+ } >+ my $thisacct = $accdata->{accountlines_id}; >+ my $usth = $dbh->prepare( >+ "UPDATE accountlines SET amountoutstanding= ? >+ WHERE (accountlines_id = ?)" >+ ); >+ $usth->execute( $newamtos, $thisacct ); >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ my $manager_id = 0; >+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ $accdata->{'amountoutstanding_new'} = $newamtos; >+ logaction( >+ "FINES", 'MODIFY', >+ $borrowernumber, >+ Dumper( >+ { action => 'fee_payment', >+ borrowernumber => $accdata->{'borrowernumber'}, >+ old_amountoutstanding => $accdata->{'amountoutstanding'}, >+ new_amountoutstanding => $newamtos, >+ amount_paid => $accdata->{'amountoutstanding'} - $newamtos, >+ accountlines_id => $accdata->{'accountlines_id'}, >+ accountno => $accdata->{'accountno'}, >+ manager_id => $manager_id, >+ } >+ ) >+ ); >+ push( @ids, $accdata->{'accountlines_id'} ); >+ } >+ } >+ return $debtamount; >+} >+ >+sub reducefinefromaccountlines { >+ >+ #here we update the account lines >+ my ( $borrowernumber, $amountpayed ) = @_; >+ my $amountleft = $amountpayed; >+ my $newamtos = 0; >+ my $dbh = C4::Context->dbh; >+ my $accdata = ""; >+ >+ # get lines with outstanding amounts to offset >+ my $sth = $dbh->prepare( >+ "SELECT * FROM accountlines >+ WHERE (borrowernumber = ?) AND (amountoutstanding<>0) >+ ORDER BY date" >+ ); >+ $sth->execute($borrowernumber); >+ my @ids; >+ >+ # offset transactions >+ while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { >+ if ( $accdata->{'amountoutstanding'} < $amountleft ) { >+ $newamtos = 0; >+ $amountleft -= $accdata->{'amountoutstanding'}; >+ } >+ else { >+ $newamtos = $accdata->{'amountoutstanding'} - $amountleft; >+ $amountleft = 0; >+ } >+ my $thisacct = $accdata->{accountlines_id}; >+ my $usth = $dbh->prepare( >+ "UPDATE accountlines SET amountoutstanding= ? >+ WHERE (accountlines_id = ?)" >+ ); >+ $usth->execute( $newamtos, $thisacct ); >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ my $manager_id = 0; >+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ $accdata->{'amountoutstanding_new'} = $newamtos; >+ logaction( >+ "FINES", 'MODIFY', >+ $borrowernumber, >+ Dumper( >+ { action => 'fee_payment', >+ borrowernumber => $accdata->{'borrowernumber'}, >+ old_amountoutstanding => $accdata->{'amountoutstanding'}, >+ new_amountoutstanding => $newamtos, >+ amount_paid => $accdata->{'amountoutstanding'} - $newamtos, >+ accountlines_id => $accdata->{'accountlines_id'}, >+ accountno => $accdata->{'accountno'}, >+ manager_id => $manager_id, >+ } >+ ) >+ ); >+ push( @ids, $accdata->{'accountlines_id'} ); >+ } >+ } >+ return $amountleft; >+} >+ >+ > END { } # module clean-up code here (global destructor) > > 1; >+ > __END__ > > =head1 SEE ALSO >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >index ec79237..dba1905 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >@@ -61,6 +61,65 @@ $(document).ready(function() { > <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li> > </ul> > <div class="tabs-container"> >+ [% IF (edit) %] >+ [% IF ( ERROR ) %] >+ ERROR an invalid itemnumber was entered, please hit back and try again >+ [% ELSE %] >+ [% IF ( error_over ) %] >+ <div id="error_message" class="dialog alert"> >+ The amount value must be less than or equal to [% total_due | format('%.2f') %]. >+ </div> >+ [% END %] >+ <form action="/cgi-bin/koha/members/boraccount.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" /> >+ <fieldset class="rows"> >+ <legend>Edit</legend> >+ <ol> >+ <li><label for="date">Date: </label><input type="text" name="date" id="date" value="[% (accdate) %]"/></li> >+ <li> >+ <!--<script type="text/javascript"> >+ var type_fees = new Array(); >+ type_fees['L'] = ''; >+ type_fees['F'] = ''; >+ type_fees['A'] = ''; >+ type_fees['N'] = ''; >+ type_fees['M'] = ''; >+ [% FOREACH invoice_types_loo IN invoice_types_loop %] >+ type_fees['[% invoice_types_loo.authorised_value %]'] = "[% invoice_types_loo.lib %]"; >+ [% END %] >+ </script>--> >+ <label for="type">Type: </label> >+ <select name="type" id="type"> >+ <option value="L" [% IF (acctype == 'L')%] selected="selected" [% END %]>Lost item</option> >+ <option value="F" [% IF (acctype == 'F')%] selected="selected" [% END %]>Fine</option> >+ <option value="A" [% IF (acctype == 'A')%] selected="selected" [% END %]>Account management fee</option> >+ <option value="N" [% IF (acctype == 'N')%] selected="selected" [% END %]>New card</option> >+ <option value="M" [% IF (acctype == 'M')%] selected="selected" [% END %]>Sundry</option> >+ <option value="C" [% IF (acctype == 'C')%] selected="selected" [% END %]>Credit</option> >+ <option value="FOR" [% IF (acctype == 'FOR' or acctype == 'FFOR')%] selected="selected" [% END %]>Forgiven</option> >+ <option value="copiers" [% IF (acctype == 'copiers')%] selected="selected" [% END %]>copiers fee</option> >+ <option value="FU" [% IF (acctype == 'FU')%] selected="selected" [% END %]>Fine Unpaid</option> >+ <option value="LR" [% IF (acctype == 'LR')%] selected="selected" [% END %]>Lost and returned</option> >+ <option value="O" [% IF (acctype == 'O')%] selected="selected" [% END %]>Overdue</option> >+ <option value="Pay" [% IF (acctype == 'Pay')%] selected="selected" [% END %]>Payment</option> >+ <option value="CR" [% IF (acctype == 'CR')%] selected="selected" [% END %]>Refund</option> >+ <option value="Rent" [% IF (acctype == 'Rent')%] selected="selected" [% END %]>Rental fee</option> >+ <option value="W" [% IF (acctype == 'W')%] selected="selected" [% END %]>Writeoff</option> >+ [% FOREACH invoice_type IN invoice_types_loop %] >+ <option value="[% invoice_type.authorised_value %]">[% invoice_type.authorised_value %]</option> >+ [% END %] >+ </select> >+ </li> >+ <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" value="[% accbarcode %]"/></li> >+ <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" value="[% (accdescription) %]"/></li> >+ <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% accnote %]"/></li> >+ <li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" value="[% accamount %]"/> Example: 5.00</li> >+ <input type="hidden" name="accountlines_id" value="[% accid %]"/> >+ <input type="hidden" name="accountoldamount" value="[% accamount %]"/> >+ </ol></fieldset> >+ <fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset> >+ </form> >+ [% END %] >+ [% ELSE %] > <!-- The table with the account items --> > <table id="table_account_fines"> > <thead> >@@ -112,6 +171,7 @@ $(document).ready(function() { > [% IF ( account.amountcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amount | $Price %]</td> > [% IF ( account.amountoutstandingcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td> > <td class="actions"> >+ <a href="boraccount.pl?action=edit&accountlines_id=[% account.accountlines_id %]&borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-edit"></i> Edit</a> > [% IF ( account.payment ) %] > <a target="_blank" href="printfeercpt.pl?action=print&accountlines_id=[% account.accountlines_id %]&borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print</a> > [% ELSE %] >@@ -140,6 +200,7 @@ $(document).ready(function() { > </tr> > </tfoot> > </table> >+[% END %] > </div></div> > > </div> >diff --git a/members/boraccount.pl b/members/boraccount.pl >index e7d769e..be8e7c6 100755 >--- a/members/boraccount.pl >+++ b/members/boraccount.pl >@@ -31,11 +31,14 @@ use CGI qw ( -utf8 ); > use C4::Members; > use C4::Accounts; > use C4::Members::Attributes qw(GetBorrowerAttributes); >+use C4::Items; > use Koha::Patrons; > use Koha::Patron::Categories; > > my $input=new CGI; > >+my $borrowernumber=$input->param('borrowernumber'); >+my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber); > > my ($template, $loggedinuser, $cookie) = get_template_and_user( > { >@@ -62,6 +65,103 @@ unless ( $patron ) { > if ( $action eq 'reverse' ) { > ReversePayment( scalar $input->param('accountlines_id') ); > } >+elsif ( $input->param('add') or $action eq 'edit' ) { >+ my $borrowernumber = $input->param('borrowernumber'); >+ >+ #get account details >+ my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber); >+ if ( $input->param('add') ) { >+ my $total_due = $total; >+ my $barcode = $input->param('barcode'); >+ my $itemnum; >+ if ($barcode) { >+ $itemnum = GetItemnumberFromBarcode($barcode); >+ } >+ my $desc = $input->param('desc'); >+ my $amount = $input->param('amount'); >+ my $oldamount = $input->param('accountoldamount'); >+ my $type = $input->param('type'); >+ my $note = $input->param('note'); >+ >+ if ( $type eq "Pay" ) { >+ if ( $amount <= $total_due + $oldamount or $amount < 0 ) { >+ my $error = updatepayment( $borrowernumber, $input->param('accountlines_id'), $input->param('date'), $itemnum, $desc, $type, $amount, $oldamount, $note ); >+ if ($error) { >+ $template->param( 'ERROR' => $error ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; >+ } >+ else { >+ print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); >+ exit; >+ } >+ } >+ else { >+ $template->param( >+ error_over => 1, >+ total_due => $total_due + $oldamount >+ ); >+ } >+ } >+ else { >+ if ( $type eq "C" or $type eq "FOR" ) { >+ $amount = -abs($amount); >+ } >+ my $error = updatepayment( $borrowernumber, $input->param('accountlines_id'), $input->param('date'), $itemnum, $desc, $type, $amount, $oldamount, $note ); >+ if ($error) { >+ $template->param( 'ERROR' => $error ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; >+ } >+ else { >+ print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); >+ exit; >+ } >+ } >+ } >+ my $data = $patron; >+ my $accountlines_id = $input->param('accountlines_id'); >+ >+ #get authorised values with type of MANUAL_INV >+ my @invoice_types; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare('SELECT * FROM authorised_values WHERE category = "MANUAL_INV"'); >+ $sth->execute(); >+ while ( my $row = $sth->fetchrow_hashref() ) { >+ push @invoice_types, $row; >+ } >+ $template->param( invoice_types_loop => \@invoice_types ); >+ >+ if ( $data->{'category_type'} eq 'C' ) { >+ my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >+ my $cnt = scalar(@$catcodes); >+ $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1; >+ $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1; >+ } >+ >+ for ( my $i = 0; $i < $numaccts; $i++ ) { >+ next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id ); >+ my $barcode; >+ if ( $accts->[$i]{'itemnumber'} ) { >+ $barcode = GetBarcodeFromItemnumber( $accts->[$i]{'itemnumber'} ); >+ } >+ my $amount = sprintf '%.2f', $accts->[$i]{'amount'}; >+ if ( $accts->[$i]{'accounttype'} eq "Pay" or $accts->[$i]{'accounttype'} eq "C" or $accts->[$i]{'accounttype'} eq "FOR" ) { >+ $amount = abs($amount); >+ } >+ $template->param( >+ accbarcode => $barcode, >+ accdate => $accts->[$i]{'date'}, >+ accdescription => $accts->[$i]{'description'}, >+ accnote => $accts->[$i]{'note'}, >+ acctype => $accts->[$i]{'accounttype'}, >+ accamount => $amount, >+ accid => $accountlines_id, >+ ); >+ } >+ >+ $template->param( edit => 1, ); >+} > > if ( $patron->category->category_type eq 'C') { > my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >-- >2.7.4
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 16820
:
67313
|
67585