Bugzilla – Attachment 95303 Details for
Bug 22393
Remove last remaining manualinvoice use
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22393: Remove last remaining use of C4::Accounts::manualinvoice
Bug-22393-Remove-last-remaining-use-of-C4Accountsm.patch (text/plain), 13.52 KB, created by
Martin Renvoize (ashimema)
on 2019-11-12 12:39:58 UTC
(
hide
)
Description:
Bug 22393: Remove last remaining use of C4::Accounts::manualinvoice
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-11-12 12:39:58 UTC
Size:
13.52 KB
patch
obsolete
>From a20cf373a1d8ebf5d88e473abb71f02209424db7 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 12 Nov 2019 12:23:32 +0000 >Subject: [PATCH] Bug 22393: Remove last remaining use of > C4::Accounts::manualinvoice > >--- > .../prog/en/modules/members/maninvoice.tt | 105 +++++++------ > members/maninvoice.pl | 142 +++++++++++------- > 2 files changed, 149 insertions(+), 98 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >index 9713cfc27f..6d54bdcf33 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >@@ -24,51 +24,72 @@ > <div class="col-sm-10 col-sm-push-2"> > <main> > >- [% INCLUDE 'members-toolbar.inc' %] >+ [% INCLUDE 'members-toolbar.inc' %] >+ >+ <!-- The manual invoice and credit buttons --> >+ <div class="statictabs"> >+ <ul> >+ <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li> >+ <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li> >+ <li class="active"><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li> >+ <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li> >+ </ul> >+ <div class="tabs-container"> > >- <!-- The manual invoice and credit buttons --> >- <div class="statictabs"> >- <ul> >- <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li> >- <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li> >- <li class="active"><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li> >- <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li> >- </ul> >- <div class="tabs-container"> >+ [% IF error %] >+ <div class="dialog alert %]"> >+ An error ocurred when adding this manual invoice: >+ [% SWITCH error %] >+ [% CASE 'debit_type_code' %] >+ Debit type not found. >+ [% CASE 'itemnumber' %] >+ Item not found. >+ [% CASE 'register_id' %] >+ Cash register not found. >+ [% CASE '1' %] >+ An unhandled error occured, please check your logs >+ [% END %] >+ </div> >+ [% END %] > >- [% IF ( ERROR ) %] >- [% IF ( ITEMNUMBER ) %] >- ERROR an invalid itemnumber was entered, please hit back and try again >- [% END %] >- [% ELSE %] >- <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" /> >- <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" /> >- <fieldset class="rows"> >- <legend>Manual invoice</legend> >- <ol> >- <li> >- <label for="type">Type: </label> >- <select name="type" id="type"> >- [% FOREACH debit_type IN debit_types %] >- <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option> >- [% END %] >- </select> >- </li> >- <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li> >- <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li> >- <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li> >- <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li> >- </ol> >- </fieldset> >- <fieldset class="action"> >- <input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a> >- </fieldset> >- </form> >- >- [% END %] >+ <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" /> >+ <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" /> >+ <fieldset class="rows"> >+ <legend>Manual invoice</legend> >+ <ol> >+ <li> >+ <label for="type">Type: </label> >+ <select name="type" id="type"> >+ [% FOREACH debit_type IN debit_types %] >+ <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option> >+ [% END %] >+ </select> >+ </li> >+ <li> >+ <label for="barcode">Barcode: </label> >+ <input type="text" name="barcode" id="barcode" /> >+ </li> >+ <li> >+ <label for="desc">Description: </label> >+ <input type="text" name="desc" id="desc" size="50" /> >+ </li> >+ <li> >+ <label for="note">Note: </label> >+ <input type="text" name="note" size="50" id="note" /> >+ </li> >+ <li> >+ <label for="amount">Amount: </label> >+ <input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00 >+ </li> >+ </ol> >+ </fieldset> >+ >+ <fieldset class="action"> >+ <input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a> >+ </fieldset> >+ </form> >+ </div> > </div> >- </div> >- > </main> > </div> <!-- /.col-sm-10.col-sm-push-2 --> > >diff --git a/members/maninvoice.pl b/members/maninvoice.pl >index a54206fb74..7299eb8575 100755 >--- a/members/maninvoice.pl >+++ b/members/maninvoice.pl >@@ -23,6 +23,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use Try::Tiny; > > use C4::Auth; > use C4::Output; >@@ -60,6 +61,17 @@ unless ($patron) { > exit; > } > >+my $logged_in_user = Koha::Patrons->find($loggedinuser); >+output_and_exit_if_error( >+ $input, $cookie, >+ $template, >+ { >+ module => 'members', >+ logged_in_user => $logged_in_user, >+ current_patron => $patron >+ } >+); >+ > my $library_id = C4::Context->userenv->{'branch'}; > > my $add = $input->param('add'); >@@ -72,69 +84,87 @@ if ($add) { > } > ); > >-# Note: If the logged in user is not allowed to see this patron an invoice can be forced >-# Here we are trusting librarians not to hack the system >+ # Note: If the logged in user is not allowed to see this patron an invoice can be forced >+ # Here we are trusting librarians not to hack the system >+ my $desc = $input->param('desc'); >+ my $amount = $input->param('amount'); >+ my $note = $input->param('note'); >+ my $debit_type = $input->param('type'); >+ >+ # If LOST try to match barcode to Item and then try to match Item + Borrower to an Issue. >+ my $failed; >+ my $item_id; > my $barcode = $input->param('barcode'); >- my $itemnum; > if ($barcode) { > my $item = Koha::Items->find( { barcode => $barcode } ); >- $itemnum = $item->itemnumber if $item; >- } >- my $desc = $input->param('desc'); >- my $amount = $input->param('amount'); >- my $type = $input->param('type'); >- my $note = $input->param('note'); >- my $error = >- C4::Accounts::manualinvoice( $borrowernumber, $itemnum, $desc, $type, >- $amount, $note ); >- if ($error) { >- if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) { >- $template->param( 'ITEMNUMBER' => 1 ); >+ if ($item) { >+ $item_id = $item->itemnumber; > } >- $template->param( >- csrf_token => Koha::Token->new->generate_csrf( >- { session_id => scalar $input->cookie('CGISESSID') } >- ) >- ); >- $template->param( 'ERROR' => $error ); >- output_html_with_http_headers $input, $cookie, $template->output; >+ else { >+ $template->param( error => 'itemnumber' ); >+ $failed = 1; >+ } >+ } >+ my $issue_id; >+ if ( $debit_type eq 'LOST' && $item_id ) { >+ my $checkouts = Koha::Checkouts->search( >+ { itemnumber => $item_id, borrowernumber => $borrowernumber } ); >+ my $checkout = >+ $checkouts->count >+ ? $checkouts->next >+ : Koha::Old::Checkouts->search( >+ { itemnumber => $item_id, borrowernumber => $borrowernumber }, >+ { order_by => { -desc => 'returndate' }, rows => 1 } >+ )->next; >+ $issue_id = $checkout ? $checkout->issue_id : undef; > } >- else { > >- if ( C4::Context->preference('AccountAutoReconcile') ) { >- $patron->account->reconcile_balance; >+ unless ($failed) { >+ try { >+ $patron->account->add_debit( >+ { >+ amount => $amount, >+ description => $desc, >+ note => $note, >+ user_id => $logged_in_user->borrowernumber, >+ interface => 'intranet', >+ library_id => $library_id, >+ type => $debit_type, >+ item_id => $item_id, >+ issue_id => $issue_id >+ } >+ ); >+ >+ if ( C4::Context->preference('AccountAutoReconcile') ) { >+ $patron->account->reconcile_balance; >+ } >+ >+ print $input->redirect( >+ "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" >+ ); >+ exit; >+ } >+ catch { >+ my $error = $_; >+ if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { >+ $template->param( error => $error->broken_fk ); >+ } else { >+ $template->param( error => '1' ); >+ } > } >- >- print $input->redirect( >- "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" >- ); >- exit; > } > } >-else { > >- my $logged_in_user = Koha::Patrons->find($loggedinuser) >- or die "Not logged in"; >- output_and_exit_if_error( >- $input, $cookie, >- $template, >- { >- module => 'members', >- logged_in_user => $logged_in_user, >- current_patron => $patron >- } >- ); >- >- my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( >- { can_be_added_manually => 1, archived => 0 }, >- {}, $library_id ); >- $template->param( debit_types => \@debit_types ); >- $template->param( >- csrf_token => Koha::Token->new->generate_csrf( >- { session_id => scalar $input->cookie('CGISESSID') } >- ), >- patron => $patron, >- finesview => 1, >- ); >- output_html_with_http_headers $input, $cookie, $template->output; >-} >+my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( >+ { can_be_added_manually => 1, archived => 0 }, >+ {}, $library_id ); >+ >+$template->param( >+ debit_types => \@debit_types, >+ csrf_token => Koha::Token->new->generate_csrf( >+ { session_id => scalar $input->cookie('CGISESSID') } >+ ), >+ patron => $patron, >+ finesview => 1, >+); >+output_html_with_http_headers $input, $cookie, $template->output; >-- >2.20.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 22393
:
85516
|
95298
|
95303
|
95308
|
95309
|
95325
|
95326
|
98662
|
98663
|
103336
|
103382
|
103897
|
103898
|
106773
|
108330
|
108331
|
108332