<?php
require_once('./../config.php');
$project_id = $_GET['project_id'] ?? '';
$period = date('Y-m-01');

// buscar si ya existe seguimiento del mes
$q = $conn->query("
    SELECT * FROM project_followups
    WHERE project_id = '$project_id'
    AND period = '$period'
");
$data = $q->fetch_assoc();
?>

<style>
#uni_modal .modal-footer{display:block;}
</style>

<div class="container-fluid">
<form id="followup-form">

<input type="hidden" name="project_id" value="<?= $project_id ?>">
<input type="hidden" name="period" value="<?= $period ?>">

<div class="form-group">
    <label>% Avance Planificado</label>
    <input type="number" name="planned_progress" class="form-control"
           min="0" max="100" required
           value="<?= $data['planned_progress'] ?? '' ?>">
</div>

<div class="form-group">
    <label>% Avance Real</label>
    <input type="number" name="real_progress" class="form-control"
           min="0" max="100" required
           value="<?= $data['real_progress'] ?? '' ?>">
</div>

<div class="form-group">
    <label>Comentario del Líder</label>
    <textarea name="comment" class="form-control" rows="4" required><?= $data['comment'] ?? '' ?></textarea>
</div>

</form>
</div>

<script>
$(function(){
    $('#uni_modal #followup-form').submit(function(e){
        e.preventDefault();
        start_loader();
        $.ajax({
            url:_base_url_+"projects/save_followup.php",
            data: new FormData($(this)[0]),
            cache:false,
            contentType:false,
            processData:false,
            method:'POST',
            dataType:'json',
            success:function(resp){
                if(resp.status == 'success'){
                    location.reload();
                }else{
                    alert_toast(resp.msg ?? "Error",'error');
                }
                end_loader();
            }
        })
    })
})
</script>

