From b138eb71b9df3305ea40c02076789dcda6def215 Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Mon, 11 Mar 2013 00:51:48 +0100 Subject: [PATCH] Bug 9780: Show basket numbers if a record is linked to an order and prevent its suppression Before this patch, librarians can delete a record even if it is used in an order. And if items are not created when ordering, librarians cannot know the record is used in orders. This patch adds one sub in Acquisiton.pm : GetOrdersByBiblionumber It makes changes to detail.pl and detail.tt : If the record is used by an active order, or a deleted order, Koha will display a warning at the end of the record, with the number of active order and deleted orders using the record, and the corresponding basket number. If the librarian have managing order permission, the basket numbers are clickable. It also make changes to cat-toolbar.inc : It adds 2 new controls when deleting a record : - librarians cannot suppress it if it is used in an active order - only librarians with managing order permission can suppress it if it is used in a deleted order To test : 1) in basket A, create 2 orders with a single record (with no items attached) 2) in basket B, create 1 order with the same record 3) check that record in catalog (detail.pl page) : you should see a line saying it is used 3 times, in baskets A and B 4) in basket A, suppress one of the order 5) check the catalog again 6) try to suppress the record : it should be impossible 7) suppress the 2 other orders in basket A and B 8) check catalogue : you should see a line saying it is only used in 3 deleted orders 9) try to delete again the record : it should be possible after a confirmation, if you have order managing rights --- C4/Acquisition.pm | 35 +++++++++++- catalogue/detail.pl | 32 +++++++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 19 ++++++- .../prog/en/modules/catalogue/detail.tt | 59 +++++++++++++++++++- 4 files changed, 140 insertions(+), 5 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4a9eae6..f309740 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -53,7 +53,7 @@ BEGIN { &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup &GetBasketgroups &ReOpenBasketgroup - &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders + &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders &GetOrdersByBiblionumber &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber &SearchOrder &GetHistory &GetRecentAcqui &ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber @@ -903,6 +903,39 @@ sub GetPendingOrders { #------------------------------------------------------------# +=head3 GetOrdersByBiblionumber + + @orders = &GetOrdersByBiblionumber($biblionumber); + +Looks up the orders with linked to a specific $biblionumber, including +cancelled orders and received orders. + +return : +C<@orders> is an array of references-to-hash, whose keys are the +fields from the aqorders, biblio, and biblioitems tables in the Koha database. + +=cut + +sub GetOrdersByBiblionumber { + my $biblionumber = shift; + my $dbh = C4::Context->dbh; + my $query =" + SELECT biblio.*,biblioitems.*, + aqorders.*, + aqbudgets.* + FROM aqorders + LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id + LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber + LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber + WHERE aqorders.biblionumber=? + "; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my $results = $sth->fetchall_arrayref({}); + $sth->finish; + return @$results; +} + =head3 GetOrders @orders = &GetOrders($basketnumber, $orderby); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index ec6f6eb..9cbfada 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -41,6 +41,7 @@ use C4::XSLT; use C4::Images; use Koha::DateUtils; use C4::HTML5Media; +use C4::Acquisition qw(GetOrdersByBiblionumber); # use Smart::Comments; @@ -398,4 +399,35 @@ if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->pref my ( $holdcount, $holds ) = C4::Reserves::GetReservesFromBiblionumber($biblionumber,1); $template->param( holdcount => $holdcount, holds => $holds ); +my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber); +my @deletedorders_using_biblio; +my @orders_using_biblio; +my @baskets_orders; +my @baskets_deletedorders; + +foreach my $myorder (@allorders_using_biblio) { + my $basket = $myorder->{'basketno'}; + if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ + push @deletedorders_using_biblio, $myorder; + unless (grep(/^$basket$/, @baskets_deletedorders)){ + push @baskets_deletedorders,$myorder->{'basketno'}; + } + } + else { + push @orders_using_biblio, $myorder; + unless (grep(/^$basket$/, @baskets_orders)){ + push @baskets_orders,$myorder->{'basketno'}; + } + } +} + +my $count_orders_using_biblio = scalar @orders_using_biblio ; +$template->param (countorders => $count_orders_using_biblio); + +my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ; +$template->param (countdeletedorders => $count_deletedorders_using_biblio); + +$template->param (basketsorders => \@baskets_orders); +$template->param (basketsdeletedorders => \@baskets_deletedorders); + output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 2dde5ad..3db25c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -31,12 +31,25 @@ function confirm_deletion() { var count = [% count %]; var holdcount = [% holdcount %]; - + var countorders = [% countorders %]; + var countdeletedorders = [% countdeletedorders %]; var is_confirmed; + if (count > 0){ is_confirmed = alert( count + " " +_("item(s) are attached to this record.\nYou must delete all items before deleting this record.") ); - } else if ( holdcount > 0 ) { - is_confirmed = confirm( holdcount + " " + _("holds(s) for this record \n Are you sure you want to delete this record?.")); + } + else if (countorders > 0){ + is_confirmed = alert( _("You cannot delete this record : it is used in")+" "+ countorders + " " +_("order(s).") ); + } + else if (countdeletedorders > 0){ + [% IF ( CAN_user_acquisition_order_manage ) %] + is_confirmed = confirm( countdeletedorders + " " +_("deleted order(s) are using this record.\nAre you sure you want to delete this record?") ); + [% ELSE %] + is_confirmed = alert( countdeletedorders + " " +_("deleted order(s) are using this record.\nYou need order managing permissions to delete this record.") ); + [% END %] + } + else if ( holdcount > 0 ) { + is_confirmed = confirm( holdcount + " " + _("holds(s) for this record.\nAre you sure you want to delete this record?")); } else { is_confirmed = confirm(_("Are you sure you want to delete this record?")); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 8f40e31..bbb09b0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -170,7 +170,36 @@ function verify_images() { [% IF ( XSLTDetailsDisplay ) %] [% XSLTBloc %] - + [% IF ( countorders || countdeletedorders ) %] + + Number of order(s) using this title: + + [% IF ( countorders ) %] + [% countorders %] active order(s) in basket(s) + [% FOREACH basketo IN basketsorders %] + [% IF ( CAN_user_acquisition_order_manage ) %] + #[% basketo %], + [% ELSE %] + [% basketo %], + [% END %] + [% END %] + [% END %] + [% IF ( countorders && countdeletedorders ) %] + and + [% END %] + [% IF ( countdeletedorders ) %] + [% countdeletedorders %] deleted order(s) in basket(s) + [% FOREACH basketdo IN basketsdeletedorders %] + [% IF ( CAN_user_acquisition_order_manage ) %] + #[% basketdo %], + [% ELSE %] + [% basketdo %], + [% END %] + [% END %] + [% END %] + + + [% END %] [% IF ( GetShelves ) %] Lists that include this title: [% FOREACH GetShelve IN GetShelves %] @@ -304,6 +333,34 @@ function verify_images() { [% END %] [% END %] +   + [% IF ( countorders || countdeletedorders ) %] +
  • Number of order(s) using this title: + [% IF ( countorders ) %] + [% countorders %] active order(s) in basket(s) + [% FOREACH basketo IN basketsorders %] + [% IF ( CAN_user_acquisition_order_manage ) %] + #[% basketo %], + [% ELSE %] + [% basketo %], + [% END %] + [% END %] + [% END %] + [% IF ( countorders && countdeletedorders ) %] + and + [% END %] + [% IF ( countdeletedorders ) %] + [% countdeletedorders %] deleted order(s) in basket(s) + [% FOREACH basketdo IN basketsdeletedorders %] + [% IF ( CAN_user_acquisition_order_manage ) %] + #[% basketdo %], + [% ELSE %] + [% basketdo %], + [% END %] + [% END %] + [% END %] +
  • + [% END %] [% IF ( GetShelves ) %]
  • Lists that include this title: -- 1.7.9.5