}
});
- return process_next('receive', list, $scope.receive_and_barcode);
+ return egSerialsCoreSvc.process_items('receive', $scope.bibId, list, $scope.receive_and_barcode, false, $scope.do_print_routing_lists, function(){reload($scope.ssubId,_paging_filter)});
}
$scope.receive_selected = function (list) {
- return process_next('receive', list.map(function(item) {
+ var items = list.filter(function(i){
+ return i.status == 'Expected';
+ });
+ return egSerialsCoreSvc.process_items('receive', $scope.bibId, items.map(function(item) {
return egCore.idl.Clone(egSerialsCoreSvc.itemMap[item.id]);
- }), $scope.receive_and_barcode);
+ }), $scope.receive_and_barcode, false, $scope.do_print_routing_lists, function(){reload($scope.ssubId,_paging_filter)});
}
$scope.reset_selected = function (list) {
- return process_next('reset', list.map(function(item) {
+ return egSerialsCoreSvc.process_items('reset', $scope.bibId, list.map(function(item) {
return egCore.idl.Clone(egSerialsCoreSvc.itemMap[item.id]);
- }));
+ }), false, false, $scope.do_print_routing_lists, function(){reload($scope.ssubId,_paging_filter)});
}
$scope.bind_selected = function (list) {
- return process_next('bind', list.map(function(item) {
+ return egSerialsCoreSvc.process_items('bind', $scope.bibId, list.map(function(item) {
return egCore.idl.Clone(egSerialsCoreSvc.itemMap[item.id]);
- }), true, true);
- }
-
- function process_next (mode, list, do_barcode, bind) {
- var bibId = $scope.bibId;
-
- if (!list.length) return $q.reject();
-
- // deal with locations and circ mods for *NEW* units
- var copy_locations = {};
- var circ_mods = {};
-
- // deal with barcodes and call numbers for *NEW* units
- var barcodes = {};
- var call_numbers = {};
- var call_numbers_by_siss_and_sdist = {};
-
- var deferred = $q.defer();
- var current_promise = deferred.promise;
- var last_promise;
- if (do_barcode || bind) {
-
- var print_routing_lists = $scope.do_print_routing_lists;
- last_promise = current_promise.then(function(){ return $uibModal.open({
- templateUrl: './serials/t_batch_receive',
- size: 'lg',
- windowClass: 'eg-wide-modal',
- backdrop: 'static',
- controller:
- ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
-
- $scope.print_routing_lists = print_routing_lists;
- $scope.barcode_items = do_barcode;
- $scope.force_bind = bind;
- $scope.bind = bind;
- $scope.items = list;
- $scope.acn_list = [];
- $scope.acpl_list = [];
-
- $scope.cannot_print = function (index) {
- return $scope.items[index].stream().routing_list_users().length == 0 || ($scope.bind && index > 0);
- }
-
- $scope.bind_or_none = function (index) {
- return !$scope.barcode_items || ($scope.bind && index > 0);
- }
-
- $scope.focus_next_barcode = function (index) {
- index++;
- $('#item_barcode_'+index).focus().select();
- }
-
- $scope.apply_template_overrides = function (e) {
- if ($scope.selected_call_number) {
- angular.forEach($scope.items, function (i) {
- i._call_number = $scope.selected_call_number;
- });
- }
- if ($scope.selected_circ_mod) {
- angular.forEach($scope.items, function (i) {
- i._circ_mod = $scope.selected_circ_mod;
- });
- }
- if ($scope.selected_copy_location) {
- angular.forEach($scope.items, function (i) {
- i._copy_location = $scope.selected_copy_location;
- });
- }
- }
-
- $scope.ok = function(items) { $uibModalInstance.close(items) }
- $scope.cancel = function () { $uibModalInstance.dismiss() }
-
- var pile_o_promises = [$q.when()];
- // let's gather what we need...
- angular.forEach(list, function (i, index) {
- if (i.unit()) {
- i._barcode = i.unit().barcode();
- pile_o_promises.push(
- egCore.pcrud.retrieve(
- 'acn', i.unit().call_number()
- ).then(function(cn){ if (cn.deleted() == 'f') i._call_number = cn.label() })
- );
- } else {
- if (i.stream().distribution()[mode + '_call_number']() &&
- i.stream().distribution()[mode + '_call_number']().deleted() == 'f'
- ) {
- i._call_number = i.stream().distribution()[mode + '_call_number']().label();
- } else {
- pile_o_promises.push(
- egSerialsCoreSvc.fetchLastCallnumber(
- i.stream().distribution().holding_lib().id()
- ).then(function(cn){ i._call_number = cn.label() })
- );
- }
- }
-
- if (i.stream().distribution()[mode + '_unit_template']()) {
- i._copy_location = i.stream().distribution()[mode + '_unit_template']().location();
- i._circ_mod = i.stream().distribution()[mode + '_unit_template']().circ_modifier();
- }
-
- if ($scope.print_routing_lists && !$scope.cannot_print(index))
- i._print_routing_list = true;
- });
-
- pile_o_promises.push(egCore.pcrud.search(
- 'acpl',
- {owning_lib : egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
- {},{ atomic : true }
- ).then(function (list) {
- $scope.acpl_list = list.map(function(i){return egCore.idl.toHash(i)});
- return $q.when();
- }));
-
- pile_o_promises.push(egCore.pcrud.search(
- 'acn',
- {deleted : 'f', record : bibId, owning_lib : egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
- {},{ atomic : true }
- ).then(function (list) {
- $scope.acn_list = list.map(function(i){return egCore.idl.toHash(i)});
- return $q.when();
- }));
-
- pile_o_promises.push(egCore.pcrud.retrieveAll(
- 'ccm', {}, { atomic : true }
- ).then(function (list) {
- $scope.ccm_list = list.map(function(i){return egCore.idl.toHash(i)});
- return $q.when();
- }));
-
- $q.all(pile_o_promises).then(function() {
- console.log('receive data collected');
- });
-
- $scope.$watch('barcode_items', function (n,o) {
- if (n === undefined || n == o) return;
- do_barcode = n;
- });
-
- $scope.$watch('bind', function (n,o) {
- if (n === undefined || n == o) return;
- bind = n;
- if (bind) {
- angular.forEach($scope.items, function (i,index) {
- if (index > 0) i._print_routing_list = false;
- });
- }
- });
-
- $scope.$watch('auto_barcodes', function (n,o) {
- if (n === undefined || n == o) return;
-
- var bc = '@@AUTO';
- if (!n) bc = '';
-
- angular.forEach($scope.items, function (i) {
- var _barcode = i._barcode;
- i._barcode = bc || i._old_barcode;
- i._old_barcode = _barcode;
- });
- });
-
- $scope.$watch('print_routing_lists', function (n,o) {
- if (n === undefined || n == o) return;
-
- angular.forEach($scope.items, function(i, index) {
- if (!$scope.cannot_print(index)) {
- i._print_routing_list = n;
- } else {
- i._print_routing_list = false;
- }
- });
- });
- }]
- }).result});
- } else {
- last_promise = current_promise.then(function(){
- return egConfirmDialog.open(
- egCore.strings.CONFIRM_CHANGE_ITEMS[mode],
- egCore.strings.CONFIRM_CHANGE_ITEMS_MESSAGE[mode],
- {items : list.length}
- ).result.then(function () {
- return $q.when(list);
- });
- });
- }
-
- last_promise.then(function (items) {
-
- var donor_unit_ids = {};
- angular.forEach(items, function(i, index) {
- if (i.unit()) donor_unit_ids[i.unit().id()] = 1;
- if (do_barcode) i.unit(-1);
- if (bind) i.unit(-2);
- copy_locations[i.id()] = i._copy_location;
- circ_mods[i.id()] = i._circ_mod;
- call_numbers[i.id()] = i._call_number || 'DEFAULT';
- barcodes[i.id()] = i._barcode || '@@AUTO';
- if (bind && index > 0) barcodes[i.id()] = items[0]._barcode;
- });
-
- var method;
- if (mode == 'receive') {
- method = 'open-ils.serial.receive_items';
- } else if ( mode == 'bind') {
- method = 'open-ils.serial.bind_items';
- } else if ( mode == 'reset') {
- method = 'open-ils.serial.reset_items';
- }
-
- return egCore.net.request(
- 'open-ils.serial', method,
- egCore.auth.token(), items, barcodes, call_numbers, donor_unit_ids,
- {circ_mods:circ_mods, copy_locations : copy_locations}
- ).then(
- function(resp) {
- var evt = egCore.evt.parse(resp);
- if (evt) {
- ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
- } else {
- ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
- return $scope.print_routing_lists_impl(items, do_barcode || bind)
- .finally(function(){reload($scope.ssubId,_paging_filter)});
- }
- },
- function(resp) {
- ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
- }
- );
- });
-
- return deferred.resolve();
+ }), true, true, $scope.do_print_routing_lists, function(){reload($scope.ssubId,_paging_filter)});
}
$scope.menu_print_routing_lists = function (items) {
items = items.map(function(item) {
return egCore.idl.Clone(egSerialsCoreSvc.itemMap[item.id]);
});
- return $scope.print_routing_lists_impl(items, false, true);
- }
-
- $scope.print_routing_lists_impl = function (items, check, force) {
- if (!check && !$scope.do_print_routing_lists && !force) return $q.when();
-
- return egCore.net.request(
- 'open-ils.search',
- 'open-ils.search.biblio.record.mods_slim.retrieve',
- $scope.bibId
- ).then(function(mvr) {
-
- var by_issuance = {};
- angular.forEach(items, function (i) {
- if (check && !i._print_routing_list) return;
- if (!by_issuance[i.issuance().id()])
- by_issuance[i.issuance().id()] = [];
- by_issuance[i.issuance().id()].push(i);
- });
-
- var issuance_matrix = [];
- angular.forEach(by_issuance, function (list) {
- issuance_matrix.push(list);
- });
-
- var deferred = $q.defer();
- var promise = deferred.promise;
-
- angular.forEach(issuance_matrix, function(item_list, index) {
-
- promise = promise.then(function(){
- return $uibModal.open({
- templateUrl: './serials/t_print_routing_list',
- size: 'lg',
- windowClass: 'eg-wide-modal',
- backdrop: 'static',
- controller:
- ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
- var all_users = [];
- var all_streams = [];
-
- angular.forEach(item_list, function(i){
- all_streams.push(i.stream());
- all_users = all_users.concat(i.stream().routing_list_users());
- });
-
- $scope.xulg = {
- show_print_button: true,
- routing_list_data: {
- streams : all_streams,
- mvr : mvr,
- issuance: item_list[0].issuance(),
- users : orderByFilter(all_users, 'pos')
- }
- };
-
- $scope.url = '/eg/serial/print_routing_list_users?ses=' + egCore.auth.token();
- $scope.last = index == issuance_matrix.length - 1 ? true : false;
- $scope.ok = function() { $uibModalInstance.close() }
- }]
- }).result;
- });
-
- });
-
- return deferred.resolve();
- });
-
+ return egSerialsCoreSv.print_routing_lists($scope.bibId, items, false, true, $scope.do_print_routing_lists);
}
$scope.add_issuances = function () {
return true;
};
+ $scope.need_expected = function() {
+ var items = $scope.itemGridControls.selectedItems().filter(function(i){
+ return i.status == 'Expected';
+ });
+ if (items.length) return false;
+ return true;
+ };
+
}]
}
angular.module('egSerialsMod', ['egCoreMod'])
.factory('egSerialsCoreSvc',
- ['egCore','orderByFilter','$q','$filter','$uibModal',
-function(egCore , orderByFilter , $q , $filter , $uibModal) {
+ ['egCore','orderByFilter','$q','$filter','$uibModal','ngToast','egConfirmDialog',
+function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirmDialog) {
var DAY = 86400000;
var service = {
bibId : null,
);
};
+ service.print_routing_lists = function (bibId, items, check, force, print_rl) {
+ if (!check && !print_rl && !force) return $q.when();
+
+ return egCore.net.request(
+ 'open-ils.search',
+ 'open-ils.search.biblio.record.mods_slim.retrieve',
+ bibId
+ ).then(function(mvr) {
+
+ var by_issuance = {};
+ angular.forEach(items, function (i) {
+ if (check && !i._print_routing_list) return;
+ if (!by_issuance[i.issuance().id()])
+ by_issuance[i.issuance().id()] = [];
+ by_issuance[i.issuance().id()].push(i);
+ });
+
+ var issuance_matrix = [];
+ angular.forEach(by_issuance, function (list) {
+ issuance_matrix.push(list);
+ });
+
+ var deferred = $q.defer();
+ var promise = deferred.promise;
+
+ angular.forEach(issuance_matrix, function(item_list, index) {
+
+ promise = promise.then(function(){
+ return $uibModal.open({
+ templateUrl: './serials/t_print_routing_list',
+ size: 'lg',
+ windowClass: 'eg-wide-modal',
+ backdrop: 'static',
+ controller:
+ ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
+ var all_users = [];
+ var all_streams = [];
+
+ angular.forEach(item_list, function(i){
+ all_streams.push(i.stream());
+ all_users = all_users.concat(i.stream().routing_list_users());
+ });
+
+ $scope.xulg = {
+ show_print_button: true,
+ routing_list_data: {
+ streams : all_streams,
+ mvr : mvr,
+ issuance: item_list[0].issuance(),
+ users : orderByFilter(all_users, 'pos')
+ }
+ };
+
+ $scope.url = '/eg/serial/print_routing_list_users?ses=' + egCore.auth.token();
+ $scope.last = index == issuance_matrix.length - 1 ? true : false;
+ $scope.ok = function() { $uibModalInstance.close() }
+ }]
+ }).result;
+ });
+
+ });
+
+ return deferred.resolve();
+ });
+
+ }
+
+ service.process_items = function (mode, bibId, list, do_barcode, bind, print_rl, callback) {
+ if (!callback) callback = function () { return $q.when() }
+ if (!list.length) return $q.reject();
+
+ // deal with locations and circ mods for *NEW* units
+ var copy_locations = {};
+ var circ_mods = {};
+
+ // deal with barcodes and call numbers for *NEW* units
+ var barcodes = {};
+ var call_numbers = {};
+ var call_numbers_by_siss_and_sdist = {};
+
+ var deferred = $q.defer();
+ var current_promise = deferred.promise;
+ var last_promise;
+ if (do_barcode || bind) {
+
+ last_promise = current_promise.then(function(){ return $uibModal.open({
+ templateUrl: './serials/t_batch_receive',
+ size: 'lg',
+ windowClass: 'eg-wide-modal',
+ backdrop: 'static',
+ controller:
+ ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
+
+ $scope.print_routing_lists = print_rl;
+ $scope.barcode_items = do_barcode;
+ $scope.force_bind = bind;
+ $scope.bind = bind;
+ $scope.items = list;
+ $scope.acn_list = [];
+ $scope.acpl_list = [];
+
+ $scope.cannot_print = function (index) {
+ return $scope.items[index].stream().routing_list_users().length == 0 || ($scope.bind && index > 0);
+ }
+
+ $scope.bind_or_none = function (index) {
+ return !$scope.barcode_items || ($scope.bind && index > 0);
+ }
+
+ $scope.focus_next_barcode = function (index) {
+ index++;
+ $('#item_barcode_'+index).focus().select();
+ }
+
+ $scope.apply_template_overrides = function (e) {
+ if ($scope.selected_call_number) {
+ angular.forEach($scope.items, function (i) {
+ i._call_number = $scope.selected_call_number;
+ });
+ }
+ if ($scope.selected_circ_mod) {
+ angular.forEach($scope.items, function (i) {
+ i._circ_mod = $scope.selected_circ_mod;
+ });
+ }
+ if ($scope.selected_copy_location) {
+ angular.forEach($scope.items, function (i) {
+ i._copy_location = $scope.selected_copy_location;
+ });
+ }
+ }
+
+ $scope.ok = function(items) { $uibModalInstance.close(items) }
+ $scope.cancel = function () { $uibModalInstance.dismiss() }
+
+ var pile_o_promises = [$q.when()];
+ // let's gather what we need...
+ angular.forEach(list, function (i, index) {
+ if (i.unit()) {
+ i._barcode = i.unit().barcode();
+ pile_o_promises.push(
+ egCore.pcrud.retrieve(
+ 'acn', i.unit().call_number()
+ ).then(function(cn){ if (cn.deleted() == 'f') i._call_number = cn.label() })
+ );
+ } else {
+ if (i.stream().distribution()[mode + '_call_number']() &&
+ i.stream().distribution()[mode + '_call_number']().deleted() == 'f'
+ ) {
+ i._call_number = i.stream().distribution()[mode + '_call_number']().label();
+ } else {
+ pile_o_promises.push(
+ service.fetchLastCallnumber(
+ i.stream().distribution().holding_lib().id()
+ ).then(function(cn){ i._call_number = cn.label() })
+ );
+ }
+ }
+
+ if (i.stream().distribution()[mode + '_unit_template']()) {
+ i._copy_location = i.stream().distribution()[mode + '_unit_template']().location();
+ i._circ_mod = i.stream().distribution()[mode + '_unit_template']().circ_modifier();
+ }
+
+ if ($scope.print_routing_lists && !$scope.cannot_print(index))
+ i._print_routing_list = true;
+ });
+
+ pile_o_promises.push(egCore.pcrud.search(
+ 'acpl',
+ {owning_lib : egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
+ {},{ atomic : true }
+ ).then(function (list) {
+ $scope.acpl_list = list.map(function(i){return egCore.idl.toHash(i)});
+ return $q.when();
+ }));
+
+ pile_o_promises.push(egCore.pcrud.search(
+ 'acn',
+ {deleted : 'f', record : bibId, owning_lib : egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
+ {},{ atomic : true }
+ ).then(function (list) {
+ $scope.acn_list = list.map(function(i){return egCore.idl.toHash(i)});
+ return $q.when();
+ }));
+
+ pile_o_promises.push(egCore.pcrud.retrieveAll(
+ 'ccm', {}, { atomic : true }
+ ).then(function (list) {
+ $scope.ccm_list = list.map(function(i){return egCore.idl.toHash(i)});
+ return $q.when();
+ }));
+
+ $q.all(pile_o_promises).then(function() {
+ console.log('receive data collected');
+ });
+
+ $scope.$watch('barcode_items', function (n,o) {
+ if (n === undefined || n == o) return;
+ do_barcode = n;
+ });
+
+ $scope.$watch('bind', function (n,o) {
+ if (n === undefined || n == o) return;
+ bind = n;
+ if (bind) {
+ angular.forEach($scope.items, function (i,index) {
+ if (index > 0) i._print_routing_list = false;
+ });
+ }
+ });
+
+ $scope.$watch('auto_barcodes', function (n,o) {
+ if (n === undefined || n == o) return;
+
+ var bc = '@@AUTO';
+ if (!n) bc = '';
+
+ angular.forEach($scope.items, function (i) {
+ var _barcode = i._barcode;
+ i._barcode = bc || i._old_barcode;
+ i._old_barcode = _barcode;
+ });
+ });
+
+ $scope.$watch('print_routing_lists', function (n,o) {
+ if (n === undefined || n == o) return;
+
+ angular.forEach($scope.items, function(i, index) {
+ if (!$scope.cannot_print(index)) {
+ i._print_routing_list = n;
+ } else {
+ i._print_routing_list = false;
+ }
+ });
+ });
+ }]
+ }).result});
+ } else {
+ last_promise = current_promise.then(function(){
+ return egConfirmDialog.open(
+ egCore.strings.CONFIRM_CHANGE_ITEMS[mode],
+ egCore.strings.CONFIRM_CHANGE_ITEMS_MESSAGE[mode],
+ {items : list.length}
+ ).result.then(function () {
+ return $q.when(list);
+ });
+ });
+ }
+
+ last_promise.then(function (items) {
+
+ var donor_unit_ids = {};
+ angular.forEach(items, function(i, index) {
+ if (i.unit()) donor_unit_ids[i.unit().id()] = 1;
+ if (do_barcode) i.unit(-1);
+ if (bind) i.unit(-2);
+ copy_locations[i.id()] = i._copy_location;
+ circ_mods[i.id()] = i._circ_mod;
+ call_numbers[i.id()] = i._call_number || 'DEFAULT';
+ barcodes[i.id()] = i._barcode || '@@AUTO';
+ if (bind && index > 0) barcodes[i.id()] = items[0]._barcode;
+ });
+
+ var method;
+ if (mode == 'receive') {
+ method = 'open-ils.serial.receive_items';
+ } else if ( mode == 'bind') {
+ method = 'open-ils.serial.bind_items';
+ } else if ( mode == 'reset') {
+ method = 'open-ils.serial.reset_items';
+ }
+
+ return egCore.net.request(
+ 'open-ils.serial', method,
+ egCore.auth.token(), items, barcodes, call_numbers, donor_unit_ids,
+ {circ_mods:circ_mods, copy_locations : copy_locations}
+ ).then(
+ function(resp) {
+ var evt = egCore.evt.parse(resp);
+ if (evt) {
+ ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+ } else {
+ ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
+ return service.print_routing_lists(bibId, items, do_barcode || bind, false, print_rl)
+ .finally(callback);
+ }
+ },
+ function(resp) {
+ ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+ }
+ );
+ });
+
+ return deferred.resolve();
+ }
+
return service;
}]);
+