<?php
$cpt_tmp = salaries::countTmpSalaries();

$json = salaries::createRapport();
file_put_contents(DIR_DATAS_JSON."tmp_salaries.json", $json["json"]);
$excelInfo = salaries::excelGetInProgress();

if(empty($json["excel"])){

?>

<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
    <h2 class="bd-title" id="content">
        <span>Traiter un fichier Excel : <?php echo $excelInfo["name"] ?> (Etape 2/2)</span>
    </h2>
</header>
<?php   
        echo core::filAriane(array(
            "current" => "Traiter un fichier Excel", 
            "arbo" => array( 
                "Salariés" => NULL,
                "Liste des salariés (base RH)" => "/",
                "Historique des chargements" => "/rh-historique-excel.html",
                "Traiter un fichier Excel" => "/rh-import-to-temp.html")
        )); 
?>
<br />
<div id="formFooter">
    <div class="alert alert-warning" role="alert" >Nous n'avons trouvez aucune donnée à traiter dans ce fichier.</div>
</div>

<?php
}
else {

    $jsonTarget = "/json.php?file=tmp_salaries";
    if(debug::isFile("debug")){
        debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
    } 
?>

<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
    <h2 class="bd-title" id="content">
        <span>Traiter un fichier Excel : <?php echo $excelInfo["name"] ?></span>
        <form style="position: absolute; right: 40px; margin-top: -40px;" method="post" action="/submit.php">
            <input type="hidden" name="from" value="rh-annule-import">
            <input type="hidden" name="id" value="<?php echo $excelInfo["id"] ?>">
            <button type="submit" style="margin-left:10px;" class="btn btn-outline-danger btn-sm" title="Annuler l'import">Annuler le traitement</button>
        </form>
    </h2>
</header>
<?php   
        echo core::filAriane(array(
            "current" => "Traiter un fichier Excel RH", 
            "arbo" => array( 
                "Salariés" => NULL,
                "Liste des salariés (base RH)" => "/",
                "Historique des chargements" => "/rh-historique-excel.html",
                "Traiter un fichier Excel RH" => "/rh-import-to-temp.html")
        )); 
?>
<div>
    <table
        id="table"
        class="table-striped table-hover table-sm" 
        data-page-size="25"
        data-toggle="table"
        data-show-columns="true"
        data-search="true"
        data-buttons-align="left"
        data-pagination="true"
        data-filter-control="true"
        data-flat="true"
        data-search="true"
        data-sort-name="cree"
        data-sort-order="desc"
        data-url="<?php echo $jsonTarget ?>">
        <thead>
            <tr>
                <th data-sortable="true" data-field="action" data-filter-control="select">Action</th>
                <th data-sortable="true" data-field="idLocal" data-filter-control="input">Id Capgemini</th>
                <th data-sortable="true" data-field="loginId" data-filter-control="input">Identifiant</th>
                <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
                <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
                <th data-sortable="true" data-field="jourEntree" data-filter-control="input">Entrée</th>
                <th data-sortable="true" data-field="contrat" data-filter-control="select">Statut Contrat</th>
                <th data-sortable="true" data-field="lieu" data-filter-control="select">Localité</th>
            </tr>
        </thead>
    </table> 
</div>

<form method="post" action="/submit.php" onsubmit="loading()">
    <input type="hidden" name="from" value="rh-temp-to-mysql">
    <input type="hidden" name="excel" value="<?php echo $json["excel"] ?>">
    <input class="btn btn-outline-primary btn-lg" style="width: 100%" type="submit" value="Valider la mise à jour des données">
</form>

<br />
<br />

<?php
}
?>
