From 4d67e6910775ea389cfa0a25e3fb55b9cf17bd6f Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Tue, 24 May 2011 16:39:42 +0200 Subject: [PATCH] Bug 5680: Order cancelling improvement : delete attached items & biblio if avalaible - all items attached to the order are deleted - if there is no more items, and if the biblio is not in other orders and no subscriptions and no holds then the biblio is proposed to deletion Now whe have 2 links : "delete order" and "delete order and catalog record", the second one appears only if the deletion is possible. Note that if an hold is related to the item or if the item is unique for the biblio the link "Delete order" is canceled due to hold remaining. On mouse over explanations are shown with count. More lines of warnings with count are shown depending of the case. Signed-off-by: Katrin Fischer Configuration: AcqCreateItem = on order Test cases and results: 1) Order new record with 2 items a) From basket - delete order: only deletes items, OK! - delete order and catalog record: deletes record and items, OK b) From shipment/receive - delete order: only deletes items, OK! 2) Order 1 additional item for existing record with 1 item a) From basket: - delete order: works, existing item and record remain, OK - Can't delete order and catalog record, 1 item left, OK! 3) Order new record with 1 item, title level hold on record a) From basket: - delete order: not possible, OK! - delete orer and catalog record: not possible, OK! b) From shipment/receive page - Cancel: Deletes order, record and hold silently. NO WARNING. NOT OK. See note below. 4) Order 1 additional item for existing record with 1 item, item level hold on existing item a) From basket: - delete order: works, hold and existing item remain, OK! - delete order and catalog record: not possible, OK! b) From shipment/receive page - Cancel: on order item is deleted, other item and hold remain. 5) Order new serial record, create subscription a) From basket: - delete order: works, record and subscription remain, OK! - delete order and catalog record: not possible, OK! b) From shipment/receive page: - Cancel: Subscription and record are silently deleted. NOT OK. 6) Order additional item for existing record with other on order items a) From basket: - delete order: works, existing on order items remain, OK! - delete order and catalog record: not possible, OK! b) From shipment: - Cancel: deletes order and ordered item. OK. Changes made: I changed the wording of the error messages a bit in the template. I changed the message 'Can't delete order and catalog record' to not be shown as a link, as the link does nothing. Tooltip still appears. I attached a screenshot to the bug showing some of my changes. Hope that's ok. Necessary enhancements: Cancelling orders when receiving items should work the same as from the basket summary page. We need the same checks and messages there before deleting records and items automatically. I am signing off on this, but to go into Koha it needs a follow-up for the order receive page. Signed-off-by: Ian Walls Signed-off-by: Chris Cormack --- C4/Acquisition.pm | 5 ++ C4/Biblio.pm | 73 +++++++++++++++++++ C4/Items.pm | 27 ++++++- acqui/addorder.pl | 4 + acqui/basket.pl | 43 ++++++++--- .../prog/en/modules/acqui/basket.tt | 33 ++++++++- 6 files changed, 170 insertions(+), 15 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index cfc261f158..19c4f087c2 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1221,6 +1221,11 @@ sub DelOrder { my $sth = $dbh->prepare($query); $sth->execute( $bibnum, $ordernumber ); $sth->finish; + my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); + foreach my $itemnumber (@itemnumbers){ + C4::Items::DelItem( $dbh, $bibnum, $itemnumber ); + } + } =head2 FUNCTIONS ABOUT PARCELS diff --git a/C4/Biblio.pm b/C4/Biblio.pm index f1aaac6a33..4a9735ffb4 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -94,6 +94,9 @@ BEGIN { &PrepHostMarcField &CountItemsIssued + &CountBiblioInOrders + &GetSubscriptionsId + &GetHolds ); # To modify something @@ -3806,6 +3809,76 @@ sub get_biblio_authorised_values { return $authorised_values; } +=head2 CountBiblioInOrders + +=over 4 +$count = &CountBiblioInOrders( $biblionumber); + +=back + +This function return count of biblios in orders with $biblionumber + +=cut + +sub CountBiblioInOrders { + my ($biblionumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) + FROM aqorders + WHERE biblionumber=? AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my $count = $sth->fetchrow; + return ($count); +} + +=head2 GetSubscriptionsId + +=over 4 +$subscriptions = &GetSubscriptionsId($biblionumber); + +=back + +This function return an array of subscriptionid with $biblionumber + +=cut + +sub GetSubscriptionsId { + my ($biblionumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT subscriptionid + FROM subscription + WHERE biblionumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my @subscriptions = $sth->fetchrow_array; + return (@subscriptions); +} + +=head2 GetHolds + +=over 4 +$holds = &GetHolds($biblionumber); + +=back + +This function return the count of holds with $biblionumber + +=cut + +sub GetHolds { + my ($biblionumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) + FROM reserves + WHERE biblionumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my $holds = $sth->fetchrow; + return ($holds); +} + + 1; __END__ diff --git a/C4/Items.pm b/C4/Items.pm index ca67c6d79a..4915884afd 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -74,14 +74,14 @@ BEGIN { get_hostitemnumbers_of GetItemnumberFromBarcode GetBarcodeFromItemnumber - GetHiddenItemnumbers - + GetHiddenItemnumbers DelItemCheck MoveItemFromBiblio GetLatestAcquisitions CartToShelf GetAnalyticsCount + GetItemHolds ); } @@ -2464,4 +2464,27 @@ sub GetAnalyticsCount { } } +=head2 GetItemHolds + +=over 4 +$holds = &GetItemHolds($biblionumber, $itemnumber); + +=back + +This function return the count of holds with $biblionumber and $itemnumber + +=cut + +sub GetItemHolds { + my ($biblionumber, $itemnumber) = @_; + my $holds; + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) + FROM reserves + WHERE biblionumber=? AND itemnumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber, $itemnumber); + $holds = $sth->fetchrow; + return $holds; +} 1; diff --git a/acqui/addorder.pl b/acqui/addorder.pl index e321d2c11b..d7f7e96363 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -190,6 +190,7 @@ my $user = $input->remote_user; # 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 my $bibitemnum; if ( $orderinfo->{quantity} ne '0' ) { #TODO:check to see if biblio exists @@ -271,6 +272,9 @@ 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}; diff --git a/acqui/basket.pl b/acqui/basket.pl index 9377a43ae4..b83628029e 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -28,12 +28,12 @@ use C4::Output; use CGI; use C4::Acquisition; use C4::Budgets; - use C4::Bookseller qw( GetBookSellerFromId); use C4::Dates qw/format_date/; use C4::Debug; - +use C4::Biblio; use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket +use C4::Items; =head1 NAME basket.pl @@ -259,13 +259,38 @@ if ( $op eq 'delete_confirm' ) { # FIXME: what about the "actual cost" field? $qty_total += $qty; my %line = %{ $order }; - - $line{order_received} = ( $qty == $order->{'quantityreceived'} ); - $line{basketno} = $basketno; - $line{budget_name} = $budget->{budget_name}; - $line{rrp} = sprintf( "%.2f", $line{'rrp'} ); - $line{ecost} = sprintf( "%.2f", $line{'ecost'} ); - $line{line_total} = sprintf( "%.2f", $line_total ); + my $biblionumber = $order->{'biblionumber'}; + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $order->{'ordernumber'}; + my @subscriptions = GetSubscriptionsId ($biblionumber); + my $itemcount = GetItemsCount($biblionumber); + my $holds = GetHolds ($biblionumber); + my @items = GetItemnumbersFromOrder( $ordernumber ); + my $itemholds; + foreach my $item (@items){ + my $nb = GetItemHolds($biblionumber, $item); + if ($nb){ + $itemholds += $nb; + } + } + # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); + $line{items} = ($itemcount) - (scalar @items); + $line{left_item} = 1 if $line{items} >= 1; + $line{left_biblio} = 1 if $countbiblio > 1; + $line{biblios} = $countbiblio - 1; + $line{left_subscription} = 1 if scalar @subscriptions >= 1; + $line{subscriptions} = scalar @subscriptions; + $line{left_holds} = 1 if $holds >= 1; + $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); + $line{holds} = $holds; + $line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; + $line{order_received} = ( $qty == $order->{'quantityreceived'} ); + $line{basketno} = $basketno; + $line{budget_name} = $budget->{budget_name}; + $line{rrp} = sprintf( "%.2f", $line{'rrp'} ); + $line{ecost} = sprintf( "%.2f", $line{'ecost'} ); + $line{line_total} = sprintf( "%.2f", $line_total ); if ($line{uncertainprice}) { $template->param( uncertainprices => 1 ); $line{rrp} .= ' (Uncertain)'; 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 26543034f6..90ddacb122 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -39,6 +39,13 @@ 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"; + } + } //]]> @@ -277,7 +284,28 @@ Modify - Delete + [% IF ( books_loo.left_holds_on_order ) %] + Can't delete order
+ [% ELSE %] + Delete order
+ [% END %] + [% IF ( books_loo.can_del_bib ) %] + Delete order and catalog record
+ [% ELSE %] + Can't delete order and catalog record
+ [% END %] + [% IF ( books_loo.left_item ) %] + [% books_loo.items %] item(s) left
+ [% END %] + [% IF ( books_loo.left_biblio ) %] + [% books_loo.biblios %] order(s) left
+ [% END %] + [% IF ( books_loo.left_subscription ) %] + [% books_loo.subscriptions %] subscription(s) left
+ [% END %] + [% IF ( books_loo.left_holds ) %] + [% books_loo.holds %] hold(s) left + [% END %] [% END %] [% END %] @@ -320,9 +348,6 @@ [% END %] - - -
-- 2.39.5