From 2d90fb22d43db986547bbaa945873d6dd78aab71 Mon Sep 17 00:00:00 2001 From: John Soros Date: Thu, 2 Jul 2009 16:22:19 +0200 Subject: [PATCH] fix for 1431 point 2: orders and orders_items also moved to new biblionumber now --- C4/Acquisition.pm | 41 ++++++++++++++++++++++++- cataloguing/moveitem.pl | 68 ++++++++++++++++++++++++++--------------- 2 files changed, 83 insertions(+), 26 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 43024b3a7c..8bd9965afb 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -45,7 +45,7 @@ BEGIN { &GetPendingOrders &GetOrder &GetOrders &GetOrderNumber &GetLateOrders &NewOrder &DelOrder &SearchOrder &GetHistory &GetRecentAcqui - &ModOrder &ModReceiveOrder &ModOrderBiblioitemNumber + &ModOrder &ModOrderItem &ModReceiveOrder &ModOrderBiblioitemNumber &NewOrderItem @@ -970,6 +970,45 @@ sub ModOrder { #------------------------------------------------------------# +=head3 ModOrderItem + +=over 4 + +&ModOrderItem(\%hashref); + +=over 2 + +Modifies the itemnumber in the aqorders_items table. The input hash needs three entities: + - itemnumber: the old itemnumber + - ordernumber: the order this item is attached to + - newitemnumber: the new itemnumber we want to attach the line to + +=back + +=back + +=cut + +sub ModOrderItem { + my $orderiteminfo = shift; + if (! $orderiteminfo->{'ordernumber'} || ! $orderiteminfo->{'itemnumber'} || ! $orderiteminfo->{'newitemnumber'}){ + die "Ordernumber, itemnumber and newitemnumber is required"; + } + + my $dbh = C4::Context->dbh; + + my $query = "UPDATE aqorders_items set itemnumber=? where itemnumber=? and ordernumber=?"; + my @params = ($orderiteminfo->{'newitemnumber'}, $orderiteminfo->{'itemnumber'}, $orderiteminfo->{'ordernumber'}); + warn $query; + warn Data::Dumper::Dumper(@params); + my $sth = $dbh->prepare($query); + $sth->execute(@params); + return 0; +} + +#------------------------------------------------------------# + + =head3 ModOrderBibliotemNumber =over 4 diff --git a/cataloguing/moveitem.pl b/cataloguing/moveitem.pl index 1461a00032..a461600ef0 100755 --- a/cataloguing/moveitem.pl +++ b/cataloguing/moveitem.pl @@ -29,6 +29,7 @@ use C4::Context; use C4::Koha; use C4::Branch; use C4::ClassSource; +use C4::Acquisition qw/GetOrderFromItemnumber ModOrder GetOrder ModOrderItem/; use Date::Calc qw(Today); @@ -63,38 +64,55 @@ if ($barcode && $biblionumber) { my $itemnumber = GetItemnumberFromBarcode($barcode); if ($itemnumber) { - # And then, we get the item - my $item = GetItem($itemnumber); - - if ($item) { - - my $results = GetBiblioFromItemNumber($itemnumber, $barcode); - my $frombiblionumber = $results->{'biblionumber'}; - - my $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber); - if ($moveresult) { - $template->param(success => 1); - } else { - $template->param(error => 1, - errornonewitem => 1); - } - - - } else { - $template->param(error => 1, - errornoitem => 1); - } + my $item = GetItem($itemnumber); + + if ($item) { + + # We delete the item from the old record (we can't delete afterwards, because of constraint on barcode duplicity) + my $results = GetBiblioFromItemNumber($itemnumber, $barcode); + my $frombiblionumber = $results->{'biblionumber'}; + + my $order = GetOrderFromItemnumber($itemnumber); + if ($order){ + $order->{'biblionumber'} = $biblionumber; + ModOrder($order); + } + + if ($frombiblionumber) { + DelItem(C4::Context->dbh, $frombiblionumber, $itemnumber); + } + + # We add the item to the requested record + my ($biblionumber, $biblioitemnumber, $newitemnumber) = AddItem($item, $biblionumber); + + if ($order){ + my $orderitem = { + ordernumber => $order->{'ordernumber'}, + itemnumber => $itemnumber, + newitemnumber => $newitemnumber, + }; + ModOrderItem($orderitem); + } + + if ($newitemnumber) { + $template->param(success => 1); + } else { + $template->param(error => 1, + errornonewitem => 1); + } + } else { + $template->param(error => 1, + errornoitem => 1); + } } else { - $template->param(error => 1, - errornoitemnumber => 1); - + $template->param(error => 1, + errornoitemnumber => 1); } $template->param( barcode => $barcode, itemnumber => $itemnumber, ); - } else { $template->param(missingparameter => 1); if (!$barcode) { $template->param(missingbarcode => 1); } -- 2.39.5