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 if (params.backdate) {
143 params.backdate.toISOString().replace(/T.*/,'');
145 // a backdate of 'today' is not really a backdate
146 if (params.backdate == $scope.max_backdate)
147 delete params.backdate;
150 angular.forEach(['noop','void_overdues',
151 'clear_expired','hold_as_transit','manual_float'],
153 if ($scope.modifiers[opt]) params[opt] = true;
157 if ($scope.modifiers.retarget_holds) {
158 if ($scope.modifiers.retarget_holds_all) {
159 params.retarget_mode = 'retarget.all';
161 params.retarget_mode = 'retarget';
164 if ($scope.modifiers.do_inventory_update) params.do_inventory_update = true;
166 egCore.hatch.setItem('circ.checkin.strict_barcode', $scope.strict_barcode);
167 egCore.hatch.setItem('circ.checkin.do_inventory_update', $scope.modifiers.do_inventory_update);
169 check_barcode : $scope.strict_barcode,
170 no_precat_alert : $scope.modifiers.no_precat_alert,
171 auto_print_holds_transits :
172 $scope.modifiers.auto_print_holds_transits,
173 suppress_popups : suppress_popups,
174 do_inventory_update : $scope.modifiers.do_inventory_update
177 return {params : params, options: options};
180 $scope.checkin = function(args) {
182 var compiled = compile_checkin_args(args);
183 args.copy_barcode = ''; // reset UI for next scan
184 $scope.focusMe = true;
186 delete $scope.billable_amount;
187 delete $scope.billable_barcode;
188 delete $scope.billable_user_id;
190 var params = compiled.params;
191 var options = compiled.options;
193 if (!params.copy_barcode) return;
197 index : checkinSvc.checkins.length,
198 input_barcode : params.copy_barcode
201 // track the item in the grid before sending the request
202 checkinSvc.checkins.unshift(row_item);
203 egCirc.checkin(params, options).then(
204 function(final_resp) {
206 row_item.evt = final_resp.evt;
207 angular.forEach(final_resp.data, function(val, key) {
211 row_item['copy_barcode'] = row_item.acp.barcode();
213 if (row_item.acp.latest_inventory() && row_item.acp.latest_inventory().inventory_date() == "now")
214 row_item.acp.latest_inventory().inventory_date(Date.now());
217 var amt = Number(row_item.mbts.balance_owed());
219 $scope.billable_barcode = row_item.copy_barcode;
220 $scope.billable_amount = amt;
221 $scope.billable_user_id = row_item.circ.usr();
223 ($scope.fine_total * 100 + amt * 100) / 100;
227 if (final_resp.evt.textcode == 'NO_CHANGE') {
229 {already_checked_in : final_resp.evt.copy_barcode};
232 if ($scope.trim_list && checkinSvc.checkins.length > 20)
233 //cut array short at 20 items
234 checkinSvc.checkins.length = 20;
237 // Checkin was rejected somewhere along the way.
238 // Remove the copy from the grid since there was no action.
239 // note: since checkins are unshifted onto the array, the
240 // index value does not (generally) match the array position.
242 angular.forEach(checkinSvc.checkins, function(ci, idx) {
243 if (ci.index == row_item.index) pos = idx;
245 checkinSvc.checkins.splice(pos, 1);
247 })['finally'](function() {
249 // when all is said and done, refresh the grid and refocus
250 checkinGrid.refresh();
251 $scope.focusMe = true;
255 $scope.print_receipt = function() {
256 var print_data = {checkins : []}
258 if (checkinSvc.checkins.length == 0) return $q.when();
260 angular.forEach(checkinSvc.checkins, function(checkin) {
263 copy : egCore.idl.toHash(checkin.acp) || {},
264 call_number : egCore.idl.toHash(checkin.acn) || {},
265 copy_barcode : checkin.copy_barcode,
266 title : checkin.title,
267 author : checkin.author
270 print_data.checkins.push(checkin);
273 return egCore.print.print({
274 template : 'checkin',
276 show_dialog : $scope.show_print_dialog
281 // --- context menu actions
283 $scope.fetchLastCircPatron = function(items) {
284 var checkin = items[0];
285 if (!checkin || !checkin.acp) return;
287 egCirc.last_copy_circ(checkin.acp.id())
288 .then(function(circ) {
291 // jump to the patron UI (separate app)
292 $window.location.href = $location
293 .path('/circ/patron/' + circ.usr() + '/checkout')
298 $scope.alert = {item_never_circed : checkin.acp.barcode()};
302 $scope.showBackdateDialog = function(items) {
305 angular.forEach(items, function(item) {
306 if (item.circ) circ_ids.push(item.circ.id());
309 if (circ_ids.length) {
310 egCirc.backdate_dialog(circ_ids).then(function(result) {
311 angular.forEach(items, function(item) {
312 item.circ.checkin_time(result.backdate);
315 // TODO: support grid row styling
316 checkinGrid.refresh();
320 $scope.showMarkDamaged = function(items) {
322 angular.forEach(items, function(item) {
324 egCirc.mark_damaged({
326 barcode: item.acp.barcode()
334 $scope.abortTransit = function(items) {
335 var transit_ids = [];
336 angular.forEach(items, function(item) {
337 if (item.transit) transit_ids.push(item.transit.id());
340 egCirc.abort_transits(transit_ids).then(function() {
341 // update grid items?
345 $scope.add_copies_to_bucket = function(items){
347 angular.forEach(items, function(cp){
348 itemsIds.push(cp.acp.id());
351 itemSvc.add_copies_to_bucket(itemsIds);
354 $scope.showBibHolds = function(items){
356 angular.forEach(items, function(i){
357 recordIds.push(i.acn.record());
359 angular.forEach(recordIds, function (r) {
360 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
361 $timeout(function() { $window.open(url, '_blank') });
365 $scope.showLastCircs = function(items){
367 angular.forEach(items, function(cp){
368 itemIds.push(cp.acp.id());
370 angular.forEach(itemIds, function (id) {
371 var url = egCore.env.basePath + 'cat/item/' + id + '/circs';
372 $timeout(function() { $window.open(url, '_blank') });
376 $scope.selectedHoldingsVolCopyEdit = function (items) {
378 angular.forEach(items, function(i){
379 var h = egCore.idl.toHash(i);
381 'call_number.record.id': h.record.doc_id,
385 itemSvc.spawnHoldingsEdit(itemObjs,false,false);
388 $scope.show_mark_missing_pieces = function(items){
389 angular.forEach(items, function(i){
390 i.acp.call_number(i.acn);
391 i.acp.call_number().record(i.record);
392 itemSvc.mark_missing_pieces(i.acp,$scope);
396 $scope.printSpineLabels = function(items){
398 angular.forEach(items, function(item) {
399 if (item.acp) copy_ids.push(item.acp.id());
401 itemSvc.print_spine_labels(copy_ids);
404 $scope.addCopyAlerts = function(items) {
406 angular.forEach(items, function(item) {
407 if (item.acp) copy_ids.push(item.acp.id());
409 egCirc.add_copy_alerts(copy_ids).then(function() {
410 // update grid items?
414 $scope.manageCopyAlerts = function(items) {
416 angular.forEach(items, function(item) {
417 if (item.acp) copy_ids.push(item.acp.id());
419 egCirc.manage_copy_alerts(copy_ids).then(function() {
420 // update grid items?