angular.module('kalgudiApp.coApp').factory('coAppfullblownFactory', ["$q","$rootScope","mybusinessMessageService","myconnectsdataFactory","mybusinessdataFactory","mycontentService", function($q,$rootScope,mybusinessMessageService,myconnectsdataFactory,mybusinessdataFactory,mycontentService) { var coAppfullblownFactoryObject = {}; coAppfullblownFactoryObject.processingfullblown=function(message_to_process) { // to get names and business names if (message_to_process.brokerBizId != "" && message_to_process.brokerBizId != undefined) { if(message_to_process.isBrokerThirdPartyUser == 0){ //message_to_process.brokerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.brokerBizId); message_to_process.brokerBusinessName ={ firstName : message_to_process.brokerFirstName || '', businessName : message_to_process.brokerBusinessName || '', businessId : message_to_process.brokerBizId || '' } }else{ message_to_process.brokerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.brokerBizId); /*if(message_to_process.brokerBusinessName == undefined){ message_to_process.brokerBusinessName = {}; message_to_process.brokerBusinessName.firstName = message_to_process.brokerName; message_to_process.brokerBusinessName.businessName = message_to_process.brokerBusinessName; }*/ message_to_process.brokerBusinessName ={ firstName : message_to_process.brokerFirstName || '', businessName : message_to_process.brokerBusinessName || '', businessId : message_to_process.brokerBizId || '' } } } if (message_to_process.transactionType.toLowerCase() == "sale") { if(message_to_process.isBuyerThirdPartyUser == 0){ if(message_to_process.buyerBizId != ""){ //message_to_process.buyerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.buyerBizId); message_to_process.buyerBusinessName = { firstName : message_to_process.buyerFirstName ||'', businessName : message_to_process.buyerBizName|| '', businessId : message_to_process.buyerBizId } } else{ //message_to_process.buyerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.farmerBizId); message_to_process.buyerBusinessName = { firstName : message_to_process.farmerFirstName || '', businessName : message_to_process.farmerBusinessName || '', businessId : message_to_process.farmerBizId } } }else{ if(message_to_process.buyerBizId != ""){ message_to_process.buyerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.buyerBizId); if(message_to_process.buyerBusinessName == undefined) { message_to_process.buyerBusinessName = {}; message_to_process.buyerBusinessName.firstName = message_to_process.buyerFirstName; message_to_process.buyerBusinessName.businessName = message_to_process.buyerBizName; } } else{ message_to_process.buyerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.farmerBizId); } if(message_to_process.buyerBusinessName == undefined){ message_to_process.buyerBusinessName = {}; message_to_process.buyerBusinessName.firstName = message_to_process.partnerName; message_to_process.buyerBusinessName.businessName = message_to_process.partnerBusinessName; } } message_to_process.sellerBusinessName = $rootScope.loggedInUserCurrentBussinessInfo; message_to_process.sellerBusinessName.firstName = $rootScope.loggedInUserBusinessProfile.firstName; } else if (message_to_process.transactionType.toLowerCase() == "purchase") { if(message_to_process.isSellerThirdPartyUser == 0){ if(message_to_process.sellerBizId != ""){ //message_to_process.sellerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.sellerBizId); message_to_process.sellerBusinessName = { firstName : message_to_process.sellerFirstName || '', businessName : message_to_process.sellerBizName || '', businessId : message_to_process.sellerBizId || '' } } else{ //message_to_process.sellerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.farmerBizId); message_to_process.sellerBusinessName = { firstName : message_to_process.farmerFirstName || '', businessName : message_to_process.farmerBusinessName || '', businessId : message_to_process.farmerBizId || '' } } }else{ if(message_to_process.sellerBizId != ""){ //message_to_process.sellerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.sellerBizId); message_to_process.sellerBusinessName = { firstName : message_to_process.sellerFirstName || '', businessName : message_to_process.sellerBizName || '', businessId : message_to_process.sellerBizId || '' } } else message_to_process.sellerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.farmerBizId); if(message_to_process.sellerBusinessName == undefined){ message_to_process.sellerBusinessName = {}; message_to_process.sellerBusinessName.firstName = message_to_process.partnerName; message_to_process.sellerBusinessName.businessName = message_to_process.partnerBusinessName; } } message_to_process.buyerBusinessName = $rootScope.loggedInUserCurrentBussinessInfo; message_to_process.buyerBusinessName.firstName = $rootScope.loggedInUserBusinessProfile.firstName; } if(message_to_process.isIncoming == 1){ //message_to_process.BusinessCreatedBy = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.createdBy); message_to_process.BusinessCreatedBy ={ firstName : message_to_process.createdByFirstName || '', businessName : message_to_process.createdByBizName || '', businessId : message_to_process.createdBy || '', profilePicURL : message_to_process.createdByPicURL || '' } } else{ message_to_process.BusinessCreatedBy = $rootScope.loggedInUserCurrentBussinessInfo; message_to_process.BusinessCreatedBy.firstName = $rootScope.loggedInUserBusinessProfile.firstName; if($rootScope.loggedInUserBusinessProfile.profilePicUrl != undefined){ message_to_process.BusinessCreatedBy.profilePicURL = $rootScope.loggedInUserBusinessProfile.profilePicUrl; } } for(var index in message_to_process.commentList) { var commentedName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.commentList[index].modifiedBy); if(commentedName == undefined){ commentedName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.commentList[index].modifiedBy); } if(commentedName.profilePicUrl != undefined){ message_to_process.commentList[index].profilePicUrl = commentedName.profilePicUrl; } } //litearls processing var literal_template = ''; if(message_to_process.transactionType.toLowerCase() == 'sale'){ if(message_to_process.isIncoming==0){ //created by us if(message_to_process.brokerBizId != ''){ //sale with broker if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0609; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0610; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.buyerBusinessName.firstName, biz_dyn:message_to_process.buyerBusinessName.businessName, caname_dyn:message_to_process.brokerBusinessName.firstName, caibzname_dyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } else{ //sale without broker //sale with multiple farmer if((message_to_process.buyerBizId =="" || message_to_process.buyerBizId== undefined) && message_to_process.farmerDistributionDetails && (message_to_process.farmerDistributionDetails.farmersList.length != 0 || message_to_process.farmerDistributionDetails.farmersList != undefined)){ var literalstr = ""; if(message_to_process.farmerDistributionDetails.farmersList.length>1){ literalstr = "Sold qyt_dyn unit_dyn of product_dyn worth currrency_dyn amt_dyn to farmer_dyn farmers"; var mapObj = { qyt_dyn:message_to_process.farmerDistributionDetails.totalQuantity, unit_dyn:message_to_process.productList[0].unitName, product_dyn:message_to_process.productList[0].productName, currrency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: parseFloat(message_to_process.farmerDistributionDetails.totalAmountDisplay).toFixed(2), farmer_dyn:message_to_process.farmerDistributionDetails.farmersList.length }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|product_dyn|currrency_dyn|amt_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); } if(message_to_process.farmerDistributionDetails.farmersList.length==1){ if(message_to_process.productList.length>1){ literalstr = "Sold product_dyn products worth currrency_dyn amt_dyn to farmer_dyn"; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currrency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount, farmer_dyn:message_to_process.farmerDistributionDetails.farmersList[0].firstName }; literalstr = literalstr.replace(/product_dyn|currrency_dyn|amt_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); } else{ literalstr = "Sold product_dyn product worth currrency_dyn amt_dyn to farmer_dyn"; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currrency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount, farmer_dyn:message_to_process.farmerDistributionDetails.farmersList[0].firstName }; literalstr = literalstr.replace(/product_dyn|currrency_dyn|amt_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); } } message_to_process.Businesstemplates = literalstr; } else{ if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a outward entry of qyt_dyn unit_dyn to name_dyn, biz_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:message_to_process.buyerBusinessName.firstName, biz_dyn:message_to_process.buyerBusinessName.businessName }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0605; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0606; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.buyerBusinessName.firstName, biz_dyn:message_to_process.buyerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } } } else if(message_to_process.isIncoming==1){ if(message_to_process.partnerBusinessTypeId=="BT000009"){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0684; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0685; } var literalstr = literal_template; var mapObj = { product_dyn:message_to_process.productList[0].productName, biz_dyn:message_to_process.sellerFirstName, biztype_dyn:message_to_process.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|biz_dyn|biztype_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(message_to_process.brokerBizId == message_to_process.createdBy){ if(message_to_process.hasOwnProperty('partnerBusinessTypeId') && message_to_process.partnerBusinessTypeId == "BT000013"){ if(message_to_process.hasOwnProperty('type') && message_to_process.type == 'SERVICES'){ if(message_to_process.totalTxAmount != '' && message_to_process.totalTxAmount!= 0){ var literalstr = $rootScope.loginpinliteral.KL_TR_0686; var mapObj = { currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), buyer_dyn:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.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:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.sellerBusinessName.businessName }; literalstr = literalstr.replace(/buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } } else if(message_to_process.hasOwnProperty('type') && message_to_process.type == 'DIGITAL'){ var literalstr = $rootScope.loginpinliteral.KL_TR_0688; var mapObj = { currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), buyer_dyn:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|buyer_dyn|buyer_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } else{ if(message_to_process.totalTxAmount != '' && message_to_process.totalTxAmount!= 0){ var literalstr = $rootScope.loginpinliteral.KL_TR_0689; var mapObj = { currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), buyer_dyn:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.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:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.sellerBusinessName.businessName }; literalstr = literalstr.replace(/buyer_dyn|buyer_biznamedyn|seller_dyn|seller_biznamedyn/gi, function(matched){ return mapObj[matched]; }); } } message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0613; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0614; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, buyer_dyn:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } } else{ //created by opposition if(message_to_process.brokerBizId != ''){ //sale with broker internally it is purchase if(Object.keys(message_to_process.productList).length ==1){ literal_template = "Sold product_dyn product worth currency_dyn amt_dyn to name_dyn,biz_dyn"; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = "Sold product_dyn products worth currency_dyn amt_dyn to name_dyn,biz_dyn"; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, caname_dyn:message_to_process.brokerBusinessName.firstName, caibzname_dyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } else{ //sale without broker if(message_to_process.isSubscribertransaction && message_to_process.isSubscribertransaction == 1){ if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a outward entry of qyt_dyn unit_dyn to name_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:message_to_process.buyerFirstName }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.isProcessing && message_to_process.isProcessing == 1){ literal_template = "Sent a product of qyt_dyn unit_dyn to processing"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = "Sold product_dyn product worth currency_dyn amt_dyn to name_dyn"; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = "Sold product_dyn products worth currency_dyn amt_dyn to name_dyn"; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.buyerFirstName || message_to_process.farmerFirstName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } else{ if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a inward entry off qyt_dyn unit_dyn to name_dyn, biz_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.isProcessing && message_to_process.isProcessing == 1){ literal_template = "Sent a product of qyt_dyn unit_dyn to processing"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0607; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0608; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), 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]; }); message_to_process.Businesstemplates = literalstr; } } } } } } } else if(message_to_process.transactionType.toLowerCase() == 'purchase' || message_to_process.transactionType.toLowerCase() == 'farmerpurchase'){ if(message_to_process.isIncoming==0){ //created by us if(message_to_process.brokerBizId != ''){ //purchase with broker if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0611; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0612; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.sellerBusinessName.firstName, biz_dyn:message_to_process.sellerBusinessName.businessName, caname_dyn:message_to_process.brokerBusinessName.firstName, caibzname_dyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } else{ //purchase without broker if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a inward entry of qyt_dyn unit_dyn to name_dyn, biz_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:message_to_process.sellerBusinessName.firstName, biz_dyn:message_to_process.sellerBusinessName.businessName }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0607; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0608; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.sellerBusinessName.firstName, biz_dyn:message_to_process.sellerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } } else if(message_to_process.isIncoming==1){ if(message_to_process.partnerBusinessTypeId=="BT000009"){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0682; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0683; } var literalstr = literal_template; var mapObj = { product_dyn:message_to_process.productList[0].productName, biz_dyn:message_to_process.buyerFirstName, biztype_dyn:message_to_process.buyerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|biz_dyn|biztype_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(message_to_process.brokerBizId == message_to_process.createdBy){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0613; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0614; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, buyer_dyn:message_to_process.buyerBusinessName.firstName, buyer_biznamedyn:message_to_process.buyerBusinessName.businessName, seller_dyn:message_to_process.sellerBusinessName.firstName, seller_biznamedyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } else{ //created by opposition if(message_to_process.brokerBizId != ''){ //purchase with broker if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0609; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0610; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:$rootScope.loggedInUserBusinessProfile.firstName, biz_dyn:$rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo[0].businessName, caname_dyn:message_to_process.brokerBusinessName.firstName, caibzname_dyn:message_to_process.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]; }); message_to_process.Businesstemplates = literalstr; } else{ //purchase without broker if(message_to_process.isSubscribertransaction && message_to_process.isSubscribertransaction == 1){ if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a inward entry of qyt_dyn unit_dyn to name_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:message_to_process.sellerFirstName }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.isProcessing && message_to_process.isProcessing == 1){ literal_template = "Received a product of qyt_dyn unit_dyn from processing"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = "Purchased product_dyn product worth currency_dyn amt_dyn from name_dyn"; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = "Purchased product_dyn products worth currency_dyn amt_dyn from name_dyn"; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.sellerFirstName || message_to_process.farmerFirstName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } else{ if(message_to_process.isStockTransfer && message_to_process.isStockTransfer == 1){ literal_template = "Created a outward entry of qyt_dyn unit_dyn to name_dyn, biz_dyn"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, name_dyn:message_to_process.buyerBusinessName.firstName, biz_dyn:message_to_process.buyerBusinessName.businessName }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.isProcessing && message_to_process.isProcessing == 1){ literal_template = "Received a product of qyt_dyn unit_dyn from processing"; var literalstr = literal_template; var mapObj = { qyt_dyn:message_to_process.productList[0].quantity, unit_dyn:message_to_process.productList[0].unitName, }; literalstr = literalstr.replace(/qyt_dyn|unit_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0605; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0606; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), 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]; }); message_to_process.Businesstemplates = literalstr; } } } } } } } else if (message_to_process.transactionType.toLowerCase() == 'inward' || message_to_process.transactionType.toLowerCase() == 'outward') { var customerBusinessData = ""; customerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.customerBizId); message_to_process.customerBusinessName = { firstName : customerBusinessData.firstName, businessName : customerBusinessData.businessName, businessId : customerBusinessData.businessId }; if(message_to_process.partnerBusinessTypeId == "BT000007"){ if(message_to_process.transactionType.toLowerCase() == 'inward'){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0676; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0677; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.transactionType.toLowerCase() == 'outward'){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0674; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0675; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } else{ if(message_to_process.transactionType.toLowerCase() == 'inward'){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0654; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0655; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.transactionType.toLowerCase() == 'outward'){ if(message_to_process.godowncharges.godownCharges != 0){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0650; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0651; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|currency_dyn|amt_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.godowncharges.godownCharges == 0){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0652; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0653; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } } } else if(message_to_process.transactionType.toLowerCase() == "transportation"){ var consigneeBusinessName={}; consignerBusinessName = {}; if(message_to_process.consigneeBizId != ""){ if(message_to_process.isConsigneeThirdPartyUser == 0){ consigneeBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.consigneeBizId); message_to_process.consigneeBusinessName = { firstName : consigneeBusinessName.firstName, businessName : consigneeBusinessName.businessName, businessId : consigneeBusinessName.businessId }; } else{ consigneeBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.consigneeBizId); message_to_process.consigneeBusinessName = { firstName : consigneeBusinessName.firstName, businessName : consigneeBusinessName.businessName, businessId : consigneeBusinessName.businessId }; } } if(message_to_process.consignerBizId != ""){ if(message_to_process.isConsignerThirdPartyUser == 0){ //consignerBusinessName = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.consignerBizId); message_to_process.consignerBusinessName = { firstName : message_to_process.consignerFirstName || '', businessName : message_to_process.consignerbusinessName || '', businessId : message_to_process.consignerBizId || '' }; } else{ //consignerBusinessName = mybusinessdataFactory.getAllconnectsListWithBizId(message_to_process.consignerBizId); message_to_process.consignerBusinessName = { firstName : message_to_process.consignerFirstName || '', businessName : message_to_process.consignerbusinessName || '', businessId : message_to_process.consignerBizId || '' }; } } var literal_template = $rootScope.loginpinliteral.KL_TR_0636; var literalstr = literal_template; var mapObj = { //product_dyn:Object.keys(message_to_process.productList).length, currency_dyn:message_to_process.currencyList[0].currencyCode, amt_dyn: message_to_process.totalTxAmount.toFixed(2), consignee_dyn:consigneeBusinessName.firstName, consigneebiz_dyn:consigneeBusinessName.businessName, consigner_dyn:consignerBusinessName.firstName, consignerbiz_dyn:consignerBusinessName.businessName }; literalstr = literalstr.replace(/currency_dyn|amt_dyn|consignee_dyn|consigneebiz_dyn|consigner_dyn|consignerbiz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else if(message_to_process.transactionType.toLowerCase() == "createpool"){ if(message_to_process.qualifiers != '' && message_to_process.qualifiers != undefined){ var literal_template = "Created a pool by pooltile_dyn with quantity_dyn unit_dyn qualifier_dyn product_dyn"; var literalstr = literal_template; var mapObj = { //product_dyn:Object.keys(message_to_process.productList).length, quantity_dyn:message_to_process.totalQuantity, unit_dyn:message_to_process.unit.unitName, qualifier_dyn:message_to_process.qualifiers, product_dyn:message_to_process.poolproductname, pooltile_dyn:message_to_process.pooltitle }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|qualifier_dyn|product_dyn|pooltile_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ var literal_template = $rootScope.loginpinliteral.KL_TR_0673; var literalstr = literal_template; var mapObj = { //product_dyn:Object.keys(message_to_process.productList).length, quantity_dyn:message_to_process.totalQuantity, unit_dyn:message_to_process.unit.unitName, product_dyn:message_to_process.poolproductname, pooltile_dyn:message_to_process.pooltitle }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|product_dyn|pooltile_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } else if(message_to_process.transactionType.toLowerCase() == "stockinward"){ if(message_to_process.qualifier != '' && message_to_process.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:message_to_process.quantity, unit_dyn:message_to_process.unitName, tag_dyn:message_to_process.qualifier, product_dyn:message_to_process.productName, farmer_dyn:message_to_process.farmerFirstName }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|tag_dyn|product_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.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:message_to_process.quantity, unit_dyn:message_to_process.unitName, product_dyn:message_to_process.productName, farmer_dyn:message_to_process.farmerFirstName }; literalstr = literalstr.replace(/quantity_dyn|unit_dyn|product_dyn|farmer_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } else if(message_to_process.transactionType.toLowerCase() == 'processing'){ var customerBusinessData = ""; customerBusinessData = myconnectsdataFactory.getConnetcs_VisitorsProfile(message_to_process.customerBizId); message_to_process.customerBusinessName = { firstName : customerBusinessData.firstName, businessName : customerBusinessData.businessName, businessId : customerBusinessData.businessId }; if(message_to_process.serviceType != undefined && message_to_process.serviceType.toLowerCase() == 'own'){ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0680; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0681; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, }; literalstr = literalstr.replace(/product_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } else{ if(Object.keys(message_to_process.productList).length ==1){ literal_template = $rootScope.loginpinliteral.KL_TR_0678; } else if(Object.keys(message_to_process.productList).length >1){ literal_template = $rootScope.loginpinliteral.KL_TR_0679; } var literalstr = literal_template; var mapObj = { product_dyn:Object.keys(message_to_process.productList).length, name_dyn:message_to_process.customerBusinessName.firstName, biz_dyn:message_to_process.customerBusinessName.businessName }; literalstr = literalstr.replace(/product_dyn|name_dyn|biz_dyn/gi, function(matched){ return mapObj[matched]; }); message_to_process.Businesstemplates = literalstr; } } //end if (message_to_process.isPostBuy === 1) { message_to_process.Businesstemplates = message_to_process.Businesstemplates.replace("product", "service") } return message_to_process; } coAppfullblownFactoryObject.getFullViewMessages = function(request){ var deferred = $q.defer(); if(window.localStorage["SOCIETY"]!=undefined){ var localstorage = JSON.parse(window.localStorage["SOCIETY"]); localstorage=localstorage.FullViews var MatchedFullBlownIds={}; if(localstorage[request.keypattern_id]!=undefined) { MatchedFullBlownIds=coAppfullblownFactoryObject.processingfullblown(localstorage[request.keypattern_id]) //MatchedFullBlownIds=localstorage[request.keypattern_id] deferred.resolve(MatchedFullBlownIds); } else{ var fullviewids =[]; fullviewids.push(request.keypattern_id); var fullviewrequest={ "module":"society", "keys":fullviewids } mycontentService.getSYNC_fullBatchcall(fullviewrequest).then(function(resultfullblow){ var tempBusinessFullViews ={}; for(index in resultfullblow) { var parsedobject=JSON.parse(resultfullblow[index]); tempBusinessFullViews[index] = parsedobject; } deferred.resolve(coAppfullblownFactoryObject.processingfullblown(tempBusinessFullViews[request.keypattern_id])); }); } } else{ var fullviewids =[]; fullviewids.push(request.keypattern_id); var fullviewrequest={ "module":"society", "keys":fullviewids } mycontentService.getSYNC_fullBatchcall(fullviewrequest).then(function(resultfullblow){ var tempBusinessFullViews ={}; for(index in resultfullblow) { var parsedobject=JSON.parse(resultfullblow[index]); tempBusinessFullViews[index] = parsedobject; } deferred.resolve(coAppfullblownFactoryObject.processingfullblown(tempBusinessFullViews[request.keypattern_id])); }); } return deferred.promise; } return coAppfullblownFactoryObject; }]);