]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/bill_details.xul
ad-hoc line-item billing.. some display fixes
[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
12 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
13 <!-- LOCALIZATION -->
14 <!DOCTYPE window PUBLIC "" ""[
15         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
16 ]>
17
18 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
19 <!-- OVERLAYS -->
20 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
21
22 <window id="bill_details_win" width="700" height="550"
23         onload="try{ my_init(); } catch(E) { alert(E); }"
24         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
25
26         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
27         <!-- BEHAVIOR -->
28         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
29         <scripts id="openils_util_scripts"/>
30
31         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
32         <script>
33         <![CDATA[
34
35                 function $(id) { return document.getElementById(id); }
36
37                 function retrieve_mbts() {
38                         g.network.simple_request('FM_MBTS_RETRIEVE',[g.session,g.mbts_id],
39                                 function(req) {
40                                         try {
41                                                 g.mbts = req.getResultObject();
42                                                 $('mbts_id').value = g.mbts.id();
43                                                 $('mbts_xact_type').value = g.mbts.xact_type();
44                                                 $('mbts_xact_start').value = g.mbts.xact_start().toString().substr(0,19);
45                                                 $('mbts_xact_finish').value = g.mbts.xact_finish() ? g.mbts.xact_finish().toString().substr(0,19) : '';
46                                                 $('mbts_total_owed').value = g.mbts.total_owed() ? util.money.sanitize( g.mbts.total_owed() ) : '';
47                                                 $('mbts_total_paid').value = g.mbts.total_paid() ? util.money.sanitize( g.mbts.total_paid() ) : '';
48                                                 $('mbts_balance_owed').value = g.mbts.balance_owed() ? util.money.sanitize( g.mbts.balance_owed() ) : '';
49                                         } catch(E) {
50                                                 g.error.sdump('D_ERROR',E);
51                                         }
52                                 }
53                         );
54                 }
55
56                 function retrieve_circ() {
57                         JSAN.use('util.widgets');
58                         g.network.simple_request('FM_CIRC_RETRIEVE_VIA_ID', [ g.session, g.mbts_id ],
59                                 function (req) {
60                                         var r_circ = req.getResultObject();
61                                         if (instanceOf(r_circ,circ)) {
62
63                                                 $('title_label').hidden = false;
64                                                 $('checked_out_label').hidden = false;
65                                                 $('due_label').hidden = false;
66                                                 $('checked_in_label').hidden = false;
67                                                 $('checked_out').value = r_circ.xact_start() ? r_circ.xact_start().toString().substr(0,10) : '';
68                                                 $('checked_in').value = r_circ.checkin_time() ? r_circ.checkin_time().toString().substr(0,10) : '';
69                                                 $('due').value = r_circ.due_date() ? r_circ.due_date().toString().substr(0,10) : '';
70
71                                                 g.network.simple_request(
72                                                         'MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',
73                                                         [ r_circ.target_copy() ],
74                                                         function (rreq) {
75                                                                 var r_mvr = rreq.getResultObject();
76                                                                 if (instanceOf(r_mvr,mvr)) {
77                                                                         util.widgets.remove_children('title');
78                                                                         $('title').appendChild( document.createTextNode( r_mvr.title() ) );
79                                                                 } else {
80                                                                         obj.network.simple_request(
81                                                                                 'FM_ACP_RETRIEVE',
82                                                                                 [ r_circ.target_copy() ],
83                                                                                 function (rrreq) {
84                                                                                         var r_acp = rrreq.getResultObject();
85                                                                                         if (instanceOf(r_acp,acp)) {
86                                                                                                 util.widgets.remove_children('title');
87                                                                                                 $('title').appendChild( document.createTextNode( r_acp.dummy_title() ) );
88                                                                                         }
89                                                                                 }
90                                                                         );
91                                                                 }
92                                                         }
93                                                 );
94
95                                         }
96                                 }
97                         );
98                 }
99
100                 function init_lists() {
101                         JSAN.use('util.list'); 
102                         g.bill_list = new util.list('bill_tree');
103                         g.payment_list = new util.list('payment_tree');
104
105                         g.bill_list.init( {
106                                 'columns' : patron.util.mb_columns({}),
107                                 'map_row_to_column' : patron.util.std_map_row_to_column(),
108                                 'on_select' : function(ev) {
109                                         JSAN.use('util.functional');
110                                         g.bill_list_selection = util.functional.map_list(
111                                                 g.bill_list.retrieve_selection(),
112                                                 function(o) { return o.getAttribute('retrieve_id'); }
113                                         );
114                                         $('void').disabled = g.bill_list_selection.length == 0;
115                                 },
116                         } );
117
118                         g.payment_list.init( {
119                                 'columns' : patron.util.mp_columns({}),
120                                 'map_row_to_column' : patron.util.std_map_row_to_column(),
121                                 'on_select' : function(ev) {
122                                         JSAN.use('util.functional');
123                                         g.payment_list_selection = util.functional.map_list(
124                                                 g.payment_list.retrieve_selection(),
125                                                 function(o) { return o.getAttribute('retrieve_id'); }
126                                         );
127                                         $('refund').disabled = g.payment_list_selection.length == 0;
128                                 },
129                         } );
130                 }
131
132                 function retrieve_mb() {
133                         var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID', [ g.session, g.mbts_id ] );
134
135                         var mb_funcs = [];
136
137                         function gen_mb_func(r) {
138                                 return function() {
139                                         g.bill_list.append( { 'retrieve_id' : r.id(), 'row' : { my : { 'mb' : r } } } );
140                                 }
141                         }
142
143                         for (var i = 0; i < mb_list.length; i++) {
144                                 mb_funcs.push( gen_mb_func(mb_list[i]) );
145                         }
146
147                         JSAN.use('util.exec');
148                         var mb_exec = new util.exec(4); mb_exec.chain(mb_funcs);
149                 }
150
151                 function retrieve_mp() {
152                         var mp_list = g.network.simple_request( 'FM_MP_RETRIEVE_VIA_MBTS_ID', [ g.session, g.mbts_id ]);
153
154                         var mp_funcs = [];
155
156                         function gen_mp_func(r) {
157                                 return function() {
158                                         g.payment_list.append( { 'retrieve_id' : r.id(), 'row' : { my : { 'mp' : r } } } );
159                                 }
160                         }
161
162                         for (var i = 0; i < mp_list.length; i++) {
163                                 mp_funcs.push( gen_mp_func(mp_list[i]) );
164                         }
165
166                         JSAN.use('util.exec');
167                         var mp_exec = new util.exec(4); mp_exec.chain(mp_funcs);
168                 }
169
170                 function my_init() {
171                         try {
172                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
173                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
174                                 JSAN.errorLevel = "die"; // none, warn, or die
175                                 JSAN.addRepository('/xul/server/');
176
177                                 JSAN.use('util.error'); g.error = new util.error();
178                                 JSAN.use('util.network'); g.network = new util.network();
179                                 JSAN.use('util.date');
180                                 JSAN.use('util.money');
181                                 JSAN.use('patron.util');
182                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
183                                 g.data.temp = ''; g.data.stash('temp');
184
185                                 g.error.sdump('D_TRACE','my_init() for bill_details.xul');
186
187                                 g.cgi = new CGI();
188
189                                 g.mbts_id = g.cgi.param('mbts_id');
190                                 g.session = g.cgi.param('session');
191
192                                 retrieve_mbts();
193                                 retrieve_circ();
194
195                                 init_lists();
196
197                                 retrieve_mb();
198                                 retrieve_mp();
199
200                                 $('void').addEventListener(
201                                         'command',
202                                         handle_void,
203                                         false
204                                 );
205
206                                 $('refund').addEventListener(
207                                         'command',
208                                         handle_refund,
209                                         false
210                                 );
211
212         
213                         } catch(E) {
214                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
215                                         "system administrator or software developer the following:\nbill_details.xul\n" + E + '\n';
216                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
217                                 alert(err_msg);
218                         }
219                 }
220
221                 function handle_void() {
222                         var msg = 'Are you sure you would like to void bill' + ( g.bill_list_selection.length > 1 ? 's ' : ' ') + g.bill_list_selection + '?';
223                         var r = g.error.yns_alert(msg,'Voiding Bills','Yes','No',null,'Check here to confirm this message');
224                         if (r == 0) {
225                                 for (var i = 0; i < g.bill_list_selection.length; i++) {
226                                         var robj = g.network.simple_request('FM_MB_VOID',[g.session,g.bill_list_selection[i]]);
227                                         if (robj.ilsevent) {
228                                                 switch(robj.ilsevent) {
229                                                         case -1 : g.error.standard_network_error_alert('Void of Bill #' + g.bill_list_selection[i] + ' failed.'); break;
230                                                         default: g.error.standard_unexpected_error_alert('Void of Bill #' + g.bill_list_selection[i] + ' failed.',robj); break;
231                                                 }
232                                         }
233                                 }
234                                 retrieve_mbts();
235                                 g.bill_list.clear();
236                                 retrieve_mb();
237                                 g.data.temp = 'refresh'; g.data.stash('temp');
238                         }
239                 }
240
241                 function handle_refund() {
242                         alert('Not Yet Implemented');
243                 }
244         ]]>
245         </script>
246
247         <vbox flex="1" class="my_overflow">
248                 <groupbox orient="vertical" flex="1">
249                         <caption label="Full Details"/>
250
251                         <groupbox orient="vertical" flex="1">
252                                 <caption label="Summary" />
253                                 <grid flex="1">
254                                         <columns>
255                                                 <column flex="1"/>
256                                                 <column flex="1"/>
257                                                 <column flex="1"/>
258                                                 <column flex="1"/>
259                                                 <column flex="1"/>
260                                                 <column flex="2"/>
261                                         </columns>
262                                         <rows>
263                                                 <row>
264                                                         <label class="header" value="Bill #"/>
265                                                         <label id="mbts_id" />
266                                                         <label class="header" value="Total Billed"/>
267                                                         <label id="mbts_total_owed" />
268                                                         <label class="header" id="title_label" value="Title" hidden="true"/>
269                                                         <description id="title"/>
270                                                 </row>
271                                                 <row>
272                                                         <label class="header" value="Type"/>
273                                                         <label id="mbts_xact_type"/>
274                                                         <label class="header" value="Total Paid"/>
275                                                         <label id="mbts_total_paid" />
276                                                         <label class="header" id="checked_out_label" value="Checked Out" hidden="true"/>
277                                                         <label id="checked_out"/>
278                                                 </row>
279                                                 <row>
280                                                         <label class="header" value="Start"/>
281                                                         <label id="mbts_xact_start"/>
282                                                         <label class="header" value="Balance Owed"/>
283                                                         <label id="mbts_balance_owed" />
284                                                         <label class="header" id="due_label" value="Due Date" hidden="true"/>
285                                                         <label id="due"/>
286                                                 </row>
287                                                 <row>
288                                                         <label class="header" value="Finish"/>
289                                                         <label id="mbts_xact_finish"/>
290                                                         <label/>
291                                                         <label/>
292                                                         <label class="header" id="checked_in_label" value="Checked In" hidden="true"/>
293                                                         <label id="checked_in"/>
294                                                 </row>
295                                         </rows>
296                                 </grid>
297                         </groupbox>
298
299                         <splitter><grippy/></splitter>
300
301                         <groupbox orient="vertical" flex="1">
302                                 <caption label="Bills" style="color: red"/>
303                                 <tree id="bill_tree" flex="1" enableColumnDrag="true"/>
304                                 <hbox><spacer flex="1"/><button id="void" label="Void selected billings" disabled="true"/></hbox>
305                         </groupbox>
306
307                         <splitter><grippy/></splitter>
308
309                         <groupbox orient="vertical" flex="1">
310                                 <caption label="Payments" style="color: green"/>
311                                 <tree id="payment_tree" flex="1" enableColumnDrag="true"/>
312                                 <hbox><spacer flex="1"/><button id="refund" label="Refund selected payments" disabled="true"/></hbox>
313                         </groupbox>
314
315                 </groupbox>
316                 <hbox>
317                         <button id="opac" label="Show in Catalog" accesskey="S" hidden="true"/>
318                         <spacer flex="1"/>
319                         <button label="Close Window" oncommand="window.close()" accesskey="c"/>
320                 </hbox>
321         </vbox>
322
323
324 </window>
325