use batch void api in full details view
authorpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 1 Feb 2007 16:26:48 +0000 (16:26 +0000)
committerpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 1 Feb 2007 16:26:48 +0000 (16:26 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6844 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/patron/bill_details.xul

index 62ebb09..f07cdc9 100644 (file)
 
                function handle_void() {
                        try {
-                               JSAN.use('util.functional');
-                               var msg = 'Are you sure you would like to void bill' + ( g.bill_list_selection.length > 1 ? 's ' : ' ') + util.functional.map_list( g.bill_list_selection, function(o) { return g.mb_list[o].id(); })  + '?';
+                               var mb_list = util.functional.map_list(g.bill_list_selection, function(o){return g.mb_list[o];}); 
+                               mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
+
+                               if (mb_list.length == 0) { alert('All selected billings have already voided.'); return; }
+
+                               var sum = 0;
+                               for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
+                               sum = util.money.cents_as_dollars( sum );
+
+                               var msg = 'Are you sure you would like to void $' + sum + ' worth of line-item billings?';
                                var r = g.error.yns_alert(msg,'Voiding Bills','Yes','No',null,'Check here to confirm this message');
                                if (r == 0) {
-                                       g.data.stash_retrieve();
-                                       for (var i = 0; i < g.bill_list_selection.length; i++) {
-                                               var robj = g.network.simple_request('FM_MB_VOID',[ses(),g.mb_list[g.bill_list_selection[i]].id()]);
-                                               if (! g.data.voided_billings ) g.data.voided_billings = []; 
-                                               if (robj.ilsevent) {
-                                                       switch(robj.ilsevent) {
-                                                               case -1 : g.error.standard_network_error_alert('Void of Bill #' + g.mb_list[g.bill_list_selection[i]].id() + ' failed.'); break;
-                                                               default: g.error.standard_unexpected_error_alert('Void of Bill #' + g.mb_list[g.bill_list_selection[i]].id() + ' failed.',robj); break;
-                                                       }
-                                               } else {
-                                                       g.data.voided_billings.push( g.mb_list[g.bill_list_selection[i]] );
-                                                       g.data.stash('voided_billings');
+                                       var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
+                                       if (robj.ilsevent) {
+                                               switch(robj.ilsevent) {
+                                                       default: 
+                                                               g.error.standard_unexpected_error_alert('Error voiding bills.',robj); 
+                                                               retrieve_mbts();
+                                                               g.bill_list.clear();
+                                                               retrieve_mb();
+                                                               if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') { window.xulG.refresh(); }
+                                                               return; 
+                                                       break;
                                                }
                                        }
-                                       alert('Action completed.');
+       
+                                       g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = []; 
+                                       for (var i = 0; i < mb_list.length; i++) {
+                                                       g.data.voided_billings.push( mb_list[i] );
+                                       }
+                                       g.data.stash('voided_billings');
+                                       alert('Billings voided.');
                                        retrieve_mbts();
                                        g.bill_list.clear();
                                        retrieve_mb();
                                        if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') { window.xulG.refresh(); }
                                }
+
                        } catch(E) {
                                try { g.error.standard_unexpected_error_alert('bill_details.xul, handle_void:',E); } catch(F) { alert(E); }
                        }