[open-ils-commits] [GIT] Evergreen ILS branch rel_2_6 updated. 3db721193f58947f40b019b2f067caaf2ce04d7c

Evergreen Git git at git.evergreen-ils.org
Mon Apr 13 10:28:23 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_6 has been updated
       via  3db721193f58947f40b019b2f067caaf2ce04d7c (commit)
       via  d57f63a17726079b0688ddcfe131876b9372e737 (commit)
      from  7821de27b91453d0e972314f45f0ccf1cc117513 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3db721193f58947f40b019b2f067caaf2ce04d7c
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Apr 6 17:33:26 2015 -0400

    LP#1380803 Update PO summary amounts
    
    Refresh the PO summary amounts (spent, encumbered, estimated) each time
    an amount-changing event occurs.  These include changing the lineitem
    price, adding/removing a direct charge, and adding/removing copies via
    the copy grid.
    
    Note that adding/removing copies via the batch-updater alread causes a
    page refresh, which updates the summary amounts.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
index 92dca62..5d74b11 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
@@ -821,6 +821,7 @@ __PACKAGE__->register_method(
         method    => 'retrieve_purchase_order',
         api_name  => 'open-ils.acq.purchase_order.retrieve',
         stream    => 1,
+        authoritative => 1,
         signature => {
                       desc      => 'Retrieves a purchase order',
                       params    => [
diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js
index eee3c16..20e38e4 100644
--- a/Open-ILS/web/js/ui/default/acq/common/li_table.js
+++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js
@@ -1466,6 +1466,7 @@ function AcqLiTable() {
                         var allSet = true;
                         dojo.forEach(priceNodes, function(node) { if (node.value == '') allSet = false});
                         if (allSet) checkCouldActivatePo();
+                        refreshPOSummaryAmounts();
                     }
                 }
             }
@@ -2706,6 +2707,7 @@ function AcqLiTable() {
                     oncomplete: function() {
                         self.drawCopies(liId, true /* force_fetch */);
                         openils.Util.hide("acq-lit-update-copies-progress");
+                        refreshPOSummaryAmounts();
                     }
                 }
             );
diff --git a/Open-ILS/web/js/ui/default/acq/po/item_table.js b/Open-ILS/web/js/ui/default/acq/po/item_table.js
index 8752e34..909f7ce 100644
--- a/Open-ILS/web/js/ui/default/acq/po/item_table.js
+++ b/Open-ILS/web/js/ui/default/acq/po/item_table.js
@@ -93,6 +93,7 @@ function PoItemTable() {
 
                     virtIds.forEach(function(k) { self.deleteRow(k); });
                     objs.forEach(function(o) { self.addItem(o); });
+                    refreshPOSummaryAmounts();
                 }
             }
         );
@@ -118,6 +119,7 @@ function PoItemTable() {
                         progressDialog.hide();
                         r = openils.Util.readResponse(r); /* may not use */
                         if (r == '1') {
+                            refreshPOSummaryAmounts();
                             self._deleteRow(id);
                         } 
                     }
diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js
index 7f2a683..e11a237 100644
--- a/Open-ILS/web/js/ui/default/acq/po/view_po.js
+++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js
@@ -299,6 +299,33 @@ function prepareInvoiceFeatures() {
     openils.Util.show("acq-po-invoice-stuff", "table-cell");
 }
 
+function setSummaryAmounts() {
+    dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered().toFixed(2);
+    dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent().toFixed(2);
+    dojo.byId("acq-po-view-total-estimated").innerHTML = PO.amount_estimated().toFixed(2);
+}
+
+function refreshPOSummaryAmounts() {
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 
+            'open-ils.acq.purchase_order.retrieve.authoritative'],
+        {   async: true,
+            params: [openils.User.authtoken, poId, {
+                "flesh_price_summary": true
+            }],
+            oncomplete: function(r) {
+                // update the global PO instead of replacing it, since other 
+                // code outside our control may be referencing it.
+                var po = openils.Util.readResponse(r);
+                PO.amount_encumbered(po.amount_encumbered());
+                PO.amount_spent(po.amount_spent());
+                PO.amount_estimated(po.amount_estimated());
+                setSummaryAmounts();
+            }
+        }
+    );
+}
+
 /* renderPo() is the best place to add tests that depend on PO-state
  * (or simple ordered-or-not? checks) to enable/disable UI elements
  * across the whole interface. */
@@ -310,10 +337,9 @@ function renderPo() {
         dojo.byId("acq-po-view-provider"),
         PO.provider()
     );
+
+    setSummaryAmounts();
     dojo.byId("acq-po-view-total-li").innerHTML = PO.lineitem_count();
-    dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered().toFixed(2);
-    dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent().toFixed(2);
-    dojo.byId("acq-po-view-total-estimated").innerHTML = PO.amount_estimated().toFixed(2);
     dojo.byId("acq-po-view-state").innerHTML = po_state; // TODO i18n
 
     if(PO.order_date()) {

commit d57f63a17726079b0688ddcfe131876b9372e737
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Apr 6 14:54:55 2015 -0400

    LP#1380803 Include direct charges in PO esimated price
    
    Move the estimated PO price calculation into the middle layer, along
    with the total encumbered and spent calculation.  Add a new
    PO.amount_estimated field for carrying the data.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 9927f56..c8c79b2 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -8042,6 +8042,7 @@ SELECT  usr,
 			<field reporter:label="Line Item Count" name="lineitem_count" oils_persist:virtual="true" reporter:datatype="int" />
 			<field reporter:label="Amount Encumbered" name="amount_encumbered" oils_persist:virtual="true" reporter:datatype="float" />
 			<field reporter:label="Amount Spent" name="amount_spent" oils_persist:virtual="true" reporter:datatype="float" />
+			<field reporter:label="Amount Estimated" name="amount_estimated" oils_persist:virtual="true" reporter:datatype="float" />
 			<field reporter:label="PO Items" name="po_items" oils_persist:virtual="true" reporter:datatype="link" />
 		</fields>
 		<links>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
index 7f20e38..92dca62 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
@@ -870,46 +870,95 @@ sub po_perm_failure {
 sub build_price_summary {
     my ($e, $po_id) = @_;
 
-    # TODO: Add summary value for estimated amount (pre-encumber)
-
-    # fetch the fund debits for this purchase order
-    my $debits = $e->json_query({
-        "select" => {"acqfdeb" => [qw/encumbrance amount/]},
-        "from" => {
-            "acqlid" => {
-                "jub" => {
-                    "fkey" => "lineitem",
-                    "field" => "id",
-                    "join" => {
-                        "acqpo" => {
-                            "fkey" => "purchase_order", "field" => "id"
+    # amounts for lineitems / lineitem_details
+    my $li_data = $e->json_query({
+        select => {
+            jub => [
+                'estimated_unit_price', 
+                {column => 'id', alias => 'li_id'}
+            ],
+            acqlid => [
+                # lineitem_detail.id is needed to ensure we have one 
+                # "row" of data for every copy, regardless of whether
+                # a fund_debit exists for each copy.
+                {column => 'id', alias => 'lid_id'}
+            ],
+            acqfdeb => [
+                'encumbrance', 
+                {column => 'amount', alias => 'debit_amount'}
+            ]
+        }, 
+        from => {
+            jub => {
+                acqlid => {
+                    fkey => 'id',
+                    field => 'lineitem',
+                    join => {
+                        acqfdeb => {
+                            type => 'left',
+                            fkey => 'fund_debit',
+                            field => 'id'
                         }
                     }
-                },
-                "acqfdeb" => {"fkey" => "fund_debit", "field" => "id"}
+                }
             }
         },
-        "where" => {"+acqpo" => {"id" => $po_id}}
+        where => {'+jub' => {purchase_order => $po_id}}
     });
 
-    # add any debits for non-bib po_items
-    push(@$debits, @{
-        $e->json_query({
-            "select" => {"acqfdeb" => [qw/encumbrance amount/]},
-            "from" => {acqpoi => 'acqfdeb'},
-            "where" => {"+acqpoi" => {"purchase_order" => $po_id}}
-        })
+    # amounts for po_item's
+    my $item_data = $e->json_query({
+        select => {
+            acqpoi => ['estimated_cost'],
+            acqfdeb => [
+                'encumbrance', 
+                {column => 'amount', alias => 'debit_amount'}
+            ]
+        },
+        from => {
+            acqpoi => {
+                acqfdeb => {
+                    type => 'left',
+                    fkey => 'fund_debit',
+                    field => 'id'
+                }
+            }
+        },
+        where => {'+acqpoi' => {purchase_order => $po_id}}
     });
+                   
+    # sum amounts debited (for activated PO's) and amounts estimated 
+    # (for pending PO's) for all lineitem_details and po_items.
+
+    my ($enc, $spent, $estimated) = (0, 0, 0);
+
+    for my $deb (@$li_data, @$item_data) {
+
+        if (defined $deb->{debit_amount}) { # could be $0
+            # we have a debit, treat it as authoritative.
+
+            # estimated amount includes all amounts encumbered or spent
+            $estimated += $deb->{debit_amount};
+
+            if($U->is_true($deb->{encumbrance})) {
+                $enc += $deb->{debit_amount};
+            } else {
+                $spent += $deb->{debit_amount};
+            }
 
-    my ($enc, $spent) = (0, 0);
-    for my $deb (@$debits) {
-        if($U->is_true($deb->{encumbrance})) {
-            $enc += $deb->{amount};
         } else {
-            $spent += $deb->{amount};
+            # PO is not activated, so sum estimated costs.
+            # There will be one $deb object for every lineitem_detail 
+            # and po_item.  Adding the estimated costs for all gives 
+            # us the total esimated amount.
+
+            $estimated += (
+                $deb->{estimated_unit_price} || $deb->{estimated_cost} || 0
+            );
         }
     }
-    ($enc, $spent);
+
+    return ($enc, $spent, $estimated);
 }
 
 
@@ -971,9 +1020,10 @@ sub retrieve_purchase_order_impl {
     }
 
     if($$options{flesh_price_summary}) {
-        my ($enc, $spent) = build_price_summary($e, $po_id);
+        my ($enc, $spent, $estimated) = build_price_summary($e, $po_id);
         $po->amount_encumbered($enc);
         $po->amount_spent($spent);
+        $po->amount_estimated($estimated);
     }
 
     return $po;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
index 1c9579e..9dd1015 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
@@ -569,7 +569,7 @@ sub check_import_li_marc_perms {
 sub describe_affected_po {
     my ($e, $po) = @_;
 
-    my ($enc, $spent) =
+    my ($enc, $spent, $estimated) =
         OpenILS::Application::Acq::Financials::build_price_summary(
             $e, $po->id
         );
@@ -577,7 +577,8 @@ sub describe_affected_po {
     +{$po->id => {
             "state" => $po->state,
             "amount_encumbered" => $enc,
-            "amount_spent" => $spent
+            "amount_spent" => $spent,
+            "amount_estimated" => $estimated
         }
     };
 }
diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js
index f1ef20c..7f2a683 100644
--- a/Open-ILS/web/js/ui/default/acq/po/view_po.js
+++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js
@@ -313,6 +313,7 @@ function renderPo() {
     dojo.byId("acq-po-view-total-li").innerHTML = PO.lineitem_count();
     dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered().toFixed(2);
     dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent().toFixed(2);
+    dojo.byId("acq-po-view-total-estimated").innerHTML = PO.amount_estimated().toFixed(2);
     dojo.byId("acq-po-view-state").innerHTML = po_state; // TODO i18n
 
     if(PO.order_date()) {
@@ -448,7 +449,6 @@ function init() {
 
 function init2() {
 
-    var totalEstimated = 0;
     var zeroLi = true;
     fieldmapper.standardRequest(
         ['open-ils.acq', 'open-ils.acq.lineitem.search'],
@@ -462,13 +462,10 @@ function init2() {
                 zeroLi = false;
                 liTable.show('list');
                 var li = openils.Util.readResponse(r);
-                // TODO: Add po_item's to total estimated amount
-                totalEstimated += (Number(li.item_count() || 0) * Number(li.estimated_unit_price() || 0));
                 liTable.addLineitem(li);
             },
 
             oncomplete : function() {
-                dojo.byId("acq-po-view-total-estimated").innerHTML = totalEstimated.toFixed(2);
                 if (liFocus) liTable.drawCopies(liFocus);
                 if(zeroLi) openils.Util.show('acq-po-no-lineitems');
             }

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       |    1 +
 .../lib/OpenILS/Application/Acq/Financials.pm      |  111 ++++++++++++++------
 .../perlmods/lib/OpenILS/Application/Acq/Order.pm  |    5 +-
 Open-ILS/web/js/ui/default/acq/common/li_table.js  |    2 +
 Open-ILS/web/js/ui/default/acq/po/item_table.js    |    2 +
 Open-ILS/web/js/ui/default/acq/po/view_po.js       |   35 +++++-
 6 files changed, 118 insertions(+), 38 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list