<?php
session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$tblName = "tblReport" . $pageSequence;
$btAdd = "btnAdd" . $pageSequence;
$btDel = "btnDel" . $pageSequence;
$btDelObj = "btnDelObj" . $pageSequence;
$dataSection = "dataSection" . $pageSequence;
$frmName = "form" . $pageSequence;
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir'] . "core.php");

$svaTool = new svaTool();

$errorCode = 0;

$password = NULL;
$confPasswd = NULL;

$startDateTime = addslashes($_REQUEST['startDateTime']);
$endDateTime = addslashes($_REQUEST['endDateTime']);
$userId = addslashes($_REQUEST['userId']);
$status = addslashes($_REQUEST['statut']);
$granularity = $_REQUEST['granularity'];
$teamId = addslashes($_REQUEST['teamId']);

$res = $dba->getReclamationOutSla($startDateTime, $endDateTime, $granularity, $status, $_SESSION['cfg']['max.sql.results.elements']);
$data = "";

$cmpt = 1;
$total = count($res);


//CONVERTIR S EN MOIS JOUR HEUR MIN S
function convertSecondsToMJDHMS($value) {
    $months = floor($value / (30 * 24 * 3600));
    $restantAPresMonths = $value % (30 * 24 * 3600);

    $days = floor($restantAPresMonths / (24 * 3600));
    $RestantApresDays = $restantAPresMonths % (24 * 3600);

    $hours = floor($RestantApresDays / 3600);
    $RestantApresHours = $RestantApresDays % 3600;

    $minutes = floor($RestantApresHours / 60);
    $seconds = $RestantApresHours % 60;

    $result = '';
    if ($months > 0) {
        $result .= $months . 'Mois ';
    }
    if ($days > 0) {
        $result .= $days . 'J ';
    }
    if ($hours > 0) {
        $result .= $hours . 'H ';
    }
    if ($minutes > 0) {
        $result .= $minutes . 'Min ';
    }
    if ($seconds > 0 || ($months == 0 && $days == 0 && $hours == 0 && $minutes == 0)) {
        $result .= $seconds . 'S';
    }

    return trim($result);
}
?>

<div class="btn-group">

    <button class="btn  btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i> Exporter</button>
    <ul class="dropdown-menu exp-drop" role="menu">
        <li>
            <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'excel', escape: 'false'});" > ,
                <img src="assets/dist/img/xls.png" width="24" alt="logo"> XLS</a>
        </li>
        <li>
            <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'csv', escape: 'false'});"> 
                <img src="assets/dist/img/csv.png" width="24" alt="logo"> CSV</a>
        </li>
        <li>
            <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'txt', escape: 'false'});"> 
                <img src="assets/dist/img/txt.png" width="24" alt="logo"> TXT</a>
        </li>

        <li class="divider"></li> 
    </ul>

</div>

<!-- ./Plugin content:powerpoint,txt,pdf,png,word,xl -->
<div class="table-responsive">

    <table id="<?php echo $tblName; ?>"  width="100%" height="100%" class="table table-striped table-bordered" >
        <thead>
            <tr>
                <th>Date de création</th>                          
                <th>Numero ticket</th>
                <th>Nom </th>               
                <th>Durée normale de traitement</th>
                <th>Durée de traitement de la reclamation</th>
                <th>Status</th>
            </tr>
        </thead>
        
        
         <tbody>
            <?php for ($i = 0; $i < $total; $i++) { ?>
                
                <tr>
                    <td><?php echo $res[$i]['periode']; ?></td>
                    <td><?php echo $res[$i]['ticket_number_v']; ?></td>
                    <td><?php echo $res[$i]['last_name_v']; ?></td>
                    <td><?php echo convertSecondsToMJDHMS($res[$i]['sla_duration_to_s']); ?></td>
                    <td><?php echo convertSecondsToMJDHMS($res[$i]['traitement_duration']); ?></td>
                    <td><?php echo $res[$i]['status_name']; ?></td>
                </tr>

            <?php } ?>
        </tbody>
        
    </table>

</div>

<script type="text/javascript" >
    $(document).ready(function () {

        var dataUrl = "<?php echo $currentBaseDir; ?>/return_json_default.php?json=[]";
        table = $('#<?php echo $tblName; ?>').DataTable();

    });
</script>
