<?php

include '../conector.php';
session_start();
$men="";$val1="";$val2="";$val3="";$val4="";$cur1="";$cur2="";$cur3="";$cur4="";
$class1="";$class2="";$class3="";$class4="";$act1="";$act2="";$act3="";$act4="";$tbody="";$cuenta="";$res_cuenta="";$rs_cta="";

if(isset($_SESSION["user"]) && ($_SESSION["tipo"]=='R'||$_SESSION["tipo"]=='S'||$_SESSION["tipo"]=='B')){

  $class1="class=\"active\"";
  $class2="";
  $act2="";
  $act1=" active ";

 $select_pago="select  	id,
			estudiante,
			titulo,
			descripcion,
			valor,
			fecha,
			fecha_insert,
			estado,
			(select estudiante.nombre from estudiante where estudiante.estudiante_id=pagos.estudiante),
			(select curso.codigo from estudiante,curso where curso.curso_id=estudiante.curso_id and estudiante.estudiante_id=pagos.estudiante)
 			from pagos 
 			where estado in ('D','P') 
 			order by id";


if(isset($_POST['val1'])&&!empty($_POST['val1'])){

if($_POST['val1']==4){
$insert_pago_det="insert into pagos_detalle 
(pago,fecha,valor,fecha_insert,user)
values
(".$_POST['pago_c'].",'".$_POST['fecha_c']."',".$_POST['abono_c'].",now(),'".$_SESSION["user"]."')
";
//mysql_query($insert_pago_det)or die(mysql_error());

if(mysql_query($insert_pago_det)){

//15042014 1136 pm

		$select_valor_gral="select valor from pagos where id=".$_POST['pago_c']." ";
 			$res_select_valor_gral=mysql_query($select_valor_gral);
			$res_vlrg=mysql_fetch_array($res_select_valor_gral);

		$select_pagos_det3="select sum(valor) as valor3 from pagos_detalle where pago=".$_POST['pago_c']." and estado='A' ";
 			$res_select_pagos_det3=mysql_query($select_pagos_det3);
			$res_pagos3=mysql_fetch_array($res_select_pagos_det3);
					
					
			if(!isset($res_pagos3[0])||$res_pagos3[0]==0){$saldo_consulta3=$res_vlrg[0];}
			else{$saldo_consulta3=$res_vlrg[0]-$res_pagos3[0];}
					
 			if($saldo_consulta3<=0){$estado_final='P';}else{$estado_final='D';}
		

		$act_estado="update pagos set
		estado='$estado_final'
		where id=".$_POST['pago_c']."
			";
		mysql_query($act_estado)or die(mysql_error());
		
		$men="<div class=\"alert alert-success\">
	                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
	                    Abono Insertado
				</div>";
				
				
}else{
		$men="<div class=\"alert alert-danger\">
	                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
	                    Error al Insertar Abono -".mysql_error()."
				</div>";


}



}
if($_POST['val1']==3){
	$borra_pago="update pagos set estado='A' where id=".$_POST['pago1']." ";
	mysql_query($borra_pago)or die(mysql_error());
		$men="<div class=\"alert alert-success\">
	                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
	                    Pago Anulado
				</div>";
}
 if($_POST['val1']==2){
 	
 	$sal=$_POST['saldo1'];
 	$abo+=$_POST['abono1']; 	
	$sal=$sal-$abo;
 	$valo=$_POST['valor1']; 
 
	$estado_final='D';	
 
 
 					$select_pagos_det2="select sum(valor) as valor2 from pagos_detalle where pago=".$_POST['pago1']." and estado='A' ";
 					$res_select_pagos_det2=mysql_query($select_pagos_det2);
					$res_pagos2=mysql_fetch_array($res_select_pagos_det2);
					
					
					if(!isset($res_pagos2[0])||$res_pagos2[0]==0){$saldo_consulta2=$_POST['valor1'];}
					else{$saldo_consulta2=$_POST['valor1']-$res_pagos2[0];}
					
 					if($saldo_consulta2==0){$estado_final='P';}
 
 	
// 	if(($abo)>=$valo){ 	$estado_final='P';	}
 	
 
 
 	$act_pago="update pagos 
 	set titulo='".$_POST['titulo1']."',
 	descripcion='".$_POST['descripcion1']."',
 	valor=".$_POST['valor1'].",
 	fecha='".$_POST['fecha_p1']."',
 	fecha_act=now(),
 	estado='".$estado_final."'


 	where id=".$_POST['pago1']." ";


	mysql_query($act_pago)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Pago Actualizado
			</div>";
 }
 if($_POST['val1']==1||$_POST['val1']==2||$_POST['val1']==3||$_POST['val1']==4){
 
  $select_pago="select  	id,
			estudiante,
			titulo,
			descripcion,
			valor,
			fecha,
			fecha_insert,
			estado,
			(select estudiante.nombre from estudiante where estudiante.estudiante_id=pagos.estudiante),
			(select curso.codigo from estudiante,curso where curso.curso_id=estudiante.curso_id and estudiante.estudiante_id=pagos.estudiante),
			saldo,
			abono
 			from pagos 
 			where estudiante=".$_POST['buscar1']."
 			and estado in ('D','P')
 			order by id";
//echo $select_pago;				
if(mysql_query($select_pago)){
 $res_select_pago=mysql_query($select_pago);
 $num_fil=mysql_num_rows($res_select_pago);}
				
					if($num_fil>0){
					$tbody="<tbody>";
					while($r_sp=mysql_fetch_array($res_select_pago)){
					
					$select_pagos_det="select sum(valor) as valor1 from pagos_detalle where pago=".$r_sp[0]." and estado='A' ";
					$res_select_pagos_det=mysql_query($select_pagos_det);
					$res_pagos=mysql_fetch_array($res_select_pagos_det);
					
					
					if(!isset($res_pagos[0])||$res_pagos[0]==0){$saldo_consulta=$r_sp[4];}
					else{$saldo_consulta=$r_sp[4]-$res_pagos[0];}

					
					 $pago="";
					if($saldo_consulta<=0){$pago="<span class='label label-success'>Pago</span>";}
					if($saldo_consulta==$r_sp[4]){$pago="<span class='label label-danger'>Debe</span>";}
					if($saldo_consulta>0&&$saldo_consulta<$r_sp[4])	{ $pago="<span class='label label-warning'>Abono</span>";}
					
					$concept="";
					if($r_sp[2]=='P'){$concept='Pensi&oacute;n';}
					if($r_sp[2]=='L'){$concept='Libros';}					
					if($r_sp[2]=='M'){$concept='Matr&iacute;cula';}					
					if($r_sp[2]=='U'){$concept='Uniformes';}					
					if($r_sp[2]=='O'){$concept='Otro';}																				
					
					$tbody.="<tr role='row'><td>".$r_sp[8]."</td><td>".$concept."</td><td>".$r_sp[3]."</td><td>$ ".number_format($r_sp[4])."</td>
					<td>$ ".number_format($saldo_consulta)."</td>
					<td>".$pago."</td><td>".$r_sp[5]."</td><td>

					
					<a class='btn btn-info btn-xs' data-toggle='modal' data-target='#mimodala".$r_sp[0]."' name='".$_POST['buscar1']."' id='".$_POST['buscar1']."' onclick=''>
			                Ver  
				            </a>
				            
					
					</td></tr>";
					$empresa="select * from empresa ";
					$rs_empresa=mysql_query($empresa);
					$rs_emp=mysql_fetch_array($rs_empresa);
					
			
					
					$tbody.="<div name='mimodala".$r_sp[0]."' id='mimodala".$r_sp[0]."' class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
					  <div class='modal-dialog modal-md'>
					    <div class='modal-content'>
					      <div class='modal-header'>
						      <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>x</button>
					      		<h4 class='modal-title' id='myLargeModalLabel'>Detalle de Pago</h4>
      					      </div>
      					      <div class='modal-body'>";
					
					     //     $select_obs_doc="select * from observacion_docente where planilla=".$_POST['per1']." and estudiante=".$r_sce[0]."   ";
					       //   $res_select_obs_doc=mysql_query($select_obs_doc);
					        //  while($r_sodoc=mysql_fetch_array($res_select_obs_doc)){
if($r_sp[7]=='D'){$estado='SIN PAGAR';}else{$estado='PAGADA';}
							$tbody.="
							<div>
							<div style=''><b>Nro. Factura: </b>".$r_sp[0]."<br><b>Fecha: </b>".$r_sp[5]."<br><b>Estado: </b>".$estado."<br></div>
							</div>
							<div>
								<hr>
							</div>
							<div>
							<div style='float:left;padding-right:8px'><b>Pagar a: </b><br>".$rs_emp[1]."<br>".$rs_emp[4]."<br><br><b>Concepto </b><br>".$r_sp[3]."</div>
							<div><b>Cliente: </b><br>".$r_sp[8]."<br>Curso: ".$r_sp[9]."<br><br><b>Valor </b><br>$ ".number_format($r_sp[4])."</div>
							</div>
							<div>
								<hr>
							</div>";
							
							$select_detalle="select * from pagos_detalle where pago=".$r_sp[0]."  ";
							$res_select_detalle=mysql_query($select_detalle);
							$num_res=mysql_num_rows($res_select_detalle);
							if($num_res>0){
							
							$tbody.="
							<div class='table-responsive'>";
							while($r_sdet=mysql_fetch_array($res_select_detalle)){
								$tbody.="
									<div>
										Nro. Pago: $r_sdet[0] <br>
										Fecha: ".date("d/m/Y",strtotime(substr($r_sdet[2],0,10)))." <br>
										Valor: $ ".number_format($r_sdet[3])."
									</div>
									<div>
										<hr>
									</div>
									";
							
							}
							$tbody.="
							</div>
							
							";
							
							
							}
							

						$tbody.="<div><button type=\"button\" class=\"btn btn-primary btn-xs\" onclick='PrintContent(".$r_sp[0].")' >Imprimir</button>
							<button type=\"button\" class=\"btn btn-info btn-xs\" data-dismiss='modal' >Cerrar</button>
							</div>
							";
					         // }
					$tbody.="
						</div>
					    </div>
					  </div>
					</div>	";	
					
					$tbody.="<div name='mimodalb".$r_sp[0]."' id='mimodalb".$r_sp[0]."' class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
					  <div class='modal-dialog modal-md'>
					    <div class='modal-content'>
					      <div class='modal-header'>
						      <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>x</button>
					      		<h4 class='modal-title' id='myLargeModalLabel'>Editar Pago</h4>
      					      </div>
      					      <div class='modal-body'>";
					
					     //     $select_obs_doc="select * from observacion_docente where planilla=".$_POST['per1']." and estudiante=".$r_sce[0]."   ";
					       //   $res_select_obs_doc=mysql_query($select_obs_doc);
					        //  while($r_sodoc=mysql_fetch_array($res_select_obs_doc)){
						if($r_sp[7]=='D'){$estado='SIN PAGAR';}else{$estado='PAGADA';}
							$tbody.="
							
							 <div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Estudiante&nbsp;
							  </div>
							 <div class='' >
							    <input disabled value='".$r_sp[8]."' type='text' id='buscar".$r_sp[0]."' name='buscar".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
							 </div>
					
							 <div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Concepto&nbsp;
							  </div>
							 <div class='input' >

							   <select id='titulo".$r_sp[0]."' name='titulo".$r_sp[0]."' style='width:48%;margin-bottom: 10px' class='form-control2'>";
							   $se1='';$se2='';$se3='';$se4='';$se5='';
							   	if($r_sp[2]=='P'){$se1=' selected';}
								if($r_sp[2]=='L'){$se2=' selected';}
								if($r_sp[2]=='M'){$se3=' selected';}
								if($r_sp[2]=='U'){$se4=' selected';}
								if($r_sp[2]=='O'){$se5=' selected';}
							   
			$tbody.="							   
							    	<option value='M' $se3 >Matr&iacute;cula</option>
							    	<option value='P' $se1 >Pension</option>		    	
							    	<option value='L' $se2 >Libros</option>		    
							    	<option value='U' $se4 >Uniforme</option>		    	
							    	<option value='O' $se5 >Otro</option>		    	
							    	
							    </select>
							    
							    
							    
							 </div>
			
							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Descripci&oacute;n &nbsp;
							  </div>
							
							 <div class='input' >
							    <input value='".$r_sp[3]."' id='descripcion".$r_sp[0]."' name='descripcion".$r_sp[0]."' type='text' class='form-control2'  placeholder='ej. pago mes de enero' style='width:48%;margin-bottom: 10px'>
							 </div>
							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Valor &nbsp;
							  </div>
							 <div class='input' >
							    <input value='".$r_sp[4]."' id='valor".$r_sp[0]."' name='valor".$r_sp[0]."' type='text' class='form-control2'  placeholder='ej. 100000' style='width:48%;margin-bottom: 10px'>
							 </div>
						

							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Estado&nbsp;
							  </div>
							 <div class='input' >
								<select disabled id='estado".$r_sp[0]."' name='estado".$r_sp[0]."' class='form-control2' style='width:48%;margin-bottom: 10px'>";
								$sel2='';$sel1='';
			if($r_sp[7]=='D'){$sel1=' selected ';}else{$sel2=' selected ';}
								$tbody.="<option value='D' $sel1 >Debe</option>
									<option value='P' $sel2 >Pago</option>";
									
							$tbody.="</select>
							 </div>
							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Fecha&nbsp;
							  </div>
							 <div class='input' >
							    <input value='".$r_sp[5]."'  id='fecha_p".$r_sp[0]."' name='fecha_p".$r_sp[0]."' type='date' class='form-control2'  style='width:48%;margin-bottom: 10px'>
							 </div>
							
							<div><button type=\"button\" class=\"btn btn-primary btn-xs\" onclick='actualiza_pago(".$r_sp[0].",".$_POST['buscar1'].",".$saldo_consulta.")' >Actualizar</button>
							<button type=\"button\" class=\"btn btn-info btn-xs\" data-dismiss='modal' >Cerrar</button>
							</div>
							";
					         // }
					$tbody.="
						</div>
					    </div>
					  </div>
					</div>	";	
					
					
					$tbody.="<div name='mimodalc".$r_sp[0]."' id='mimodalc".$r_sp[0]."' class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
					  <div class='modal-dialog modal-md'>
					    <div class='modal-content'>
					      <div class='modal-header'>
						      <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>x</button>
					      		<h4 class='modal-title' id='myLargeModalLabel'>Abono</h4>
      					      </div>
      					      <div class='modal-body'>";
					
					     //     $select_obs_doc="select * from observacion_docente where planilla=".$_POST['per1']." and estudiante=".$r_sce[0]."   ";
					       //   $res_select_obs_doc=mysql_query($select_obs_doc);
					        //  while($r_sodoc=mysql_fetch_array($res_select_obs_doc)){

							$tbody.="
							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Descripcion&nbsp;
							  </div>
							 <div class='' >
							    <input disabled value='".$r_sp[3]."' type='text' id='descripcion_c_".$r_sp[0]."' name='descripcion_c_".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
    							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Valor&nbsp;
							  </div>
							 <div class='' >
							    <input disabled value='".($r_sp[4])."' type='text' id='valor_c_".$r_sp[0]."' name='valor_c_".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
							 </div>
    							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Saldo&nbsp;
							  </div>
							 <div class='' >
							    <input disabled value='".$saldo_consulta."' type='text' id='saldo_c_".$r_sp[0]."' name='saldo_c_".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
							 </div>
    							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Abono&nbsp;
							  </div>
							 <div class='' >
							    <input value='0' type='text' id='abono_c_".$r_sp[0]."' name='abono_c_".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
							 </div>
    							<div class='input' style='float:left;width: 140px;padding-top: 0px;padding-left: 10px;text-align: left;' >
								Fecha&nbsp;
							  </div>
							 <div class='' >
							    <input value='' type='date' id='fecha_c_".$r_sp[0]."' name='fecha_c_".$r_sp[0]."' class='form-control2'  style='width:48%;margin-bottom: 10px' >
							 </div>

							 <a class='btn btn-success btn-xs'  id='guardar_c_".$r_sp[0]."' name='guardar_c_".$r_sp[0]."' onclick='guardar_det(".$r_sp[0].",".$_POST['buscar1'].")'>
			                Guardar  
				            </a>
							 
							";
					         // }
					$tbody.="
						</div>
					    </div>
					  </div>
					</div>	";	
					
					
					
					
					
					}
					$tbody.="</tbody>";
 					}else
 					{
 					$men="<div class=\"alert alert-danger\">
		                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
		                    No existen registros para esta busqueda.
					</div>";
 					
 					}
 
 }


}

if(isset($_POST['val2'])&&!empty($_POST['val2'])){

 if($_POST['val2']==1){
  $class1="";
  $class2="class=\"active\"";
  $act1="";
  $act2=" active ";

$saldo_=($_POST['valor2']-$_POST['abono2']);
$abono_=$_POST['abono2'];

if($_POST['valor2']==$_POST['abono2']){$nvo_est='P';}
if($_POST['valor2']>$_POST['abono2']){$nvo_est='D';}

	$insertar_pago='insert into pagos (estudiante,titulo,descripcion,valor,fecha,fecha_insert,estado)
	values("'.$_POST['buscar2'].'","'.$_POST['titulo2'].'","'.$_POST['descripcion2'].'","'.$_POST['valor2'].'","'.$_POST['fecha_p2'].'",now(),"'.$nvo_est.'"
	)';
	
	
//echo $insertar_pago;
	if(mysql_query($insertar_pago)){
		$nro_pago=mysql_insert_id();
		if($_POST['abono2']>0&&isset($_POST['abono2'])){
			$inserta_detalle_pago="insert into pagos_detalle
			(pago,fecha,valor,fecha_insert,user)
			values
			(".$nro_pago.",'".$_POST['fecha_p2']."',".$_POST['abono2'].",now(),'".$_SESSION["user"]."')	";
			
			mysql_query($inserta_detalle_pago)or die(mysql_error());
		}	

	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Pago Insertado
			</div>";
	
	}else{
	$men="<div class=\"alert alert-danger\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Error al insertar pago 
			</div>";

	}	

 }
}

echo "
<!DOCTYPE html>
<html lang=\"en\">
  <head>
    <meta charset=\"utf-8\">
    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
    <meta name=\"description\" content=\"\">
    <meta name=\"author\" content=\"\">
    <link rel=\"shortcut icon\" href=\"../assets/ico/favicon.ico\">
<link rel='stylesheet' href='../js/css/jquery-ui-1.9.2.custom.css' />	

    <title>Pagos</title>

    <!-- Bootstrap core CSS -->
    <link href=\"../dist/css/bootstrap.min.css\" rel=\"stylesheet\">

    <!-- Custom styles for this template -->
    <link href=\"../offcanvas.css\" rel=\"stylesheet\">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src=\"../assets/js/ie8-responsive-file-warning.js\"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src=\"https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\"></script>
      <script src=\"https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\"></script>
    <![endif]-->


    <script>
function guardar_det(ide,est){

document.getElementById('buscar1').value=est;
	if(document.getElementById('abono_c_'+ide).value==''){alert('Debe digitar el valor del abono');return false;}
		else{
			if(parseInt(document.getElementById('saldo_c_'+ide).value)<=0)
			{		alert('saldo de la deuda es 0');
					return false;}
			if(parseInt(document.getElementById('abono_c_'+ide).value)==0)
			{		alert('Valor de abono es 0');
					return false;}		
			if( parseInt(document.getElementById('abono_c_'+ide).value)> parseInt(document.getElementById('saldo_c_'+ide).value))
			{		alert('abono es mayor al saldo');
					return false;}
			else
			{		document.getElementById('abono_c').value=document.getElementById('abono_c_'+ide).value;
			}
		}
	if(document.getElementById('fecha_c_'+ide).value==''){alert('Debe seleccionar fecha de pago');return false;}
		else{document.getElementById('fecha_c').value=document.getElementById('fecha_c_'+ide).value;}
	
	document.getElementById('pago_c').value=ide;
	
	document.getElementById('val1').value=4;
	document.forms['listar_pago'].submit();
}

function crea_pago(){
	if(document.getElementById('buscar').value==''){alert('Debe digitar el nombre');return false;}
		else{
		var mystr = document.getElementById('buscar').value;
		var myarr = mystr.split(' - ');var t_id = myarr[0];
		document.getElementById('buscar2').value=t_id;
		}
	
	if(document.getElementById('titulo').value==''){alert('Debe digitar el titutlo');return false;}
		else{document.getElementById('titulo2').value=document.getElementById('titulo').value}
	
	if(document.getElementById('descripcion').value==''){alert('Debe digitar descripcion');return false;}
		else{document.getElementById('descripcion2').value=document.getElementById('descripcion').value}
	
	if(document.getElementById('valor').value==''){alert('Debe digitar valor');return false;}
		else{document.getElementById('valor2').value=document.getElementById('valor').value}

	if(document.getElementById('abono').value==''){}
		else{document.getElementById('abono2').value=document.getElementById('abono').value}

	
	if(document.getElementById('estado').value==''){}
		else{document.getElementById('estado2').value=document.getElementById('estado').value}
	
	if(document.getElementById('fecha_p').value==''){alert('Debe seleccionar fecha');return false;}
		else{document.getElementById('fecha_p2').value=document.getElementById('fecha_p').value}


	document.getElementById('val2').value=1;
	document.forms['crear_pago'].submit();			
}
function buscar_pago(){

if(document.getElementById('buscar_').value==''){alert('Debe digitar el nombre');return false;}
		else{
		var mystr = document.getElementById('buscar_').value;
		var myarr = mystr.split(' - ');var t_id = myarr[0];
		document.getElementById('buscar1').value=t_id;
		}

	document.getElementById('val1').value=1;
	document.forms['listar_pago'].submit();

}
function actualiza_pago(ide,est,sal){

document.getElementById('buscar1').value=est;
if(document.getElementById('titulo'+ide).value==''){alert('Debe digitar el titutlo');return false;}
		else{document.getElementById('titulo1').value=document.getElementById('titulo'+ide).value}
	
	if(document.getElementById('descripcion'+ide).value==''){alert('Debe digitar descripcion');return false;}
		else{document.getElementById('descripcion1').value=document.getElementById('descripcion'+ide).value}
	
	if(document.getElementById('valor'+ide).value==''){alert('Debe digitar valor');return false;}
		else{document.getElementById('valor1').value=document.getElementById('valor'+ide).value}

	
	
	if(document.getElementById('estado'+ide).value==''){}
		else{document.getElementById('estado1').value=document.getElementById('estado'+ide).value}
	
	if(document.getElementById('fecha_p'+ide).value==''){alert('Debe seleccionar fecha');return false;}
		else{document.getElementById('fecha_p1').value=document.getElementById('fecha_p'+ide).value}				
	document.getElementById('pago1').value=ide;
	
	if(document.getElementById('estado1').value=='P'){alert('concepto pago , no se puede modificar');return false;}
	
	document.getElementById('saldo1').value=sal;
	
	document.getElementById('val1').value=2;
	document.forms['listar_pago'].submit();
}
function borra_pago(ide,est,sta){

if(sta=='P'){alert('Deuda ya se encuentra paga');return false;}

if (confirm('Esta seguro que desea anular este registro? se perderan los abonos realizados')) {	

document.getElementById('buscar1').value=est;
document.getElementById('pago1').value=ide;

	document.getElementById('val1').value=3;
	document.forms['listar_pago'].submit();


}
		else{return false;}



}
</script>
    
  </head>

  <body>
    <div class=\"navbar navbar-fixed-top navbar-inverse\" role=\"navigation\">
      <div class=\"container\">

        
          <a class=\"\" href=\"general.php\"><img src='../img/logo1.png' style='margin-top:5px'></a>

        
       <a href=\"index.php\"><img src='../img/salir.png' style='float:right;margin-top:15px'>
             	          <span style='float:right;margin-right:10px; margin-top:15px' class='label label-success'><span class='glyphicon glyphicon-user'></span> ".$_SESSION["user"]."</span>
       </a>
      </div><!-- /.container -->
    </div><!-- /.navbar -->


    <div class=\"container\">

      <div class=\"row row-offcanvas row-offcanvas-left\">

       <div class=\"col-xs-6 col-sm-3 sidebar-offcanvas\" id=\"sidebar\" role=\"navigation\">
          <div class=\"list-group\">
           <a href=\"general.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-home\"></span> General</a>
            <a href=\"estudiantes.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-th\"></span> Estudiantes</a>
            <a href=\"docentes.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-user\"></span> Docentes</a>
            <a href=\"horario.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Horario</a>
            <a href=\"planilla.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Planilla Notas</a>            
            <a href=\"planilla_obs.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Planilla Obs.</a>
            <a href=\"reportes.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Reportes</a>
            <a href=\"pagos.php\" class=\"list-group-item active\"><span class=\"glyphicon glyphicon-list\"></span> Pagos</a>
<a href=\"obs_disciplinarias.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Obs. Disc.</a>                        
<a href=\"eventos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Eventos</a>   
          </div>
        </div><!--/span-->

        <div class=\"col-xs-12 col-sm-9\">
          <p class=\"pull-left visible-xs\">
            <button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"offcanvas\">menu</button>
          </p>
    
	<div class=\"panel panel-default\">
	<br>";
echo $men;	
echo	      "<!-- Nav tabs -->
	<ul class=\"nav nav-tabs\">
		<li >&nbsp;</li>
	  <li $class1 ><a href=\"#home\" data-toggle=\"tab\">Gesti&oacute;n Pagos</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	<div class=\"tab-pane fade in $act2 \" id=\"profile\">
		<form name='crear_pago' id='crear_pago' method='post' action='pagos.php#profile' target='' enctype='multipart/form-data'>
		<input type='hidden' name='val2' id='val2' value='".$val2."'>	
		<input type='hidden' name='buscar2' id='buscar2' value='".$buscar2."'>	
		<input type='hidden' name='titulo2' id='titulo2' value='".$titulo2."'>	
		<input type='hidden' name='descripcion2' id='descripcion2' value='".$descripcion2."'>			
		<input type='hidden' name='valor2' id='valor2' value='".$valor2."'>			
		<input type='hidden' name='estado2' id='estado2' value='".$estado2."'>
		<input type='hidden' name='fecha_p2' id='fecha_p2' value='".$fecha_p2."'>				
		<input type='hidden' name='abono2' id='abono2' value='".$abono2."'>			
		
		<div class=\"page\">
			<fieldset>
				<legend>
					<br><span class=\"glyphicon glyphicon-plus\"></span> Nuevo Pago          
				</legend>			
			</fieldset>
		
		
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Estudiante&nbsp;
		  </div>
		 <div class='' >
		    <input type='text' id='buscar' name='buscar' class='form-control' value='' style='width:48%;margin-bottom: 10px' onclick='this.value=\"\"'>
		 </div>

		 <div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			T&iacute;tulo&nbsp;
		  </div>
		 <div class='input' >
		    <select id='titulo' name='titulo' style='width:48%;margin-bottom: 10px' class='form-control'>
		    	<option value='M'>Matr&iacute;cula</option>
		    	<option value='P'>Pension</option>		    	
		    	<option value='L'>Libros</option>		    
		    	<option value='U'>Uniforme</option>		    	
		    	<option value='O'>Otro</option>		    	
		    </select>
		 </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Descripci&oacute;n &nbsp;
		  </div>
		 <div class='input' >
		    <input id='descripcion' name='descripcion' type='text' class='form-control'  placeholder='ej. pago mes de enero' style='width:48%;margin-bottom: 10px'>
		 </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Valor &nbsp;
		  </div>
		 <div class='input' >
		    <input id='valor' name='valor' type='text' class='form-control'  placeholder='ej. 100000' style='width:48%;margin-bottom: 10px'>
		 </div>
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Abono &nbsp;
		  </div>
		 <div class='input' >
		    <input value=0 id='abono' name='abono' type='text' class='form-control'  placeholder='ej. 100000' style='width:48%;margin-bottom: 10px'>
		 </div>
		 
		<div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Estado&nbsp;
		  </div>
		 <div class='input' >
			<select id='estado' name='estado' class='form-control' style='width:48%;margin-bottom: 10px'>
				<option value='D'>Debe</option>
			</select>
		 </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Fecha&nbsp;
		  </div>
		 <div class='input' >
		    <input id='fecha_p' name='fecha_p' type='date' class='form-control'  style='width:48%;margin-bottom: 10px'>
		 </div>


		<fieldset>
		<legend>
					<br>
					
		</legend>	
			<button type='button' class='btn btn-info' onclick='crea_pago()'> Crear Pago</button>     
			<input type='reset' class='btn' value='Borrar'>
						
		</fieldset>
			
			<br>
		</div>
	</form>
</div>

<div class=\"tab-pane fade in $act1 \" id=\"home\">
	<form name='listar_pago' id='listar_pago' method='post' action='pagos.php' target=''>
	<div class=\"page\">
	

	<input type='hidden' name='val1' id='val1' value='".$val1."'>	
<input type='hidden' name='buscar1' id='buscar1' value='".$buscar1."'>	
		<input type='hidden' name='titulo1' id='titulo1' value='".$titulo1."'>	
		<input type='hidden' name='descripcion1' id='descripcion1' value='".$descripcion1."'>			
		<input type='hidden' name='valor1' id='valor1' value='".$valor1."'>			
		<input type='hidden' name='estado1' id='estado1' value='".$estado1."'>
		<input type='hidden' name='fecha_p1' id='fecha_p1' value='".$fecha_p1."'>
		<input type='hidden' name='pago1' id='pago1' value='".$pago1."'>		
		<input type='hidden' name='abono1' id='abono1' value='".$abono1."'>					
		<input type='hidden' name='saldo1' id='saldo1' value='".$saldo1."'>
		
		<input type='hidden' name='abono_c' id='abono_c' value='".$abono_c."'>
		<input type='hidden' name='fecha_c' id='fecha_c' value='".$fecha_c."'>		
		<input type='hidden' name='pago_c' id='pago_c' value='".$pago_c."'>				

	<input type='hidden' name='cur1' id='cur1' value='".$cur1."'>	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-th-list\"></span> 
				Lista de Pagos
			</legend>			
		</fieldset>
	</div>
	 <div class='input' style='float:left;width: 100px;padding-top: 5px;padding-left: 12px;text-align: left;' >
			Estudiante:&nbsp;
	  </div>
	 <div class='input' style='padding-left:11px;'>
		    <input type='text' id='buscar_' name='buscar_' class='' value='' style='width:30%;margin-bottom: 10px' onclick='this.value=\"\"'>
		 <button type='button' class='btn btn-info btn-sm' onclick='buscar_pago()' style='margin-left: 10px'> Buscar</button>    
	 </div>

	<fieldset>
	<div class='table-responsive'>
	<table class='table table-striped table-bordered '>
		<thead>
			<tr role='row'>
				<th>Estudiante</th>
				<th>T&iacute;tulo</th>				
				<th>Descripci&oacute;n</th>				
				<th>Valor</th>
				<th>Saldo</th>												
				<th>Estado</th>								
				<th>Fecha</th>				
				<th></th>				
			</tr>
		</thead>";
		
echo $tbody;
echo	"
	</div>
	</table>
	</fieldset>
	
	
	
	</form>

</div>
 
         
        </div><!--/span-->

       
      </div><!--/row-->


      <footer>
        <p>&copy; Company 2022</p>
      </footer>

    </div><!--/.container-->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src=\"https://code.jquery.com/jquery-1.10.2.min.js\"></script>
  <script src=\"../js/jquery-ui-1.10.3.custom.js\"></script>
  
    <script src=\"../dist/js/bootstrap.min.js\"></script>
    <script src=\"../offcanvas.js\"></script>
<script>
      $(function() {
	$( \"#buscar\" ).autocomplete(
	{
		 source:'../source.php',		 
		 minLength: 3
	})
}); 
$(function() {
	$( \"#buscar_\" ).autocomplete(
	{	 source:'../source.php',		 
		 minLength: 3	})
}); 

function PrintContent(iden)
{
var DocumentContainer = document.getElementById('mimodala'+iden);
var WindowObject = window.open('', 'PrintWindow',
'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
       if (WindowObject.print()){ 
                WindowObject.close(); 
        }else{ 
                WindowObject.close(); 
        } 

//WindowObject.print();
//WindowObject.close();
}



</script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='index.php' > Registrar</a></div>";
}
?>
