//
// With Detail per item which is possible only for VEN or ACH
//
if ($get_option == 2) {
    if ($jrn_type != 'ACH' && $jrn_type != 'VEN' || $Jrn->id == 0) {
        $get_option = 0;
    } else {
        switch ($jrn_type) {
            case 'VEN':
                $ledger = new Acc_Ledger_Sold($cn, $get_jrn);
                $ret_detail = $ledger->get_detail_sale($get_from_periode, $get_to_periode);
                $a_heading = Acc_Ledger_Sold::heading_detail_sale();
                break;
            case 'ACH':
                $ledger = new Acc_Ledger_Purchase($cn, $get_jrn);
                $ret_detail = $ledger->get_detail_purchase($get_from_periode, $get_to_periode);
                $a_heading = Acc_Ledger_Purchase::heading_detail_purchase();
                break;
            default:
                die(__FILE__ . ":" . __LINE__ . 'Journal invalide');
                break;
        }
        if ($ret_detail == null) {
            return;
        }
        $nb = Database::num_row($ret_detail);
        $output = fopen("php://output", "w");
        for ($i = 0; $i < $nb; $i++) {
            $row = Database::fetch_array($ret_detail, $i);
            if ($i == 0) {
                fputcsv($output, $a_heading, ';');
 /**
  *@brief export the ledger in  PDF
  */
 function export()
 {
     bcscale(2);
     $jrn_type = $this->ledger->get_type();
     switch ($jrn_type) {
         case 'VEN':
             $ledger = new Acc_Ledger_Sold($this->cn, $this->ledger->jrn_def_id);
             $ret_detail = $ledger->get_detail_sale($_GET['from_periode'], $_GET['to_periode']);
             break;
         case 'ACH':
             $ledger = new Acc_Ledger_Purchase($this->cn, $this->ledger->jrn_def_id);
             $ret_detail = $ledger->get_detail_purchase($_GET['from_periode'], $_GET['to_periode']);
             break;
         default:
             die(__FILE__ . ":" . __LINE__ . 'Journal invalide');
             break;
     }
     if ($ret_detail == null) {
         return;
     }
     $nb = Database::num_row($ret_detail);
     $this->SetFont('DejaVu', '', 6);
     $internal = "";
     $this->SetFillColor(220, 221, 255);
     $high = 4;
     for ($i = 0; $i < $nb; $i++) {
         $row = Database::fetch_array($ret_detail, $i);
         if ($internal != $row['jr_internal']) {
             // Print the general info line width=270mm
             $this->LongLine(20, $high, $row['jr_date'], 1, 'L', true);
             $this->Cell(20, $high, $row['jr_internal'], 1, 0, 'L', true);
             $this->LongLine(50, $high, $row['quick_code'] . " " . $row['tiers_name'], 1, 'L', true);
             $this->LongLine(80, $high, $row['jr_comment'], 1, 'L', true);
             $this->Cell(20, $high, nbm($row['htva']), 1, 0, 'R', true);
             $this->Cell(20, $high, nbm($row['tot_tva_np']), 1, 0, 'R', true);
             $this->Cell(20, $high, "", 1, 0, 'R', true);
             $this->Cell(20, $high, nbm($row['tot_vat']), 1, 0, 'R', true);
             $sum = bcadd($row['htva'], $row['tot_vat']);
             $sum = bcsub($sum, $row['tot_tva_np']);
             $this->Cell(20, $high, nbm($sum), 1, 0, 'R', true);
             $internal = $row['jr_internal'];
             $this->Ln(6);
             // on the first line, the code for each column is displaid
             if ($this->show_col == true) {
                 //
                 // Header detail
                 $this->LongLine(30, $high, 'QuickCode');
                 $this->Cell(30, $high, 'Poste');
                 $this->LongLine(70, $high, 'Libellé');
                 $this->Cell(20, $high, 'Prix/Unit', 0, 0, 'R');
                 $this->Cell(20, $high, 'Quant.', 0, 0, 'R');
                 $this->Cell(20, $high, 'HTVA', 0, 0, 'R');
                 $this->Cell(20, $high, 'TVA NP', 0, 0, 'R');
                 $this->Cell(20, $high, 'Code TVA');
                 $this->Cell(20, $high, 'TVA', 0, 0, 'R');
                 $this->Cell(20, $high, 'TVAC', 0, 0, 'R');
                 $this->Ln(6);
                 $this->show_col = false;
             }
         }
         // Print detail sale / purchase
         $this->LongLine(30, $high, $row['j_qcode']);
         $this->Cell(30, $high, $row['j_poste']);
         $comment = $row['j_text'] == "" ? $row['item_name'] : $row['j_text'];
         $this->LongLine(70, $high, $comment);
         $this->Cell(20, $high, nbm($row['price_per_unit']), 0, 0, 'R');
         $this->Cell(20, $high, nbm($row['quantity']), 0, 0, 'R');
         $this->Cell(20, $high, nbm($row['price']), 0, 0, 'R');
         $this->Cell(20, $high, nbm($row['vat_sided']), 0, 0, 'R');
         $this->Cell(20, $high, $row['vat_code'] . " " . $row['tva_label']);
         $this->Cell(20, $high, nbm($row['vat']), 0, 0, 'R');
         $sum = bcadd($row['price'], $row['vat']);
         $this->Cell(20, $high, nbm($sum), 0, 0, 'R');
         $this->Ln(6);
     }
 }