]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/circ/circ_utils.js
returning circ on transiting LOST
[working/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 msg = pretty_print( js2JSON( check ) );
176                                                 sdump('D_CIRC_UTILS',msg);
177                                                 alert(msg);
178                                         break;
179                                         case '3': case 3: /* TRANSIT ELSEWHERE */
180                                                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
181                                                 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
182                                                                 check.record.title() + '  Author: ' + check.record.author() + 
183                                                                 '\r\n' + 'Route To: ' + check.route_to + '\r\n';
184                                                 var pcheck = yns_alert(
185                                                         msg,
186                                                         'Alert',
187                                                         'Print Receipt',
188                                                         "Don't Print",
189                                                         null,
190                                                         "Check here to confirm this message"
191                                                 ); 
192                                                 if (pcheck == 0) {
193                                                         sPrint( msg.match( /\n/g, '<br />\r\n'), true );
194                                                 }
195
196                                         break;
197                                         case '4': case 4: /* transit for hold is complete */
198                                                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
199                                                 var msg = check.text + '\r\n' + 'Barcode: ' + barcode + '  Title: ' + 
200                                                                 check.record.title() + '  Author: ' + check.record.author() + 
201                                                                 '\r\n' + 'Route To: ' + check.route_to +
202                                                                 '\r\n';
203                                                 var pcheck = yns_alert(
204                                                         msg,
205                                                         'Alert',
206                                                         'Print Receipt',
207                                                         "Don't Print",
208                                                         null,
209                                                         "Check here to confirm this message"
210                                                 ); 
211                                                 if (pcheck == 0) {
212                                                         sPrint( msg.match( /\n/g, '<br />\r\n'), true );
213                                                 }
214
215                                         break;
216
217                                         default: 
218                                                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
219                                                 var msg = check.text + '\r\nBarcode: ' + barcode + '  Route To: ' + check.route_to;
220                                                 var pcheck = yns_alert(
221                                                         msg,
222                                                         'Alert',
223                                                         'Print Receipt',
224                                                         "Don't Print",
225                                                         null,
226                                                         "Check here to confirm this message"
227                                                 ); 
228                                                 if (pcheck == 0) {
229                                                         sPrint( msg.match( /\n/g, '<br />\r\n'), true );
230                                                 }
231                                         break;
232                                 }
233                         } else {  // status == 0
234                                 if (parseInt(check.route_to)) {
235                                         if (check.route_to != mw.G.user_ou.id()) {
236                                                 check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
237                                         } else {
238                                                 check.route_to = mw.G.acpl_hash[ check.copy.location() ].name();
239                                         }
240                                 }
241                         }
242                 }
243                 return check;
244         } catch(E) {
245                 handle_error(E, true);
246                 return null;
247         }
248 }
249
250 function renew_by_circ_id(id, f) {
251         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
252         try {
253                 var check = user_request(
254                         'open-ils.circ',
255                         'open-ils.circ.renew',
256                         [ mw.G.auth_ses[0], id ],
257                         f
258                 )[0];
259                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
260                 return check;
261         } catch(E) {
262                 sdump('D_ERROR',E);
263                 return null;
264         }
265 }
266
267 function hold_cols() {
268         var cols = [
269 {
270         'id' : 'request_time', 'label' : getString('ahr_request_time_label'), 'flex' : 0,
271         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
272         'fm_field_render' : '.request_time().toString().substr(0,10)'
273 },
274 {
275         'id' : 'status', 'label' : getString('ahr_status_label'), 'flex' : 1,
276         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.status()'
277 },
278 {
279         'id' : 'hold_type', 'label' : getString('ahr_hold_type_label'), 'flex' : 0,
280         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.hold_type()'
281 },
282 {
283         'id' : 'pickup_lib', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 1,
284         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 
285         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].name()'
286 },
287 {
288         'id' : 'pickup_lib_shortname', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 0,
289         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
290         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].shortname()'
291 },
292                 {
293                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 1,
294                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
295                 },
296                 {
297                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
298                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
299                 },
300 {
301         'id' : 'capture_time', 'label' : getString('ahr_capture_time_label'), 'flex' : 1,
302         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.capture_time()'
303 },
304 {
305         'id' : 'current_copy', 'label' : getString('ahr_current_copy_label'), 'flex' : 1,
306         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.current_copy()'
307 },
308 {
309         'id' : 'email_notify', 'label' : getString('ahr_email_notify_label'), 'flex' : 1,
310         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.email_notify()'
311 },
312 {
313         'id' : 'expire_time', 'label' : getString('ahr_expire_time_label'), 'flex' : 1,
314         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.expire_time()'
315 },
316 {
317         'id' : 'fulfillment_time', 'label' : getString('ahr_fulfillment_time_label'), 'flex' : 1,
318         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.fulfillment_time()'
319 },
320 {
321         'id' : 'holdable_formats', 'label' : getString('ahr_holdable_formats_label'), 'flex' : 1,
322         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.holdable_formats()'
323 },
324 {
325         'id' : 'id', 'label' : getString('ahr_id_label'), 'flex' : 1,
326         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.id()'
327 },
328 {
329         'id' : 'phone_notify', 'label' : getString('ahr_phone_notify_label'), 'flex' : 1,
330         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.phone_notify()'
331 },
332 {
333         'id' : 'prev_check_time', 'label' : getString('ahr_prev_check_time_label'), 'flex' : 1,
334         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.prev_check_time()'
335 },
336 {
337         'id' : 'requestor', 'label' : getString('ahr_requestor_label'), 'flex' : 1,
338         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.requestor()'
339 },
340 {
341         'id' : 'selection_depth', 'label' : getString('ahr_selection_depth_label'), 'flex' : 1,
342         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.selection_depth()'
343 },
344 {
345         'id' : 'target', 'label' : getString('ahr_target_label'), 'flex' : 1,
346         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.target()'
347 },
348 {
349         'id' : 'usr', 'label' : getString('ahr_usr_label'), 'flex' : 1,
350         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.usr()'
351 }
352         ];
353         return cols;
354 }
355
356 function checkin_cols() {
357         var cols = [
358                 {
359                         'id' : 'checkin_status', 'label' : getString('checkin_label_status'), 'flex' : 1,
360                         'primary' : false, 'hidden' : true, 'fm_class' : '', 'fm_field_render' : '.status.toString()'
361                 },
362                 {
363                         'id' : 'checkin_route_to', 'label' : getString('checkin_label_route_to'), 'flex' : 1,
364                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.route_to.toString()'
365                 },
366                 {
367                         'id' : 'checkin_text', 'label' : getString('checkin_label_text'), 'flex' : 1,
368                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.text.toString()'
369                 }
370         ];
371         var std_cols = map_list( 
372                 circ_cols(), 
373                 function(o){ if ((o.fm_class == 'acp')||(o.fm_class == 'circ')) o.hidden = true; return o; }
374         );
375         return cols.concat( std_cols );
376 }
377
378 function circ_cols() {
379         return  [
380                 {
381                         'id' : 'acp_id', 'label' : getString('acp_label_id'), 'flex' : 1,
382                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.id()'
383                 },
384                 {
385                         'id' : 'circ_id', 'label' : getString('circ_label_id'), 'flex' : 1,
386                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.id()'
387                 },
388                 {
389                         'id' : 'mvr_doc_id', 'label' : getString('mvr_label_doc_id'), 'flex' : 1,
390                         'primary' : false, 'hidden' : true, 'fm_class' : 'mvr', 'fm_field_render' : '.doc_id()'
391                 },
392                 {
393                         'id' : 'barcode', 'label' : getString('acp_label_barcode'), 'flex' : 1,
394                         'primary' : false, 'hidden' : false, 'fm_class' : 'acp', 'fm_field_render' : '.barcode()'
395                 },
396                 {
397                         'id' : 'call_number', 'label' : getString('acp_label_call_number'), 'flex' : 1,
398                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.call_number()'
399                 },
400                 {
401                         'id' : 'copy_number', 'label' : getString('acp_label_copy_number'), 'flex' : 1,
402                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.copy_number()'
403                 },
404                 {
405                         'id' : 'location', 'label' : getString('acp_label_location'), 'flex' : 1,
406                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.location()'
407                 },
408                 {
409                         'id' : 'loan_duration', 'label' : getString('acp_label_loan_duration'), 'flex' : 1,
410                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.loan_duration()'
411                 },
412                 {
413                         'id' : 'circ_lib', 'label' : getString('acp_label_circ_lib'), 'flex' : 1,
414                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_lib()'
415                 },
416                 {
417                         'id' : 'fine_level', 'label' : getString('acp_label_fine_level'), 'flex' : 1,
418                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.fine_level()'
419                 },
420                 {
421                         'id' : 'deposit', 'label' : getString('acp_label_deposit'), 'flex' : 1,
422                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit()'
423                 },
424                 {
425                         'id' : 'deposit_amount', 'label' : getString('acp_label_deposit_amount'), 'flex' : 1,
426                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit_amount()'
427                 },
428                 {
429                         'id' : 'price', 'label' : getString('acp_label_price'), 'flex' : 1,
430                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.price()'
431                 },
432                 {
433                         'id' : 'circ_as_type', 'label' : getString('acp_label_circ_as_type'), 'flex' : 1,
434                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_as_type()'
435                 },
436                 {
437                         'id' : 'circ_modifier', 'label' : getString('acp_label_circ_modifier'), 'flex' : 1,
438                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_modifier()'
439                 },
440                 {
441                         'id' : 'xact_start', 'label' : getString('circ_label_xact_start'), 'flex' : 1,
442                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_start()'
443                 },
444                 {
445                         'id' : 'xact_finish', 'label' : getString('circ_label_xact_finish'), 'flex' : 1,
446                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_finish()'
447                 },
448                 {
449                         'id' : 'due_date', 'label' : getString('circ_label_due_date'), 'flex' : 1,
450                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.due_date().substr(0,10)'
451                 },
452                 {
453                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 2,
454                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
455                 },
456                 {
457                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
458                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
459                 },
460                 {
461                         'id' : 'renewal_remaining', 'label' : getString('circ_label_renewal_remaining'), 'flex' : 0,
462                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.renewal_remaining()'
463                 },
464                 {
465                         'id' : 'status', 'label' : getString('acp_label_status'), 'flex' : 1,
466                         'primary' : false, 'hidden' : false, 'fm_class' : 'acp', 'fm_field_render' : 'mw.G.ccs_hash[ $$.status() ].name()'
467                 }
468         ]
469 };
470
471