<?php
session_start();
/* if($_SESSION['tipven']==""){
  $_SESSION['tipven'] = $_POST['tip_ven'];
  }
  $com = "A"; */
include("DMMYSQLG.php");
include("JQUERY.inc");
if (isset($_POST['bot2'])) {
    @$r1 = mysqli_query($con ,"select * from dgrequie where fol_ven = '" . $_POST['bot'] . "'");
    @$r2 = mysqli_fetch_array($r1);
    $p1 = $r2['tip_ven'];
}
?>
<html>
    <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
    <script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
    <script type="text/javascript">
                var patron = new Array(2, 2, 4)
                var patron2 = new Array(1, 3, 3, 3, 3)
                function mascara(d, sep, pat, nums){
                if (d.valant != d.value){
                val = d.value
                        largo = val.length
                        val = val.split(sep)
                        val2 = ''
                        for (r = 0; r < val.length; r++){
                val2 += val['r']
                }
                if (nums){
                for (z = 0; z < val2.length; z++){
                if (isNaN(val2.charAt(z))){
                letra = new RegExp(val2.charAt(z), "g")
                        val2 = val2.replace(letra, "")
                }
                }
                }
                val = ''
                        val3 = new Array()
                        for (s = 0; s < pat.length; s++){
                val3['s'] = val2.substring(0, pat['s'])
                        val2 = val2.substr(pat['s'])
                }
                for (q = 0; q < val3.length; q++){
                if (q == 0){
                val = val3['q']
                }
                else{
                if (val3['q'] != ""){
                val += sep + val3['q']
                }
                }
                }
                d.value = val
                        d.valant = val
                }
                }
    </script>


    <script type='text/javascript'>
        function valida(){
        if (document.frm1.tfec.value.length == 0){  //valida campo factura
        alert("INGRESE EL NUMERO DE FACTURA")
                document.frm1.tfec.focus()
                return 0;
        } else if (document.frm1.tip_ven.value.length == 0){  //valida campo factura
        alert("SELECCIONE PROVEEDOR")
                document.frm1.tip_ven.focus()
                return 0;
        }
        else
        {
        $.ajax({
        url: "compruebainv.php?fec="+document.frm1.tfec.value,
                type: 'GET',
                success: function(data) {
          
             if (data == 0){
                        if (confirm("esto INICIA un nuevo inventario y FINALIZA el anterior\n Desea Continuar?") == true){
                        $.ajax({
                        url: "resetinv.php",
                                type: 'GET',
                                success: function(data) {

                                }});
                                openpage('AL10800_AC.php', '_self');
                                console.log('entro');
                        }
                        }
                else
                        openpage('AL10800_AC.php', '_self');
                },
                        error: function() {
                        alert("Ha ocurrido un error");
                        }
                });
                        }
                return false;
                        }
    </script> 


    <body onLoad = "self.focus (); document.frm1.folio_control.focus ()">
        <form name="frm1" id="frm1" method="post" >
            <div id="width_wrapper" align="center">
                <table width="490" align="center">
                    <tr>
                        <td colspan="4" class="titulo"  style="color:#000">SALIDAS DE ALMACEN X REQUISICION</th>    </tr>
                    <tr>
                        <th width="86" style="#FFCC00">DEPARTAMENTO</th>
                        <td width="211" class="inputcodigo">
                            <select name="tip_ven" id="tip_ven" tabindex="2">
                                <?php
                                @$resultad = mysqli_query($con ,"select * from fdepartamento where sub='NO'");
                                while ($registr = mysqli_fetch_array($resultad)) {
                                    echo '<option value="' . $registr['nparte1'] . '">' . $registr['np_desc1'] . '</option>';
                                    $sqm = mysqli_query($con ,"SELECT * FROM fdepartamentd WHERE nparte1='" . $registr['nparte1'] . "'");
                                    while ($sqn = mysqli_fetch_array($sqm)) {
                                        $subDepto = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM fdepartamento where nparte1='" . $sqn['nparte1_det'] . "'"));
                                        echo '<option value="' . $registr['nparte1'] . '.' . $sqn['nparte1_det'] . '">' . $registr['np_desc1'] . ' | ' . $subDepto['np_desc1'] . '</option>';
                                    }

                                    //echo '<option value="'.$registr['codigo'].'">'.$registr['departamento'].' | '.$registr['+[a-z_]+'].'</option>';
//$sqm=mysqli_query($con ,"SELECT * FROM fdepartamentd WHERE nparte1='".$registr['nparte1']."'");
//if()
                                }
                                ?>
                            </select>	  </td>
                        <td width="66" STYLE="color:#000">FECHA.</td>
                        <td width="99" >
                            <input type="text" class="date" name="tfec" maxlength="10" id="tfec" size="11" onBlur="valFecha(this)"
<?php
if (isset($_POST['tfec'])) {
    echo 'value="' . $_POST['tfec'] . '"';
} else {
	$ultima_sal = mysqli_fetch_array(mysqli_query($con ,"SELECT fec_ven FROM dgrequie d ORDER BY d.fec_ven DESC LIMIT 1"));
	$date = new DateTime($ultima_sal['fec_ven']);
    echo 'value="' . $date->format('d/m/Y'). '"';
}
?> 
                                   ></td>
                    </tr>
                    <tr>
                        <th style="#FFCC00">REQUISICION</th>

                        <td colspan="3"><input name="folio_control" type="text" id="folio_control"
<?php
if (isset($_REQUEST['folio_control'])) {
    echo 'value = "' . $_REQUEST['folio_control'] . '"';
}
?>
                                               >
                            <?php $vv = (isset($var)) ? $var : "";
                            echo $vv
                            ?></td>
                    </tr>
                    <tr>
                        <td colspan="4" class="titulo">
                            <div align="center">
                                <input type="hidden" name="Submit22" value="Procesar" class="original"/>
                                <input type="button" name="Submit22" value="Procesar" onClick="valida()" class="original"/>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="button" name="Submit2" value="Regresar" onClick="openpage('AL10800_PR.php', '_self')" class="bot_WsW">
                            </div></th>    </tr>
                </table>
            </div>
        </form>
    </b
