]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/circ/circ_utils.js
8ec90663d0cefad8be4c7e6721c6aeb225669922
[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 checkout_permit(barcode, patron_id, num_of_open_async_checkout_requests, f) {
27         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true,1:true,2:true}));
28         try {
29                 var check = user_request(
30                         'open-ils.circ',
31                         'open-ils.circ.permit_checkout',
32                         [ mw.G.auth_ses[0], barcode, patron_id, num_of_open_async_checkout_requests ],
33                         f
34                 )[0];
35                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
36                 return check;   
37         } catch(E) {
38                 handle_error(E);
39                 return null;
40         }       
41 }
42
43 function checkout_by_copy_barcode(barcode, patron_id, f) {
44         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true,1:true}));
45         try {
46                 var check = user_request(
47                         'open-ils.circ',
48                         'open-ils.circ.checkout.barcode',
49                         [ mw.G.auth_ses[0], barcode, patron_id ],
50                         f
51                 )[0];
52                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
53                 return check;
54         } catch(E) {
55                 sdump('D_ERROR',E);
56                 return null;
57         }
58 }
59
60 function hold_capture_by_copy_barcode( barcode, retrieve_flag ) {
61         try {
62                 var check = user_request(
63                         'open-ils.circ',
64                         'open-ils.circ.hold.capture_copy.barcode',
65                         [ mw.G.auth_ses[0], barcode, retrieve_flag ]
66                 )[0];
67                 check.text = 'Captured for Hold';
68                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
69                 return check;
70         } catch(E) {
71                 handle_error(E, true);
72                 return null;
73         }
74 }
75
76 function checkin_by_copy_barcode(barcode, backdate, f) {
77         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
78         try {
79                 if (backdate && (backdate == formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
80
81                 var check = user_request(
82                         'open-ils.circ',
83                         'open-ils.circ.checkin.barcode',
84                         [ mw.G.auth_ses[0], barcode, null, backdate ],
85                         f
86                 )[0];
87
88                 /*
89                 { // REMOVE_ME, forcing a condition for testing
90                         check.status = 1;
91                         check.text = 'This copy is the first that could fulfill a hold.  Do it?';
92                 }
93                 */
94
95                 if (!f) {
96                         sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
97                         if (check.status != 0) {
98                                 switch(check.status) {
99                                         case '1': case 1: /* possible hold capture */
100                                                 var rv = yns_alert(
101                                                         check.text,
102                                                         'Alert',
103                                                         "Capture",
104                                                         "Don't Capture",
105                                                         null,
106                                                         "Check here to confirm this message"
107                                                 );
108                                                 switch(rv) {
109                                                         case 0: /* capture */
110                                                         try {
111                                                                 var check2 = hold_capture_by_copy_barcode( barcode );
112                                                                 if (check2) {
113                                                                         sdump('D_CIRC_UTILS','check2 = ' + js2JSON(check2) + '\n');
114                                                                         check.copy = check2.copy;
115                                                                         check.text = check2.text;
116                                                                         check.route_to = check2.route_to;
117                                                                         sPrint(check.record.title() + '<br />\r\n' + check.text + '\r\n<br />Barcode: ' + barcode + '  Route to: ' + check.route_to + '\r\n' );
118                                                                 }
119
120                                                         } catch(E) { 
121                                                                 sdump('D_ERROR',E + '\n'); 
122                                                                 /* 
123                                                                 // demo testing 
124                                                                 check.text = 'Captured for Hold';
125                                                                 check.route_to = 'ARL-ATH';
126                                                                 */
127                                                         }
128                                                         break;
129                                                         case 1: /* don't capture */
130
131                                                                 check.text = 'Not Captured for Hold';
132                                                         break;
133                                                 }
134                                         break;
135
136                                         default: 
137                                                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
138                                                 var msg = check.text + '\r\nBarcode: ' + barcode + '  Route To: ' + check.route_to;
139                                                 var pcheck = yns_alert(
140                                                         msg,
141                                                         'Alert',
142                                                         'Print Receipt',
143                                                         "Don't Print",
144                                                         null,
145                                                         "Check here to confirm this message"
146                                                 ); 
147                                                 if (pcheck == 0) {
148                                                         sPrint( msg.match( /\n/g, '<br />\r\n'), true );
149                                                 }
150                                         break;
151                                 }
152                         }
153                 }
154                 if (parseInt(check.route_to)) check.route_to = mw.G.org_tree_hash[ check.route_to ].shortname();
155                 return check;
156         } catch(E) {
157                 handle_error(E, true);
158                 return null;
159         }
160 }
161
162 function renew_by_circ_id(id, f) {
163         sdump('D_CIRC_UTILS',arg_dump(arguments,{0:true}));
164         try {
165                 var check = user_request(
166                         'open-ils.circ',
167                         'open-ils.circ.renew',
168                         [ mw.G.auth_ses[0], id ],
169                         f
170                 )[0];
171                 if (!f) sdump('D_CIRC_UTILS','check = ' + js2JSON(check) + '\n');
172                 return check;
173         } catch(E) {
174                 sdump('D_ERROR',E);
175                 return null;
176         }
177 }
178
179 function hold_cols() {
180         var cols = [
181 {
182         'id' : 'request_time', 'label' : getString('ahr_request_time_label'), 'flex' : 0,
183         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
184         'fm_field_render' : '.request_time().toString().substr(0,10)'
185 },
186 {
187         'id' : 'status', 'label' : getString('ahr_status_label'), 'flex' : 1,
188         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.status()'
189 },
190 {
191         'id' : 'hold_type', 'label' : getString('ahr_hold_type_label'), 'flex' : 0,
192         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 'fm_field_render' : '.hold_type()'
193 },
194 {
195         'id' : 'pickup_lib', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 1,
196         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 
197         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].name()'
198 },
199 {
200         'id' : 'pickup_lib_shortname', 'label' : getString('ahr_pickup_lib_label'), 'flex' : 0,
201         'primary' : false, 'hidden' : false, 'fm_class' : 'ahr', 
202         'fm_field_render' : 'mw.G.org_tree_hash[ $$.pickup_lib() ].shortname()'
203 },
204                 {
205                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 1,
206                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
207                 },
208                 {
209                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
210                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
211                 },
212 {
213         'id' : 'capture_time', 'label' : getString('ahr_capture_time_label'), 'flex' : 1,
214         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.capture_time()'
215 },
216 {
217         'id' : 'current_copy', 'label' : getString('ahr_current_copy_label'), 'flex' : 1,
218         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.current_copy()'
219 },
220 {
221         'id' : 'email_notify', 'label' : getString('ahr_email_notify_label'), 'flex' : 1,
222         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.email_notify()'
223 },
224 {
225         'id' : 'expire_time', 'label' : getString('ahr_expire_time_label'), 'flex' : 1,
226         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.expire_time()'
227 },
228 {
229         'id' : 'fulfillment_time', 'label' : getString('ahr_fulfillment_time_label'), 'flex' : 1,
230         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.fulfillment_time()'
231 },
232 {
233         'id' : 'holdable_formats', 'label' : getString('ahr_holdable_formats_label'), 'flex' : 1,
234         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.holdable_formats()'
235 },
236 {
237         'id' : 'id', 'label' : getString('ahr_id_label'), 'flex' : 1,
238         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.id()'
239 },
240 {
241         'id' : 'phone_notify', 'label' : getString('ahr_phone_notify_label'), 'flex' : 1,
242         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.phone_notify()'
243 },
244 {
245         'id' : 'prev_check_time', 'label' : getString('ahr_prev_check_time_label'), 'flex' : 1,
246         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.prev_check_time()'
247 },
248 {
249         'id' : 'requestor', 'label' : getString('ahr_requestor_label'), 'flex' : 1,
250         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.requestor()'
251 },
252 {
253         'id' : 'selection_depth', 'label' : getString('ahr_selection_depth_label'), 'flex' : 1,
254         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.selection_depth()'
255 },
256 {
257         'id' : 'target', 'label' : getString('ahr_target_label'), 'flex' : 1,
258         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.target()'
259 },
260 {
261         'id' : 'usr', 'label' : getString('ahr_usr_label'), 'flex' : 1,
262         'primary' : false, 'hidden' : true, 'fm_class' : 'ahr', 'fm_field_render' : '.usr()'
263 }
264         ];
265         return cols;
266 }
267
268 function checkin_cols() {
269         var cols = [
270                 {
271                         'id' : 'checkin_status', 'label' : getString('checkin_label_status'), 'flex' : 1,
272                         'primary' : false, 'hidden' : true, 'fm_class' : '', 'fm_field_render' : '.status.toString()'
273                 },
274                 {
275                         'id' : 'checkin_route_to', 'label' : getString('checkin_label_route_to'), 'flex' : 1,
276                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.route_to.toString()'
277                 },
278                 {
279                         'id' : 'checkin_text', 'label' : getString('checkin_label_text'), 'flex' : 1,
280                         'primary' : false, 'hidden' : false, 'fm_class' : '', 'fm_field_render' : '.text.toString()'
281                 }
282         ];
283         var std_cols = map_list( 
284                 circ_cols(), 
285                 function(o){ if ((o.fm_class == 'acp')||(o.fm_class == 'circ')) o.hidden = true; return o; }
286         );
287         return cols.concat( std_cols );
288 }
289
290 function circ_cols() {
291         return  [
292                 {
293                         'id' : 'barcode', 'label' : getString('acp_label_barcode'), 'flex' : 1,
294                         'primary' : false, 'hidden' : false, 'fm_class' : 'acp', 'fm_field_render' : '.barcode()'
295                 },
296                 {
297                         'id' : 'call_number', 'label' : getString('acp_label_call_number'), 'flex' : 1,
298                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.call_number()'
299                 },
300                 {
301                         'id' : 'copy_number', 'label' : getString('acp_label_copy_number'), 'flex' : 1,
302                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.copy_number()'
303                 },
304                 {
305                         'id' : 'status', 'label' : getString('acp_label_status'), 'flex' : 1,
306                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.status()'
307                 },
308                 {
309                         'id' : 'location', 'label' : getString('acp_label_location'), 'flex' : 1,
310                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.location()'
311                 },
312                 {
313                         'id' : 'loan_duration', 'label' : getString('acp_label_loan_duration'), 'flex' : 1,
314                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.loan_duration()'
315                 },
316                 {
317                         'id' : 'circ_lib', 'label' : getString('acp_label_circ_lib'), 'flex' : 1,
318                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_lib()'
319                 },
320                 {
321                         'id' : 'fine_level', 'label' : getString('acp_label_fine_level'), 'flex' : 1,
322                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.fine_level()'
323                 },
324                 {
325                         'id' : 'deposit', 'label' : getString('acp_label_deposit'), 'flex' : 1,
326                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit()'
327                 },
328                 {
329                         'id' : 'deposit_amount', 'label' : getString('acp_label_deposit_amount'), 'flex' : 1,
330                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.deposit_amount()'
331                 },
332                 {
333                         'id' : 'price', 'label' : getString('acp_label_price'), 'flex' : 1,
334                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.price()'
335                 },
336                 {
337                         'id' : 'circ_as_type', 'label' : getString('acp_label_circ_as_type'), 'flex' : 1,
338                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_as_type()'
339                 },
340                 {
341                         'id' : 'circ_modifier', 'label' : getString('acp_label_circ_modifier'), 'flex' : 1,
342                         'primary' : false, 'hidden' : true, 'fm_class' : 'acp', 'fm_field_render' : '.circ_modifier()'
343                 },
344                 {
345                         'id' : 'xact_start', 'label' : getString('circ_label_xact_start'), 'flex' : 1,
346                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_start()'
347                 },
348                 {
349                         'id' : 'xact_finish', 'label' : getString('circ_label_xact_finish'), 'flex' : 1,
350                         'primary' : false, 'hidden' : true, 'fm_class' : 'circ', 'fm_field_render' : '.xact_finish()'
351                 },
352                 {
353                         'id' : 'renewal_remaining', 'label' : getString('circ_label_renewal_remaining'), 'flex' : 1,
354                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.renewal_remaining()'
355                 },
356                 {
357                         'id' : 'due_date', 'label' : getString('circ_label_due_date'), 'flex' : 1,
358                         'primary' : false, 'hidden' : false, 'fm_class' : 'circ', 'fm_field_render' : '.due_date().substr(0,10)'
359                 },
360                 {
361                         'id' : 'title', 'label' : getString('mvr_label_title'), 'flex' : 2,
362                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.title()'
363                 },
364                 {
365                         'id' : 'author', 'label' : getString('mvr_label_author'), 'flex' : 1,
366                         'primary' : false, 'hidden' : false, 'fm_class' : 'mvr', 'fm_field_render' : '.author()'
367                 }
368                 
369         ]
370 };
371
372