<?php
include('conexion.php');
//EJECUTAMOS LA CONSULTA DE BUSQUEDA

	//$registro = mysqli_query($conexion,"SELECT * FROM factGDL JOIN  ORDER BY IdCliente ASC ");
	$registro = mysqli_query($conexion,"SELECT V.IdMovimiento AS 'Consecutivo',V.Fecha AS 'Fecha', V.Serie AS 'Serie', V.FolioVenta AS 'Folio' ,V.IdSucursal AS 'Sucursal',V.Total AS 'Total',V.Anticipo AS 'Anticipo',V.Saldo AS 'Saldo',V.IdUsuario,V.Descripcion,V.TipoMovimiento  FROM Movimientos V 

		WHERE V.Activo = 1  ORDER BY V.IdSucursal,V.IdMovimiento ASC");

	//CREAMOS NUESTRA VISTA Y LA DEVOLVEMOS AL AJAX
	$contador = mysqli_num_rows($registro);
	$d = mysqli_fetch_array($registro);
	$subtotalg = 0;
	$subtotald = 0;
	$subtotalt = 0;
	
echo '<div align="center">
<table class="table table-striped table-condensed table-hover" style="font-size:14px;width:100%;">
	        	<thead>
	        	<tr class="pagado">
	            	<th colspan="14" style="font-size:20px;" >Busqueda general ARQUEO</th>
	            </tr>

	        	<tr >
	        		<th ></th>
	            	<th >Fecha</th>
	            	<th >Descripcion</th>
	            	<th ></th>
	                <th >Egresos</th>
	                <th>Ingresos</th>
	            </tr></thead>
	            <tbody>';


	$url_actual = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
	if($contador == -1){
			
		do{
			$ea = 0;
			$fecha= $d['Fecha'];
			$des = $d['Descripcion'];
			$i = $d['Anticipo'];
			
			$tipo = $d['TipoMovimiento'];
			if($tipo == 2){
				$ea = $d['Total'];
			}
			$suc= $d['Sucursal'];
			if($suc == 1){
			    $sucn = 'CUL';
			}else if ($suc == 2){
			    $sucn = 'MAZ';
			}else if($suc == 3){
			    $sucn = 'HER';
			}
			$total = $d['Total'];
			$saldo = $d['Saldo'];
			$id = $d['Consecutivo'];

			$subtotalg = $subtotalg + $i;
			$subtotalu = $subtotalu + $ea;
			$total = number_format($total,2,'.',',');
			$i = number_format($i,2,'.',',');
			$ea = number_format($ea,2,'.',',');


			echo '
			<tr class="'.$id.'">
			<td class="'.$id.'"><input type="checkbox" id="'.$id.'" value="'.$id.'" name="cons[]" onclick="check(this,'.$id.');"></td>					
			<td class="'.$id.'">'.$fecha.'</td>
			<td class="'.$id.'">'.$des.'</td>
			<td class="'.$id.'"></td>
			<td class="'.$id.'">$'.$ea.'</td>
			<td class="'.$id.'">$'.$i.'</td>
			';			
					

			
			}while(($d = mysqli_fetch_array($registro)));
		}else{
			echo '<tr>
					<td colspan="10">No se encontraron resultados</td>
				</tr>';
			}

	$subtotalg = number_format($subtotalg,2,'.',',');
	$subtotalu = number_format($subtotalu,2,'.',',');
	echo '
			<tr>
			<td colspan="6"></br></td>
			</tr>
			<tr>
				<td colspan="4"></td>
				<td>$'.$subtotalu.'</td>
				<td>$'.$subtotalg.'</td>
			</tr>';
	echo '<tr>
				<td colspan="3"></td>
				<td>Accion: </td>
				<td><select id="accnor">
					<option value="0" selected>Selecciona una opcion</option> 
					<option value="1">Revisado</option>
					<option value="2">No revisado</option>
				 </td>
				<td colspan="1" ><button id="aplicaracc" onclick="revisado()" >Aceptar</button></td>
				
			</tr>';
	echo '</tbody></table></div>';



?>