[Koha-patches] [PATCH] Bug 11206 - Factorize code for getting orders in C4::Acquisitions

Mathieu Saby mathieu.saby at univ-rennes2.fr
Wed Nov 6 10:35:26 CET 2013


Content-Type: text/plain; charset="utf-8"

This patch adds a new sub C4::Acquisition::_get_orders_with_params
This sub is now called by
- GetOrder
- GetOrders
- GetCancelledOrders
- GetOrdersByBiblionumber
- GetOrderFromItemnumber
- SearchOrder

It also makes changes to  acqui/lateorders-export.pl, .../prog/en/modules/acqui/csv/lateorders.tt and .../prog/en/modules/acqui/lateorders.tt to take into account some variable renaming

Next step : use it in GetLateOrders

---
 C4/Acquisition.pm                                  |  410 ++++++++------------
 acqui/lateorders-export.pl                         |   16 +-
 .../prog/en/modules/acqui/csv/lateorders.tt        |    2 +-
 .../prog/en/modules/acqui/lateorders.tt            |   24 +-
 4 files changed, 191 insertions(+), 261 deletions(-)

diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index aabc0ed..9e3e8de 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -85,29 +85,6 @@ BEGIN {
 }
 
 
-
-
-
-sub GetOrderFromItemnumber {
-    my ($itemnumber) = @_;
-    my $dbh          = C4::Context->dbh;
-    my $query        = qq|
-
-    SELECT  * from aqorders    LEFT JOIN aqorders_items
-    ON (     aqorders.ordernumber = aqorders_items.ordernumber   )
-    WHERE itemnumber = ?  |;
-
-    my $sth = $dbh->prepare($query);
-
-#    $sth->trace(3);
-
-    $sth->execute($itemnumber);
-
-    my $order = $sth->fetchrow_hashref;
-    return ( $order  );
-
-}
-
 # Returns the itemnumber(s) associated with the ordernumber given in parameter
 sub GetItemnumbersFromOrder {
     my ($ordernumber) = @_;
@@ -127,9 +104,6 @@ sub GetItemnumbersFromOrder {
 
 
 
-
-
-
 =head1 NAME
 
 C4::Acquisition - Koha functions for dealing with orders and acquisitions
@@ -1017,6 +991,116 @@ sub GetBasketgroups {
 
 =head2 FUNCTIONS ABOUT ORDERS
 
+=head3 _get_orders_with_params
+
+  $results = _get_orders_with_params ([$params]);
+
+Non exported 
+$params is an optional hashref
+if no $params, $results return a hashref describing all the orders, cancelled or not
+$param can contain :
+- $ordernumber
+- $biblionumber
+- $basket_id
+- $basketgroup_id
+- $supplier_id
+- \@status_list : a list of status to filter on (active, cancelled)
+- $orderby : a key for ordering results
+
+=cut
+
+sub _get_orders_with_params {
+    my ($params) =@_;
+    my $dbh   = C4::Context->dbh;
+    my $query  =qq{
+        SELECT aqorders.*,
+            biblio.title,
+            biblio.author,
+            biblio.unititle,
+            biblio.notes                        AS biblio_notes,
+            biblio.serial,
+            biblio.seriestitle,
+            biblio.copyrightdate,
+            biblio.abstract,
+            biblioitems.itemtype,
+            biblioitems.publicationyear,
+            biblioitems.editionstatement,
+            biblioitems.publishercode,
+            biblioitems.isbn,
+            biblioitems.ean,
+            biblioitems.marcxml,
+            aqbasket.basketname                 AS basket_name,
+            aqbasket.basketno                   AS basket_id,
+            aqbasket.deliveryplace              AS basket_deliveryplace,
+            aqbasket.billingplace               AS basket_billingplace,
+            aqbasket.creationdate               AS basket_creationdate,
+            aqbasket.closedate                  AS basket_closedate,
+            aqbasketgroups.id                   AS basketgroup_id,
+            aqbasketgroups.name                 AS basketgroup_name,
+            aqbasketgroups.closed               AS basketgroup_closed,
+            aqbasketgroups.deliveryplace        AS basketgroup_deliveryplace,
+            aqbasketgroups.freedeliveryplace    AS basketgroup_freedeliveryplace,
+            aqbasketgroups.billingplace         AS basketgroup_billingplace,
+            borrowers.branchcode                AS borrower_branchcode,
+            aqbudgets.budget_name,
+            aqbooksellers.name                  AS supplier_name,
+            aqbooksellers.id                    AS supplier_id,
+            aqorders_transfers.ordernumber_from AS transferred_from,
+            aqorders_transfers.timestamp        AS transferred_from_timestamp,    
+            ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY)         AS estimateddeliverydate,
+            DATE(aqbasket.closedate)                                                     AS orderdate,
+            aqorders.quantity - COALESCE(aqorders.quantityreceived,0)                    AS quantity_to_receive,
+            (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp   AS rrp_subtotal_to_receive,
+            (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.ecost AS ecost_subtotal_to_receive,
+            DATEDIFF(CURDATE( ),aqbasket.closedate)                                      AS latesince                
+            FROM aqorders
+            LEFT JOIN biblio             ON biblio.biblionumber = aqorders.biblionumber
+            LEFT JOIN biblioitems        ON biblioitems.biblionumber = biblio.biblionumber
+            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
+            LEFT JOIN aqorders_items     ON aqorders.ordernumber = aqorders_items.ordernumber
+            LEFT JOIN aqbasket           ON aqbasket.basketno = aqorders.basketno
+            LEFT JOIN aqbooksellers      ON aqbasket.booksellerid = aqbooksellers.id
+            LEFT JOIN aqbasketgroups     ON aqbasket.basketgroupid = aqbasketgroups.id
+            LEFT JOIN aqbudgets          ON aqorders.budget_id = aqbudgets.budget_id            
+            LEFT JOIN borrowers          ON aqbasket.authorisedby = borrowers.borrowernumber
+        };
+    my @list_for_where;    
+    push @list_for_where, "aqorders.ordernumber=".$params->{ordernumber}      if defined $params->{ordernumber};
+    push @list_for_where, "aqorders.biblionumber".$params->{biblionumber}     if defined $params->{biblionumber};
+    push @list_for_where, "aqorders.basketno=".$params->{basket_id}           if defined $params->{basket_id};
+    push @list_for_where, "aqbasket.basketgroupid=".$params->{basketgroup_id} if defined $params->{basketgroup_id};
+    push @list_for_where, "aqorders_items.itemnumber=".$params->{itemnumber}  if defined $params->{itemnumber};
+    push @list_for_where, "aqbasket.booksellerid=".$params->{supplier_id}     if defined $params->{supplier_id};
+    push @list_for_where, "aqbasket.basketname LIKE".$params->{basket_name}   if defined $params->{basket_name};
+    push @list_for_where, "aqbasketgroups.name LIKE".$params->{basketgroup_name}   if defined $params->{basketgroup_name};
+    push @list_for_where, "aqbasket.authorisedby=".$params->{borrowernumber}  if defined $params->{borrowernumber};
+    push @list_for_where, "biblioitems.ean LIKE ".$params->{ean}              if defined $params->{ean};
+    push @list_for_where, "biblioitems.isbn LIKE ".$params->{isbn}            if defined $params->{isbn};
+    push @list_for_where, "biblio.title LIKE ".$params->{title}               if defined $params->{title};
+    push @list_for_where, "biblio.author LIKE ".$params->{author}             if defined $params->{author};
+    push @list_for_where, "(biblio.title LIKE ".$params->{multisearch}." OR biblio.author LIKE ".$params->{multisearch}." OR biblioitems.isbn LIKE ".$params->{multisearch}.")" if defined $params->{multisearch};
+    push @list_for_where, "(borrowers.branchcode = ".$params->{borrower_branchcode}." OR borrowers.branchcode  = '')" if defined $params->{borrower_branchcode};
+    push @list_for_where, "aqorders.orderstatus IN (\"".(join "\",\"",@{$params->{include_status}})."\")"    if defined $params->{include_status};
+    push @list_for_where, "aqorders.orderstatus NOT IN (\"".(join "\",\"",@{$params->{exclude_status}})."\")"    if defined $params->{exclude_status};
+    push @list_for_where, "(quantity > quantityreceived OR quantityreceived is NULL)" if defined $params->{pending};
+    $query .=  "WHERE ".join " AND ", at list_for_where if (scalar @list_for_where > 0 );    
+    $query .= " ORDER BY ".$params->{orderby} if defined $params->{orderby};
+ warn $query;
+    my $sth = $dbh->prepare($query);
+    $sth->execute;
+    my $results = $sth->fetchall_arrayref({});
+    return $results;   
+}
+
+
+sub GetOrderFromItemnumber {
+    my ($itemnumber) = @_;
+    my $param = {itemnumber=>$itemnumber};
+    my $results = _get_orders_with_params ($param);
+    return if scalar @$results != 1;
+    return $$results[0];
+}
+
 =head3 GetOrders
 
   @orders = &GetOrders($basketnumber, $orderby);
@@ -1034,29 +1118,8 @@ biblio, and biblioitems tables in the Koha database.
 
 sub GetOrders {
     my ( $basketno, $orderby ) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query  ="
-        SELECT biblio.*,biblioitems.*,
-                aqorders.*,
-                aqbudgets.*,
-                biblio.title,
-                aqorders_transfers.ordernumber_from AS transferred_from,
-                aqorders_transfers.timestamp AS transferred_from_timestamp
-        FROM    aqorders
-            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
-            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
-            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
-            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
-        WHERE   basketno=?
-            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
-    ";
-
-    $orderby = "biblioitems.publishercode,biblio.title" unless $orderby;
-    $query .= " ORDER BY $orderby";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($basketno);
-    my $results = $sth->fetchall_arrayref({});
-    $sth->finish;
+    my $param = {basket_id=>$basketno,orderby=>"biblioitems.publishercode,biblio.title",exclude_status=>['cancelled']};
+    my $results = _get_orders_with_params ($param);
     return @$results;
 }
 
@@ -1076,25 +1139,13 @@ fields from the aqorders, biblio, and biblioitems tables in the Koha database.
 
 sub GetOrdersByBiblionumber {
     my $biblionumber = shift;
-    return unless $biblionumber;
-    my $dbh   = C4::Context->dbh;
-    my $query  ="
-        SELECT biblio.*,biblioitems.*,
-                aqorders.*,
-                aqbudgets.*
-        FROM    aqorders
-            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
-            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
-            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
-        WHERE   aqorders.biblionumber=?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($biblionumber);
-    my $results = $sth->fetchall_arrayref({});
-    $sth->finish;
+    return unless $biblionumber;    
+    my $param = {biblionumber=>$biblionumber,exclude_status=>['cancelled']};
+    my $results = _get_orders_with_params ($param);
     return @$results;
 }
 
+
 #------------------------------------------------------------#
 
 =head3 GetOrder
@@ -1103,53 +1154,29 @@ sub GetOrdersByBiblionumber {
 
 Looks up an order by order number.
 
-Returns a reference-to-hash describing the order. The keys of
-C<$order> are fields from the biblio, biblioitems, aqorders tables of the Koha database.
+Returns a reference-to-hash describing the order. The keys of C<$order> are :
+- all the fields from the aqorder table
+- some fields from biblio and biblioitems (biblio.notes returned as biblio_notes),
+- budget : the budget name (aqbudgets.budget_name)
+- supplier : the supplier's name (aqbooksellers.name)
+- supplierid : the supplier's id (aqbooksellers.id)
+- basketname : the basket name (aqbasket.basketname)
+- borrower_branchcode : the branchcode of the borrower managing the basket
+- estimateddeliverydate : ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY)
+- orderdate : the date of the closure of the basket DATE(aqbasket.closedate)
+- quantity_to_receive
+- rrp_subtotal and ecost_subtotal : the sum of prices of items yet to received (without gst management)
+- latesince : DATEDIFF(CURDATE( ),closedate)
 
 =cut
 
 sub GetOrder {
     my ($ordernumber) = @_;
-    my $dbh      = C4::Context->dbh;
-    my $query = qq{SELECT
-                aqorders.*,
-                biblio.title,
-                biblio.author,
-                aqbasket.basketname,
-                borrowers.branchcode,
-                biblioitems.publicationyear,
-                biblio.copyrightdate,
-                biblioitems.editionstatement,
-                biblioitems.isbn,
-                biblioitems.ean,
-                biblio.seriestitle,
-                biblioitems.publishercode,
-                aqorders.rrp              AS unitpricesupplier,
-                aqorders.ecost            AS unitpricelib,
-                aqorders.claims_count     AS claims_count,
-                aqorders.claimed_date     AS claimed_date,
-                aqbudgets.budget_name     AS budget,
-                aqbooksellers.name        AS supplier,
-                aqbooksellers.id          AS supplierid,
-                biblioitems.publishercode AS publisher,
-                ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate,
-                DATE(aqbasket.closedate)  AS orderdate,
-                aqorders.quantity - COALESCE(aqorders.quantityreceived,0)                 AS quantity_to_receive,
-                (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
-                DATEDIFF(CURDATE( ),closedate) AS latesince
-                FROM aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
-                LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
-                LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id,
-                aqbasket LEFT JOIN borrowers  ON aqbasket.authorisedby = borrowers.borrowernumber
-                LEFT JOIN aqbooksellers       ON aqbasket.booksellerid = aqbooksellers.id
-                WHERE aqorders.basketno = aqbasket.basketno
-                    AND ordernumber=?};
-    my $sth= $dbh->prepare($query);
-    $sth->execute($ordernumber);
-    my $data = $sth->fetchrow_hashref;
-    $data->{orderdate} = format_date( $data->{orderdate} );
-    $sth->finish;
-    return $data;
+    my $param = {ordernumber=>$ordernumber};
+    my $results = _get_orders_with_params ($param);
+    return if scalar @$results != 1;
+    $$results [0]->{orderdate} = format_date( $$results [0]->{orderdate} );
+    return $$results[0];
 }
 
 =head3 GetLastOrderNotReceivedFromSubscriptionid
@@ -1389,35 +1416,9 @@ Returns cancelled orders for a basket
 
 sub GetCancelledOrders {
     my ( $basketno, $orderby ) = @_;
-
     return () unless $basketno;
-
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT
-            biblio.*,
-            biblioitems.*,
-            aqorders.*,
-            aqbudgets.*,
-            aqorders_transfers.ordernumber_to AS transferred_to,
-            aqorders_transfers.timestamp AS transferred_to_timestamp
-        FROM aqorders
-          LEFT JOIN aqbudgets   ON aqbudgets.budget_id = aqorders.budget_id
-          LEFT JOIN biblio      ON biblio.biblionumber = aqorders.biblionumber
-          LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
-          LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_from = aqorders.ordernumber
-        WHERE basketno = ?
-          AND (datecancellationprinted IS NOT NULL
-               AND datecancellationprinted <> '0000-00-00')
-    ";
-
-    $orderby = "aqorders.datecancellationprinted desc, aqorders.timestamp desc"
-        unless $orderby;
-    $query .= " ORDER BY $orderby";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($basketno);
-    my $results = $sth->fetchall_arrayref( {} );
-
+    my $param = {basket_id=>$basketno,orderby=>"aqorders.datecancellationprinted desc, aqorders.timestamp desc",include_status=>['cancelled']};
+    my $results = _get_orders_with_params ($param);
     return @$results;
 }
 
@@ -1632,7 +1633,7 @@ sub CancelReceipt {
 
 =head3 SearchOrders
 
- at results = &SearchOrders({
+\@results = &SearchOrders({
     ordernumber => $ordernumber,
     search => $search,
     biblionumber => $biblionumber,
@@ -1648,102 +1649,29 @@ Searches for orders.
 C<$owner> Finds order for the logged in user.
 C<$pending> Finds pending orders. Ignores completed and cancelled orders.
 
-
-C<@results> is an array of references-to-hash with the keys are fields
+C<\@results> is an hashref to an array of references-to-hash with the keys are fields
 from aqorders, biblio, biblioitems and aqbasket tables.
 
 =cut
 
 sub SearchOrders {
     my ( $params ) = @_;
-    my $ordernumber = $params->{ordernumber};
-    my $search = $params->{search};
-    my $ean = $params->{ean};
-    my $booksellerid = $params->{booksellerid};
-    my $basketno = $params->{basketno};
-    my $basketname = $params->{basketname};
-    my $basketgroupname = $params->{basketgroupname};
-    my $owner = $params->{owner};
-    my $pending = $params->{pending};
-
-    my $dbh = C4::Context->dbh;
-    my @args = ();
-    my $query = q{
-        SELECT aqbasket.basketno,
-               borrowers.surname,
-               borrowers.firstname,
-               biblio.*,
-               biblioitems.isbn,
-               biblioitems.biblioitemnumber,
-               aqbasket.closedate,
-               aqbasket.creationdate,
-               aqbasket.basketname,
-               aqorders.*
-        FROM aqorders
-            LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
-            LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid = aqbasketgroups.id
-            LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
-            LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
-            LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
-        WHERE (datecancellationprinted is NULL)
-    };
-
-    $query .= q{
-        AND (quantity > quantityreceived OR quantityreceived is NULL)
-    } if $pending;
-
-    my $userenv = C4::Context->userenv;
-    if ( C4::Context->preference("IndependentBranches") ) {
-        if ( ( $userenv ) and ( $userenv->{flags} != 1 ) ) {
-            $query .= q{
-                AND (
-                    borrowers.branchcode = ?
-                    OR borrowers.branchcode  = ''
-                )
-            };
-            push @args, $userenv->{branch};
-        }
-    }
-
-    if ( $ordernumber ) {
-        $query .= ' AND (aqorders.ordernumber=?)';
-        push @args, $ordernumber;
-    }
-    if( $search ) {
-        $query .= ' AND (biblio.title LIKE ? OR biblio.author LIKE ? OR biblioitems.isbn LIKE ?)';
-        push @args, ("%$search%","%$search%","%$search%");
-    }
-    if ( $ean ) {
-        $query .= ' AND biblioitems.ean = ?';
-        push @args, $ean;
-    }
-    if ( $booksellerid ) {
-        $query .= 'AND aqbasket.booksellerid = ?';
-        push @args, $booksellerid;
-    }
-    if( $basketno ) {
-        $query .= 'AND aqbasket.basketno = ?';
-        push @args, $basketno;
-    }
-    if( $basketname ) {
-        $query .= 'AND aqbasket.basketname LIKE ?';
-        push @args, "%$basketname%";
-    }
-    if( $basketgroupname ) {
-        $query .= ' AND aqbasketgroups.name LIKE ?';
-        push @args, "%$basketgroupname%";
-    }
-
-    if ( $owner ) {
-        $query .= ' AND aqbasket.authorisedby=? ';
-        push @args, $userenv->{'number'};
-    }
-
-    $query .= ' ORDER BY aqbasket.basketno';
-
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@args);
-    return $sth->fetchall_arrayref({});
+    my $userenv = C4::Context->userenv;    
+    my $new_param = {basket_id=>$params->{basketno},
+                    ordernumber=>$params->{ordernumber},
+                    multisearch=>$params->{search},
+                    ean=>$params->{ean},
+                    supplier_id=> $params->{booksellerid},
+                    basket_id=> $params->{basketno},
+                    basket_name=> $params->{basketname},
+                    basketgroup_name=> $params->{basketgroupname},
+                    pending=> $params->{pending},
+                    orderby=>"aqbasket.basketno",                    
+                    exclude_status=>['cancelled']};
+    $new_param ->{borrowernumber} = $userenv->{'number'} if defined $params->{owner};
+    $new_param ->{borrower_branchcode} = $userenv->{branch} if (defined C4::Context->preference("IndependentBranches")) and ((defined $userenv ) and ( $userenv->{flags} != 1 ) );
+    my $results = _get_orders_with_params ($new_param);
+    return $results;
 }
 
 #------------------------------------------------------------#
@@ -2029,16 +1957,16 @@ sub GetLateOrders {
     SELECT aqbasket.basketno,
         aqorders.ordernumber,
         DATE(aqbasket.closedate)  AS orderdate,
-        aqorders.rrp              AS unitpricesupplier,
-        aqorders.ecost            AS unitpricelib,
-        aqorders.claims_count     AS claims_count,
-        aqorders.claimed_date     AS claimed_date,
+        aqorders.rrp,
+        aqorders.ecost,
+        aqorders.claims_count,
+        aqorders.claimed_date,
         aqbudgets.budget_name     AS budget,
-        borrowers.branchcode      AS branch,
+        borrowers.branchcode      AS borrower_branchcode,
         aqbooksellers.name        AS supplier,
         aqbooksellers.id          AS supplierid,
         biblio.author, biblio.title,
-        biblioitems.publishercode AS publisher,
+        biblioitems.publishercode,
         biblioitems.publicationyear,
         ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate,
     ";
@@ -2060,9 +1988,10 @@ sub GetLateOrders {
     my $having = "";
     if ($dbdriver eq "mysql") {
         $select .= "
-        aqorders.quantity - COALESCE(aqorders.quantityreceived,0)                 AS quantity,
-        (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
-        DATEDIFF(CAST(now() AS date),closedate) AS latesince
+        aqorders.quantity - COALESCE(aqorders.quantityreceived,0)                    AS quantity,
+        (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp   AS rrp_subtotal,
+        (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.ecost AS ecost_subtotal,
+        DATEDIFF(CAST(now() AS date),closedate)                                      AS latesince
         ";
         if ( defined $delay ) {
             $from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ;
@@ -2070,15 +1999,16 @@ sub GetLateOrders {
         }
         $having = "
         HAVING quantity          <> 0
-            AND unitpricesupplier <> 0
-            AND unitpricelib      <> 0
+            AND rrp <> 0
+            AND ecost      <> 0
         ";
     } else {
         # FIXME: account for IFNULL as above
         $select .= "
-                aqorders.quantity                AS quantity,
-                aqorders.quantity * aqorders.rrp AS subtotal,
-                (CAST(now() AS date) - closedate)            AS latesince
+                aqorders.quantity                  AS quantity,
+                aqorders.quantity * aqorders.rrp   AS rrp_subtotal,
+                aqorders.quantity * aqorders.ecost AS ecost_subtotal,
+                (CAST(now() AS date) - closedate)  AS latesince
         ";
         if ( defined $delay ) {
             $from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) ";
diff --git a/acqui/lateorders-export.pl b/acqui/lateorders-export.pl
index 585cac8..d554410 100755
--- a/acqui/lateorders-export.pl
+++ b/acqui/lateorders-export.pl
@@ -40,17 +40,17 @@ for my $ordernumber ( @ordernumbers ) {
             orderdate => $order->{orderdate},
             latesince => $order->{latesince},
             estimateddeliverydate => $order->{estimateddeliverydate},
-            supplier => $order->{supplier},
-            supplierid => $order->{supplierid},
+            supplier_name => $order->{supplier_name},
+            supplier_id => $order->{supplier_id},
             title => $order->{title},
             author => $order->{author},
-            publisher => $order->{publisher},
-            unitpricesupplier => $order->{unitpricesupplier},
+            publishercode => $order->{publishercode},
+            rrp => $order->{rrp},
             quantity_to_receive => $order->{quantity_to_receive},
-            subtotal => $order->{subtotal},
-            budget => $order->{budget},
-            basketname => $order->{basketname},
-            basketno => $order->{basketno},
+            rrp_subtotal_to_receive => $order->{rrp_subtotal_to_receive},
+            budget_name => $order->{budget_name},
+            basket_name => $order->{basket_name},
+            basket_id => $order->{basket_id},
             claims_count => $order->{claims_count},
             claimed_date => $order->{claimed_date},
         }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt
index 34d9db0..b543f4f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt
@@ -1,5 +1,5 @@
 [% USE KohaDates %][% INCLUDE csv_headers/acqui/lateorders.tt %]
-[% FOREACH o IN orders %]"[% o.orderdate %] ([% o.latesince %] days)","[% o.estimateddeliverydate | $KohaDates %]","[% o.supplier (o.supplierid) %]","[% o.title %] [% IF o.author %]Author: [% o.author %].[% END %][% IF o.publisher %]Published by: [% o.publisher %].[% END %]","[% o.unitpricesupplier %] x [% o.quantity_to_receive %] = [% o.subtotal %] ([% o.budget %])","[% o.basketname %] ([% o.basketno %])","[% o.claims_count %]","[% o.claimed_date %]"
+[% FOREACH o IN orders %]"[% o.orderdate %] ([% o.latesince %] days)","[% o.estimateddeliverydate | $KohaDates %]","[% o.supplier_name (o.supplier_id) %]","[% o.title %] [% IF o.author %]Author: [% o.author %].[% END %][% IF o.publishercode %]Published by: [% o.publishercode %].[% END %]","[% o.rrp %] x [% o.quantity_to_receive %] = [% o.rrp_subtotal_to_receive %] ([% o.budget_name %])","[% o.basket_name %] ([% o.basket_id %])","[% o.claims_count %]","[% o.claimed_date %]"
 [% END %]
 
 ,,Total orders in late, [% orders.size %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
index c76cf2d..be8396e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
@@ -106,7 +106,7 @@ $(document).ready(function() {
     <table id="late_orders">
       <thead>
         <tr>
-            [% IF Supplier %]
+            [% IF supplier_name %]
                 <th><a id="CheckAll" href="#">Check all</a><br /><a id="CheckNone" href="#">Uncheck all</a></th>
             [% ELSE %]
                 <th></th>
@@ -126,7 +126,7 @@ $(document).ready(function() {
         [% UNLESS ( loop.odd ) %]<tr class="highlight">
         [% ELSE %]<tr>[% END %]
             <td>
-                <input type="checkbox" value="[% lateorder.ordernumber %]" data-booksellerid="[% lateorder.supplierid %]" name="ordernumber">
+                <input type="checkbox" value="[% lateorder.ordernumber %]" data-booksellerid="[% lateorder.supplier_id %]" name="ordernumber">
             </td>
             <td>
                 [% lateorder.orderdate %]
@@ -138,30 +138,30 @@ $(document).ready(function() {
                 [% END %]
             </td>
             <td>
-                [% lateorder.supplier %]
-                ([% lateorder.supplierid %])
+                [% lateorder.supplier_name %]
+                ([% lateorder.supplier_id %])
             </td>
             <td>
                 <b>[% lateorder.title |html %]</b>
                    [% IF ( lateorder.author ) %]<br/><i>Author:</i> [% lateorder.author %][% END %]
-                   [% IF ( lateorder.publisher ) %]
-                        <br/><i>Published by:</i> [% lateorder.publisher %]
+                   [% IF ( lateorder.publishercode ) %]
+                        <br/><i>Published by:</i> [% lateorder.publishercode %]
                         [% IF ( lateorder.publicationyear ) %]
                             <i> in </i>[% lateorder.publicationyear %]
                         [% END %]
                    [% END %]
             </td>
             <td>
-                   [% lateorder.unitpricesupplier %]x[% lateorder.quantity %] = 
-                   [% lateorder.subtotal %]
-                    <p title="budget">[% lateorder.budget %]</p>
+                   [% lateorder.rrp %]x[% lateorder.quantity %] = 
+                   [% lateorder.rrp_subtotal_to_receive %]
+                    <p title="budget">[% lateorder.budget_name %]</p>
             </td>
             <td>
-                 <p><a href="basket.pl?basketno=[% lateorder.basketno %]" title="basket">
-                        [% lateorder.basketno %]
+                 <p><a href="basket.pl?basketno=[% lateorder.basket_id %]" title="basket">
+                        [% lateorder.basket_id %]
                  	</a>
                  </p>
-                 <p title="branch">[% lateorder.branch %]</p>
+                 <p title="branch">[% lateorder.borrower_branchcode %]</p>
             </td>
             <td>[% lateorder.claims_count %]</td>
             <td>[% lateorder.claimed_date %]</td>
-- 
1.7.9.5


-- 
Mathieu Saby
Service d'Informatique Documentaire
Service Commun de la Documentation
Université Rennes 2
Téléphone : 02 99 14 12 65
Courriel : mathieu.saby at univ-rennes2.fr



More information about the Koha-patches mailing list