]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
handle new checkin code. doesnt handle all cases yet
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / util.js
1 dump('entering circ/util.js\n');
2
3 if (typeof circ == 'undefined') var circ = {};
4 circ.util = {};
5
6 circ.util.EXPORT_OK     = [ 
7         'columns', 'hold_columns', 'CHECKIN_VIA_BARCODE', 'std_map_row_to_column', 'hold_capture_via_copy_barcode'
8 ];
9 circ.util.EXPORT_TAGS   = { ':all' : circ.util.EXPORT_OK };
10
11 circ.util.columns = function(modify) {
12         
13         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
14
15         function getString(s) { return data.entities[s]; }
16
17         var c = [
18                 {
19                         'id' : 'acp_id', 'label' : getString('staff.acp_label_id'), 'flex' : 1,
20                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.id()'
21                 },
22                 {
23                         'id' : 'circ_id', 'label' : getString('staff.circ_label_id'), 'flex' : 1,
24                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.id()'
25                 },
26                 {
27                         'id' : 'mvr_doc_id', 'label' : getString('staff.mvr_label_doc_id'), 'flex' : 1,
28                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.doc_id()'
29                 },
30                 {
31                         'id' : 'barcode', 'label' : getString('staff.acp_label_barcode'), 'flex' : 1,
32                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.barcode()'
33                 },
34                 {
35                         'id' : 'call_number', 'label' : getString('staff.acp_label_call_number'), 'flex' : 1,
36                         'primary' : false, 'hidden' : true, 'render' : 'obj.network.simple_request("FM_ACN_RETRIEVE",[ my.acp.call_number() ]).label()'
37                 },
38                 {
39                         'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1,
40                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.copy_number()'
41                 },
42                 {
43                         'id' : 'location', 'label' : getString('staff.acp_label_location'), 'flex' : 1,
44                         'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.acpl[ my.acp.location() ].name()'
45                 },
46                 {
47                         'id' : 'loan_duration', 'label' : getString('staff.acp_label_loan_duration'), 'flex' : 1,
48                         'primary' : false, 'hidden' : true, 
49                         'render' : 'switch(my.acp.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }'
50                 },
51                 {
52                         'id' : 'circ_lib', 'label' : getString('staff.acp_label_circ_lib'), 'flex' : 1,
53                         'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.aou[ my.acp.circ_lib() ].shortname()'
54                 },
55                 {
56                         'id' : 'fine_level', 'label' : getString('staff.acp_label_fine_level'), 'flex' : 1,
57                         'primary' : false, 'hidden' : true,
58                         'render' : 'switch(my.acp.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }'
59                 },
60                 {
61                         'id' : 'deposit', 'label' : getString('staff.acp_label_deposit'), 'flex' : 1,
62                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit()'
63                 },
64                 {
65                         'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
66                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
67                 },
68                 {
69                         'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
70                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
71                 },
72                 {
73                         'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
74                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_as_type()'
75                 },
76                 {
77                         'id' : 'circ_modifier', 'label' : getString('staff.acp_label_circ_modifier'), 'flex' : 1,
78                         'primary' : false, 'hidden' : true, 'render' : 'my.acp.circ_modifier()'
79                 },
80                 {
81                         'id' : 'xact_start', 'label' : getString('staff.circ_label_xact_start'), 'flex' : 1,
82                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_start()'
83                 },
84                 {
85                         'id' : 'xact_finish', 'label' : getString('staff.circ_label_xact_finish'), 'flex' : 1,
86                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.xact_finish()'
87                 },
88                 {
89                         'id' : 'due_date', 'label' : getString('staff.circ_label_due_date'), 'flex' : 1,
90                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.due_date().substr(0,10)'
91                 },
92                 {
93                         'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 2,
94                         'primary' : false, 'hidden' : true, 'render' : 'try { my.mvr.title(); } catch(E) { my.acp.dummy_title(); }'
95                 },
96                 {
97                         'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
98                         'primary' : false, 'hidden' : true, 'render' : 'try { my.mvr.author(); } catch(E) { my.acp.dummy_author(); }'
99                 },
100                 {
101                         'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
102                         'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
103                 },
104                 {
105                         'id' : 'status', 'label' : getString('staff.acp_label_status'), 'flex' : 1,
106                         'primary' : false, 'hidden' : true, 'render' : 'obj.data.hash.ccs[ my.acp.status() ].name()'
107                 },
108                 {
109                         'id' : 'checkin_status', 'label' : getString('staff.checkin_label_status'), 'flex' : 1,
110                         'primary' : false, 'hidden' : true, 'render' : 'my.status.toString()'
111                 },
112                 {
113                         'id' : 'checkin_route_to', 'label' : getString('staff.checkin_label_route_to'), 'flex' : 1,
114                         'primary' : false, 'hidden' : true, 'render' : 'my.route_to.toString()'
115                 },
116                 {
117                         'id' : 'checkin_text', 'label' : getString('staff.checkin_label_text'), 'flex' : 1,
118                         'primary' : false, 'hidden' : true, 'render' : 'my.text.toString()'
119                 }
120
121         ];
122         for (var i = 0; i < c.length; i++) {
123                 if (modify[ c[i].id ]) {
124                         for (var j in modify[ c[i].id ]) {
125                                 c[i][j] = modify[ c[i].id ][j];
126                         }
127                 }
128         }
129         return c;
130 }
131
132 circ.util.hold_columns = function(modify) {
133         
134         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
135
136         function getString(s) { return data.entities[s]; }
137
138         var c = [
139                 {
140                         'id' : 'request_time', 'label' : getString('staff.ahr_request_time_label'), 'flex' : 0,
141                         'primary' : false, 'hidden' : true,  
142                         'render' : 'my.ahr.request_time().toString().substr(0,10)'
143                 },
144                 {
145                         'id' : 'capture_time', 'label' : getString('staff.ahr_capture_time_label'), 'flex' : 1,
146                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.capture_time()'
147                 },
148                 {
149                         'id' : 'status', 'label' : getString('staff.ahr_status_label'), 'flex' : 1,
150                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.status()'
151                 },
152                 {
153                         'id' : 'hold_type', 'label' : getString('staff.ahr_hold_type_label'), 'flex' : 0,
154                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.hold_type()'
155                 },
156                 {
157                         'id' : 'pickup_lib', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 1,
158                         'primary' : false, 'hidden' : true,  
159                         'render' : 'obj.data.hash.aou[ my.ahr.pickup_lib() ].name()'
160                 },
161                 {
162                         'id' : 'pickup_lib_shortname', 'label' : getString('staff.ahr_pickup_lib_label'), 'flex' : 0,
163                         'primary' : false, 'hidden' : true,  
164                         'render' : 'obj.data.hash.aou[ my.ahr.pickup_lib() ].shortname()'
165                 },
166                 {
167                         'id' : 'current_copy', 'label' : getString('staff.ahr_current_copy_label'), 'flex' : 1,
168                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.current_copy()'
169                 },
170                 {
171                         'id' : 'email_notify', 'label' : getString('staff.ahr_email_notify_label'), 'flex' : 1,
172                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.email_notify()'
173                 },
174                 {
175                         'id' : 'expire_time', 'label' : getString('staff.ahr_expire_time_label'), 'flex' : 1,
176                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.expire_time()'
177                 },
178                 {
179                         'id' : 'fulfillment_time', 'label' : getString('staff.ahr_fulfillment_time_label'), 'flex' : 1,
180                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.fulfillment_time()'
181                 },
182                 {
183                         'id' : 'holdable_formats', 'label' : getString('staff.ahr_holdable_formats_label'), 'flex' : 1,
184                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.holdable_formats()'
185                 },
186                 {
187                         'id' : 'id', 'label' : getString('staff.ahr_id_label'), 'flex' : 1,
188                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.id()'
189                 },
190                 {
191                         'id' : 'phone_notify', 'label' : getString('staff.ahr_phone_notify_label'), 'flex' : 1,
192                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.phone_notify()'
193                 },
194                 {
195                         'id' : 'prev_check_time', 'label' : getString('staff.ahr_prev_check_time_label'), 'flex' : 1,
196                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.prev_check_time()'
197                 },
198                 {
199                         'id' : 'requestor', 'label' : getString('staff.ahr_requestor_label'), 'flex' : 1,
200                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.requestor()'
201                 },
202                 {
203                         'id' : 'selection_depth', 'label' : getString('staff.ahr_selection_depth_label'), 'flex' : 1,
204                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.selection_depth()'
205                 },
206                 {
207                         'id' : 'target', 'label' : getString('staff.ahr_target_label'), 'flex' : 1,
208                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.target()'
209                 },
210                 {
211                         'id' : 'usr', 'label' : getString('staff.ahr_usr_label'), 'flex' : 1,
212                         'primary' : false, 'hidden' : true,  'render' : 'my.ahr.usr()'
213                 },
214                 {
215                         'id' : 'title', 'label' : getString('staff.mvr_label_title'), 'flex' : 1,
216                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.title()'
217                 },
218                 {
219                         'id' : 'author', 'label' : getString('staff.mvr_label_author'), 'flex' : 1,
220                         'primary' : false, 'hidden' : true, 'render' : 'my.mvr.author()'
221                 },
222
223         ];
224         for (var i = 0; i < c.length; i++) {
225                 if (modify[ c[i].id ]) {
226                         for (var j in modify[ c[i].id ]) {
227                                 c[i][j] = modify[ c[i].id ][j];
228                         }
229                 }
230         }
231         return c;
232 }
233
234 circ.util.std_map_row_to_column = function() {
235         return function(row,col) {
236                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
237                 // col contains one of the objects listed above in columns
238                 
239                 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
240                 var obj = {}; 
241                 JSAN.use('util.error'); obj.error = new util.error();
242                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
243                 JSAN.use('util.network'); obj.network = new util.network();
244
245                 var my = row.my;
246                 var value;
247                 try { 
248                         value = eval( col.render );
249                 } catch(E) {
250                         obj.error.sdump('D_ERROR','map_row_to_column: ' + E);
251                         value = '???';
252                 }
253                 return value;
254         }
255 }
256
257 circ.util.checkin_via_barcode = function(session,barcode,backdate) {
258         try {
259                 JSAN.use('util.error'); var error = new util.error();
260                 JSAN.use('util.network'); var network = new util.network();
261                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
262                 JSAN.use('util.date');
263                 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
264
265                 var params = { 'barcode' : barcode };
266                 if (backdate) params.backdate = backdate;
267
268                 var check = network.request(
269                         api.CHECKIN_VIA_BARCODE.app,
270                         api.CHECKIN_VIA_BARCODE.method,
271                         [ session, params ]
272                 );
273
274                 /* legacy */
275                 check.status = check.textcode;
276                 check.text = check.textcode;
277                 if (check.payload) { 
278                         check.copy = check.payload.copy;
279                         check.circ = check.payload.circ;
280                         check.record = check.payload.record;
281                         check.hold = check.payload.hold;
282                 } else {
283                         check.copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]);
284                         if (check.copy.ilsevent) {
285                                 check.text = check.copy.textcode; /* Probably 1502 - COPY_NOT_FOUND */
286                                 check.copy = new acp();
287                         } else {
288                                 check.record = network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY',[ check.copy.id() ]);
289                                 if (check.record.ilsevent) {
290                                         check.text = check.record.textcode; /* Probably 1202 - ITEM_NOT_CATALOGED */
291                                         if (check.record.ilsevent == 1202) check.route_to = 'CATALOGING';
292                                 }
293                         }
294                         check.circ = new aoc();
295                 }
296                 if (typeof check.route_to != 'undefined') {
297                         if (parseInt(check.route_to)) {
298                                 if (check.route_to != data.list.au[0].home_ou()) {
299                                         check.route_to = data.hash.aou[ check.route_to ].shortname();
300                                 } else {
301                                         check.route_to = data.hash.acpl[ check.copy.location() ].name();
302                                 }
303                         }
304                 } else {
305                         check.route_to = data.hash.acpl[ check.copy.location() ].name();
306                 }
307
308                 if (check.ilsevent != 0) {
309                         switch(check.ilsevent) {
310                                 case '1': case 1: /* possible hold capture */
311                                         var rv = error.yns_alert(
312                                                 check.textcode,
313                                                 'Alert',
314                                                 "Capture",
315                                                 "Don't Capture",
316                                                 null,
317                                                 "Check here to confirm this message"
318                                         );
319                                         switch(rv) {
320                                                 case 0: /* capture */
321                                                 try {
322                                                         var check2 = this.hold_capture_via_copy_barcode( session, barcode );
323                                                         if (check2) {
324                                                                 check.copy = check2.copy;
325                                                                 check.text = check2.textcode;
326                                                                 check.route_to = check2.route_to;
327                                                                 JSAN.use('patron.util');
328                                                                 var au_obj = patron.util.retrieve_au_via_id( session, check.payload.hold.usr() );
329                                                                 alert('To Printer\n' + check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
330                                                                         check.record.title() + '  Author: ' + check.record.author() + 
331                                                                         '\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
332                                                                         au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + 
333                                                                         au_obj.first_given_name() + '\r\n'); //FIXME
334
335                                                                 /*
336                                                                 sPrint(check.text + '<br />\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
337                                                                         check.record.title() + '  Author: ' + check.record.author() + 
338                                                                         '<br />\r\n' + 'Route To: ' + check.route_to + '  Patron: ' + 
339                                                                         au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' + 
340                                                                         au_obj.first_given_name() + '<br />\r\n'
341                                                                 );
342                                                                 */
343
344                                                         }
345
346                                                 } catch(E) { 
347                                                         error.sdump('D_ERROR',E + '\n'); 
348                                                         /* 
349                                                         // demo testing 
350                                                         check.text = 'Captured for Hold';
351                                                         check.route_to = 'ARL-ATH';
352                                                         */
353                                                 }
354                                                 break;
355                                                 case 1: /* don't capture */
356
357                                                         check.text = 'Not Captured for Hold';
358                                                 break;
359                                         }
360                                 break;
361                                 case '2': case 2: /* LOST??? */
362                                         JSAN.use('patron.util');
363                                         var au_obj = patron.util.retrieve_au_via_id( session, check.circ.usr() );
364                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
365                                                         check.record.title() + '  Author: ' + check.record.author() + '\r\n' +
366                                                         'Patron: ' + au_obj.card().barcode() + ' ' + au_obj.family_name() + ', ' +
367                                                         au_obj.first_given_name();
368                                         var pcheck = error.yns_alert(
369                                                 msg,
370                                                 'Lost Item',
371                                                 'Edit Copy & Patron',
372                                                 "Just Continue",
373                                                 null,
374                                                 "Check here to confirm this message"
375                                         ); 
376                                         if (pcheck == 0) {
377                                                 //FIXME//Re-implement
378                                                 /*
379                                                 var w = mw.spawn_main();
380                                                 setTimeout(
381                                                         function() {
382                                                                 mw.spawn_patron_display(w.document,'new_tab','main_tabbox',{'patron':au_obj});
383                                                                 mw.spawn_batch_copy_editor(w.document,'new_tab','main_tabbox',
384                                                                         {'copy_ids':[ check.copy.id() ]});
385                                                         }, 0
386                                                 );
387                                                 */
388                                         }
389                                 break;
390                                 case '3': case 3: /* TRANSIT ELSEWHERE */
391                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
392                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
393                                                         check.record.title() + '  Author: ' + check.record.author() + 
394                                                         '\r\n' + 'Route To: ' + check.route_to + '\r\n';
395                                         var pcheck = error.yns_alert(
396                                                 msg,
397                                                 'Alert',
398                                                 'Print Receipt',
399                                                 "Don't Print",
400                                                 null,
401                                                 "Check here to confirm this message"
402                                         ); 
403                                         if (pcheck == 0) {
404                                                 alert('To Printer\n' + msg); //FIXME//
405                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
406                                         }
407
408                                 break;
409                                 case '4': case 4: /* transit for hold is complete */
410                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
411                                         var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
412                                                         check.record.title() + '  Author: ' + check.record.author() + 
413                                                         '\r\n' + 'Route To: ' + check.route_to +
414                                                         '\r\n';
415                                         var pcheck = error.yns_alert(
416                                                 msg,
417                                                 'Alert',
418                                                 'Print Receipt',
419                                                 "Don't Print",
420                                                 null,
421                                                 "Check here to confirm this message"
422                                         ); 
423                                         if (pcheck == 0) {
424                                                 alert('To Printer\n' + msg); //FIXME//
425                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
426                                         }
427
428                                 break;
429
430                                 default: /* 1500 - "CIRCULATION_NOT_FOUND" */
431                                         if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
432                                         var msg = check.text + '\r\nBarcode: ' + barcode + '  Route To: ' + check.route_to;
433                                         var pcheck = error.yns_alert(
434                                                 msg,
435                                                 'Alert',
436                                                 'Print Receipt',
437                                                 "Don't Print",
438                                                 null,
439                                                 "Check here to confirm this message"
440                                         ); 
441                                         if (pcheck == 0) {
442                                                 alert('To Printer\n' + msg); //FIXME//
443                                                 //sPrint( msg.match( /\n/g, '<br />\r\n'), true );
444                                         }
445                                 break;
446                         }
447                 } else {  // ilsevent == 0
448                 }
449                 return check;
450         } catch(E) {
451                 JSAN.use('util.error'); var error = new util.error();
452                 var msg = E + '\n---\n' + js2JSON(E);
453                 error.sdump('D_ERROR',msg);
454                 alert(msg);
455                 return null;
456         }
457 }
458
459 circ.util.hold_capture_via_copy_barcode = function ( session, barcode, retrieve_flag ) {
460         try {
461                 JSAN.use('util.network'); var network = new util.network();
462                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
463                 var robj = network.request(
464                         api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.app,
465                         api.CAPTURE_COPY_FOR_HOLD_VIA_BARCODE.method,
466                         [ session, barcode, retrieve_flag ]
467                 );
468                 var check = robj.payload;
469                 if (!check) {
470                         check = {};
471                         check.status = robj.ilsevent;
472                         check.copy = new acp(); check.copy.barcode( barcode );
473                 }
474                 check.text = robj.textcode;
475                 check.route_to = robj.route_to;
476                 //check.text = 'Captured for Hold';
477                 if (parseInt(check.route_to)) check.route_to = data.hash.aou[ check.route_to ].shortname();
478                 return check;
479         } catch(E) {
480                 JSAN.use('util.error'); var error = new util.error();
481                 var msg = E + '\n---\n' + js2JSON(E);
482                 error.sdump('D_ERROR',msg);
483                 alert(msg);
484                 return null;
485         }
486 }
487
488
489 dump('exiting circ/util.js\n');