[open-ils-commits] [GIT] Evergreen ILS branch rel_2_8 updated. 192dc57619a1810cfa5096318dc0b1df856bf511

Evergreen Git git at git.evergreen-ils.org
Mon Apr 13 10:27:40 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_8 has been updated
       via  192dc57619a1810cfa5096318dc0b1df856bf511 (commit)
       via  6bbb096121de908ef7dcc9b6d7ac500395361dfe (commit)
      from  122df457f2b6a0f8c163bdbbe18e9dca3c41958c (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 192dc57619a1810cfa5096318dc0b1df856bf511
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 a94d403..bf4e4e3 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
@@ -1489,6 +1489,7 @@ function AcqLiTable() {
                         var allSet = true;
                         dojo.forEach(priceNodes, function(node) { if (node.value == '') allSet = false});
                         if (allSet) checkCouldActivatePo();
+                        refreshPOSummaryAmounts();
                     }
                 }
             }
@@ -2737,6 +2738,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 9d463aa..dbe7705 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
@@ -300,6 +300,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. */
@@ -311,10 +338,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 6bbb096121de908ef7dcc9b6d7ac500395361dfe
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 354d396..2719924 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -8236,6 +8236,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 a63b948..4dec15d 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 436450a..9d463aa 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
@@ -314,6 +314,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()) {
@@ -449,7 +450,6 @@ function init() {
 
 function init2() {
 
-    var totalEstimated = 0;
     var zeroLi = true;
     fieldmapper.standardRequest(
         ['open-ils.acq', 'open-ils.acq.lineitem.search'],
@@ -463,13 +463,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