<?php
 session_start();
 include ("otro_numeroapalabras.php");
 if (!isset($_SESSION['nick'])){
  header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php" );
 }
//------INI-Coneccion Local
 require ("conecta.php");
 //-----INI-Coneccion Local
 
 $numero1=sprintf("%010d",$_POST['numero']);
 $codtipo=$_POST['hdtipod'];
 //consulta encabezado
 $sqlc="SELECT * from m02005 where NUMERO like '%$numero1';";
 $mensaje="NO encontrado";
 $resc=mysql_query($sqlc,$con) or die(mysql_error());
 if (mysql_num_rows($resc)>0){
  $mensaje="Encontrado";
  while($fila=mysql_fetch_row($resc)){//while
   $nombre=$fila[5];
   $direccion=$fila[6];
   $largorut=strlen($fila[4]);
   $codestado=$fila[20];
   $rutnum = substr($fila[4],0,$largorut-1);
   $dv=substr($fila[4],$largorut-1,1);
   $rut=$rutnum . "-" .$dv;
   $total=$fila[15];
   $cod_tipo_d=$fila[0];
  }//while
 }
 $err=0;
 if ($codtipo <> $cod_tipo_d ){
  $mensaje="Error, No coinciden los tipos de doc.";
  $err=1;
 } 
 if($codestado=="03"){
  $mensaje="Documento ya esta pagado";
  $err=1;
 }
?>
<!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>

<TITLE>Documentos</TITLE>

<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo2 {color: #FF0000}
-->
</style>
<script language="javascript">
function salir(){
 window.history.back( );
// document.form1.action="M0205005.php";
 //document.form1.method="post";
 //document.form1.submit();
}
</script>   
</HEAD>
<BODY <?php if ($err==1){
  echo "onload='javascript:(document.form1.pagar.disabled=\"disabled\")'";
  }
  ?> >
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top><div align="left" class="MainMenuHead">Movimiento de documento:</div></TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD height="100%" align=left vAlign=top class="contentcell"><form action="<?php if($codtipo=='01'){
				                                                                              echo 'fact.php';
																							  }elseif($codtipo=='02'){ 
																							  echo 'boleta.php';
																							  }else{
																							   echo 'guia.php';
																							  }  ?>"
				 method="post" name="form1" id="form1" target="_blank">
                  <table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <th colspan="2" scope="col">&nbsp;</th>
                        </tr>
                    <tr>
                      <td width="41%" scope="row"><label>
                        </label> <div align="right"><span class="LeftMenu">Rut:                        
                          </span>
                        </div>
                        <div align="right"></div></td>
                        <td width="59%" class="LeftMenu">                          <label></label>                          <div align="left"><?php echo $rut ?></div></td>
                      </tr>
                    <tr>
                      <td height="32" scope="row"><label>
                        <div align="right" class="LeftMenu">Nombre:</div></td>
                        <td><div align="left"><span class="LeftMenu"><?php echo $nombre ?></span></div></td>
                      </tr>
                    <tr>
                      <td height="32" scope="row"><span class="Estilo2">
                        <label>
                        <div align="right" class="LeftMenu Estilo2">Factura Nro:</div></td>
                      <td><div align="left" class="Estilo2"><span class="LeftMenu"><?php echo $numero1 ?></span>
                        <input name="hddoc" type="hidden" id="hddoc" value="<?php echo $numero1 ?>" />
                      </div></td>
                    </tr>
                    <tr>
                      <td height="32" scope="row"><label>
                          <div align="right" class="LeftMenu">Total:</div></td>
                      <td><div align="left"><span class="LeftMenu"><?php echo number_format($total,0,".",",") ?></span></div></td>
                    </tr>
                    <tr>
                      <td height="32" scope="row"><label>
                          <div align="right" class="LeftMenu">Son:</div></td>
                      <td><div align="left"><span class="LeftMenu"><?php $numerop=$total;
	  echo ucfirst(docenumeros($numerop));
	  ?></span></div></td>
                    </tr>
                    <tr>
                      <td height="32" scope="row"><label>
                          <div align="right" class="LeftMenu">Estado:</div></td>
                      <td class="LeftMenu">
					    <div align="left">
					      <?php if ($codestado=="00"){
					         echo "sin pagar";
							 }elseif($codestado=="01"){
							 echo "sin pagar";
							 }elseif($codestado=="02"){
							 echo "Anulada";
							 }elseif($codestado=="03"){
							 echo "Pagada";
							  }
							 
							  ?>
					      </div></td>
                    </tr>
                    <tr>
                      <td height="32" colspan="2" class="larger Estilo2" scope="row"><div align="center">Registro <?php echo $mensaje ?>. </div></td>
                      </tr>
                    <tr>
                      <th scope="row">
                        <div align="right">
                          <input name="pagar" type="submit" id="pagar"
						  value="Pagar Documento"/>
                          </div></th>
                        <td>                          <div align="left">
                            <input name="salir1" type="button" id="salir1"
							value="Salir" onclick="salir()"/>
                            <input type="text" name="textfield" value="<?php echo $codtipo ?>"/>
                          </div></td>
                      </tr>
                    <tr>
                      <td colspan="2" scope="row">&nbsp;</td>
                        </tr>
                    </table>
                </form>                  </TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD height=8>&nbsp;</TD>
                <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
</TABLE>
</BODY><?php
	mysql_close($con);
?>
</HTML>