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;
241 // Checkin was rejected somewhere along the way.
242 // Remove the copy from the grid since there was no action.
243 // note: since checkins are unshifted onto the array, the
244 // index value does not (generally) match the array position.
246 angular.forEach(checkinSvc.checkins, function(ci, idx) {
247 if (ci.index == row_item.index) pos = idx;
249 checkinSvc.checkins.splice(pos, 1);
251 })['finally'](function() {
253 // when all is said and done, refresh the grid and refocus
254 checkinGrid.refresh();
255 $scope.focusMe = true;
259 $scope.print_receipt = function() {
260 var print_data = {checkins : []}
262 if (checkinSvc.checkins.length == 0) return $q.when();
264 angular.forEach(checkinSvc.checkins, function(checkin) {
267 copy : egCore.idl.toHash(checkin.acp) || {},
268 call_number : egCore.idl.toHash(checkin.acn) || {},
269 copy_barcode : checkin.copy_barcode,
270 title : checkin.title,
271 author : checkin.author
274 print_data.checkins.push(checkin);
277 return egCore.print.print({
278 template : 'checkin',
280 show_dialog : $scope.show_print_dialog
285 // --- context menu actions
287 $scope.fetchLastCircPatron = function(items) {
288 var checkin = items[0];
289 if (!checkin || !checkin.acp) return;
291 egCirc.last_copy_circ(checkin.acp.id())
292 .then(function(circ) {
295 // jump to the patron UI (separate app)
296 $window.location.href = $location
297 .path('/circ/patron/' + circ.usr() + '/checkout')
302 $scope.alert = {item_never_circed : checkin.acp.barcode()};
306 $scope.showBackdateDialog = function(items) {
309 angular.forEach(items, function(item) {
310 if (item.circ) circ_ids.push(item.circ.id());
313 if (circ_ids.length) {
314 egCirc.backdate_dialog(circ_ids).then(function(result) {
315 angular.forEach(items, function(item) {
316 item.circ.checkin_time(result.backdate);
319 // TODO: support grid row styling
320 checkinGrid.refresh();
324 $scope.showMarkDamaged = function(items) {
326 angular.forEach(items, function(item) {
328 egCirc.mark_damaged({
330 barcode: item.acp.barcode()
338 $scope.abortTransit = function(items) {
339 var transit_ids = [];
340 angular.forEach(items, function(item) {
341 if (item.transit) transit_ids.push(item.transit.id());
344 egCirc.abort_transits(transit_ids).then(function() {
345 // update grid items?
349 $scope.add_copies_to_bucket = function(items){
351 angular.forEach(items, function(cp){
352 itemsIds.push(cp.acp.id());
355 itemSvc.add_copies_to_bucket(itemsIds);
358 $scope.showBibHolds = function(items){
360 angular.forEach(items, function(i){
361 recordIds.push(i.acn.record());
363 angular.forEach(recordIds, function (r) {
364 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
365 $timeout(function() { $window.open(url, '_blank') });
369 $scope.showLastCircs = function(items){
371 angular.forEach(items, function(cp){
372 itemIds.push(cp.acp.id());
374 angular.forEach(itemIds, function (id) {
375 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
376 $timeout(function() { $window.open(url, '_blank') });
380 $scope.selectedHoldingsVolCopyEdit = function (items) {
382 angular.forEach(items, function(i){
383 var h = egCore.idl.toHash(i);
385 'call_number.record.id': h.record.doc_id,
389 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
392 $scope.show_mark_missing_pieces = function(items){
393 angular.forEach(items, function(i){
394 i.acp.call_number(i.acn);
395 i.acp.call_number().record(i.record);
396 itemSvc.mark_missing_pieces(i.acp,$scope);
400 $scope.printSpineLabels = function(items){
402 angular.forEach(items, function(item) {
403 if (item.acp) copy_ids.push(item.acp.id());
405 itemSvc.print_spine_labels(copy_ids);
408 $scope.addCopyAlerts = function(items) {
410 angular.forEach(items, function(item) {
411 if (item.acp) copy_ids.push(item.acp.id());
413 egCirc.add_copy_alerts(copy_ids).then(function() {
414 // update grid items?
418 $scope.manageCopyAlerts = function(items) {
420 angular.forEach(items, function(item) {
421 if (item.acp) copy_ids.push(item.acp.id());
423 egCirc.manage_copy_alerts(copy_ids).then(function() {
424 // update grid items?