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
&PrepHostMarcField
&CountItemsIssued
+ &CountBiblioInOrders
+ &GetSubscriptionsId
+ &GetHolds
);
# To modify something
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__
get_hostitemnumbers_of
GetItemnumberFromBarcode
GetBarcodeFromItemnumber
- GetHiddenItemnumbers
-
+ GetHiddenItemnumbers
DelItemCheck
MoveItemFromBiblio
GetLatestAcquisitions
CartToShelf
GetAnalyticsCount
+ GetItemHolds
);
}
}
}
+=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;
# 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
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};
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
# 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)';
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";
+ }
+ }
//]]>
</script>
<a href="neworderempty.pl?ordernumber=[% books_loo.ordernumber %]&booksellerid=[% booksellerid %]&basketno=[% basketno %]">Modify</a>
</td>
<td>
- <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete</a>
+ [% IF ( books_loo.left_holds_on_order ) %]
+ <span class="button" title="Can't delete order, ([% books_loo.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
+ [% ELSE %]
+ <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order</a><br>
+ [% END %]
+ [% IF ( books_loo.can_del_bib ) %]
+ <a href="javascript:confirm_delete_biblio([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order and catalog record</a><br>
+ [% ELSE %]
+ <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
+ [% END %]
+ [% IF ( books_loo.left_item ) %]
+ <b title="Can't delete catalog record, because of [% books_loo.items %] existing hold(s)" >[% books_loo.items %] item(s) left</b><br>
+ [% END %]
+ [% IF ( books_loo.left_biblio ) %]
+ <b title="Can't delete catalog record, delete other orders linked to it first">[% books_loo.biblios %] order(s) left</b><br>
+ [% END %]
+ [% IF ( books_loo.left_subscription ) %]
+ <b title="Can't delete catalog record, delete subscriptions first">[% books_loo.subscriptions %] subscription(s) left</b><br>
+ [% END %]
+ [% IF ( books_loo.left_holds ) %]
+ <b title="Can't delete catalog record or order, cancel holds first">[% books_loo.holds %] hold(s) left</b>
+ [% END %]
</td>
[% END %]
[% END %]
</form>
</div>
[% END %]
-
-
-
</div>
</div>
<div class="yui-b">