@@ -, +, @@ - all items attached to the order are deleted - if there is no more items, and if the biblio is not in other orders and no subscriptions and no holds then the biblio is proposed to deletion - delete order: only deletes items, OK! - delete order and catalog record: deletes record and items, OK - delete order: only deletes items, OK! - delete order: works, existing item and record remain, OK - Can't delete order and catalog record, 1 item left, OK! - delete order: not possible, OK! - delete orer and catalog record: not possible, OK! - Cancel: Deletes order, record and hold silently. - delete order: works, hold and existing item remain, OK! - delete order and catalog record: not possible, OK! - Cancel: on order item is deleted, other item and hold remain. - delete order: works, record and subscription remain, OK! - delete order and catalog record: not possible, OK! - Cancel: Subscription and record are silently deleted. NOT OK. - delete order: works, existing on order items remain, OK! - delete order and catalog record: not possible, OK! - Cancel: deletes order and ordered item. OK. --- C4/Acquisition.pm | 5 ++ C4/Biblio.pm | 73 ++++++++++++++++++++ C4/Items.pm | 27 +++++++- acqui/addorder.pl | 4 + acqui/basket.pl | 43 +++++++++--- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 33 ++++++++- 6 files changed, 170 insertions(+), 15 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -1221,6 +1221,11 @@ sub DelOrder { my $sth = $dbh->prepare($query); $sth->execute( $bibnum, $ordernumber ); $sth->finish; + my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); + foreach my $itemnumber (@itemnumbers){ + C4::Items::DelItem( $dbh, $bibnum, $itemnumber ); + } + } =head2 FUNCTIONS ABOUT PARCELS --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -94,6 +94,9 @@ BEGIN { &PrepHostMarcField &CountItemsIssued + &CountBiblioInOrders + &GetSubscriptionsId + &GetHolds ); # To modify something @@ -3806,6 +3809,76 @@ 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); +} + +=head2 GetSubscriptionsId + +=over 4 +$subscriptions = &GetSubscriptionsId($biblionumber); + +=back + +This function return an array of subscriptionid with $biblionumber + +=cut + +sub GetSubscriptionsId { + my ($biblionumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT subscriptionid + FROM subscription + WHERE biblionumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my @subscriptions = $sth->fetchrow_array; + return (@subscriptions); +} + +=head2 GetHolds + +=over 4 +$holds = &GetHolds($biblionumber); + +=back + +This function return the count of holds with $biblionumber + +=cut + +sub GetHolds { + my ($biblionumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) + FROM reserves + WHERE biblionumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber); + my $holds = $sth->fetchrow; + return ($holds); +} + + 1; __END__ --- a/C4/Items.pm +++ a/C4/Items.pm @@ -74,14 +74,14 @@ BEGIN { get_hostitemnumbers_of GetItemnumberFromBarcode GetBarcodeFromItemnumber - GetHiddenItemnumbers - + GetHiddenItemnumbers DelItemCheck MoveItemFromBiblio GetLatestAcquisitions CartToShelf GetAnalyticsCount + GetItemHolds ); } @@ -2464,4 +2464,27 @@ sub GetAnalyticsCount { } } +=head2 GetItemHolds + +=over 4 +$holds = &GetItemHolds($biblionumber, $itemnumber); + +=back + +This function return the count of holds with $biblionumber and $itemnumber + +=cut + +sub GetItemHolds { + my ($biblionumber, $itemnumber) = @_; + my $holds; + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) + FROM reserves + WHERE biblionumber=? AND itemnumber=?"; + my $sth = $dbh->prepare($query); + $sth->execute($biblionumber, $itemnumber); + $holds = $sth->fetchrow; + return $holds; +} 1; --- 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 @@ -271,6 +272,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); + } } 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 @@ -259,13 +259,38 @@ if ( $op eq 'delete_confirm' ) { # FIXME: what about the "actual cost" field? $qty_total += $qty; my %line = %{ $order }; - - $line{order_received} = ( $qty == $order->{'quantityreceived'} ); - $line{basketno} = $basketno; - $line{budget_name} = $budget->{budget_name}; - $line{rrp} = sprintf( "%.2f", $line{'rrp'} ); - $line{ecost} = sprintf( "%.2f", $line{'ecost'} ); - $line{line_total} = sprintf( "%.2f", $line_total ); + my $biblionumber = $order->{'biblionumber'}; + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $order->{'ordernumber'}; + my @subscriptions = GetSubscriptionsId ($biblionumber); + my $itemcount = GetItemsCount($biblionumber); + my $holds = GetHolds ($biblionumber); + my @items = GetItemnumbersFromOrder( $ordernumber ); + my $itemholds; + foreach my $item (@items){ + my $nb = GetItemHolds($biblionumber, $item); + if ($nb){ + $itemholds += $nb; + } + } + # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); + $line{items} = ($itemcount) - (scalar @items); + $line{left_item} = 1 if $line{items} >= 1; + $line{left_biblio} = 1 if $countbiblio > 1; + $line{biblios} = $countbiblio - 1; + $line{left_subscription} = 1 if scalar @subscriptions >= 1; + $line{subscriptions} = scalar @subscriptions; + $line{left_holds} = 1 if $holds >= 1; + $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); + $line{holds} = $holds; + $line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; + $line{order_received} = ( $qty == $order->{'quantityreceived'} ); + $line{basketno} = $basketno; + $line{budget_name} = $budget->{budget_name}; + $line{rrp} = sprintf( "%.2f", $line{'rrp'} ); + $line{ecost} = sprintf( "%.2f", $line{'ecost'} ); + $line{line_total} = sprintf( "%.2f", $line_total ); if ($line{uncertainprice}) { $template->param( uncertainprices => 1 ); $line{rrp} .= ' (Uncertain)'; --- 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 catalog record and order ?')); + if (is_confirmed) { + window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1"; + } + } //]]> @@ -277,7 +284,28 @@ Modify - Delete + [% IF ( books_loo.left_holds_on_order ) %] + Can't delete order
+ [% ELSE %] + Delete order
+ [% END %] + [% IF ( books_loo.can_del_bib ) %] + Delete order and catalog record
+ [% ELSE %] + Can't delete order and catalog record
+ [% END %] + [% IF ( books_loo.left_item ) %] + [% books_loo.items %] item(s) left
+ [% END %] + [% IF ( books_loo.left_biblio ) %] + [% books_loo.biblios %] order(s) left
+ [% END %] + [% IF ( books_loo.left_subscription ) %] + [% books_loo.subscriptions %] subscription(s) left
+ [% END %] + [% IF ( books_loo.left_holds ) %] + [% books_loo.holds %] hold(s) left + [% END %] [% END %] [% END %] @@ -320,9 +348,6 @@ [% END %] - - -
--