<?php require('../cfg/cfg.php'); ?>
<script type="text/javascript">
function regcont11()
{

//if(e.keyCode==13)
//{
	if(docucambio!=document.getElementById('docu').value && document.getElementById('docu').value!='')
	{
		regcont1(document.getElementById('docu').value);
		//busca_maes2('docu',document.getElementById('docu').value,'docu_descri','h','l');
		docucambio=document.getElementById('docu').value;
	}
//}

}
function regcont1(docu)
{
	
	
	$.ajax({
		cache:false,
		url:'../lib/regcont11.php',
		datatype: "text",
	    async:false,
		type:'GET',
		data:{docu:docu}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('regcont1_det').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
    	    	document.getElementById('docu_descri').innerHTML=document.getElementById('docu_descri_hdd').value;
				document.getElementById('ptoe_codigo').value=document.getElementById('ptoe_hdd').value;
				document.getElementById('numero_codigo').value=document.getElementById('numero_hdd').value;
			//window.history.pushState('estado', 'null', '<?php echo $dir_raiz.'main/?opt=dcont';?>&docu='+document.getElementById('docu').value);
				

			}           
		},
		timeout:30000
	});



}

function enti()
{

	//if(e.keyCode==13)
	//{
		if(enticambio!=document.getElementById('enti').value && document.getElementById('enti').value!='')
		{
		busca_maes2('enti',document.getElementById('enti').value,'enti_descri','h','enti');
		cobro_grid(document.getElementById('enti').value);
		enticambio=document.getElementById('enti').value;
		}
		
	//}

}

function csub(e)
{

	if(e.keyCode==13)
	{
		
		busca_maes2('csub',document.getElementById('csub').value,'csub_descri','v','csub');
	}

	if(e.keyCode==40)
	{
		
		
		addBowler();
	}

	if(e.keyCode==38)
	{
		var xnelem=document.getElementsByClassName('csub_cont').length;
		if(xnelem>1)
		{
			xnelem=xnelem-2;
			document.getElementsByClassName('csub_cont').item(xnelem).focus();
		}
	}
	if(e.keyCode==39)
	{
		document.getElementById('csub_descri').focus();
	}
	if(e.keyCode==37)
	{
		document.getElementById('cre_cont').focus();
		       
	}
	

}

function ctas(e)
{
	

	if(e.keyCode==13)
	{
		
		busca_maes2('ctas',document.getElementById('ctas').value,'ctas_descri','v','ctas');
		
		if(document.getElementById('ctas_descri').value=='N/A')
		{
			list_carga('ctas','ctas','ctas_descri');	
			
		}
		
	}
	if(e.keyCode==40)
	{
		addBowler();
	}
	if(e.keyCode==38)
	{
		var xnelem=document.getElementsByClassName('ctas').length;
		if(xnelem>1)
		{
			xnelem=xnelem-2;
			document.getElementsByClassName('ctas').item(xnelem).focus();
		}
	}
	if(e.keyCode==39)
	{
		document.getElementById('ctas_descri').focus();
	}
	if(e.keyCode==37)
	{
		document.getElementById('num').focus();
		       
	}

	

}


function addBowler() 
{
	busca_maes2('enti',document.getElementById('enti').value,'enti_descri','h','enti');
	var cuenta=document.getElementById('ctas').value;
	var cuenta_des=document.getElementById('ctas_descri').value;
	cuenta=cuenta.trim();
	cuenta_des=cuenta_des.trim();
	if(cuenta=="" || cuenta.length==0 || cuenta.length<10 || cuenta_des=="" || cuenta_des==" " || cuenta_des=="N/A" )
	{
		alert('Codigo de Cuenta Invalida');
		return false;
	}
	


	var valor;
	var numero= document.getElementById('num').value;		
		 
 	var tr = document.createElement('tr');
	tr.id=fila;
	tr.className='cont_fila_200';
	
//+++++++++++++++
	
	$.ajax({
		cache:false,
		url:'../lib/reg_cont3.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{tipo:'ingresa',num:numero,cuenta:cuenta,cuenta_des:cuenta_des,debito:document.getElementById('deb_cont').value,credito:document.getElementById('cre_cont').value,csub:document.getElementById('csub').value,csub_descri:document.getElementById('csub_descri').value,det_cont:document.getElementById('det_cont').value}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
	
			}           
		},
		timeout:30000
	});	
	
	
	
	
	
	
	
	
//+++++++++++++++	
	
	var td1 = tr.appendChild(document.createElement('td'));
	td1.id='trash'+fila;
	param="'bote"+fila+"'";
	
	td1.innerHTML = '<img src="../img/trash.jpg"  class="docu_trash" onclick="borraBowler('+fila+');" title="ELIMINAR LINEA"  />';
	//td1.innerHTML ='<input type="text" class="docu_bote"  id="bote'+fila+'"  onkeydown="recorrer(event,'+param+');"  />';
	
	var param="'numero"+fila+"'";
	var td2 = tr.appendChild(document.createElement('td'));
    //td2.id=;
	td2.innerHTML ='<input type="text" class="num"  id="numero'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'ctas\',\'\');" value="'+fila+'" readonly="readonly"   />';

	var td3 = tr.appendChild(document.createElement('td'));
    param="'cuenta"+fila+"'";
	valor=document.getElementById("ctas").value;
	td3.innerHTML ='<input type="text" class="ctas" id="cuenta'+fila+'"  onkeydown="mov_cont(event,this.id,this.className,\'ctas_descri\',\'num\');"  value="'+valor+'" readonly="readonly"   />';
	
	var td4 = tr.appendChild(document.createElement('td'));
    param="'contable"+fila+"'";
	valor=document.getElementById("ctas_descri").value; 
	td4.innerHTML ='<input type="text" class="ctas_descri"  id="contable'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'deb_cont\',\'ctas\');" value="'+valor+'" readonly="readonly"  />';

	var td5 = tr.appendChild(document.createElement('td'));
    param="'debito"+fila+"'";
	valor=document.getElementById("deb_cont").value;
	//td5.innerHTML ='<input type="text" class="deb_cont"  id="debito'+fila+'" value="'+valor+'"    />';
	td5.innerHTML ='<input type="text"  class="deb_cont" id="debi'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'cre_cont\',\'ctas_descri\');"  value="'+valor+'"  onblur="recalc_cont();"  />';

	var td6 = tr.appendChild(document.createElement('td'));
    param="'credito"+fila+"'";
	valor=document.getElementById("cre_cont").value;
	td6.innerHTML ='<input type="text" class="cre_cont"  id="credito'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'csub_cont\',\'deb_cont\');" value="'+valor+'" onblur="recalc_cont();" />';

	var td7 = tr.appendChild(document.createElement('td'));
    param="'csub"+fila+"'";
	valor=document.getElementById("csub").value;
	td7.innerHTML ='<input type="text" class="csub_cont"  id="csub'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'ctrsub_cont\',\'cre_cont\');" value="'+valor+'" readonly="readonly"  />';

	var td8 = tr.appendChild(document.createElement('td'));
    param="'ctsub"+fila+"'";
	valor=document.getElementById("csub_descri").value;
	td8.innerHTML ='<input type="text" class="ctrsub_cont"  id="ctsub'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'det_cont\',\'csub_cont\');" value="'+valor+'"  readonly="readonly" />';

	var td9 = tr.appendChild(document.createElement('td'));
    param="'deta"+fila+"'";
	valor=document.getElementById("det_cont").value;
	td9.innerHTML ='<input type="text" class="det_cont"  id="deta'+fila+'" onkeydown="mov_cont(event,this.id,this.className,\'\',\'ctrsub_cont\');" value="'+valor+'"   />';

	document.getElementById("bowlerList").appendChild(tr);
		
	document.getElementById('num').value=fila+1;
	
/*
	var table = document.getElementById("bowlerList");
	var row = table.insertRow(0);
	var cell1 = row.insertCell(0);
	var cell2 = row.insertCell(1);
	cell1.innerHTML = "Quiero insertar input text aaqui"+fila;
	cell2.innerHTML = "Aqui tambien"+fila;
*/	
	fila++;
	//barrido();
	//limpia_cont();
	//document.getElementById('cuent_cont').focus();

document.getElementById('ctas').value='';
document.getElementById('ctas_descri').value='';
document.getElementById('deb_cont').value=0;
document.getElementById('cre_cont').value=0;

document.getElementById('csub').value='';
document.getElementById('csub_descri').value='';
document.getElementById('det_cont').value='';

}
function recalc_cont()
{

	var acum_deb=0.00;
	var acum_cre=0.00;
	
	
	for(indy=0;indy<=document.getElementsByClassName('deb_cont').length-1;indy++)
	{
		acum_deb=acum_deb + parseFloat(document.getElementsByClassName('deb_cont').item(indy).value);
		acum_cre=acum_cre + parseFloat(document.getElementsByClassName('cre_cont').item(indy).value);
		
	}

	
	document.getElementById('debitos').value=acum_deb;
	document.getElementById('creditos').value=acum_cre;
	document.getElementById('diferencia').value=acum_deb-acum_cre;
	
}
function borraBowler(i)
{
	if(confirm("¿Quieres Eliminar?")) 
	{
		var fila= document.getElementById(i);
		fila.parentNode.removeChild(fila);
		//barrido();
	}
	
}


function mov_cont(e,d,c,der,izq)
{
	
	if(e.keyCode==40)
	{
		for(i=0;i<=document.getElementsByClassName(c).length-1;i++)
		{
			if(document.getElementsByClassName(c).item(i).id==d)
			{ 
				i++;
				if(document.getElementsByClassName(c).item(i))
				{
					document.getElementsByClassName(c).item(i).focus();
					
				}
				i--;
				break;
			}
		}
		
		if( (document.getElementsByClassName(c).length-1)==i )
		{
				
				addBowler(); 
		}
		
	}

	if(e.keyCode==38)
	{
		
		for(i=document.getElementsByClassName(c).length-1;i>=0;i--)
		{
			if(document.getElementsByClassName(c).item(i).id==d)
			{
				i--;
				if(document.getElementsByClassName(c).item(i))
				{
					document.getElementsByClassName(c).item(i).focus();
				}
				break;
			}
		}
	}

	if(e.keyCode==39)
	{
		for(i=0;i<=document.getElementsByClassName(c).length-1;i++)
		{
			if(document.getElementsByClassName(c).item(i).id==d)
			{ 
				if(document.getElementsByClassName(der).item(i))
				{
					document.getElementsByClassName(der).item(i).focus();
					break;
				}
			}
		}
	}

	if(e.keyCode==37)
	{
		for(i=0;i<=document.getElementsByClassName(c).length-1;i++)
		{
			if(document.getElementsByClassName(c).item(i).id==d)
			{ 
				if(document.getElementsByClassName(izq).item(i))
				{
					document.getElementsByClassName(izq).item(i).focus();
					break;
				}
			}
		}
	}

}

function cont_guarda_0()
{
	if(!confirm("¿Desea Guardar?")) 
	{
		return false;
	}
	
	addBowler();
	if(document.getElementsByClassName('ctas').length<2)
	{
		alert('No ha ingresado Ninguna Cuenta');
		return false;
	}
	else
	{
	
	var err_g='';
	var docux=document.getElementById('docu').value;
	var fechx=document.getElementById('docu_fecha').value;
	var ptoex=document.getElementById('ptoe_codigo').value;
	var numex=document.getElementById('numero_codigo').value;
	var entix='';
	var conse=document.getElementById('concepto').value;
	conse=conse.trim();
	if(document.getElementById('enti'))
	{
		entix=document.getElementById('enti').value;
	}
	$.ajax({
		cache:false,
		url:'../lib/reg_cont1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{docux:docux,fechx:fechx,ptoex:ptoex,numex:numex,entix:entix,conse:conse}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			err_g=dato.toString();
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
				
				if(err_g!='0')
				{
					
					cont_guarda_1(err_g);			
				}
				else
				{
					console.log(err_g);
				}
			}           
		},
		timeout:30000
	});
	
	}
	var filas=document.getElementById('bowlerList').rows.length;
	
	for(i=1;i<=filas-1;i++)
	{
		document.getElementById('bowlerList').deleteRow(1);	
	}
	fila=1;
	document.getElementById('num').value=1;
	document.getElementById('debitos').value=0;
	document.getElementById('creditos').value=0;
	document.getElementById('diferencia').value=0;
	document.getElementById('concepto').value='';
	if(document.getElementById('enti'))
	{
		document.getElementById('enti').value='';
		document.getElementById('enti_descri').innerHTML='';
	}
	regcont1(document.getElementById('docu').value);

}

function cont_guarda_1(indidocu)
{
	var ctasx='';
	var csubx='';
	var cantx=0;
	var detax='';
	for(ic=0;ic<=document.getElementsByClassName('ctas').length-2;ic++)
	{
		ctasx=document.getElementsByClassName('ctas').item(ic).value;
		csubx=document.getElementsByClassName('csub_cont').item(ic).value;
		detax=document.getElementsByClassName('det_cont').item(ic).value;
		if(document.getElementsByClassName('deb_cont').item(ic).value!=0)
		{
			cantx=parseFloat(document.getElementsByClassName('deb_cont').item(ic).value);
		}
		else
		{
			cantx=parseFloat(document.getElementsByClassName('cre_cont').item(ic).value)* -1;
		}
	//+++++++++	
		//console.log(document.getElementsByClassName('ctas').item(ic).value);
			$.ajax({
		cache:false,
		url:'../lib/reg_cont2.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{iddetx:indidocu,ctasx:ctasx,csubx:csubx,cantx:cantx,detax:detax}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			err_g=dato.toString();
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
				console.log(err_g);
				
			}           
		},
		timeout:30000
	});
//+++++++++
	}
}

function regcont_cabecera()
{
	docuy=document.getElementById('docu').value;
	fechy=document.getElementById('docu_fecha').value;
	ptoey=document.getElementById('ptoe_codigo').value;
	numey=document.getElementById('numero_codigo').value;
	entiy=document.getElementById('enti').value;
	concey=document.getElementById('concepto').value;
	
	if(docuy.length>=3)
	{
		$.ajax({
		cache:false,
		url:'../lib/reg_cont8.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{docu:docuy,fech:fechy,ptoe:ptoey,nume:numey,enti:entiy,conce:concey}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
			}           
		},
		timeout:30000
	});
	}



}
function cobro_grid(idcxc)
{
	
	$.ajax({
		cache:false,
		url:'../lib/vrcobrar1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{idcxc:idcxc}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('lista_cobro').innerHTML=dato;
			
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
				
			}           
		},
		timeout:30000
	});

}
<?php include('../../_js/lista_maes2.js');?>
<?php include('../../_js/busca_maes2.js');?>

</script>
<div align="left" style="background:#fff;font-size:12px;padding:5px;">
<table border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>
	<td><span style="font-weight:bolder;">Documento: </span></td>
	<td width="193"><input type="text" name="docu_codigo" id="docu"  onblur="regcont11();" value="" size="4"    style="border:solid 1px #000;text-transform: uppercase;" /></td>
    <td width="996">    <span id="docu_descri"></span></td>
</tr>

<tr>
	<td width="127"><span style="font-weight:bolder;">Fecha: </span></td>
    <td><input type="text" name="docu_fecha" id="docu_fecha" value="<?php echo date('Y-m-d');?>" width="100" size="4" style="border:solid 1px #000;" /></td>
    <td></td>
    
</tr>

<tr>
	<td><span style="font-weight:bolder;"> PTOE/NUMERO: </span></td>
    <td>
    	<input type="text" name="ptoe_codigo" id="ptoe_codigo"  value="001001" size="4" style="border:solid 1px #000;" /> 
	    <input type="text" name="numero_codigo" id="numero_codigo"  value="" size="4" style="border:solid 1px #000; text-align: right;" />
    </td>
    <td></td>
    
</tr>
<tr>
	<td><span style="font-weight:bolder;">Entidad: </span> </td>
	<td><input type="text" name="enti" id="enti"  onblur="enti();" style="border:solid 1px #000;"  /> </td>
    <td><span id="enti_descri"></span></td>
    
    
</tr>
<tr>
	<td><span style="font-weight:bolder;">VALOR: </span> </td>
	<td><input type="text" name="valor" id="valor"   style="border:solid 1px #000;"  /> </td>    
	<td></td>
</tr>


<tr>
	<td><span style="font-weight:bolder;">CONCEPTO: </span> </td>
	<td>
   	   
   	   <textarea name="concepto" id="concepto" cols="15" rows="5" maxlength="200" style="border: solid 1px #000; border-radius:5px; margin:0px; padding:5px; resize:none;"></textarea>
    </td>
    <td></td>
    
    
</tr>



</table>
<div>
	
    


<div id="regcont1_det"></div>


<div align="right" style="padding-right:100px;" >
<input type="button" value="Grabar" id="btn_graba" class="btn_deta" onclick="" />
</div>
<div id="lista_cobro"></div>
<div id="temporal"></div>

<div align="center"   id="lista_temporal_contenedor" style=" background:#fff;  z-index:1000; position:fixed;  top:50px; display:none; padding:10px; border:1px solid #000; border-radius:5px;">
<div align="right"><img src="http://vcrxol.com/_img/x.png" onclick="document.getElementById('lista_temporal_contenedor').style.display='none';document.getElementById('lista_temporal').innerHTML='';" /></div>
<div id="lista_temporal" style=" height:300px; overflow-y:scroll; background:#FFF; padding:10px; " ></div>


</div>

