koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 Acquisition.pm [dev_week]


From: Ryan Higgins
Subject: [Koha-cvs] koha/C4 Acquisition.pm [dev_week]
Date: Tue, 13 Feb 2007 15:03:06 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Ryan Higgins <rych>     07/02/13 15:03:06

Modified files:
        C4             : Acquisition.pm 

Log message:
        If partial order is received in parcel, it is split into received order 
and new order
        so that order details are preserved across parcels.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Acquisition.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.9.2.16.2.1&r2=1.9.2.16.2.2

Patches:
Index: Acquisition.pm
===================================================================
RCS file: /sources/koha/koha/C4/Acquisition.pm,v
retrieving revision 1.9.2.16.2.1
retrieving revision 1.9.2.16.2.2
diff -u -b -r1.9.2.16.2.1 -r1.9.2.16.2.2
--- Acquisition.pm      27 Jul 2006 15:41:16 -0000      1.9.2.16.2.1
+++ Acquisition.pm      13 Feb 2007 15:03:06 -0000      1.9.2.16.2.2
@@ -87,7 +87,7 @@
 sub getbasket {
        my ($basketno)address@hidden;
        my $dbh=C4::Context->dbh;
-       my $sth=$dbh->prepare("select aqbasket.*,borrowers.firstname+' 
'+borrowers.surname as authorisedbyname from aqbasket left join borrowers on 
aqbasket.authorisedby=borrowers.borrowernumber where basketno=?");
+       my $sth=$dbh->prepare("select aqbasket.*,concat(borrowers.firstname,' 
',borrowers.surname) as authorisedbyname from aqbasket left join borrowers on 
aqbasket.authorisedby=borrowers.borrowernumber where basketno=?");
        $sth->execute($basketno);
        return($sth->fetchrow_hashref);
 }
@@ -288,7 +288,8 @@
 
 =cut
 #'
-# FIXME - Race condition
+# FIXME - Race condition  - why not auto_increment?
+
 sub newordernum {
   my $dbh = C4::Context->dbh;
   my $sth=$dbh->prepare("Select max(ordernumber) from aqorders");
@@ -310,6 +311,9 @@
 in part. All arguments not mentioned below update the fields with the
 same name in the aqorders table of the Koha database.
 
+If a partial order is received, splits the order into two.  The received
+portion must have a booksellerinvoicenumber.  
+
 Updates the order with bibilionumber C<$biblionumber> and ordernumber
 C<$ordernumber>.
 
@@ -325,15 +329,36 @@
         my ($year,$month,$day) = Today();
         $datereceived = "$year-$month-$day";
     }
-       my $sth=$dbh->prepare("update aqorders set 
quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
-                                                                               
        unitprice=?,freight=?,rrp=?
+   my $sth=$dbh->prepare("SELECT * FROM aqorders WHERE biblionumber=? AND 
ordernumber=?");
+   $sth->execute($biblio,$ordnum);                                             
                            
+   my $order = $sth->fetchrow_hashref();  
+   $sth->finish();            
+       if ( $order->{quantity} > $quantrec ) {
+               $sth=$dbh->prepare("update aqorders set 
quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, 
unitprice=?,freight=?,rrp=?,quantity=?
+                                                       where biblionumber=? 
and ordernumber=?");
+               
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblio,$ordnum);
+           $sth->finish;
+               # create a new order for the remaining items, and set its 
bookfund.
+               my $newOrder = 
neworder($order->{'basketno'},$order->{'biblionumber'},$order->{'title'}, 
$order->{'quantity'} - $quantrec,    
+                                       
$order->{'listprice'},$order->{'booksellerid'},$order->{'authorisedby'},$order->{'notes'},
   
+                                       
$order->{'bookfund'},$order->{'biblioitemnumber'},$order->{'rrp'},$order->{'ecost'},
  
+                                       
$order->{'budget'},$order->{'sub'},'',$order->{'sort1'},$order->{'sort2'});    
+               $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);
+       } else {
+               $sth=$dbh->prepare("update aqorders set 
quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,    
unitprice=?,freight=?,rrp=?
                                                        where biblionumber=? 
and ordernumber=?");
+               
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblio,$ordnum);
+       $sth->finish;
+       }
        my $suggestionid = findsuggestion_from_biblionumber($dbh,$biblio);
        if ($suggestionid) {
                changestatus($suggestionid,'AVAILABLE','',$biblio);
        }
-       
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblio,$ordnum);
-    $sth->finish;
     return $datereceived;
 }
 
@@ -351,13 +376,10 @@
 
 =cut
 #'
-sub updaterecorder{
+sub updaterecorder {
   my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)address@hidden;
   my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("update aqorders set
-  unitprice=?, rrp=?
-  where biblionumber=? and ordernumber=?
-  ");
+  my $sth=$dbh->prepare("update aqorders set  unitprice=?, rrp=? where 
biblionumber=? and ordernumber=? ");
   $sth->execute($cost,$rrp,$biblio,$ordnum);
   $sth->finish;
   $sth=$dbh->prepare("update aqorderbreakdown set bookfundid=? where 
ordernumber=?");
@@ -503,8 +525,8 @@
   my ($supplierid)address@hidden;
   my $dbh = C4::Context->dbh;
   my @results = ();
-       my $strsth ="Select 
count(*),authorisedby,creationdate,aqbasket.basketno,
-closedate,surname,firstname,aqorders.biblionumber,aqorders.title, 
aqorders.ordernumber 
+       my $strsth ="Select authorisedby,creationdate,aqbasket.basketno,
+closedate,surname,firstname,aqorders.biblionumber,aqorders.title, 
aqorders.ordernumber, quantity, quantityreceived
 from aqorders 
 left join aqbasket on aqbasket.basketno=aqorders.basketno 
 left join borrowers on aqbasket.authorisedby=borrowers.borrowernumber
@@ -517,10 +539,17 @@
                        $strsth .= " and (borrowers.branchcode = 
'".$userenv->{branch}."' or borrowers.branchcode ='')";
                }
        }
-       $strsth.=" group by basketno order by aqbasket.basketno";
+       $strsth.=" order by aqbasket.basketno";
        my $sth=$dbh->prepare($strsth);
   $sth->execute($supplierid);
+  my $sth_received=$dbh->prepare("select quantityreceived from aqorders where 
basketno=? and title=? and quantity=quantityreceived");
   while (my $data=$sth->fetchrow_hashref){
+       $sth_received->execute($data->{'basketno'},$data->{'title'});
+       my $receivedfrombasket;
+       while (my ($qrec) = $sth_received->fetchrow_array) {
+               $receivedfrombasket += $qrec;
+    }
+       $data->{'receivedinbasket'}= $receivedfrombasket;
     push(@results,$data);
   }
   $sth->finish;
@@ -541,13 +570,19 @@
 
 =cut
 #'
+#
+# FIXME - we're storing freight with each order, which makes no sense.
+#  need to add a parcel table to db or make a 'basket' synonmyous with a 
'parcel'.
+#  
 sub getparcelinformation {
   #gets all orders from a certain supplier, orders them alphabetically
   my ($supplierid,$code, $datereceived)address@hidden;
   my $dbh = C4::Context->dbh;
   my @results = ();
   $code .='%' if $code; # add % if we search on a given code (otherwise, let 
him empty)
-       my $strsth ="Select 
authorisedby,creationdate,aqbasket.basketno,closedate,surname,firstname,aqorders.biblionumber,aqorders.title,aqorders.ordernumber,
 aqorders.quantity, aqorders.quantityreceived, aqorders.unitprice, 
aqorders.listprice, aqorders.rrp, aqorders.ecost from aqorders,aqbasket left 
join borrowers on aqbasket.authorisedby=borrowers.borrowernumber where 
aqbasket.basketno=aqorders.basketno and aqbasket.booksellerid=? and 
aqorders.booksellerinvoicenumber like  \"$code\" and aqorders.datereceived= 
\'$datereceived\'";
+       my $strsth ="Select freight, 
authorisedby,creationdate,aqbasket.basketno,closedate,surname,firstname,aqorders.biblionumber,aqorders.title,aqorders.ordernumber,
 aqorders.quantity, aqorders.quantityreceived, aqorders.unitprice, 
aqorders.listprice, aqorders.rrp, aqorders.ecost 
+                               from aqorders,aqbasket left join borrowers on 
aqbasket.authorisedby=borrowers.borrowernumber 
+                               where aqbasket.basketno=aqorders.basketno and 
aqbasket.booksellerid=? and aqorders.booksellerinvoicenumber like  \"$code\" 
and aqorders.datereceived= \'$datereceived\'";
                
        if (C4::Context->preference("IndependantBranches")) {
                my $userenv = C4::Context->userenv;
@@ -796,8 +831,8 @@
                $query .= " and biblio.title like ".$dbh->quote("%".$title."%") 
if $title;
                $query .= " and biblio.author like 
".$dbh->quote("%".$author."%") if $author;
                $query .= " and name like ".$dbh->quote("%".$name."%") if $name;
-               $query .= " and creationdate >" .$dbh->quote($from_placed_on) 
if $from_placed_on;
-               $query .= " and creationdate<".$dbh->quote($to_placed_on) if 
$to_placed_on;
+               $query .= " and creationdate >=" .$dbh->quote($from_placed_on) 
if $from_placed_on;
+               $query .= " and creationdate=<".$dbh->quote($to_placed_on) if 
$to_placed_on;
                if (C4::Context->preference("IndependantBranches")) {
                        my $userenv = C4::Context->userenv;
                        if (($userenv) &&($userenv->{flags} != 1)){
@@ -908,7 +943,7 @@
 sub bookfundbreakdown {
   my ($id, $year)address@hidden;
   my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("SELECT startdate, enddate, quantity, datereceived, 
freight, unitprice, listprice, ecost, quantityreceived, subscription
+  my $sth=$dbh->prepare("SELECT startdate, enddate, quantity, datereceived, 
aqorders.booksellerinvoicenumber as invoice, aqorders.ordernumber, freight, 
unitprice, listprice, ecost, quantityreceived, subscription
 FROM aqorders, aqorderbreakdown, aqbudget, aqbasket
 WHERE aqorderbreakdown.bookfundid = ?
 AND aqorders.ordernumber = aqorderbreakdown.ordernumber
@@ -924,6 +959,8 @@
   $sth->execute($id);
   my $comtd=0;
   my $spent=0;
+  my %invoiceseen;
+  my $totalfreight = 0;
   while (my $data=$sth->fetchrow_hashref){
     if ($data->{'subscription'} == 1){
       $spent+=$data->{'quantity'}*$data->{'unitprice'};
@@ -932,9 +969,13 @@
       $comtd+=($data->{'ecost'})*$leftover;
       $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
     }
+       unless ($invoiceseen{$data->{'invoice'}}) {
+               $invoiceseen{$data->{'invoice'}}++;
+               $totalfreight += $data->{'freight'};
+       }
   }
   $sth->finish;
-  return($spent,$comtd);
+  return($spent,$comtd,$totalfreight);
 }
 
 
@@ -1178,7 +1219,7 @@
 sub getparcels {
   my ($bookseller, $order, $code,$datefrom,$dateto, $limit)address@hidden;
        my $dbh = C4::Context->dbh;
-       my $strsth = "SELECT aqorders.booksellerinvoicenumber, datereceived, 
count(DISTINCT biblionumber) as biblio, sum(quantity) as itemsexpected, 
sum(quantityreceived) as itemsreceived from aqorders, aqbasket where 
aqbasket.basketno = aqorders.basketno and aqbasket.booksellerid = $bookseller 
and datereceived is not null ";
+       my $strsth = "SELECT aqorders.purchaseordernumber, 
aqorders.booksellerinvoicenumber, datereceived, count(DISTINCT biblionumber) as 
biblio, sum(quantity) as itemsexpected, sum(quantityreceived) as itemsreceived 
from aqorders, aqbasket where aqbasket.basketno = aqorders.basketno and 
aqbasket.booksellerid = $bookseller and datereceived is not null ";
        $strsth .= "and aqorders.booksellerinvoicenumber like \"$code%\" " if 
($code);
        $strsth .= "and datereceived >=".$dbh->quote($datefrom)." " if 
($datefrom);
        $strsth .= "and datereceived <=".$dbh->quote($dateto)." " if ($dateto);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]