Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
12 kB
2
Indexable
({
	getPaymentPlan : function(cmp, event, helper) {
		cmp.set('v.isAddOrDelPaymentLoading', true);

		var action = cmp.get('c.getPaymentPlan');
		action.setParams({
			quoteId : cmp.get('v.quoteId')
		});
		action.setCallback(this, function(response){
			var state = response.getState();
			if(state === "SUCCESS"){
				var paymentPlan = response.getReturnValue();
                cmp.set('v.paymentPlan', paymentPlan);
                if (paymentPlan.length > 0)
                    cmp.set('v.desabilitarDesconto', true);
				paymentPlan.forEach(plan => {
					let form = plan.Forma_de_Pagamento__c;
					let cond = plan.Condi_o_de_Pagamento__c;
					let desc = plan.Descricao__c;
					if(form && form.toLowerCase().includes('crediário') && (desc && desc.toLowerCase().includes('boleto')) && (cond && cond > 2) ){
					let crediarioQuoteEvent = $A.get("e.c:CrediarioQuoteEvent");
					crediarioQuoteEvent.setParams({
						"acao" : "add"
					});
					crediarioQuoteEvent.fire();
					}
					if(form && form.toLowerCase().includes('crediário') && (desc && desc.toLowerCase().includes('santander')) ){
						var verifyStoreEnableSantander = cmp.get('c.verifyStoreEnableSantander');
						verifyStoreEnableSantander.setCallback(this, function(response){
							let resposta = response.getReturnValue();
							if(resposta){
								var getDomains = cmp.get('c.getDomains');
								getDomains.setParams({
									"quoteId": cmp.get('v.quoteId')
								});
								getDomains.setCallback(this, function(response){
									var valueReturn = response.getReturnValue();
									if(valueReturn){
										var cmpEvent = cmp.getEvent("bancoCamposEvent");
										cmpEvent.setParams({
											"nomeBanco": cmp.get('v.getNomeBanco'),
											"campos" : valueReturn,
											"paymentPlanInsert": cmp.get('v.paymentPlanInsert')
										});
										cmpEvent.fire();
									}
								})
								$A.enqueueAction(getDomains);
							}
						});
						$A.enqueueAction(verifyStoreEnableSantander);
					}
					if(form && form.toLowerCase().includes('crediário') && (desc && desc.toLowerCase().includes('losango')) ){
						if(cmp.get('v.isLosangoEnabled')){
							this.callDomains(cmp);
						}
					}
				})

				cmp.set('v.isAddOrDelPaymentLoading', false);
			}
		});

		$A.enqueueAction(action);
	},

	setQuoteRecordType: function (cmp, event, helper) {
		const recordTypeName = cmp.get('v.quoteData.RecordType.Name');
        cmp.set('v.quoteRecordType', recordTypeName);
        cmp.set('v.disableValorAPagar', ['Vendas Corporativas', 'Porcelanateria'].includes(recordTypeName));
	},

    getFormasJS : function(cmp) {
		var creditoCliente = cmp.get('v.creditoCliente');
		var creditoDisponivel = cmp.get('v.creditoValor');
        var action = cmp.get('c.getPaymentMethodDominio');
        action.setParams({
            quoteId : cmp.get('v.quoteId'),
        });
		action.setCallback(this, function(response){
			var state = response.getState();
			if(state === "SUCCESS"){
				var retorno = JSON.parse(response.getReturnValue());
                cmp.set('v.PaymentMethod',retorno);
                var formas = [];
                for(var i in retorno.formas)
                {
					formas.push(retorno.formas[i].nome);
                }

                formas.sort();
				formas.unshift('Selecione o Método');
                cmp.set('v.Formas',formas);
                cmp.set('v.loaded',true);

            }
			cmp.set('v.paymentPlanInsert.Valor__c', cmp.get('v.FaltaPagar'));
		});

		$A.enqueueAction(action);
	},
    getCondicoesJS : function(cmp) {
		var action = cmp.get('c.getCondicoes');
		action.setCallback(this, function(response){
			var state = response.getState();
			if(state === "SUCCESS"){
				var retorno = response.getReturnValue();
                cmp.set('v.Condicoes', retorno);
			}
		});

		$A.enqueueAction(action);
	},

	verifyLinkPagamento : function(cmp) {
		var action = cmp.get('c.verifyStoreEnableLinkPagamento')
        action.setCallback(this, function(response){
            console.log('Retorno metodo verify: '+response.getReturnValue());
            let retorno = response.getReturnValue();
            if(retorno){
                cmp.set('v.storeEnable', true);
				var action2 = cmp.get('c.containsTransaction')
				action2.setParams({
					quoteId : cmp.get('v.quoteId'),
				});
				action2.setCallback(this, function(response){
					let containsTransaction = response.getReturnValue();
					console.log('ContainsTransaction: '+containsTransaction);
					cmp.set('v.linkPagamento',containsTransaction);
				});
				$A.enqueueAction(action2);
			}
        });
        $A.enqueueAction(action);
	},

	toastError : function(message,objeto,idObjeto,numero) {
		console.log('teste');
		var toastEvent = $A.get("e.force:showToast");
		toastEvent.setParams({
			type: "warning",
			title: "",
			duration:'4000',
			mode:'sticky',
			message: "error",
			messageTemplate:message,
			messageTemplateData: [{
				label:numero,
				url: "/lojas/s/"+objeto+"/"+idObjeto,
				
			}],
		});
        toastEvent.fire();
    },
	getNomeBanco: function(cmp){
		let nomeBanco;
		if(cmp.get('v.boletoSantander')){
			nomeBanco = 'Santander';
		} else if(cmp.get('v.boletoLosango')){
			nomeBanco = 'Losango';
		} else {
			nomeBanco = 'NeuroTech';
		}
		return nomeBanco;
	},
	atualizaValores: function(cmp, event, helper){
		cmp.set('v.paymentPlanInsert.Valor__c', null);
		cmp.set('v.paymentPlanInsert.Forma_de_Pagamento__c', null);
		cmp.set('v.paymentPlanInsert.Condi_o_de_Pagamento__c', null);
		cmp.set('v.paymentPlanInsert.Descricao__c', null);
		cmp.set('v.paymentPlanInsert.Condicao_de_Pagamento_Lkp__c', null);
		cmp.set('v.paymentPlanInsert.Desconto_Condicao_Pagamento__c', null);
		cmp.set('v.paymentPlanInsert.Desconto_Valor_Condicao_Pagamento__c', null);
		cmp.set('v.DescontoMaximo', null);
		cmp.set('v.DescontoMaximoValor', null);
		cmp.set('v.DisabledDesconto', true);
		
		helper.reQueryQuote(cmp, event, helper);
	},
	exibeCamposBancos: function(cmp, event, helper){
		var verifyStoreEnableSantander = cmp.get('c.verifyStoreEnableSantander');
		verifyStoreEnableSantander.setCallback(this, function(response){
			let resposta = response.getReturnValue();
			if(resposta){
				var getDomains = cmp.get('c.getDomains');
				getDomains.setParams({
					"quoteId": cmp.get('v.quoteId')
				});
				getDomains.setCallback(this, function(response){
					var valueReturn = response.getReturnValue();
					if(valueReturn){
						var cmpEvent = cmp.getEvent("bancoCamposEvent");
						cmpEvent.setParams({
							"nomeBanco": this.getNomeBanco(cmp),//cmp.get('v.getNomeBanco'),
							"campos" : valueReturn,
							"paymentPlanInsert": cmp.get('v.paymentPlanInsert')
						});
						cmpEvent.fire();
						this.atualizaValores(cmp, event, helper);
					}
				})
				$A.enqueueAction(getDomains);
			}
		});
		$A.enqueueAction(verifyStoreEnableSantander);
	},
	callDomains: function(cmp) {
		var getDomains = cmp.get('c.getDomains');
		getDomains.setParams({
			"quoteId": cmp.get('v.quoteId')
		});
		getDomains.setCallback(this, function(response){
			var valueReturn = response.getReturnValue();
			if(valueReturn){
				var cmpEvent = cmp.getEvent("bancoCamposEvent");
				cmpEvent.setParams({
					"nomeBanco": this.getNomeBanco(cmp),//cmp.get('v.getNomeBanco'),
					"campos" : valueReturn,
					"paymentPlanInsert": cmp.get('v.paymentPlanInsert')
				});
				cmpEvent.fire();
			}
		})
		$A.enqueueAction(getDomains);
    },
	exibeCamposFinanciamento: function(cmp, nomeBanco){
		//Pega domains do Losango
		var cmpEvent = cmp.getEvent("bancoCamposEvent");
		cmpEvent.setParams({
			"nomeBanco": this.getNomeBanco(cmp),
			"campos" : {},
			"paymentPlanInsert": cmp.get('v.paymentPlanInsert')
		});
		cmpEvent.fire();
		this.atualizaValores(cmp);
	},
	calcularDisponibilidadeBoleto: function(cmp){
		let condicao = cmp.get('v.paymentPlanInsert.Condi_o_de_Pagamento__c');
		let forma = cmp.get('v.paymentPlanInsert.Forma_de_Pagamento__c');

		if((forma && forma.toLowerCase() === 'crediário') && (condicao && condicao > 2)){
			var getFinanciamentoSantanderNegado = cmp.get('c.getFinanciamentoSantanderNegado');
			getFinanciamentoSantanderNegado.setParams({
				quoteId : cmp.get('v.quoteId')
			});
			getFinanciamentoSantanderNegado.setCallback(this, function(response){
				let valueReturn = response.getReturnValue();
				if(!valueReturn){
					console.log('negado');
				}
			});
			$A.enqueueAction(getFinanciamentoSantanderNegado);
		}
	},
	verificaSantanderHabilitado: function(cmp) {
		var verifyStoreEnableSantander = cmp.get('c.verifyStoreEnableSantander');
		verifyStoreEnableSantander.setCallback(this, function(response){
			let resposta = response.getReturnValue();
			if(resposta){
				cmp.set('v.isSantanderEnabled', true);
			}
		})
		$A.enqueueAction(verifyStoreEnableSantander);
	},
	verificaLosangoHabilitado: function(cmp) {
		var verifyStoreEnableLosango = cmp.get('c.verifyStoreEnableLosango');
		verifyStoreEnableLosango.setCallback(this, function(response){
			let resposta = response.getReturnValue();
			if(resposta){
				cmp.set('v.isLosangoEnabled', true);
			}
		})
		$A.enqueueAction(verifyStoreEnableLosango);
	},
	verificaLiberacaoBoletoProprio: function(cmp, event, helper){
		let quoteStatus = cmp.get('v.quoteData');
		cmp.set('v.quoteStatus', quoteStatus.Status);
		cmp.set('v.isBoletoProprioLiberado', quoteStatus.BoletoProprioLiberado__c);

			var isBoletoProprioLiberado = cmp.get('c.isBoletoProprioLiberado');
			isBoletoProprioLiberado.setParams({
				quoteId : cmp.get('v.quoteId')
			});
			isBoletoProprioLiberado.setCallback(this, function(response){
				let valueReturn = response.getReturnValue();
			cmp.set('v.exibeLiberarBoletoProprio', valueReturn);
			});
			$A.enqueueAction(isBoletoProprioLiberado);
	},

	recallDiscountCalcs: function (cmp, event, helper){
        var cmpEvt = cmp.getEvent('ReCalculateDiscounts');
        cmpEvt.setParams({
            "callName": 'default',
        });
        cmpEvt.fire();
	},
	
    reQueryQuote: function (cmp, event, helper){
        var cmpEvt = cmp.getEvent('ReQueryQuote');
        cmpEvt.setParams({
            "callName": 'default',
		});
		cmpEvt.fire()
	},

	getShowEsteira: function(cmp, event, helper){
		let viewEsteira = cmp.get('c.showEsteira'); 
        viewEsteira.setParams({
            quoteId : cmp.get('v.quoteId')
        });
        viewEsteira.setCallback(this, function(response){
            var resposta = response.getReturnValue();
            
            if(resposta === 'ignorar'){
                cmp.set('v.isviewEsteira', false)
            }else{
                cmp.set('v.isviewEsteira', true)
            }
        });
        
        $A.enqueueAction(viewEsteira);
	},
	verificaPJLosango: function(cmp){
		var verificaUsuarioPJ = cmp.get('c.verificaUsuarioPJ');
		verificaUsuarioPJ.setParams({
			quoteId : cmp.get('v.quoteId')
		});
		verificaUsuarioPJ.setCallback(this, function(response){
			let valueReturn = response.getReturnValue();
			cmp.set('v.isUsuarioPJ', valueReturn);
		});
		$A.enqueueAction(verificaUsuarioPJ);
	}
})
Leave a Comment