[open-ils-commits] r14669 - trunk/Open-ILS/xul/staff_client/server/patron (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 29 02:59:19 EDT 2009


Author: phasefx
Date: 2009-10-29 02:59:14 -0400 (Thu, 29 Oct 2009)
New Revision: 14669

Modified:
   trunk/Open-ILS/xul/staff_client/server/patron/bill2.js
   trunk/Open-ILS/xul/staff_client/server/patron/bill2.xul
Log:
Some refactoring and payment distribution logic.  Refunds have the same limitation as before in that they only get further applied to subsequent bills in the list.  We could either put refundable transactions at the top of the 
list by default (maybe a good idea for making them more prominent if nothing else), and/or we could make a second pass over the list whenever money is left over. 



Modified: trunk/Open-ILS/xul/staff_client/server/patron/bill2.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/patron/bill2.js	2009-10-29 05:29:33 UTC (rev 14668)
+++ trunk/Open-ILS/xul/staff_client/server/patron/bill2.js	2009-10-29 06:59:14 UTC (rev 14669)
@@ -1,3 +1,80 @@
+function my_init() {
+    try {
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
+        JSAN.errorLevel = "die"; // none, warn, or die
+        JSAN.addRepository('/xul/server/');
+
+        JSAN.use('util.error'); g.error = new util.error();
+        JSAN.use('util.network'); g.network = new util.network();
+        JSAN.use('util.date');
+        JSAN.use('util.money');
+        JSAN.use('patron.util');
+        JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
+        //g.data.temp = ''; g.data.stash('temp');
+
+        g.error.sdump('D_TRACE','my_init() for bill2.xul');
+
+        if (xul_param('current')) {
+            $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.current_bills'));
+            document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
+        } else {
+            $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.bill_history'));
+            document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.bill_history');
+        }
+
+        g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
+
+        g.patron_id = xul_param('patron_id');
+
+        init_lists();
+
+        retrieve_mbts_for_list();
+
+        $('details').addEventListener(
+            'command',
+            handle_details,
+            false
+        );
+
+        $('add').addEventListener(
+            'command',
+            handle_add,
+            false
+        );
+
+        JSAN.use('util.exec'); var exec = new util.exec(20); 
+        exec.on_error = function(E) { alert(E); return true; }
+        exec.timer(g.funcs,100);
+
+        $('credit_forward').setAttribute('value','???');
+        if (!g.patron) {
+            g.network.simple_request(
+                'FM_AU_FLESHED_RETRIEVE_VIA_ID.authoritative',
+                [ ses(), g.patron_id ],
+                function(req) {
+                    try {
+                        g.patron = req.getResultObject();
+                        if (typeof g.patron.ilsevent != 'undefined') throw(g.patron);
+                        $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() ));
+                    } catch(E) {
+                        alert('Error in bill2.js, retrieve patron callback: ' + E);
+                    }
+                }
+            );
+        } else {
+            $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() ));
+        }
+
+        default_focus();
+
+    } catch(E) {
+        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
+        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+        alert(err_msg);
+    }
+}
+
 function $(id) { return document.getElementById(id); }
 
 function default_focus() {
@@ -82,20 +159,53 @@
         $('total_owed').setAttribute('value', '$' + util.money.cents_as_dollars( total_balance ) );
         $('total_owed2').setAttribute('value', '$' + util.money.cents_as_dollars( total_balance ) );
         $('refunds_owed').setAttribute('value', '$' + util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
+        // tally_selected();
     } catch(E) {
         alert('Error in bill2.js, tally_all(): ' + E);
     }
 }
 
+function check_all() {
+    try {
+        for (var i in g.bill_map) {
+            g.check_map[i] = true;
+            var row_params = g.row_map[i];
+            row_params.row.my.checked = true;
+            g.bill_list.refresh_row(row_params);
+        }
+        distribute_payment();
+    } catch(E) {
+        alert('Error in bill2.js, check_all(): ' + E);
+    }
+
+}
+
+function uncheck_all() {
+    try {
+        for (var i in g.bill_map) {
+            g.check_map[i] = false;
+            var row_params = g.row_map[i];
+            row_params.row.my.checked = false;
+            g.bill_list.refresh_row(row_params);
+        }
+        distribute_payment();
+    } catch(E) {
+        alert('Error in bill2.js, check_all(): ' + E);
+    }
+
+}
+
 function check_all_refunds() {
     try {
         for (var i in g.bill_map) {
+            g.check_map[i] = true;
             if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
                 var row_params = g.row_map[i];
                 row_params.row.my.checked = true;
                 g.bill_list.refresh_row(row_params);
             }
         }
+        distribute_payment();
     } catch(E) {
         alert('Error in bill2.js, check_all_refunds(): ' + E);
     }
@@ -112,7 +222,9 @@
     } else if (g.mbts_ids == null) {
         g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
     } else {
-    
+   
+        g.mbts_ids.reverse();
+ 
         function gen_func(r) {
             return function() {
                 if (typeof r == 'object') { g.row_map[ r.id() ] = g.bill_list.append( { 'retrieve_id' : r.id(), 'row' : { 'my' : { 'checked' : true, 'mbts' : r } } } );
@@ -151,7 +263,7 @@
             ).concat( 
                 [
                     {
-                        'id' : 'payment_pending', 'editable' : false, 'label' : 'Payment Pending', 'sort_type' : 'money', 'render' : function(my) { return '$0.00'; }, 
+                        'id' : 'payment_pending', 'editable' : false, 'label' : 'Payment Pending', 'sort_type' : 'money', 'render' : function(my) { return my.payment_pending || '0.00'; }, 
                     }
                 ]
             ))),
@@ -163,7 +275,6 @@
                 function(o) { return o.getAttribute('retrieve_id'); }
             );
             tally_selected();
-            tally_all();
             $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
             $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
             $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
@@ -177,12 +288,14 @@
             if (treeItem.nodeName != 'treeitem') return;
             var treeRow = treeItem.firstChild;
             var treeCell = treeRow.firstChild;
-            g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
-            tally_selected();
-            tally_all();
+            if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
+                g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
+                g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
+                tally_all();
+                distribute_payment();
+            }
         },
         'on_sort' : function() {
-            tally_selected();
             tally_all();
         },
         'on_checkbox_toggle' : function(toggle) {
@@ -190,8 +303,8 @@
                 var retrieve_ids = g.bill_list.dump_retrieve_ids();
                 for (var i = 0; i < retrieve_ids.length; i++) {
                     g.check_map[ retrieve_ids[i] ] = (toggle=='on');
+                    g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
                 }
-                tally_selected();
                 tally_all();
             } catch(E) {
                 alert('error in on_checkbox_toggle(): ' + E);
@@ -219,7 +332,6 @@
                             };
                             g.bill_map[ id ] = blob;
                             g.check_map[ id ] = row.my.checked;
-                            tally_selected();
                             tally_all();
                         } );
                     } else {
@@ -239,83 +351,6 @@
     g.bill_list.set_list_actions();
 }
 
-function my_init() {
-    try {
-        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-        if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
-        JSAN.errorLevel = "die"; // none, warn, or die
-        JSAN.addRepository('/xul/server/');
-
-        JSAN.use('util.error'); g.error = new util.error();
-        JSAN.use('util.network'); g.network = new util.network();
-        JSAN.use('util.date');
-        JSAN.use('util.money');
-        JSAN.use('patron.util');
-        JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
-        //g.data.temp = ''; g.data.stash('temp');
-
-        g.error.sdump('D_TRACE','my_init() for bill2.xul');
-
-        if (xul_param('current')) {
-            $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.current_bills'));
-            document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
-        } else {
-            $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.bill_history'));
-            document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.bill_history');
-        }
-
-        g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
-
-        g.patron_id = xul_param('patron_id');
-
-        init_lists();
-
-        retrieve_mbts_for_list();
-
-        $('details').addEventListener(
-            'command',
-            handle_details,
-            false
-        );
-
-        $('add').addEventListener(
-            'command',
-            handle_add,
-            false
-        );
-
-        JSAN.use('util.exec'); var exec = new util.exec(20); 
-        exec.on_error = function(E) { alert(E); return true; }
-        exec.timer(g.funcs,100);
-
-        $('credit_forward').setAttribute('value','???');
-        if (!g.patron) {
-            g.network.simple_request(
-                'FM_AU_FLESHED_RETRIEVE_VIA_ID.authoritative',
-                [ ses(), g.patron_id ],
-                function(req) {
-                    try {
-                        g.patron = req.getResultObject();
-                        if (typeof g.patron.ilsevent != 'undefined') throw(g.patron);
-                        $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() ));
-                    } catch(E) {
-                        alert('Error in bill2.js, retrieve patron callback: ' + E);
-                    }
-                }
-            );
-        } else {
-            $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() ));
-        }
-
-        default_focus();
-
-    } catch(E) {
-        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
-        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
-        alert(err_msg);
-    }
-}
-
 function handle_add() {
     if(g.bill_list_selection.length > 1)
         var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
@@ -378,4 +413,35 @@
     }
 }
 
+function distribute_payment() {
+    try {
+        JSAN.use('util.money');
+        var tb = $('payment');
+        tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
+        tb.setAttribute('value', tb.value );
+        var total = util.money.dollars_float_to_cents_integer( tb.value );
+        if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
+        var retrieve_ids = g.bill_list.dump_retrieve_ids();
+        for (var i = 0; i < retrieve_ids.length; i++) {
+            var row_params = g.row_map[retrieve_ids[i]];
+            if (g.check_map[retrieve_ids[i]]) { 
+                var bill = g.bill_map[retrieve_ids[i]].transaction;
+                var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
+                if ( bo > total ) {
+                    row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
+                    total = 0;
+                } else {
+                    row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
+                    total = total - bo;
+                }
+            } else {
+                row_params.row.my.payment_pending = '0.00';
+            }
+            g.bill_list.refresh_row(row_params);
+        }
+        //obj.update_payment_applied();
+    } catch(E) {
+        alert('Error in bill2.js, distribute_payment(): ' + E);
+    }
+}
 

Modified: trunk/Open-ILS/xul/staff_client/server/patron/bill2.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/patron/bill2.xul	2009-10-29 05:29:33 UTC (rev 14668)
+++ trunk/Open-ILS/xul/staff_client/server/patron/bill2.xul	2009-10-29 06:59:14 UTC (rev 14669)
@@ -109,7 +109,7 @@
                     </grid>
                     <hbox>
                         <checkbox id="annotate_payment" label="&staff.patron.bills_overlay.annotate_payment.label;" accesskey="n" oils_persist="checked" checked="false" oncommand="default_focus();"/>
-                        <button label="See Distribution" accesskey="D" oncommand="default_focus();"/>
+                        <button label="See Distribution" accesskey="D" oncommand="distribute_payment(); default_focus();"/>
                         <button label="Apply Payment" accesskey="P"/>
                     </hbox>
                 </groupbox>
@@ -134,8 +134,8 @@
             <tree id="bill_tree" flex="1" enableColumnDrag="true" seltype="multiple" editable="true" context="actions_popup"/>
             <hbox>
                 <hbox id="bill_list_actions" />
-                <button label="Check All" oncommand="g.bill_list._toggle_checkbox_column({'id':'select'},'on');"/>
-                <button label="Uncheck All" oncommand="g.bill_list._toggle_checkbox_column({'id':'select'},'off');"/>
+                <button label="Check All" oncommand="check_all();"/>
+                <button label="Uncheck All" oncommand="uncheck_all();"/>
                 <button label="Check All Refunds" oncommand="check_all_refunds();"/>
                 <button id="print" label="Print Bills" oncommand="print_bills();"/>
                 <spacer flex="1"/>



More information about the open-ils-commits mailing list