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

//--------------------------------------------------------//
function CompensarPago(){
	var CompFromPers= "";
	var PersToComp	= "";	
	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];
							}
						}
					}
					CompFromPers += TariffGridPER+"|"+TariffGridDIM+"|"+Trib+"|"+TariffValues[2]+"|"+TariffGridVAL+"|"+TariffGridFIE.toFixed(i2_digitos)+"|"+TariffGridINT.toFixed(i2_digitos)+"|"+TariffGridMUL.toFixed(i2_digitos)+"~~";
				}
				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];
							}
						}
					}
					PersToComp += TariffGridPER+"|"+TariffGridDIM+"|"+Trib+"|"+TariffValues[2]+"|"+TariffGridVAL+"|"+TariffGridFIE.toFixed(i2_digitos)+"|"+TariffGridINT.toFixed(i2_digitos)+"|"+TariffGridMUL.toFixed(i2_digitos)+"~~";
				}
			}
		}
	}
	document.compensar.Compensar.value = CompFromPers;
	document.compensar.ACompensar.value = PersToComp;	
	document.compensar.submit();	
}