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