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