VirtualShelves.pm - expanded SQL for shelf contents, fixes bug of no itemtypes displa...
[koha.git] / C4 / Acquisition.pm
index b4b2655..51a3dcb 100644 (file)
@@ -19,7 +19,6 @@ package C4::Acquisition;
 
 
 use strict;
-require Exporter;
 use C4::Context;
 use C4::Dates qw(format_date);
 use MARC::Record;
@@ -28,8 +27,20 @@ use Time::localtime;
 
 use vars qw($VERSION @ISA @EXPORT);
 
-# set the version for version checking
-$VERSION = 3.01;
+BEGIN {
+       # set the version for version checking
+       $VERSION = 3.01;
+       require Exporter;
+       @ISA    = qw(Exporter);
+       @EXPORT = qw(
+               &GetBasket &NewBasket &CloseBasket
+               &GetPendingOrders &GetOrder &GetOrders
+               &GetOrderNumber &GetLateOrders &NewOrder &DelOrder
+               &SearchOrder &GetHistory &GetRecentAcqui
+               &ModOrder &ModReceiveOrder &ModOrderBiblioNumber
+               &GetParcels &GetParcel
+       );
+}
 
 # used in receiveorder subroutine
 # to provide library specific handling
@@ -52,26 +63,10 @@ orders, basket and parcels.
 
 =over 2
 
-=cut
-
-@ISA    = qw(Exporter);
-@EXPORT = qw(
-  &GetBasket &NewBasket &CloseBasket
-  &GetPendingOrders &GetOrder &GetOrders
-  &GetOrderNumber &GetLateOrders &NewOrder &DelOrder
-  &SearchOrder &GetHistory &GetRecentAcqui
-  &ModOrder &ModReceiveOrder &ModOrderBiblioNumber
-  &GetParcels &GetParcel
-);
-
 =head2 FUNCTIONS ABOUT BASKETS
 
 =over 2
 
-=cut
-
-#------------------------------------------------------------#
-
 =head3 GetBasket
 
 =over 4
@@ -595,6 +590,22 @@ sub ModReceiveOrder {
 #    $daterecieved=POSIX::strftime("%Y-%m-%d",CORE::localtime) unless $daterecieved;
 #     warn "DATE REC : $daterecieved";
        $datereceived = C4::Dates->output('iso') unless $datereceived;
+    my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
+    if ($suggestionid) {
+        ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
+    }
+    # Allows libraries to change their bookfund during receiving orders
+    # allows them to adjust budgets
+    if ( C4::Context->preference("LooseBudgets") && $bookfund ) {
+        my $query = "
+            UPDATE aqorderbreakdown
+            SET    bookfundid=?
+            WHERE  ordernumber=?
+        ";
+        my $sth = $dbh->prepare($query);
+        $sth->execute( $bookfund, $ordnum );
+        $sth->finish;
+    }
    
        my $sth=$dbh->prepare("SELECT * FROM aqorders  LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
                                                        WHERE biblionumber=? AND aqorders.ordernumber=?");
@@ -615,12 +626,8 @@ sub ModReceiveOrder {
                     $order->{'bookfundid'},$order->{'biblioitemnumber'},$order->{'rrp'},$order->{'ecost'},$order->{'gst'},
                     $order->{'budget'},$order->{'unitcost'},$order->{'sub'},'',$order->{'sort1'},$order->{'sort2'},$order->{'purchaseordernumber'});
     
-        $sth = $dbh->prepare("select branchcode, bookfundid from aqorderbreakdown where ordernumber=?");
-        $sth->execute($ordnum);
-        my ($branch,$bookfund) = $sth->fetchrow_array;
-        $sth->finish;
         $sth=$dbh->prepare(" insert into aqorderbreakdown (ordernumber, branchcode, bookfundid) values (?,?,?)"); 
-        $sth->execute($newOrder,$branch,$bookfund);
+        $sth->execute($newOrder,$order->{branch},$order->{bookfundid});
     } else {
         $sth=$dbh->prepare("update aqorders 
                                                        set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, 
@@ -629,22 +636,6 @@ sub ModReceiveOrder {
         $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordnum);
         $sth->finish;
     }
-    my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
-    if ($suggestionid) {
-        ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
-    }
-    # Allows libraries to change their bookfund during receiving orders
-    # allows them to adjust budgets
-    if ( C4::Context->preference("LooseBudgets") ) {
-        my $query = "
-            UPDATE aqorderbreakdown
-            SET    bookfundid=?
-            WHERE  ordernumber=?
-        ";
-        my $sth = $dbh->prepare($query);
-        $sth->execute( $bookfund, $ordnum );
-        $sth->finish;
-    }
     return $datereceived;
 }
 #------------------------------------------------------------#
@@ -865,7 +856,7 @@ sub GetParcel {
     }
     $strsth .= " ORDER BY aqbasket.basketno";
     ### parcelinformation : $strsth
-    warn "STH : $strsth";
#   warn "STH : $strsth";
     my $sth = $dbh->prepare($strsth);
     $sth->execute($supplierid);
     while ( my $data = $sth->fetchrow_hashref ) {
@@ -1179,10 +1170,7 @@ sub GetRecentAcqui {
     return \@results;
 }
 
-END { }    # module clean-up code here (global destructor)
-
 1;
-
 __END__
 
 =back