4502182c5fad7fa0e2f3914fb02ad045c57764cc
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / bill_history.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_history_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 = g.cgi.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', g.au_obj.family_name() + ', ' + g.au_obj.first_given_name() + ' : ' + g.au_obj.card().barcode() );
47                         }
48
49                 }
50
51                 function retrieve_mbts_for_list() {
52                         //var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_CHARGE';
53                         var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BILL';
54                         if (g.cgi.param('current')) method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE';
55                         g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
56                         if (g.mbts_ids.ilsevent) {
57                                 switch(g.mbts_ids.ilsevent) {
58                                         case -1: g.error.standard_network_error_alert('Please close this window and try again.'); break;
59                                         default: g.error.standard_unexpected_error_alert('Please close this window and try again.',g.mbts_ids); break;
60                                 }
61                         } else if (g.mbts_ids == null) {
62                                 g.error.standard_unexpected_error_alert('Please close this window and try again.',null);
63                         } else {
64                                 //g.mbts_ids.reverse();
65                                 var funcs = [];
66                         
67                                                 function gen_func(r) {
68                                                         return function() {
69                                                                 g.bill_list.append( { 'retrieve_id' : r, 'row' : {} } );
70                                                         }
71                                                 }
72                         
73                                 for (var i = 0; i < g.mbts_ids.length; i++) {
74                                         dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
75                                         funcs.push( gen_func(g.mbts_ids[i]) );
76                                 }
77                                 JSAN.use('util.exec'); var exec = new util.exec(4);
78                                 exec.on_error = function(E) { alert(E); return true; }
79                                 exec.chain(funcs);
80                         }
81                 }
82
83                 function retrieve_specific_mbts() {
84                         if (g.mbts_id) g.network.simple_request('FM_MBTS_RETRIEVE',[ses(),g.mbts_id],
85                                 function(req) {
86                                         try {
87                                                 g.mbts = req.getResultObject();
88                                                 if (g.mbts.ilsevent) {
89                                                         switch(g.mbts.ilsevent) {
90                                                                 case -1: g.error.standard_network_error_alert('mbts_id = ' + g.mbts_id); break;
91                                                                 default: g.error.standard_unexpected_error_alert('mbts_id = ' + g.mbts_id,g.mbts); break;
92                                                         }
93                                                 } else {
94                                                         $('mbts_id').value = g.mbts_id;
95                                                         $('mbts_xact_type').value = g.mbts.xact_type();
96                                                         $('mbts_xact_start').value = g.mbts.xact_start().toString().substr(0,19);
97                                                         $('mbts_xact_finish').value = g.mbts.xact_finish() ? g.mbts.xact_finish().toString().substr(0,19) : '';
98                                                         $('mbts_total_owed').value = g.mbts.total_owed() ? util.money.sanitize( g.mbts.total_owed() ) : '';
99                                                         $('mbts_total_paid').value = g.mbts.total_paid() ? util.money.sanitize( g.mbts.total_paid() ) : '';
100                                                         $('mbts_balance_owed').value = g.mbts.balance_owed() ? util.money.sanitize( g.mbts.balance_owed() ) : '';
101                                                 }
102                                         } catch(E) {
103                                                 g.error.sdump('D_ERROR',E);
104                                         }
105                                 }
106                         );
107                 }
108
109                 function retrieve_circ() {
110                         JSAN.use('util.widgets');
111                         util.widgets.remove_children('title');
112                         $('title_label').hidden = true;
113                         $('checked_out_label').hidden = true;
114                         $('due_label').hidden = true;
115                         $('checked_in_label').hidden = true;
116                         $('checked_out').value = '';
117                         $('checked_in').value = '';
118                         $('due').value = '';
119                         $('copy_summary').hidden=true;
120
121                         g.network.simple_request('FM_CIRC_RETRIEVE_VIA_ID', [ ses(), g.mbts_id ],
122                                 function (req) {
123                                         var r_circ = req.getResultObject();
124                                         if (instanceOf(r_circ,circ)) {
125
126                                                 $('title_label').hidden = false;
127                                                 $('checked_out_label').hidden = false;
128                                                 $('due_label').hidden = false;
129                                                 $('checked_in_label').hidden = false;
130                                                 $('checked_out').value = r_circ.xact_start() ? r_circ.xact_start().toString().substr(0,10) : '';
131                                                 $('checked_in').value = r_circ.checkin_time() ? r_circ.checkin_time().toString().substr(0,10) : '';
132                                                 $('due').value = r_circ.due_date() ? r_circ.due_date().toString().substr(0,10) : '';
133
134                                                 $('copy_summary').setAttribute('src',urls.XUL_COPY_SUMMARY + '?copy_id=' + r_circ.target_copy());
135                                                 $('copy_summary').hidden=false;
136
137                                                 g.network.simple_request(
138                                                         'MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',
139                                                         [ r_circ.target_copy() ],
140                                                         function (rreq) {
141                                                                 var r_mvr = rreq.getResultObject();
142                                                                 if (instanceOf(r_mvr,mvr)) {
143                                                                         $('title').appendChild( document.createTextNode( r_mvr.title().substr(0,50) ) );
144                                                                 } else {
145                                                                         g.network.simple_request(
146                                                                                 'FM_ACP_RETRIEVE',
147                                                                                 [ r_circ.target_copy() ],
148                                                                                 function (rrreq) {
149                                                                                         var r_acp = rrreq.getResultObject();
150                                                                                         if (instanceOf(r_acp,acp)) {
151                                                                                                 $('title').appendChild( document.createTextNode( r_acp.dummy_title() ) );
152                                                                                         }
153                                                                                 }
154                                                                         );
155                                                                 }
156                                                         }
157                                                 );
158
159                                         }
160                                 }
161                         );
162                 }
163
164                 function init_lists() {
165                         JSAN.use('util.list'); 
166                         g.bill_list = new util.list('bill_tree');
167
168                         g.bill_list.init( {
169                                 'columns' : patron.util.mbts_columns({}),
170                                 'map_row_to_column' : patron.util.std_map_row_to_column(' '),
171                                 'on_select' : function(ev) {
172                                         JSAN.use('util.functional');
173                                         g.bill_list_selection = util.functional.map_list(
174                                                 g.bill_list.retrieve_selection(),
175                                                 function(o) { return o.getAttribute('retrieve_id'); }
176                                         );
177                                         $('details').disabled = g.bill_list_selection.length == 0;
178                                         $('add').disabled = g.bill_list_selection.length == 0;
179                                         $('summary').hidden = g.bill_list_selection.length == 0;
180                                         $('copy_summary').hidden = g.bill_list_selection.length == 0;
181                                         g.mbts_id = g.bill_list_selection[0];
182                                         retrieve_specific_mbts();
183                                         retrieve_circ();
184                                 },
185                 'retrieve_row' : function(params) {
186                     var id = params.retrieve_id;
187                                         var row = params.row;
188                                         if (id) {
189                                                 var mbts_obj = g.network.simple_request('FM_MBTS_RETRIEVE',[ses(),id]);
190                                                 if (typeof row.my == 'undefined') row.my = {};
191                                                 row.my.mbts = mbts_obj;
192                                         }
193                                         if (typeof params.on_retrieve == 'function') {
194                                                 params.on_retrieve(row);
195                                         }
196                     return row;
197                 },
198                         } );
199
200                 }
201
202                 function my_init() {
203                         try {
204                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
205                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
206                                 JSAN.errorLevel = "die"; // none, warn, or die
207                                 JSAN.addRepository('/xul/server/');
208
209                                 JSAN.use('util.error'); g.error = new util.error();
210                                 JSAN.use('util.network'); g.network = new util.network();
211                                 JSAN.use('util.date');
212                                 JSAN.use('util.money');
213                                 JSAN.use('patron.util');
214                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
215                                 //g.data.temp = ''; g.data.stash('temp');
216
217                                 g.error.sdump('D_TRACE','my_init() for bill_history.xul');
218
219                                 g.cgi = new CGI();
220
221                                 retrieve_patron();
222
223                                 init_lists();
224
225                                 retrieve_mbts_for_list();
226
227                                 $('details').addEventListener(
228                                         'command',
229                                         handle_details,
230                                         false
231                                 );
232
233                                 $('add').addEventListener(
234                                         'command',
235                                         handle_add,
236                                         false
237                                 );
238
239                                 if (g.cgi.param('current')) {
240                                         $('caption').setAttribute('label','Current Bills');
241                                         document.title = 'Current Bills';
242                                 } else {
243                                         $('caption').setAttribute('label','Bill History');
244                                         document.title = 'Bill History';
245                                 }
246
247                         } catch(E) {
248                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
249                                         "system administrator or software developer the following:\nbill_history.xul\n" + E + '\n';
250                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
251                                 alert(err_msg);
252                         }
253                 }
254
255                 function handle_add() {
256                         var msg = 'Are you sure you would like to add a billing to bill' + ( g.bill_list_selection.length > 1 ? 's ' : ' ') + g.bill_list_selection + '?';
257                         var r = g.error.yns_alert(msg,'Bill Patron','Yes','No',null,'Check here to confirm this message');
258                         if (r == 0) {
259                                 JSAN.use('util.window');
260                                 var win = new util.window();
261                                 var w = win.open(
262                                         urls.XUL_PATRON_BILL_WIZARD
263                                                 + '?patron_id=' + window.escape(g.patron_id)
264                                                 + '&xact_id=' + window.escape( g.bill_list_selection[0] ),
265                                         'billwizard',
266                                         'chrome,resizable,modal'
267                                 );
268                                 g.bill_list.clear();
269                                 retrieve_mbts_for_list();
270                                 if (typeof window.refresh == 'function') window.refresh();
271                                 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
272                         }
273                 }
274
275                 function handle_details() {
276                         JSAN.use('util.window'); var win = new util.window();
277                         var w = win.open(
278                                 urls.XUL_PATRON_BILL_DETAILS 
279                                 + '?patron_id=' + window.escape(g.patron_id)
280                                 + '&mbts_id=' + window.escape( g.bill_list_selection[0] ),
281                                 'test_billdetails',
282                                 'chrome,resizable'
283                         );
284                         w.xulG = { 'refresh' : function() { 
285                                 if (typeof window.refresh == 'function') window.refresh();
286                                 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
287                         } };
288                 }
289
290                 function print_bills() {
291                         try {
292                                 g.bill_list.on_all_fleshed = function() {
293                                         try {
294                                                 var template = 'bills_historical'; if (g.cgi.param('current')) template = 'bills_current';
295                                                 JSAN.use('patron.util');
296                                                 var params = { 
297                                                         'patron' : patron.util.retrieve_au_via_id(ses(),g.patron_id), 
298                                                         'lib' : g.data.hash.aou[ g.data.list.au[0].ws_ou() ],
299                                                         'staff' : g.data.list.au[0],
300                                                         'header' : g.data.print_list_templates[template].header,
301                                                         'line_item' : g.data.print_list_templates[template].line_item,
302                                                         'footer' : g.data.print_list_templates[template].footer,
303                                                         'type' : g.data.print_list_templates[template].type,
304                                                         'list' : g.bill_list.dump_with_keys(),
305                                                         //'modal' : true,
306                                                 };
307                                                 JSAN.use('util.print'); var print = new util.print();
308                                                 print.tree_list( params );
309                                                 setTimeout(function(){ g.bill_list.on_all_fleshed = null; },0);
310                                         } catch(E) {
311                                                 g.error.standard_unexpected_error_alert('printing bills', E);
312                                         }
313                                 }
314                                 g.bill_list.full_retrieve();
315                         } catch(E) {
316                                 g.error.standard_unexpected_error_alert('printing bills', E);
317                         }
318                 }
319
320         ]]>
321         </script>
322
323         <vbox flex="1" class="my_overflow">
324                 <label id="patron_name" class="patronNameLarge"/>
325
326                 <vbox flex="0">
327                         <groupbox orient="vertical" flex="0" id="summary" hidden="true"/>
328                         <iframe id="copy_summary" hidden="true" flex="0"/>
329                 </vbox>
330
331                 <splitter><grippy/></splitter>
332
333                 <groupbox orient="vertical" flex="1">
334                         <caption id="caption" label="Bill History"/>
335                         <tree id="bill_tree" flex="1" enableColumnDrag="true" seltype="single"/>
336                         <hbox>
337                                 <spacer flex="1"/>
338                                 <button id="add" label="Add Billing" disabled="true"/>
339                                 <button id="details" label="Full Details" disabled="true" accesskey="D"/>
340                         </hbox>
341                 </groupbox>
342
343                 <hbox flex="0">
344                         <button id="opac" label="Show in Catalog" accesskey="S" hidden="true" oncommand="alert('Not Yet Implemented');"/>
345                         <button id="print" label="Print" accesskey="P" hidden="false" oncommand="print_bills();"/>
346                         <spacer flex="1"/>
347                         <button label="Close Window" oncommand="window.close()" accesskey="c"/>
348                 </hbox>
349         </vbox>
350
351
352 </window>
353