//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: bsws.abonos.js
// Created: 2016-07-17
// Updates: 2016-07-17
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//

//--------------------------------------------------------//
function AbonarPeriodos(){
	var AbonoPers 	= "";
	var Rows   	= GridData.split("~~");	
	if(Rows<1){alert(document.form.empty_grid.value);return}
	for(var k=1;k<Rows.length;k++ ) {
		if(eval("document.form.chk_"+k+".checked")){
			var RowsValues	= Rows[k-1].split("&&");
			for(var l=0;l<RowsValues.length-1;l++ ) {
				var TariffGridFIE= 0;
				var TariffGridINT= 0;
				var TariffGridMUL= 0;
				var TariffValues = RowsValues[l].split("|");
				var TariffGridPER= eval("document.form.PER_"+k+".value");
				var TariffGridDIM= eval("document.form.DIM_"+k+".value");
				var TariffGridVAL= eval("document.form.TAR_"+TariffValues[2].substr(0,8)+"_"+k+".value");
				var TarData = RowsValues[l].split("|");				
				if(TariffGridVAL>0){
					var Trib  = GetTributo(TariffValues[2].substr(0,8));
					if(document.form.ACC_FIESTAS_chk){if(document.form.ACC_FIESTAS_chk.checked){if(TarData[4]>0){TariffGridFIE = Math.round(TariffGridVAL*GridParams['FIE']*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
					if(document.form.ACC_INTERESES_chk){if(document.form.ACC_INTERESES_chk.checked){if(TarData[5]>0){TariffGridINT = Math.round(TariffGridDIM*TariffGridVAL*(GridParams['INT']/365)*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
					if(document.form.ACC_MULTAS_chk){
						if(document.form.ACC_MULTAS_chk.checked){
							if(TarData[6]>0){
								if(TariffGridDIM>=1 && TariffGridDIM<90){TariffGridMUL = TariffGridVAL*GridParams['M89']}
								if(TariffGridDIM>=90){TariffGridMUL = TariffGridVAL*GridParams['M90']}
								if(TariffGridDIM<1){TariffGridMUL = 0}
								TariffGridMUL = Math.round(TariffGridMUL*DDigits[i2_digitos])/DDigits[i2_digitos];
							}
						}
					}
					AbonoPers += TariffGridPER+"|"+TariffGridDIM+"|"+Trib+"|"+TariffValues[2]+"|"+TariffGridVAL+"|"+TariffGridFIE.toFixed(i2_digitos)+"|"+TariffGridINT.toFixed(i2_digitos)+"|"+TariffGridMUL.toFixed(i2_digitos)+"~~";
				}
			}
		}
	}
	document.abonar.Abonos.value = AbonoPers;	
	document.abonar.submit();	
}
function AbonarPeriodo(objRef){
	var chk_name	= objRef.name;
	var chk_indx	= objRef.name.split("_");
	var generador   = document.form.generador.value;
	var TarPer      = eval("document.form.PER_"+chk_indx[1]+".value");
	var TarDIM      = eval("document.form.DIM_"+chk_indx[1]+".value");
	var AbonoPer    = TarPer+"|"+TarDIM+"|~~";
	var Rows	= GridData.split("~~");
	var RowsValues	= Rows[chk_indx[1]-1].split("&&");
	for(var l=0;l<RowsValues.length-1;l++ ) {
		var TarFie  = 0;
		var TarINT  = 0;
		var TarMUL  = 0;
		var TarData = RowsValues[l].split("|");
		var TarVAL  = eval("document.form.TAR_"+TarData[2].substr(0,8)+"_"+chk_indx[1]+".value");
		var Trib    = GetTributo(TarData[2].substr(0,8));
		if(eval("document.form.TAR_"+Trib+"_chk.checked")){
			if(document.form.ACC_FIESTAS_chk){if(document.form.ACC_FIESTAS_chk.checked){if(TarData[4]>0){TarFie = Math.round(TarVAL*GridParams['FIE']*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_INTERESES_chk){if(document.form.ACC_INTERESES_chk.checked){if(TarData[5]>0){TarINT = Math.round(TarDIM*TarVAL*(GridParams['INT']/365)*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_MULTAS_chk){
				if(document.form.ACC_MULTAS_chk.checked){
					if(TarData[6]>0){
						if(TarDIM>=1 && TarDIM<90){TarMUL = TarVAL*GridParams['M89']}
						if(TarDIM>=90){TarMUL = TarVAL*GridParams['M90']}
						if(TarDIM<1){TarMUL = 0}
						TarMUL = Math.round(TarMUL*DDigits[i2_digitos])/DDigits[i2_digitos];
					}
				}
			}
			AbonoPer += Trib+"|"+TarData[2]+"|"+TarVAL+"|"+TarFie.toFixed(i2_digitos)+"|"+TarINT.toFixed(i2_digitos)+"|"+TarMUL.toFixed(i2_digitos)+"|~~";
		}
	}	
        var winAbonarPeriodo;
	if (!winAbonarPeriodo || winAbonarPeriodo.closed){                            
            winAbonarPeriodo =     window.open("/cgi-bin/"+appid+"/pl/procesar_abonar_periodo.pl?lan="+lan+"&appid="+appid+"&i8_expediente_id="+id+"&generador="+generador+"&AbonoPeriodo="+AbonoPer,"AbonarPeriodo","top=100,left=100 width=500,height=300,resizable=no,status=no,scrollbars=no");
	}else{winAbonarPeriodo.focus()}	
}
function AbonarFuturo(objRef){
	var chk_name	= objRef.name;
	var chk_indx	= objRef.name.split("_");
	var generador   = document.form.generador.value;
	var TarPer      = eval("document.form.PER_"+chk_indx[1]+".value");
	var TarDIM      = eval("document.form.DIM_"+chk_indx[1]+".value");
	var AbonoPer    = TarPer+"|"+TarDIM+"|~~";
	var Rows		= GridData.split("~~");
	var RowsValues	= Rows[chk_indx[1]-1].split("&&");
	//alert(RowsValues);
	for(var l=0;l<RowsValues.length-1;l++ ) {
		var TarFie  = 0;
		var TarINT  = 0;
		var TarMUL  = 0;
		var TarData = RowsValues[l].split("|");
		var TarVAL  = eval("document.form.TAR_"+TarData[2].substr(0,8)+"_"+chk_indx[1]+".value");
		var Trib    = GetTributo(TarData[2].substr(0,8));
		if(eval("document.form.TAR_"+Trib+"_chk.checked")){
			if(document.form.ACC_FIESTAS_chk){if(document.form.ACC_FIESTAS_chk.checked){if(TarData[4]>0){TarFie = Math.round(TarVAL*GridParams['FIE']*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_INTERESES_chk){if(document.form.ACC_INTERESES_chk.checked){if(TarData[5]>0){TarINT = Math.round(TarDIM*TarVAL*(GridParams['INT']/365)*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_MULTAS_chk){
				if(document.form.ACC_MULTAS_chk.checked){
					if(TarData[6]>0){
						if(TarDIM>=1 && TarDIM<90){TarMUL = TarVAL*GridParams['M89']}
						if(TarDIM>=90){TarMUL = TarVAL*GridParams['M90']}
						if(TarDIM<1){TarMUL = 0}
						TarMUL = Math.round(TarMUL*DDigits[i2_digitos])/DDigits[i2_digitos];
					}
				}
			}
			AbonoPer += Trib+"|"+TarData[2]+"|"+TarVAL+"|"+TarFie.toFixed(i2_digitos)+"|"+TarINT.toFixed(i2_digitos)+"|"+TarMUL.toFixed(i2_digitos)+"|~~";
		}
	}	
    var winAbonarPeriodo;
	if (!winAbonarPeriodo || winAbonarPeriodo.closed){                            
            winAbonarPeriodo =     window.open("/cgi-bin/"+appid+"/pl/procesar_abonar_futuro.pl?lan="+lan+"&appid="+appid+"&i8_expediente_id="+id+"&generador="+generador+"&AbonoPeriodo="+AbonoPer,"AbonarPeriodo","top=100,left=100 width=500,height=300,resizable=no,status=no,scrollbars=no");
	}else{winAbonarPeriodo.focus()}	
}
function AbonarTributoPeriodo(objRef){
	var tributo	  = "";
	var TarFie  	  = 0;
	var TarINT  	  = 0;
	var TarMUL  	  = 0;
	var chk_name	  = objRef.name;
	var chk_indx	  = objRef.name.split("_");
	var c8_tributo_id = chk_indx[1];
	var generador     = document.form.generador.value;
        var TarPER	  = eval("document.form.PER_"+chk_indx[2]+".value");
	var TarDIM        = eval("document.form.DIM_"+chk_indx[2]+".value");
        var TarVAL	  = eval("document.form.TAR_"+chk_indx[1]+"_"+chk_indx[2]+".value");
	var c16_tarifa_id = ShowTarifa(objRef);
	var tributo	  = GetTributo(c8_tributo_id);
	var AbonoTarPer   = TarPER+"|"+TarDIM+"|~~"+tributo+"|"+c16_tarifa_id+"|"+TarVAL+"|";
	var Rows	  = GridData.split("~~");
	var RowsValues	  = Rows[chk_indx[2]-1].split("&&");
	for(var l=0;l<RowsValues.length-1;l++ ) {
		var TarData = RowsValues[l].split("|");
		if(TarData[2].substr(0,8)==c8_tributo_id){
			if(document.form.ACC_FIESTAS_chk){if(document.form.ACC_FIESTAS_chk.checked){if(TarData[4]>0){TarFie = Math.round(TarVAL*GridParams['FIE']*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_INTERESES_chk){if(document.form.ACC_INTERESES_chk.checked){if(TarData[5]>0){TarINT = Math.round(TarDIM*TarVAL*(GridParams['INT']/365)*DDigits[i2_digitos])/DDigits[i2_digitos];}}}
			if(document.form.ACC_MULTAS_chk){
				if(document.form.ACC_MULTAS_chk.checked){
					if(TarData[6]>0){
						if(TarDIM>=1 && TarDIM<90){TarMUL = TarVAL*GridParams['M89']}
						if(TarDIM>=90){TarMUL = TarVAL*GridParams['M90']}
						if(TarDIM<1){TarMUL = 0}
						TarMUL = Math.round(TarMUL*DDigits[i2_digitos])/DDigits[i2_digitos];
					}
				}
			}
		}		
	}	
	AbonoTarPer += TarFie.toFixed(i2_digitos)+"|"+TarINT.toFixed(i2_digitos)+"|"+TarMUL.toFixed(i2_digitos)+"|";	
        var winAbonarTributoPeriodo;
	if (!winAbonarTributoPeriodo || winAbonarTributoPeriodo.closed){                            
            winAbonarTributoPeriodo =     window.open("/cgi-bin/"+appid+"/pl/procesar_abonar_tributo_periodo.pl?lan="+lan+"&appid="+appid+"&i8_expediente_id="+id+"&generador="+generador+"&AbonoTarPeriodo="+AbonoTarPer,"AbonarPeriodo","top=100,left=100 width=500,height=200,resizable=no,status=no,scrollbars=no");
	}else{winAbonarTributoPeriodo.focus()}	
}
//-------------------------------------------------------//
