<?php 	
	session_start();	
	include 'conexion.php';

$id_empresa = $_SESSION["s_empresa"];
$nombre = $_SESSION["s_nombre"];
$usuario = $_SESSION["s_usuario"];
$camposSelect = "Select id_empresa,anio Anio, mes Mes, cant_empleados Empleados, imp_art_100 'Articulo 100',imp_art_101 'Articulo 101', imp_otros Otros,sum( imp_art_100 + imp_art_101 + imp_otros) Total, fecha  'Emision' ,bancodepo Banco ,id_tipo_formulario,CASE id_tipo_formulario  WHEN 1 THEN 'Original'  WHEN 2 THEN 'Rectificativa'  end tipo_form";
$miTabla = " from com_formularios f";
$miWhere = " where f.fecha >= '2020-01-01' and id_empresa = " .$id_empresa ." and tipo_pago > 2 and ";

$miWhere .= " (SELECT total FROM det_cobros d where d.id_empresa = f.id_empresa and d.anio = f.anio and d.mes = f.mes) is null  and ";

$miWhere .= " (SELECT total FROM com_depositos dp where dp.activo = 1 and dp.id_empresa = f.id_empresa and dp.anio = f.anio and dp.mes = f.mes) is null " ;

$miGrupo = " group by f.id_empresa,f.anio,f.mes,f.id_tipo_formulario ";
$miGrupo .= " order by f.id_empresa,f.anio,f.mes,f.id_tipo_formulario ";


$sql = $camposSelect . $miTabla . $miWhere . $miGrupo;


 ?>	
<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<link rel="stylesheet" href="../css/bootstrap.min.css">
	<script src="https://kit.fontawesome.com/d73eb638c2.js" crossorigin="anonymous"></script>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
	<script type="text/javascript" src="js/funciones.js"> </script>	
	<title>Consulta de Formularios</title>
</head>

<body >

<section id="container" class="div-responsive">
	
		<h3> Empresa: <?php echo $nombre;?> </h3> 
		<h3>Formularios Emitidos para pago por transferencia bancaria o deposito en cajero automático</h3>
		
		<h5>Seleccione el ó los Formularios abonados por Comprobante de Pago</h5>

		<form action="formulario_pago.php" method="post" class="form_busqueda">		
			
			
					
    	<table data-toggle="table" data-click-to-select="true"  class="table-hover table-responsive" id="tableRoomList">
      	<thead>
			<tr>
				<th>Seleccionado</th>
				<th>Año Comp.</th>
				<th>Mes Comp.</th>
				<th>Cant. Empl.</th>
				<th style="text-align: right">Art. 100</th>
				<th style="text-align: right">Art. 101</th>
				<th style="text-align: right">Otros</th>
				<th style="text-align: right">Total</th>
				<th>Fecha Emision</th>
				<th>Banco Pago</th>
				<th>Formulario</th>
			</tr>
		</thead>
			<?php				

				$sql = $camposSelect . $miTabla . $miWhere . $miGrupo;
				
				$query = mysqli_query($coneccion ,$sql);	

				$resul_q = mysqli_num_rows($query);	
				mysqli_close($coneccion);
				if($resul_q > 0) {
					while ($data = mysqli_fetch_array($query)){
			?>
						<tr> 							
                  			<td><input type="checkbox" class="custom-control-input" name="check_lista[]" value= "<?php echo $data['id_tipo_formulario'].','.$data['Anio'].','.$data['Mes'].','.$data['Total']; ?>" uncheked ></td>
							<td><?php echo $data['Anio'] ?></td>
							<td><?php echo $data['Mes'] ?></td> 
							<td><?php echo $data['Empleados'] ?></td>
							<td align="right"><?php echo $data['Articulo 100'] ?></td> 
							<td align="right"><?php echo $data['Articulo 101'] ?></td> 
							<td align="right"><?php echo $data['Otros'] ?></td> 
							<td align="right"><?php echo $data['Total'] ?></td> 
							<td><?php echo $data['Emision'] ?></td>
							<td><?php echo $data['Banco'] ?></td>
							<td><?php echo $data['tipo_form'] ?></td>					
							
						</tr>
			<?php
					}
				}	
			
			?>
			<td>
				<div> 
					<button type="submit" class="btn btn-primary" name="enviar">  <i class="fa fa-usd" aria-hidden="true"></i> Registrar Pago</button>
				</div>
			</td>
			<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
			<td>
			<div> 
				<a href="menu.php" target="_self"><img src="images/regresar2.png" width="150"  height="50" border="0"></a>
			</div>

			</td>
		</table>

			
		</form>		

		

	</section>	
	
		


</body>
</html>