require_once NOALYSS_INCLUDE . '/class_fiche.php';
$f_id = HtmlInput::default_value_request("f_id", "-");
if ($f_id == "-") {
    throw new Exception('Invalid parameter');
}
require_once NOALYSS_INCLUDE . '/class_dossier.php';
$gDossier = dossier::id();
/* Admin. Dossier */
$cn = new Database($gDossier);
$Fiche = new Fiche($cn, $f_id);
$qcode = $Fiche->get_quick_code();
header('Content-type: application/csv');
header('Pragma: public');
header('Content-Disposition: attachment;filename="fiche-' . $qcode . '.csv"', FALSE);
$Fiche->getName();
list($array, $tot_deb, $tot_cred) = $Fiche->get_row_date($_GET['from_periode'], $_GET['to_periode'], $_GET['ople']);
if (count($Fiche->row) == 0) {
    echo "Aucune donnée";
    return;
}
if (!isset($_REQUEST['oper_detail'])) {
    echo '"Qcode";' . "\"Date\";" . "\"n° pièce\";" . "\"Code interne\";" . '"Code journal";' . '"Nom journal";' . "\"Description\";" . "\"Débit\";" . "\"Crédit\";" . "\"Prog.\";" . "\"Let.\"";
    printf("\n");
    $progress = 0;
    $current_exercice = "";
    $tot_deb = 0;
    $tot_cred = 0;
    bcscale(2);
    foreach ($Fiche->row as $op) {
        /*
         * separation per exercice