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