$chargeManager = new ChargeCommunManager($pdo);
 $typeChargeManager = new TypeChargeCommunManager($pdo);
 $criteria = htmlentities($_POST['criteria']);
 $resumeDetail = "";
 if ($criteria == "parDate") {
     $dateFrom = htmlentities($_POST['dateFrom']);
     $dateTo = htmlentities($_POST['dateTo']);
     $type = htmlentities($_POST['type']);
     if ($type == "Toutes") {
         $charges = $chargeManager->getChargesByDates($dateFrom, $dateTo);
         $totalCharges = number_format($chargeManager->getTotalByDates($dateFrom, $dateTo), 2, ',', ' ');
         $titreDocument = "Liste des charges communs entre : " . date('d/m/Y', strtotime($dateFrom)) . ' - ' . date('d/m/Y', strtotime($dateTo));
     } else {
         $charges = $chargeManager->getChargesByDatesByType($dateFrom, $dateTo, $type);
         $totalCharges = number_format($chargeManager->getTotalByDatesByType($dateFrom, $dateTo, $type), 2, ',', ' ');
         $titreDocument = "Liste des charges communs " . $typeChargeManager->getTypeChargeById($type)->nom() . " entre : " . date('d/m/Y', strtotime($dateFrom)) . ' - ' . date('d/m/Y', strtotime($dateTo));
     }
 } else {
     if ($criteria == "toutesCharges") {
         $charges = $chargeManager->getCharges();
         $totalCharges = number_format($chargeManager->getTotal(), 2, ',', ' ');
         $titreDocument = "Liste de toutes les charges communs";
         if (isset($_POST['type']) and (isset($_POST['source']) and $_POST['source'] == "charges-communs-type")) {
             $type = htmlentities($_POST['type']);
             $charges = $chargeManager->getChargesByType($type);
             $totalCharges = number_format($chargeManager->getTotalByType($type), 2, ',', ' ');
             $titreDocument = "Liste des charges communs de " . $typeChargeManager->getTypeChargeById($type)->nom();
         }
         if (isset($_POST['source']) and $_POST['source'] == "charges-communs-grouped") {
             $resumeDetail = htmlentities($_POST['resume-detaile']);
             if ($resumeDetail == "resume") {
                                            <th style="width: 50%">Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php 
    foreach ($charges as $charge) {
        ?>
      
                                        <tr class="charges">
                                            <td>
                                                <a class="btn mini btn-fixed-width btn-fixed-height" href="charges-communs-type.php?type=<?php 
        echo $charge->type();
        ?>
">
                                                    Charges <?php 
        echo $typeChargeManager->getTypeChargeById($charge->type())->nom();
        ?>
 
                                                </a>
                                            </td>
                                            <td class="hidden-phone"><?php 
        echo number_format($charge->montant(), 2, ',', ' ');
        ?>
</td>
                                        </tr> 
                                        <?php 
    }
    //end of loop
    ?>
                                        <tr>
                                            <td></td>
    } elseif (file_exists('controller/' . $myClass . '.php')) {
        include 'controller/' . $myClass . '.php';
    }
}
spl_autoload_register("classLoad");
include 'config.php';
include 'lib/pagination.php';
//classes loading end
session_start();
if (isset($_SESSION['userMerlaTrav']) and ($_SESSION['userMerlaTrav']->profil() == "admin" or $_SESSION['userMerlaTrav']->profil() == "consultant")) {
    //classManagers
    $chargeManager = new ChargeCommunManager($pdo);
    $typeChargeManager = new TypeChargeCommunManager($pdo);
    //
    $typeCharge = $_GET['type'];
    $nomTypeCharge = $typeChargeManager->getTypeChargeById($typeCharge)->nom();
    $charges = $chargeManager->getChargesByType($typeCharge);
    $total = number_format($chargeManager->getTotalByType($typeCharge), 2, ',', ' ');
    $typeCharges = $typeChargeManager->getTypeCharges();
    ?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <meta charset="utf-8" />
    <title>ImmoERP - Management Application</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />