@@ -, +, @@
---
C4/Acquisition.pm | 48 +++++++++++--
acqui/addorder.pl | 15 +---
acqui/cancelorder.pl | 79 ++++++++++++++++++++++
.../intranet-tmpl/prog/en/modules/acqui/basket.tt | 18 +----
.../prog/en/modules/acqui/cancelorder.tt | 62 +++++++++++++++++
.../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 18 +----
6 files changed, 191 insertions(+), 49 deletions(-)
create mode 100755 acqui/cancelorder.pl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt
--- a/C4/Acquisition.pm
+++ a/C4/Acquisition.pm
@@ -1837,20 +1837,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(), orderstatus='cancelled'
- 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;
+ }
}
- return;
+
+ 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;
}
=head3 TransferOrder
--- a/acqui/addorder.pl
+++ a/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::Budgets;
@@ -230,10 +230,8 @@ $orderinfo->{subscriptionid} ||= undef;
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'
if ( $orderinfo->{quantity} ne '0' ) {
#TODO:check to see if biblio exists
unless ( $$orderinfo{biblionumber} ) {
@@ -321,13 +319,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}) {
--- a/acqui/cancelorder.pl
+++ a/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;
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -48,20 +48,6 @@
window.location = "[% script_name %]?op=delete_confirm&delbiblio="+delbiblio+"&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";
- }
- }
-
function transfer_order_popup(ordernumber) {
var url = "/cgi-bin/koha/acqui/transferorder.pl?"
+ "ordernumber=" + ordernumber
@@ -539,10 +525,10 @@
[% IF ( books_loo.left_holds_on_order ) %]
[% ELSE %]
- Delete order
+ Delete order
[% END %]
[% IF ( books_loo.can_del_bib ) %]
- Delete order and catalog record
+ Delete order and catalog record
[% ELSE %]
[% END %]
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt
@@ -0,0 +1,62 @@
+[% INCLUDE 'doc-head-open.inc' %]
+