angular.module('kalgudiApp.farmer').factory('farmerStreamInboxFactory', ["mybusinessMessageService","$filter","$rootScope","$q","mybusinessdataFactory","myconnectsdataFactory","mycontentService","mybusinessSalesService","profileService","farmerService","loadingS3UrlFactory","loadingS3UrlServices","opportunityInboxFactory","myaccountsInboxFactory","myconnectslistFactory", function(mybusinessMessageService,$filter,$rootScope,$q,mybusinessdataFactory,myconnectsdataFactory,mycontentService,mybusinessSalesService,profileService,farmerService,loadingS3UrlFactory,loadingS3UrlServices,opportunityInboxFactory,myaccountsInboxFactory, myconnectslistFactory) { var farmerInboxFactoryObject = {}; var fullBlownMessages = {}; farmerInboxFactoryObject.updateReadStatus = function(selectedMsg,index){ var isreadrequestarray = []; var seller = ""; var buyer = ""; var broker = ""; var farmer = ""; var msgToRead = ""; var customer = ""; msgToRead = selectedMsg; var isreadrequest = { "userOperationType" :"read", "keyPatternId" : msgToRead._inboxId, "sellerFirstName":"", "buyerFirstName":"", "brokerFirstName":"", "farmerFirstName":"", "sellerBizName":"", "buyerBizName":"", "brokerBizName":"", "farmerBizName":"", "customerFirstName":"", "customerBizName":"", "warehouseFirstName":"", "warehouseBizName":"" }; if(msgToRead.transactionType.toLowerCase() == 'sale'){ buyer = msgToRead.buyerBusinessName; isreadrequest.sellerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; isreadrequest.sellerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; isreadrequest.buyerFirstName = buyer.firstName; isreadrequest.buyerBizName = buyer.businessName; } else if(msgToRead.transactionType.toLowerCase() == 'purchase'){ seller = msgToRead.sellerBusinessName; isreadrequest.sellerFirstName = seller.firstName; isreadrequest.sellerBizName = seller.businessName; isreadrequest.buyerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; isreadrequest.buyerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; } else if(msgToRead.transactionType.toLowerCase() == 'inward' || msgToRead.transactionType.toLowerCase() == 'outward'){ customer = msgToRead.customerBusinessName; isreadrequest.customerFirstName = customer.firstName; isreadrequest.customerBizName = customer.businessName; isreadrequest.warehouseFirstName = msgToRead.BusinessCreatedBy.firstName; isreadrequest.warehouseBizName = msgToRead.BusinessCreatedBy.businessName; } isreadrequestarray.push(isreadrequest); farmerService.updateTransaction(isreadrequestarray).then(function(responseData){ if(responseData.code == 201){ var localstorage = JSON.parse(window.localStorage["FARMER"]); var inbox_localstorage = localstorage.Inbox; if(inbox_localstorage[index]!=undefined){ inbox_localstorage[index]._isRead = 1; localstorage.Inbox = inbox_localstorage; checkLocalStorage("FARMER",localstorage); //window.localStorage["BUSINESS"] = JSON.stringify(localstorage); } if($rootScope.totalUnreadCounts.myBizInboxUnRead > 0){ $rootScope.totalUnreadCounts.myBizInboxUnRead--; } } }); }; farmerInboxFactoryObject.acceptTransaction = function(businessMsg) { var deferred = $q.defer(); var msgToAccept = businessMsg; var acceptrequestarray = []; var acceptrequest = { "userOperationType" :"ACCEPT", "keyPatternId" : "", "docKeys":[], "sellerFirstName":"", "buyerFirstName":"", "brokerFirstName":"", "farmerFirstName":"", "sellerBizName":"", "buyerBizName":"", "brokerBizName":"", "farmerBizName":"", "internationalDocsToShare":"", "brokerLocationId":msgToAccept.brokerLocationId, "internationalDocs": "" , "customerFirstName":"", "customerBizName":"", "warehouseFirstName":"", "warehouseBizName":"", "consignerFirstName":"", "consignerBizName":"", "consigneeFirstName":"", "consigneeBizName":"", } if(msgToAccept._inboxId != undefined){ acceptrequest.keyPatternId = msgToAccept._inboxId; } else { acceptrequest.keyPatternId = msgToAccept.keyPatternId; } var seller = ""; var buyer = ""; var broker = ""; var farmer = ""; var customer = ""; if(msgToAccept.transactionType.toLowerCase() == 'sale'){ buyer = msgToAccept.buyerBusinessName; acceptrequest.sellerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; acceptrequest.sellerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; acceptrequest.buyerFirstName = buyer.firstName; acceptrequest.buyerBizName = buyer.businessName; } else if(msgToAccept.transactionType.toLowerCase() == 'purchase'){ seller = msgToAccept.sellerBusinessName; acceptrequest.sellerFirstName = seller.firstName; acceptrequest.sellerBizName = seller.businessName; acceptrequest.buyerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; acceptrequest.buyerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; } else if(msgToAccept.transactionType.toLowerCase() == 'inward' || msgToAccept.transactionType.toLowerCase() == 'outward'){ customer = msgToAccept.customerBusinessName; acceptrequest.customerFirstName = customer.firstName; acceptrequest.customerBizName = customer.businessName; acceptrequest.warehouseFirstName = msgToAccept.BusinessCreatedBy.firstName; acceptrequest.warehouseBizName = msgToAccept.BusinessCreatedBy.businessName; } else if(msgToAccept.transactionType.toLowerCase() == "transportation"){ acceptrequest.consignerFirstName = msgToAccept.consignerBusinessName.firstName; acceptrequest.consignerBizName = msgToAccept.consignerBusinessName.businessName; acceptrequest.consigneeFirstName = msgToAccept.consigneeBusinessName.firstName; acceptrequest.consigneeBizName =msgToAccept.consigneeBusinessName.businessName; } acceptrequestarray.push(acceptrequest); // if product id is not there in profile call update product service if(msgToAccept.transactionType.toLowerCase() != "transportation"){ var newStock = []; var products = {}; var productArray = []; var productList = msgToAccept.productList; for(index in productList){ var selectedproductId = productList[index].productId; var listOfProducts = _.find($rootScope.loggedInUserCurrentBussinessInfo.lstOfProducts,function(rw){ return rw.productId == selectedproductId; }); productArray[index] = { "productId":productList[index].productId, "productName":productList[index].productName, "baseUnitId" :productList[index].baseUnitId, "baseUnitName":productList[index].baseUnitName } } products = { "lstOfProducts" : productArray } if(listOfProducts == undefined ) { newStock[index] = 0; profileService.addNewProductsBiz(products,$rootScope.loggedInUserBusinessProfile.profileKey,$rootScope.loggedInUserCurrentBussinessInfo.businessKey).then(function(result) { if(result.code == 201) { //$rootScope.showCommonTopInfoAlert($scope.TaLiterals.searchByKey('KL_TR_0171')); } }); }; } farmerService.acceptTransaction(acceptrequestarray).then(function(responseData){ deferred.resolve(responseData); }); return deferred.promise; } farmerInboxFactoryObject.rejectTransaction = function(businessMsg) { var msgToReject = businessMsg; var rejectrequestarray = []; var rejectrequest = { "userOperationType" :"reject", "keyPatternId" : "", "sellerFirstName":"", "buyerFirstName":"", "brokerFirstName":"", "farmerFirstName":"", "sellerBizName":"", "buyerBizName":"", "brokerBizName":"", "farmerBizName":"", "customerFirstName":"", "customerBizName":"", "warehouseFirstName":"", "warehouseBizName":"", "consignerFirstName":"", "consignerBizName":"", "consigneeFirstName":"", "consigneeBizName":"", } if(msgToReject._inboxId != undefined){ rejectrequest.keyPatternId = msgToReject._inboxId; } else{ rejectrequest.keyPatternId = msgToReject.keyPatternId; } var seller = ""; var buyer = ""; var broker = ""; var farmer = ""; if(msgToReject.transactionType.toLowerCase() == 'sale'){ buyer = msgToReject.buyerBusinessName; rejectrequest.sellerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; rejectrequest.sellerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; rejectrequest.buyerFirstName = buyer.firstName; rejectrequest.buyerBizName = buyer.businessName; } else if(msgToReject.transactionType.toLowerCase() == 'purchase'){ seller = msgToReject.sellerBusinessName; rejectrequest.sellerFirstName = seller.firstName; rejectrequest.sellerBizName = seller.businessName; rejectrequest.buyerFirstName = $rootScope.loggedInUserBusinessProfile.firstName; rejectrequest.buyerBizName = $rootScope.loggedInUserCurrentBussinessInfo.businessName; } else if(msgToReject.transactionType.toLowerCase() == 'inward' || msgToReject.transactionType.toLowerCase() == 'outward'){ customer = msgToReject.customerBusinessName; rejectrequest.customerFirstName = customer.firstName; rejectrequest.customerBizName = customer.businessName; rejectrequest.warehouseFirstName = msgToReject.BusinessCreatedBy.firstName; rejectrequest.warehouseBizName = msgToReject.BusinessCreatedBy.businessName; } else if(msgToReject.transactionType.toLowerCase() == "transportation"){ rejectrequest.consignerFirstName = msgToReject.consignerBusinessName.firstName; rejectrequest.consignerBizName = msgToReject.consignerBusinessName.businessName; rejectrequest.consigneeFirstName = msgToReject.consigneeBusinessName.firstName; rejectrequest.consigneeBizName =msgToReject.consigneeBusinessName.businessName; } rejectrequestarray.push(rejectrequest); var deferred = $q.defer(); farmerService.updateTransaction(rejectrequestarray).then(function(responseData){ deferred.resolve(responseData); }); return deferred.promise; } farmerInboxFactoryObject.snapshot_message_processing=function(snapshot_message) { if(snapshot_message!= undefined){ var brokerBusinessData = ""; var buyerBusinessData = ""; var sellerBusinessData = ""; var createdByBusinessData = ""; if(snapshot_message.brokerBizId != '' && snapshot_message.brokerBizId != undefined){ if(snapshot_message.isBrokerThirdPartyUser == 0){ //brokerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.brokerBizId); snapshot_message.brokerBusinessName = { firstName : snapshot_message.brokerFirstName ||'', businessName : snapshot_message.brokerBusinessName ||'', businessId : snapshot_message.brokerBizId }; }else{ /*brokerBusinessData = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.brokerBizId); if(brokerBusinessData == undefined){ snapshot_message.brokerBusinessName = {}; snapshot_message.brokerBusinessName.firstName = snapshot_message.brokerName; snapshot_message.brokerBusinessName.businessName = snapshot_message.brokerBizName; } else{ snapshot_message.brokerBusinessName = brokerBusinessData; }*/ snapshot_message.brokerBusinessName = { firstName : snapshot_message.brokerFirstName ||'', businessName : snapshot_message.brokerBusinessName ||'', businessId : snapshot_message.brokerBizId }; } } if (snapshot_message.transactionType.toLowerCase() == 'sale') { if(snapshot_message.isBuyerThirdPartyUser == 0){ if(snapshot_message.buyerBizId != ""){ /*buyerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.buyerBizId);*/ snapshot_message.buyerBusinessName = { firstName : snapshot_message.buyerFirstName, businessName : snapshot_message.buyerBusinessName || '', businessId : snapshot_message.buyerBizId }; } else{ //buyerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.farmerBizId); snapshot_message.buyerBusinessName = { firstName : snapshot_message.farmerFirstName, businessName : snapshot_message.farmerBusinessName || '', businessId : snapshot_message.farmerBizId }; } }else{ if(snapshot_message.buyerBizId != ""){ //buyerBusinessData = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.buyerBizId); snapshot_message.buyerBusinessName = { firstName : snapshot_message.buyerFirstName, businessName : snapshot_message.buyerBusinessName || '', businessId : snapshot_message.buyerBizId }; } else{ //buyerBusinessData = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.farmerBizId); snapshot_message.buyerBusinessName = { firstName : snapshot_message.farmerFirstName, businessName : snapshot_message.farmerBusinessName || '', businessId : snapshot_message.farmerBizId }; } /* if(buyerBusinessData == undefined){ snapshot_message.buyerBusinessName = {}; snapshot_message.buyerBusinessName.firstName = snapshot_message.partnerName; snapshot_message.buyerBusinessName.businessName = snapshot_message.partnerBusinessName; } else{ snapshot_message.buyerBusinessName = buyerBusinessData; }*/ } snapshot_message.sellerBusinessName = { firstName : $rootScope.loggedInUserBusinessProfile.firstName, businessName : $rootScope.loggedInUserCurrentBussinessInfo.businessName, businessId : $rootScope.loggedInUserCurrentBussinessInfo.businessKey }; } else if (snapshot_message.transactionType.toLowerCase() == 'purchase') { if(snapshot_message.isSellerThirdPartyUser == 0){ if(snapshot_message.sellerBizId != ""){ //sellerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.sellerBizId); snapshot_message.sellerBusinessName = { firstName : snapshot_message.sellerFirstName || '', businessName : snapshot_message.businessName || '', businessId : snapshot_message.sellerBizId || '' }; } else{ //sellerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.farmerBizId); snapshot_message.sellerBusinessName = { firstName : snapshot_message.farmerFirstName, businessName : snapshot_message.farmerBusinessName || '', businessId : snapshot_message.farmerBizId }; } /*snapshot_message.sellerBusinessName = { firstName : sellerBusinessData.firstName, businessName : sellerBusinessData.businessName, businessId : sellerBusinessData.businessId };*/ }else{ if(snapshot_message.sellerBizId != ""){ //sellerBusinessData = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.sellerBizId); snapshot_message.sellerBusinessName = { firstName : snapshot_message.sellerFirstName || '', businessName : snapshot_message.businessName || '', businessId : snapshot_message.sellerBizId || '' }; } else{ snapshot_message.sellerBusinessName = { firstName : snapshot_message.farmerFirstName, businessName : snapshot_message.farmerBusinessName || '', businessId : snapshot_message.farmerBizId }; //sellerBusinessData = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.farmerBizId); } /* if(sellerBusinessData == undefined){ snapshot_message.sellerBusinessName = {}; snapshot_message.sellerBusinessName.firstName = snapshot_message.partnerName; snapshot_message.sellerBusinessName.businessName = snapshot_message.partnerBusinessName; } else{ snapshot_message.sellerBusinessName = sellerBusinessData; }*/ } snapshot_message.buyerBusinessName = { firstName : $rootScope.loggedInUserBusinessProfile.firstName, businessName : $rootScope.loggedInUserCurrentBussinessInfo.businessName, businessId : $rootScope.loggedInUserCurrentBussinessInfo.businessKey }; } if(snapshot_message.isIncoming == 1){ //createdByBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.createdBy); snapshot_message.BusinessCreatedBy = { firstName : snapshot_message.createdByFirstName || '', businessName : snapshot_message.createdByBizName || '', businessId : snapshot_message.createdBy || '', profilePicURL : snapshot_message.createdByPicURL || '' }; if(snapshot_message.transactionType.toLowerCase() == "transportation"){ snapshot_message.BusinessCreatedBy = { firstName : snapshot_message.transporterFirstName || '', businessName : snapshot_message.transporterBizName || '', businessId : snapshot_message.createdBy || '', profilePicURL : snapshot_message.createdByPicURL || '' }; }; } else{ snapshot_message.BusinessCreatedBy = { firstName : $rootScope.loggedInUserBusinessProfile.firstName, businessName : $rootScope.loggedInUserCurrentBussinessInfo.businessName, businessId : $rootScope.loggedInUserCurrentBussinessInfo.businessKey }; if($rootScope.loggedInUserBusinessProfile.profilePicUrl != undefined){ snapshot_message.BusinessCreatedBy.profilePicURL = $rootScope.loggedInUserBusinessProfile.profilePicUrl; } } var filesArrayMain = []; if(snapshot_message.hasOwnProperty("fileNames")){ if(snapshot_message.fileNames!="") { var totalfileNames = snapshot_message.fileNames.split(','); for(var index in totalfileNames){ if(totalfileNames[index]!=""){ var splitNames = totalfileNames[index].split('/'); var filekeyTemp = totalfileNames[index]; filesArrayMain.push({ "text": splitNames[1] }); } snapshot_message.MainFiles = filesArrayMain; } } } if(snapshot_message.hasOwnProperty("commentList")){ var commentList = snapshot_message.commentList; var len = commentList.length; var CommentfilesArray = []; var loginDetails = $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0]; for(var index in commentList){ var modifiedName = commentList[index].modifiedBy; var commentedName = myconnectsdataFactory.getConnetcs_VisitorsProfile(modifiedName); if(commentedName == undefined){ commentedName = mybusinessdataFactory.getAllconnectsListWithBizId(modifiedName); } if(modifiedName == loginDetails.businessKey){ snapshot_message.commenterName = $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].firstName; snapshot_message.commentimagesDisplayUrl = $rootScope.loggedInUserBusinessProfile.profilePicUrl; }else{ snapshot_message.commenterName = (commentedName?commentedName.businessName:'')||''; snapshot_message.commentimagesDisplayUrl =(commentedName?commentedName.profilePicURL:'')||''; } snapshot_message.commentDate = $filter('datefilter')(commentList[commentList.length-1].modifiedDate); } snapshot_message.commentBox = false; snapshot_message.modifiedDateFilter = $filter('contentdatefilter')(snapshot_message._modifiedTS); if(snapshot_message.totalTxAmount){ snapshot_message.customTotalTxAmt = $filter('number')(snapshot_message.totalTxAmount, 2).toString().replace(/,/g,''); } //snapshot_message.customEntrydate = $filter('date')(snapshot_message.entryDate, 'dd MMM yy' ); snapshot_message.customEntrydate = snapshot_message.entryDate; } //litearls processing var literal_template = ''; if(snapshot_message.transactionType.toLowerCase() == 'sale'){ if(snapshot_message.isIncoming==0){ //created by us if(snapshot_message.brokerBizId != ''){ //sale with broker if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0609; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0610; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.buyerBusinessName.firstName, biz_dyn:snapshot_message.buyerBusinessName.businessName, caname_dyn:snapshot_message.brokerBusinessName.firstName, caibzname_dyn:snapshot_message.brokerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|caname_dyn|caibzname_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ //sale without broker if((snapshot_message.buyerBizId =="" || snapshot_message.buyerBizId== undefined) && $rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessTypeId == "BT000010"){ var literalstr = "Procured amt_dyn unit_dyn of product_dyn "; var mapObj = { amt_dyn: snapshot_message.procurementDetails.totalQuantity, unit_dyn:snapshot_message.procurementDetails.units.unitName, product_dyn:snapshot_message.procurementDetails.product.productName }; literalstr = literalstr.replace(/amt_dyn|unit_dyn|product_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0605; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0606; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.totalTxAmount, name_dyn:snapshot_message.buyerBusinessName.firstName, biz_dyn:snapshot_message.buyerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } } else if(snapshot_message.isIncoming==1){ if(snapshot_message.partnerBusinessTypeId=="BT000009"){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0684; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0685; } var literalstr = literal_template; var mapObj = { product_dyn:snapshot_message.productList[0].productName, biz_dyn:snapshot_message.sellerBusinessName.businessName, biztype_dyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|biz_dyn|biztype_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ if(snapshot_message.brokerBizId == snapshot_message.createdBy){ if(snapshot_message.hasOwnProperty('partnerBusinessTypeId') && snapshot_message.partnerBusinessTypeId == "BT000013"){ if(snapshot_message.hasOwnProperty('type') && snapshot_message.type == 'SERVICES'){ if(snapshot_message.totalTxAmount != '' && snapshot_message.totalTxAmount != 0){ var literalstr = $rootScope.loginpinliteral.KL_TR_0686; var mapObj = { currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } else{ var literalstr = $rootScope.loginpinliteral.KL_TR_0687; var mapObj = { buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } } else if(snapshot_message.hasOwnProperty('type') && snapshot_message.type == 'DIGITAL'){ var literalstr = $rootScope.loginpinliteral.KL_TR_0688; var mapObj = { currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|buyer_dyn|buyer_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } else{ if(snapshot_message.totalTxAmount != '' && snapshot_message.totalTxAmount != 0){ var literalstr = $rootScope.loginpinliteral.KL_TR_0689; var mapObj = { currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } else{ var literalstr = $rootScope.loginpinliteral.KL_TR_0690; var mapObj = { buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } } snapshot_message.Businesstemplates = literalstr; } else{ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0613; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0614; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } else{ //created by opposition if(snapshot_message.brokerBizId != ''){ //sale with broker internally it is purchase if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0611; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0612; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, caname_dyn:snapshot_message.brokerBusinessName.firstName, caibzname_dyn:snapshot_message.brokerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|caname_dyn|caibzname_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ //sale without broker if(snapshot_message.partnerBusinessTypeId == 'BT000010' && snapshot_message.farmerBizId != '' && snapshot_message.buyerBizId != ''){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0605; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0606; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.buyerBusinessName.firstName, biz_dyn:snapshot_message.buyerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0607; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0608; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } } } } } else if(snapshot_message.transactionType.toLowerCase() == 'purchase' || snapshot_message.transactionType.toLowerCase() == 'farmerpurchase'){ if(snapshot_message.isIncoming==0){ //created by us if(snapshot_message.brokerBizId != ''){ //purchase with broker if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0611; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0612; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.sellerBusinessName.firstName, biz_dyn:snapshot_message.sellerBusinessName.businessName, caname_dyn:snapshot_message.brokerBusinessName.firstName, caibzname_dyn:snapshot_message.brokerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|caname_dyn|caibzname_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ //purchase without broker if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0607; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0608; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.sellerBusinessName.firstName, biz_dyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } else if(snapshot_message.isIncoming==1){ if(snapshot_message.partnerBusinessTypeId=="BT000009"){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0682; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0683; } var literalstr = literal_template; var mapObj = { product_dyn:snapshot_message.productList[0].productName, biz_dyn:snapshot_message.buyerBusinessName.businessName, biztype_dyn:snapshot_message.buyerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|biz_dyn|biztype_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ if(snapshot_message.isStockTransfer && snapshot_message.isStockTransfer==1){ var literalstr = $rootScope.loginpinliteral.KL_TR_0686; var mapObj = { currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = "Created processing service with "+snapshot_message.buyerBusinessName.firstName+","+snapshot_message.buyerBusinessName.businessName; snapshot_message.Businesstemplates = literalstr; } else if(snapshot_message.brokerBizId == snapshot_message.createdBy){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0613; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0614; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, buyer_dyn:snapshot_message.buyerBusinessName.firstName, buyer_biznamedyn:snapshot_message.buyerBusinessName.businessName, seller_dyn:snapshot_message.sellerBusinessName.firstName, seller_biznamedyn:snapshot_message.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ //created by opposition if(snapshot_message.brokerBizId != ''){ //purchase with broker if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0609; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0610; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, caname_dyn:snapshot_message.brokerBusinessName.firstName, caibzname_dyn:snapshot_message.brokerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn|caname_dyn|caibzname_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ //purchase without broker if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0605; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0606; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.totalTxAmount, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } } } } else if (snapshot_message.transactionType.toLowerCase() == 'inward' || snapshot_message.transactionType.toLowerCase() == 'outward') { var customerBusinessData = ""; customerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.customerBizId); snapshot_message.customerBusinessName = { firstName : customerBusinessData.firstName, businessName : customerBusinessData.businessName, businessId : customerBusinessData.businessId }; if(snapshot_message.partnerBusinessTypeId == "BT000007"){ if(snapshot_message.transactionType.toLowerCase() == 'inward'){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0676; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0677; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else if(snapshot_message.transactionType.toLowerCase() == 'outward'){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0674; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0675; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } else{ if(snapshot_message.transactionType.toLowerCase() == 'inward'){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0654; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0655; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else if(snapshot_message.transactionType.toLowerCase() == 'outward'){ if(snapshot_message.godowncharges.godownCharges != 0){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0650; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0651; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.customTotalTxAmt, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else if(snapshot_message.godowncharges.godownCharges == 0){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0652; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0653; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); literalstr="Provided storage service to "+snapshot_message.customerBusinessName.firstName+","+snapshot_message.customerBusinessName.businessName; snapshot_message.Businesstemplates = literalstr; } } } } else if(snapshot_message.transactionType.toLowerCase() == "transportation"){ var consigneeBusinessName={}; consignerBusinessName = {}; if(snapshot_message.consigneeBizId != ""){ if(snapshot_message.isConsigneeThirdPartyUser == 0){ consigneeBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.consigneeBizId); snapshot_message.consigneeBusinessName = { firstName : snapshot_message.consigneeFirstName, businessName : snapshot_message.consigneeBizName, businessId : snapshot_message.consigneeBizId }; } else{ consigneeBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.consigneeBizId); snapshot_message.consigneeBusinessName = { firstName : snapshot_message.consigneeFirstName, businessName : snapshot_message.consigneeBizName, businessId : snapshot_message.consigneeBizId }; } } if(snapshot_message.consignerBizId != ""){ if(snapshot_message.isConsignerThirdPartyUser == 0){ //consignerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(snapshot_message.consignerBizId); snapshot_message.consignerBusinessName = { firstName : snapshot_message.consignerFirstName, businessName : snapshot_message.consignerBizName, businessId : snapshot_message.consignerBizId }; } else{ //consignerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(snapshot_message.consignerBizId); snapshot_message.consignerBusinessName = { firstName : snapshot_message.consignerFirstName, businessName : snapshot_message.consignerBizName, businessId : snapshot_message.consignerBizId }; } } var literal_template = $rootScope.loginpinliteral.KL_TR_0636; var literalstr = literal_template; var mapObj = { //product_dyn:Object.keys(snapshot_message.productList).length, currency_dyn:snapshot_message.currencyList[0].currencyCode, amt_dyn: snapshot_message.totalTxAmount.toFixed(2), consignee_dyn:snapshot_message.consigneeBusinessName.firstName, consigneebiz_dyn:snapshot_message.consigneeBusinessName.businessName, consigner_dyn:snapshot_message.consignerBusinessName.firstName, consignerbiz_dyn:snapshot_message.consignerBusinessName.businessName }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|consignee_dyn|consigneebiz_dyn|consigner_dyn|consignerbiz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else if(snapshot_message.transactionType.toLowerCase() == 'createpool'){ if(snapshot_message.isIncoming==1){ if(snapshot_message.poolinfo.qualifiers != '' && snapshot_message.poolinfo.qualifiers != undefined){ var literalstr = "Created a pool by pooltile_dyn with quantity_dyn unit_dyn qualifier_dyn product_dyn"; var mapObj = { quantity_dyn:snapshot_message.poolinfo.poolmembersinfo[0].quantity, unit_dyn: snapshot_message.poolinfo.unit.unitName, qualifier_dyn:snapshot_message.poolinfo.qualifiers, product_dyn:snapshot_message.poolinfo.poolproductname, pooltile_dyn:snapshot_message.poolinfo.pooltitle, }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|qualifier_dyn|product_dyn|pooltile_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ var literalstr = $rootScope.loginpinliteral.KL_TR_0673; var mapObj = { quantity_dyn:snapshot_message.poolinfo.poolmembersinfo[0].quantity, unit_dyn: snapshot_message.poolinfo.unit.unitName, product_dyn:snapshot_message.poolinfo.poolproductname, pooltile_dyn:snapshot_message.poolinfo.pooltitle, }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|product_dyn|pooltile_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } } else if(snapshot_message.transactionType.toLowerCase() == "stockinward"){ if(snapshot_message.qualifier != '' && snapshot_message.qualifier != undefined){ var literal_template = "Created an stock entry for quantity_dyn unit_dyn tag_dyn product_dyn from farmer_dyn"; var literalstr = literal_template; var mapObj = { quantity_dyn:snapshot_message.totalQuantity, unit_dyn:snapshot_message.unitName, tag_dyn:snapshot_message.qualifier, product_dyn:snapshot_message.productName, farmer_dyn:snapshot_message.farmerFirstName }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|tag_dyn|product_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ var literal_template = "Created an stock entry for quantity_dyn unit_dyn product_dyn from farmer_dyn"; var literalstr = literal_template; var mapObj = { quantity_dyn:snapshot_message.totalQuantity, unit_dyn:snapshot_message.unitName, product_dyn:snapshot_message.productName, farmer_dyn:snapshot_message.farmerFirstName }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|product_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } else if(snapshot_message.transactionType.toLowerCase() == 'processing'){ var customerBusinessData = ""; customerBusinessData = getConnetcs_VisitorsProfile(snapshot_message.customerBizId); snapshot_message.customerBusinessName = { firstName : customerBusinessData.firstName, businessName : customerBusinessData.businessName, businessId : customerBusinessData.businessId }; if(snapshot_message.serviceType != undefined && snapshot_message.serviceType.toLowerCase() == 'own'){ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0680; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0681; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, }; literalstr = literalstr.replace(/product_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } else{ if(Object.keys(snapshot_message.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0678; } else if(Object.keys(snapshot_message.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0679; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(snapshot_message.productList).length, name_dyn:snapshot_message.customerBusinessName.firstName, biz_dyn:snapshot_message.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); snapshot_message.Businesstemplates = literalstr; } } //end } return snapshot_message; } farmerInboxFactoryObject.snapshot_fullviewmessage=function(fullviewids){ var deferred = $q.defer(); var fullviewrequest={ "module":"farmerapp", "keys":fullviewids } var localstorage = JSON.parse(window.localStorage["FARMER"]); mycontentService.getSYNC_fullBatchcall(fullviewrequest).then(function(resultfullblow){ for(index in resultfullblow) { var parsedobject=JSON.parse(resultfullblow[index]); localstorage.FullViews[index] = parsedobject; } checkLocalStorage("FARMER",localstorage); //window.localStorage["BUSINESS"] = JSON.stringify(localstorage); deferred.resolve("success"); }); return deferred.promise; } //streams farmerInboxFactoryObject.getStreamInboxMessages = function(){ var deferred = $q.defer(); //console.log("loadingS3UrlFactoryObject.businessNewNotification",loadingS3UrlFactory.businessNewNotification); var businessStream = loadingS3UrlFactory.businessNewNotification; deferred.resolve(businessStream); /*loadingS3UrlFactory.businessNewNotification().then(function(snapshot_message){ console.log("snapshot_message",snapshot_message); if(snapshot_message!= undefined){ for(index in snapshot_message){ farmerInboxFactoryObject.snapshot_message_processing(snapshot_message[index]); } } deferred.resolve(snapshot_message); });*/ return deferred.promise; }; farmerInboxFactoryObject.fetchDataFromUrls =function(urlResponse,whereToAppend){ var deferred = $q.defer(); if(urlResponse.length!=0){ var lengthurls = 0; for(var i in urlResponse){ if(urlResponse[i].hasOwnProperty('url')){ /* call callS3RespectiveUrls() from loadingS3UrlServices if no browser-cache is needed, * callBUsinessS3RespectiveUrls() from loadingS3UrlServices if browser-cache is needed. */ loadingS3UrlServices.callBUsinessS3RespectiveUrls(urlResponse[i].url, parseInt(i)).then(function(urlRespectiveResponse){ var dummyActulaurlResponse=angular.copy(urlResponse[urlRespectiveResponse.index]); if(!(nonContentMessages.indexOf(urlResponse[urlRespectiveResponse.index].event)>-1)){ if(urlResponse[urlRespectiveResponse.index].event == "BUSINESS"){ urlResponse[urlRespectiveResponse.index].data = farmerInboxFactoryObject.snapshot_message_processing(urlRespectiveResponse.data); } if(urlResponse[urlRespectiveResponse.index].moduleKey == "MARKETPLACE" || urlResponse[urlRespectiveResponse.index].moduleKey == "businessrequirement"){ urlResponse[urlRespectiveResponse.index].data = opportunityInboxFactory.processingConnectsData(urlRespectiveResponse.data); } if(urlResponse[urlRespectiveResponse.index].event == "Accounts"){ urlResponse[urlRespectiveResponse.index].data = myaccountsInboxFactory.snapshot_message_processing(urlRespectiveResponse.data); } }else{ urlResponse[urlRespectiveResponse.index].data = urlRespectiveResponse.data; }; urlResponse[urlRespectiveResponse.index].data.latestActivity = dummyActulaurlResponse; lengthurls++; if(whereToAppend!=undefined){ urlResponse[urlRespectiveResponse.index].whereToAppend=whereToAppend; } if(urlResponse[urlRespectiveResponse.index].hasOwnProperty('recommendationsFeed')){ urlResponse[urlRespectiveResponse.index].data.recommendationsFeed=true; } console.log("urlResponse",urlResponse); $rootScope.$broadcast('newbusinessFeedS3Stream',urlResponse[urlRespectiveResponse.index]); if(lengthurls>=urlResponse.length){ deferred.resolve(urlResponse); } }); } else{ lengthurls++; if(lengthurls>=urlResponse.length){ deferred.resolve(urlResponse); } } } }else{ deferred.resolve(urlResponse); } return deferred.promise; }; farmerInboxFactoryObject.storeNotificationResult = []; farmerInboxFactoryObject.storeNext20Urls = []; var nonContentMessages=['Share a Thought','question','answer']; farmerInboxFactoryObject.callForLodingS3Urls =function(notificationsResult,request,loadmore){ var deferred = $q.defer(); if(notificationsResult!=undefined){ farmerInboxFactoryObject.storeNotificationResult=notificationsResult; var notificationArray=angular.copy(notificationsResult); var first20Notification= notificationArray.splice(0,loadmore.limit); farmerInboxFactoryObject.storeNext20Urls = notificationArray; farmerInboxFactoryObject.fetchDataFromUrls(first20Notification).then(function(fetchedurldataresult){ deferred.resolve(fetchedurldataresult); }); }else{ deferred.resolve(notificationsResult); } return deferred.promise; }; farmerInboxFactoryObject.feedNotification =function(feedRequest){ var deferred = $q.defer(); var differenceFinalLIst = _.filter(loadingS3UrlFactory.businessNewNotification, function(o) { return o.isViewed==false}); farmerInboxFactoryObject.fetchDataFromUrls(differenceFinalLIst,'top').then(function(newNotificationResponseData){ deferred.resolve(newNotificationResponseData); }); farmerInboxFactoryObject.callForNewInStoredUrls(feedRequest); farmerInboxFactoryObject.storeNotificationResult=loadingS3UrlFactory.businessNewNotification; return deferred.promise; }; farmerInboxFactoryObject.callForNewInStoredUrls =function(feedRequest){ var storeNotificationsids = _.pluck(farmerInboxFactoryObject.storeNext20Urls,'activityId'); var differenceFinalLIst = _.filter(loadingS3UrlFactory.businessNewNotification, function(o) { return ((storeNotificationsids.indexOf(o.activityId)>-1) && (o.isViewed==false)) }); if(differenceFinalLIst.length>0){ if(feedRequest.offset=0){ feedRequest.offset=20; feedRequest.limit=20; }else{ feedRequest.offset=feedRequest.offset-feedRequest.limit; } farmerInboxFactoryObject.LoadmorecallForLodingS3Urls(feedRequest).then(function(Next20urlResponse){ }); } }; farmerInboxFactoryObject.LoadmorecallForLodingS3Urls =function(requestNext20){ var deferred = $q.defer(); farmerInboxFactoryObject.storeNext20Urls=[]; loadingS3UrlServices.callS3Urls(requestNext20,"business").then(function(Next20urlResponse){ farmerInboxFactoryObject.storeNext20Urls=Next20urlResponse; deferred.resolve(Next20urlResponse); },function(err) { deferred.reject("s3urlError"); }); return deferred.promise; }; return farmerInboxFactoryObject; } ]);