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