<?php include('./config/db.php'); ?>
<?php 

$selPlan=(isset($_GET['selPlan']))?$_GET['selPlan']:"";
$action=(isset($_POST['action']))?$_POST['action']:"";
$dato=(isset($_GET['dato']))?$_GET['dato']:"";
$return=(isset($_GET['return']))?$_GET['return']:"";

switch($action){
    case "Volver":
        header("location:".$return);
        break;
    case "pdf":
        header('Location: actaPlanPdf.php?selPlan='.$selPlan);
        break;
}

$sql=$conexion->prepare("select fi.id, pp.nombrePlan, cli.nombre, act.detalle, fi.fechaRealizacion, fi.adjunto 
from formularioingreso fi inner join planprevencion pp on fi.planId=pp.id
inner join cliente cli on cli.id = fi.clienteId
inner join actividades act on act.id = fi.actividadId
where pp.id in (:planId) order by fi.fechaRealizacion asc");
$sql->bindParam(":planId",$selPlan, PDO::PARAM_INT);
$sql->execute();
$ingresos = $sql->fetchAll(PDO::FETCH_ASSOC);
?>
<style>
.align {
    text-align: right;      
}
</style>
<link rel="icon" type="image/png" href="./img/favicon.png" sizes="16x16">
<link rel="stylesheet" href="./css/bootstrap.min.css" />
<br/>
<div class="container">
<div class="card">
        <div class="row">
            <div class="col-md-12">
                &nbsp;
            </div>
        </div>
        <div class="row">
            <div class="col-md-4">
                &nbsp;
            </div>
            <div class="col-md-6">
                <h6><strong><u>
                    <?php 
                    $sql=$conexion->prepare("select nombrePlan from planprevencion where id=:id;");  
                    $sql->bindParam(":id",$selPlan);
                    $sql->execute();
                    $nomPlan = $sql->fetch(PDO::FETCH_LAZY);

                    echo $nomPlan['nombrePlan']; 
                    ?></u></strong>
                </h6>
            </div>
            <div class="col-md-2">
                
            </div>
            <div class="col-md-1">
                &nbsp;
            </div>
        </div>
        <div class="row">
            <div class="col-md-7">
                &nbsp;
            </div>
            <div class="col-md-3">
                
                    <h6><p class="align">Las Condes,&nbsp;&nbsp;<?php 
                    $today = date("Y-m-d H:i:s");  
                    echo date("d-m-Y",strtotime($today)); ?>.
                    </p></h6>
                
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-1">
                &nbsp;
            </div>
            <div class="col-md-9">
            El siguiente plan cuenta con las siguientes acciones ingresadas: 
                       
            </div>
        </div>
        <br/>
        <div class="row">
            <div class="col-md-1">
                
            </div>
            <div class="col-md-9">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Cliente</th>
                            <th>Actividad</th>
                            <th>F. realizaci&oacute;n</th>
                            <th>Adjunto</th>
                            <th>Instalaci&oacute;n</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        foreach($ingresos as $acta) { ?>
                        <tr>
                            <td><?php echo $acta['id'] ?></td>
                            <td><?php echo $acta['nombre'] ?></td>
                            <td><?php echo $acta['detalle'] ?></td>
                            <td><?php echo date("d-m-Y",strtotime($acta['fechaRealizacion']))?></td>
                            <td><?php echo $acta['adjunto'] ?></td>
                            <td>
                                <?php 
                                    $sql=$conexion->prepare("SELECT inst.id, inst.nombre as nomInsti FROM formularioingreso ing inner JOIN 
                                    formularioinstalacion ins on ins.formularioId = ing.id inner JOIN instalacion inst on inst.id = ins.instalacionId 
                                    where ing.id in (:id) order by ins.id asc;");
                                    $sql->bindParam(":id",$acta['id']);
                                    $sql->execute();
                                    $instalaciones = $sql->fetchAll(PDO::FETCH_ASSOC);
                                    foreach($instalaciones as $inst) { 
                                        echo ($inst['nomInsti']."<br>");
                                    }
                                ?>
                            </td>
                        </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>


        <div class="row">
            <div class="col-md-12">
                &nbsp;
            </div>
        </div>
        <div class="row">
            <div class="col-md-3">
                &nbsp;
            </div>       
            
            <div class="col-md-6">
                
                    <div class="btn-group pull-right" role="group" aria-label="">
                        <form method="post">
                            <input type="hidden" name="selPlan" id="selPlan" value="<?php echo $selPlan; ?>" >
                            <button type="submit" name="action" value="pdf" class="btn btn-outline-warning">Descargar pdf</button>&nbsp;
                            <!--button type="submit" name="action" value="Volver" class="btn btn-outline-info">Volver</button-->
                        </form>
                        <form method="post" action="reportePlan.php?pagina=1">
                            <input type="hidden" name="selPlan" id="selPlan" value="<?php echo $selPlan; ?>" >
                        <button type="submit"  value="Volver" class="btn btn-outline-info">Volver</button>
                </form>
                    </div>
                
                
            </div>

        </div>
        <br/>
    </div>
    <br/><br/>
</div>

