function getavoirlist()
{
    $mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB);
    $query = "SELECT `avoirs`.`idavoir`,`avoirs`.`montant`,`avoirs`.`reste`,`avoirs`.`validation`,`avoirs`.`idfacture`,`avoirs`.`date`," . "`avoirs`.`obs`,`factures_cantine`.`datefacture`,`factures_cantine`.`datefacture`,`factures_cantine`.`montantfcp`," . "`factures_cantine`.`montanteuro`,`factures_cantine`.`duplicata` FROM `avoirs` INNER JOIN `factures_cantine` ON `avoirs`.`idfacture`=`factures_cantine`.`idfacture`" . "WHERE `avoirs`.`validation` = '0' ORDER BY date ASC, `idavoir`";
    $type = "cantine";
    $result = $mysqli->query($query);
    while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($row["duplicata"] == '0') {
            $pdf = "<img src=\"img/opdf.png\" alt=\"original\" class=\"ico\">";
        } else {
            $pdf = "<img src=\"img/dpdf.png\" alt=\"duplicata\" class=\"ico\">";
        }
        $output .= "<tr><td>" . trispace($row["montant"]) . " FCP</td><td>" . trispace($row["reste"]) . " FCP</td>" . "<td>Facture " . $row["communeid"] . " du " . french_date($row["datefacture"]) . " montant de ";
        $output .= trispace($row["montantfcp"]);
        $output .= " FCP (soit " . $row["montanteuro"] . "&euro;)</td><td><a href='createpdf.php?idfacture=" . $row['idfacture'] . "&type={$type}' target='_blank'>{$pdf}</a></td><td>" . french_date($row['date']) . "</td>" . "<td>" . $row['obs'] . "</td><td style=\"text-align:center\"><a href=\"javascript:validate('" . $row["idavoir"] . "',true)\">" . "<img src=\"img/checked.png\" alt=\"checked\" height=\"32\" style=\"border:0px\"></a> / <a href=\"javascript:validate('" . $row["idavoir"] . "',false)\">" . "<img src=\"img/close.png\" alt=\"close\" height=\"32\" style=\"border:0px\"></a></td></tr>";
    }
    return $output;
}
function getcantinelist($client, $range)
{
    $mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB);
    $query = "SELECT * FROM `factures_cantine` INNER JOIN `clients` ON `factures_cantine`.`idclient` = `clients`.`clientid` WHERE `factures_cantine`.`validation` = '1' AND `acceptation` = '1' AND `reglement` = '0' AND `bourse` = '0' {$range}{$client} ORDER BY `datefacture` ASC";
    $result = $mysqli->query($query);
    while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($row["duplicata"] == '0') {
            $pdf = "<img src=\"img/opdf.png\" alt=\"original\" class=\"ico\">";
        } else {
            $pdf = "<img src=\"img/dpdf.png\" alt=\"duplicata\" class=\"ico\">";
        }
        $datef = $row["datefacture"];
        $dayslate = strtotime("now") - strtotime($datef);
        $dayslate = floor($dayslate / 86400);
        $type = 'cantine';
        $enfant_prenom = "<br/>" . getEnfantPrenom($row['idfacture']);
        $relance_date = getRelance($row['idfacture']);
        if (isset($relance_date)) {
            $relance_date_fr = french_date($relance_date);
            $titlerelance = "Derni&egrave;re relance le " . $relance_date_fr;
        } else {
            $relance_date_fr = "";
            $titlerelance = "";
        }
        $output .= "<tr><td>{$type}{$enfant_prenom}</td><td><a href='clients.php?edit=" . $row["clientid"] . "&hideerrors=1'>" . $row["clientcivilite"] . " " . strtoupper(htmlentities($row["clientnom"])) . " " . strtoupper(htmlentities($row["clientprenom"])) . " " . strtoupper(htmlentities($row["clientprenom2"])) . "</a></td>" . "<td>Facture " . $row["communeid"] . " du " . french_date($row["datefacture"]) . " montant de ";
        $output .= trispace($row["montantfcp"]);
        $output .= " FCP (soit " . $row["montanteuro"] . "&euro;)</td><td><a href='createpdf.php?idfacture=" . $row['idfacture'] . "&type={$type}' target='_blank'>{$pdf}</a></td>" . "<td class='center'>{$dayslate} jours</td><td>{$relance_date_fr}<br/><a href='javascript:relance_warning(\"{$relance_date_fr}\",\"create_relance.php?idfacture=" . $row['idfacture'] . "&type={$type}&table=factures_cantine&montant=" . $row["montantfcp"] . "&communeid=" . $row["communeid"] . "&date=" . $row["datefacture"] . "&relancedate={$relance_date}\");'><img src='img/gmail.png' title='{$titlerelance}'/></a></td></tr>";
        $ar_ids[] .= $row["idfacture"];
    }
    $mysqli->close();
    //return $output;
    //print_r($ar_ids);
    return array($output, $ar_ids);
}
function getcantinelist($client)
{
    $mysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB);
    $query = "SELECT * FROM `" . DB . "`.`factures_cantine` INNER JOIN `clients` ON `factures_cantine`.`idclient` = `clients`.`clientid` WHERE `factures_cantine`.`validation` = '1' AND `acceptation` = '1' AND `reglement` = '0'{$client}";
    $result = $mysqli->query($query);
    while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($row["duplicata"] == '0') {
            $pdf = "<img src=\"img/opdf.png\" alt=\"original\" class=\"ico\">";
        } else {
            $pdf = "<img src=\"img/dpdf.png\" alt=\"duplicata\" class=\"ico\">";
        }
        $type = 'cantine';
        $enfant_prenom = "<br/>" . getEnfantPrenom($row['idfacture']);
        $output .= "<tr><td>{$type}{$enfant_prenom}</td><td><a href='clients.php?edit=" . $row["clientid"] . "&hideerrors=1'>" . $row["clientcivilite"] . " " . strtoupper(htmlentities($row["clientnom"])) . " " . strtoupper(htmlentities($row["clientprenom"])) . " " . strtoupper(htmlentities($row["clientprenom2"])) . "</td>" . "<td>Facture " . $row["communeid"] . " du " . french_date($row["datefacture"]) . " montant de ";
        $output .= trispace($row["montantfcp"]);
        $output .= " FCP (soit " . $row["montanteuro"] . "&euro;)</a></td><td><a href='createpdf.php?idfacture=" . $row['idfacture'] . "&type={$type}' target='_blank'>{$pdf}</a></td>" . "<td class='center'><a href=\"javascript:devalidate('{$type}','" . $row["idfacture"] . "')\"><img src=\"img/close.png\" alt=\"close\" height=\"32\" style=\"border:0px\"></a></td></tr>";
    }
    return $output;
}