<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	$cV01 = $_POST['v1'];	/* DEPOSITO */
?>
<?php
	// conexión
	$servername = $svr_servidor;
	$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
	$conexion = sqlsrv_connect($servername, $conectioninfo);
	if ($conexion == false)
	{
		$mensaje = "Existe un error al intentar conectarse con el servidor...";
	}
	else
	{
		// CONSULTA SQL
		$sql = "SELECT R.ID, R.Fecha, R.IdEstado, R.CodCliente, R.CodTipoPago, R.Deposito, R.Valor, R.FechaAccion, R.DepositoC, R.ValorC, \n"
			  ."R.FechaConciliacion, R.EnvioSap, R.DocEntry, L.STATUS_WS, L.STATUSTEXT_WS \n"
			  ."FROM JOIN_DEPOSITOS_REGISTRO AS R \n"
			  ."LEFT JOIN JOIN_DEPOSITOS_LOG AS L ON (R.ID = L.ID) \n"
			  ."WHERE (R.Deposito LIKE '%".$cV01."%') OR (R.DepositoC LIKE '%".$cV01."%')";
		$pa1 = array();
		$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
		// Lanzar la consulta
		$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
		if (sqlsrv_num_rows($re1) != 0)
		{
			echo "
			<div class='x_panel'>
				<div class='x_title'>
					<h3>Datos depositos</h3>
					<div class='clearfix'></div>					
				</div>
				<div class='table-responsive'>
					<table class='table table-striped jambo_table bulk_action'>
						<thead>
							<tr>
								<th></th>
								<th>ID</th>
								<th>FECHA</th>
								<th>CLIENTE</th>
								<th>DEPOSITO</th>
								<th>VALOR</th>
								<th>DEPOSITO C</th>
								<th>VALOR C</th>
								<th>FECHA CONCILIACION</th>
								<th>ENVIO SAP</th>
								<th>DOCENTRY</th>
							</tr>
						</thead>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							$cV01 = $fila['ID'];
							echo "
								<tbody>
									<tr>
										<td class='a-center'>
											<button class='btn btn-sm btn-warning' type='button' data-placement='top' onclick='popup01($cV01)' data-toggle='tooltip' data-original-title='Ver Trama'><i class='fa fa-edit'></i></button>
										</td>
										<td>".$fila['ID']."</td>
										<td>".$fila['Fecha']->format('Y-m-d')."</td>
										<td>".$fila['CodCliente']."</td>
										<td>".$fila['Deposito']."</td>
										<td>".$fila['Valor']."</td>
										<td>".$fila['DepositoC']."</td>
										<td>".$fila['ValorC']."</td>
										<td>".$fila['FechaConciliacion']->format('Y-m-d h:m:s')."</td>
										<td>".$fila['EnvioSap']."</td>
										<td>".$fila['DocEntry']."</td>
									</tr>
								</tbody>
							";
						}
					echo "
					</table>
				</div>
			</div>
			";
		}
		else
		{
			echo "
			<div class='alert alert-warning alert-dismissible fade in' role='alert'>
			<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span>
			</button>
				Registros <strong>NO</strong> localizados.
			</div>
			";
		}
		sqlsrv_free_stmt($re1);
	}
	sqlsrv_close($conexion);
?>