From dc5d11c3694eb10a128983b79c21816002038b50 Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Tue, 24 May 2011 16:39:42 +0200 Subject: [PATCH 1/1] [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 then the biblio is proposed to deletion Now whe have 2 links : delete order and delete order and biblio, the second one appears only if the deletion is possible. --- C4/Acquisition.pm | 2 + C4/Biblio.pm | 25 +++++++++++++++++++- acqui/addorder.pl | 4 +++ acqui/basket.pl | 10 +++++-- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 12 ++++++++- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index e431bd2..2e5f4bc 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1223,6 +1223,8 @@ sub DelOrder { my $sth = $dbh->prepare($query); $sth->execute( $bibnum, $ordernumber ); $sth->finish; + my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); + C4::Items::DelItem( $dbh, $bibnum, $_ ) for @itemnumbers; } =head2 FUNCTIONS ABOUT PARCELS diff --git a/C4/Biblio.pm b/C4/Biblio.pm index c9590c2..5b918e1 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -89,8 +89,8 @@ BEGIN { &GetMarcFromKohaField &GetFrameworkCode &TransformKohaToMarc - &CountItemsIssued + &CountBiblioInOrders ); # To modify something @@ -3630,6 +3630,29 @@ 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); +} + 1; __END__ diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 44623ec..b8d0e21 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 @@ -270,6 +271,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) if (C4::Items::GetItemsCount($biblionumber) == 0 && CountBiblioInOrders($biblionumber) <= 1); + } } my $basketno=$$orderinfo{basketno}; my $booksellerid=$$orderinfo{booksellerid}; diff --git a/acqui/basket.pl b/acqui/basket.pl index 0261e86..99956cf 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 @@ -253,7 +253,11 @@ if ( $op eq 'delete_confirm' ) { # FIXME: what about the "actual cost" field? $qty_total += $qty; my %line = %{ $order }; - + my $biblionumber = $order->{'biblionumber'}; + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $order->{'ordernumber'}; + # if the biblio is not in other orders and if there is no items elsewhere we can show the link "Delete order and Biblio" see bug 5680 + $line{can_del_bib} = 1 if $countbiblio <= 1 && GetItemsCount($biblionumber) == scalar GetItemnumbersFromOrder( $ordernumber ); $line{order_received} = ( $qty == $order->{'quantityreceived'} ); $line{basketno} = $basketno; $line{budget_name} = $budget->{budget_name}; 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 d34e3d5..c1e574a 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 order with his biblio ?')); + if (is_confirmed) { + window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1"; + } + } //]]> @@ -278,9 +285,12 @@ Modify - Delete + Delete order
+ [% IF ( books_loo.can_del_bib ) %] + Delete order and Biblio [% END %] + [% END %] [% END %] [% END %] -- 1.7.0.4