From 3db5380a8500956bbdf8b47ca1b248b36c023d7b Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Mon, 11 Mar 2013 00:51:48 +0100 Subject: [PATCH][Revised] Bug 9780: Show if a record is used by orders and prevent its suppression Revised : suppressing tabs, adding 5) and 18) step in test 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 : A. test what can do and see a librarian with order managing rights 0) Connect to Koha with a borrower with order managing rights 1) check XSLTDetailsDisplay syspref is disabled 2) in basket A, create 2 orders with a single record 3) in basket B, create 1 order with the same record 4) check that record in catalog (detail.pl page) : you should see a line saying it is used 3 times, in baskets A and B 5) if some items are attached to that record, suppress all items 6) in basket A, suppress one of the 2 orders 7) check the record again : you should see a line saying it is used 2 times in active orders, in baskets A and B, and 1 time in suppressed order in basket A 8) enable XSLTDetailsDisplay syspref 9) check the record again : you should see the same information as 5. 10) each basket number must be a hyperlink. Check if the links are correct 11) try to suppress the record : it should be impossible 12) suppress the 2 other orders in basket A and B 13) check catalogue : you should see a line saying it is only used in 3 deleted orders 14) try to delete again the record : it should be possible after a confirmation B. test what can do and see a librarian without order managing rights 15) in basket A, create again 1 order with a single record 16) disconnect yourself and connect to Koha with a borrower without order managing rights 17) check the record in the catalog : you should see information, but without any link to basket A 18) if some items are attached to that record, suppress all items 19) try to suppress the record : it should be impossible (like before) 20) disconnect yourself and connect to Koha with a borrower with order managing rights 21) suppress the order in basket A 22) disconnect yourself and connect to Koha with a borrower without order managing rights 23) check the record again : you should see a line saying it is only used in a deleted order in basket A 24) try to delete the record : it should be impossible, because you don't have order managing rights Signed-off-by: Julian Maurice --- C4/Acquisition.pm | 35 +++++- catalogue/detail.pl | 32 +++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 21 +++- .../prog/en/modules/catalogue/detail.tt | 129 ++++++++++++++------ 4 files changed, 178 insertions(+), 39 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4a9eae6..8390670 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..636e0a4 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..32586ae 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){ + + 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..32acd66 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -136,41 +136,70 @@ function verify_images() {
- -[% IF ( unknownbiblionumber ) %] -
The record you requested does not exist ([% biblionumber %]).
-[% ELSE %] -
-
-
- -[% INCLUDE 'cat-toolbar.inc' %] - [% IF ( ocoins ) %] - - - [% END %] - - [% IF ( AmazonCoverImages ) %] - [% IF ( XSLTDetailsDisplay ) %] -
-
- [% ELSE %] -
-
- [% END %] + [% IF ( unknownbiblionumber ) %] +
The record you requested does not exist ([% biblionumber %]).
[% ELSE %] - [% IF ( XSLTDetailsDisplay ) %] -
-
- [% ELSE %] -
-
- [% END %] - [% END %] - - [% IF ( XSLTDetailsDisplay ) %] - [% XSLTBloc %] - +
+
+
+ [% INCLUDE 'cat-toolbar.inc' %] + [% IF ( ocoins ) %] + + + [% END %] + [% IF ( AmazonCoverImages ) %] + [% IF ( XSLTDetailsDisplay ) %] +
+
+ [% ELSE %] +
+
+ [% END %] + [% ELSE %] + [% IF ( XSLTDetailsDisplay ) %] +
+
+ [% ELSE %] +
+
+ [% END %] + [% END %] + [% 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 %] + [%- UNLESS loop.last %],[% END %] + [% ELSE %] + [% basketo %] + [%- UNLESS loop.last %],[% END %] + [% 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 %] + [%- UNLESS loop.last %],[% END %] + [% ELSE %] + [% basketdo %] + [%- UNLESS loop.last %],[% END %] + [% END %] + [% END %] + [% END %] + + + [% END %] [% IF ( GetShelves ) %] Lists that include this title: [% FOREACH GetShelve IN GetShelves %] @@ -304,6 +333,38 @@ 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 %] + [%- UNLESS loop.last %],[% END %] + [% ELSE %] + [% basketo %] + [%- UNLESS loop.last %],[% END %] + [% 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 %] + [%- UNLESS loop.last %],[% END %] + [% ELSE %] + [% basketdo %] + [%- UNLESS loop.last %],[% END %] + [% END %] + [% END %] + [% END %] +
  • + [% END %] [% IF ( GetShelves ) %]
  • Lists that include this title: -- 1.7.9.5