<?php
session_start();
include('../_cfg/config.php');
include('php_session.php');
include('php_gene1.php'); 
// include('lsub_grabar.php');

$a = 1;
$b = 1;
$c = 2;
?>


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <!--<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>-->
        <script src="http://vcrxol.com/_js/jquery-3.3.1.min.js"></script>
<!--          <script type="text/javascript" src="../_js/js_jorge.js"></script> -->
    </head>
    <body>
        
    <?php$orient=$_POST['orient']; ?>
    
    <?php $fsize=15?>
    <?php $trbreak='';?>
    <?php $tipomenu='';?>
    <?php $maxmenu=2 ;?>
    <?php if($mobile=='true'){$desktop='false';$maxmenu=2;}else{$desktop='true';} ?>
    <?php if($mobile=='true' and $orient=='V'){$fsize=40; $trbreak='</tr><tr><td style="font-size:4px;"></br></td></tr><tr>';}?>
    <?php if($mobile=='true' and $orient=='H'){$fsize=15; $trbreak='</tr><tr><td style="font-size:4px;"></br></td></tr><tr>';}?>
    
    
    <?php
    //SENTECIA SQL
    $query = "SELECT * FROM lsub0";
    $result = mysql_query($query);
    // echo mysql_error($link);
    
    $field = mysql_num_fields($result);
    // echo "Numero de Columnas: ".$field."<br><br>";
    ?>
    
    <div style="text-align:right;">
        <!--<input type="submit" value="Grabar">-->
    </div>
    <div class="container" style="margin-top:5px;">
<!--     <table align="center" style="width:100%">
        <tr>
            <td> -->
    <table style="background-color:#FFFDFB; border:0px solid #34495e; width:100%; text-align:center;" class="tabla">
    <thead>
        <tr>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">ID</th>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">Codigo</th>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">Descripción</th>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">Cuentas_Ventas</th>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">Cuentas_Inventario</th>
            <th style="border-bottom:solid 0px #34495e; background:#34495e; color:white; padding:3px;">Cuentas_Producto</th>
        </tr>
    </thead>
    <tbody>
    <?php
    $i = 1;
//                 $a = "grabar_".$i."()";
    while($consulta = mysql_fetch_array($result)){  ?>

    <tr id="f<?php echo $i;?>" style='padding:2px;'>

        <td style="padding:2px;"><?php echo $i; ?></td>
        <td style="padding:2px;"><?php echo $consulta['lsub_codigo'] ?></td>
        <td style="padding:2px;"><?php echo $consulta['lsub_descri'] ?></td>
        <td align="center">
            <?php
            $pidtxt="txt_".$i.".1";
            $ptabla="ctas";
            $pobj="1";
            include('vrgetcod.php') ?>
        </td>
        <td>
            <?php
            $pidtxt="txt_".$i.".2";
            $ptabla="ctas";
            $pobj="1";
            include('vrgetcod.php') ?>
        </td>
        <td>
            <?php
            $pidtxt="txt_".$i.".3";
            $ptabla="ctas";
            $pobj="1";
            include('vrgetcod.php') ?>
        </td>
        <td id="padre<?php echo $i;?>">
           <button id="btn" onClick="if(confirm('¿Guardar Cambios?')){grabar();}">Grabar</button>
        <?php // echo $i;?>
        </td>
    </tr>  

    <?php
    $i ++;
    } ?>

    </tbody>
    </table>
    </div>
    <script>
//      $(document).ready(
    function grabar(){
        
        <?php $query = "SELECT * FROM lsub0";
        $result = mysql_query($query);

        while($consulta = mysql_fetch_row($result)){
            
            $num = $consulta;
            if($num <= 3) {?>
                var txt<?php echo $num;?> = document.getElementById("txt_1.<?php echo $a++;?>").value;
            <?php}
            if($num >= 4 && $num <= 6 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_2.<?php echo $a++;?>").value;
            <?php}
            if($num >= 7 && $num <= 9 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_3.<?php echo $a++;?>").value;
            <?php}
            if($num >= 10 && $num <= 12 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_4.<?php echo $a++;?>").value;
            <?php}
            if($num >= 13 && $num <= 15 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_5.<?php echo $a++;?>").value;
            <?php}
            if($num >= 16 && $num <= 18 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_6.<?php echo $a++;?>").value;
            <?php}
            if($num >= 19 && $num <= 21 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_7.<?php echo $a++;?>").value;
            <?php}
            if($num >= 22 && $num <= 24 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_8.<?php echo $a++;?>").value;
            <?php}
            if($num >= 25 && $num <= 27 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_9.<?php echo $a++;?>").value;
            <?php}
            if($num >= 28 && $num <= 30 ){?>
                var txt<?php echo $num;?> = document.getElementById("txt_10.<?php echo $a++;?>").value;
            <?php}
            if($a == 3){
                $a = $a - $c;
            }
        }
        ?>
        
        //seleccionar fila del boton 
//         btn = $("#btn");
//         col = btn.closest("#padre1");
//         fil = btn.closest("#f1");
      
        if($(this).closest("#f1")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt1+", lsub_ctainve="+txt2+", lsub_ctaprod="+txt3+" WHERE ID = 1";
            <?php$resultado = mysql_query($query);?>
        }
        if($(this).closest("#f2")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt4+", lsub_ctainve="+txt5+", lsub_ctaprod="+txt6+" WHERE ID = 2";
            <?php$resultado = mysql_query($query);?>
        }
        if($(this).closest("#f3")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt7+", lsub_ctainve="+txt8+", lsub_ctaprod="+txt9+" WHERE ID = 3";
            <?php$resultado = mysql_query($query);?>
        }
        if($(this).closest("#f4")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt10+", lsub_ctainve="+txt11+", lsub_ctaprod="+txt12+" WHERE ID = 4";
            <?php$resultado = mysql_query($query);?>
        }
        if($(this).closest("#f5")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt13+", lsub_ctainve="+txt4+", lsub_ctaprod="+txt15+" WHERE ID = 5";
            <?php$resultado = mysql_query($query);?>
        }
        if($(this).closest("#f6")){
            <?php $query?>= "UPDATE lsub0 SET lsub_ctavtas="+txt16+", lsub_ctainve="+txt17+", lsub_ctaprod="+txt18+" WHERE ID = 6";
            <?php$resultado = mysql_query($query);?>
        }
        
        
        
//        function grabar(){
//           var txt1 = document.getElementById("txt_1.1").value; 
//           var txt2 = document.getElementById("txt_1.2").value;
//           var txt3 = document.getElementById("txt_1.3").value;
//           var txt4 = document.getElementById("txt_2.1").value;
//           var txt5 = document.getElementById("txt_2.2").value;
//           var txt6 = document.getElementById("txt_2.3").value;
//           var txt7 = document.getElementById("txt_3.1").value;
//           var txt8 = document.getElementById("txt_3.2").value;
//           var txt9 = document.getElementById("txt_3.3").value;
//           var txt10 = document.getElementById("txt_4.1").value;
//           var txt11 = document.getElementById("txt_4.2").value;
//           var txt12 = document.getElementById("txt_4.3").value;
//           var txt13 = document.getElementById("txt_5.1").value;
//           var txt14 = document.getElementById("txt_5.2").value;
//           var txt15 = document.getElementById("txt_5.3").value;
//           var txt16 = document.getElementById("txt_6.1").value;
//           var txt17 = document.getElementById("txt_6.2").value;
//           var txt18 = document.getElementById("txt_6.3").value;

          
          
          
//           $.ajax({
//             type: "POST",
//             url: "lsub_grabar.php",
//             data: 
                <?php // while($consulta = mysql_fetch_row($result)){ $num = $consulta;?> //txt <?php //echo $num;}?>,
// //               txt1 + txt2 + txt3 + txt4 + txt5 + txt6 + txt7 + txt8 + txt9 + txt10 +
// //               txt11 + txt12 + txt13 + txt14 + txt15 + txt16 + txt17 + txt18 + txt19 + txt20 + txt22
            
//             dataType: "",
//             asycn: false, //el error que cometi de sintaxis, es async
//             success: function() {
//               console.log("Éxito");
//             },
//             error: function(xhr, status) {
//               alert("Disculpe, problema");
//             }
//           })
//           console.log("<?php //while($consulta = mysql_fetch_row($result)){ $num = $consulta;?> txt <?php //echo $num;}?> - ");
    })
    </script>
</body>
</html>






















