From 04058ed34bac3525ec87b294e52ddc631f4017e7 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 5 Aug 2009 15:37:22 +0200 Subject: [PATCH] MT 1487 : Ability to cancel orders when receiving shipments Related items are also suppressed, as well as the record if there are no more items associed with it --- C4/Acquisition.pm | 17 ++++++++ acqui/parcel.pl | 42 +++++++++++++++++++ .../prog/en/modules/acqui/parcel.tmpl | 19 ++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 59cc2a59a2..c4fc0ca420 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -53,6 +53,7 @@ BEGIN { &GetContracts &GetContract &GetOrderFromItemnumber + &GetItemnumbersFromOrder ); } @@ -80,6 +81,22 @@ sub GetOrderFromItemnumber { } +# Returns the itemnumber(s) associated with the ordernumber given in parameter +sub GetItemnumbersFromOrder { + my ($ordernumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT itemnumber FROM aqorders_items WHERE ordernumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($ordernumber); + my @tab; + + while (my $order = $sth->fetchrow_hashref) { + push @tab, $order->{'itemnumber'}; + } + + return @tab; + +} diff --git a/acqui/parcel.pl b/acqui/parcel.pl index d2296ece20..3a161eb33a 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -54,8 +54,10 @@ To filter the results list on this given date. use C4::Auth; use C4::Acquisition; +use C4::Budgets; use C4::Bookseller; use C4::Biblio; +use C4::Items; use CGI; use C4::Output; use C4::Dates qw/format_date format_date_in_iso/; @@ -90,6 +92,46 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); +my $action = $input->param('action'); +my $ordernumber = $input->param('ordernumber'); +my $biblionumber = $input->param('biblionumber'); + +# If canceling an order +if ($action eq "cancelorder") { + + my $error_delitem; + my $error_delbiblio; + + # We delete the order + DelOrder($biblionumber, $ordernumber); + + # We delete all the items related to this order + my @itemnumbers = GetItemnumbersFromOrder($ordernumber); + foreach (@itemnumbers) { + my $delcheck = DelItemCheck(C4::Context->dbh, $biblionumber, $_); + # (should always success, as no issue should exist on item on order) + if ($delcheck != 1) { $error_delitem = 1; } + } + + # We get the number of remaining items + my $itemcount = GetItemsCount($biblionumber); + + # If there are no items left, + if ($itemcount eq 0) { + # We delete the record + $error_delbiblio = DelBiblio($biblionumber); + } + + if ($error_delitem || $error_delbiblio) { + warn $error_delitem; + warn $error_delbiblio; + if ($error_delitem) { $template->param(error_delitem => 1); } + if ($error_delbiblio) { $template->param(error_delbiblio => 1); } + } else { + $template->param(success_delorder => 1); + } +} + # If receiving error, report the error (coming from finishrecieve.pl(sic)). if( scalar(@rcv_err) ) { my $cnt=0; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl index c624f5b39d..1dfaee7e24 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl @@ -142,6 +142,18 @@ Receive orders from + + +
The order has been successfully canceled.
+ + +
The order has been canceled, although one or more items could not have been deleted.
+ + +
The order has been canceled, although the record has not been deleted.
+ + +

Invoice number:

Received by:

@@ -192,7 +204,7 @@ Still on order Unit cost Order cost - Receive + Order @@ -214,7 +226,10 @@ / - &datereceived=&invoice=&gst=&freight=&supplierid=">Receive + + &datereceived=&invoice=&gst=&freight=&supplierid=">Receive / + &biblionumber=&action=cancelorder&supplierid=&datereceived=&invoice=" onclick="return confirm(_('Are you sure you want to cancel this order?'));">Cancel + -- 2.39.5