@@ -, +, @@ - 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 --- 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(-) --- a/C4/Acquisition.pm +++ a/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 --- a/C4/Biblio.pm +++ a/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__ --- a/acqui/addorder.pl +++ a/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}; --- a/acqui/basket.pl +++ a/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}; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ a/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 %] --