Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/stock-adjustment-creation/adjustment-creation.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
'ADJUSTMENT_TYPE', 'UNPACK_REASONS', 'REASON_TYPES', 'STOCKCARD_STATUS', 'hasPermissionToAddNewLot',
'LotResource', '$q', 'editLotModalService', 'moment', 'rejectionReasonService', 'receivingAddDiscrepancyModalService',
'complaintFormModalService', 'suppliers', 'ReferenceNumbers', 'facilityWithType',
'QUANTITY_UNIT', 'quantityUnitCalculateService', 'requisitionLineItems'];
'QUANTITY_UNIT', 'quantityUnitCalculateService', 'requisitionLineItems', 'adjustmentLineItemsService'];

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, rejectionReasonService, receivingAddDiscrepancyModalService, complaintFormModalService,
suppliers, ReferenceNumbers, facilityWithType, QUANTITY_UNIT, quantityUnitCalculateService, requisitionLineItems) {
suppliers, ReferenceNumbers, facilityWithType, QUANTITY_UNIT, quantityUnitCalculateService, requisitionLineItems, adjustmentLineItemsService) {
var vm = this,
previousAdded = {};

Expand Down Expand Up @@ -204,8 +204,10 @@

$stateParams.addedLineItems = vm.addedLineItems;
$stateParams.displayItems = vm.displayItems;
adjustmentLineItemsService.setLineItems(vm.addedLineItems);
$stateParams.keyword = vm.keyword;
$stateParams.page = getPageNumber();
$stateParams.noReload = true;
$state.go($state.current.name, $stateParams, {
reload: true,
notify: false,
Expand Down Expand Up @@ -807,6 +809,7 @@
)
.then(
function () {
adjustmentLineItemsService.clearLineItems();
if (offlineService.isOffline()) {
notificationService.offline(vm.key('submittedOffline'));
} else {
Expand Down Expand Up @@ -981,8 +984,11 @@
'openlmis.stockmanagement.stockCardSummaries'
);

$scope.$on('$stateChangeStart', function () {
$scope.$on('$stateChangeStart', function (event, toState) {
angular.element('.popover').popover('destroy');
if (toState.name !== $state.current.name && !$stateParams.noReload) {
adjustmentLineItemsService.clearLineItems();
}
});
}

Expand Down Expand Up @@ -1018,12 +1024,18 @@
adjustmentType.state === ADJUSTMENT_TYPE.RECEIVE.state && (facilityWithType.type.code === "service_point");//(facility.type.code === "quarantine" || facility.type.code === "unserviceable");
/* eLMIS Lesotho : end */

vm.addedLineItems = $stateParams.addedLineItems || [];
var savedItems = adjustmentLineItemsService.getLineItems();
vm.addedLineItems = (savedItems.length > 0) ? savedItems : [];
$stateParams.noReload = undefined;
$stateParams.displayItems = displayItems;
vm.keyword = $stateParams.keyword;

// vm.displayItems = $stateParams.displayItems || [];
vm.displayItems = [];
vm.keyword = $stateParams.keyword;
vm.displayItems = stockAdjustmentCreationService.search(
vm.keyword,
vm.addedLineItems,
vm.hasLot
);
updateNeedToConfirmFlag();

vm.orderableGroups = orderableGroups;
Expand Down Expand Up @@ -1272,3 +1284,25 @@
onInit();
}
})();

(function() {
'use strict';

angular
.module('stock-adjustment-creation')
.service('adjustmentLineItemsService', function() {
var lineItems = [];

this.getLineItems = function() {
return lineItems;
};

this.setLineItems = function(items) {
lineItems = items;
};

this.clearLineItems = function() {
lineItems = [];
};
});
})();