1 angular.module('egCheckinApp', ['ngRoute', 'ui.bootstrap',
2 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
8 var resolver = {delay :
9 ['egStartup', function(egStartup) {return egStartup.go()}]}
11 $routeProvider.when('/circ/checkin/checkin', {
12 templateUrl: './circ/checkin/t_checkin',
13 controller: 'CheckinCtrl',
17 $routeProvider.when('/circ/checkin/capture', {
18 templateUrl: './circ/checkin/t_checkin',
19 controller: 'CheckinCtrl',
23 $routeProvider.otherwise({redirectTo : '/circ/checkin/checkin'});
26 .factory('checkinSvc', [function() {
28 service.checkins = [];
36 .controller('CheckinCtrl',
37 ['$scope','$q','$window','$location', '$timeout','egCore','checkinSvc','egGridDataProvider','egCirc', 'egItem',
38 function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , egGridDataProvider , egCirc, itemSvc) {
40 $scope.focusMe = true;
41 $scope.checkins = checkinSvc.checkins;
42 var today = new Date();
43 $scope.checkinArgs = {backdate : today}
44 $scope.using_hatch_printer = egCore.hatch.usePrinting();
45 $scope.modifiers = {};
46 $scope.fine_total = 0;
47 $scope.is_capture = $location.path().match(/capture$/);
48 var suppress_popups = false;
49 $scope.grid_persist_key = $scope.is_capture ?
50 'circ.checkin.capture' : 'circ.checkin.checkin';
52 // TODO: add this to the setting batch lookup below
53 egCore.hatch.getItem('circ.checkin.strict_barcode')
54 .then(function(sb){ $scope.strict_barcode = sb });
57 'ui.circ.suppress_checkin_popups' // add other settings as needed
58 ]).then(function(set) {
59 suppress_popups = set['ui.circ.suppress_checkin_popups'];
62 $scope.sort_money = function (a,b) {
63 var ma = parseFloat(a);
64 var mb = parseFloat(b);
65 if (ma < mb) return -1;
66 if (ma > mb) return 1;
70 // checkin & hold capture modifiers
81 if ($scope.is_capture) {
82 // in hold capture mode, some values are forced, regardless
83 // of stored preferences.
84 $scope.modifiers.noop = false;
85 $scope.modifiers.auto_print_holds_transits = true;
87 modifiers.push('noop'); // AKA suppress holds and transits
88 modifiers.push('auto_print_holds_transits');
89 modifiers.push('do_inventory_update');
92 // set modifiers from stored preferences
93 var snames = modifiers.map(function(m) {return 'eg.circ.checkin.' + m;});
94 egCore.hatch.getItemBatch(snames).then(function(settings) {
95 angular.forEach(settings, function(val, key) {
97 var parts = key.split('.')
98 var mod = parts.pop();
99 $scope.modifiers[mod] = true;
104 // set / unset a checkin modifier
105 // when set, store the preference
106 $scope.toggle_mod = function(mod) {
107 if ($scope.modifiers[mod]) {
108 $scope.modifiers[mod] = false;
109 egCore.hatch.removeItem('eg.circ.checkin.' + mod);
111 $scope.modifiers[mod] = true;
112 egCore.hatch.setItem('eg.circ.checkin.' + mod, true);
117 // ensure the backdate is not in the future
118 // note: input type=date max=foo not yet supported anywhere
119 $scope.$watch('checkinArgs.backdate', function(newval) {
120 if (newval && newval > today)
121 $scope.checkinArgs.backdate = today;
124 $scope.is_backdate = function() {
125 return $scope.checkinArgs.backdate < today;
128 var checkinGrid = $scope.gridControls = {};
130 $scope.gridDataProvider = egGridDataProvider.instance({
131 get : function(offset, count) {
132 return this.arrayNotifier($scope.checkins, offset, count);
136 // turns the various inputs (form args, modifiers, etc.) into
137 // checkin params and options.
138 function compile_checkin_args(args) {
139 var params = angular.copy(args);
141 // a backdate of 'today' is not really a backdate
142 // (and this particularly matters when checking in hourly
143 // loans, as backdated checkins currently get the time
144 // portion of the checkin time from the due date; this will
145 // stop mattering when FIXME bug 1793817 is dealt with)
146 if (!$scope.is_backdate())
147 delete params.backdate;
149 if (params.backdate) {
151 params.backdate.toISOString().replace(/T.*/,'');
154 angular.forEach(['noop','void_overdues',
155 'clear_expired','hold_as_transit','manual_float'],
157 if ($scope.modifiers[opt]) params[opt] = true;
161 if ($scope.modifiers.retarget_holds) {
162 if ($scope.modifiers.retarget_holds_all) {
163 params.retarget_mode = 'retarget.all';
165 params.retarget_mode = 'retarget';
168 if ($scope.modifiers.do_inventory_update) params.do_inventory_update = true;
170 egCore.hatch.setItem('circ.checkin.strict_barcode', $scope.strict_barcode);
171 egCore.hatch.setItem('circ.checkin.do_inventory_update', $scope.modifiers.do_inventory_update);
173 check_barcode : $scope.strict_barcode,
174 no_precat_alert : $scope.modifiers.no_precat_alert,
175 auto_print_holds_transits :
176 $scope.modifiers.auto_print_holds_transits,
177 suppress_popups : suppress_popups,
178 do_inventory_update : $scope.modifiers.do_inventory_update
181 return {params : params, options: options};
184 $scope.checkin = function(args) {
186 var compiled = compile_checkin_args(args);
187 args.copy_barcode = ''; // reset UI for next scan
188 $scope.focusMe = true;
190 delete $scope.billable_amount;
191 delete $scope.billable_barcode;
192 delete $scope.billable_user_id;
194 var params = compiled.params;
195 var options = compiled.options;
197 if (!params.copy_barcode) return;
201 index : checkinSvc.checkins.length,
202 input_barcode : params.copy_barcode
205 // track the item in the grid before sending the request
206 checkinSvc.checkins.unshift(row_item);
207 egCirc.checkin(params, options).then(
208 function(final_resp) {
210 row_item.evt = final_resp.evt;
211 angular.forEach(final_resp.data, function(val, key) {
215 row_item['copy_barcode'] = row_item.acp.barcode();
217 if (row_item.acp.latest_inventory() && row_item.acp.latest_inventory().inventory_date() == "now")
218 row_item.acp.latest_inventory().inventory_date(Date.now());
221 var amt = Number(row_item.mbts.balance_owed());
223 $scope.billable_barcode = row_item.copy_barcode;
224 $scope.billable_amount = amt;
225 $scope.billable_user_id = row_item.circ.usr();
227 ($scope.fine_total * 100 + amt * 100) / 100;
231 if (final_resp.evt.textcode == 'NO_CHANGE') {
233 {already_checked_in : final_resp.evt.copy_barcode};
236 if ($scope.trim_list && checkinSvc.checkins.length > 20) {
237 //cut array short at 20 items
238 checkinSvc.checkins.length = 20;
239 checkinGrid.prepend(20);
241 checkinGrid.prepend();
245 // Checkin was rejected somewhere along the way.
246 // Remove the copy from the grid since there was no action.
247 // note: since checkins are unshifted onto the array, the
248 // index value does not (generally) match the array position.
250 angular.forEach(checkinSvc.checkins, function(ci, idx) {
251 if (ci.index == row_item.index) pos = idx;
253 checkinSvc.checkins.splice(pos, 1);
255 })['finally'](function() {
256 // when all is said and done, refocus
257 $scope.focusMe = true;
261 $scope.print_receipt = function() {
262 var print_data = {checkins : []}
264 if (checkinSvc.checkins.length == 0) return $q.when();
266 angular.forEach(checkinSvc.checkins, function(checkin) {
269 copy : egCore.idl.toHash(checkin.acp) || {},
270 call_number : egCore.idl.toHash(checkin.acn) || {},
271 copy_barcode : checkin.copy_barcode,
272 title : checkin.title,
273 author : checkin.author
276 print_data.checkins.push(checkin);
279 return egCore.print.print({
280 template : 'checkin',
282 show_dialog : $scope.show_print_dialog
287 // --- context menu actions
289 $scope.fetchLastCircPatron = function(items) {
290 var checkin = items[0];
291 if (!checkin || !checkin.acp) return;
293 egCirc.last_copy_circ(checkin.acp.id())
294 .then(function(circ) {
297 // jump to the patron UI (separate app)
298 $window.location.href = $location
299 .path('/circ/patron/' + circ.usr() + '/checkout')
304 $scope.alert = {item_never_circed : checkin.acp.barcode()};
308 $scope.showBackdateDialog = function(items) {
311 angular.forEach(items, function(item) {
312 if (item.circ) circ_ids.push(item.circ.id());
315 if (circ_ids.length) {
316 egCirc.backdate_dialog(circ_ids).then(function(result) {
317 angular.forEach(items, function(item) {
318 item.circ.checkin_time(result.backdate);
321 // TODO: support grid row styling
322 checkinGrid.refresh();
326 $scope.showMarkDamaged = function(items) {
328 angular.forEach(items, function(item) {
330 egCirc.mark_damaged({
332 barcode: item.acp.barcode()
340 $scope.showMarkDiscard = function(items) {
342 angular.forEach(items, function(item) {
344 copies.push(egCore.idl.toHash(item.acp));
348 egCirc.mark_discard(copies).then(function() {
349 // update grid items?
354 $scope.abortTransit = function(items) {
355 var transit_ids = [];
356 angular.forEach(items, function(item) {
357 if (item.transit) transit_ids.push(item.transit.id());
360 egCirc.abort_transits(transit_ids).then(function() {
361 // update grid items?
365 $scope.add_copies_to_bucket = function(items){
367 angular.forEach(items, function(cp){
368 itemsIds.push(cp.acp.id());
371 itemSvc.add_copies_to_bucket(itemsIds);
374 $scope.showBibHolds = function(items){
376 angular.forEach(items, function(i){
377 recordIds.push(i.acn.record());
379 angular.forEach(recordIds, function (r) {
380 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
381 $timeout(function() { $window.open(url, '_blank') });
385 $scope.showLastCircs = function(items){
387 angular.forEach(items, function(cp){
388 itemIds.push(cp.acp.id());
390 angular.forEach(itemIds, function (id) {
391 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
392 $timeout(function() { $window.open(url, '_blank') });
396 $scope.selectedHoldingsVolCopyEdit = function (items) {
398 angular.forEach(items, function(i){
399 var h = egCore.idl.toHash(i);
401 'call_number.record.id': h.record.doc_id,
405 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
408 $scope.show_mark_missing_pieces = function(items){
409 angular.forEach(items, function(i){
410 i.acp.call_number(i.acn);
411 i.acp.call_number().record(i.record);
412 itemSvc.mark_missing_pieces(i.acp,$scope);
416 $scope.printSpineLabels = function(items){
418 angular.forEach(items, function(item) {
419 if (item.acp) copy_ids.push(item.acp.id());
421 itemSvc.print_spine_labels(copy_ids);
424 $scope.addCopyAlerts = function(items) {
426 angular.forEach(items, function(item) {
427 if (item.acp) copy_ids.push(item.acp.id());
429 egCirc.add_copy_alerts(copy_ids).then(function() {
430 // update grid items?
434 $scope.manageCopyAlerts = function(items) {
436 angular.forEach(items, function(item) {
437 if (item.acp) copy_ids.push(item.acp.id());
439 egCirc.manage_copy_alerts(copy_ids).then(function() {
440 // update grid items?