angular.module('kalgudiApp.eCommerce').controller('storeOrdersInboxFullviewController', ['$scope', '$state', '$rootScope', '$injector', '$interval', 'kalgudiLiterals', 'eCommerceServices', 'basicAppMessageService', function ($scope, $state, $rootScope, $injector, $interval, kalgudiLiterals, eCommerceServices, basicAppMessageService) { $scope.orderLiterals = kalgudiLiterals; const orderId = $state.params.id; const defaultTab = $state.params.defaultTab || 0; const ORD_RECEIVED = { title: $scope.orderLiterals.literalsData.NEW_ORD, imgUrl: 'common/images/state-machine/lace.png' } const ORD_CONFIRMED = { title: $scope.orderLiterals.literalsData.ORD_CONFIRMED, imgUrl: 'common/images/state-machine/checked.svg' } const ORD_SCF = { title: $scope.orderLiterals.literalsData.WAITING_FOR_SELLER_CONFIRM, imgUrl: 'common/images/state-machine/exclamation.svg' } const ORD_INP = { title: $scope.orderLiterals.literalsData.ORD_PROGRESS, imgUrl: 'common/images/state-machine/sand-clock.png' } const QC_WAITING = { title: $scope.orderLiterals.literalsData.WAIT_FOR_QC_ACCPET, imgUrl: 'common/images/state-machine/exclamation.svg' } const QC_INP = { title: $scope.orderLiterals.literalsData.QC_IN_PROGRESS, imgUrl: 'common/images/state-machine/sand-clock.png' } const PKG_WAITING = { title: $scope.orderLiterals.literalsData.WAIT_FOR_PACK_ACCEPT, imgUrl: 'common/images/state-machine/exclamation.svg' } const PKG_INP = { title: $scope.orderLiterals.literalsData.PACKING_PROGRESS, imgUrl: 'common/images/state-machine/packingbox.png' } const TR_WAITING = { title: $scope.orderLiterals.literalsData.WAIT_FOR_TRANSPORT_ACCEPT, imgUrl: 'common/images/state-machine/exclamation.svg' } const TR_INP = { title: $scope.orderLiterals.literalsData.IN_TRANSIT, imgUrl: 'common/images/state-machine/transit.png' } const ORD_DELIVERED = { title: $scope.orderLiterals.literalsData.ORD_DELIVERED, imgUrl: 'common/images/state-machine/delivery.png' } $scope.orderImages = { 'ORD_RECEIVED': 'common/images/state-machine/lace.png', 'ORD_INP': 'common/images/state-machine/sand-clock.png', 'QC_WAITING': 'common/images/state-machine/quality.png', 'QC_INP': 'common/images/state-machine/quality.png', 'PKG_WAITING': 'common/images/state-machine/packingbox.png', 'PKG_INP': 'common/images/state-machine/box.png', 'TR_WAITING': 'common/images/state-machine/transit.png', 'TR_INP': 'common/images/state-machine/transit.png', 'ORD_DELIVERED': 'common/images/state-machine/delivery.png', }; $scope.actionMessageLookup = { 'ord_RECEIVED': $scope.orderLiterals.literalsData.WAITING_FOR_SELLER_CONFIRM, 'ord_REJECT': $scope.orderLiterals.literalsData.ORD_REJ, 'ord_ACCEPT': $scope.orderLiterals.literalsData.ORD_ACCEPTED, 'ord_UPDATE': $scope.orderLiterals.literalsData.ORD_ACCEPTED, 'ord_READY': $scope.orderLiterals.literalsData.ORD_READY, 'ord_READY_ACCEPT_QC': 'Order ready and QC accepted', 'qc_ACCEPT': 'Order ready and QC accepted', 'qc_REJECT': 'QC rejected', 'qc_UPDATE': 'Order ready and QC accepted', 'qc_PASS': $scope.orderLiterals.literalsData.QC_PASSED, 'qc_FAIL': $scope.orderLiterals.literalsData.QC_FAILED, 'qc_PASS_ACCEPT_PKG': 'QC Passed and Packing accepted', 'pkg_ACCEPT': 'QC Passed and Packing accepted', 'pkg_REJECT': $scope.orderLiterals.literalsData.PACKING_REJECTED, 'pkg_UPDATE': 'QC Passed and Packing accepted', 'pkg_DONE': $scope.orderLiterals.literalsData.PACKING_DONE, 'pkg_FAIL': $scope.orderLiterals.literalsData.PACK_FAILED, 'pkg_DONE_ACCEPT_TR': 'Packing done and Transport accepted', 'tr_ACCEPT': 'Packing done and Transport accepted', 'tr_REJECT': $scope.orderLiterals.literalsData.TRANSIT_REJECTED, 'tr_UPDATE': 'Packing done and Transport accepted', 'tr_DELIVER': $scope.orderLiterals.literalsData.PACK_DELIVERY, 'tr_FAIL_TO_DELIVER': $scope.orderLiterals.literalsData.FAIL_DELIVER }; $scope.stateMessageLookup = { "ORD_RECEIVED": $scope.orderLiterals.literalsData.ORD_PLACED, "ORD_INP": $scope.orderLiterals.literalsData.ORD_PROGRESS, "QC_WAITING": $scope.orderLiterals.literalsData.QC, "QC_INP": $scope.orderLiterals.literalsData.QC, "PKG_WAITING": $scope.orderLiterals.literalsData.PACKING, "PKG_INP": $scope.orderLiterals.literalsData.PACKING, "TR_WAITING": $scope.orderLiterals.literalsData.BUSINESS_TRANSPORTATION, "TR_INP": $scope.orderLiterals.literalsData.BUSINESS_TRANSPORTATION, "ORD_DELIVERED": $scope.orderLiterals.literalsData.DELIVERED }; $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.rejectedActionsLookup = { "ord_REJECT": true, "qc_REJECT": true, "qc_FAIL": true, "pkg_REJECT": true, "pkg_FAIL": true, "tr_REJECT": true, "tr_FAIL_TO_DELIVER": true, }; $scope.selectedActivityTab = defaultTab; $scope.transactionsTabs = { TRACKING: 0, CHAT: 1, TRANSACTION: 2, LOGS: 3 } $scope.toggleTabs = function (selectedTab) { $scope.selectedActivityTab = selectedTab; } $scope.orderStateDetails = {}; // Flag to distinguish buyer and other actors $scope.isBuyer = false; // Object structure for posting new order update $scope.update = { "message": '', "lstOfAttachments": [], } $scope.init = function () { if (detectmob()) { $ionicModal = $injector.get('$ionicModal'); } else { $uibModal = $injector.get('$uibModal'); } $scope.uploadedData = []; $scope.getOrder(); } /** * Resets order update posting field values. */ $scope.resetUpdateFields = function () { $scope.update.message = ''; $scope.update.lstOfAttachments = []; } $scope.getOrderImage = function (state) { return $scope.orderImages[state]; }; $scope.getTrackingStateImage = function (state, previousAction) { return $scope.trackingOrderImages[state + '_' + previousAction]; } $scope.getActionMessage = function (action) { action = action || 'ord_RECEIVED'; return $scope.actionMessageLookup[action]; } $scope.getStateMessage = function (state) { return $scope.stateMessageLookup[state]; } $scope.getStateMessageFullview = function (state) { return $scope.stateMessageLookupFullview[state]; } $scope.isRejectedAction = function (action) { action = action || 'NONE'; return $scope.rejectedActionsLookup[action]; } /** * Get order details from service. */ $scope.getOrder = function () { //$rootScope.spinerisActive = true; eCommerceServices.getOrder(orderId).then( function (response) { $rootScope.spinerisActive = false; if (response.code === 200 && response.data.length != 0) { var data = JSON.parse(response.data); $scope.orderDetails = data; console.log($scope.orderDetails); if ($scope.checkInAdminList()) { $scope.sortActionLabel($scope.orderDetails.stateInfo.adminActions); } if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.stateInfo.actor) { $scope.sortActionLabel($scope.orderDetails.stateInfo.actions); } if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { $scope.sortActionLabel($scope.orderDetails.stateInfo.buyerActions); } // Check if current user is buyer or not if ($scope.orderDetails && $scope.orderDetails.buyerId) { $scope.isBuyer = $scope.orderDetails.buyerId === $rootScope.loggedInUserBusinessProfile.profileKey; $rootScope.$broadcast('orderDetailsFetched', $scope.isBuyer); } if ($scope.orderDetails.stateInfo.currentState == 'ORD_RECEIVED') { if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_SCF'); } else { $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_RECEIVED'); } } else if ($scope.orderDetails.stateInfo.currentState == 'ORD_INP') { $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_INP'); } else if ($scope.orderDetails.stateInfo.currentState == 'QC_WAITING') { $scope.currentStateStatus = $scope.getStateMessageFullview('QC_WAITING'); } else if ($scope.orderDetails.stateInfo.currentState == 'QC_INP') { $scope.currentStateStatus = $scope.getStateMessageFullview('QC_INP'); } else if ($scope.orderDetails.stateInfo.currentState == 'PKG_WAITING') { $scope.currentStateStatus = $scope.getStateMessageFullview('PKG_WAITING'); } else if ($scope.orderDetails.stateInfo.currentState == 'PKG_INP') { $scope.currentStateStatus = $scope.getStateMessageFullview('PKG_INP'); } else if ($scope.orderDetails.stateInfo.currentState == 'TR_WAITING') { $scope.currentStateStatus = $scope.getStateMessageFullview('TR_WAITING'); } else if ($scope.orderDetails.stateInfo.currentState == 'TR_INP') { $scope.currentStateStatus = $scope.getStateMessageFullview('TR_INP'); } else if ($scope.orderDetails.stateInfo.currentState == 'ORD_DELIVERED') { $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_DELIVERED'); } else if ($scope.orderDetails.stateInfo.currentState == 'FMT_REJECTIONS') { if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_SCF'); } else { $scope.currentStateStatus = $scope.getStateMessageFullview($scope.orderDetails.stateInfo.previousState + '_FMT_REJECTIONS'); } } else if ($scope.orderDetails.stateInfo.currentState == 'QC_FAILURES') { if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { $scope.currentStateStatus = $scope.getStateMessageFullview($scope.orderDetails.stateInfo.previousState); } else { $scope.currentStateStatus = $scope.getStateMessageFullview($scope.orderDetails.stateInfo.currentState); } } else if ($scope.orderDetails.stateInfo.currentState == 'TIME_OUT') { if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { if ($scope.orderDetails.stateInfo.previousState === 'ORD_RECEIVED') $scope.currentStateStatus = $scope.getStateMessageFullview('ORD_SCF'); else { $scope.currentStateStatus = $scope.getStateMessageFullview($scope.orderDetails.stateInfo.previousState); } } else { $scope.currentStateStatus = $scope.getStateMessageFullview($scope.orderDetails.stateInfo.previousState + '_TIME_OUT'); } } else if ($scope.orderDetails.stateInfo.currentState == 'REFUND_INPROGRESS') { $scope.currentStateStatus = $scope.getStateMessageFullview('REFUND_INPROGRESS'); } else if ($scope.orderDetails.stateInfo.currentState == 'CLOSED') { $scope.currentStateStatus = $scope.getStateMessageFullview('CLOSED'); } else if ($scope.orderDetails.stateInfo.currentState == 'CANCEL_REQUESTED') { if ($rootScope.loggedInUserBusinessProfile.profileKey == $scope.orderDetails.buyerId) { $scope.currentStateStatus = $scope.getStateMessageFullview('CANCEL_REQUESTED_BUYER'); } else { $scope.currentStateStatus = $scope.getStateMessageFullview('CANCEL_REQUESTED'); } } console.log($scope.orderDetails.tracking); } }, function (err) { $rootScope.spinerisActive = false; console.log("Unable to get Orders List"); } ); }; $scope.updateOrderStatus = function (statusToUpdate) { delete statusToUpdate['$$hashKey']; var action = Object.keys(statusToUpdate).filter(function (e) { if (e == 'title') { } else { return e; } })[0]; if (/update/i.test(action)) { $scope.selectedActivityTab = $scope.transactionsTabs.TRACKING; } else { $rootScope.spinerisActive = true; eCommerceServices.updateOrder($scope.orderDetails.orderId, action).then( function (response) { $rootScope.spinerisActive = false; if (response.code === 200 || response.code === 201) { $scope.init(); } }, function (err) { console.log("Unable to update the Order"); }); } } /** * Opens image attachment dialog window. The image attachment * dialog window handles image upload to s3 and returns an * object containing attachmentTO. */ $scope.postImage = function () { var obj = { uploadType: 'IMAGE' }; var modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue + 'shared/uploadMultimedia.html', controller: 'uploadMultimediaController', windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return obj; } } }); // uploadedMedia will contain all uploaded objects as an array modalInstance.result.then(function (uploadedMedia) { // Delete name and size coming from image upload dialog for (i in uploadedMedia) { if (uploadedMedia.hasOwnProperty(i)) { if (!uploadedMedia[i].url.includes('http') || uploadedMedia[i].url.includes('https')) { uploadedMedia[i].url = env.secure + uploadedMedia[i].url; } delete uploadedMedia[i].name; delete uploadedMedia[i].size; } } $scope.update.lstOfAttachments = uploadedMedia; $scope.postUpdate(); }); }; /** * Posts an order update to the server. */ $scope.postUpdate = function () { // Validate update posting request $scope.update.message = typeof ($scope.update.message) === 'string' && $scope.update.message.trim().length > 0 ? $scope.update.message : ''; $scope.update.lstOfAttachments = typeof ($scope.update.lstOfAttachments) === 'object' && Array.isArray($scope.update.lstOfAttachments) ? $scope.update.lstOfAttachments : []; // Nothing to update, return from the function. if (!$scope.update.message && $scope.update.lstOfAttachments.length <= 0) { return false; } $rootScope.spinerisActive = true; // Prepare request payload const payload = { "message": $scope.update.message, "lstOfAttachments": $scope.update.lstOfAttachments, }; eCommerceServices.postStatus($scope.orderDetails.orderId, payload).then( function (res) { console.log(res); $rootScope.spinerisActive = false; if (res.code === 200) { try { $scope.orderDetails.tracking = JSON.parse(res.data).tracking; } catch (e) { console.warn('Unable to parse tracking details.', e, res); } } $scope.resetUpdateFields(); }, function (err) { console.error('Unable to post order update.', err); $rootScope.spinerisActive = false; } ); } /** * Opens list of attachments in kalgudi image fullview. * @param {} attachments */ $scope.openImageFullview = function (attachments) { const data = { lstOfAttachments: attachments, }; var modalInstance = $uibModal.open({ templateUrl: 'webapp/themes/html/newsFeed/shareAthoughtFullview.html', controller: 'sharefullviewController', size: 'md', windowClass: 'share-full', resolve: { items: function () { return data; } } }); modalInstance.result.then( function (selectedItem) { }, function () { } ); }; /* * Download the Invoice the Order */ $scope.downloadOrderInvoice = function (orderId, invoiceName, mobileflag) { $rootScope.spinerisActive = true; if (invoiceName) { eCommerceServices.generateReceipts(orderId, invoiceName).then( function (response) { var key = response.data; var splitFile = key.split('/'); var fileToDownload = splitFile[0] + "/" + splitFile[1]; basicAppMessageService.downloadFile(fileToDownload).then(function (result) { $rootScope.spinerisActive = false; var fileName = key.split('/')[1]; var shortName = splitFile[2]; var type = splitFile[3]; $rootScope.spinerisActive = false; if (mobileflag) { if (detectmob()) { showInGallery(result, fileName, shortName, type); } else { var a = document.createElement('a'); a.href = result; a.download = result.filename; a.target = '_blank'; a.click(); } } else { window.open(result); } }); }, function (err) { $rootScope.spinerisActive = false; if (detectmob()) { var title = "Invoice Download"; var icon = "warning"; var expires = "2500"; var message = "Not able to download"; $rootScope.showAlertBox(message, title, icon, expires); } } ) } } $scope.modalInstance; $scope.openGuidelines = 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', // controller: 'uploadMultimediaController', scope: $scope, windowClass: 'app-modal-window', size: 'lg', resolve: { items: function () { return obj; } } }); }; $scope.cancel = function () { $scope.modalInstance.close(); } // Ionic model open for Guide Lines in mobile $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(); }); }; //ionic Model Close $scope.closeGuideline = function () { $scope.adminModal.hide(); } /* * Checks the logged in user is contributor of Kalgudi Support Program */ $scope.checkInAdminList = function (actor, buyer) { const data = JSON.parse(localStorage.getItem('userdata')); if (data.listOfPageDetails) { for (var i = 0; i < data.listOfPageDetails.length; i++) { if ((data.listOfPageDetails[i].pageId === 'O00k4jn1PROCRE2018111425291806UNH001' || data.listOfPageDetails[i].pageId === 'O00000u1PROCRE2018111424408497UNH001') && (data.listOfPageDetails[i].relation === 'CONTRIBUTOR') && (actor !== data.profileKey) && (buyer !== data.profileKey)) { return true; } } } return false; } $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); } }; $scope.getCurrentStateLiteral = function (currentAction) { if (currentAction == 'fmt_revertState' || currentAction == 'cancel_revertState' || currentAction == 'timeout_revertState' || currentAction == 'qcFail_revertState') { return 'Order reverted'; } if (currentAction == 'cancel_order') { return 'Order cancelled'; } if (currentAction == 'initiate_Refund') { return 'Refund initiated'; } if (currentAction == 'refunded') { return 'Amount refunded'; } if (currentAction == 'kForce_Timeout') { return 'Timeout'; } if (currentAction == 'ord_ACCEPT') { return 'Order Accepted'; } if (currentAction == 'qc_ACCEPT') { return 'QC Accepted'; } if (currentAction == 'qc_FAIL') { return 'QC Failed'; } if (currentAction == 'qcFail_revertState') { return 'Order rejected'; } if (currentAction == 'ord_READY') { return 'Order Ready'; } if (currentAction == 'ord_READY_ACCEPT_QC') { return 'Order Ready and Quality Check Accepted'; } if (currentAction == 'qc_REJECT') { return 'QC rejected'; } if (currentAction == 'qc_PASS') { return 'QC passed'; } if (currentAction == 'pkg_REJECT') { return 'Packaging rejected'; } if (currentAction == 'pkg_ACCEPT') { return 'Packaging accepted'; } if (currentAction == 'qc_PASS_ACCEPT_PKG') { return 'Quality Check passed and packaging accepted'; } if (currentAction == 'pkg_DONE') { return 'Packaging completed'; } if (currentAction == 'pkg_DONE_ACCEPT_TR') { return 'Packaging completed and Transit Accepted'; } if (currentAction == 'tr_REJECT') { return 'Transit rejected'; } if (currentAction == 'tr_ACCEPT') { return 'Transit Accepted'; } if (currentAction == 'tr_DELIVER') { return 'Order delivered'; } } $scope.checkSellerForLogsTab = function (productList) { if (productList) { for (var i = 0; i < productList.length; i++) { if (productList[i].sellerId === $rootScope.loggedInUserBusinessProfile.profileKey) { return true; } else { return false; } } } } $scope.finalActions = []; $scope.sortActionLabel = function (action) { if (action) { var accept = { "title": "accept", "ord_ACCEPT": "Accept", "qc_ACCEPT": "Accept", "pkg_ACCEPT": "Accept", "tr_ACCEPT": "Accept", }, reject = { "title": "reject", "ord_REJECT": "Reject", "qc_REJECT": "Reject", "pkg_REJECT": "Reject", "tr_REJECT": "Reject", }, done = { "title": "Packaging done", "pkg_DONE": "Packaging done", "pkg_DONE_ACCEPT_TR": "Packaging done", }, ready = { "title": "Ready", "ord_READY": "Ready", "ord_READY_ACCEPT_QC": "Ready", }, update = { "title": "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" }, pass = { "title": "pass", "qc_PASS": "Pass", "qc_PASS_ACCEPT_PKG": "Pass", }, revert = { "title": "revert", "fmt_revertState": "revert", "qcFail_revertState": "revert", "timeout_revertState": "revert", "cancel_revertState": "revert" }, fail = { "title": "fail", "qc_FAIL": "Fail", "pkg_FAIL": "Fail" }, timeout = { "title": "timeout", "kForce_Timeout": "Timeout" }, deliver = { "title": "deliver", "tr_DELIVER": "Deliver", "tr_FAIL_TO_DELIVER": "Deliver" }, refund = { "title": "refund", "initiate_Refund": "Refund", "refunded": "Refund" }, cancel = { "title": "cancel order", "cancel_order": "Cancel", }; var actionsLookup = [accept, pass, ready, done, deliver, refund, update, revert, fail, cancel, timeout, reject]; var result = []; for (var i in action) { for (var j in actionsLookup) { if (actionsLookup[j][i]) { actionsLookup result.push(j); } else { } } } result = result.sort().map(function (e) { var item = actionsLookup[e]; for (var i in item) { if (action[i]) { item[i] = action[i]; } else if (i == 'title') { } else delete item[i]; } return item; }); console.log(result); $scope.finalActions = result; return true; } } $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; } $interval(callAtInterval, 30000); function callAtInterval() { $scope.getOrder(); console.log("Interval occurred"); } $scope.init(); }]);