Acq: In fund transfer, add destination amount field when warranted
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 29 Mar 2010 19:31:59 +0000 (19:31 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 29 Mar 2010 19:31:59 +0000 (19:31 +0000)
When warranted means when source and dest fund have differing currencies.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16039 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0221.perm.perm_list.acq_imbalanced_xfer.sql [new file with mode: 0644]
Open-ILS/web/css/skin/default/acq.css
Open-ILS/web/js/ui/default/acq/financial/view_fund.js
Open-ILS/web/templates/default/acq/financial/view_fund.tt2

index caa14d4..e669e11 100644 (file)
@@ -429,6 +429,8 @@ sub transfer_money_between_funds {
             $ratio = @{$exchange_rate}[0]->{ratio};
         }
         $dfund_amount = $ofund_amount * $ratio;
+    } else {
+        return $e->die_event unless $e->allowed("ACQ_XFER_MANUAL_DFUND_AMOUNT");
     }
 
     $e->json_query({
index e2f7eb5..00d9cb1 100644 (file)
@@ -60,7 +60,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0220); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0221'); -- senator
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index ef48b0c..327c8cd 100644 (file)
@@ -1332,7 +1332,8 @@ INSERT INTO permission.perm_list VALUES
     (385, 'CREATE_TRIGGER_VALIDATOR', oils_i18n_gettext(385, 'Allow a user to create trigger validators', 'ppl', 'description')),
     (386, 'DELETE_TRIGGER_VALIDATOR', oils_i18n_gettext(386, 'Allow a user to delete trigger validators', 'ppl', 'description')),
     (387, 'UPDATE_TRIGGER_VALIDATOR', oils_i18n_gettext(387, 'Allow a user to update trigger validators', 'ppl', 'description')),
-    (388, 'UPDATE_ORG_UNIT_SETTING.circ.block_renews_for_holds', oils_i18n_gettext(388, 'Allow a user to enable blocking of renews on items that could fulfill holds', 'ppl', 'description'))
+    (388, 'UPDATE_ORG_UNIT_SETTING.circ.block_renews_for_holds', oils_i18n_gettext(388, 'Allow a user to enable blocking of renews on items that could fulfill holds', 'ppl', 'description')),
+    (389, 'ACQ_XFER_MANUAL_DFUND_AMOUNT', oils_i18n_gettext(389, 'Allow a user to transfer different amounts of money out of one fund and into another', 'ppl', 'description'))
 ;
 
 SELECT SETVAL('permission.perm_list_id_seq'::TEXT, 1000);
diff --git a/Open-ILS/src/sql/Pg/upgrade/0221.perm.perm_list.acq_imbalanced_xfer.sql b/Open-ILS/src/sql/Pg/upgrade/0221.perm.perm_list.acq_imbalanced_xfer.sql
new file mode 100644 (file)
index 0000000..ba94860
--- /dev/null
@@ -0,0 +1,9 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0221'); -- senator
+
+INSERT INTO permission.perm_list (id, code, description)
+    VALUES (389, 'ACQ_XFER_MANUAL_DFUND_AMOUNT',
+       oils_i18n_gettext( 389, 'Allow a user to transfer different amounts of money out of one fund and into another', 'ppl', 'description' ));
+
+COMMIT;
index 78e2bd1..be0c83b 100644 (file)
     padding: 4px;
 }
 .oils-acq-fund-tag A { margin-left: 10px; }
-#oils-acq-fund-xfer-table th { vertical-align: top; border-right: 1px solid #999; border-top: 1px solid #999; border-bottom: 1px solid #999; padding: 4px; }
-#oils-acq-fund-xfer-table td { padding-left: 24px; }
-#oils-acq-fund-xfer-name-fund { font-style: italic; }
+#oils-acq-fund-xfer-table th { border-right: 1px solid #999; border-top: 1px solid #999; border-bottom: 1px solid #999; padding: 4px; }
+#oils-acq-fund-xfer-table td { padding: 4px 4px 4px 24px; }
 #oils-acq-fund-xfer-submit-row { text-align: center; }
 
 /* li search page */
index 5a0a779..aedddf1 100644 (file)
@@ -4,6 +4,7 @@ dojo.require('dijit.layout.TabContainer');
 dojo.require('dijit.layout.ContentPane');
 dojo.require('dojox.grid.DataGrid');
 dojo.require('dijit.form.CurrencyTextBox');
+dojo.require("dijit.form.CheckBox");
 dojo.require('dojo.data.ItemFileReadStore');
 dojo.require("fieldmapper.OrgUtils");
 dojo.require('openils.acq.Fund');
@@ -85,23 +86,43 @@ function fetchFund() {
 function TransferManager() {
     var self = this;
 
-    new openils.widget.AutoFieldWidget({
-        "fmField": "fund",
-        /* We're not really using LIDs here, we just need some class that has
-         * a fund field to take advantage of AutoFieldWidget's magic.
-         */
-        "fmClass": "acqlid",
-        "labelFormat": ["${0} (${1})", "code", "year"],
-        "searchFormat": ["${0} (${1})", "code", "year"],
-        "searchFilter": {"active": "t"}, /* consider making it possible to select inactive? */
-        "parentNode": dojo.byId("oils-acq-fund-xfer-d-selector"),
-        "orgLimitPerms": ["ADMIN_ACQ_FUND"], /* XXX is there a more appropriate permission for this? */
-        "dijitArgs": {"name": "d_fund"},
-        "forceSync": true
-    }).build(function(w, ww) { self.fundSelector = w; });
+    this._init = function() {
+        new openils.widget.AutoFieldWidget({
+            "fmField": "fund",
+            /* We're not really using LIDs here, we just need some class
+             * that has a fund field to take advantage of AutoFieldWidget's
+             * magic. */
+            "fmClass": "acqlid",
+            "labelFormat": ["${0} (${1})", "code", "year"],
+            "searchFormat": ["${0} (${1})", "code", "year"],
+            "searchFilter": {"active": "t"}, /* consider making it possible
+                                                to select inactive? */
+            "parentNode": dojo.byId("oils-acq-fund-xfer-d-selector"),
+            "orgLimitPerms": ["ADMIN_ACQ_FUND"], /* XXX is there a more
+                                                    appropriate permission
+                                                    for this? */
+            "dijitArgs": {
+                "onChange": function() {
+                    openils.Util[
+                        this.item.currency_type == fund.currency_type() ?
+                            "hide" : "show"
+                    ]("oils-acq-fund-xfer-dest-amount", "table-row");
+                }
+            },
+            "forceSync": true
+        }).build(function(w, ww) { self.fundSelector = w; });
+
+        dijit.byId("oils-acq-fund-xfer-same-o-d").onChange = function() {
+            dijit.byId("oils-acq-fund-xfer-d-amount").attr(
+                "disabled", this.attr("checked")
+            );
+        }
+    };
+
+    this._init();
 
     this.clearFundSelector = function() {
-        if (!this.fundSelector.attr("value"))
+        if (this.fundSelector.attr("value"))
             this.fundSelector.attr("value", "");
     };
 
@@ -112,7 +133,10 @@ function TransferManager() {
 
     this.submit = function() {
         var values = xferDialog.getValues();
-        if (values.d_fund == fund.id()) {
+        var dfund = this.fundSelector.item;
+        var dfund_id = typeof(dfund.id) == "object" ? dfund.id[0] : dfund.id;
+
+        if (dfund_id == fund.id()) {
             alert(localeStrings.FUND_XFER_SAME_SOURCE_AND_DEST);
             return false;
         }
@@ -121,8 +145,11 @@ function TransferManager() {
                 ["open-ils.acq", "open-ils.acq.funds.transfer_money"], {
                     "params": [
                         openils.User.authtoken,
-                        fund.id(), values.o_amount,
-                        values.d_fund, null,
+                        fund.id(),
+                        values.o_amount,
+                        dfund_id,
+                        (dfund.currency_type != fund.currency_type() &&
+                            values.same_o_d.length) ? null : values.d_amount,
                         values.note
                     ],
                     "async": true,
@@ -134,7 +161,6 @@ function TransferManager() {
                 }
             );
         }
-        return true;
     };
 }
 
index f98c385..4d183d1 100644 (file)
@@ -76,7 +76,7 @@
         <span>Transfer Money</span>
         <div jsId="xferDialog" dojoType="dijit.TooltipDialog">
             <script type="dojo/connect" event="onOpen">
-                /* If something is selected (from a previous time that the
+                /* If a fund is selected (from a previous time that the
                 user popped open this dialog), unselect it. Wouldn't want to
                 accidentally encourage a transfer that the user didn't mean. */
                 xferManager.clearFundSelector();
                 <tr>
                     <th>
                         <label for="oils-acq-fund-xfer-o-amount">
-                            Amount to transfer from<br />
-                            <span id="oils-acq-fund-xfer-name-fund"></span>
+                            Source amount<br />
+                            <em>Amount to transfer from<br />
+                                <span id="oils-acq-fund-xfer-name-fund"></span>
+                            </em>
                         </label>
                     </th>
                     <td>
                         <span id="oils-acq-fund-xfer-d-selector"></span>
                     </td>
                 </tr>
+                <tr id="oils-acq-fund-xfer-dest-amount" class="hidden">
+                    <th>
+                        <label for="oils-acq-fund-xfer-d-selector">
+                            Destination amount
+                        </label>
+                    </th>
+                    <td>
+                        <div class="oils-acq-basic-roomy">
+                            <input id="oils-acq-fund-xfer-same-o-d"
+                                dojoType="dijit.form.CheckBox" checked="checked"
+                                value="1" name="same_o_d" />
+                            <label for="oils-acq-fund-xfer-same-o-d">
+                                Same as source amount?
+                            </label>
+                        </div>
+                        <div class="oils-acq-basic-roomy">
+                            <input id="oils-acq-fund-xfer-d-amount"
+                                dojoType="dijit.form.CurrencyTextBox"
+                                name="d_amount" disabled="disabled" />
+                        </div>
+                    </td>
+                </tr>
                 <tr>
                     <th>
                         <label for="oils-acq-fund-xfer-note">Note</label>