<?php
session_start();

include("DMMYSQLG.php");

//incluímos la clase ajax
require ('xajax/xajax_core/xajax.inc.php');
//instanciamos el objeto de la clase xajax
$xajax = new xajax(); 

function mod_rec($form_entrada) {
    @$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres WHERE cla_emp = '" . $_SESSION['empresa'] . "'"));
    $bus = mysqli_fetch_array(mysqli_query($con ,"select con_ven from dgpemema order by con_ven desc limit 1"));
    $folio = $bus['con_ven'] + 1;
    $ssql = "UPDATE ctmesas SET status=1, fol_ven='" . $folio . "',posicion='" . $form_entrada['txtcont'] . "',acc_fec='" . $dt_empres['fec_alta'] . "' where nparte1='" . $form_entrada["txtmesa"] . "' and descripcion='" . $form_entrada["txtpunto"] . "' and area='" . $form_entrada["txtarea"] . "' ";
    if (mysqli_query($con ,$ssql)) {
        $salida = "Insertado correctamente";
    } else {
        $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }
}

function ing_comd($form_entrada) {
    @$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres WHERE cla_emp = '" . $_SESSION['empresa'] . "'"));

    @$bus = mysqli_fetch_array(mysqli_query($con ,"select nparte1 from ctmeser where codigo='" . $form_entrada['txtmeser'] . "' and cvpvta='" . $form_entrada['txtpunto'] . "' "));

    $ssql = ("insert into fcomanda (fol_ven,cvmesa,cvpunto,cvarea,cvmesero,usuario,fol_comd,acc_fec) values ('" . $form_entrada["txtfolio"] . "','" . $form_entrada["txtmesa"] . "','" . $form_entrada["txtpunto"] . "','" . $form_entrada["txtarea"] . "','" . $bus["nparte1"] . "','" . $_SESSION["num_usu"] . "','" . $dt_empres['fec_alta'] . "')");
    /* $ssql = "INSERT INTO fcomanda set fol_ven='" . $form_entrada["txtfolio"] . "',cvmesa='" . $form_entrada["txtmesa"] . "',cvpunto='" . $form_entrada["txtpunto"] . "',cvarea='" . $form_entrada["txtarea"] . "',cvmesero='" . $bus['nparte1'] . "',usuario='".$_SESSION['num_usu']."',fol_comd='" . $form_entrada['Clave'] . "' ";	 */
    if (mysqli_query($con ,$ssql)) {
        echo $salida = "Insertado correctamente";
    } else {
        echo $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }
}

function cancela_cta($form_entrada) {

    $ssql = "update dgpemema set cancelado='8' where fol_ven='" . $form_entrada['Clave'] . "' ";
    if (mysqli_query($con ,$ssql)) {
        $salida = "Insertado correctamente";
    } else {
        $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }

    /*
      $ssqla = "update ctmesas set status=0, fol_ven=0 where fol_ven='" . $form_entrada['Clave'] . "' ";
      if (mysqli_query($con ,$ssqla)){
      $salida = "Insertado correctamente";
      }else{
      $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
      } */
}

//registramos la función creada anteriormente al objeto xajax
$xajax->registerFunction("mod_rec");
$xajax->registerFunction("ing_comd");
$xajax->registerFunction("cancela_cta");
//El objeto xajax tiene que procesar cualquier petición
$xajax->processRequest();
include("CAL10000_CG.php");
require_once('DFJSISCI.inc');
?>
<html>
    <head>
        <script type="text/javascript" src="ajax2.js"></script>



        <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
        <script type="text/javascript" src="ajax.js"></script>
<?php
$xajax->printJavascript("xajax/");
//quitar estas lineas para que la comanda sea manual 
if ($_GET['tpo'] == 4) {
    $ssql = "UPDATE ctmesas SET status=1,posicion='" . $_GET['cont'] . "',acc_fec='" . $dt_empres['fec_alta'] . "' where nparte1='" . $_GET['ms'] . "' and descripcion='" . $_GET['pt'] . "' and area='" . $_GET['ar'] . "' ";
    if (mysqli_query($con ,$ssql)) {
        $salida = "Insertado correctamente";
    } else {
        $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }

    echo $_GET['folio'];
//where cons_ven='".$_GET['folio']."'
    $sql_fcom = mysqli_query($con ,"select fcomd from dgpememd  order by fcomd desc limit 1");
    $regf = mysqli_fetch_array($sql_fcom);
    echo $cmk = $regf['fcomd'] + 1;
    echo
    "<script type='text/javascript'>
				window.open('CAJA1.php?mesero=" . $_GET['mesero'] . "&pt=" . $_GET['pt'] . "&ar=" . $_GET['ar'] . "&ms=" . $_GET['ms'] . "&comand=" . $cmk . "&pos=" . $_GET['pos'] . "&cont=" . $_GET['cont'] . "','mainFrame');				
				window.close();
				</script> ";
}
?>

        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">

        </style></head>
    <body  onLoad = " $('#Clave').focus();">

        <?php
        if ((isset($_GET['tpo']) && $_GET['tpo'] == 1) or ( isset($_GET['tpo']) && $_GET['tpo'] == 11) or ( isset($_POST['txtipo']) && $_POST['txtipo'] == 1)or ( isset($_POST['txtipo']) && $_POST['txtipo'] == 11)) {
            echo "<div class='tltpant'>CLAVE DEL MESERO</div>";
        } elseif (($_GET['tpo'] == 2) or ( $_POST['txtipo'] == 2)) {
            echo "<div class='tltpant'>NUMERO DE PERSONAS</div>";
        } elseif ((isset($_GET['tpo']) && $_GET['tpo'] == 3) or ( $_POST['txtipo'] == 3)) {
            echo "<div class='tltpant'>NUMERO DE HABITACION</div>";
        } elseif (($_GET['tpo'] == 4) or ( $_POST['txtipo'] == 4)or ( $_GET['tpo'] == 5) or ( $_POST['txtipo'] == 5)) {
            echo "<div class='tltpant'>NUMERO DE COMANDA</div>";
        } elseif (($_GET['tpo'] == 6) or ( $_POST['txtipo'] == 6)or ( $_GET['tpo'] == 8)or ( $_POST['txtipo'] == 8)) {
            echo "<div class='tltpant'>NUMERO DE FOLIO</div>";
        } elseif (($_GET['tpo'] == 7) or ( $_POST['txtipo'] == 7)or ( $_GET['tpo'] == 13)or ( $_POST['txtipo'] == 13)or ( $_GET['tpo'] == 14)or ( $_POST['txtipo'] == 14)) {
            echo "<div class='tltpant'>CLAVE DEL CAJERO</div>";
        } elseif (($_GET['tpo'] == 12) or ( $_POST['txtipo'] == 12)) {
            echo "<div class='tltpant'>NUMERO DE POSICIONES</div>";
        } elseif (($_GET['tpo'] == 15) or ( $_POST['txtipo'] == 15)) {
            echo "<div class='tltpant'>NUMERO DE MESA</div>";
        } elseif (($_GET['tpo'] == 16) or ( $_POST['txtipo'] == 16)) {
            echo "<div class='tltpant'>NUEVA POSICION</div>";
        }
        ?>
        <form name="Keypad" action="CALHAB00.php" method="post" enctype="multipart/form-data">
            <div align="center">
                <?php @$bu = mysqli_fetch_array(mysqli_query($con ,"select np_desc1 from ctmesas where nparte1=" . $_GET['ms'] . "")); ?>  		 
                <input type="hidden" name="txtm" border="0" style="background:none; border:none " 
                <?php
                $varfo = (isset($_GET['fol'])) ? $_GET['fol'] : "0";
                $varpo = (isset($_GET['pos'])) ? $_GET['pos'] : "0";
                $varcon = (isset($_GET['cont'])) ? $_GET['cont'] : "0";
                $valpm = (isset($_GET['pms'])) ? $_GET['pms'] : "0";
                $varpos = (isset($_GET['posn'])) ? $_GET['posn'] : "0";
                $vartm = (isset($_GET['tm'])) ? $_GET['tm'] : "0";

                if (isset($_POST['txtm']))
                    echo 'value="' . $_POST['txtm'] . '"';
                else
                    echo 'value="' . $bu['np_desc1'] . '"';
                ?>>
                <input type="hidden" name="txtmeser" border="0" 
                <?php
                if (isset($_POST['txtmeser']))
                    echo 'value="' . $_POST['txtmeser'] . '"';
                else
                    echo 'value="' . $_GET['mesero'] . '"';
                ?>>
                <input type="hidden" name="txtcant" border="0" 
                <?php
                if (isset($_POST['txtcant']))
                    echo 'value="' . $_POST['txtcant'] . '"';
                else
                    echo 'value="' . $_GET['cant'] . '"';
                ?>>
                <input type="hidden" name="txtipo" border="0" 
                <?php
                if (isset($_POST['txtipo']))
                    echo 'value="' . $_POST['txtipo'] . '"';
                else
                    echo 'value="' . $_GET['tpo'] . '"';
                ?>>
                <input type="hidden" name="txtmesa" border="0" 
                <?php
                if (isset($_POST['txtmesa']))
                    echo 'value="' . $_POST['txtmesa'] . '"';
                else
                    echo 'value="' . $_GET['ms'] . '"';
                ?>>
                <input type="hidden" name="txtarea" <?php
                if (isset($_POST['txtarea']))
                    echo 'value="' . $_POST['txtarea'] . '"';
                else
                    echo 'value="' . $_GET['ar'] . '"';
                ?>>
                <input type="hidden" name="txtpunto" <?php
                       if (isset($_POST['txtpunto']))
                           echo 'value="' . $_POST['txtpunto'] . '"';
                       else
                           echo 'value="' . $_GET['pt'] . '"';
                       ?>>
                <input type="hidden" name="txtfolio" <?php
                if (isset($_POST['txtfolio']))
                    echo 'value="' . $_POST['txtfolio'] . '"';
                else
                    echo 'value="' . $varfo . '"';
                ?>>
                <input type="hidden" name="txtpos" <?php
                if (isset($_POST['txtpos']))
                    echo 'value="' . $_POST['txtpos'] . '"';
                else
                    echo 'value="' . $varpo . '"';
                ?>>
                <input type="hidden" name="txtcont" <?php
                if (isset($_POST['txtcont']))
                    echo 'value="' . $_POST['txtcont'] . '"';
                else
                    echo 'value="' . $varcon . '"';
                ?>>
                <input type="hidden" name="txtposm" <?php
                if (isset($_POST['txtposm']))
                    echo 'value="' . $_POST['txtposm'] . '"';
                else
                    echo 'value="' . $valpm . '"';
                ?>>
                <input type="hidden" name="txtposn" <?php
                if (isset($_POST['txtposn']))
                    echo 'value="' . $_POST['txtposn'] . '"';
                else
                    echo 'value="' . $varpos . '"';
                ?>>
                <input type="hidden" name="cancela" <?php
                if (isset($_POST['cancela']))
                    echo 'value="' . $_POST['cancela'] . '"';
                else
                    echo 'value="' . $vartm . '"';
                ?>>

            </div>
            <div align="center">
                <table border="0" cellpadding="0">
                    <tbody>
                        <tr>
                            <td colspan="4" align="middle">

                                <input name="Clave" onload="this.blur()" onblur="var that = this;
                                                          setTimeout(function () {
                                                              that.focus();
                                                          }, 0);" autofocus="autofocus" id="Clave" type="text" class="emplea" style="text-align: right;font-size:17px" size="25" >

                            </td>
                        </tr>
                        <tr>
                            <td width="43" align="center"> 
                                <div align="center">
                                    <input name="btnSeven" type="button" class="men" onClick="NumPressed(7)" value="  7  " />
                                </div></td>
                            <td width="54"  align="center">
                                <div align="center">
                                    <input name="btnEight" type="button" class="men" onClick="NumPressed(8)" value="  8  " />
                                </div></td>
                            <td width="49"  align="center">
                                <div align="center">
                                    <input name="btnNine" type="button" class="men" onClick="NumPressed(9)" value="  9  " />
                                </div></td>


                        </tr>
                        <tr>
                            <td  align="center">
                                <div align="center">
                                    <input name="btnFour" type="button" class="men" onClick="NumPressed(4)" value="  4  " />
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnFive" type="button" class="men" onClick="NumPressed(5)" value="  5  " />
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnSix" type="button" class="men" onClick="NumPressed(6)" value="  6  " />
                                </div></td>

                            <td align="center">
                                <div align="center">

                                </div></td>

                        </tr>
                        <tr>
                            <td align="center">
                                <div align="center">
                                    <input name="btnOne" type="button" class="men" onClick="NumPressed(1)" value="  1  " />
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnTwo" type="button" class="men" onClick="NumPressed(2)" value="  2  " />
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnThree" type="button" class="men" onClick="NumPressed(3)" value="  3  " />
                                </div></td>
                        </tr>
                        <tr>
                            <td align="center">
                                <div align="center">
                                    <input name="btnZero" type="button" class="men" onClick="NumPressed(0)" value="  0  " />
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnok" type="submit" class="men" id="btnok" value=" OK"/>
                                </div></td>
                            <td align="center">
                                <div align="center">
                                    <input name="btnClear" type="button" id="clear" class="men" onClick="Clear()" value="  X  " />    
                                </div></td>



                        </tr>

                        </body>
                </table>
            </div>
        </form>
    
    <script language="JavaScript" type="text/javascript">
        var FKeyPad = document.Keypad;
        var Accum = 0;
        var FlagNewNum = false;
        var PendingOp = "";
        function NumPressed(Num) {
            if (FlagNewNum) {
                FKeyPad.Clave.value = Num;
                FlagNewNum = false;
            }

            else
                FKeyPad.Clave.value += Num;

            document.Keypad.Clave.focus();
        }
        function Operation(Op) {
            var Clave = FKeyPad.Clave.value;
            if (FlagNewNum && PendingOp != "=")
                ;
            else
            {
                FlagNewNum = true;
                if ('+' == PendingOp)
                    Accum += parseFloat(Clave);
                else if ('-' == PendingOp)
                    Accum -= parseFloat(Clave);
                else if ('/' == PendingOp)
                    Accum /= parseFloat(Clave);
                else if ('*' == PendingOp)
                    Accum *= parseFloat(Clave);
                else
                    Accum = parseFloat(Clave);
                FKeyPad.Clave.value = Accum;
                PendingOp = Op;
            }
        }
        function Decimal() {
            var curClave = FKeyPad.Clave.value;
            if (FlagNewNum) {
                curClave = "0.";
                FlagNewNum = false;
            }
            else
            {
                if (curClave.indexOf(".") == -1)
                    curClave += ".";
            }
            FKeyPad.Clave.value = curClave;
        }
        function ClearEntry() {
            FKeyPad.Clave.value = "";
            FlagNewNum = true;
            document.Keypad.Clave.focus();
            console.log(2);
        }
        function Clear() {
            Accum = 0;
            PendingOp = "";
            ClearEntry();
        }
        function Neg() {
            FKeyPad.Clave.value = parseFloat(FKeyPad.Clave.value) * -1;
        }
        function Percent() {
            FKeyPad.Clave.value = (parseFloat(FKeyPad.Clave.value) / 100) * parseFloat(Accum);
        }

    </script>
</body>
</html>

<script src="js/jquery-ui.js"></script>
<script language="JavaScript" type="text/javascript">
    
    $( document ).ready(function() {
  $( "#Clave" ).blur();
        $( "#Clave" ).focus();
 console.log(8);

   
});
</script>