@@ -, +, @@
- 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
---
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(-)
--- a/C4/Acquisition.pm
+++ a/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);
--- a/catalogue/detail.pl
+++ a/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;
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc
+++ a/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?"));
}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
+++ a/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:
--