Bugzilla – Attachment 16373 Details for
Bug 7162
Factorize code for order cancellation and add field for giving a reason
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7162: Factorize code for order cancellation
Bug-7162-Factorize-code-for-order-cancellation.patch (text/plain), 15.29 KB, created by
Julian Maurice
on 2013-03-19 12:10:31 UTC
(
hide
)
Description:
Bug 7162: Factorize code for order cancellation
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2013-03-19 12:10:31 UTC
Size:
15.29 KB
patch
obsolete
>From a985d23d4bd735aabe4cd69d7e7fc8a8cc0aaf2a Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Sat, 5 Nov 2011 12:29:25 +0530 >Subject: [PATCH] Bug 7162: Factorize code for order cancellation > >Some code was duplicated, all is now in cancelorder.pl >Added possibility to provide a reason for cancellation (or other things, >this is saved in aqorders.notes) >--- > C4/Acquisition.pm | 47 ++++++++++- > acqui/addorder.pl | 15 +--- > acqui/cancelorder.pl | 79 ++++++++++++++++++++ > .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 17 +---- > .../prog/en/modules/acqui/cancelorder.tt | 62 +++++++++++++++ > .../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 22 +----- > 6 files changed, 191 insertions(+), 51 deletions(-) > create mode 100755 acqui/cancelorder.pl > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 4a9eae6..cefdcfa 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -1553,21 +1553,58 @@ cancelled. > =cut > > sub DelOrder { >- my ( $bibnum, $ordernumber ) = @_; >+ my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_; >+ >+ my $error; > my $dbh = C4::Context->dbh; > my $query = " > UPDATE aqorders > SET datecancellationprinted=now() >- WHERE biblionumber=? AND ordernumber=? >+ "; >+ if($reason) { >+ $query .= " >+ , notes = IF(notes IS NULL, >+ CONCAT('Cancellation reason: ', ?), >+ CONCAT(notes, ' - Cancellation reason: ', ?) >+ ) >+ "; >+ } >+ $query .= " >+ WHERE biblionumber=? AND ordernumber=? > "; > my $sth = $dbh->prepare($query); >- $sth->execute( $bibnum, $ordernumber ); >+ if($reason) { >+ $sth->execute($reason, $reason, $bibnum, $ordernumber); >+ } else { >+ $sth->execute( $bibnum, $ordernumber ); >+ } > $sth->finish; >+ > my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); > foreach my $itemnumber (@itemnumbers){ >- C4::Items::DelItem( $dbh, $bibnum, $itemnumber ); >+ my $delcheck = C4::Items::DelItemCheck( $dbh, $bibnum, $itemnumber ); >+ >+ if($delcheck != 1) { >+ $error->{'delitem'} = 1; >+ } >+ } >+ >+ if($delete_biblio) { >+ # We get the number of remaining items >+ my $itemcount = C4::Items::GetItemsCount($bibnum); >+ >+ # If there are no items left, >+ if ( $itemcount == 0 ) { >+ # We delete the record >+ my $delcheck = DelBiblio($bibnum); >+ >+ if($delcheck) { >+ $error->{'delbiblio'} = 1; >+ } >+ } > } >- >+ >+ return $error; > } > > =head2 FUNCTIONS ABOUT PARCELS >diff --git a/acqui/addorder.pl b/acqui/addorder.pl >index 3fa7620..3bc6ef4 100755 >--- a/acqui/addorder.pl >+++ b/acqui/addorder.pl >@@ -123,7 +123,7 @@ use strict; > use warnings; > use CGI; > use C4::Auth; # get_template_and_user >-use C4::Acquisition; # NewOrder DelOrder ModOrder >+use C4::Acquisition; # NewOrder ModOrder > use C4::Suggestions; # ModStatus > use C4::Biblio; # AddBiblio TransformKohaToMarc > use C4::Items; >@@ -157,10 +157,8 @@ $orderinfo->{'uncertainprice'} ||= 0; > my $user = $input->remote_user; > > # create, modify or delete biblio >-# create if $quantity>=0 and $existing='no' >-# modify if $quantity>=0 and $existing='yes' >-# delete if $quantity has been set to 0 by the librarian >-# delete biblio if delbiblio has been set to 1 by the librarian >+# create if $quantity>0 and $existing='no' >+# modify if $quantity>0 and $existing='yes' > my $bibitemnum; > if ( $orderinfo->{quantity} ne '0' ) { > #TODO:check to see if biblio exists >@@ -250,13 +248,6 @@ if ( $orderinfo->{quantity} ne '0' ) { > > } > >-else { # qty=0, delete the line >- my $biblionumber = $input->param('biblionumber'); >- DelOrder( $biblionumber, $$orderinfo{ordernumber} ); >- if ($orderinfo->{delbiblio} == 1){ >- DelBiblio($biblionumber); >- } >-} > my $basketno=$$orderinfo{basketno}; > my $booksellerid=$$orderinfo{booksellerid}; > if (my $import_batch_id=$$orderinfo{import_batch_id}) { >diff --git a/acqui/cancelorder.pl b/acqui/cancelorder.pl >new file mode 100755 >index 0000000..0c24893 >--- /dev/null >+++ b/acqui/cancelorder.pl >@@ -0,0 +1,79 @@ >+#!/usr/bin/perl >+ >+# Copyright 2011 BibLibre SARL >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+=head1 NAME >+ >+cancelorder.pl >+ >+=head1 DESCRIPTION >+ >+Ask confirmation for cancelling an order line >+and add possibility to indicate a reason for cancellation >+(saved in aqorders.notes) >+ >+=cut >+ >+use Modern::Perl; >+ >+use CGI; >+use C4::Auth; >+use C4::Output; >+# FIXME: C4::Search is needed by C4::Items::GetAnalyticsCount, which is called >+# by C4::Acquisition::DelOrder. But C4::Search is not imported by C4::Items. >+# Once this problem is resolved, the following line can be removed. >+# See Bug 7847. >+use C4::Search; >+use C4::Acquisition; >+ >+my $input = new CGI; >+my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { >+ template_name => 'acqui/cancelorder.tt', >+ query => $input, >+ type => 'intranet', >+ authnotrequired => 0, >+ flagsrequired => { 'acquisition' => 'order_manage' }, >+ debug => 1, >+} ); >+ >+my $action = $input->param('action'); >+my $ordernumber = $input->param('ordernumber'); >+my $biblionumber = $input->param('biblionumber'); >+my $referrer = $input->param('referrer') || $input->referer; >+my $del_biblio = $input->param('del_biblio') ? 1 : 0; >+ >+if($action and $action eq "confirmcancel") { >+ my $reason = $input->param('reason'); >+ my $error = DelOrder($biblionumber, $ordernumber, $del_biblio, $reason); >+ >+ if($error) { >+ $template->param(error_delitem => 1) if $error->{'delitem'}; >+ $template->param(error_delbiblio => 1) if $error->{'delbiblio'}; >+ } else { >+ $template->param(success_cancelorder => 1); >+ } >+ $template->param(confirmcancel => 1); >+} >+ >+$template->param( >+ ordernumber => $ordernumber, >+ biblionumber => $biblionumber, >+ referrer => $referrer, >+ del_biblio => $del_biblio, >+); >+ >+output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >index 386d699..e28e7c7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >@@ -47,19 +47,6 @@ > window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]"; > } > } >- function confirm_delete_item(ordernumber, biblionumber) { >- var is_confirmed = confirm(_("Are you sure you want to delete this order ?")); >- if (is_confirmed) { >- window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber; >- } >- } >- >- function confirm_delete_biblio(ordernumber, biblionumber) { >- var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?")); >- if (is_confirmed) { >- window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1"; >- } >- } > > //]]> > </script> >@@ -382,10 +369,10 @@ > [% IF ( books_loo.left_holds_on_order ) %] > <span class="button" title="Can't delete order, ([% books_loo.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br> > [% ELSE %] >- <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order</a><br> >+ <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% books_loo.ordernumber %]&biblionumber=[% books_loo.biblionumber %]&referrer=/cgi-bin/koha/acqui/basket.pl%3Fbasketno=[% basketno %]" class="button">Delete order</a><br> > [% END %] > [% IF ( books_loo.can_del_bib ) %] >- <a href="javascript:confirm_delete_biblio([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order and catalog record</a><br> >+ <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% books_loo.ordernumber %]&biblionumber=[% books_loo.biblionumber %]&del_biblio=1&referrer=/cgi-bin/koha/acqui/basket.pl%3Fbasketno=[% basketno %]" class="button">Delete order and catalog record</a><br> > [% ELSE %] > <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt >new file mode 100644 >index 0000000..4ac1f82 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt >@@ -0,0 +1,62 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Acquisition › Cancel order</title> >+[% INCLUDE 'doc-head-close.inc' %] >+</head> >+ >+<body> >+[% INCLUDE 'header.inc' %] >+ >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisition</a> › Cancel order</div> >+ >+<div id="doc3" class="yui-t2"> >+ >+<div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ [% UNLESS ( confirmcancel ) %] >+ <form method="post" action=""> >+ <div class="dialog alert"> >+ <h3>Are you sure you want to cancel this order ([% ordernumber %])</h3> >+ <p> >+ [% IF (del_biblio) %] >+ Bibliographic record will be deleted too. >+ [% ELSE %] >+ Bibliographic record will not be deleted. >+ [% END %] >+ </p> >+ <p> >+ <textarea name="reason" placeholder="Reason of cancellation"></textarea> >+ </p> >+ <input type="hidden" name="action" value="confirmcancel" /> >+ <input type="hidden" value="[% ordernumber %]" name="ordernumber" /> >+ <input type="hidden" value="[% biblionumber %]" name="biblionumber" /> >+ <input type="hidden" value="[% referrer %]" name="referrer" /> >+ [% IF (del_biblio) %] >+ <input type="hidden" value="1" name="del_biblio" /> >+ [% END %] >+ <input type="submit" class="approve" value="Yes, Cancel (Y)" accesskey="y" /> >+ <input type="submit" class="deny" value="No, Don't Cancel (N)" accesskey="n" onclick="window.location='[% referrer %]';return false;" /> >+ </div> >+ </form> >+ [% ELSE %] >+ [% IF ( success_cancelorder ) %] >+ <div class="dialog message"> >+ The order has been successfully canceled >+ [% ELSE %] >+ <div class="dialog alert"> >+ An error has occured. >+ [% IF ( error_delitem ) %] >+ <p>The order has been canceled, although one or more items could not have been deleted.</p> >+ [% END %] >+ [% IF ( error_delbiblio ) %] >+ <p>The order has been canceled, although the record has not been deleted.</p> >+ [% END %] >+ [% END %] >+ <p>Click <a href="[% referrer %]">here</a> to return to previous page</p> >+ </div> >+ [% END %] >+ >+ </div> >+ </div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt >index fae8473..d41b51e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt >@@ -75,23 +75,7 @@ > > //]]> > </script> >-<script type="text/javascript"> >-//<![CDATA[ >- function confirm_delete_item(ordernumber, basketno, biblionumber) { >- var is_confirmed = confirm(_("Are you sure you want to delete this order ?")); >- if (is_confirmed) { >- window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&invoiceid=[% invoiceid %]"; >- } >- } >- >- function confirm_delete_biblio(ordernumber, basketno, biblionumber) { >- var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?")); >- if (is_confirmed) { >- window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&delbiblio=1&invoiceid=[% invoiceid %]"; >- } >- } >-//]]> >-</script> >+ > </head> > <body id="acq_parcel" class="acq"> > [% INCLUDE 'header.inc' %] >@@ -217,10 +201,10 @@ > [% IF ( loop_order.left_holds_on_order ) %] > <span class="button" title="Can't delete order, ([% loop_order.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br> > [% ELSE %] >- <a href="javascript:confirm_delete_item([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order</a><br> >+ <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% loop_order.ordernumber %]&biblionumber=[% loop_order.biblionumber %]&referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$datereceived&invoice=$invoice" | uri %]">Delete order</a><br /> > [% END %] > [% IF ( loop_order.can_del_bib ) %] >- <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br> >+ <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% loop_order.ordernumber %]&biblionumber=[% loop_order.biblionumber %]&del_biblio=1&referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$datereceived&invoice=$invoice" | uri %]">Delete order and catalog record</a><br /> > [% ELSE %] > <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br> > [% END %] >-- >1.7.2.5
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 7162
:
6219
|
7007
|
9148
|
9238
|
13224
|
13225
|
16373
|
16374
|
16409
|
16457
|
18455
|
18456
|
19315
|
21333
|
21334
|
21335
|
22719
|
22720
|
22721
|
24075
|
24076
|
24077
|
26235
|
26236
|
26237
|
28353
|
28558
|
28559
|
28560
|
28836
|
29535
|
29536
|
29661
|
29662
|
29663
|
29664
|
29665
|
29698
|
29889
|
29890
|
29891
|
29892
|
29893
|
29894
|
29918
|
29943
|
32895
|
32896
|
32897
|
32898
|
32899
|
32900
|
32902