<?php
    include './conexion.php';

    //$semana='39'; //2024-09-20 al 2024-09-26
    $status=null;
    $anio= $_POST['anio'];
    $periodo = $_POST['periodo'];
    $ubicacion = $_POST['ubicacion'];
    $supervisor = $_POST['supervisor'];
    $lugar = $_POST['lugar'];
    $lugarz= $_POST['lugarz'];
    $inicio=null;
    $final=null;
    $hrs=null;
    $sql=null;
    
    if($supervisor=='0'){
        $sql= "select * from movs where semana='".$anio."_".$periodo."' and ubicacion='".$ubicacion."'";
    } else{
        $sql= "select * from movs where semana='".$anio."_".$periodo."' and supervisor='".$supervisor."'";
    }

    function cambio2($x){
        $status=null;
        switch($x){
            case '1': $status="A";break;
            case '9': $status="D";break;
            
        }
        return $status;
    }
    function cambio($x){
        $status=null;
        if($x==1){
            $status='<option selected value="1">A</option>
                     <option value="2">F</option>         
                     <option value="9">D</option>
            ';

        }else if($x==9){
            $status='   <option value="1">A</option>
                        <option value="2">F</option>         
                        <option selected value="9">D</option>
            ';
        }
        return $status;
    }
    
    $status.="<table class='tabla1'>
    <thead>
        <tr>
            
            
            <th colspan='9'></th>
            <th colspan='7' style='text-align:center;'>Asistencia</th>
            <th></th>
            

        </tr>
        <tr>
            <th rowspan='2'></th>
            <th rowspan='2' style='width:80px;'>Ubicacion</th>
            <th rowspan='2'>Supervisor</th>
            <th>Lugar de Trabajo</th>
            <th>Num. Empl.</th>
            <th style='width:600px;'>Nombre Completo</th>
            <th>Sueldo Dato</th>
            <th style='width:1200px;'>Turno</th>
            <th>Descansos</th>
            <!--<th>D2</th>
            <th>D3</th>
            <th>D4</th>-->
            <th>V</th>
            <th>S</th>
            <th>D</th>
            <th>L</th>
            <th>M</th>
            <th>Mi</th>
            <th>J</th>
            <th>Observaciones</th>

        </tr>
    </thead>
    <tbody>";
        
        $num = 0;
        $valores=null;
        // Imprimir filas ordenadas
        
        
        $sqlx = mysqli_query($connection, $sql);
        $resultx=mysqli_num_rows($sqlx);
                    if($resultx>0){
                        while($data=mysqli_fetch_array($sqlx)){
        
            $num++;

            

            $status.="<tr>
            <th scope='row'>" . $num . "</th>
            <td> ".$data['ubicacion']."</td>
            <td> " . $data['supervisor'] . "</td>
            <td> " . $data['lugTrab'] . "</td>
            <td> " . $data['nemp'] . "</td>
            <td> " . str_replace(',', '', $data['nombre']) . "</td>
            <td> " . $data['salario'] . "</td>
            <td> " . $data['turno']."</td>


            <td> <input style='width: 80px;' disabled name='D1' type='text' style='text-align:right;' value='"  .$data['D1']. $data['D2'].$data['D3'].$data['D4']. "'/></td>
            <td> <select style='width: 50px;name='turno1' >".cambio($data['V']) . "'</select></td>
            <td> <select style='width: 50px;name='turno2' >" . cambio($data['S']) . "'</select></td>
            <td> <select style='width: 50px;name='turno3' >" . cambio($data['D']) . "'</select></td>
            <td> <select style='width: 50px;name='turno4' >" . cambio($data['L']) . "'</select></td>
            <td> <select style='width: 50px;name='turno5' >" . cambio($data['M']) . "'</select></td>
            <td> <select style='width: 50px;name='turno6' >" . cambio($data['Mi']) . "'</select></td>
            <td> <select style='width: 50px;name='turno7' >" . cambio($data['J']) . "'</select></td>

            <td> <input style='width: 300px;' name='observaciones' type='text' value='" . $data['comentario'] . "'/></td>
            
            </tr>";

                                 
          }
        
          
        }
        
    $status.="</tbody>
</table>";
    

$mensaje = array(
    'respuesta' => $status
);
    
echo json_encode($mensaje);		
