diff --git a/config.json b/config.json index 74d5c56..ef024bc 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,5 @@ "REPORTING_SERVICES": "angola", "applicationLoadingMessage": "Iniciando SIGLOFA", "applicationTitle": "SIGLOFA", - "defaultLanguage": "pt", - "showRequisitionLessOrder": "true" + "defaultLanguage": "pt" } \ No newline at end of file diff --git a/project.properties b/project.properties index 8ba8836..e083f84 100644 --- a/project.properties +++ b/project.properties @@ -1,3 +1,3 @@ -version=1.5.8-SNAPSHOT +version=1.5.8 projectName=OpenLMIS Angola UI transifexProject=openlmis-angola-ui diff --git a/src/openlmis-form/not-negative-float.directive.js b/src/openlmis-form/not-negative-float.directive.js deleted file mode 100644 index 23db2f9..0000000 --- a/src/openlmis-form/not-negative-float.directive.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This program is part of the OpenLMIS logistics management information system platform software. - * Copyright © 2017 VillageReach - * - * This program is free software: you can redistribute it and/or modify it under the terms - * of the GNU Affero General Public License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - *   - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  - * See the GNU Affero General Public License for more details. You should have received a copy of - * the GNU Affero General Public License along with this program. If not, see - * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  - */ - -(function() { - - 'use strict'; - - /** - * @ngdoc directive - * @restrict A - * @name openlmis-form.directive:positiveInteger - * - * @description - * Restricts the ngModel to only allow positive integers. - * - * @example - * Extend the input element to force it to only accept positive integers as values. - * ``` - * - * ``` - */ - angular - .module('openlmis-form') - .directive('notNegativeFloat', positiveInteger); - - function positiveInteger() { - var directive = { - require: 'ngModel', - link: link, - priority: 100 - }; - return directive; - - function link(scope, element, attrs, modelCtrl) { - - element.attr('type', 'text'); - element.addClass('number'); - - modelCtrl.$parsers.push(function(inputValue) { - var pattern = /^[0-9]*(\.[0-9]([0-9])?)?/g; - - if (inputValue === undefined) { - return ''; - } - - var matchedValue = inputValue.match(pattern)[0]; - if (matchedValue !== inputValue) { - modelCtrl.$setViewValue(matchedValue); - modelCtrl.$render(); - } - return matchedValue ? parseFloat(inputValue).toFixed(2) : null; - }); - } - } -})(); \ No newline at end of file diff --git a/src/openlmis-rights/administration-rights.constant.js b/src/openlmis-rights/administration-rights.constant.js deleted file mode 100644 index ea60a70..0000000 --- a/src/openlmis-rights/administration-rights.constant.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This program is part of the OpenLMIS logistics management information system platform software. - * Copyright © 2017 VillageReach - * - * This program is free software: you can redistribute it and/or modify it under the terms - * of the GNU Affero General Public License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - *   - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  - * See the GNU Affero General Public License for more details. You should have received a copy of - * the GNU Affero General Public License along with this program. If not, see - * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  - */ - -(function() { - - 'use strict'; - - /** - * @ngdoc object - * @name openlmis-rights.ADMINISTRATION_RIGHTS - * - * @description - * This is constant for administration rights. - */ - angular - .module('openlmis-rights') - .constant('ADMINISTRATION_RIGHTS', rights()); - - function rights() { - return { - USERS_MANAGE: 'USERS_MANAGE', - FACILITIES_MANAGE: 'FACILITIES_MANAGE', - ORDERABLES_MANAGE: 'ORDERABLES_MANAGE', - SUPERVISORY_NODES_MANAGE: 'SUPERVISORY_NODES_MANAGE', - REQUISITION_GROUPS_MANAGE: 'REQUISITION_GROUPS_MANAGE', - GEOGRAPHIC_ZONES_MANAGE: 'GEOGRAPHIC_ZONES_MANAGE', - SUPPLY_LINES_MANAGE: 'SUPPLY_LINES_MANAGE', - SUPPLY_PARTNERS_MANAGE: 'SUPPLY_PARTNERS_MANAGE', - SYSTEM_IDEAL_STOCK_AMOUNTS_MANAGE: 'SYSTEM_IDEAL_STOCK_AMOUNTS_MANAGE', - SERVICE_ACCOUNTS_MANAGE: 'SERVICE_ACCOUNTS_MANAGE', - PROCESSING_SCHEDULES_MANAGE: 'PROCESSING_SCHEDULES_MANAGE', - SYSTEM_NOTIFICATIONS_MANAGE: 'SYSTEM_NOTIFICATIONS_MANAGE', - FACILITY_APPROVED_ORDERABLES_MANAGE: 'FACILITY_APPROVED_ORDERABLES_MANAGE', - LOTS_MANAGE: 'LOTS_MANAGE', - STOCK_SOURCES_MANAGE: 'STOCK_SOURCES_MANAGE', - STOCK_DESTINATIONS_MANAGE: 'STOCK_DESTINATIONS_MANAGE', - ORDER_CREATE: 'ORDER_CREATE', - DATA_EXPORT: 'DATA_EXPORT', - DATA_IMPORT: 'DATA_IMPORT', - // AO-805: Allow users with proper rights to edit product prices - EDIT_PRODUCT_PRICE_STOCK_MANAGEMENT: 'EDIT_PRODUCT_PRICE_STOCK_MANAGEMENT' - // AO-805: Ends here - }; - } - -})(); \ No newline at end of file diff --git a/src/stock-adjustment-creation/adjustment-creation.controller.js b/src/stock-adjustment-creation/adjustment-creation.controller.js deleted file mode 100644 index 8231df8..0000000 --- a/src/stock-adjustment-creation/adjustment-creation.controller.js +++ /dev/null @@ -1,971 +0,0 @@ -/* - * This program is part of the OpenLMIS logistics management information system platform software. - * Copyright © 2017 VillageReach - * - * This program is free software: you can redistribute it and/or modify it under the terms - * of the GNU Affero General Public License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - *   - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  - * See the GNU Affero General Public License for more details. You should have received a copy of - * the GNU Affero General Public License along with this program. If not, see - * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  - */ - -(function() { - - 'use strict'; - - /** - * @ngdoc controller - * @name stock-adjustment-creation.controller:StockAdjustmentCreationController - * - * @description - * Controller for managing stock adjustment creation. - */ - angular - .module('stock-adjustment-creation') - .controller('StockAdjustmentCreationController', controller); - - controller.$inject = [ - '$scope', '$state', '$stateParams', '$filter', 'confirmDiscardService', 'program', 'facility', - 'orderableGroups', 'reasons', 'confirmService', 'messageService', 'user', 'adjustmentType', - 'srcDstAssignments', 'stockAdjustmentCreationService', 'notificationService', 'offlineService', - 'orderableGroupService', 'MAX_INTEGER_VALUE', 'VVM_STATUS', 'loadingModalService', 'alertService', - 'dateUtils', 'displayItems', 'ADJUSTMENT_TYPE', 'UNPACK_REASONS', 'REASON_TYPES', 'STOCKCARD_STATUS', - 'hasPermissionToAddNewLot', 'LotResource', '$q', 'editLotModalService', 'moment', - // ANGOLASUP-717: Create New Issue Report - 'accessTokenFactory', '$window', 'stockmanagementUrlFactory', - // ANGOLASUP-717: ends here - // AO-805: Allow users with proper rights to edit product prices - 'OrderableResource', 'permissionService', 'ADMINISTRATION_RIGHTS', 'authorizationService' - // AO-805: Ends here - ]; - - function controller($scope, $state, $stateParams, $filter, confirmDiscardService, program, - facility, orderableGroups, reasons, confirmService, messageService, user, - adjustmentType, srcDstAssignments, stockAdjustmentCreationService, notificationService, - offlineService, orderableGroupService, MAX_INTEGER_VALUE, VVM_STATUS, loadingModalService, - alertService, dateUtils, displayItems, ADJUSTMENT_TYPE, UNPACK_REASONS, REASON_TYPES, - STOCKCARD_STATUS, hasPermissionToAddNewLot, LotResource, $q, editLotModalService, moment, - // ANGOLASUP-717: Create New Issue Report - // AO-805: Allow users with proper rights to edit product prices - accessTokenFactory, $window, stockmanagementUrlFactory, OrderableResource, permissionService, - ADMINISTRATION_RIGHTS, authorizationService) { - // ANGOLASUP-717: ends here - // AO-805: Ends here - var vm = this, - previousAdded = {}; - - vm.expirationDateChanged = expirationDateChanged; - vm.newLotCodeChanged = newLotCodeChanged; - vm.validateExpirationDate = validateExpirationDate; - vm.lotChanged = lotChanged; - vm.addProduct = addProduct; - vm.hasPermissionToAddNewLot = hasPermissionToAddNewLot; - // AO-805: Allow users with proper rights to edit product prices - vm.editProductPriceAdjustmentTypes = ['receive', 'adjustment']; - vm.hasPermissionToEditProductPrices = hasPermissionToEditProductPrices(); - // AO-805: Ends here - - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name totalCost - * @type {Number} - * - * @description - * Holds total cost of adjustments line items - */ - vm.totalCost = 0; - // AO-804: Ends here - - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name vvmStatuses - * @type {Object} - * - * @description - * Holds list of VVM statuses. - */ - vm.vvmStatuses = VVM_STATUS; - - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name showReasonDropdown - * @type {boolean} - */ - vm.showReasonDropdown = true; - - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name showVVMStatusColumn - * @type {boolean} - * - * @description - * Indicates if VVM Status column should be visible. - */ - vm.showVVMStatusColumn = false; - - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name offline - * @type {boolean} - * - * @description - * Holds information about internet connection - */ - vm.offline = offlineService.isOffline; - - vm.key = function(secondaryKey) { - return adjustmentType.prefix + 'Creation.' + secondaryKey; - }; - - /** - * @ngdoc property - * @propertyOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name newLot - * @type {Object} - * - * @description - * Holds new lot object. - */ - vm.newLot = undefined; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name search - * - * @description - * It searches from the total line items with given keyword. If keyword is empty then all line - * items will be shown. - */ - vm.search = function() { - vm.displayItems = stockAdjustmentCreationService.search(vm.keyword, vm.addedLineItems, vm.hasLot); - - $stateParams.addedLineItems = vm.addedLineItems; - $stateParams.displayItems = vm.displayItems; - $stateParams.keyword = vm.keyword; - $stateParams.page = getPageNumber(); - $state.go($state.current.name, $stateParams, { - reload: true, - notify: false - }); - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name addProduct - * - * @description - * Add a product for stock adjustment. - */ - function addProduct() { - var selectedItem; - - if (vm.selectedOrderableGroup && vm.selectedOrderableGroup.length) { - vm.newLot.tradeItemId = vm.selectedOrderableGroup[0].orderable.identifiers.tradeItem; - } - - if (vm.newLot.lotCode) { - var createdLot = angular.copy(vm.newLot); - selectedItem = orderableGroupService - .findByLotInOrderableGroup(vm.selectedOrderableGroup, createdLot, true); - selectedItem.$isNewItem = true; - } else { - selectedItem = orderableGroupService - .findByLotInOrderableGroup(vm.selectedOrderableGroup, vm.selectedLot); - } - - vm.newLot.expirationDateInvalid = undefined; - vm.newLot.lotCodeInvalid = undefined; - validateExpirationDate(); - validateLotCode(vm.addedLineItems, selectedItem); - validateLotCode(vm.allItems, selectedItem); - var noErrors = !vm.newLot.expirationDateInvalid && !vm.newLot.lotCodeInvalid; - - if (noErrors) { - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - vm.addedLineItems.unshift(_.extend({ - $errors: {}, - $previewSOH: selectedItem.stockOnHand, - price: getProductPrice(selectedItem), - totalPrice: 0 - }, - selectedItem, copyDefaultValue())); - // AO-804: Ends here - - previousAdded = vm.addedLineItems[0]; - - vm.search(); - } - } - - function copyDefaultValue() { - var defaultDate; - if (previousAdded.occurredDate) { - defaultDate = previousAdded.occurredDate; - } else { - defaultDate = dateUtils.toStringDate(new Date()); - } - - return { - assignment: previousAdded.assignment, - srcDstFreeText: previousAdded.srcDstFreeText, - reason: (adjustmentType.state === ADJUSTMENT_TYPE.KIT_UNPACK.state) - ? { - id: UNPACK_REASONS.KIT_UNPACK_REASON_ID - } : previousAdded.reason, - reasonFreeText: previousAdded.reasonFreeText, - occurredDate: defaultDate - }; - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name remove - * - * @description - * Remove a line item from added products. - * - * @param {Object} lineItem line item to be removed. - */ - vm.remove = function(lineItem) { - var index = vm.addedLineItems.indexOf(lineItem); - vm.addedLineItems.splice(index, 1); - - vm.search(); - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name removeDisplayItems - * - * @description - * Remove all displayed line items. - */ - vm.removeDisplayItems = function() { - confirmService.confirmDestroy(vm.key('clearAll'), vm.key('clear')) - .then(function() { - vm.addedLineItems = _.difference(vm.addedLineItems, vm.displayItems); - vm.displayItems = []; - }); - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateQuantity - * - * @description - * Validate line item quantity and returns self. - * - * @param {Object} lineItem line item to be validated. - */ - vm.validateQuantity = function(lineItem) { - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - lineItem.totalPrice = 0; - // AO-804: Ends here - if (lineItem.quantity > lineItem.$previewSOH && lineItem.reason - && lineItem.reason.reasonType === REASON_TYPES.DEBIT) { - lineItem.$errors.quantityInvalid = messageService - .get('stockAdjustmentCreation.quantityGreaterThanStockOnHand'); - } else if (lineItem.quantity > MAX_INTEGER_VALUE) { - lineItem.$errors.quantityInvalid = messageService.get('stockmanagement.numberTooLarge'); - } else if (lineItem.quantity >= 1) { - lineItem.$errors.quantityInvalid = false; - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - lineItem.totalPrice = calculateTotalPrice(lineItem); - // AO-804: Ends here - } else { - lineItem.$errors.quantityInvalid = messageService.get(vm.key('positiveInteger')); - } - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - calculateTotalCost(vm.addedLineItems); - // AO-804: Ends here - return lineItem; - }; - - // AO-805: Allow users with proper rights to edit product prices - vm.validatePrice = function(lineItem) { - lineItem.totalPrice = 0; - if (lineItem.price === '' || lineItem.price === null) { - lineItem.$errors.priceInvalid = messageService.get('adjustmentCreation.numberEqualOrGreaterThan0'); - } else if (lineItem.price > MAX_INTEGER_VALUE) { - lineItem.$errors.priceInvalid = messageService.get('stockmanagement.numberTooLarge'); - } else if (lineItem.price >= 0) { - lineItem.$errors.priceInvalid = false; - lineItem.totalPrice = calculateTotalPrice(lineItem); - } - calculateTotalCost(vm.addedLineItems); - return lineItem; - }; - // AO-805: Ends here - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateAssignment - * - * @description - * Validate line item assignment and returns self. - * - * @param {Object} lineItem line item to be validated. - */ - vm.validateAssignment = function(lineItem) { - if (adjustmentType.state !== ADJUSTMENT_TYPE.ADJUSTMENT.state && - adjustmentType.state !== ADJUSTMENT_TYPE.KIT_UNPACK.state) { - lineItem.$errors.assignmentInvalid = isEmpty(lineItem.assignment); - } - return lineItem; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateReason - * - * @description - * Validate line item reason and returns self. - * - * @param {Object} lineItem line item to be validated. - */ - vm.validateReason = function(lineItem) { - if (adjustmentType.state === 'adjustment') { - lineItem.$errors.reasonInvalid = isEmpty(lineItem.reason); - } - // AO-805: Allow users with proper rights to edit product prices - if (lineItem.reason && lineItem.reason.debitReasonType) { - lineItem.price = getProductPrice(lineItem); - lineItem.totalPrice = calculateTotalPrice(lineItem); - calculateTotalCost(vm.addedLineItems); - } - // AO-805: Ends here - return lineItem; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name lotChanged - * - * @description - * Allows inputs to add missing lot to be displayed. - */ - function lotChanged() { - vm.canAddNewLot = vm.selectedLot - && vm.selectedLot.lotCode === messageService.get('orderableGroupService.addMissingLot'); - initiateNewLotObject(); - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateDate - * - * @description - * Validate line item occurred date and returns self. - * - * @param {Object} lineItem line item to be validated. - */ - vm.validateDate = function(lineItem) { - lineItem.$errors.occurredDateInvalid = isEmpty(lineItem.occurredDate); - return lineItem; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name clearFreeText - * - * @description - * remove free text from given object. - * - * @param {Object} obj given target to be changed. - * @param {String} property given property to be cleared. - */ - vm.clearFreeText = function(obj, property) { - obj[property] = null; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name submit - * - * @description - * Submit all added items. - */ - vm.submit = function() { - $scope.$broadcast('openlmis-form-submit'); - if (validateAllAddedItems()) { - var confirmMessage = messageService.get(vm.key('confirmInfo'), { - username: user.username, - number: vm.addedLineItems.length - }); - confirmService.confirm(confirmMessage, vm.key('confirm')).then(confirmSubmit); - } else { - vm.keyword = null; - reorderItems(); - alertService.error('stockAdjustmentCreation.submitInvalid'); - } - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name orderableSelectionChanged - * - * @description - * Reset form status and change content inside lots drop down list. - */ - vm.orderableSelectionChanged = function() { - //reset selected lot, so that lot field has no default value - vm.selectedLot = null; - - initiateNewLotObject(); - vm.canAddNewLot = false; - - //same as above - $scope.productForm.$setUntouched(); - - //make form good as new, so errors won't persist - $scope.productForm.$setPristine(); - - vm.lots = orderableGroupService.lotsOf(vm.selectedOrderableGroup, vm.hasPermissionToAddNewLot); - vm.selectedOrderableHasLots = vm.lots.length > 0; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name getStatusDisplay - * - * @description - * Returns VVM status display. - * - * @param {String} status VVM status - * @return {String} VVM status display name - */ - vm.getStatusDisplay = function(status) { - return messageService.get(VVM_STATUS.$getDisplayName(status)); - }; - - // AO-805: Allow users with proper rights to edit product prices - vm.canEditProductPrice = function(lineItem) { - var hasProperPermission = vm.hasPermissionToEditProductPrices.$$state.value; - var canEditProductPrice = vm.editProductPriceAdjustmentTypes.includes(adjustmentType.state) && - hasProperPermission; - if (adjustmentType.state === 'adjustment') { - var adjustmentReason = lineItem.reason; - canEditProductPrice = adjustmentReason ? (adjustmentReason.reasonType === 'CREDIT') - && hasProperPermission : false; - } - return canEditProductPrice; - }; - // AO-805: Ends here - - function isEmpty(value) { - return _.isUndefined(value) || _.isNull(value); - } - - function validateAllAddedItems() { - _.each(vm.addedLineItems, function(item) { - vm.validateQuantity(item); - vm.validateDate(item); - vm.validateAssignment(item); - vm.validateReason(item); - // AO-805: Allow users with proper rights to edit product prices - vm.validatePrice(item); - // AO-805: Ends here - }); - return _.chain(vm.addedLineItems) - .groupBy(function(item) { - return item.lot ? item.lot.id : item.orderable.id; - }) - .values() - .flatten() - .all(isItemValid) - .value(); - } - - function isItemValid(item) { - return _.chain(item.$errors).keys() - .all(function(key) { - return item.$errors[key] === false; - }) - .value(); - } - - function reorderItems() { - var sorted = $filter('orderBy')(vm.addedLineItems, ['orderable.productCode', '-occurredDate']); - - vm.displayItems = _.chain(sorted).groupBy(function(item) { - return item.lot ? item.lot.id : item.orderable.id; - }) - .sortBy(function(group) { - return _.every(group, function(item) { - return !item.$errors.quantityInvalid; - }); - }) - .flatten(true) - .value(); - } - - function confirmSubmit() { - loadingModalService.open(); - - var addedLineItems = angular.copy(vm.addedLineItems); - - generateKitConstituentLineItem(addedLineItems); - - var lotPromises = [], - errorLots = []; - var distinctLots = []; - var lotResource = new LotResource(); - addedLineItems.forEach(function(lineItem) { - if (lineItem.lot && lineItem.$isNewItem && _.isUndefined(lineItem.lot.id) && - !listContainsTheSameLot(distinctLots, lineItem.lot)) { - distinctLots.push(lineItem.lot); - } - }); - distinctLots.forEach(function(lot) { - lotPromises.push(lotResource.create(lot) - .then(function(createResponse) { - vm.addedLineItems.forEach(function(item) { - if (item.lot.lotCode === lot.lotCode) { - item.$isNewItem = false; - addItemToOrderableGroups(item); - } - }); - return createResponse; - }) - .catch(function(response) { - if (response.data.messageKey === - 'referenceData.error.lot.lotCode.mustBeUnique' || - response.data.messageKey === - 'referenceData.error.lot.tradeItem.required') { - errorLots.push({ - lotCode: lot.lotCode, - error: response.data.messageKey === - 'referenceData.error.lot.lotCode.mustBeUnique' ? - 'stockPhysicalInventoryDraft.lotCodeMustBeUnique' : - 'stockPhysicalInventoryDraft.tradeItemRequuiredToAddLotCode' - }); - } - })); - }); - - var productsWithPriceChanged = getProductsWithPriceChanged(addedLineItems); - var lastProductWithPriceChanged = productsWithPriceChanged[productsWithPriceChanged.length - 1]; - var priceChangesPromises = []; - - setProductPriceForProgram(lastProductWithPriceChanged, program); - priceChangesPromises.push(updateProductPrice(lastProductWithPriceChanged.orderable, - lastProductWithPriceChanged.price)); - - return $q.all(priceChangesPromises).then(function() { - return $q.all(lotPromises) - .then(function(responses) { - if (errorLots !== undefined && errorLots.length > 0) { - return $q.reject(); - } - responses.forEach(function(lot) { - addedLineItems.forEach(function(lineItem) { - if (lineItem.lot && lineItem.lot.lotCode === lot.lotCode - && lineItem.lot.tradeItemId === lot.tradeItemId) { - lineItem.lot = lot; - } - }); - return addedLineItems; - }); - - stockAdjustmentCreationService.submitAdjustments(program.id, facility.id, - // AO-668: Use username as signature for Issue, Receive and Adjustment - addedLineItems, adjustmentType, user) - // AO-668: ends here - // ANGOLASUP-717: Create New Issue Report - .then(function(stockEventId) { - if (adjustmentType.state === ADJUSTMENT_TYPE.ISSUE.state) { - confirmService.confirm('adjustmentCreation.printModal.label', - 'stockPhysicalInventoryDraft.printModal.yes', - 'stockPhysicalInventoryDraft.printModal.no') - .then(function() { - $window.open(accessTokenFactory.addAccessToken(getPrintUrl(stockEventId)), - '_blank'); - }) - .finally(function() { - goToStockCardSummaries(); - }); - } else { - goToStockCardSummaries(); - } - // ANGOLASUP-717: ends here - }, function(errorResponse) { - loadingModalService.close(); - alertService.error(errorResponse.data.message); - }); - }) - .catch(function(errorResponse) { - loadingModalService.close(); - if (errorLots) { - var errorLotsReduced = errorLots.reduce(function(result, currentValue) { - if (currentValue.error in result) { - result[currentValue.error].push(currentValue.lotCode); - } else { - result[currentValue.error] = [currentValue.lotCode]; - } - return result; - }, {}); - for (var error in errorLotsReduced) { - alertService.error(error, errorLotsReduced[error].join(', ')); - } - vm.selectedOrderableGroup = undefined; - vm.selectedLot = undefined; - vm.lotChanged(); - return $q.reject(errorResponse.data.message); - } - alertService.error(errorResponse.data.message); - }); - }) - .catch(function(errorResponse) { - loadingModalService.close(); - $q.reject(); - alertService.error(errorResponse.data.message); - }); - } - - // ANGOLASUP-717: Create New Issue Report - function getPrintUrl(stockEventId) { - var reportTemplateId = '79301ebf-1198-4a35-9d00-18c9fe450807'; - return stockmanagementUrlFactory('/api/reports/templates/angola/' + reportTemplateId - + '/pdf?stockEventId=' + stockEventId); - } - - function goToStockCardSummaries() { - if (offlineService.isOffline()) { - notificationService.offline(vm.key('submittedOffline')); - } else { - notificationService.success(vm.key('submitted')); - } - $state.go('openlmis.stockmanagement.stockCardSummaries', { - facility: facility.id, - program: program.id, - active: STOCKCARD_STATUS.ACTIVE - }); - } - // ANGOLASUP-717: ends here - - function addItemToOrderableGroups(item) { - vm.orderableGroups.forEach(function(array) { - if (array[0].orderable.id === item.orderable.id) { - array.push(angular.copy(item)); - } - }); - } - - function listContainsTheSameLot(list, lot) { - var itemExistsOnList = false; - list.forEach(function(item) { - if (item.lotCode === lot.lotCode && - item.tradeItemId === lot.tradeItemId) { - itemExistsOnList = true; - } - }); - return itemExistsOnList; - } - - function generateKitConstituentLineItem(addedLineItems) { - if (adjustmentType.state !== ADJUSTMENT_TYPE.KIT_UNPACK.state) { - return; - } - - //CREDIT reason ID - var creditReason = { - id: UNPACK_REASONS.UNPACKED_FROM_KIT_REASON_ID - }; - - var constituentLineItems = []; - - addedLineItems.forEach(function(lineItem) { - lineItem.orderable.children.forEach(function(constituent) { - constituent.reason = creditReason; - constituent.occurredDate = lineItem.occurredDate; - constituent.quantity = lineItem.quantity * constituent.quantity; - constituentLineItems.push(constituent); - }); - }); - - addedLineItems.push.apply(addedLineItems, constituentLineItems); - } - - function onInit() { - var copiedOrderableGroups = angular.copy(orderableGroups); - vm.allItems = _.flatten(copiedOrderableGroups); - - $state.current.label = messageService.get(vm.key('title'), { - facilityCode: facility.code, - facilityName: facility.name, - program: program.name - }); - - initViewModel(); - initStateParams(); - - $scope.$watch(function() { - return vm.addedLineItems; - }, function(newValue) { - $scope.needToConfirm = newValue.length > 0; - if (!vm.keyword) { - vm.addedLineItems = vm.displayItems; - } - $stateParams.addedLineItems = vm.addedLineItems; - $stateParams.displayItems = vm.displayItems; - $stateParams.keyword = vm.keyword; - $state.go($state.current.name, $stateParams, { - reload: false, - notify: false - }); - }, true); - confirmDiscardService.register($scope, 'openlmis.stockmanagement.stockCardSummaries'); - - $scope.$on('$stateChangeStart', function() { - angular.element('.popover').popover('destroy'); - }); - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - calculateTotalCost(vm.addedLineItems); - // AO-804: Ends here - } - - function initViewModel() { - //Set the max-date of date picker to the end of the current day. - vm.maxDate = new Date(); - vm.maxDate.setHours(23, 59, 59, 999); - - vm.program = program; - vm.facility = facility; - vm.reasons = reasons; - vm.showReasonDropdown = (adjustmentType.state !== ADJUSTMENT_TYPE.KIT_UNPACK.state); - vm.srcDstAssignments = srcDstAssignments; - vm.addedLineItems = $stateParams.addedLineItems || []; - $stateParams.displayItems = displayItems; - vm.displayItems = $stateParams.displayItems || []; - vm.keyword = $stateParams.keyword; - - vm.orderableGroups = orderableGroups; - vm.hasLot = false; - vm.orderableGroups.forEach(function(group) { - vm.hasLot = vm.hasLot || orderableGroupService.lotsOf(group, hasPermissionToAddNewLot).length > 0; - }); - vm.showVVMStatusColumn = orderableGroupService.areOrderablesUseVvm(vm.orderableGroups); - vm.hasPermissionToAddNewLot = hasPermissionToAddNewLot; - vm.canAddNewLot = false; - initiateNewLotObject(); - } - - function initiateNewLotObject() { - vm.newLot = { - active: true - }; - } - - function initStateParams() { - $stateParams.page = getPageNumber(); - $stateParams.program = program; - $stateParams.facility = facility; - $stateParams.reasons = reasons; - $stateParams.srcDstAssignments = srcDstAssignments; - $stateParams.orderableGroups = orderableGroups; - } - - function getPageNumber() { - var totalPages = Math.ceil(vm.displayItems.length / parseInt($stateParams.size)); - var pageNumber = parseInt($state.params.page || 0); - if (pageNumber > totalPages - 1) { - return totalPages > 0 ? totalPages - 1 : 0; - } - return pageNumber; - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name editLot - * - * @description - * Pops up a modal for users to edit lot for selected line item. - * - * @param {Object} lineItem line items to be edited. - */ - vm.editLot = function(lineItem) { - var oldLotCode = lineItem.lot.lotCode; - var oldLotExpirationDate = lineItem.lot.expirationDate; - editLotModalService.show(lineItem, vm.allItems, vm.addedLineItems).then(function() { - $stateParams.displayItems = vm.displayItems; - if (oldLotCode === lineItem.lot.lotCode - && oldLotExpirationDate !== lineItem.lot.expirationDate) { - vm.addedLineItems.forEach(function(item) { - if (item.lot && item.lot.lotCode === oldLotCode && - oldLotExpirationDate === item.lot.expirationDate) { - item.lot.expirationDate = lineItem.lot.expirationDate; - } - }); - } - }); - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name canEditLot - * - * @description - * Checks if user can edit lot. - * - * @param {Object} lineItem line item to edit - */ - vm.canEditLot = function(lineItem) { - return vm.hasPermissionToAddNewLot && lineItem.lot && lineItem.$isNewItem; - }; - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateExpirationDate - * - * @description - * Validate if expirationDate is a future date. - */ - function validateExpirationDate() { - var currentDate = moment(new Date()).format('YYYY-MM-DD'); - - if (vm.newLot.expirationDate && vm.newLot.expirationDate < currentDate) { - vm.newLot.expirationDateInvalid = messageService.get('stockEditLotModal.expirationDateInvalid'); - } - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name expirationDateChanged - * - * @description - * Hides the error message if exists after changed expiration date. - */ - function expirationDateChanged() { - vm.newLot.expirationDateInvalid = undefined; - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name newLotCodeChanged - * - * @description - * Hides the error message if exists after changed new lot code. - */ - function newLotCodeChanged() { - vm.newLot.lotCodeInvalid = undefined; - } - - /** - * @ngdoc method - * @methodOf stock-adjustment-creation.controller:StockAdjustmentCreationController - * @name validateLotCode - * - * @description - * Validate if on line item list exists the same orderable with the same lot code - */ - function validateLotCode(listItems, selectedItem) { - if (selectedItem && selectedItem.$isNewItem) { - listItems.forEach(function(lineItem) { - if (lineItem.orderable && lineItem.lot && selectedItem.lot && - lineItem.orderable.productCode === selectedItem.orderable.productCode && - selectedItem.lot.lotCode === lineItem.lot.lotCode && - ((!lineItem.$isNewItem) || (lineItem.$isNewItem && - selectedItem.lot.expirationDate !== lineItem.lot.expirationDate))) { - vm.newLot.lotCodeInvalid = messageService.get('stockEditLotModal.lotCodeInvalid'); - } - }); - } - } - - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - function getProductPrice(lineItem) { - var programOrderable = lineItem.orderable.programs.find(function(programOrderable) { - return programOrderable.programId === program.id; - }); - - return programOrderable.pricePerPack; - } - - function calculateTotalCost(items) { - var sum = 0; - if (items !== undefined) { - items.forEach(function(lineItem) { - sum += lineItem.totalPrice; - }); - } - - if (vm.totalCost !== sum) { - vm.totalCost = sum; - } - } - // AO-804: Ends here - - // AO-805: Allow users with proper rights to edit product prices - function calculateTotalPrice(lineItem) { - return lineItem.price && lineItem.quantity ? lineItem.price * lineItem.quantity : 0; - } - - function hasPermissionToEditProductPrices() { - return permissionService.hasPermissionWithAnyProgramAndAnyFacility( - authorizationService.getUser().user_id, - { - right: ADMINISTRATION_RIGHTS.EDIT_PRODUCT_PRICE_STOCK_MANAGEMENT - } - ) - .then(function() { - return true; - }) - .catch(function() { - return false; - }); - } - - function getProductsWithPriceChanged(products) { - return products.filter(function(product) { - return product.price !== getProductPrice(product); - }); - } - - function setProductPriceForProgram(lineItem, program) { - var updatedLineItem = lineItem.orderable.programs.map(function(programOrderable) { - if (programOrderable.programId === program.id) { - programOrderable.pricePerPack = parseFloat(lineItem.price); - } - return lineItem; - }); - - lineItem = updatedLineItem; - } - - function updateProductPrice(product) { - return new OrderableResource() - .update(product); - } - // AO-805: Ends here - - onInit(); - } -})(); \ No newline at end of file diff --git a/src/stock-adjustment-creation/adjustment-creation.controller.spec.js b/src/stock-adjustment-creation/adjustment-creation.controller.spec.js deleted file mode 100644 index a47161a..0000000 --- a/src/stock-adjustment-creation/adjustment-creation.controller.spec.js +++ /dev/null @@ -1,565 +0,0 @@ -/* - * This program is part of the OpenLMIS logistics management information system platform software. - * Copyright © 2017 VillageReach - * - * This program is free software: you can redistribute it and/or modify it under the terms - * of the GNU Affero General Public License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - *   - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  - * See the GNU Affero General Public License for more details. You should have received a copy of - * the GNU Affero General Public License along with this program. If not, see - * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  - */ - -describe('StockAdjustmentCreationController', function() { - - var vm, q, rootScope, state, stateParams, facility, program, confirmService, VVM_STATUS, messageService, scope, - stockAdjustmentCreationService, reasons, $controller, ADJUSTMENT_TYPE, ProgramDataBuilder, FacilityDataBuilder, - ReasonDataBuilder, OrderableGroupDataBuilder, OrderableDataBuilder, alertService, notificationService, - orderableGroups, LotDataBuilder, UNPACK_REASONS, LotResource, timeout; - - beforeEach(function() { - - module('referencedata-lot'); - module('stock-adjustment-creation', function($provide) { - var stockEventRepositoryMock = jasmine.createSpyObj('stockEventRepository', ['create']); - $provide.factory('StockEventRepository', function() { - return function() { - return stockEventRepositoryMock; - }; - }); - }); - - inject(function($injector) { - q = $injector.get('$q'); - timeout = $injector.get('$timeout'); - rootScope = $injector.get('$rootScope'); - stateParams = $injector.get('$stateParams'); - $controller = $injector.get('$controller'); - VVM_STATUS = $injector.get('VVM_STATUS'); - ADJUSTMENT_TYPE = $injector.get('ADJUSTMENT_TYPE'); - messageService = $injector.get('messageService'); - confirmService = $injector.get('confirmService'); - stockAdjustmentCreationService = $injector.get('stockAdjustmentCreationService'); - ProgramDataBuilder = $injector.get('ProgramDataBuilder'); - FacilityDataBuilder = $injector.get('FacilityDataBuilder'); - ReasonDataBuilder = $injector.get('ReasonDataBuilder'); - OrderableGroupDataBuilder = $injector.get('OrderableGroupDataBuilder'); - OrderableDataBuilder = $injector.get('OrderableDataBuilder'); - alertService = $injector.get('alertService'); - notificationService = $injector.get('notificationService'); - LotDataBuilder = $injector.get('LotDataBuilder'); - UNPACK_REASONS = $injector.get('UNPACK_REASONS'); - LotResource = $injector.get('LotResource'); - this.OrderableDataBuilder = $injector.get('OrderableDataBuilder'); - this.OrderableChildrenDataBuilder = $injector.get('OrderableChildrenDataBuilder'); - this.offlineService = $injector.get('offlineService'); - this.editLotModalService = $injector.get('editLotModalService'); - spyOn(this.editLotModalService, 'show'); - - state = jasmine.createSpyObj('$state', ['go']); - state.current = { - name: '/a/b' - }; - state.params = { - page: 0 - }; - - program = new ProgramDataBuilder().build(); - facility = new FacilityDataBuilder().build(); - - orderableGroups = [ - new OrderableGroupDataBuilder().build() - ]; - reasons = [new ReasonDataBuilder().build()]; - - this.kitConstituents = [ - new this.OrderableChildrenDataBuilder().withId('child_product_1_id') - .withQuantity(30) - .buildJson() - ]; - - this.kitOrderable = new this.OrderableDataBuilder().withId('kit_product_id') - .withChildren(this.kitConstituents) - .buildJson(); - - this.orderableGroup = new OrderableGroupDataBuilder() - .withOrderable(new OrderableDataBuilder().withExtraData({ - useVVM: 'true' - }) - .build()) - .build(); - - scope = rootScope.$new(); - scope.productForm = jasmine.createSpyObj('productForm', ['$setUntouched', '$setPristine']); - - vm = initController(orderableGroups); - }); - }); - - describe('onInit', function() { - it('should init page properly', function() { - expect(stateParams.page).toEqual(0); - }); - - it('should set showVVMStatusColumn to true if any orderable use vvm', function() { - - vm = initController([this.orderableGroup]); - - expect(vm.showVVMStatusColumn).toBe(true); - }); - - it('should set showVVMStatusColumn to false if no orderable use vvm', function() { - var orderableGroup = new OrderableGroupDataBuilder() - .withOrderable(new OrderableDataBuilder().withExtraData({ - useVVM: 'false' - }) - .build()) - .build(); - - vm = initController([orderableGroup]); - - expect(vm.showVVMStatusColumn).toBe(false); - }); - }); - - describe('validate', function() { - - it('line item quantity is valid given positive integer', function() { - var lineItem = { - id: '1', - quantity: 1, - $errors: {} - }; - vm.validateQuantity(lineItem); - - expect(lineItem.$errors.quantityInvalid).toBeFalsy(); - }); - - it('line item quantity is invalid given 0', function() { - var lineItem = { - id: '1', - quantity: 0, - $errors: {} - }; - vm.validateQuantity(lineItem); - - expect(lineItem.$errors.quantityInvalid).toEqual('stockAdjustmentCreation.positiveInteger'); - }); - - it('line item quantity is invalid when is greater than stock on hand and reason type is DEBIT', function() { - var lineItem = { - id: '1', - quantity: 6, - $previewSOH: 5, - reason: { - reasonType: 'DEBIT' - }, - $errors: {} - }; - vm.validateQuantity(lineItem); - - expect(lineItem.$errors.quantityInvalid).toEqual('stockAdjustmentCreation.quantityGreaterThanStockOnHand'); - }); - - it('line item quantity is invalid given -1', function() { - var lineItem = { - id: '1', - quantity: -1, - $errors: {} - }; - vm.validateQuantity(lineItem); - - expect(lineItem.$errors.quantityInvalid).toEqual('stockAdjustmentCreation.positiveInteger'); - }); - }); - - it('should reorder all added items when quantity validation failed', function() { - var date1 = new Date(2017, 3, 20); - var lineItem1 = { - reason: { - id: '123', - reasonType: 'DEBIT' - }, - orderable: { - productCode: 'C100' - }, - occurredDate: date1, - $errors: {} - }; - - var lineItem2 = { - reason: { - id: '123', - reasonType: 'DEBIT' - }, - orderable: { - productCode: 'C150' - }, - occurredDate: date1, - $errors: {} - }; - - var date2 = new Date(2017, 3, 25); - var lineItem3 = { - reason: { - id: '123', - reasonType: 'DEBIT' - }, - orderable: { - productCode: 'C100' - }, - occurredDate: date2, - $errors: { - quantityInvalid: 'stockAdjustmentCreation.sohCanNotBeNegative' - } - }; - - var lineItem4 = { - reason: { - id: '123', - reasonType: 'DEBIT' - }, - orderable: { - productCode: 'C120' - }, - occurredDate: date2, - $errors: { - quantityInvalid: 'stockAdjustmentCreation.sohCanNotBeNegative' - } - }; - - vm.addedLineItems = [lineItem1, lineItem2, lineItem3, lineItem4]; - - vm.submit(); - - var expectItems = [lineItem3, lineItem1, lineItem4, lineItem2]; - - expect(vm.displayItems).toEqual(expectItems); - }); - - it('should remove all line items', function() { - var lineItem1 = { - id: '1', - quantity: 0 - }; - var lineItem2 = { - id: '2', - quantity: 1 - }; - vm.addedLineItems = [lineItem1, lineItem2]; - vm.displayItems = [lineItem1]; - vm.keyword = '1'; - spyOn(confirmService, 'confirmDestroy'); - var deferred = q.defer(); - deferred.resolve(); - confirmService.confirmDestroy.andReturn(deferred.promise); - - vm.removeDisplayItems(); - rootScope.$apply(); - - expect(confirmService.confirmDestroy).toHaveBeenCalledWith('stockAdjustmentCreation.clearAll', - 'stockAdjustmentCreation.clear'); - - expect(vm.addedLineItems).toEqual([lineItem2]); - expect(vm.displayItems).toEqual([]); - }); - - it('should remove one line item from added line items', function() { - var lineItem1 = { - id: '1', - quantity: 0 - }; - var lineItem2 = { - id: '2', - quantity: 1 - }; - vm.addedLineItems = [lineItem1, lineItem2]; - - vm.remove(lineItem1); - - expect(vm.addedLineItems).toEqual([lineItem2]); - }); - - describe('addProduct', function() { - - beforeEach(function() { - vm.selectedOrderableGroup = new OrderableGroupDataBuilder() - .withOrderable(new OrderableDataBuilder().withFullProductName('Implanon') - .build()) - .withStockOnHand(2) - .build(); - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - vm.selectedOrderableGroup[0].orderable.programs = [{ - programId: program.id, - pricePerPack: 0 - }]; - // AO-804: Ends here - vm.addProduct(); - }); - - it('should add one line item to addedLineItem array', function() { - var addedLineItem = vm.addedLineItems[0]; - - expect(addedLineItem.stockOnHand).toEqual(2); - expect(addedLineItem.orderable.fullProductName).toEqual('Implanon'); - expect(typeof(addedLineItem.occurredDate)).toBe('string'); - }); - - it('should properly add another line item to addedLineItem array', function() { - vm.selectedOrderableGroup = new OrderableGroupDataBuilder() - .withOrderable(new OrderableDataBuilder().withFullProductName('Adsorbentia') - .build()) - .withStockOnHand(10) - .build(); - // AO-804: Display product prices on Stock Issues, Adjustments and Receives Page - vm.selectedOrderableGroup[0].orderable.programs = [{ - programId: program.id, - pricePerPack: 0 - }]; - // AO-804: Ends here - vm.addProduct(); - - var addedLineItem = vm.addedLineItems[0]; - - expect(addedLineItem.stockOnHand).toEqual(10); - expect(addedLineItem.orderable.fullProductName).toEqual('Adsorbentia'); - expect(addedLineItem.occurredDate).toEqual(vm.addedLineItems[1].occurredDate); - }); - }); - - it('should search from added line items', function() { - var lineItem1 = { - id: '1', - quantity: 0 - }; - var lineItem2 = { - id: '2', - quantity: 1 - }; - vm.addedLineItems = [lineItem1, lineItem2]; - - spyOn(stockAdjustmentCreationService, 'search'); - stockAdjustmentCreationService.search.andReturn([lineItem1]); - var params = { - page: 0, - program: program, - facility: facility, - reasons: reasons, - orderableGroups: orderableGroups, - addedLineItems: [lineItem1, lineItem2], - displayItems: [lineItem1], - keyword: undefined - }; - - vm.search(); - - expect(vm.displayItems).toEqual([lineItem1]); - expect(state.go).toHaveBeenCalledWith('/a/b', params, { - reload: true, - notify: false - }); - }); - - describe('getStatusDisplay', function() { - it('should expose getStatusDisplay method', function() { - expect(angular.isFunction(vm.getStatusDisplay)).toBe(true); - }); - - it('should call messageService', function() { - spyOn(messageService, 'get').andReturn(true); - vm.getStatusDisplay(VVM_STATUS.STAGE_1); - - expect(messageService.get).toHaveBeenCalled(); - }); - }); - - describe('submit', function() { - - beforeEach(function() { - spyOn(alertService, 'error'); - spyOn(confirmService, 'confirm'); - spyOn(notificationService, 'success'); - spyOn(notificationService, 'offline'); - spyOn(this.offlineService, 'isOffline').andReturn(false); - confirmService.confirm.andReturn(q.resolve()); - }); - - it('should not show success message after success if offline', function() { - this.offlineService.isOffline.andReturn(true); - spyOn(stockAdjustmentCreationService, 'submitAdjustments'); - stockAdjustmentCreationService.submitAdjustments.andReturn(q.resolve()); - - vm.submit(); - rootScope.$apply(); - - expect(notificationService.success).not.toHaveBeenCalledWith('stockAdjustmentCreation.submitted'); - }); - - it('should redirect with proper state params after success', function() { - spyOn(stockAdjustmentCreationService, 'submitAdjustments'); - stockAdjustmentCreationService.submitAdjustments.andReturn(q.resolve()); - - vm.submit(); - rootScope.$apply(); - - expect(alertService.error).not.toHaveBeenCalled(); - }); - - it('should not redirect after error', function() { - spyOn(stockAdjustmentCreationService, 'submitAdjustments'); - stockAdjustmentCreationService.submitAdjustments - .andReturn(q.reject({ - data: { - message: 'error occurred' - } - })); - - vm.submit(); - rootScope.$apply(); - - expect(state.go).toHaveBeenCalledWith(state.current.name, stateParams, { - reload: false, - notify: false - }); - - expect(notificationService.success).not.toHaveBeenCalled(); - }); - - it('should not submit if new lot code exists in the database', function() { - spyOn(LotResource.prototype, 'query').andCallFake(function(response) { - response.numberOfElements = 1; - return q.resolve(response); - }); - vm.submit(); - rootScope.$apply(); - - expect(state.go).toHaveBeenCalledWith(state.current.name, stateParams, { - reload: false, - notify: false - }); - - expect(notificationService.success).not.toHaveBeenCalled(); - }); - - it('should generate kit constituent if the state is unpacking', function() { - spyOn(stockAdjustmentCreationService, 'submitAdjustments'); - stockAdjustmentCreationService.submitAdjustments.andReturn(q.resolve()); - - vm = initController([this.orderableGroup], ADJUSTMENT_TYPE.KIT_UNPACK); - - vm.addedLineItems = [{ - reason: { - id: UNPACK_REASONS.KIT_UNPACK_REASON_ID - }, - orderable: this.kitOrderable, - occurredDate: new Date(), - quantity: 2, - $errors: {} - }]; - - vm.submit(); - - rootScope.$applyAsync(); - - timeout(function() { - var unpackingLineItem = stockAdjustmentCreationService.submitAdjustments - .mostRecentCall.args[2]; - - expect(unpackingLineItem.length).toEqual(2); - expect(unpackingLineItem[1].reason.id).toEqual(UNPACK_REASONS.UNPACKED_FROM_KIT_REASON_ID); - expect(unpackingLineItem[0].reason.id).toEqual(UNPACK_REASONS.KIT_UNPACK_REASON_ID); - expect(unpackingLineItem[1].quantity).toEqual(60); - expect(unpackingLineItem[0].quantity).toEqual(2); - }, 1000); - }); - - it('should redirect with proper state params after success in offline mode', function() { - this.offlineService.isOffline.andReturn(true); - - spyOn(stockAdjustmentCreationService, 'submitAdjustments'); - stockAdjustmentCreationService.submitAdjustments.andReturn(q.resolve()); - - vm.submit(); - rootScope.$apply(); - - expect(notificationService.success).not.toHaveBeenCalled(); - expect(alertService.error).not.toHaveBeenCalled(); - }); - }); - - describe('orderableSelectionChanged', function() { - - it('should unselect lot', function() { - vm.selectedLot = new LotDataBuilder().build(); - - vm.orderableSelectionChanged(); - - expect(vm.selectedLot).toBe(null); - }); - - it('should clear form', function() { - vm.selectedLot = new LotDataBuilder().build(); - - vm.orderableSelectionChanged(); - - expect(scope.productForm.$setPristine).toHaveBeenCalled(); - expect(scope.productForm.$setUntouched).toHaveBeenCalled(); - }); - - }); - - describe('lotChanged', function() { - - it('should clear new lot code', function() { - vm.newLot.lotCode = 'NewLot001'; - vm.lotChanged(); - - expect(vm.newLot.lotCode).not.toBeDefined(); - }); - - it('should clear new lot expiration date', function() { - vm.newLot.expirationDate = '2019-08-06'; - vm.lotChanged(); - - expect(vm.newLot.expirationDate).not.toBeDefined(); - }); - - it('should set canAddNewLot as true', function() { - vm.selectedLot = new LotDataBuilder() - .withCode('orderableGroupService.addMissingLot') - .build(); - vm.lotChanged(); - - expect(vm.canAddNewLot).toBeTruthy(); - }); - - it('should set canAddNewLot as false', function() { - vm.selectedLot = new LotDataBuilder().build(); - vm.lotChanged(); - - expect(vm.canAddNewLot).toBeFalsy(); - }); - }); - - function initController(orderableGroups, adjustmentType) { - return $controller('StockAdjustmentCreationController', { - $scope: scope, - $state: state, - $stateParams: stateParams, - program: program, - facility: facility, - adjustmentType: adjustmentType ? adjustmentType : ADJUSTMENT_TYPE.ADJUSTMENT, - srcDstAssignments: undefined, - user: {}, - reasons: reasons, - orderableGroups: orderableGroups, - displayItems: [], - hasPermissionToAddNewLot: true, - editLotModalService: this.editLotModalService - }); - } - -}); \ No newline at end of file diff --git a/src/stock-adjustment-creation/adjustment-creation.html b/src/stock-adjustment-creation/adjustment-creation.html deleted file mode 100644 index 6cafad4..0000000 --- a/src/stock-adjustment-creation/adjustment-creation.html +++ /dev/null @@ -1,154 +0,0 @@ -

- {{vm.key('title') | message:{'facilityCode': vm.facility.code, 'facilityName': vm.facility.name, 'program': vm.program.name} }} -

- -
-
-
-
- - -
- - -
-
-
-
- - -
-
- - -
-
- - - - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{vm.key('noProducts') | message}}
{{vm.key('productCode') | message}}{{vm.key('product') | message}}{{vm.key('lotCode') | message}}{{vm.key('expiryDate') | message}}{{vm.key('soh') | message}}{{vm.key('srcDstLabel') | message}}{{vm.key('srcDstComments') | message}}{{vm.key('reason') | message}}{{vm.key('reasonComments') | message}}{{vm.key('quantity') | message}}{{'adjustmentCreation.price' | message}}{{'adjustmentCreation.totalPrice' | message}}{{vm.key('vvmStatus') | message}}{{vm.key('date') | message}}{{vm.key('actions') | message}}
{{lineItem.orderable.productCode}}{{lineItem.orderable | productName}} - - - {{lineItem.displayLotMessage}} - {{lineItem.lot.expirationDate | openlmisDate}}{{lineItem.$previewSOH}} - - - - - - - - - - - {{lineItem.price | openlmisCurrency}} - - - - {{lineItem.totalPrice | openlmisCurrency}} - - - - - - -
- -
-
- - - - \ No newline at end of file diff --git a/src/stock-adjustment-creation/adjustment-creation.service.spec.js b/src/stock-adjustment-creation/adjustment-creation.service.spec.js index 16c406f..680d754 100644 --- a/src/stock-adjustment-creation/adjustment-creation.service.spec.js +++ b/src/stock-adjustment-creation/adjustment-creation.service.spec.js @@ -229,4 +229,4 @@ describe('stockAdjustmentCreationService', function() { .toHaveBeenCalledWith('openlmis-referencedata.offline-events-indicator'); }); }); -}); +}); \ No newline at end of file diff --git a/src/stock-adjustment-creation/messages_en.json b/src/stock-adjustment-creation/messages_en.json index 05f6c1e..ab11a6c 100644 --- a/src/stock-adjustment-creation/messages_en.json +++ b/src/stock-adjustment-creation/messages_en.json @@ -1,7 +1,3 @@ { - "adjustmentCreation.printModal.label": "Print this issue?", - "adjustmentCreation.price": "Unit Price", - "adjustmentCreation.totalPrice": "Total Price", - "adjustmentCreation.numberEqualOrGreaterThan0": "You must input number equal or greater than 0", - "adjustmentCreation.totalCost": "Total Cost" + "adjustmentCreation.printModal.label": "Print this issue?" } \ No newline at end of file diff --git a/src/stock-card-summary-list/messages_en.json b/src/stock-card-summary-list/messages_en.json index d904733..da76702 100644 --- a/src/stock-card-summary-list/messages_en.json +++ b/src/stock-card-summary-list/messages_en.json @@ -1,7 +1,5 @@ { "stockCardSummaryList.productName": "Product Name", "stockCardSummaryList.lotCode": "Lot code", - "stockCardSummaryList.productCode": "Product Code", - "stockCardSummaryList.unitPrice": "Unit Price", - "stockCardSummaryList.totalPrice": "Total Price" + "stockCardSummaryList.productCode": "Product Code" } \ No newline at end of file diff --git a/src/stock-card-summary-list/stock-card-summary-list.controller.js b/src/stock-card-summary-list/stock-card-summary-list.controller.js index 0d1a569..84612d8 100644 --- a/src/stock-card-summary-list/stock-card-summary-list.controller.js +++ b/src/stock-card-summary-list/stock-card-summary-list.controller.js @@ -105,19 +105,6 @@ */ vm.lotCode = $stateParams.lotCode; - // AO-816: Add prices to the Stock On Hand view - /** - * @ngdoc property - * @propertyOf stock-card-summary-list.controller:StockCardSummaryListController - * @name totalCost - * @type {Number} - * - * @description - * Holds total cost of adjustments line items - */ - vm.totalCost = 0; - // AO-816: Ends here - /** * @ngdoc method * @methodOf stock-card-summary-list.controller:StockCardSummaryListController @@ -127,14 +114,6 @@ * Initialization method for StockCardSummaryListController. */ function onInit() { - // AO-816: Add prices to the Stock On Hand view - stockCardSummaries.forEach(function(stockCardSummary) { - stockCardSummary.orderable.unitPrice = getProductPrice(stockCardSummary); - stockCardSummary.orderable.totalPrice = stockCardSummary.orderable.unitPrice * - stockCardSummary.stockOnHand; - }); - calculateTotalCost(stockCardSummaries); - // AO-816: Ends here vm.stockCardSummaries = stockCardSummaries; vm.displayStockCardSummaries = angular.copy(stockCardSummaries); checkCanFulFillIsEmpty(); @@ -256,24 +235,5 @@ } }); } - - // AO-816: Add prices to the Stock On Hand view - function getProductPrice(product) { - var programOrderable = product.orderable.programs.find(function(programOrderable) { - return programOrderable.programId === $stateParams.program; - }); - - return programOrderable.pricePerPack; - } - - function calculateTotalCost(stockCardSummaries) { - var sum = 0; - stockCardSummaries.forEach(function(stockCardSummary) { - sum += stockCardSummary.orderable.totalPrice; - }); - - vm.totalCost = sum; - } - // AO-816: Ends here } })(); \ No newline at end of file diff --git a/src/stock-card-summary-list/stock-card-summary-list.controller.spec.js b/src/stock-card-summary-list/stock-card-summary-list.controller.spec.js index 7d6438e..b343870 100644 --- a/src/stock-card-summary-list/stock-card-summary-list.controller.spec.js +++ b/src/stock-card-summary-list/stock-card-summary-list.controller.spec.js @@ -48,20 +48,10 @@ describe('StockCardSummaryListController', function() { new this.StockCardSummaryDataBuilder().build() ]; - // AO-816: Add prices to the Stock On Hand view this.stateParams = { - param: 'param', - program: 'program' + param: 'param' }; - this.stockCardSummaries.forEach(function(stockCardSummary) { - stockCardSummary.orderable.programs = [{ - programId: 'program', - pricePerPack: 0 - }]; - }); - // AO-816: Ends here - spyOn(this.offlineService, 'isOffline').andReturn(true); this.vm = this.$controller('StockCardSummaryListController', { diff --git a/src/stock-card-summary-list/stock-card-summary-list.html b/src/stock-card-summary-list/stock-card-summary-list.html index 9e417f0..8bc6d70 100644 --- a/src/stock-card-summary-list/stock-card-summary-list.html +++ b/src/stock-card-summary-list/stock-card-summary-list.html @@ -55,10 +55,6 @@

{{'stockCardSummaryList.stockOnHand' | m {{'stockCardSummaryList.expiryDate' | message}} {{'stockCardSummaryList.lastUpdate' | message}} {{'stockCardSummaryList.stockOnHand' | message}} - - {{'stockCardSummaryList.unitPrice' | message}} - {{'stockCardSummaryList.totalPrice' | message}} - {{'stockCardSummaryList.actions' | message}} @@ -70,10 +66,6 @@

{{'stockCardSummaryList.stockOnHand' | m {{summary.stockOnHand}} - - {{summary.orderable.unitPrice | openlmisCurrency}} - {{summary.orderable.totalPrice | openlmisCurrency}} - @@ -85,10 +77,6 @@

{{'stockCardSummaryList.stockOnHand' | m {{fulfills.lot ? (fulfills.lot.expirationDate | openlmisDate) : ''}} {{fulfills.occurredDate | openlmisDate}} {{fulfills.stockOnHand}} - - - -