LP#1175400 Check for over allocation from funding source
authorLiam Whalen <liam.whalen@bc.libraries.coop>
Wed, 4 Nov 2015 22:03:59 +0000 (14:03 -0800)
committerLiam Whalen <liam.whalen@bc.libraries.coop>
Wed, 4 Nov 2015 22:03:59 +0000 (14:03 -0800)
When allocating money from a funding source to a fund it is possible to
allocate more money to the fund than exists in the funding source.  This
code adds a check with a dialog that stops the user from over allocating
from a funding source unless they choose an override option.

TODO: Need to add a permission check to allow the override.

Signed-off-by: Liam Whalen <liam.whalen@bc.libraries.coop>
s# Open-ILS/web/js/ui/default/acq/financial/view_funding_source.js~

Open-ILS/src/templates/acq/funding_source/over_allocate_dialog.tt2 [new file with mode: 0644]
Open-ILS/src/templates/acq/funding_source/view.tt2
Open-ILS/web/js/ui/default/acq/financial/view_funding_source.js

diff --git a/Open-ILS/src/templates/acq/funding_source/over_allocate_dialog.tt2 b/Open-ILS/src/templates/acq/funding_source/over_allocate_dialog.tt2
new file mode 100644 (file)
index 0000000..c644c32
--- /dev/null
@@ -0,0 +1,13 @@
+<div dojoType="dijit.Dialog" jsId='oilsFSOverAllocateDialog' style='display:none;'>
+  <p>[% l('You are attempting to allocate more money than is available in the funding source.') %]</p>
+    <td>
+      <button jsId='oilsFSOverAllocateContinue' 
+        dojoType='dijit.form.Button'>[% l('Ok') %]</button>
+    </td>
+    <td>
+      <button jsId='oilsFSOverAllocateOverride' 
+        dojoType='dijit.form.Button'>[% l('Override') %]</button>
+    </td>
+  </tr></table>
+</div>
+
index 61e1903..4f8c3c1 100644 (file)
@@ -1,3 +1,4 @@
+[%INCLUDE 'acq/funding_source/over_allocate_dialog.tt2'%]
 [% WRAPPER 'base.tt2' %]
 <script type="text/javascript"> var fundingSourceID = [% ctx.page_args.0 %]; </script>
 
index 5a68df1..1c1c546 100644 (file)
@@ -39,10 +39,48 @@ function applyFSCredit(fields) {
 
 function applyFSAllocation(fields) {
     fields.funding_source = fundingSourceID;
+    //fs = openils.acq.FundingSource.retrieve(fundingSourceID, {flesh_summary:1});
+    var req = ses.request(
+        'open-ils.acq.funding_source.retrieve', 
+        openils.User.authtoken, fundingSourceID, 
+        {flesh_summary:1}
+    );
+
+    req.oncomplete = function(r) {
+        var msg = req.recv();
+        fundingSource = msg.content();
+    }
+
+    req.send();
+
+    var balance = fundingSource.summary().balance;
+
     if(isNaN(fields.amount)) fields.amount = null;
-    openils.acq.Fund.createAllocation(
-        fields, function() { resetPage(loadAllocationGrid); }
+
+    dojo.connect(oilsFSOverAllocateContinue, 'onClick', 
+        function() {
+            oilsFSOverAllocateDialog.hide();
+        }
     );
+
+    dojo.connect(oilsFSOverAllocateOverride, 'onClick', 
+        function() {
+            oilsFSOverAllocateDialog.hide();
+            doAllocation(fields);
+        }
+    );
+
+    if(fields.amount > balance) {
+        oilsFSOverAllocateDialog.show();
+    } else {
+        doAllocation(fields);
+    }
+
+    function doAllocation(fields) {
+        openils.acq.Fund.createAllocation(
+            fields, function() { resetPage(loadAllocationGrid); }
+        );
+    }
 }
 
 /** fetch the fleshed funding source ----- */