Bug 8037: Display holds & fund on the already received table on order receipt summary
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 28 Mar 2012 17:33:36 +0000 (13:33 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 31 Oct 2013 14:53:07 +0000 (14:53 +0000)
Adds a column to indicate holds on received items, as well as adding
a new column for fund and showing the subtotals per fund above
the total subtotal.

To test:

[1] Create an order basket containing at least one title and
    ensure that an item is created for that title.  Close the
    basket.
[2] Place a hold on the title.
[3] Receive the order.  After receiving it, but before finishing
    the invoice, the table of already received orders should now
    have columns for the order budget and number of holds on the
    title as well as lines with the subtotal per fund.

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Acquisition.pm
C4/Budgets.pm
C4/Reserves.pm
acqui/parcel.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt

index 8c40dcd..88783e7 100644 (file)
@@ -2460,11 +2460,12 @@ sub GetInvoiceDetails {
     my $invoice = $sth->fetchrow_hashref;
 
     $query = qq{
-        SELECT aqorders.*, biblio.*,
+        SELECT aqorders.*, biblio.*, aqorders_items.itemnumber,
         aqbasket.basketname
         FROM aqorders
           LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
           LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
+          LEFT JOIN aqorders_items ON aqorders.ordernumber = aqorders_items.ordernumber
         WHERE invoiceid = ?
     };
     $sth = $dbh->prepare($query);
index a648773..334e610 100644 (file)
@@ -34,6 +34,7 @@ BEGIN {
        @EXPORT = qw(
 
         &GetBudget
+        &GetBudgetByOrderNumber
         &GetBudgets
         &GetBudgetHierarchy
            &AddBudget
@@ -672,6 +673,30 @@ sub GetBudget {
     return $result;
 }
 
+=head2 GetBudgetByOrderNumber
+
+  &GetBudgetByOrderNumber($ordernumber);
+
+get a specific budget by order number
+
+=cut
+
+# -------------------------------------------------------------------
+sub GetBudgetByOrderNumber {
+    my ( $ordernumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $query = "
+        SELECT aqbudgets.*
+        FROM   aqbudgets, aqorders
+        WHERE  ordernumber=?
+        AND    aqorders.budget_id = aqbudgets.budget_id
+        ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $ordernumber );
+    my $result = $sth->fetchrow_hashref;
+    return $result;
+}
+
 =head2 GetChildBudgetsSpent
 
   &GetChildBudgetsSpent($budget-id);
index f8666a3..9826f2c 100644 (file)
@@ -277,9 +277,12 @@ of the reserves and an arrayref pointing to the reserves for C<$biblionumber>.
 sub GetReservesFromBiblionumber {
     my ($biblionumber) = shift or return (0, []);
     my ($all_dates) = shift;
+    my ($itemnumber) = shift;
+    warn "ITEMNUMBER: $itemnumber";
     my $dbh   = C4::Context->dbh;
 
     # Find the desired items in the reserves
+    my @params;
     my $query = "
         SELECT  reserve_id,
                 branchcode,
@@ -298,12 +301,17 @@ sub GetReservesFromBiblionumber {
                 suspend_until
         FROM     reserves
         WHERE biblionumber = ? ";
+    push( @params, $biblionumber );
     unless ( $all_dates ) {
-        $query .= "AND reservedate <= CURRENT_DATE()";
+        $query .= " AND reservedate <= CURRENT_DATE() ";
+    }
+    if ( $itemnumber ) {
+        $query .= " AND ( itemnumber IS NULL OR itemnumber = ? )";
+        push( @params, $itemnumber );
     }
     $query .= "ORDER BY priority";
     my $sth = $dbh->prepare($query);
-    $sth->execute($biblionumber);
+    $sth->execute( @params );
     my @results;
     my $i = 0;
     while ( my $data = $sth->fetchrow_hashref ) {
index 839c2a9..7ad184d 100755 (executable)
@@ -67,6 +67,7 @@ use CGI;
 use C4::Output;
 use C4::Dates qw/format_date format_date_in_iso/;
 use C4::Suggestions;
+use C4::Reserves qw/GetReservesFromBiblionumber/;
 use JSON;
 
 my $input=new CGI;
@@ -170,6 +171,9 @@ for my $item ( @parcelitems ) {
     $line{invoice} = $invoice->{invoicenumber};
     $line{total} = sprintf($cfstr, $total);
     $line{booksellerid} = $invoice->{booksellerid};
+    my ($count) = &GetReservesFromBiblionumber($line{biblionumber},undef,$item->{itemnumber});
+    $line{holds} = $count;
+    $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
     $totalprice += $item->{'unitprice'};
     $line{unitprice} = sprintf( $cfstr, $item->{'unitprice'} );
     my $gste = get_gste( $line{total}, $line{gstrate}, $bookseller );
@@ -187,7 +191,8 @@ for my $item ( @parcelitems ) {
 
     if ( $line{parent_ordernumber} != $line{ordernumber} ) {
         if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
-            @parcelitems )
+            @parcelitems
+            )
         {
             $line{cannot_cancel} = 1;
         }
index fef72dc..d208802 100644 (file)
@@ -1,3 +1,4 @@
+[% USE currency = format('%.2f') -%]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; [% IF ( date ) %]
             Receipt summary for [% name %] [% IF ( invoice ) %]invoice [% invoice %][% END %] on [% formatteddatereceived %][% ELSE %]Receive orders from [% name %][% END %]</title>
             "iCookieDuration": 60*60*24*1000, // 1000 days
             "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
             "aoColumnDefs": [
-                { "aTargets": [ 3, -1 ], "bSortable": false, "bSearchable": false },
+                { "aTargets": [ 4, -1 ], "bSortable": false, "bSearchable": false },
             ],
             "aoColumns": [
                 { "sType": "num-html" },
                 { "sType": "num-html" },
                 { "sType": "html" },
+                { "sType": "html" },
+                null,
                 null,
                 null,
                 null,
 
 
    [% IF ( loop_received ) %]
+       [% SET funds = {} %]
+       [% SET estimated_total = 0 %]
+
+       [% FOREACH loop_receive IN loop_received %]
+           [% SET estimated_total = estimated_total + ( loop_receive.ecost * loop_receive.quantityreceived ) %]
+           [% SET funds.${ loop_receive.budget.budget_name }.estimated = funds.${ loop_receive.budget.budget_name }.estimated + ( loop_receive.ecost * loop_receive.quantityreceived )%]
+           [% SET funds.${ loop_receive.budget.budget_name }.actual = funds.${ loop_receive.budget.budget_name }.actual + loop_receive.total %]
+       [% END %]
+
    <form action="/cgi-bin/koha/acqui/parcel.pl" method="get" name="orderform">
     <table id="receivedt">
         <thead>
            <tr>
-               <th>Basket</th>
-        <th>Order line</th>
-               <th>Summary</th>
-        <th>View record</th>
-               <th>Quantity</th>  
-               <th>Est cost</th>
-               <th>Actual cost</th>
-               <th>TOTAL</th>
+                <th>Basket</th>
+                <th>Order Line</th>
+                <th>Holds</th>
+                <th>Summary</th>
+                <th>View record</th>
+                <th>Quantity</th>
+                <th>Fund</th>
+                <th>Est cost</th>
+                <th>Actual cost</th>
+                <th>TOTAL</th>
         <th></th>
            </tr>
     </thead>
     <tfoot>
+        [% FOREACH key IN funds.keys.sort %]
+            <tr>
+                <td colspan="6" class="total"> &nbsp; </td>
+                <td><i>Subtotal for</i> [% key %]</td>
+                <td>[% currency( funds.$key.estimated ) %]</td>
+                <td>[% currency( funds.$key.actual ) %]</td>
+                <td>&nbsp;</td>
+                <td>&nbsp;</td>
+            </tr>
+        [% END %]
         <tr>
-            <th colspan="7" class="total">Total tax exc.</th>
+            <th colspan="9" class="total">Total tax exc.</th>
             <th>[% total_gste %]</th>
             <th></th>
         </tr>
         [% FOREACH book_foot IN book_foot_loop %]
             <tr>
-                <th colspan="7">Total (GST [% book_foot.gstrate * 100 | format ("%.1f") %]%)</th>
+                <th colspan="9">Total (GST [% book_foot.gstrate * 100 | format ("%.1f") %]%)</th>
                 <th>[% book_foot.value %]</th>
                 <th></th>
             </tr>
         [% END %]
         <tr>
-            <th colspan="7" class="total">Total tax inc.</th>
+            <th colspan="9" class="total">Total tax inc.</th>
             <th>[% total_gsti %]</th>
             <th></th>
         </tr>
             <tr>
                 <td>[% loop_receive.basketname %] (<a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% loop_receive.basketno %]">[% loop_receive.basketno %]</a>)</td>
                 <td><a href="neworderempty.pl?ordernumber=[% loop_receive.ordernumber %]&amp;booksellerid=[% booksellerid %]">[% loop_receive.ordernumber %]</a></td>
+                <td>[% IF loop_receive.holds %]<span class="error"><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% loop_receive.biblionumber %]">[% loop_receive.holds %]</a></span>[% END %]</td>
                 <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% loop_receive.biblionumber %]">[% loop_receive.title |html %]</a>
                 [% IF ( loop_receive.author ) %] / [% loop_receive.author %][% END %]
                 [% IF ( loop_receive.isbn ) %] - [% loop_receive.isbn %][% END %]
                 </td>
                 <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% loop_receive.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">MARC</a> | <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=[% loop_receive.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">Card</a></td>
                 <td>[% loop_receive.quantityreceived %]</td>
+                <td>[% loop_receive.budget.budget_name %]</td>
                 <td>[% loop_receive.ecost %]</td>
                 <td>[% loop_receive.unitprice %]</td>
                 <td>[% loop_receive.total %]</td>