<?php
include("conexion.php");

$consfolio = $_POST['folio'];
$cons4 = "SELECT * FROM salida WHERE idSalida='$consfolio' and estado='Finalizada'";
$res4 = mysql_query($cons4, $conex) or die("No se consulto la existencia");
$existe = mysql_num_rows($res4);
if ($consfolio == '') {
?>
  <script>
    location.href = "main.php?a=461&error=1";
  </script>
<?php
}
if ($existe == '0') {
?>
  <script>
    location.href = "main.php?a=461&error=2";
  </script>
<?php
}

$idClinica = mysql_result($res4, 0, 'idClinica');
$idpaquete = mysql_result($res4, 0, 'idPaquete');
$fecha = mysql_result($res4, 0, 'fechaSalida');
$expediente = mysql_result($res4, 0, 'expedientePaciente');
$nombre = mysql_result($res4, 0, 'nombrePaciente');
$doctor = mysql_result($res4, 0, 'doctor');
$monto = mysql_result($res4, 0, 'montoTotal');
$materia = mysql_result($res4, 0, 'materia');
$idTratamiento = mysql_result($res4, 0, 'idTratamiento');

if ($idTratamiento == 0) {
  $con2 = "SELECT nompaquete FROM paquetes WHERE idPaquete='$idpaquete'";
  $res2 = mysql_query($con2, $conex) or die("No se realizo con1");
  $concepto = mysql_result($res2, 0, 'nompaquete');
}
if ($idpaquete == 0) {
  $con2 = "SELECT tratamientoCompleto FROM tratamientocompleto WHERE idTratamiento='$idTratamiento'";
  $res2 = mysql_query($con2, $conex) or die("No se realizo con1");
  $concepto = mysql_result($res2, 0, 'tratamientoCompleto');
}


//NOMBRE DE LAS CLINICAS ORIGEN Y DESTINO

$cons6 = "SELECT clinica FROM clinicas WHERE idClinica='$idClinica'";
$res6 = mysql_query($cons6, $conex) or die("No se obtubo el nombre de clinica origen");
$clinica = mysql_result($res6, 0, 'clinica');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>UCA :.</title>
  <link href="ucaestilos.css" rel="stylesheet" type="text/css" />
  <script src="lightbox/js/prototype.js" type="text/javascript"></script>
  <script src="lightbox/js/scriptaculous.js?load=effects" type="text/javascript"></script>
  <script src="lightbox/js/lightbox.js" type="text/javascript"></script>
  <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />
  <style type="text/css">
    <!--
    body {
      background-color: #CCCCCC;
    }
    -->
  </style>
  <script src="prototype.js" language="javascript"></script>
  <script src="ajax_ejecutarsalida.js" language="javascript"></script>
  <!--ARCHIVOS PARA LISTA EN TEXTEDIT -->
  <script src="ajax.js" language="javascript"></script>
  <script src="ajax-dynamic-list.js" type="text/javascript"></script>
  <link href="ajaxestilosautocomplete.css" rel="stylesheet" type="text/css">
  <style type="text/css">
    <!--
    .boton {
      font-size: 10px
    }
    -->
  </style>
</head>

<body>
  <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
      <td><img src="img/top02.jpg" width="800" height="100" /></td>
    </tr>
    <tr>
      <td>
        <table width="790" border="0" align="center">
          <tr>
            <td>
              <table width="100%" border="0" cellspacing="10" cellpadding="0">
                <tr>
                  <td>
                    <div align="center" class="style77">VERIFICAR ESTADO PARA CANCELACI&Oacute;N DE TICKET</div>
                  </td>
                </tr>
              </table>
              <table width="100%" border="0" align="center" cellspacing="0">
                <tr>
                  <td width="23%">
                    <hr />
                  </td>
                  <td width="54%" align="center"><span class="style7">No. Control del Ticket # <span class="style9"><?php echo $consfolio; ?></span></span></td>
                  <td width="23%">
                    <hr />
                  </td>
                </tr>
              </table>
              <br />
              <table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
                <tr>
                  <td valign="top" class="style7">
                    <div align="center">DATOS DEL TICKET</div>
                  </td>
                </tr>
              </table>
              <table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
                <tr>
                  <td width="14%">
                    <div id="noimprimible">
                      <div align="right" class="style4"><strong>Paciente:</strong></div>
                    </div>
                  </td>
                  <td colspan="3" class="style9"><?php echo $nombre; ?></td>
                </tr>

                <tr>
                  <td class="style4">
                    <div id="noimprimible">
                      <div align="right"><strong>Fecha:</strong></div>
                    </div>
                  </td>
                  <td width="46%" class="style9"><?php echo $fecha; ?></td>
                  <td width="12%">
                    <div id="noimprimible">
                      <div align="right" class="style4"><strong>Expediente:</strong></div>
                    </div>
                  </td>
                  <td width="28%" class="style9"><?php echo $expediente; ?></td>
                </tr>
                <tr>
                  <td>
                    <div id="noimprimible">
                      <div align="right" class="style4"><strong>Alumno:</strong></div>
                    </div>
                  </td>
                  <td colspan="3" class="style9"><?php echo $doctor; ?></td>
                </tr>
                <tr>
                  <td class="style4">
                    <div align="right"><strong>Materia:</strong></div>
                  </td>
                  <td colspan="3" class="style9"><?php echo $materia; ?></td>
                </tr>
                <tr>
                  <td class="style4">
                    <div align="right"><strong class="style4">Tratamiento:</strong></div>
                  </td>
                  <td colspan="3" class="style9"><?php echo $concepto; ?></td>
                </tr>
              </table>
              <table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
                <tr>
                  <td valign="top" class="style7">
                    <div align="center">ESTADO DEL TICKET</div>
                  </td>
                </tr>
              </table>
              <div id="contenido">
                <?php

                echo "<table align='center' cellpadding='2' class='tablaBordes'>";
                echo "<tr class='tablaCabecera' align='center'>";

                echo "<td align='center'>";
                echo "ENTREGADO";
                echo "</td>";

                echo "<td  align='center'>";
                echo " ID ";
                echo "</td>";

                echo "<td align='center'>";
                echo "Nombre";
                echo "</td>";

                echo "<td align='center'>";
                echo "Presentaci&oacute;n";
                echo "</td>";

                echo "<td align='center'>";
                echo "Cantidad";
                echo "</td>";

                echo "</tr>";
                include("conexion.php");
                $yahayentregados = 0;
                $cons3 = "SELECT idProducto,cantidad,entregado FROM contenido_salida WHERE idSalida='$consfolio'";
                $res3 = mysql_query($cons3, $conex) or die("No se realizo el barrido en la tabla contenido_salida");
                while ($fila2 = mysql_fetch_array($res3)) {
                  $query = "SELECT clave,nombre,clasificacion FROM productos Where clave='$fila2[0]'";
                  $result = mysql_query($query, $conex) or die("No se consultaron los productos");
                  $numero_filas = mysql_num_rows($result);
                  $numero_campos = mysql_num_fields($result);
                  while ($fila = mysql_fetch_array($result)) {

                    echo "<tr class='tablaBordes'>";

                    //CONSULTO NOMBRE DE LA PRESENTACION
                    $cons1 = "SELECT idPresentacion FROM  productos WHERE clave='" . $fila[0] . "'";
                    $res1 = mysql_query($cons1, $conex) or die("No consulto ID de presentacion");
                    $idpresen = mysql_result($res1, 0, 'idPresentacion');

                    $cons2 = "SELECT presentacion FROM presentaciones WHERE idPresentacion='$idpresen'";
                    $res2 = mysql_query($cons2, $conex) or die("No consulto nombre de presentacion");
                    $presen = mysql_result($res2, 0, 'presentacion');

                    //IMPRIMO CHECKBOX
                    if ($fila2[2] == 'No') {
                      $status = "chkbx";
                      $detalle = "El material no ha sido entregado";
                    } else {
                      $status = "chkbx_si";
                      $detalle = "Material entregado";
                      if ($fila['clasificacion'] == 'Contables variables' or $fila['clasificacion'] == 'Contables fijos') {
                        $yahayentregados = $yahayentregados + 1;
                      }
                    }

                    echo "<td class='style1' align='center'>";
                    echo "<img src='img/" . $status . ".jpg' border='0' ALT='" . $detalle . "'>";
                    echo "</td>";

                    echo "<td class='style1'>";
                    echo $fila[0];
                    echo "</td>";

                    echo "<td class='style1'>";
                    echo utf8_encode($fila[1]);
                    echo "</td>";

                    //IMPRIMO PRESENTACION
                    echo "<td class='style1'>";
                    echo $presen;
                    echo "</td>";

                    //CANTIDAD
                    echo "<td class='titulo' bgcolor='#999999'  align='center'>";
                    echo $fila2[1];
                    echo "</td>";

                    //CAMBIOS
                    /*
				if ($fila[2] == "Contables variables")
				{
					echo "<td align='center'>";								
					echo "<a href='cambiosenvariables.php?venta=".$consfolio."&producto=".$fila[0]."' rel='lightbox_text'><img src='img/icon_change.jpg' border='0' ALT='Elegir medida o talla'> </a>";
					echo "</td>";
				}
				if ($fila[2] == "Liquidos - polvos")
				{
					echo "<td align='center'>";
					echo "<a href='cambiosenliquidos.php?venta=".$consfolio."&producto=".$fila[0]."' rel='lightbox_text'><img src='img/icon_change.jpg' border='0' ALT='Seleccionar otro liquido o polvo'> </a>";
					echo "</td>";
				}
				if ($fila[2] == "Materiales de impresion")
				{
					echo "<td align='center'>";
					echo "<a href='cambiosenmateriales.php?venta=".$consfolio."&producto=".$fila[0]."' rel='lightbox_text'><img src='img/icon_change.jpg' border='0' ALT='Selecciona otro material'> </a>";
					echo "</td>";
				}
				*/
                  }

                  echo "</tr>";
                }


                echo "</table>";

                ?>
              </div>
              <table width="125" border="0" align="center" cellpadding="0" cellspacing="10">
                <tr>
                  <td width="41" height="24">
                    <form id="form1" name="form1" method="post" action="main.php">
                      <input name="Submit2" type="button" class="boton2" value="Volver a inicio" onClick="javascript:history.back()" />
                    </form>
                  </td>
                  <td width="54">
                    <form id="form2" name="form1" method="post" action="cancelacion3.php">
                      <?php
                      echo "<input name='Submit' type='submit' class='boton2' value='Ejecutar Cancelaci&oacute;n'>";
                      /*
                  if ($yahayentregados==0)
						{
							echo "<input name='Submit' type='submit' class='boton2' value='Ejecutar Cancelaci&oacute;n'>";
						}
						else
						{
							echo "<input name='Submit' type='submit' class='boton2' value='No se puede cancelar' disabled='disabled'>";
						}
            */
                      ?>

                      <input name="folio" type="hidden" id="folio" value="<?php echo $consfolio; ?>" />
                    </form>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
        <br>
        <table width="100%" border="0">
          <tr>
            <td height="26" style="background-color:#0D3356;">
              <div align="center" id="noimprimible">
                <table width="99%" border="0" align="center" cellpadding="2" cellspacing="0">
                  <tr>
                    <td align="center" class="style8">Desarrollado para la Universidad Cuauht&eacute;moc por <a href="http://www.upweb.mx" target="_blank"><img src="img/webmaster.svg" style="height:16px; vertical-align:bottom;"></a></td>
                  </tr>
                </table>
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>

</html>