[open-ils-commits] r12912 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 19 20:44:52 EDT 2009


Author: erickson
Date: 2009-04-19 20:44:51 -0400 (Sun, 19 Apr 2009)
New Revision: 12912

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Log:
added option to flesh total spent/encumbered for a PO

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2009-04-20 00:43:50 UTC (rev 12911)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2009-04-20 00:44:51 UTC (rev 12912)
@@ -917,6 +917,7 @@
     my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->event;
 
     if($$options{flesh_lineitems}) {
+
         my $items = $e->search_acq_lineitem([
             {purchase_order => $po_id},
             {
@@ -935,13 +936,44 @@
         }
 
         $po->lineitems($items);
-    }
+        $po->lineitem_count(scalar(@$items));
 
-    if($$options{flesh_lineitem_count}) {
+    } elsif( $$options{flesh_lineitem_count} ) {
+
         my $items = $e->search_acq_lineitem({purchase_order => $po_id}, {idlist=>1});
         $po->lineitem_count(scalar(@$items));
     }
 
+    if($$options{flesh_price_summary}) {
+
+        # fetch the fund debits for this purchase order
+        my $debits = $e->json_query({
+            select => {acqfdeb => ["encumbrance", "amount"]},
+            from => {
+                acqlid => {
+                    jub => {fkey => "lineitem", field => "id", 
+                        join => {acqpo => {fkey => "purchase_order", field => "id"}}
+                    },
+                acqfdeb => {fkey => "fund_debit", field =>"id"}
+                }
+            },
+            where => {'+acqpo' => {id => $po_id}}
+        });
+
+        my $enc = 0;
+        my $spent = 0;
+        for my $deb (@$debits) {
+            if($U->is_true($deb->{encumbrance})) {
+                $enc += $deb->{amount};
+            } else {
+                $spent += $deb->{amount};
+            }
+        }
+
+        $po->amount_encumbered($enc);
+        $po->amount_spent($spent);
+    }
+
     return $po;
 }
 



More information about the open-ils-commits mailing list