angular.module('kalgudiApp.eCommerce').controller('storeOrdersInboxController', ['$scope', '$state', '$rootScope', 'eCommerceServices', 'kalgudiLiterals', '$interval', '$filter', '$sce', '$injector', 'myaccountsreportService', function ($scope, $state, $rootScope, eCommerceServices, kalgudiLiterals, $interval, $filter, $sce, $injector, myaccountsreportService) { /* Kalgudi Store Front Related Starts */ $scope.tabs = ["Orders", "Accounts", "Reports"]; $scope.selectedTab = "Orders"; $scope.selectedActivityTab = 0; $scope.orderLiterals = kalgudiLiterals; $scope.activityTabs = { ORDERS: 0, ACCOUNTS: 1, REPORTS: 2, }; $scope.toggleTabs = function (selectedTab, reportsTab) { $scope.selectedActivityTab = selectedTab; }; /*----------------- To use date picker while creating a survey -----------------*/ var today = new Date(); $scope.datevar = { fromDate: new Date(), toDate: new Date() }; $scope.AvailableDate = ''; $scope.ExpireDate = new Date(); $scope.dateFormat = 'dd-MMM-yy'; $scope.availableDates = { formatYear: 'yy', startingDay: 1, minDate: new Date(1995, 1, 1), maxDate: new Date(2030, 5, 22) }; $scope.fromDatePopup = { opened: false, fromOpened: false, toOpened: false }; $scope.toDatePopup = { opened: false, fromOpened: false, toOpened: false }; $scope.ChangeExpiryMinDate = function (availableDate) { if (availableDate != null) { var expiryMinDate = new Date(availableDate); $scope.expireDateOptions.minDate = expiryMinDate; $scope.ExpireDate = expiryMinDate; } }; $scope.ChangeExpiryMinDate(); $scope.OpenFromDate = function () { $scope.fromDatePopup.opened = !$scope.fromDatePopup.opened; }; $scope.OpenToDate = function () { $scope.toDatePopup.opened = !$scope.toDatePopup.opened; }; $scope.setfromDate = function (fromDate) { $scope.datevar.fromDate = fromDate; }; $scope.setToDate = function (toDate) { $scope.datevar.toDate = todayDate; }; /* ------------------------- end of date picker ---------------------*/ var orderListSet = new Set(); $scope.init = function () { $scope.offset = 0; $scope.limit = 100; $scope.type = ''; $scope.ordersList = []; orderListSet = new Set(); $scope.accountInfo = { 'accountId': '' } $scope.orderImages = { 'ORD_RECEIVED': { sellerTitle: $scope.orderLiterals.literalsData.NEW_ORD, buyerTitle: 'Waiting for Seller confirmation', sellerImageUrl: 'common/images/state-machine/lace.png', buyerImageUrl: 'common/images/state-machine/exclamation.svg' }, 'ORD_INP': { buyerTitle: $scope.orderLiterals.literalsData.ORD_CONFIRMED, sellerTitle: $scope.orderLiterals.literalsData.ORD_PROGRESS, sellerImageUrl: 'common/images/state-machine/sand-clock.png', buyerImageUrl: 'common/images/state-machine/checked.svg', }, 'QC_WAITING': { sellerTitle: $scope.orderLiterals.literalsData.WAIT_FOR_QC_ACCPET, buyerTitle: $scope.orderLiterals.literalsData.IN_QC, sellerImageUrl: 'common/images/state-machine/sand-clock.png', buyerImageUrl: 'common/images/state-machine/sand-clock.png', }, 'QC_INP': { sellerTitle: $scope.orderLiterals.literalsData.QC_IN_PROGRESS, buyerTitle: $scope.orderLiterals.literalsData.IN_QC, sellerImageUrl: 'common/images/state-machine/quality.png', buyerImageUrl: 'common/images/state-machine/quality.png', }, 'PKG_WAITING': { buyerTitle: $scope.orderLiterals.literalsData.WAIT_FOR_PACK_ACCEPT, sellerTitle: $scope.orderLiterals.literalsData.WAIT_FOR_PACK_ACCEPT, sellerImageUrl: 'common/images/state-machine/sand-clock.png', buyerImageUrl: 'common/images/state-machine/sand-clock.png', }, 'PKG_INP': { buyerTitle: $scope.orderLiterals.literalsData.PACKING_PROGRESS, sellerTitle: $scope.orderLiterals.literalsData.PACKING_PROGRESS, sellerImageUrl: 'common/images/state-machine/packingbox.png', buyerImageUrl: 'common/images/state-machine/packingbox.png', }, 'TR_WAITING': { buyerTitle: $scope.orderLiterals.literalsData.WAIT_FOR_TRANSPORT_ACCEPT, sellerTitle: $scope.orderLiterals.literalsData.WAIT_FOR_TRANSPORT_ACCEPT, sellerImageUrl: 'common/images/state-machine/sand-clock.png', buyerImageUrl: 'common/images/state-machine/sand-clock.png', }, 'TR_INP': { buyerTitle: 'In transit', sellerTitle: 'In transit', sellerImageUrl: 'common/images/state-machine/transit.png', buyerImageUrl: 'common/images/state-machine/transit.png', }, 'ORD_DELIVERED': { buyerTitle: $scope.orderLiterals.literalsData.ORD_DELIVERED, sellerTitle: $scope.orderLiterals.literalsData.ORD_DELIVERED, sellerImageUrl: 'common/images/state-machine/delivery.png', buyerImageUrl: 'common/images/state-machine/delivery.png', } }; $scope.stateMessageLookupFullview = { "ORD_RECEIVED": { title: $scope.orderLiterals.literalsData.NEW_ORD, imgUrl: 'common/images/state-machine/lace.png' }, "ORD_CONFIRMED": { title: $scope.orderLiterals.literalsData.ORD_CONFIRMED, imgUrl: 'common/images/state-machine/checked.svg' }, "ORD_SCF": { title: $scope.orderLiterals.literalsData.WAITING_FOR_SELLER_CONFIRM, imgUrl: 'common/images/state-machine/exclamation.svg' }, "ORD_INP": { title: $scope.orderLiterals.literalsData.ORD_PROGRESS, imgUrl: 'common/images/state-machine/sand-clock.png' }, "QC_WAITING": { title: $scope.orderLiterals.literalsData.WAIT_FOR_QC_ACCPET, imgUrl: 'common/images/state-machine/exclamation.svg' }, "QC_INP": { title: $scope.orderLiterals.literalsData.QC_IN_PROGRESS, imgUrl: 'common/images/state-machine/sand-clock.png' }, "PKG_WAITING": { title: $scope.orderLiterals.literalsData.WAIT_FOR_PACK_ACCEPT, imgUrl: 'common/images/state-machine/exclamation.svg' }, "PKG_INP": { title: $scope.orderLiterals.literalsData.PACKING_PROGRESS, imgUrl: 'common/images/state-machine/packingbox.png' }, "TR_WAITING": { title: $scope.orderLiterals.literalsData.WAIT_FOR_TRANSPORT_ACCEPT, imgUrl: 'common/images/state-machine/exclamation.svg' }, "TR_INP": { title: $scope.orderLiterals.literalsData.IN_TRANSIT, imgUrl: 'common/images/state-machine/transit.png' }, "ORD_DELIVERED": { title: $scope.orderLiterals.literalsData.ORD_DELIVERED, imgUrl: 'common/images/state-machine/delivery.png' }, "ORD_RECEIVED_FMT_REJECTIONS": { title: $scope.orderLiterals.literalsData.ORD_RECEIVED_FMT_REJECTIONS, imgUrl: 'common/images/state-machine/reject.jpg' }, "QC_WAITING_FMT_REJECTIONS": { title: $scope.orderLiterals.literalsData.QC_WAITING_FMT_REJECTIONS, imgUrl: 'common/images/state-machine/reject.jpg' }, "PKG_WAITING_FMT_REJECTIONS": { title: $scope.orderLiterals.literalsData.PKG_WAITING_FMT_REJECTIONS, imgUrl: 'common/images/state-machine/reject.jpg' }, "TR_WAITING_FMT_REJECTIONS": { title: $scope.orderLiterals.literalsData.TR_WAITING_FMT_REJECTIONS, imgUrl: 'common/images/state-machine/reject.jpg' }, "QC_FAILURES": { title: $scope.orderLiterals.literalsData.QC_FAILURES, imgUrl: 'common/images/state-machine/failed.jpg' }, "ORD_RECEIVED_TIME_OUT": { title: $scope.orderLiterals.literalsData.NEW_ORD + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "ORD_INP_TIME_OUT": { title: $scope.orderLiterals.literalsData.ORD_PROGRESS + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "QC_WAITING_TIME_OUT": { title: $scope.orderLiterals.literalsData.WAIT_FOR_QC_ACCPET + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "QC_INP_TIME_OUT": { title: $scope.orderLiterals.literalsData.QC_IN_PROGRESS + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "PKG_WAITING_TIME_OUT": { title: $scope.orderLiterals.literalsData.WAIT_FOR_PACK_ACCEPT + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "PKG_INP_TIME_OUT": { title: $scope.orderLiterals.literalsData.PACKING_PROGRESS + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "TR_WAITING_TIME_OUT": { title: $scope.orderLiterals.literalsData.WAIT_FOR_TRANSPORT_ACCEPT + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "TR_INP_TIME_OUT": { title: $scope.orderLiterals.literalsData.IN_TRANSIT + " Time out", imgUrl: 'common/images/state-machine/timeout_new.png' }, "REFUND_INPROGRESS": { title: $scope.orderLiterals.literalsData.REFUND_INPROGRESS, imgUrl: 'common/images/state-machine/refund_progress.jpg' }, "CLOSED": { title: $scope.orderLiterals.literalsData.CLOSED, imgUrl: 'common/images/state-machine/refunded.jpg' }, "CANCEL_REQUESTED": { title: $scope.orderLiterals.literalsData.CANCEL_REQUESTED, imgUrl: 'common/images/state-machine/cancel.png' }, "CANCEL_REQUESTED_BUYER": { title: $scope.orderLiterals.literalsData.CANCEL_REQUESTED_BUYER, imgUrl: 'common/images/state-machine/cancel.png' }, }; $scope.getStateMessageFullview = function (state) { return $scope.stateMessageLookupFullview[state]; }; $scope.help = function (order) { if (detectmob()) { var title = "for Queries call"; var icon = "call"; var expires = "4000"; var message = "@ 083284 57072"; $rootScope.showAlertBox(message, title, icon, expires); } else { order.helpFlag = !order.helpFlag; } }; $scope.getOrders(); if (detectmob()) { $ionicModal = $injector.get("$ionicModal"); } else { $uibModal = $injector.get('$uibModal'); } }; $scope.reset = function () { $scope.offset = 0; $scope.limit = 100; $scope.type = ''; } $scope.getOrders = function () { //$rootScope.spinerisActive = true; eCommerceServices.getOrdersList($scope.offset, $scope.limit, $scope.type).then(function (response) { if ((response.code === 200 || response.code === 201) && response.data) { var data = JSON.parse(response.data); for (var i = 0; i < data.length; i++) { data[i] = JSON.parse(data[i]); data[i].LUT = new Date(data[i].LUT).getTime(); data[i] = $scope.resetActions(data[i]); if (!(orderListSet.has(data[i].orderId))) { orderListSet.add(data[i].orderId); $scope.ordersList.push(data[i]); } else { try { const index = $scope.ordersList.findIndex(function (order) { return (order.orderId === data[i].orderId); }); if (new Date($scope.ordersList[index].LUT) < new Date(data[i].LUT)) { console.log('replacing order object'); $scope.ordersList[index] = data[i]; } } catch (e) { console.warn('Something went wrong.', e); } } // If order id does not exits in array // Add order id to the array or ids // push order to the orderslist } $scope.chatNotification = false; } }, function (err) { console.log("Unable to load the Orders"); }); }; $scope.resetActions = function (order) { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.stateInfo.actor) { if (order.stateInfo.actions) { order.stateInfo.actions = $scope.sortActionLabel(order.stateInfo.actions); } } if ($rootScope.loggedInUserBusinessProfile.profileKey == order.buyerId) { if (order.stateInfo.buyerActions) { order.stateInfo.buyerActions = $scope.sortActionLabel(order.stateInfo.buyerActions); } } return order; } $scope.updateOrderStatus = function (orderId, statusToUpdate) { $rootScope.spinerisActive = true; if ($scope.checkActions(orderId, statusToUpdate)) { eCommerceServices.updateOrder(orderId, statusToUpdate).then( function (response) { $rootScope.spinerisActive = false; if (response.code === 201 || response.code === 200) { console.log(response.data); $scope.init(); } }, function (err) { $rootScope.spinerisActive = false; console.log("Unable to update the Order"); }); } else { $rootScope.spinerisActive = false; } }; $scope.openOrderFullView = function (orderId, defaultTab) { defaultTab = defaultTab || 0; $rootScope.goToState('eCommerce.fullview', { id: orderId, defaultTab: defaultTab }); }; $scope.isChatNotification = function (order) { for (key in order.map) { if (key.includes($rootScope.loggedInUserBusinessProfile.profileKey) && order.map[key] === true) { return true; } } return false; }; $scope.checkActions = function (orderId, actionName) { const updateActions = { 'ord_UPDATE': true, 'qc_UPDATE': true, 'pkg_UPDATE': true, 'tr_UPDATE': true, }; actionName = actionName || 'NONE'; if (updateActions[actionName]) { $rootScope.goToState('eCommerce.fullview', { id: orderId }); } else { return true; } } $scope.checkDisable = function (actionName) { const rejectActions = { 'qc_REJECT': true, 'qc_FAIL': true, 'pkg_REJECT': true, 'pkg_FAIL': true, 'tr_REJECT': true, 'tr_FAIL_TO_DELIVER': true, 'ord_REJECT': true }; actionName = actionName || 'NONE'; return rejectActions[actionName]; } $interval(callAtInterval, 30000); function callAtInterval() { console.log("Interval occurred"); $scope.reset(); $scope.getOrders(); } $scope.reportsTypes = [ { title: 'All', value: 'ALLORDERS' }, { title: 'Delivered', value: 'DELORDER' }, { title: 'Pending', value: 'PENORDERS' }, { title: '--Accounts--', value: '' }, { title: 'Daybook', value: 'Daybook' }, { title: 'Ledger', value: 'Ledger' } ] $scope.selectReport = function (selectedReportType) { $scope.selectedReportType = selectedReportType; $scope.reportOrders = []; if ($scope.selectedReportType.value.toLowerCase() === 'ledger') { $scope.dataparams = { "transaction_type": "others" } myaccountsreportService.getAccountsDetails($scope.dataparams).then(function (data) { $scope.accountData = data; for (index in $scope.accountData) { $scope.accountData[index].childAccountName = ($scope.accountData[index].account_name).split('$')[0]; $scope.accountData[index].parentAccountName = ($scope.accountData[index].account_name).split('$')[1]; } }); } }; $scope.downloadReport = function (fromDate, toDate) { $scope.reportOrders = []; $rootScope.spinerisActive = true; if (fromDate && toDate && ($scope.selectedReportType.value === 'ALLORDERS' || $scope.selectedReportType.value === 'DELORDER' || $scope.selectedReportType.value === 'PENORDERS')) { fromDate = $filter('date')(fromDate, 'yyyy-MM-dd'); toDate = $filter('date')(toDate, 'yyyy-MM-dd'); eCommerceServices.orderReports(fromDate, toDate, $scope.selectedReportType.value).then( function (response) { $rootScope.spinerisActive = false; if (response.code == 200 && response.data) { response.data = JSON.parse(response.data); for (var i = 0; i < response.data.length; i++) { $scope.reportOrders.push(response.data[i]); } } else { console.log("Unable to Download the Report") } }, function (err) { $rootScope.spinerisActive = false; } ); } else if ((fromDate && toDate)) { fromDate = $filter('date')(fromDate, 'dd MMM yy'); toDate = $filter('date')(toDate, 'dd MMM yy'); if ($scope.selectedReportType.value.toLowerCase() === 'daybook') { $scope.dataparams = { "date_from": fromDate, "date_to": toDate } //Daybook Reports myaccountsreportService.getDayBookReports($scope.dataparams).then( function (response) { $rootScope.spinerisActive = false; if (response.length) { $scope.reportOrders = response; } else { console.log("Unable to Fetch the Daybook"); } }, function (err) { $rootScope.spinerisActive = false; console.log("Error! Unable to Fetch the Daybook"); } ); } else if ($scope.selectedReportType.value.toLowerCase() === 'ledger') { $scope.dataparams = { "date_from": fromDate, "date_to": toDate, "account_id": $scope.accountInfo.accountname.account_id } // Ledger Reports myaccountsreportService.getGeneralLedgerReports($scope.dataparams).then( function (response) { $rootScope.spinerisActive = false; if (response.length) { $scope.reportOrders = response; } else { console.log("Unable to Fetch the Ledger"); } }, function (err) { $rootScope.spinerisActive = false; console.log("Error! Unable to Fetch the Ledger"); } ); } } } $scope.modalInstance; $scope.open = function (order) { var obj = { state: order.stateInfo.currentState, productData: $scope.getProductGuidelines(order.productList) }; $scope.currentGuideline = obj; $scope.modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'eCommerce/guidelines.html', scope: $scope, windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return obj; } } }); }; /* * Close the $uibModal */ $scope.cancel = function () { $scope.modalInstance.close(); } $scope.openGuideline = function (order) { var obj = { state: order.stateInfo.currentState, productData: $scope.getProductGuidelines(order.productList), }; $scope.currentGuideline = obj; $scope.adminModal = $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue + 'eCommerce/guidelines.html', { scope: $scope, animation: 'slide-in-up', }).then(function (modal) { $scope.adminModal = modal; $scope.adminModal.show(); }); }; //Model Close $scope.closeGuideline = function () { $scope.adminModal.hide(); } /* * Selects New User for Configuration */ $scope.openOrderConfig = function (order) { $scope.sellerConfigurationActivity = order.fulfillmentDeatils; for (actor in $scope.sellerConfigurationActivity) { $scope.sellerConfigurationActivity[actor] = { 'activity_id': actor, 'activity_type': actor, 'fullfillment_Activity': actor, 'resonsible_Party': $scope.sellerConfigurationActivity[actor].name, 'editable': $scope.checkState(order.stateInfo.currentState, actor), 'key': $scope.sellerConfigurationActivity[actor].key, 'name': $scope.sellerConfigurationActivity[actor].name, 'commission': $scope.sellerConfigurationActivity[actor].commission } } var configData = []; if ($scope.sellerConfigurationActivity['PROCESSING']) { const a = $scope.sellerConfigurationActivity['PROCESSING']; configData.push(a); } if ($scope.sellerConfigurationActivity['QC']) { const b = $scope.sellerConfigurationActivity['QC']; configData.push(b); } if ($scope.sellerConfigurationActivity['PACKAGING']) { const c = $scope.sellerConfigurationActivity['PACKAGING']; configData.push(c); } if ($scope.sellerConfigurationActivity['TRANSPORT']) { const d = $scope.sellerConfigurationActivity['TRANSPORT']; configData.push(d); } var obj = { order: order, sellerConfigurationActivity: configData }; $scope.currentOrder = obj; $scope.modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'eCommerce/order-configuration-template.html', scope: $scope, windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return obj; } } }); } //Model Start $scope.orderOpenConfig = function (order) { $scope.sellerConfigurationActivity = order.fulfillmentDeatils; for (actor in $scope.sellerConfigurationActivity) { $scope.sellerConfigurationActivity[actor] = { 'activity_id': actor, 'activity_type': actor, 'fullfillment_Activity': actor, 'resonsible_Party': $scope.sellerConfigurationActivity[actor].name, 'editable': $scope.checkState(order.stateInfo.currentState, actor), 'key': $scope.sellerConfigurationActivity[actor].key, 'name': $scope.sellerConfigurationActivity[actor].name } } var obj = { order: order, sellerConfigurationActivity: $scope.sellerConfigurationActivity }; $scope.currentOrder = obj; // Initialize add admin modal $scope.adminModal = $ionicModal.fromTemplateUrl($rootScope.themebasepathvalue + 'eCommerce/order-configuration-template.html', { scope: $scope, animation: 'slide-in-up', }).then(function (modal) { $scope.adminModal = modal; $scope.adminModal.show(); }); } //Model Close $scope.closeorderConfig = function () { $scope.adminModal.hide(); } /* * Get the current order configuration */ $scope.getOrderConfiguration = function (profileKey) { var deferred = $q.defer(); profileService.getUserProfile(profileKey).then( function (response) { deferred.resolve(response); // return response.firstName; }, function (err) { console.log("Unable to get the Profile Data - ", profileKey); deferred.reject(err); } ); return deferred.promise; } /* * Selects and update the Actor in the order configuration */ $scope.updateActor = function (selectedActor) { var responseData = { isMultiSelectAllowed: false }; var modalInstance = $uibModal.open({ templateUrl: 'webapp/themes/html/shared/connects.html', controller: 'kalgudiSearchContacts', size: 'md', scope: $scope, resolve: { filterData: responseData } }); modalInstance.result.then( function (selectedItem) { console.log(selectedActor) $scope.sellerConfigurationActivity[selectedActor].key = selectedItem[0].profileKey; $scope.sellerConfigurationActivity[selectedActor].resonsible_Party = selectedItem[0].firstName; $scope.sellerConfigurationActivity[selectedActor].name = selectedItem[0].firstName; }, function (err) { } ); } //updating Actor from mobile $scope.onMembersSelect = function (users) { $scope.sellerConfigurationActivity[$scope.selectedActor].key = users[0].profileKey; $scope.sellerConfigurationActivity[$scope.selectedActor].resonsible_Party = users[0].firstName; $scope.sellerConfigurationActivity[$scope.selectedActor].name = users[0].firstName, $scope.isUserPickerShown = false; } //Method for kalgudi users directive $scope.showUserPicker = function (selectedActor) { $scope.selectedActor = selectedActor title = "Select Target Members"; $rootScope.$broadcast("changeHeaderTitle", title); $scope.isUserPickerShown = true; } /* * Check state of order and actor * Enable and Disable Configuration */ $scope.checkState = function (state, actor) { if ((state === 'ORD_RECEIVED' || state === 'ORD_INP') && actor === 'PROCESSING') { return false; } if ((state === 'QC_WAITING' || state === 'QC_INP') && (actor === 'PROCESSING' || actor === 'QC')) { return false; } if ((state === 'PKG_WAITING' || state === 'PKG_INP') && (actor === 'PROCESSING' || actor === 'QC' || actor === 'PACKAGING')) { return false; } if ((state === 'TR_WAITING' || state === 'TR_INP') && (actor === 'PROCESSING' || actor === 'QC' || actor === 'PACKAGING' || actor === 'TRANSPORT')) { return false; } if (state === 'ORD_DELIVERED') { return false; } if (state === 'FMT_REJECTIONS') { return false; } if (state === 'QC_FAILURES') { return false; } if (state === 'TIME_OUT') { return false; } if (state === 'REFUND_INPROGRESS') { return false; } if (state === 'CANCEL_REQUESTED') { return false; } return true; } /* * Update the Order Configuration */ $scope.updateConfiguration = function (order) { if (detectmob()) { $scope.closeorderConfig(); } else { $scope.cancel(); } $rootScope.spinerisActive = true; console.log($scope.sellerConfigurationActivity) order.fulfillmentDeatils = $scope.sellerConfigurationActivity; for (i in order.fulfillmentDeatils) { delete order.fulfillmentDeatils[i].activity_id delete order.fulfillmentDeatils[i].activity_type delete order.fulfillmentDeatils[i].fullfillment_Activity delete order.fulfillmentDeatils[i].resonsible_Party delete order.fulfillmentDeatils[i].editable } const orderId = order.orderId; eCommerceServices.updateOrderConfiguration(orderId, { "fulfillmentDeatils": order.fulfillmentDeatils }).then( function (response) { $rootScope.spinerisActive = false; if (response.data && response.code === 200) { if (!detectmob()) { $rootScope.showSuccessMessage('Updated', 'Configuration Updated Successfully', 4000); } else { var title = "Updated"; var icon = "done"; var expires = "4000"; var message = "Configuration Updated Successfully"; $rootScope.showAlertBox(message, title, icon, expires); } } }, function (err) { $rootScope.spinerisActive = false; console.log("Unable to Update Order Configuration"); if (!detectmob()) { $rootScope.showErrorMessage('Something went wrong', 'Please try after some time', 2500); } else { var title = "Something went wrong"; var icon = "warning"; var expires = "2500"; var message = "Please try after some time"; $rootScope.showAlertBox(message, title, icon, expires); } } ); } $scope.getStateMessage = function (order) { if (order.stateInfo.currentState == 'ORD_RECEIVED') { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.stateInfo.actor) { return $scope.getStateMessageFullview('ORD_RECEIVED'); } else { return $scope.getStateMessageFullview('ORD_SCF'); } } else if (order.stateInfo.currentState == 'ORD_INP') { return $scope.getStateMessageFullview('ORD_INP'); } else if (order.stateInfo.currentState == 'QC_WAITING') { return $scope.getStateMessageFullview('QC_WAITING'); } else if (order.stateInfo.currentState == 'QC_INP') { return $scope.getStateMessageFullview('QC_INP'); } else if (order.stateInfo.currentState == 'PKG_WAITING') { return $scope.getStateMessageFullview('PKG_WAITING'); } else if (order.stateInfo.currentState == 'PKG_INP') { return $scope.getStateMessageFullview('PKG_INP'); } else if (order.stateInfo.currentState == 'TR_WAITING') { return $scope.getStateMessageFullview('TR_WAITING'); } else if (order.stateInfo.currentState == 'TR_INP') { return $scope.getStateMessageFullview('TR_INP'); } else if (order.stateInfo.currentState == 'ORD_DELIVERED') { return $scope.getStateMessageFullview('ORD_DELIVERED'); } else if (order.stateInfo.currentState == 'FMT_REJECTIONS') { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.buyerId) { return $scope.getStateMessageFullview('ORD_SCF'); } else { return $scope.getStateMessageFullview(order.stateInfo.previousState + '_FMT_REJECTIONS'); } } else if (order.stateInfo.currentState == 'QC_FAILURES') { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.buyerId) { return $scope.getStateMessageFullview(order.stateInfo.previousState); } else { return $scope.getStateMessageFullview(order.stateInfo.currentState); } } else if (order.stateInfo.currentState == 'TIME_OUT') { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.buyerId) { if (order.stateInfo.previousState === 'ORD_RECEIVED') return $scope.getStateMessageFullview('ORD_SCF'); else { return $scope.getStateMessageFullview(order.stateInfo.previousState); } } else { return $scope.getStateMessageFullview(order.stateInfo.previousState + '_TIME_OUT'); } } else if (order.stateInfo.currentState == 'REFUND_INPROGRESS') { return $scope.getStateMessageFullview('REFUND_INPROGRESS'); } else if (order.stateInfo.currentState == 'CLOSED') { return $scope.getStateMessageFullview('CLOSED'); } else if (order.stateInfo.currentState == 'CANCEL_REQUESTED') { if ($rootScope.loggedInUserBusinessProfile.profileKey == order.buyerId) { return $scope.getStateMessageFullview('CANCEL_REQUESTED_BUYER'); } else { return $scope.getStateMessageFullview('CANCEL_REQUESTED'); } } } $scope.guidelines = []; $scope.getProductGuidelines = function (productList) { var guideLine = {}; for (var i = 0; i < productList.length; i++) { eCommerceServices.getProductGuidelines(productList[i].productLevel1Id, productList[i].productLevel2Id).then( function (response) { if (response.code === 200 && response.data) { var data = JSON.parse(response.data); guideLine.productName = data.productLevel1Title; guideLine.precautions = data.precautions; guideLine.packagingDetails = data.packagingDetails; guideLine.qualityCheck = data.qualityCheck; $scope.guidelines.push(guideLine); } }, function (err) { console.log("Unable to fetch Guidelines"); } ); } return $scope.guidelines; } $scope.sortActionLabel = function (action) { if (action) { const actionKeys = Object.keys(action); var actionsInSortedOrder = [ 'ord_ACCEPT', 'qc_ACCEPT', 'pkg_ACCEPT', 'tr_ACCEPT', 'pkg_DONE', 'pkg_DONE_ACCEPT_TR', 'ord_READY', 'ord_READY_ACCEPT_QC', 'qc_PASS', 'qc_PASS_ACCEPT_PKG', 'tr_DELIVER', 'tr_FAIL_TO_DELIVER', 'initiate_Refund', 'refunded', 'fmt_revertState', 'qcFail_revertState', 'timeout_revertState', 'ord_UPDATE', 'qc_UPDATE', 'pkg_UPDATE', 'tr_UPDATE', 'cancel_UPDATE', 'fmt_UPDATE', 'qcFail_UPDATE', 'timeout_UPDATE', 'refund_UPDATE', 'ord_REJECT', 'qc_REJECT', 'pkg_REJECT', 'tr_REJECT', 'qc_FAIL', 'pkg_FAIL', 'kForce_Timeout', 'cancel_order', 'cancel_revertState', ]; const orderActionTitle = { "ord_ACCEPT": "Accept", "qc_ACCEPT": "Accept", "pkg_ACCEPT": "Accept", "tr_ACCEPT": "Accept", "pkg_DONE": "Packaging done", "pkg_DONE_ACCEPT_TR": "Packaging done", "ord_READY": "Ready", "ord_READY_ACCEPT_QC": "Ready", "qc_PASS": "Pass", "qc_PASS_ACCEPT_PKG": "Pass", "tr_DELIVER": "Deliver", "tr_FAIL_TO_DELIVER": "Deliver", "initiate_Refund": "Refund", "refunded": "Refund", "fmt_revertState": "Update", "qcFail_revertState": "Update", "timeout_revertState": "Update", "ord_UPDATE": "Update", "qc_UPDATE": "Update", "pkg_UPDATE": "Update", "tr_UPDATE": "Update", "cancel_UPDATE": "Update", "fmt_UPDATE": "Update", "qcFail_UPDATE": "Update", "timeout_UPDATE": "Update", "refund_UPDATE": "Update", "ord_REJECT": "Reject", "qc_REJECT": "Reject", "pkg_REJECT": "Reject", "tr_REJECT": "Reject", "qc_FAIL": "Fail", "pkg_FAIL": "Fail", "kForce_Timeout": "Timeout", "cancel_order": "Cancel Order", "cancel_revertState": "Cancel Order", }; const actions = actionsInSortedOrder.filter(function (e) { var actionToReturn = ''; actionKeys.forEach(function (orderAction) { if (e === orderAction) { actionToReturn = e; } }); if (actionToReturn.length > 0) return actionToReturn; }); const actionsTitles = actions.map(function (e) { return { action: e, value: orderActionTitle[e] }; }); return actionsTitles; console.log(actionsTitles); } } $scope.init(); }]);