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); }
}
);
}
+ var btn4 = document.createElement('button');
+ btn_box.appendChild( btn4 );
+ btn4.setAttribute( 'label', 'Void All Billings' );
+ btn4.setAttribute( 'mobts_id', my.mobts.id() );
+ btn4.addEventListener(
+ 'command',
+ function(ev) {
+ obj.void_all_billings( my.mobts.id() );
+ },
+ false
+ );
+
return vbox;
} catch(E) {
obj.error.standard_unexpected_error_alert('bills -> info_box',E);
this.error.standard_unexpected_error_alert('bills -> payment_box',E);
}
},
+
+ 'void_all_billings' : function(mobts_id) {
+ try {
+ var obj = this;
+ JSAN.use('util.functional');
+
+ var mb_list = obj.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID', [ ses(), mobts_id ] );
+ if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
+
+ mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
+
+ if (mb_list.length == 0) { alert('All billings already voided on this bill.'); 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 = obj.error.yns_alert(msg,'Voiding Bills','Yes','No',null,'Check here to confirm this message');
+ if (r == 0) {
+ var robj = obj.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:
+ obj.error.standard_unexpected_error_alert('Error voiding bills.',robj);
+ obj.refresh(); return;
+ break;
+ }
+ }
+
+ obj.data.stash_retrieve(); if (! obj.data.voided_billings ) obj.data.voided_billings = [];
+ for (var i = 0; i < mb_list.length; i++) {
+ obj.data.voided_billings.push( mb_list[i] );
+ }
+ obj.data.stash('voided_billings');
+ alert('Billings voided.');
+ obj.refresh();
+ }
+ } catch(E) {
+ try { obj.error.standard_unexpected_error_alert('bills.js, void_all_billings():',E); } catch(F) { alert(E); }
+ }
+
+ },
'gen_map_row_to_column' : function() {
var obj = this;