<?php
session_start();
include("DMMYSQLG.php");
//include("DSA1000.php");
//include("DF30000.inc");
include("DF80000.php");
//incluímos la clase ajax
require ('xajax/xajax_core/xajax.inc.php');
//instanciamos el objeto de la clase xajax  
$xajax = new xajax();
//$xajax->configure('debug', true); 

$regh = array();

function agrega($form_entrada) {
    @$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres WHERE cla_emp = '" . $_SESSION['empresa'] . "'"));
    $varfec = date('Y-m-d');
    $ssql = "insert into fcomhues  (no_pers,no_hab,folio,nombre,comentarios,cvmesa,cvpunto,cvarea,cvmesero,acc_fec,usuario) values ('" . $form_entrada["txtpersona"] . "','" . $form_entrada["txthabit"] . "','" . $form_entrada["txtfolio"] . "','" . $form_entrada["txtnombre"] . "','" . $form_entrada["txtcomen"] . "','" . $_GET['ms'] . "','" . $_GET['pt'] . "','" . $_GET['ar'] . "','" . $form_entrada["txtmesero"] . "','" . $varfec . "','" . $_SESSION['num_usu'] . "' )";
    if (mysqli_query($con ,$ssql)) {
        $salida = "Insertado correctamente";
    } else {
        $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }
    return $salida;
}

//registramos la función creada anteriormente al objeto xajax
$xajax->registerFunction("agrega");
//El objeto xajax tiene que procesar cualquier petición
$xajax->processRequest();
include("DFJSISCI.inc");
$_SESSION['habitacion'] = "";
$_SESSION['foliohb'] = "";
$_SESSION['hsp'] = "";
?>
<html>
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript" src="ajax2.js"></script>
    <script type='text/javascript'>
    </script>

    <head>
        <script type="text/javascript" language="javascript" src="DSSCRIPT.js"></script>
        <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
        <?php $xajax->printJavascript("xajax/"); ?> 
        <?php
        include("JQUERY.inc");
        $varfec = (isset($dt_empres['fec_alta'])) ? $dt_empres['fec_alta'] : "0"; //no sale la fecha alta 
        $_SESSION['empresa'];
        ?>

        <style>
            #regBus{
                height:400px;
                overflow:auto;
            }


        </style>
        <script type='text/javascript'>
        function abrir(URL) {
            //window.open(URL,"ventana1","width=300,height=290,scrollbars=NO,minimize=0") 


            $.fancybox.open({
                href: URL,
                type: 'iframe',
                padding: 5,
                width: 310,
                height: 310,
                autoSize: false,
                oncomplete: function () {
                    document.getElementById('Clave').focus();
                }
            });
        }
        function changehab() {
            window.open(<?php echo "'MESA4000_PR.php?mesero=" . $_POST['txtmesero'] . "&pt=" . $_POST['txtpunto'] . "&ar=" . $_POST['txtarea'] . "&ms=" . $_POST['txtmesa'] . "&cant=" . $_POST['txtcant'] . "&hab=" . $_POST['Clave'] . "'" ?>, 'mainFrame', 'Keypad');
            window.close();
        }
        </script>
        <script type='text/javascript'>
            function valida(url) {

                //valido el nombre 
                if (document.form1.txtpersona.value.length == 0) {
                    alert("INGRESE EL NUMERO DE PERSONAS")
                    document.form1.txtpersona.focus()
                    return 0;
                } else
                {
                    //  url=url+"&hb="+$("#txthabit").val();
                    //  console.log($('#form1').serialize());
                    //console.log(xajax.getFormValues('form1'));
                    xajax_agrega(xajax.getFormValues('form1'));

                    xajax.request({xjxfun: 'xajax_agrega'}, {
                        parameters:
                                xajax.getFormValues('form1'),
                        onRequest: function () { },
                        onSuccess: function () {
                            window.open('MESA5000_PR.php?mesero=' +<?php echo $_GET['mesero']; ?> + '&pt=<?php echo $_GET['pt']; ?>&ar=<?php echo $_GET['ar']; ?>&ms=<?php echo $_GET['ms']; ?>&pos=' + document.Keypad.Clave.value, 'mainFrame', 'Keypad');


                        },
                        onFailure: function (args) {
                            console.log(args);
                        }
                    });
                    //	window.close();
                }
                return false;

            }
            function opentec() {
                if (document.form1.txtpersona.value.length == 0) {
                    alert("INGRESE EL NUMERO DE PERSONAS")
                    document.form1.txtpersona.focus()
                    return 0;
                } else
                {
                    $("#botonera").dialog({modal: true, width: 400});
                }
                return false;
            }
        </script> 
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


    </head>
    <body onLoad = "self.focus();
    <?php
    if (!isset($_GET['cant'])) {
        echo "$('#txtpersona').focus()";
    } else if ($_GET['cant'] != "" && !isset($_GET['hab'])) {

        echo '$(\'#btnper2\').focus();';
    } else if ($_GET['hab'] != "") {
;

        echo '$(\'#Submit\').focus();';
        ;
    }
    ?>">

        <form name="form1" id="form1" action="" method="post">
            <?php
            $msr = mysqli_fetch_array(mysqli_query($con ,"select nparte1 from ctmeser where codigo='" . $_GET['mesero'] . "'"));
            $reg = mysqli_fetch_array($sql = mysqli_query($con ,"SELECT * FROM ctmesas where nparte1='" . $_GET['ms'] . "' "));


            include("DE10000.php");
            ?>
            <input name="txtmesero" type="hidden" value="<?php echo $msr['nparte1']; ?>">
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <div align="center">
                <table width="463" height="22" border='0'>
                    <tr>
                        <th colspan="8"> 
                            <div align="center">DATOS DEL CLIENTE</div>
                        </th></tr>
                </table>
                <table width="460" height="132" border="0">
                    <tr>
                        <td style="border:double" width="100">
                            <div align="center">
                                <input name="btnper" id="btnper"   type="button" class="boton" onClick="abrir('CAL10000.php?ms=<?php echo $reg['nparte1']; ?>&ar=<?php echo $reg['area']; ?>&pt=<?php echo $reg['descripcion']; ?>&mesero=<?php echo $_GET['mesero']; ?>&tpo=2')" style="font-family:Arial, Helvetica, sans-serif; font-size:12px;" value=" PERSONAS ">          
                            </div>        </td>
                        <td width="171"><label>
                                <input name="txtpersona" type="text" tabindex="1" id="txtpersona"  
                                <?php
                                $varcan = (isset($_GET['cant'])) ? $_GET['cant'] : "0";

                                if (isset($_POST['txtpersona']))
                                    echo 'value="' . $_POST['txtpersona'] . '"';
                                else
                                    echo 'value="' . $varcan . '"';
                                ?>>
                            </label></td>
                        <td width="59"><label></label></td>
                        <td width="144">&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="border:double" height="28"><div align="center">
                                <input name="btnper2" id="btnper2" type="button"  class="boton" onClick="abrir('CALHAB00.php?ms=<?php echo $reg['nparte1']; ?>&ar=<?php echo $reg['area']; ?>&pt=<?php echo $reg['descripcion']; ?>&mesero=<?php echo $_GET['mesero']; ?>&cant=<?php echo $_GET['cant']; ?>&tpo=3')" style="font-family:Arial, Helvetica, sans-serif; font-size:12px" value="HABITACION">
                            </div></td>
                        <?php
                        if (isset($_GET['hab'])) {
                            $query = mysqli_query($con ,"select * from valeryus19 where fnumcto='" . $_GET['hab'] . "' and (status='HUESPED' or status='MISCELANEOS')");
                            $regh = mysqli_fetch_array($query);
                            if (mysqli_num_rows($query) == 0) {
                                $_GET['hab'] = '';
                            } else {
                                $_GET['hab'] = $regh['fnumcto'];
                            }
                        } elseif (isset($_GET['fol'])) {
                            $query = mysqli_query($con ,"select * from valeryus19 where n_reg='" . $_GET['fol'] . "' AND (status='HUESPED' or status='MISCELANEOS')");
                            $regh = mysqli_fetch_array($query);
                            if (mysqli_num_rows($query) == 0) {
                                $_GET['hab'] = '';
                            } else {
                                $_GET['hab'] = $regh['fnumcto'];
                            }
                        }
                        ?>
                        <td><input name="txthabit" type="text" tabindex="2"  id="txthabit" onchange="getHabitacion(this.value);" value="<?php
                            $varha = (isset($_GET['hab'])) ? $_GET['hab'] : "0";
                            echo $varha;
                            ?>"></td>
<?php
//FOLIO
?>
                        <td style="border:double" height="28"><div align="center">
                                <input name="btnper2" type="button" class="boton" onClick="abrir('CALFOL00.php?ms=<?php echo $reg['nparte1']; ?>&ar=<?php echo $reg['area']; ?>&pt=<?php echo $reg['descripcion']; ?>&mesero=<?php echo $_GET['mesero']; ?>&cant=<?php echo $_GET['cant']; ?>&tpo=99')" style="font-family:Arial, Helvetica, sans-serif; font-size:15px" value="FOLIO"></div></td>

                        <td><input name="txtfolio" type="text" id="txtfolio" readonly="readonly" value="<?php
                            $varn = (isset($regh['n_reg'])) ? $regh['n_reg'] : "0";
                            echo $varn;
?>"></td>
                    </tr>
                    <tr>
                        <td height="25" style="border:double"><div align="center" class="boton" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">NOMBRE</div></td>
                        <td colspan="3"><input name="txtnombre" type="text" id="txtnombre" value="<?php
                                               $varfa = (isset($regh["fapellido"])) ? $regh["fapellido"] : "0";
                                               $varfn = (isset($regh["fnombre"])) ? $regh["fnombre"] : "0";
                                               echo $varfa . ' ' . $varfn;
                                               ?>" size="60" ></td>
                    </tr>
                    <tr>
                        <td height="35" style="border:double"><div align="center" class="boton" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">COMENTARIO</div></td>
                        <td><label>
                                <textarea name="txtcomen" cols="30" rows="5" id="txtcomen"><?php
                                               $varfn = (isset($regh['fnorasvip'])) ? $regh['fnorasvip'] : "0";
                                               echo $varfn
                                               ?></textarea>
                            </label></td>
                        <td>&nbsp;</td>
                        <td><div align="right">
                                <?php
                                $vartx = (isset($_POST['txthabit'])) ? $_POST['txthabit'] : "0";
                                $params[] = "mesero=" . $_GET['mesero'] . "";
                                $params[] = "pt=" . $_GET['pt'] . "";
                                $params[] = "ar=" . $_GET['ar'] . "";
                                $params[] = "ms=" . $_GET['ms'] . "";
//$params[] = "hb=" . $vartx . "";
                                $params[] = "tpo=12";
                                $data = "?" . implode("&", $params);
                                ?>
                                <input name="Submit" id="Submit" type="button" tabindex="2" class="boton" style="font-family:Arial, Helvetica, sans-serif; font-size:12px" onClick="opentec('CALACE00.php<?php echo "" . $data . ""; ?>')" value="ACEPTAR">
                            </div></td>
                    </tr>
                </table
                <p>

                </p>
                <label></label>
                <div align="center" id="area">

                </div>
                <div align="center" id="mesas">

                </div>
                <div align="center" id="clave">

                </div>

            </div>
        </form>


        <div id="botonera" style="display:none;background: #000;color:#fff;height: 100%;" title="NUMERO DE POSICIONES">
            <!--<div class='tltpant'>CLAVE DEL MESERO</div>-->
            <form name="Keypad" id="Keypad"  onsubmit="valida(this.Clave.value)" action="#" method="post" enctype="multipart/form-data">
                <table border="0" cellpadding="0">
                    <tbody>
                        <tr><td colspan="3" align="middle">
                                <input name="Clave" 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" >
                        </tr>
                        <tr>
                            <td align="center"><div align="center">
                                    <input name="btnSeven" type="button" class="men" onClick="NumPressed(7)" value="  7  " /></div></td>
                            <td  align="center"><div align="center">
                                    <input name="btnEight" type="button" class="men" onClick="NumPressed(8)" value="  8  " /></div></td>
                            <td  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>
                        </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="button" onClick="valida(document.Keypad.Clave.value)" class="men" id="btnok" value="OK"/></div></td>
                            <td align="center"><div align="center">
                                    <input name="btnClear" type="button" class="men" onClick="Clear()" value="  X " /></div></td>
                        </tr>
                    </tbody>
                </table>
            </form>

        </div>
    </body>
</html>
<?php mysqli_close($con); ?>

<script>
    function getHabitacion(num) {

        $.ajax({
            url: 'ws_habitacion.php?hab=' + num,
            type: 'get',
            beforeSend: function () {
                //  $.fancybox.showLoading();
            },
            success: function (response) {
                //  $.fancybox.hideLoading();

//                $("#nameg").html(name);
                if (response.trim() == "0") {
                    //  alert("ENVIADO" )
                    $('#txthabit').val('');
                    $('#txtnombre').val('');
                    $('#txtfolio').val('');
                    $('#txtcomen').val('');

                } else {
                    response = JSON.parse(response);
                    $('#txthabit').val(response.fnumcto);
                    $('#txtnombre').val(response.fnombre + " " + response.fapellido);
                    $('#txtfolio').val(response.n_reg);
                    $('#txtcomen').val(response.fnorasvip);
                }
            }
        });

    }

</script>
<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;

    }
    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;
    }
    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);
    }

    $(function () {
        $("#Keypad").submit(function (event) {
            //console.log('sumbi');
            valida(FKeyPad.Clave.value);
            event.preventDefault();
        });
    });
</script>
<script>
    $('#txtpersona').on("keypress", function (e) {
        /* ENTER PRESSED*/
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            /* FOCUS ELEMENT */
            $('#txthabit').focus();
            $('#txthabit').select();
            return false;
        }
    });
    $('#txthabit').on("keypress", function (e) {
        /* ENTER PRESSED*/
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            /* FOCUS ELEMENT */
            $('#Submit').focus();
            $('#Submit').select();
            return false;
        }
    });
</script>