]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/bill_details.xul
explicit number casting for JSON results
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / bill_details.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Patron Display -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
10 <?xml-stylesheet href="/xul/server/skin/circ.css" type="text/css"?>
11 <?xml-stylesheet href="/xul/server/skin/patron_display.css" type="text/css"?>
12
13 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
14 <!-- LOCALIZATION -->
15 <!DOCTYPE window PUBLIC "" ""[
16         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
17 ]>
18
19 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
20 <!-- OVERLAYS -->
21 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
22 <?xul-overlay href="/xul/server/patron/bill_summary_overlay.xul"?>
23
24 <window id="bill_details_win" width="700" height="550"
25         onload="try{ my_init(); font_helper(); } catch(E) { alert(E); }"
26         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
27
28         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
29         <!-- BEHAVIOR -->
30         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
31         <scripts id="openils_util_scripts"/>
32
33         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
34         <script>
35         <![CDATA[
36
37                 function $(id) { return document.getElementById(id); }
38
39                 function retrieve_patron() {
40                         g.patron_id = xul_param('patron_id');
41
42                         if (g.patron_id) {
43                                 JSAN.use('patron.util'); 
44                                 g.au_obj = patron.util.retrieve_fleshed_au_via_id( ses(), g.patron_id );
45                                 
46                                 $('patron_name').setAttribute('value', 
47                                         ( g.au_obj.prefix() ? g.au_obj.prefix() + ' ' : '') + 
48                                         g.au_obj.family_name() + ', ' + 
49                                         g.au_obj.first_given_name() + ' ' +
50                                         ( g.au_obj.second_given_name() ? g.au_obj.second_given_name() + ' ': '' ) +
51                                         ( g.au_obj.suffix() ? g.au_obj.suffix() : '')
52                                         + ' : ' + g.au_obj.card().barcode() 
53                                 );
54                         }
55
56                 }
57
58                 function retrieve_mbts() {
59                         g.network.simple_request('FM_MBTS_RETRIEVE',[ses(),g.mbts_id],
60                                 function(req) {
61                                         try {
62                                                 g.mbts = req.getResultObject();
63                                                 $('mbts_id').value = g.mbts.id();
64                                                 $('mbts_xact_type').value = g.mbts.xact_type();
65                                                 $('mbts_xact_start').value = g.mbts.xact_start().toString().substr(0,19);
66                                                 $('mbts_xact_finish').value = g.mbts.xact_finish() ? g.mbts.xact_finish().toString().substr(0,19) : '';
67                                                 $('mbts_total_owed').value = g.mbts.total_owed() ? util.money.sanitize( g.mbts.total_owed() ) : '';
68                                                 $('mbts_total_paid').value = g.mbts.total_paid() ? util.money.sanitize( g.mbts.total_paid() ) : '';
69                                                 $('mbts_balance_owed').value = g.mbts.balance_owed() ? util.money.sanitize( g.mbts.balance_owed() ) : '';
70
71                                                 switch(g.mbts.xact_type()) {
72                                                         case 'circulation' : retrieve_circ(); break;
73                                                         case 'grocery' : retrieve_grocery(); break;
74                                                         default: break;
75                                                 }
76
77                                         } catch(E) {
78                                                 g.error.sdump('D_ERROR',E);
79                                         }
80                                 }
81                         );
82                 }
83
84                 function retrieve_grocery() {
85                         JSAN.use('util.widgets');
86                         g.network.simple_request('FM_MG_RETRIEVE', [ ses(), g.mbts_id ],
87                                 function (req) {
88                                         var r_mg = req.getResultObject();
89                                         if (instanceOf(r_mg,mg)) {
90                                                 $('billing_location').value = g.data.hash.aou[ r_mg.billing_location() ].shortname() + ' : ' + g.data.hash.aou[ r_mg.billing_location() ].name();
91                                         }
92                                 }
93                         );
94                 }
95
96                 function retrieve_circ() {
97                         JSAN.use('util.widgets');
98                         g.network.simple_request('FM_CIRC_RETRIEVE_VIA_ID', [ ses(), g.mbts_id ],
99                                 function (req) {
100                                         var r_circ = req.getResultObject();
101                                         if (instanceOf(r_circ,circ)) {
102
103                                                 $('title_label').hidden = false;
104                                                 $('checked_out_label').hidden = false;
105                                                 $('due_label').hidden = false;
106                                                 $('checked_in_label').hidden = false;
107                                                 $('checked_out').value = r_circ.xact_start() ? r_circ.xact_start().toString().substr(0,10) : '';
108                                                 $('checked_in').value = r_circ.checkin_time() ? r_circ.checkin_time().toString().substr(0,10) : '';
109                                                 $('due').value = r_circ.due_date() ? r_circ.due_date().toString().substr(0,10) : '';
110                                                 $('billing_location').value = g.data.hash.aou[ r_circ.circ_lib() ].shortname() + ' : ' + g.data.hash.aou[ r_circ.circ_lib() ].name();
111                                                 var r = '';
112                                                 if (get_bool( r_circ.desk_renewal() ) ) r += 'DESK ';
113                                                 if (get_bool(r_circ.opac_renewal() ) ) r += 'OPAC ';
114                                                 if (get_bool(r_circ.phone_renewal() ) ) r += 'PHONE ';
115                                                 $('renewal').value = r || 'No';
116
117                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
118                                                 $('copy_summary').setAttribute('src',urls.XUL_COPY_SUMMARY + '?copy_id=' + r_circ.target_copy());
119                                                 //get_contentWindow($('copy_summary')).xulG = { 'copy_id' : r_circ.target_copy() };
120                                                 $('copy_summary').hidden=false;
121
122                                                 g.network.simple_request(
123                                                         'MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',
124                                                         [ r_circ.target_copy() ],
125                                                         function (rreq) {
126                                                                 var r_mvr = rreq.getResultObject();
127                                                                 if (instanceOf(r_mvr,mvr)) {
128                                                                         util.widgets.remove_children('title');
129                                                                         $('title').appendChild( document.createTextNode( String(r_mvr.title()).substr(0,50) ) );
130                                                                 } else {
131                                                                         g.network.simple_request(
132                                                                                 'FM_ACP_RETRIEVE',
133                                                                                 [ r_circ.target_copy() ],
134                                                                                 function (rrreq) {
135                                                                                         var r_acp = rrreq.getResultObject();
136                                                                                         if (instanceOf(r_acp,acp)) {
137                                                                                                 util.widgets.remove_children('title');
138                                                                                                 $('title').appendChild( document.createTextNode( r_acp.dummy_title() ) );
139                                                                                         }
140                                                                                 }
141                                                                         );
142                                                                 }
143                                                         }
144                                                 );
145
146                                         }
147                                 }
148                         );
149                 }
150
151                 function init_lists() {
152                         JSAN.use('util.list'); 
153                         g.bill_list = new util.list('bill_tree');
154                         g.payment_list = new util.list('payment_tree');
155
156                         g.bill_list.init( {
157                                 'columns' : patron.util.mb_columns({}),
158                                 'map_row_to_columns' : patron.util.std_map_row_to_columns(),
159                                 'on_select' : function(ev) {
160                                         JSAN.use('util.functional');
161                                         g.bill_list_selection = util.functional.map_list(
162                                                 g.bill_list.retrieve_selection(),
163                                                 function(o) { return o.getAttribute('retrieve_id'); }
164                                         );
165                                         $('void').disabled = g.bill_list_selection.length == 0;
166                                 },
167                         } );
168
169                         g.payment_list.init( {
170                                 'columns' : patron.util.mp_columns({}),
171                                 'map_row_to_columns' : patron.util.std_map_row_to_columns(),
172                                 'on_select' : function(ev) {
173                                         JSAN.use('util.functional');
174                                         g.payment_list_selection = util.functional.map_list(
175                                                 g.payment_list.retrieve_selection(),
176                                                 function(o) { return o.getAttribute('retrieve_id'); }
177                                         );
178                                 },
179                         } );
180                 }
181
182                 function retrieve_mb() {
183                         g.mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID', [ ses(), g.mbts_id ] );
184                         //g.error.sdump('D_DEBUG',g.error.pretty_print( js2JSON(g.mb_list) ));
185
186                         var mb_funcs = [];
187
188                         function gen_mb_func(i,r) {
189                                 return function() {
190                                         g.bill_list.append( { 'retrieve_id' : i, 'row' : { my : { 'mb' : r } } } );
191                                 }
192                         }
193
194                         for (var i = 0; i < g.mb_list.length; i++) {
195                                 mb_funcs.push( gen_mb_func(i,g.mb_list[i]) );
196                         }
197
198                         JSAN.use('util.exec');
199                         var mb_exec = new util.exec(4); mb_exec.chain(mb_funcs);
200                 }
201
202                 function retrieve_mp() {
203                         var mp_list = g.network.simple_request( 'FM_MP_RETRIEVE_VIA_MBTS_ID', [ ses(), g.mbts_id ]);
204                         //g.error.sdump('D_DEBUG',g.error.pretty_print( js2JSON(mp_list) ));
205
206                         var mp_funcs = [];
207
208                         function gen_mp_func(r) {
209                                 return function() {
210                                         g.payment_list.append( { 'retrieve_id' : r.id(), 'row' : { my : { 'mp' : r } } } );
211                                 }
212                         }
213
214                         for (var i = 0; i < mp_list.length; i++) {
215                                 mp_funcs.push( gen_mp_func(mp_list[i]) );
216                         }
217
218                         JSAN.use('util.exec');
219                         var mp_exec = new util.exec(4); mp_exec.chain(mp_funcs);
220                 }
221
222                 function my_init() {
223                         try {
224                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
225                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
226                                 JSAN.errorLevel = "die"; // none, warn, or die
227                                 JSAN.addRepository('/xul/server/');
228
229                                 JSAN.use('util.error'); g.error = new util.error();
230                                 JSAN.use('util.network'); g.network = new util.network();
231                                 JSAN.use('util.date');
232                                 JSAN.use('util.money');
233                                 JSAN.use('patron.util');
234                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
235
236                                 g.error.sdump('D_TRACE','my_init() for bill_details.xul');
237
238                                 g.mbts_id = xul_param('mbts_id');
239
240                                 retrieve_patron();
241
242                                 retrieve_mbts();
243                                 //retrieve_circ();
244
245                                 init_lists();
246
247                                 retrieve_mb();
248                                 retrieve_mp();
249
250                                 $('void').addEventListener(
251                                         'command',
252                                         handle_void,
253                                         false
254                                 );
255
256                         } catch(E) {
257                                 try { g.error.standard_unexpected_error_alert('bill_details.xul, my_init:',E); } catch(F) { alert(E); }
258                         }
259                 }
260
261                 function handle_void() {
262                         try {
263                                 var mb_list = util.functional.map_list(g.bill_list_selection, function(o){return g.mb_list[o];}); 
264                                 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
265
266                                 if (mb_list.length == 0) { alert('All selected billings have already voided.'); return; }
267
268                                 var sum = 0;
269                                 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
270                                 sum = util.money.cents_as_dollars( sum );
271
272                                 var msg = 'Are you sure you would like to void $' + sum + ' worth of line-item billings?';
273                                 var r = g.error.yns_alert(msg,'Voiding Bills','Yes','No',null,'Check here to confirm this message');
274                                 if (r == 0) {
275                                         var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
276                                         if (robj.ilsevent) {
277                                                 switch(Number(robj.ilsevent)) {
278                                                         default: 
279                                                                 g.error.standard_unexpected_error_alert('Error voiding bills.',robj); 
280                                                                 retrieve_mbts();
281                                                                 g.bill_list.clear();
282                                                                 retrieve_mb();
283                                                                 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') { window.xulG.refresh(); }
284                                                                 return; 
285                                                         break;
286                                                 }
287                                         }
288         
289                                         g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = []; 
290                                         for (var i = 0; i < mb_list.length; i++) {
291                                                         g.data.voided_billings.push( mb_list[i] );
292                                         }
293                                         g.data.stash('voided_billings');
294                                         alert('Billings voided.');
295                                         retrieve_mbts();
296                                         g.bill_list.clear();
297                                         retrieve_mb();
298                                         if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') { window.xulG.refresh(); }
299                                 }
300
301                         } catch(E) {
302                                 try { g.error.standard_unexpected_error_alert('bill_details.xul, handle_void:',E); } catch(F) { alert(E); }
303                         }
304                 }
305
306         ]]>
307         </script>
308
309     <messagecatalog id="commonStrings" src="/xul/server/locale/<!--#echo var='locale'-->/common.properties"/>
310
311         <vbox flex="1" class="my_overflow">
312                 <label id="patron_name" class="patronNameLarge"/>
313
314                 <groupbox orient="vertical" flex="1" id="summary" />
315
316                 <splitter><grippy/></splitter>
317
318                 <iframe id="copy_summary" flex="1" hidden="true"/>
319
320                 <splitter><grippy/></splitter>
321
322                         <groupbox orient="vertical" flex="2">
323                                 <caption label="Bills" style="color: red"/>
324                                 <tree id="bill_tree" flex="1" enableColumnDrag="true"/>
325                                 <hbox>
326                                         <button label="Save Columns" oncommand="g.bill_list.save_columns();"/>
327                                         <button label="Copy to Clipboard" oncommand="g.bill_list.clipboard();"/>
328                                         <button label="Print Export" oncommand="try { g.bill_list.on_all_fleshed = function() { JSAN.use('util.print'); var p = new util.print(); p.simple( g.bill_list.dump_csv(), { 'content_type' : 'text/plain' } ); setTimeout( function() { g.bill_list.on_all_fleshed = null; }, 0); }; g.bill_list.full_retrieve(); } catch(E) { alert(E); }"/>
329                                         <spacer flex="1"/>
330                                         <button id="void" label="Void selected billings" disabled="true"/>
331                                 </hbox>
332                         </groupbox>
333
334                         <splitter><grippy/></splitter>
335
336                         <groupbox orient="vertical" flex="2">
337                                 <caption label="Payments" style="color: green"/>
338                                 <tree id="payment_tree" flex="1" enableColumnDrag="true"/>
339                                 <hbox>
340                                         <button label="Save Columns" oncommand="g.payment_list.save_columns();"/>
341                                         <button label="Copy to Clipboard" oncommand="g.payment_list.clipboard();"/>
342                                         <button label="Print Export" oncommand="try { g.payment_list.on_all_fleshed = function() { JSAN.use('util.print'); var p = new util.print(); p.simple( g.payment_list.dump_csv(), { 'content_type' : 'text/plain' } ); setTimeout( function() { g.payment_list.on_all_fleshed = null; }, 0); }; g.payment_list.full_retrieve(); } catch(E) { alert(E); }"/>
343                                         <spacer flex="1"/>
344                                 </hbox>
345                         </groupbox>
346
347                 <hbox>
348                         <button id="opac" label="Show in Catalog" accesskey="S" hidden="true"/>
349                         <spacer flex="1"/>
350                         <button label="Close Window" oncommand="window.close()" accesskey="c"/>
351                 </hbox>
352         </vbox>
353
354
355 </window>
356