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.modifiers = {};
45 $scope.fine_total = 0;
46 $scope.is_capture = $location.path().match(/capture$/);
47 var suppress_popups = false;
48 $scope.grid_persist_key = $scope.is_capture ?
49 'circ.checkin.capture' : 'circ.checkin.checkin';
51 egCore.hatch.usePrinting().then(function(useHatch) {
52 $scope.using_hatch_printer = useHatch;
55 // TODO: add this to the setting batch lookup below
56 egCore.hatch.getItem('circ.checkin.strict_barcode')
57 .then(function(sb){ $scope.strict_barcode = sb });
60 'ui.circ.suppress_checkin_popups' // add other settings as needed
61 ]).then(function(set) {
62 suppress_popups = set['ui.circ.suppress_checkin_popups'];
65 $scope.sort_money = function (a,b) {
66 var ma = parseFloat(a);
67 var mb = parseFloat(b);
68 if (ma < mb) return -1;
69 if (ma > mb) return 1;
73 // checkin & hold capture modifiers
84 if ($scope.is_capture) {
85 // in hold capture mode, some values are forced, regardless
86 // of stored preferences.
87 $scope.modifiers.noop = false;
88 $scope.modifiers.auto_print_holds_transits = true;
90 modifiers.push('noop'); // AKA suppress holds and transits
91 modifiers.push('auto_print_holds_transits');
92 modifiers.push('do_inventory_update');
95 // set modifiers from stored preferences
96 var snames = modifiers.map(function(m) {return 'eg.circ.checkin.' + m;});
97 egCore.hatch.getItemBatch(snames).then(function(settings) {
98 angular.forEach(settings, function(val, key) {
100 var parts = key.split('.')
101 var mod = parts.pop();
102 $scope.modifiers[mod] = true;
107 // set / unset a checkin modifier
108 // when set, store the preference
109 $scope.toggle_mod = function(mod) {
110 if ($scope.modifiers[mod]) {
111 $scope.modifiers[mod] = false;
112 egCore.hatch.removeItem('eg.circ.checkin.' + mod);
114 $scope.modifiers[mod] = true;
115 egCore.hatch.setItem('eg.circ.checkin.' + mod, true);
120 // ensure the backdate is not in the future
121 // note: input type=date max=foo not yet supported anywhere
122 $scope.$watch('checkinArgs.backdate', function(newval) {
123 if (newval && newval > today)
124 $scope.checkinArgs.backdate = today;
127 $scope.is_backdate = function() {
128 return $scope.checkinArgs.backdate < today;
131 var checkinGrid = $scope.gridControls = {};
133 $scope.gridDataProvider = egGridDataProvider.instance({
134 get : function(offset, count) {
135 return this.arrayNotifier($scope.checkins, offset, count);
139 // turns the various inputs (form args, modifiers, etc.) into
140 // checkin params and options.
141 function compile_checkin_args(args) {
142 var params = angular.copy(args);
144 // a backdate of 'today' is not really a backdate
145 // (and this particularly matters when checking in hourly
146 // loans, as backdated checkins currently get the time
147 // portion of the checkin time from the due date; this will
148 // stop mattering when FIXME bug 1793817 is dealt with)
149 if (!$scope.is_backdate())
150 delete params.backdate;
152 if (params.backdate) {
154 params.backdate.toISOString().replace(/T.*/,'');
157 angular.forEach(['noop','void_overdues',
158 'clear_expired','hold_as_transit','manual_float'],
160 if ($scope.modifiers[opt]) params[opt] = true;
164 if ($scope.modifiers.retarget_holds) {
165 if ($scope.modifiers.retarget_holds_all) {
166 params.retarget_mode = 'retarget.all';
168 params.retarget_mode = 'retarget';
171 if ($scope.modifiers.do_inventory_update) params.do_inventory_update = true;
173 egCore.hatch.setItem('circ.checkin.strict_barcode', $scope.strict_barcode);
174 egCore.hatch.setItem('circ.checkin.do_inventory_update', $scope.modifiers.do_inventory_update);
176 check_barcode : $scope.strict_barcode,
177 no_precat_alert : $scope.modifiers.no_precat_alert,
178 auto_print_holds_transits :
179 $scope.modifiers.auto_print_holds_transits,
180 suppress_popups : suppress_popups,
181 do_inventory_update : $scope.modifiers.do_inventory_update
184 return {params : params, options: options};
187 $scope.checkin = function(args) {
189 var compiled = compile_checkin_args(args);
190 args.copy_barcode = ''; // reset UI for next scan
191 $scope.focusMe = true;
193 delete $scope.billable_amount;
194 delete $scope.billable_barcode;
195 delete $scope.billable_user_id;
197 var params = compiled.params;
198 var options = compiled.options;
200 if (!params.copy_barcode) return;
204 index : checkinSvc.checkins.length,
205 input_barcode : params.copy_barcode
208 // track the item in the grid before sending the request
209 checkinSvc.checkins.unshift(row_item);
210 egCirc.checkin(params, options).then(
211 function(final_resp) {
213 row_item.evt = final_resp.evt;
214 angular.forEach(final_resp.data, function(val, key) {
218 row_item['copy_barcode'] = row_item.acp.barcode();
220 if (row_item.acp.latest_inventory() && row_item.acp.latest_inventory().inventory_date() == "now")
221 row_item.acp.latest_inventory().inventory_date(Date.now());
224 var amt = Number(row_item.mbts.balance_owed());
226 $scope.billable_barcode = row_item.copy_barcode;
227 $scope.billable_amount = amt;
228 $scope.billable_user_id = row_item.circ.usr();
230 ($scope.fine_total * 100 + amt * 100) / 100;
234 if (final_resp.evt.textcode == 'NO_CHANGE') {
236 {already_checked_in : final_resp.evt.copy_barcode};
239 if ($scope.trim_list && checkinSvc.checkins.length > 20) {
240 //cut array short at 20 items
241 checkinSvc.checkins.length = 20;
242 checkinGrid.prepend(20);
244 checkinGrid.prepend();
248 // Checkin was rejected somewhere along the way.
249 // Remove the copy from the grid since there was no action.
250 // note: since checkins are unshifted onto the array, the
251 // index value does not (generally) match the array position.
253 angular.forEach(checkinSvc.checkins, function(ci, idx) {
254 if (ci.index == row_item.index) pos = idx;
256 checkinSvc.checkins.splice(pos, 1);
258 })['finally'](function() {
259 // when all is said and done, refocus
260 $scope.focusMe = true;
264 $scope.print_receipt = function() {
265 var print_data = {checkins : []}
267 if (checkinSvc.checkins.length == 0) return $q.when();
269 angular.forEach(checkinSvc.checkins, function(checkin) {
272 copy : egCore.idl.toHash(checkin.acp) || {},
273 call_number : egCore.idl.toHash(checkin.acn) || {},
274 copy_barcode : checkin.copy_barcode,
275 title : checkin.title,
276 author : checkin.author
279 print_data.checkins.push(checkin);
282 return egCore.print.print({
283 template : 'checkin',
285 show_dialog : $scope.show_print_dialog
290 // --- context menu actions
292 $scope.fetchLastCircPatron = function(items) {
293 var checkin = items[0];
294 if (!checkin || !checkin.acp) return;
296 egCirc.last_copy_circ(checkin.acp.id())
297 .then(function(circ) {
300 // jump to the patron UI (separate app)
301 $window.location.href = $location
302 .path('/circ/patron/' + circ.usr() + '/checkout')
307 $scope.alert = {item_never_circed : checkin.acp.barcode()};
311 $scope.showBackdateDialog = function(items) {
314 angular.forEach(items, function(item) {
315 if (item.circ) circ_ids.push(item.circ.id());
318 if (circ_ids.length) {
319 egCirc.backdate_dialog(circ_ids).then(function(result) {
320 angular.forEach(items, function(item) {
321 item.circ.checkin_time(result.backdate);
324 // TODO: support grid row styling
325 checkinGrid.refresh();
329 $scope.showMarkDamaged = function(items) {
331 angular.forEach(items, function(item) {
333 egCirc.mark_damaged({
335 barcode: item.acp.barcode()
343 $scope.showMarkDiscard = function(items) {
345 angular.forEach(items, function(item) {
347 copies.push(egCore.idl.toHash(item.acp));
351 egCirc.mark_discard(copies).then(function() {
352 // update grid items?
357 $scope.abortTransit = function(items) {
358 var transit_ids = [];
359 angular.forEach(items, function(item) {
360 if (item.transit) transit_ids.push(item.transit.id());
363 egCirc.abort_transits(transit_ids).then(function() {
364 // update grid items?
368 $scope.add_copies_to_bucket = function(items){
370 angular.forEach(items, function(cp){
371 itemsIds.push(cp.acp.id());
374 itemSvc.add_copies_to_bucket(itemsIds);
377 $scope.showBibHolds = function(items){
379 angular.forEach(items, function(i){
380 recordIds.push(i.acn.record());
382 angular.forEach(recordIds, function (r) {
383 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
384 $timeout(function() { $window.open(url, '_blank') });
388 $scope.showLastCircs = function(items){
390 angular.forEach(items, function(cp){
391 itemIds.push(cp.acp.id());
393 angular.forEach(itemIds, function (id) {
394 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
395 $timeout(function() { $window.open(url, '_blank') });
399 $scope.selectedHoldingsVolCopyEdit = function (items) {
401 angular.forEach(items, function(i){
402 var h = egCore.idl.toHash(i);
404 'call_number.record.id': h.record.doc_id,
408 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
411 $scope.show_mark_missing_pieces = function(items){
412 angular.forEach(items, function(i){
413 i.acp.call_number(i.acn);
414 i.acp.call_number().record(i.record);
415 itemSvc.mark_missing_pieces(i.acp,$scope);
419 $scope.printSpineLabels = function(items){
421 angular.forEach(items, function(item) {
422 if (item.acp) copy_ids.push(item.acp.id());
424 itemSvc.print_spine_labels(copy_ids);
427 $scope.addCopyAlerts = function(items) {
429 angular.forEach(items, function(item) {
430 if (item.acp) copy_ids.push(item.acp.id());
432 egCirc.add_copy_alerts(copy_ids).then(function() {
433 // update grid items?
437 $scope.manageCopyAlerts = function(items) {
439 angular.forEach(items, function(item) {
440 if (item.acp) copy_ids.push(item.acp.id());
442 egCirc.manage_copy_alerts(copy_ids).then(function() {
443 // update grid items?