<?php

use Fpdf\Fpdf;

require('fpdf2.php');

function compta_ecran()
{
  global $Detail, $intervalle, $Detail1, $Detail2, $Detail3, $Detail4, $Detail5, $Detail6, $Detail7, $Detail8, $Detail9;
  set_time_limit(600);
  if (!isset($Detail)) {
    $Detail = 0;
  }
  if (!isset($Detail1)) {
    $Detail1 = 0;
  }
  if (!isset($Detail2)) {
    $Detail2 = 0;
  }
  if (!isset($Detail3)) {
    $Detail3 = 0;
  }
  if (!isset($Detail4)) {
    $Detail4 = 0;
  }
  if (!isset($Detail5)) {
    $Detail5 = 0;
  }
  if (!isset($Detail6)) {
    $Detail6 = 0;
  }
  if (!isset($Detail7)) {
    $Detail7 = 0;
  }
  $nb_caisses = Config::getNbCaisse();
  //----------------------------------------//
  //           Date ou période              //
  //                                        //
  //----------------------------------------//
  if ($intervalle[5] != 0) {
    echo "<BIG>Comptabilité du " . $intervalle[0] . "." . $intervalle[1] . "." . $intervalle[2] . " au " . $intervalle[3] . "." . $intervalle[4] . "." . $intervalle[5] . "</BIG>\n";
  } else {
    echo "<BIG>Comptabilité du " . $intervalle[0] . "." . $intervalle[1] . "." . $intervalle[2] . "</BIG>\n";
  }
  //----------------------------------------//
  //           Montant en caisse            //
  //           ouverture cloture            //
  //----------------------------------------//
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $requette = "SELECT * FROM caisse" . ID_GARAGE . " WHERE Date<'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . "' AND NoCaisse=$cpt_caisse ORDER BY Date DESC LIMIT 0, 1";
    $resultat = Connection::executeRawQueryWithfetchAll($requette);
    if ($ligne = $resultat[0]) {
      $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . $ligne['Date'] . " 23:59:59' AND Date<'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 00:00:00' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      $somme = 0;
      foreach ($resultat2 as $ligne2) {
        $somme += $ligne2['Somme'];
      }
      $total = round($ligne['Montant'] + $somme, 2);
      $tab_caisse_ouverture[$cpt_caisse] = $total;
      if ($intervalle[5] != 0) {
        $tmp_int[0] = $intervalle[3];
        $tmp_int[1] = $intervalle[4];
        $tmp_int[2] = $intervalle[5];
        //	  	$requette2="SELECT * FROM dbcash".ID_GARAGE." WHERE Date>'".$ligne['Date']." 23:59:59' AND Date<='".substr(Decode_Entree_Type($tmp_int,2),0,10)." 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
        $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 23:59:59' AND Date<='" . substr(Decode_Entree_Type($tmp_int, 2), 0, 10) . " 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      } else {
        //	    $requette2="SELECT * FROM dbcash".ID_GARAGE." WHERE Date>'".$ligne['Date']." 23:59:59' AND Date<='".substr(Decode_Entree_Type($intervalle,2),0,10)." 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
        $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 23:59:59' AND Date<='" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      }
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      $somme = 0;
      foreach ($resultat2 as $ligne2) {
        $somme += $ligne2['Somme'];
      }
      $total = round($ligne['Montant'] + $somme, 2);
      $tab_caisse_cloture[$cpt_caisse] = $total;
    }
  }
  //****************************************//
  echo "<TABLE border=1>\n<TR><TH>Montant en caisse</TH>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TD>caisse $cpt_caisse</TD>";
  }
  echo "</TR>\n";
  echo "<TR><TD>ouverture</TD>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TD>" . $tab_caisse_ouverture[$cpt_caisse] . "</TD>";
  }
  echo "</TR>\n";
  echo "<TR><TD>cloture</TD>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TD>" . $tab_caisse_cloture[$cpt_caisse] . "</TD>";
  }
  echo "</TR>\n";
  echo "<TR><TH>diff</TH>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH>" . ($tab_caisse_cloture[$cpt_caisse] - $tab_caisse_ouverture[$cpt_caisse]) . "</TH>";
  }
  echo "</TR>\n";
  echo "</TABLE><BR>\n";
  //----------------------------------------//
  //           Mouvements d'argent          //
  //           banques et caisses           //
  //----------------------------------------//
  $acompteplus = 0;
  $acompteplus_achat = 0;
  $detail_acompte = "<TABLE border=1>\n<TR><TH>Date</TH><TH>acompte entree</TH><TH>acompte sortie</TH><TH>NoCommande</TH></TR>\n";
  $detail_acompte_achat = "<TABLE border=1>\n<TR><TH>Date</TH><TH>acompte entree</TH><TH>acompte sortie</TH><TH>NoCommande</TH></TR>\n";
  for ($cpt_caisse = 0; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $somme_caisse_vente[$cpt_caisse] = 0;
    $somme_caisse_vente_cc[$cpt_caisse] = 0;
    $resultat = ModePayement::getModePayementsByNoCaisse($cpt_caisse);
    foreach ($resultat as $ligne) {
      $cpt_mode = $ligne['NoMode'];
      $detail_mouvement[$cpt_caisse][$cpt_mode] = "<BIG>Caisse $cpt_caisse " . $ligne['Description'] . "</BIG><BR>\n<TABLE border=1>\n<TR><TH>Date</TH><TH>Somme</TH><TH>No commande</TH></TR>\n";
      $somme_mouvement[$cpt_caisse][$cpt_mode] = 0;
      $somme_vente[$cpt_caisse][$cpt_mode] = 0;
      $somme_achat[$cpt_caisse][$cpt_mode] = 0;
      $somme_transfert[$cpt_caisse][$cpt_mode] = 0;
      $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE " . Requette_Recherche("Date", 18, $intervalle) . " AND NoCaisse=$cpt_caisse AND ModePayement=$cpt_mode ORDER BY Date";
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      foreach ($resultat2 as $ligne2) {
        $detail_mouvement[$cpt_caisse][$cpt_mode] .= "<TR><TD>" . Cree_Entree_Type("", 18, 0, $ligne2['Date'], AFFICHAGE) . "</TD><TD>" . $ligne2['Somme'] . "</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
        $somme_mouvement[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
        if ($ligne3 = Commande::getCommandeByNoCommande($ligne2['NoFacture'])) {
          switch ($ligne3['Genre']) {
            case 'F':
            case 'G':
            case 'N':
              $somme_vente[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              $requette4 = "SELECT * FROM commande" . ID_GARAGE . " WHERE NoCommande=" . $ligne2['NoFacture'] . " AND Paye='O' AND DatePayement='" . substr($ligne2['Date'], 0, 10) . "'";
              $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
              if ($ligne4 = $requette4[0]) {
              } else {
                $detail_acompte .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne2['Date'], AFFICHAGE) . "</TD><TD>" . $ligne2['Somme'] . "</TD><TD>0</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
                $acompteplus += $ligne2['Somme'];
              }
              break;
            case 'C':
            case 'R':
            case 'A':
            case 'V':
              $somme_achat[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              $requette4 = "SELECT * FROM commande" . ID_GARAGE . " WHERE NoCommande=" . $ligne2['NoFacture'] . " AND Paye='O' AND DatePayement='" . substr($ligne2['Date'], 0, 10) . "'";
              $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
              if ($ligne4 = $requette4[0]) {
              } else {
                $detail_acompte_achat .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne2['Date'], AFFICHAGE) . "</TD><TD>" . -$ligne2['Somme'] . "</TD><TD>0</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
                $acompteplus_achat -= $ligne2['Somme'];
              }
              break;
            case 'T':
              $somme_transfert[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              break;
          }
        } else {
          $somme_vente[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
        }
      }
      $somme_caisse_vente[$cpt_caisse] += $somme_vente[$cpt_caisse][$cpt_mode];
      if ($ligne['Type'] == 1) {
        $somme_caisse_vente_cc[$cpt_caisse] += $somme_vente[$cpt_caisse][$cpt_mode];
      }
      $detail_mouvement[$cpt_caisse][$cpt_mode] .= "<TR><TH colspan=3><BIG>" . $somme_mouvement[$cpt_caisse][$cpt_mode] . "  vente " . $somme_vente[$cpt_caisse][$cpt_mode] . "  achat " . $somme_achat[$cpt_caisse][$cpt_mode] . "  transferts " . $somme_transfert[$cpt_caisse][$cpt_mode] . "</BIG></TH></TR>\n";
      $detail_mouvement[$cpt_caisse][$cpt_mode] .= "</TABLE>\n";
      //	  echo $detail_mouvement[$cpt_caisse][$cpt_mode];
    }
  }
  //****************************************//
  echo "<TABLE><TR><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH>Mouvement vente</TH>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH>caisse $cpt_caisse</TH>";
  }
  echo "<TH>Total</TH></TR>\n";
  $grand_tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(1);
  foreach ($resultat as $ligne) {
    $tot = 0;
    echo "<TR><TH>" . $ligne['Description'] . "</TH>";
    for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
      echo "<TD>" . $somme_vente[$cpt_caisse][$ligne['NoMode']] . "</TD>";
      $tot += $somme_vente[$cpt_caisse][$ligne['NoMode']];
      $grand_tot += $somme_vente[$cpt_caisse][$ligne['NoMode']];
    }
    echo "<TH>" . $tot . "</TH></TR>\n";
  }
  echo "<TR><TH>Total carte de crédit</TH>";
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH>" . $somme_caisse_vente_cc[$cpt_caisse] . "</TH>";
    $tot += $somme_caisse_vente_cc[$cpt_caisse];
  }
  echo "<TH><BIG>$tot</BIG></TH></TR>";
  echo "<TR><TH><BIG>Total</BIG></TH>";
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH><BIG>" . $somme_caisse_vente[$cpt_caisse] . "</BIG></TH>";
    $tot += $somme_caisse_vente[$cpt_caisse];
  }
  echo "<TH bgcolor='yellow'><BIG>$grand_tot</BIG></TH></TR>";
  echo "</TABLE><BR>\n";
  echo "</TD><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH colspan=2>Mouvement banque vente</TH></TR>\n";
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    echo "<TR><TH>" . $ligne['Description'] . "</TH><TD>" . $somme_vente[0][$ligne['NoMode']] . "</TD></TR>\n";
    $tot += $somme_vente[0][$ligne['NoMode']];
  }
  echo "<TR><TH><BIG>Total</BIG></TH><TH bgcolor='yellow'><BIG>$tot</BIG></TH></TR>\n";
  echo "</TABLE><BR>\n";
  echo "<TABLE border=1><TR><TH><BIG>Tot mouvement vente banque et caisses</BIG></TH><TH bgcolor='yellow'><BIG>" . ($grand_tot + $tot) . "</BIG></TH></TR></TABLE>\n";
  echo "</TD></TR>\n";
  echo "<TR><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH>Mouvement achat</TH>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH>caisse $cpt_caisse</TH>";
  }
  echo "<TH>Total</TH></TR>\n";
  $ligne = ModePayement::getModePayementsByNoModeAndNoCaisse(1, 1);
  echo "<TR><TH>" . $ligne['Description'] . "</TH>";
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TD>" . $somme_achat[$cpt_caisse][1] . "</TD>";
    $tot += $somme_achat[$cpt_caisse][1];
  }
  echo "<TH bgcolor='#ff8000'><BIG>" . $tot . "</BIG></TH></TR>";
  $grand_tot = $tot;
  echo "</TABLE><BR>\n";
  echo "</TD><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH colspan=2>Mouvement banque achat</TH></TR>\n";
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    echo "<TR><TH>" . $ligne['Description'] . "</TH><TD>" . $somme_achat[0][$ligne['NoMode']] . "</TD></TR>\n";
    $tot += $somme_achat[0][$ligne['NoMode']];
  }
  echo "<TR><TH><BIG>Total</BIG></TH><TH bgcolor='#ff8000'><BIG>$tot</BIG></TH></TR>\n";
  echo "</TABLE><BR>\n";
  echo "<TABLE border=1><TR><TH><BIG>Tot mouvement achat banque et caisses</BIG></TH><TH bgcolor='#ff8000'><BIG>" . ($grand_tot + $tot) . "</BIG></TH></TR></TABLE>\n";
  echo "</TD></TR>\n";
  echo "<TR><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH>Transfert cash</TH>";
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TH>caisse $cpt_caisse</TH>";
  }
  echo "<TH>Total</TH></TR>\n";
  $ligne = ModePayement::getModePayementsByNoModeAndNoCaisse(1, 1);
  echo "<TR><TH>" . $ligne['Description'] . "</TH>";
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    echo "<TD>" . $somme_transfert[$cpt_caisse][1] . "</TD>";
    $tot += $somme_transfert[$cpt_caisse][1];
  }
  echo "<TH><BIG>" . $tot . "</BIG></TH></TR>";
  echo "</TABLE><BR>\n";
  echo "</TD><TD valign='top'>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH colspan=2>Transfert banque</TH></TR>\n";
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    echo "<TR><TH>" . $ligne['Description'] . "</TH><TD>" . $somme_transfert[0][$ligne['NoMode']] . "</TD></TR>\n";
    $tot += $somme_transfert[0][$ligne['NoMode']];
  }
  echo "<TR><TH><BIG>Total</BIG></TH><TH><BIG>$tot</BIG></TH></TR>\n";
  echo "</TABLE><BR>\n";
  echo "</TD></TR></TABLE>\n";
  //----------------------------------------//
  //          Detail articles vente         //
  //          TVA, GM, TVA marges           //
  //----------------------------------------//
  $detail_vente_articles = "<TABLE border=1>\n<TR><TH>NoCommande</TH><TH>NoClient</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $detail_tva_marges = "<TABLE border=1><TR><TH>NoCommande</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $somme_detail_vente_articles = 0;
  $somme_detail_tva_marges = 0;
  $acomptemoin = 0;
  $tax_vente = array();
  $tax_marges = array();
  $total_vente_gm_tva = array();
  $requette = "SELECT * FROM commande" . ID_GARAGE . " WHERE (Genre='F' OR Genre='N' OR Genre='G') AND Paye='O' AND " . Requette_Recherche("DatePayement", 2, $intervalle) . " ORDER BY DatePayement";
  $resultat = Connection::executeRawQueryWithfetchAll($requette);
  foreach ($resultat as $ligne) {
    if ($ligne['Genre'] == 'N')
      $pos = false;
    else
      $pos = true;
    $resultat2 = DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'] . ' 00:00:00');;
    foreach ($resultat2 as $ligne2) {
      $acomptemoin += $ligne2['Somme'];
      //	  $acomptemoin=712;
      //	  if($pos) $acomptemoin+=$ligne2['Somme']; else $acomptemoin-=$ligne2['Somme'];
      $detail_acompte .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE) . "</TD><TD>0</TD><TD>" . $ligne2['Somme'] . "</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
    }
    $resultat2 = CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
    foreach ($resultat2 as $ligne2) {
      if ($ligne2['TypeData'] == 0) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        $detail_vente_articles .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne['NoClient'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>";
        if ($pos) $detail_vente_articles .= $ligne2['PrixMulti'];
        else $detail_vente_articles .= (-$ligne2['PrixMulti']);
        $detail_vente_articles .= "</TD></TR>";
        if ($pos) $somme_detail_vente_articles += $ligne2['PrixMulti'];
        else $somme_detail_vente_articles -= $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_vente)) {
          $tax_vente["$tva2"] = 0;
        }
        if ($pos) $tax_vente["$tva2"] += $ligne2['PrixMulti'];
        else $tax_vente["$tva2"] -= $ligne2['PrixMulti'];
        //		}
        if (!array_key_exists("$tva2", $total_vente_gm_tva)) {
          $total_vente_gm_tva["$tva2"] = array();
          for ($cpt = 0; $cpt < 300; $cpt++) {
            $total_vente_gm_tva["$tva2"][$cpt] = 0.0;
          }
        }
        if ($pos) $total_vente_gm_tva["$tva2"][$ligne2['GM']] += $ligne2['PrixMulti'];
        else $total_vente_gm_tva["$tva2"][$ligne2['GM']] -= $ligne2['PrixMulti'];
      }
      if ($ligne2['TypeData'] == 3) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        $detail_tva_marges .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>";
        if ($pos) $detail_tva_marges .= $ligne2['PrixMulti'];
        else $detail_tva_marges .= (-$ligne2['PrixMulti']);
        $detail_tva_marges .= "</TD></TR>";
        if ($pos) $somme_detail_tva_marges += $ligne2['PrixMulti'];
        else $somme_detail_tva_marges -= $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_marges)) {
          $tax_marges["$tva2"] = 0;
        }
        if ($pos) $tax_marges["$tva2"] += $ligne2['PrixMulti'];
        else $tax_marges["$tva2"] -= $ligne2['PrixMulti'];
        //		}
      }
    }
  }
  $acomptediff = $acompteplus - $acomptemoin;
  $detail_acompte .= "<TR><TH>Total</TH><TH>$acompteplus</TH><TH>$acomptemoin</TH><TH>diff $acomptediff</TH></TR></TABLE>\n";
  $detail_vente_articles .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_vente_articles</TH></TR></TABLE>\n";
  $detail_tva_marges .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_tva_marges</TH></TR></TABLE>\n";
  //****************************************//
  echo "<BIG>Comptes TVA Vente</BIG><BR>\n";
  array_multisort($tax_vente, SORT_ASC, SORT_NUMERIC);
  echo "<TABLE border=1>\n";
  echo "<TR>";
  foreach ($tax_vente as $taux => $somme) {
    echo "<TH>$taux %</TH><TH>tax $taux %</TH>";
  }
  echo "<TH>Total</TH><TH>Total tax</TH>";
  echo "</TR>\n";
  echo "<TR>";
  $tot = 0;
  $tot_tax = 0;
  $somme_total_vente_gm_tva = array();
  foreach ($tax_vente as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    echo "<TH>" . $somme . "</TH><TH>" . Arrondi_2_Dec($somme * (1 - (1 / ((100 + $taux) / 100)))) . "</TH>";
  }
  $grand_tot = $tot;
  echo "<TH bgcolor='yellow'><BIG>$tot</BIG></TH><TH>" . Arrondi_2_Dec($tot_tax) . "</TH>";
  echo "</TR>\n";
  echo "</TABLE><BR>\n";
  echo "<BIG>TVA des marges véhicule occasion</BIG><BR>\n";
  array_multisort($tax_marges, SORT_ASC, SORT_NUMERIC);
  echo "<TABLE border=1>\n";
  echo "<TR>";
  foreach ($tax_marges as $taux => $somme) {
    echo "<TH>$taux %</TH><TH>tax $taux %</TH>";
  }
  echo "<TH>Total</TH><TH>Total tax</TH>";
  echo "</TR>\n";
  echo "<TR>";
  $tot = 0;
  $tot_tax = 0;
  $somme_total_vente_gm_tva = array();
  foreach ($tax_marges as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    echo "<TH>" . $somme . "</TH><TH>" . Arrondi_2_Dec($somme * (1 - (1 / ((100 + $taux) / 100)))) . "</TH>";
  }
  echo "<TH>$tot</TH><TH>" . Arrondi_2_Dec($tot_tax) . "</TH>";
  echo "</TR>\n";
  echo "</TABLE><BR>\n";
  echo "<BIG>Payement partiels vente</BIG><BR>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH>&nbsp;</TH><TH>Entrée</TH><TH>Sortie</TH><TH>Différence</TH></TR>\n";
  echo "<TR><TD>Montant TTC</TD><TD>$acompteplus</TD><TD>$acomptemoin</TD><TD bgcolor='yellow'>$acomptediff</TD></TR>\n";
  echo "<TR><TD>Tax 7.6 %</TD><TD>" . Arrondi_2_Dec($acompteplus * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD><TD>" . Arrondi_2_Dec($acomptemoin * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD><TD>" . Arrondi_2_Dec($acomptediff * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD></TR>\n";
  echo "</TABLE><BR>\n";
  $grand_tot += $acomptediff;
  echo "<TABLE border=1><TR><TH>Total chiffre affaires et payements partiels</TH><TH bgcolor='yellow'><BIG>$grand_tot</BIG></TH></TR></TABLE><BR>\n";

  //----------------------------------------//
  //          Detail articles achat         //
  //          TVA, GM                       //
  //----------------------------------------//
  $detail_achat_articles = "<TABLE border=1>\n<TR><TH>NoCommande</TH><TH>NoClient</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $somme_detail_achat_articles = 0;
  $acomptemoin_achat = 0;
  $tax_achat = array();
  $total_achat_gm_tva = array();
  $requette = "SELECT * FROM commande" . ID_GARAGE . " WHERE (Genre='C' OR Genre='A' OR Genre='R') AND Paye='O' AND " . Requette_Recherche("DatePayement", 2, $intervalle) . " ORDER BY DatePayement";
  $resultat = Connection::executeRawQueryWithfetchAll($requette);
  foreach ($resultat as $ligne) {
    $resultat2 = DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'] . ' 00:00:00');;
    foreach ($resultat2 as $ligne2) {
      $acomptemoin_achat -= $ligne2['Somme'];
      $detail_acompte_achat .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE) . "</TD><TD>0</TD><TD>" . -$ligne2['Somme'] . "</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
    }
    $resultat2 = CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
    foreach ($resultat2 as $ligne2) {
      if ($ligne2['TypeData'] != 1) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        $detail_achat_articles .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne['NoClient'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>" . $ligne2['PrixMulti'] . "</TD></TR>";
        $somme_detail_achat_articles += $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_achat)) {
          $tax_achat["$tva2"] = 0;
        }
        $tax_achat["$tva2"] += $ligne2['PrixMulti'];
        //		}
        if (!array_key_exists("$tva2", $total_achat_gm_tva)) {
          $total_achat_gm_tva["$tva2"] = array();
          for ($cpt = 0; $cpt < 300; $cpt++) {
            $total_achat_gm_tva["$tva2"][$cpt] = 0.0;
          }
        }
        $total_achat_gm_tva["$tva2"][$ligne2['GM']] += $ligne2['PrixMulti'];
      }
    }
  }
  $acomptediff_achat = $acompteplus_achat - $acomptemoin_achat;
  $detail_acompte_achat .= "<TR><TH>Total</TH><TH>$acompteplus_achat</TH><TH>$acomptemoin_achat</TH><TH>diff $acomptediff_achat</TH></TR></TABLE>\n";
  $detail_achat_articles .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_achat_articles</TH></TR></TABLE>\n";
  //****************************************//
  echo "<BIG>Comptes TVA Achat</BIG><BR>\n";
  array_multisort($tax_achat, SORT_ASC, SORT_NUMERIC);
  echo "<TABLE border=1>\n";
  echo "<TR>";
  foreach ($tax_achat as $taux => $somme) {
    echo "<TH>$taux %</TH><TH>tax $taux %</TH>";
  }
  echo "<TH>Total</TH><TH>Total tax</TH>";
  echo "</TR>\n";
  echo "<TR>";
  $tot = 0;
  $tot_tax = 0;
  $somme_total_vente_gm_tva = array();
  foreach ($tax_achat as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    echo "<TH>" . $somme . "</TH><TH>" . Arrondi_2_Dec($somme * (1 - (1 / ((100 + $taux) / 100)))) . "</TH>";
  }
  echo "<TH>$tot</TH><TH>" . Arrondi_2_Dec($tot_tax) . "</TH>";
  echo "</TR>\n";
  echo "</TABLE><BR>\n";
  echo "<BIG>Payement partiels achat</BIG><BR>\n";
  echo "<TABLE border=1>\n";
  echo "<TR><TH>&nbsp;</TH><TH>Entrée</TH><TH>Sortie</TH><TH>Différence</TH></TR>\n";
  echo "<TR><TD>Montant TTC</TD><TD>$acompteplus_achat</TD><TD>$acomptemoin_achat</TD><TD bgcolor='#ff8000'>$acomptediff_achat</TD></TR>\n";
  echo "<TR><TD>Tax 7.6 %</TD><TD>" . Arrondi_2_Dec($acompteplus_achat * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD><TD>" . Arrondi_2_Dec($acomptemoin_achat * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD><TD>" . Arrondi_2_Dec($acomptediff_achat * (1 - (1 / ((100 + 7.6) / 100)))) . "</TD></TR>\n";
  echo "</TABLE><BR>\n";
  $tot += $acomptediff_achat;
  echo "<TABLE border=1><TR><TH>Total achats et payements partiels</TH><TH bgcolor='#ff8000'><BIG>$tot</BIG></TH></TR></TABLE><BR>\n";
  if ($Detail == 1) {
    if ($Detail1 == 1) {
      for ($cpt_caisse = 0; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
        $resultat = ModePayement::getModePayementsByNoCaisse($cpt_caisse);
        foreach ($resultat as $ligne) {
          $cpt_mode = $ligne['NoMode'];
          echo $detail_mouvement[$cpt_caisse][$cpt_mode];
        }
      }
    }
    if ($Detail2 == 1) {
      echo "<BIG>Détail vente</BIG><BR>\n";
      echo $detail_vente_articles;
    }
    if ($Detail3 == 1) {
      echo "<BIG>GM vente</BIG><BR>" . "<TABLE border=1><TR><TH>GM</TH>\n";
      array_multisort($total_vente_gm_tva, SORT_ASC, SORT_NUMERIC);
      foreach ($total_vente_gm_tva as $taux => $somme) {
        echo "<TH colspan=2>TOT($taux)</TH>";
      }
      echo "</TR>\n";
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $tmp_out = "<TR><TD>$cpt</TD>";
        $zero = true;
        foreach ($total_vente_gm_tva as $taux => $somme) {
          if ($somme[$cpt] != 0)
            $zero = false;
          $tmp_out .= "<TD>" . $somme[$cpt] . "</TD><TD>" . Arrondi_2_Dec($somme[$cpt] * (1 - (1 / ((100 + $taux) / 100)))) . "</TD>";
        }
        $tmp_out .= "</TR>\n";
        if (!$zero) {
          echo $tmp_out;
        }
      }
      echo "</TABLE>";
      echo "<BIG>Compte comptable vente</BIG><BR>" . "<TABLE border=1><TR><TH>CC</TH>\n";
      $total_cc_vente = array();
      foreach ($total_vente_gm_tva as $taux => $somme) {
        $total_cc_vente["$taux"] = array();
        echo "<TH colspan=2>TOT($taux)</TH>";
      }
      echo "</TR>\n";
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $no_cc = 0;
        $resultat_cc = Compta::getByVenteAndGM(1, $cpt);
        if ($ligne_cc = $resultat_cc[0]) {
          $no_cc = $ligne_cc['Compte'];
        }
        foreach ($total_vente_gm_tva as $taux => $somme) {
          if (array_key_exists("$no_cc", $total_cc_vente["$taux"])) {
            $total_cc_vente["$taux"]["$no_cc"] += $total_vente_gm_tva["$taux"][$cpt];
          } else {
            $total_cc_vente["$taux"]["$no_cc"] = $total_vente_gm_tva["$taux"][$cpt];
          }
        }
      }
      if (count($total_cc_vente) != 0) {
        $lolo = array_keys($total_cc_vente);
        $lolo2 = $lolo[0];
        foreach ($total_cc_vente["$lolo2"] as $cc => $somme) {
          echo "<TR><TH>$cc</TH>";
          foreach ($total_cc_vente as $taux => $somme2) {
            echo "<TD>" . $somme2[$cc] . "</TD><TD>" . Arrondi_2_Dec($somme2[$cc] * (1 - (1 / ((100 + $taux) / 100)))) . "</TD>";
          }
          echo "</TR>";
        }
      }
      echo "</TABLE>";
    }
    if ($Detail4 == 1) {
      echo "<BIG>Détail achat</BIG><BR>\n";
      echo $detail_achat_articles;
    }
    if ($Detail5 == 1) {
      echo "<BIG>GM achat</BIG><BR>" . "<TABLE border=1><TR><TH>GM</TH>\n";
      array_multisort($total_achat_gm_tva, SORT_ASC, SORT_NUMERIC);
      foreach ($total_achat_gm_tva as $taux => $somme) {
        echo "<TH colspan=2>TOT($taux)</TH>";
      }
      echo "</TR>\n";
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $tmp_out = "<TR><TD>$cpt</TD>";
        $zero = true;
        foreach ($total_achat_gm_tva as $taux => $somme) {
          if ($somme[$cpt] != 0)
            $zero = false;
          $tmp_out .= "<TD>" . $somme[$cpt] . "</TD><TD>" . Arrondi_2_Dec($somme[$cpt] * (1 - (1 / ((100 + $taux) / 100)))) . "</TD>";
        }
        $tmp_out .= "</TR>\n";
        if (!$zero) {
          echo $tmp_out;
        }
      }
      echo "</TABLE>";
      echo "<BIG>Compte comptable achat</BIG><BR>" . "<TABLE border=1><TR><TH>CC</TH>\n";
      $total_cc_achat = array();
      foreach ($total_achat_gm_tva as $taux => $somme) {
        $total_cc_achat["$taux"] = array();
        echo "<TH colspan=2>TOT($taux)</TH>";
      }
      echo "</TR>\n";
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $no_cc = 0;
        $resultat_cc = Compta::getByVenteAndGM(0, $cpt);
        if ($ligne_cc = $resultat_cc[0]) {
          $no_cc = $ligne_cc['Compte'];
        }
        foreach ($total_achat_gm_tva as $taux => $somme) {
          if (array_key_exists("$no_cc", $total_cc_achat["$taux"])) {
            $total_cc_achat["$taux"]["$no_cc"] += $total_achat_gm_tva["$taux"][$cpt];
          } else {
            $total_cc_achat["$taux"]["$no_cc"] = $total_achat_gm_tva["$taux"][$cpt];
          }
        }
      }
      if (count($total_cc_achat) != 0) {
        $lolo = array_keys($total_cc_achat);
        $lolo2 = $lolo[0];
        foreach ($total_cc_achat["$lolo2"] as $cc => $somme) {
          echo "<TR><TH>$cc</TH>";
          foreach ($total_cc_achat as $taux => $somme2) {
            echo "<TD>" . $somme2[$cc] . "</TD><TD>" . Arrondi_2_Dec($somme2[$cc] * (1 - (1 / ((100 + $taux) / 100)))) . "</TD>";
          }
          echo "</TR>";
        }
      }
      echo "</TABLE>";
    }
    if ($Detail6 == 1) {
      echo $detail_acompte . "<BR>\n";
    }
    if ($Detail7 == 1) {
      echo $detail_acompte_achat . "<BR>\n";
    }
  }
}
function compta_pdf()
{
  global $Detail, $intervalle, $Detail1, $Detail2, $Detail3, $Detail4, $Detail5, $Detail6, $Detail7, $Detail8, $Detail9;
  set_time_limit(600);
  Header('Content-Type: application/pdf');
  Header('Content-disposition: inline; filename=doc.pdf');
  $pdf = new Fpdf('P', 'mm', 'A4');
  $pdf->SetTitle("Compta");
  $pdf->SetSubject("Compta");
  $pdf->SetAuthor("Laurent");
  $pdf->SetCreator("Laurent");
  $pdf->SetDisplayMode("fullpage");
  $pdf->AddPage();
  $pdf->SetLineWidth(0.2);
  if (!isset($Detail)) {
    $Detail = 0;
  }
  if (!isset($Detail1)) {
    $Detail1 = 0;
  }
  if (!isset($Detail2)) {
    $Detail2 = 0;
  }
  if (!isset($Detail3)) {
    $Detail3 = 0;
  }
  if (!isset($Detail4)) {
    $Detail4 = 0;
  }
  if (!isset($Detail5)) {
    $Detail5 = 0;
  }
  if (!isset($Detail6)) {
    $Detail6 = 0;
  }
  if (!isset($Detail7)) {
    $Detail7 = 0;
  }
  $nb_caisses = Config::getNbCaisse();
  /*  else
  {
  	echo $requette;
    $nb_caisses = 1;
  }*/
  //----------------------------------------//
  //           Date ou période              //
  //                                        //
  //----------------------------------------//
  if ($intervalle[5] != 0) {
    $txt = "Comptabilité du " . $intervalle[0] . "." . $intervalle[1] . "." . $intervalle[2] . " au " . $intervalle[3] . "." . $intervalle[4] . "." . $intervalle[5] . "\n";
  } else {
    $txt = "Comptabilité du " . $intervalle[0] . "." . $intervalle[1] . "." . $intervalle[2] . "\n";
  }
  $no_page = 1;
  $pdf->SetXY(30, 18);
  $pdf->SetFont("Helvetica", "", 12);
  $pdf->Cell(200, 8, $txt, 0, 0, "L");
  $pdf->SetXY(150, 18);
  $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
  $no_page++;
  //----------------------------------------//
  //           Montant en caisse            //
  //           ouverture cloture            //
  //----------------------------------------//
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $requette = "SELECT * FROM caisse" . ID_GARAGE . " WHERE Date<'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . "' AND NoCaisse=$cpt_caisse ORDER BY Date DESC LIMIT 0, 1";
    $resultat = Connection::executeRawQueryWithfetchAll($requette);
    if ($ligne = $resultat[0]) {
      $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . $ligne['Date'] . " 23:59:59' AND Date<'" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 00:00:00' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      $somme = 0;
      foreach ($resultat2 as $ligne2) {
        $somme += $ligne2['Somme'];
      }
      $total = round($ligne['Montant'] + $somme, 2);
      $tab_caisse_ouverture[$cpt_caisse] = $total;
      if ($intervalle[5] != 0) {
        $tmp_int[0] = $intervalle[3];
        $tmp_int[1] = $intervalle[4];
        $tmp_int[2] = $intervalle[5];
        $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . $ligne['Date'] . " 23:59:59' AND Date<='" . substr(Decode_Entree_Type($tmp_int, 2), 0, 10) . " 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      } else {
        $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE Date>'" . $ligne['Date'] . " 23:59:59' AND Date<='" . substr(Decode_Entree_Type($intervalle, 2), 0, 10) . " 23:59:59' AND ModePayement=1 AND NoCaisse=$cpt_caisse";
      }
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      $somme = 0;
      foreach ($resultat2 as $ligne2) {
        $somme += $ligne2['Somme'];
      }
      $total = round($ligne['Montant'] + $somme, 2);
      $tab_caisse_cloture[$cpt_caisse] = $total;
    }
  }
  //****************************************//
  $pdf->Line(30, 30, 80 + ($nb_caisses * 20), 30);
  $pdf->Line(30, 34, 80 + ($nb_caisses * 20), 34);
  $pdf->Line(30, 38, 80 + ($nb_caisses * 20), 38);
  $pdf->Line(30, 42, 80 + ($nb_caisses * 20), 42);
  $pdf->Line(30, 46, 80 + ($nb_caisses * 20), 46);
  $pdf->Line(30, 30, 30, 46);
  $pdf->Line(60, 30, 60, 46);
  $pdf->SetXY(30, 30);
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->Cell(30, 4, "Montant en caisse", 0, 0, "L");
  $pdf->SetXY(30, 34);
  $pdf->Cell(30, 4, "Ouverture", 0, 0, "L");
  $pdf->SetXY(30, 38);
  $pdf->Cell(30, 4, "Clôture", 0, 0, "L");
  $pdf->SetXY(30, 42);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "Différence", 0, 0, "L");
  $tot_caisse_ouverture = 0;
  $tot_caisse_cloture = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $tot_caisse_ouverture += $tab_caisse_ouverture[$cpt_caisse];
    $tot_caisse_cloture += $tab_caisse_cloture[$cpt_caisse];
    $pdf->Line(60 + ($cpt_caisse * 20), 30, 60 + ($cpt_caisse * 20), 46);
    $pdf->SetXY(40 + (20 * $cpt_caisse), 30);
    $pdf->SetFont("Helvetica", "", 8);
    $pdf->Cell(20, 4, "Caisse " . $cpt_caisse, 0, 0, "J");
    $pdf->SetXY(40 + (20 * $cpt_caisse), 34);
    $pdf->Cell(20, 4, number_format($tab_caisse_ouverture[$cpt_caisse], 2, '.', "'"), 0, 0, "R");
    $pdf->SetXY(40 + (20 * $cpt_caisse), 38);
    $pdf->Cell(20, 4, number_format($tab_caisse_cloture[$cpt_caisse], 2, '.', "'"), 0, 0, "R");
    $pdf->SetXY(40 + (20 * $cpt_caisse), 42);
    $pdf->SetFont("Helvetica", "B", 8);
    $pdf->Cell(20, 4, number_format($tab_caisse_cloture[$cpt_caisse] - $tab_caisse_ouverture[$cpt_caisse], 2, '.', "'"), 0, 0, "R");
  }
  $pdf->Line(60 + ($cpt_caisse * 20), 30, 60 + ($cpt_caisse * 20), 46);
  $pdf->SetXY(40 + (20 * $cpt_caisse), 30);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(20, 4, "Total", 0, 0, "J");
  $pdf->SetXY(40 + (20 * $cpt_caisse), 34);
  $pdf->Cell(20, 4, number_format($tot_caisse_ouverture, 2, '.', "'"), 0, 0, "R");
  $pdf->SetXY(40 + (20 * $cpt_caisse), 38);
  $pdf->Cell(20, 4, number_format($tot_caisse_cloture, 2, '.', "'"), 0, 0, "R");
  $pdf->SetXY(40 + (20 * $cpt_caisse), 42);
  $pdf->Cell(20, 4, number_format($tot_caisse_cloture - $tot_caisse_ouverture, 2, '.', "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);

  //----------------------------------------//
  //           Mouvements d'argent          //
  //           banques et caisses           //
  //----------------------------------------//
  $acompteplus = 0;
  $tab_detail_acompte[0] = array();
  $tab_detail_acompte[1] = array();
  $tab_detail_acompte[2] = array();
  $tab_detail_acompte[3] = array();
  $acompteplus_achat = 0;
  $tab_detail_acompte_achat[0] = array();
  $tab_detail_acompte_achat[1] = array();
  $tab_detail_acompte_achat[2] = array();
  $tab_detail_acompte_achat[3] = array();
  $detail_acompte = "<TABLE border=1>\n<TR><TH>Date</TH><TH>acompte entree</TH><TH>acompte sortie</TH><TH>NoCommande</TH></TR>\n";
  for ($cpt_caisse = 0; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $somme_caisse_vente[$cpt_caisse] = 0;
    $somme_caisse_vente_cc[$cpt_caisse] = 0;
    $resultat = ModePayement::getModePayementsByNoCaisse($cpt_caisse);
    foreach ($resultat as $ligne) {
      $cpt_mode = $ligne['NoMode'];
      $tab_detail_mouvement[$cpt_caisse][$cpt_mode][0] = array();
      $tab_detail_mouvement[$cpt_caisse][$cpt_mode][1] = array();
      $tab_detail_mouvement[$cpt_caisse][$cpt_mode][2] = array();
      //  	  $tab_detail_mouvement[$cpt_caisse][$cpt_mode]="<BIG>Caisse $cpt_caisse ".$ligne['Description']."</BIG><BR>\n<TABLE border=1>\n<TR><TH>Date</TH><TH>Somme</TH><TH>No commande</TH></TR>\n";
      $somme_mouvement[$cpt_caisse][$cpt_mode] = 0;
      $somme_vente[$cpt_caisse][$cpt_mode] = 0;
      $somme_achat[$cpt_caisse][$cpt_mode] = 0;
      $somme_transfert[$cpt_caisse][$cpt_mode] = 0;
      $requette2 = "SELECT * FROM dbcash" . ID_GARAGE . " WHERE " . Requette_Recherche("Date", 18, $intervalle) . " AND NoCaisse=$cpt_caisse AND ModePayement=$cpt_mode ORDER BY Date";
      $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
      foreach ($resultat2 as $ligne2) {
        array_push($tab_detail_mouvement[$cpt_caisse][$cpt_mode][0], Cree_Entree_Type("", 18, 0, $ligne2['Date'], AFFICHAGE));
        array_push($tab_detail_mouvement[$cpt_caisse][$cpt_mode][1], $ligne2['Somme']);
        array_push($tab_detail_mouvement[$cpt_caisse][$cpt_mode][2], $ligne2['NoFacture']);
        $somme_mouvement[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
        if ($ligne3 = Commande::getCommandeByNoCommande($ligne2['NoFacture'])) {
          switch ($ligne3['Genre']) {
            case 'F':
            case 'G':
            case 'N':
              $somme_vente[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              $requette4 = "SELECT * FROM commande" . ID_GARAGE . " WHERE NoCommande=" . $ligne2['NoFacture'] . " AND Paye='O' AND DatePayement='" . substr($ligne2['Date'], 0, 10) . "'";
              $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
              if ($ligne4 = $requette4[0]) {
              } else {
                array_push($tab_detail_acompte[0], Cree_Entree_Type("", 2, 0, $ligne2['Date'], AFFICHAGE));
                array_push($tab_detail_acompte[1], $ligne2['Somme']);
                array_push($tab_detail_acompte[2], 0);
                array_push($tab_detail_acompte[3], $ligne2['NoFacture']);
                $detail_acompte .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne2['Date'], AFFICHAGE) . "</TD><TD>" . $ligne2['Somme'] . "</TD><TD>0</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
                $acompteplus += $ligne2['Somme'];
              }
              break;
            case 'C':
            case 'R':
            case 'A':
            case 'V':
              $somme_achat[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              $requette4 = "SELECT * FROM commande" . ID_GARAGE . " WHERE NoCommande=" . $ligne2['NoFacture'] . " AND Paye='O' AND DatePayement='" . substr($ligne2['Date'], 0, 10) . "'";
              $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
              if ($ligne4 = $requette4[0]) {
              } else {
                array_push($tab_detail_acompte_achat[0], Cree_Entree_Type("", 2, 0, $ligne2['Date'], AFFICHAGE));
                array_push($tab_detail_acompte_achat[1], -$ligne2['Somme']);
                array_push($tab_detail_acompte_achat[2], 0);
                array_push($tab_detail_acompte_achat[3], $ligne2['NoFacture']);
                $acompteplus_achat -= $ligne2['Somme'];
              }
              break;
            case 'T':
              $somme_transfert[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
              break;
          }
        } else {
          $somme_vente[$cpt_caisse][$cpt_mode] += $ligne2['Somme'];
        }
      }
      $somme_caisse_vente[$cpt_caisse] += $somme_vente[$cpt_caisse][$cpt_mode];
      if ($ligne['Type'] == 1) {
        $somme_caisse_vente_cc[$cpt_caisse] += $somme_vente[$cpt_caisse][$cpt_mode];
      }
      //	  $detail_mouvement[$cpt_caisse][$cpt_mode].="<TR><TH colspan=3><BIG>".$somme_mouvement[$cpt_caisse][$cpt_mode]."  vente ".$somme_vente[$cpt_caisse][$cpt_mode]."  achat ".$somme_achat[$cpt_caisse][$cpt_mode]."  transferts ".$somme_transfert[$cpt_caisse][$cpt_mode]."</BIG></TH></TR>\n";
      //	  $detail_mouvement[$cpt_caisse][$cpt_mode].="</TABLE>\n";
      //	  echo $detail_mouvement[$cpt_caisse][$cpt_mode];
    }
  }
  //****************************************//
  $y = 50;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "Mouvements vente", 0, 0, "J");
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(40 + (20 * $cpt_caisse), $y);
    $pdf->Cell(20, 4, "Caisse " . $cpt_caisse, 0, 0, "J");
  }
  $pdf->SetXY(60 + ($nb_caisses * 20), $y);
  $pdf->Cell(20, 4, "Total", 0, 0, "J");
  $y += 4;
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $resultat = ModePayement::getModePayementsByNoCaisse(1);
  $pdf->SetFont("Helvetica", "", 8);
  $grand_tot = 0;
  foreach ($resultat as $ligne) {
    $tot = 0;
    $pdf->SetXY(30, $y);
    $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
    for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
      $pdf->SetXY(40 + ($cpt_caisse * 20), $y);
      $pdf->Cell(20, 4, number_format($somme_vente[$cpt_caisse][$ligne['NoMode']], 2, ".", "'"), 0, 0, "R");
      $tot += $somme_vente[$cpt_caisse][$ligne['NoMode']];
      $grand_tot += $somme_vente[$cpt_caisse][$ligne['NoMode']];
    }
    $pdf->SetXY(60 + ($nb_caisses * 20), $y);
    $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
    $y += 4;
    $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  }
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 9);
  $pdf->SetLineWidth(0.5);
  $pdf->Cell(40, 4, "Total cartes", 0, 0, "L");
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(35 + ($cpt_caisse * 20), $y);
    $pdf->Cell(25, 4, number_format($somme_caisse_vente_cc[$cpt_caisse], 2, ".", "'"), 0, 0, "R");
    $tot += $somme_caisse_vente_cc[$cpt_caisse];
  }
  $pdf->SetXY(55 + ($nb_caisses * 20), $y);
  $pdf->Cell(25, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $pdf->SetXY(30, $y);
  $pdf->Cell(40, 4, "Total", 0, 0, "L");
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(35 + ($cpt_caisse * 20), $y);
    $pdf->Cell(25, 4, number_format($somme_caisse_vente[$cpt_caisse], 2, ".", "'"), 0, 0, "R");
    $tot += $somme_caisse_vente[$cpt_caisse];
  }
  $pdf->SetXY(55 + ($nb_caisses * 20), $y);
  $pdf->Cell(25, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $pdf->Line(30, 50, 30, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(60, 50, 60, $y);
  $pdf->Line(80, 50, 80, $y);
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    if ($cpt_caisse == $nb_caisses)
      $pdf->SetLineWidth(0.5);
    $pdf->Line(80 + (20 * $cpt_caisse), 50, 80 + (20 * $cpt_caisse), $y);
  }
  $y = 50;
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(50, 4, "Mouvements vente banques", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    $pdf->SetXY(140, $y);
    $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
    $pdf->SetXY(170, $y);
    $pdf->Cell(20, 4, number_format($somme_vente[0][$ligne['NoMode']], 2, ".", "'"), 0, 0, "R");
    $y += 4;
    $pdf->Line(140, $y, 190, $y);
    $tot += $somme_vente[0][$ligne['NoMode']];
  }
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 9);
  $pdf->Cell(30, 4, "Total", 0, 0, "J");
  $pdf->SetXY(165, $y);
  $pdf->Cell(25, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->Line(140,  50, 140, $y);
  $pdf->Line(190, 50, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(170, 54, 170, $y);

  $y += 4;
  $haut = $y;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->Cell(30, 4, "Total caisses", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($grand_tot, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetXY(140, $y);
  $pdf->Cell(30, 4, "Total banques", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 9);
  $pdf->Cell(30, 4, "Total ventes", 0, 0, "J");
  $pdf->SetXY(165, $y);
  $pdf->Cell(25, 4, number_format($grand_tot + $tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $pdf->Line(140, $haut, 140, $y);
  $pdf->Line(190, $haut, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(170, $haut, 170, $y);
  $y = 100;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "Achat depuis caisse", 0, 0, "J");
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(40 + (20 * $cpt_caisse), $y);
    $pdf->Cell(20, 4, "Caisse " . $cpt_caisse, 0, 0, "J");
  }
  $pdf->SetXY(60 + ($nb_caisses * 20), $y);
  $pdf->Cell(30, 4, "Total", 0, 0, "J");
  $y += 4;
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $ligne = ModePayement::getModePayementsByNoModeAndNoCaisse(1, 1);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
  $tot = 0;
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(40 + ($cpt_caisse * 20), $y);
    $pdf->Cell(20, 4, number_format($somme_achat[$cpt_caisse][1], 2, ".", "'"), 0, 0, "R");
    $tot += $somme_achat[$cpt_caisse][1];
  }
  $grand_tot = $tot;
  $pdf->SetXY(60 + ($nb_caisses * 20), $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 80 + ($nb_caisses * 20), $y);
  $pdf->Line(30, 100, 30, $y);
  $pdf->SetLineWidth(0.2);
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->Line(80 + (20 * $cpt_caisse), 100, 80 + (20 * $cpt_caisse), $y);
  }
  $pdf->SetLineWidth(0.5);
  $pdf->Line(80 + (20 * $nb_caisses), 100, 80 + (20 * $nb_caisses), $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(80, 100, 80, $y);
  $pdf->Line(60, 100, 60, $y);
  $y = 100;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(50, 4, "Mouvements achats depuis banques", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    $pdf->SetXY(140, $y);
    $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
    $pdf->SetXY(170, $y);
    $pdf->Cell(20, 4, number_format($somme_achat[0][$ligne['NoMode']], 2, ".", "'"), 0, 0, "R");
    $y += 4;
    $pdf->Line(140, $y, 190, $y);
    $tot += $somme_achat[0][$ligne['NoMode']];
  }
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 9);
  $pdf->Cell(30, 4, "Total", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->Line(140, 100, 140, $y);
  $pdf->Line(190, 100, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(170, 104, 170, $y);
  $y += 4;
  $haut = $y;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->Cell(30, 4, "Total caisses", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($grand_tot, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetXY(140, $y);
  $pdf->Cell(30, 4, "Total banques", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 9);
  $pdf->Cell(30, 4, "Total achats", 0, 0, "J");
  $pdf->SetXY(170, $y);
  $pdf->Cell(20, 4, number_format($grand_tot + $tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $pdf->Line(140, $haut, 140, $y);
  $pdf->Line(190, $haut, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(170, $haut, 170, $y);
  $y = 140;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 60 + ($nb_caisses * 20), $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "Transferts caisses", 0, 0, "J");
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(40 + (20 * $cpt_caisse), $y);
    $pdf->Cell(20, 4, "Caisse " . $cpt_caisse, 0, 0, "J");
  }
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(30, $y, 60 + ($nb_caisses * 20), $y);
  $ligne = ModePayement::getModePayementsByNoModeAndNoCaisse(1, 1);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->SetXY(40 + ($cpt_caisse * 20), $y);
    $pdf->Cell(20, 4, number_format($somme_transfert[$cpt_caisse][1], 2, ".", "'"), 0, 0, "R");
  }
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 60 + ($nb_caisses * 20), $y);
  $pdf->Line(30, 140, 30, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(60, 140, 60, $y);
  for ($cpt_caisse = 1; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
    $pdf->Line(60 + (20 * $cpt_caisse), 140, 60 + (20 * $cpt_caisse), $y);
  }
  $pdf->SetLineWidth(0.5);
  $pdf->Line(60 + (20 * $nb_caisses), 140, 60 + (20 * $nb_caisses), $y);
  $pdf->SetLineWidth(0.2);
  $y = 144;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(50, 4, "Transferts banques", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 190, $y);
  $tot = 0;
  $resultat = ModePayement::getModePayementsByNoCaisse(0);
  foreach ($resultat as $ligne) {
    $pdf->SetXY(140, $y);
    $pdf->Cell(30, 4, $ligne['Description'], 0, 0, "J");
    $pdf->SetXY(170, $y);
    $pdf->Cell(20, 4, number_format($somme_transfert[0][$ligne['NoMode']], 2, ".", "'"), 0, 0, "R");
    $y += 4;
    $pdf->Line(140, $y, 190, $y);
  }
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 190, $y);
  $pdf->Line(140, 140, 140, $y);
  $pdf->Line(190, 140, 190, $y);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(170, 144, 170, $y);
  //----------------------------------------//
  //          Detail articles vente         //
  //          TVA, GM, TVA marges           //
  //----------------------------------------//
  //  $table_detail_vente_articles="<TABLE border=1>\n<TR><TH>NoCommande</TH><TH>NoClient</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $tab_detail_vente_articles[0] = array();
  $tab_detail_vente_articles[1] = array();
  $tab_detail_vente_articles[2] = array();
  $tab_detail_vente_articles[3] = array();
  $tab_detail_vente_articles[4] = array();
  $tab_detail_vente_articles[5] = array();
  $tab_detail_vente_articles[6] = array();
  $tab_detail_vente_articles[7] = array();
  $detail_tva_marges = "<TABLE border=1><TR><TH>NoCommande</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $somme_detail_vente_articles = 0;
  $somme_detail_tva_marges = 0;
  $acomptemoin = 0;
  $tax_vente = array();
  $tax_marges = array();
  $total_vente_gm_tva = array();
  $requette = "SELECT * FROM commande" . ID_GARAGE . " WHERE (Genre='F' OR Genre='N' OR Genre='G') AND Paye='O' AND " . Requette_Recherche("DatePayement", 2, $intervalle) . " ORDER BY DatePayement";
  $resultat = Connection::executeRawQueryWithfetchAll($requette);
  foreach ($resultat as $ligne) {
    if ($ligne['Genre'] == 'N')
      $pos = false;
    else
      $pos = true;
    $resultat2 = DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'] . ' 00:00:00');;
    foreach ($resultat2 as $ligne2) {
      $acomptemoin += $ligne2['Somme'];
      //	  if($pos) $acomptemoin+=$ligne2['Somme']; else $acomptemoin-=$ligne2['Somme'];
      array_push($tab_detail_acompte[0], Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE));
      array_push($tab_detail_acompte[1], 0);
      array_push($tab_detail_acompte[2], $ligne2['Somme']);
      array_push($tab_detail_acompte[3], $ligne2['NoFacture']);
      $detail_acompte .= "<TR><TD>" . Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE) . "</TD><TD>0</TD><TD>" . $ligne2['Somme'] . "</TD><TD>" . $ligne2['NoFacture'] . "</TD></TR>\n";
    }
    $resultat2 = CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
    foreach ($resultat2 as $ligne2) {
      if ($ligne2['TypeData'] == 0) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        array_push($tab_detail_vente_articles[0], $ligne2['NoCommande']);
        array_push($tab_detail_vente_articles[1], $ligne['NoClient']);
        array_push($tab_detail_vente_articles[2], $ligne2['NoArticle']);
        array_push($tab_detail_vente_articles[3], $ligne2['Description']);
        array_push($tab_detail_vente_articles[4], $ligne2['GM']);
        array_push($tab_detail_vente_articles[7], substr($ligne['DatePayement'], 8, 2) . "." . substr($ligne['DatePayement'], 5, 2) . "." . substr($ligne['DatePayement'], 2, 2));
        array_push($tab_detail_vente_articles[5], $tva2);
        if ($pos) array_push($tab_detail_vente_articles[6], $ligne2['PrixMulti']);
        else array_push($tab_detail_vente_articles[6], (-$ligne2['PrixMulti']));
        if ($pos) $somme_detail_vente_articles += $ligne2['PrixMulti'];
        else $somme_detail_vente_articles -= $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_vente)) {
          $tax_vente["$tva2"] = 0;
        }
        if ($pos) $tax_vente["$tva2"] += $ligne2['PrixMulti'];
        else $tax_vente["$tva2"] -= $ligne2['PrixMulti'];
        //		}
        if (!array_key_exists("$tva2", $total_vente_gm_tva)) {
          $total_vente_gm_tva["$tva2"] = array();
          for ($cpt = 0; $cpt < 300; $cpt++) {
            $total_vente_gm_tva["$tva2"][$cpt] = 0.0;
          }
        }
        if ($pos) $total_vente_gm_tva["$tva2"][$ligne2['GM']] += $ligne2['PrixMulti'];
        else $total_vente_gm_tva["$tva2"][$ligne2['GM']] -= $ligne2['PrixMulti'];
      }
      if ($ligne2['TypeData'] == 3) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        $detail_tva_marges .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>";
        if ($pos) $detail_tva_marges .= $ligne2['PrixMulti'];
        else $detail_tva_marges .= (-$ligne2['PrixMulti']);
        $detail_tva_marges .= "</TD></TR>";
        if ($pos) $somme_detail_tva_marges += $ligne2['PrixMulti'];
        else $somme_detail_tva_marges -= $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_marges)) {
          $tax_marges["$tva2"] = 0;
        }
        if ($pos) $tax_marges["$tva2"] += $ligne2['PrixMulti'];
        else $tax_marges["$tva2"] -= $ligne2['PrixMulti'];
        //		}
      }
    }
  }
  $acomptediff = $acompteplus - $acomptemoin;
  $detail_acompte .= "<TR><TH>Total</TH><TH>$acompteplus</TH><TH>$acomptemoin</TH><TH>diff $acomptediff</TH></TR></TABLE>\n";
  //  $detail_vente_articles .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_vente_articles</TH></TR></TABLE>\n";
  $detail_tva_marges .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_tva_marges</TH></TR></TABLE>\n";
  //****************************************//
  array_multisort($tax_vente, SORT_ASC, SORT_NUMERIC);
  $y = 167;
  $pdf->SetXY(30, $y);
  $pdf->Cell(30, 4, "Comptes TVA Vente", 0, 0, "J");
  $y += 4;
  $nb = 0;
  $pdf->SetFont("Helvetica", "B", 8);
  foreach ($tax_vente as $taux => $somme) {
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "TTC $taux%", 0, 0, "J");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "Tax $taux%", 0, 0, "J");
    $nb++;
  }
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total TTC", 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total Tax", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $y += 4;
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $tot = 0;
  $tot_tax = 0;
  $somme_total_vente_gm_tva = array();
  $nb = 0;
  foreach ($tax_vente as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    if ($nb == 0)
      $pdf->SetLineWidth(0.5);
    $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
    if ($nb == 0)
      $pdf->SetLineWidth(0.2);
    $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme, 2, ".", "'"), 0, 0, "R");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
    $nb++;
  }
  $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
  $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(70 + (40 * $nb), $y - 4, 70 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot_tax, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  array_multisort($tax_marges, SORT_ASC, SORT_NUMERIC);
  $y = 180;
  $pdf->SetXY(30, $y);
  $pdf->Cell(60, 4, "TVA des marges véhicules occasion", 0, 0, "J");
  $y += 4;
  $nb = 0;
  $tot_vente = $tot;
  $pdf->SetFont("Helvetica", "B", 8);
  foreach ($tax_marges as $taux => $somme) {
    if ($taux != 0) {
      $pdf->SetXY(30 + ($nb * 40), $y);
      $pdf->Cell(20, 4, "TTC $taux%", 0, 0, "J");
      $pdf->SetXY(50 + ($nb * 40), $y);
      $pdf->Cell(20, 4, "Tax $taux%", 0, 0, "J");
      $nb++;
    }
  }
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total TTC", 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total Tax", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $y += 4;
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $tot = 0;
  $tot_tax = 0;
  $somme_total_vente_gm_tva = array();
  $nb = 0;
  foreach ($tax_marges as $taux => $somme) {
    if ($taux != 0) {
      $tot += $somme;
      $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
      if ($nb == 0)
        $pdf->SetLineWidth(0.5);
      $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
      if ($nb == 0)
        $pdf->SetLineWidth(0.2);
      $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
      $pdf->SetXY(30 + ($nb * 40), $y);
      $pdf->Cell(20, 4, number_format($somme, 2, ".", "'"), 0, 0, "R");
      $pdf->SetXY(50 + ($nb * 40), $y);
      $pdf->Cell(20, 4, number_format($somme * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
      $nb++;
    }
  }
  $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
  $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(70 + (40 * $nb), $y - 4, 70 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot_tax, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $y = 195;
  $pdf->SetXY(30, $y);
  $pdf->Cell(50, 4, "Payements partiels ventes", 0, 0, "J");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->Line(30, $y, 30, $y + 12);
  $pdf->Line(120, $y, 120, $y + 12);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(60, $y, 60, $y + 12);
  $pdf->Line(80, $y, 80, $y + 12);
  $pdf->Line(100, $y, 100, $y + 12);
  $pdf->SetXY(60, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(20, 4, "Entrée", 0, 0, "J");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, "Sortie", 0, 0, "J");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, "Différence", 0, 0, "J");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->Cell(30, 4, "Montant TTC", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "TAX 7.6%", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetLineWidth(0.2);
  $y = 195;
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->Line(140, $y, 140, $y + 8);
  $pdf->Line(200, $y, 200, $y + 8);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(60, 4, "Total chiffre affaires et payements partiels", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetXY(140, $y);
  if ($acomptediff < 0) {
    $pdf->Cell(60, 4, number_format($tot_vente, 2, ".", "'") . " - " . number_format(-$acomptediff, 2, ".", "'") . " = " . number_format($tot_vente + $acomptediff, 2, ".", "'"), 0, 0, "R");
  } else {
    $pdf->Cell(60, 4, number_format($tot_vente, 2, ".", "'") . " + " . number_format($acomptediff, 2, ".", "'") . " = " . number_format($tot_vente + $acomptediff, 2, ".", "'"), 0, 0, "R");
  }
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetLineWidth(0.2);
  //----------------------------------------//
  //          Detail articles garantie         //
  //          TVA, GM                       //
  //----------------------------------------//
  $detail_garantie_articles = "<TABLE border=1>\n<TR><TH>NoCommande</TH><TH>NoClient</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $tab_detail_garantie_articles[0] = array();
  $tab_detail_garantie_articles[1] = array();
  $tab_detail_garantie_articles[2] = array();
  $tab_detail_garantie_articles[3] = array();
  $tab_detail_garantie_articles[4] = array();
  $tab_detail_garantie_articles[5] = array();
  $tab_detail_garantie_articles[6] = array();
  $tab_detail_garantie_articles[7] = array();
  $tab_detail_acompte_garantie[0] = array();
  $tab_detail_acompte_garantie[1] = array();
  $tab_detail_acompte_garantie[2] = array();
  $tab_detail_acompte_garantie[3] = array();
  $somme_detail_garantie_articles = 0;
  $acomptemoin_garantie = 0;
  $tax_garantie = array();
  $total_garantie_gm_tva = array();
  $requette = "SELECT * FROM commande" . ID_GARAGE . " WHERE (Genre='G') AND Paye='O' AND " . Requette_Recherche("DatePayement", 2, $intervalle) . " ORDER BY DatePayement";
  $resultat = Connection::executeRawQueryWithfetchAll($requette);
  foreach ($resultat as $ligne) {
    $resultat2 = DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'] . ' 00:00:00');;
    foreach ($resultat2 as $ligne2) {
      $acomptemoin_garantie -= $ligne2['Somme'];
      array_push($tab_detail_acompte_garantie[0], Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE));
      array_push($tab_detail_acompte_garantie[1], 0);
      array_push($tab_detail_acompte_garantie[2], -$ligne2['Somme']);
      array_push($tab_detail_acompte_garantie[3], $ligne2['NoFacture']);
      //echo $ligne2['NoFacture'];
      //exit();
    }
    $resultat2 = CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
    foreach ($resultat2 as $ligne2) {
      if ($ligne2['TypeData'] != 1) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        array_push($tab_detail_garantie_articles[0], $ligne2['NoCommande']);
        array_push($tab_detail_garantie_articles[1], $ligne['NoClient']);
        array_push($tab_detail_garantie_articles[2], $ligne2['NoArticle']);
        array_push($tab_detail_garantie_articles[3], $ligne2['Description']);
        array_push($tab_detail_garantie_articles[4], $ligne2['GM']);
        array_push($tab_detail_garantie_articles[5], $tva2);
        array_push($tab_detail_garantie_articles[6], $ligne2['PrixMulti']);
        array_push($tab_detail_garantie_articles[7], substr($ligne['DatePayement'], 8, 2) . "." . substr($ligne['DatePayement'], 5, 2) . "." . substr($ligne['DatePayement'], 2, 2));
        $detail_garantie_articles .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne['NoClient'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>" . $ligne2['PrixMulti'] . "</TD></TR>";
        $somme_detail_garantie_articles += $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_garantie)) {
          $tax_garantie["$tva2"] = 0;
        }
        $tax_garantie["$tva2"] += $ligne2['PrixMulti'];
        //		}
        if (!array_key_exists("$tva2", $total_garantie_gm_tva)) {
          $total_garantie_gm_tva["$tva2"] = array();
          for ($cpt = 0; $cpt < 300; $cpt++) {
            $total_garantie_gm_tva["$tva2"][$cpt] = 0.0;
          }
        }
        $total_garantie_gm_tva["$tva2"][$ligne2['GM']] += $ligne2['PrixMulti'];
      }
    }
  }
  if (!isset($acompteplus_garantie)) {
    $acompteplus_garantie = 0;
  }
  $detail_garantie_articles .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_garantie_articles</TH></TR></TABLE>\n";
  $acomptediff_garantie = $acompteplus_garantie - $acomptemoin_garantie;
  //****************************************//
  array_multisort($tax_garantie, SORT_ASC, SORT_NUMERIC);
  $y = 212;
  $pdf->SetXY(30, $y);
  $pdf->Cell(35, 4, "Comptes TVA garantie", 0, 0, "J");
  $y += 4;
  $nb = 0;
  $pdf->SetFont("Helvetica", "B", 8);
  foreach ($tax_garantie as $taux => $somme) {
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "TTC $taux%", 0, 0, "J");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "Tax $taux%", 0, 0, "J");
    $nb++;
  }
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total TTC", 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total Tax", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $y += 4;
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $tot = 0;
  $tot_tax = 0;
  $somme_total_garantie_gm_tva = array();
  $nb = 0;
  foreach ($tax_garantie as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    if ($nb == 0)
      $pdf->SetLineWidth(0.5);
    $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
    if ($nb == 0)
      $pdf->SetLineWidth(0.2);
    $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme, 2, ".", "'"), 0, 0, "J");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "J");
    $nb++;
  }
  $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
  $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(70 + (40 * $nb), $y - 4, 70 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot_tax, 2, ".", "'"), 0, 0, "J");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $tot_garantie = $tot;
  $y = 225;
  $pdf->SetXY(30, $y);
  $pdf->Cell(50, 4, "Payements partiels garantie", 0, 0, "J");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->Line(30, $y, 30, $y + 12);
  $pdf->Line(120, $y, 120, $y + 12);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(60, $y, 60, $y + 12);
  $pdf->Line(80, $y, 80, $y + 12);
  $pdf->Line(100, $y, 100, $y + 12);
  $pdf->SetXY(60, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(20, 4, "Entrée", 0, 0, "J");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, "Sortie", 0, 0, "J");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, "Différence", 0, 0, "J");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->Cell(30, 4, "Montant TTC", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus_garantie, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin_garantie, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff_garantie, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "TAX 7.6%", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus_garantie * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin_garantie * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff_garantie * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetLineWidth(0.2);
  $y = 225;
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->Line(140, $y, 140, $y + 8);
  $pdf->Line(200, $y, 200, $y + 8);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(60, 4, "Total garantie et payements partiels", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetXY(140, $y);
  if ($acomptediff_garantie < 0) {
    $pdf->Cell(60, 4, number_format($tot_garantie, 2, ".", "'") . " - " . number_format(-$acomptediff_garantie, 2, ".", "'") . " = " . number_format($tot_garantie + $acomptediff_garantie, 2, ".", "'"), 0, 0, "R");
  } else {
    $pdf->Cell(60, 4, number_format($tot_garantie, 2, ".", "'") . " + " . number_format($acomptediff_garantie, 2, ".", "'") . " = " . number_format($tot_garantie + $acomptediff_garantie, 2, ".", "'"), 0, 0, "R");
  }
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetLineWidth(0.2);
  //----------------------------------------//
  //          Detail articles achat         //
  //          TVA, GM                       //
  //----------------------------------------//
  $detail_achat_articles = "<TABLE border=1>\n<TR><TH>NoCommande</TH><TH>NoClient</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
  $tab_detail_achat_articles[0] = array();
  $tab_detail_achat_articles[1] = array();
  $tab_detail_achat_articles[2] = array();
  $tab_detail_achat_articles[3] = array();
  $tab_detail_achat_articles[4] = array();
  $tab_detail_achat_articles[5] = array();
  $tab_detail_achat_articles[6] = array();
  $tab_detail_achat_articles[7] = array();
  $somme_detail_achat_articles = 0;
  $acomptemoin_achat = 0;
  $tax_achat = array();
  $total_achat_gm_tva = array();
  $requette = "SELECT * FROM commande" . ID_GARAGE . " WHERE (Genre='C' OR Genre='A' OR Genre='R') AND Paye='O' AND " . Requette_Recherche("DatePayement", 2, $intervalle) . " ORDER BY DatePayement";
  $resultat = Connection::executeRawQueryWithfetchAll($requette);
  foreach ($resultat as $ligne) {
    $resultat2 = DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'] . ' 00:00:00');;
    foreach ($resultat2 as $ligne2) {
      $acomptemoin_achat -= $ligne2['Somme'];
      array_push($tab_detail_acompte_achat[0], Cree_Entree_Type("", 2, 0, $ligne['DatePayement'], AFFICHAGE));
      array_push($tab_detail_acompte_achat[1], 0);
      array_push($tab_detail_acompte_achat[2], -$ligne2['Somme']);
      array_push($tab_detail_acompte_achat[3], $ligne2['NoFacture']);
    }
    $resultat2 = CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
    foreach ($resultat2 as $ligne2) {
      if ($ligne2['TypeData'] != 1) {
        $tva = $ligne2['TVA'];
        $tva2 = abs($tva);
        array_push($tab_detail_achat_articles[0], $ligne2['NoCommande']);
        array_push($tab_detail_achat_articles[1], $ligne['NoClient']);
        array_push($tab_detail_achat_articles[2], $ligne2['NoArticle']);
        array_push($tab_detail_achat_articles[3], $ligne2['Description']);
        array_push($tab_detail_achat_articles[4], $ligne2['GM']);
        array_push($tab_detail_achat_articles[5], $tva2);
        array_push($tab_detail_achat_articles[6], $ligne2['PrixMulti']);
        array_push($tab_detail_achat_articles[7], substr($ligne['DatePayement'], 8, 2) . "." . substr($ligne['DatePayement'], 5, 2) . "." . substr($ligne['DatePayement'], 2, 2));
        $detail_achat_articles .= "<TR><TD>" . $ligne2['NoCommande'] . "</TD><TD>" . $ligne['NoClient'] . "</TD><TD>" . $ligne2['NoArticle'] . "</TD><TD>" . $ligne2['Description'] . "</TD><TD>" . $ligne2['GM'] . "</TD><TD>" . $tva2 . "</TD><TD>" . $ligne2['PrixMulti'] . "</TD></TR>";
        $somme_detail_achat_articles += $ligne2['PrixMulti'];
        //        if($tva!=0)
        //        {
        if (!array_key_exists("$tva2", $tax_achat)) {
          $tax_achat["$tva2"] = 0;
        }
        $tax_achat["$tva2"] += $ligne2['PrixMulti'];
        //		}
        if (!array_key_exists("$tva2", $total_achat_gm_tva)) {
          $total_achat_gm_tva["$tva2"] = array();
          for ($cpt = 0; $cpt < 300; $cpt++) {
            $total_achat_gm_tva["$tva2"][$cpt] = 0.0;
          }
        }
        $total_achat_gm_tva["$tva2"][$ligne2['GM']] += $ligne2['PrixMulti'];
      }
    }
  }
  $detail_achat_articles .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$somme_detail_achat_articles</TH></TR></TABLE>\n";
  $acomptediff_achat = $acompteplus_achat - $acomptemoin_achat;
  //****************************************//
  array_multisort($tax_achat, SORT_ASC, SORT_NUMERIC);
  $y = 242;
  $pdf->SetXY(30, $y);
  $pdf->Cell(30, 4, "Comptes TVA Achat", 0, 0, "J");
  $y += 4;
  $nb = 0;
  $pdf->SetFont("Helvetica", "B", 8);
  foreach ($tax_achat as $taux => $somme) {
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "TTC $taux%", 0, 0, "J");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, "Tax $taux%", 0, 0, "J");
    $nb++;
  }
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total TTC", 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, "Total Tax", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $y += 4;
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $tot = 0;
  $tot_tax = 0;
  $somme_total_achat_gm_tva = array();
  $nb = 0;
  foreach ($tax_achat as $taux => $somme) {
    $tot += $somme;
    $tot_tax += $somme * (1 - (1 / ((100 + $taux) / 100)));
    if ($nb == 0)
      $pdf->SetLineWidth(0.5);
    $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
    if ($nb == 0)
      $pdf->SetLineWidth(0.2);
    $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
    $pdf->SetXY(30 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme, 2, ".", "'"), 0, 0, "J");
    $pdf->SetXY(50 + ($nb * 40), $y);
    $pdf->Cell(20, 4, number_format($somme * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "J");
    $nb++;
  }
  $pdf->Line(30 + (40 * $nb), $y - 4, 30 + (40 * $nb), $y + 4);
  $pdf->Line(50 + (40 * $nb), $y - 4, 50 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.5);
  $pdf->Line(70 + (40 * $nb), $y - 4, 70 + (40 * $nb), $y + 4);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(30 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot, 2, ".", "'"), 0, 0, "J");
  $pdf->SetXY(50 + ($nb * 40), $y);
  $pdf->Cell(20, 4, number_format($tot_tax, 2, ".", "'"), 0, 0, "J");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 70 + (40 * $nb), $y);
  $pdf->SetLineWidth(0.2);
  $tot_achat = $tot;
  $y = 255;
  $pdf->SetXY(30, $y);
  $pdf->Cell(50, 4, "Payements partiels achat", 0, 0, "J");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->Line(30, $y, 30, $y + 12);
  $pdf->Line(120, $y, 120, $y + 12);
  $pdf->SetLineWidth(0.2);
  $pdf->Line(60, $y, 60, $y + 12);
  $pdf->Line(80, $y, 80, $y + 12);
  $pdf->Line(100, $y, 100, $y + 12);
  $pdf->SetXY(60, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(20, 4, "Entrée", 0, 0, "J");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, "Sortie", 0, 0, "J");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, "Différence", 0, 0, "J");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->Cell(30, 4, "Montant TTC", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus_achat, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin_achat, 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff_achat, 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetXY(30, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(30, 4, "TAX 7.6%", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $pdf->SetXY(60, $y);
  $pdf->Cell(20, 4, number_format($acompteplus_achat * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(80, $y);
  $pdf->Cell(20, 4, number_format($acomptemoin_achat * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $pdf->SetXY(100, $y);
  $pdf->Cell(20, 4, number_format($acomptediff_achat * (1 - (1 / ((100 + 7.6) / 100))), 2, ".", "'"), 0, 0, "R");
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(30, $y, 120, $y);
  $pdf->SetLineWidth(0.2);
  $y = 260;
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->Line(140, $y, 140, $y + 8);
  $pdf->Line(200, $y, 200, $y + 8);
  $pdf->SetLineWidth(0.2);
  $pdf->SetXY(140, $y);
  $pdf->SetFont("Helvetica", "B", 8);
  $pdf->Cell(60, 4, "Total achat et payements partiels", 0, 0, "J");
  $pdf->SetFont("Helvetica", "", 8);
  $y += 4;
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetXY(140, $y);
  if ($acomptediff_achat < 0) {
    $pdf->Cell(60, 4, number_format($tot_achat, 2, ".", "'") . " - " . number_format(-$acomptediff_achat, 2, ".", "'") . " = " . number_format($tot_achat + $acomptediff_achat, 2, ".", "'"), 0, 0, "R");
  } else {
    $pdf->Cell(60, 4, number_format($tot_achat, 2, ".", "'") . " + " . number_format($acomptediff_achat, 2, ".", "'") . " = " . number_format($tot_achat + $acomptediff_achat, 2, ".", "'"), 0, 0, "R");
  }
  $y += 4;
  $pdf->SetLineWidth(0.5);
  $pdf->Line(140, $y, 200, $y);
  $pdf->SetLineWidth(0.2);
  if ($Detail == 1) {
    if ($Detail1 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      for ($cpt_caisse = 0; $cpt_caisse <= $nb_caisses; $cpt_caisse++) {
        $resultat = ModePayement::getModePayementsByNoCaisse($cpt_caisse);
        foreach ($resultat as $ligne) {
          $cpt_mode = $ligne['NoMode'];
          $pdf->SetXY($x, $y);
          $pdf->Cell(40, 4, "Caisse " . $cpt_caisse . " " . $ligne['Description'], 0, 0, "J");
          $y += 4;
          $pdf->Line($x, $y, $x + 70, $y);
          $pdf->SetXY($x, $y);
          $pdf->SetFont("Helvetica", "B", 8);
          $pdf->Cell(30, 4, "Date", 0, 0, "J");
          $pdf->SetXY($x + 30, $y);
          $pdf->Cell(20, 4, "Somme", 0, 0, "J");
          $pdf->SetXY($x + 50, $y);
          $pdf->Cell(20, 4, "No cmd", 0, 0, "J");
          $pdf->SetFont("Helvetica", "", 8);
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 30, $y, $x + 30, $y + 4);
          $pdf->Line($x + 50, $y, $x + 50, $y + 4);
          $pdf->Line($x + 70, $y, $x + 70, $y + 4);
          $y += 4;
          $pdf->Line($x, $y, $x + 70, $y);
          foreach ($tab_detail_mouvement[$cpt_caisse][$cpt_mode][0] as $pos => $date) {
            $pdf->SetXY($x, $y);
            $pdf->Cell(30, 4, $date, 0, 0, "J");
            $pdf->SetXY($x + 30, $y);
            $pdf->Cell(20, 4, number_format($tab_detail_mouvement[$cpt_caisse][$cpt_mode][1][$pos], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 50, $y);
            $pdf->Cell(20, 4, $tab_detail_mouvement[$cpt_caisse][$cpt_mode][2][$pos], 0, 0, "J");
            $pdf->Line($x, $y, $x, $y + 4);
            $pdf->Line($x + 30, $y, $x + 30, $y + 4);
            $pdf->Line($x + 50, $y, $x + 50, $y + 4);
            $pdf->Line($x + 70, $y, $x + 70, $y + 4);
            $y += 4;
            $pdf->Line($x, $y, $x + 70, $y);
            if ($y > 250) {
              if ($x > 30) {
                $pdf->AddPage();
                $pdf->SetXY(30, 18);
                $pdf->SetFont("Helvetica", "", 12);
                $pdf->Cell(200, 8, $txt, 0, 0, "L");
                $pdf->SetXY(150, 18);
                $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
                $no_page++;
                $pdf->SetFont("Helvetica", "", 8);
                $y = 30;
                $x = 30;
                $pdf->Line($x, $y, $x + 70, $y);
                $pdf->Line($x, $y, $x, $y + 4);
                $pdf->Line($x + 30, $y, $x + 30, $y + 4);
                $pdf->Line($x + 50, $y, $x + 50, $y + 4);
                $pdf->Line($x + 70, $y, $x + 70, $y + 4);
              } else {
                $x += 80;
                $y = 30;
                $pdf->Line($x, $y, $x + 70, $y);
                $pdf->Line($x, $y, $x, $y + 4);
                $pdf->Line($x + 30, $y, $x + 30, $y + 4);
                $pdf->Line($x + 50, $y, $x + 50, $y + 4);
                $pdf->Line($x + 70, $y, $x + 70, $y + 4);
              }
            }
          }
          $pdf->SetFont("Helvetica", "B", 8);
          $pdf->SetXY($x, $y);
          $pdf->Cell(70, 4, "mouvements " . number_format($somme_mouvement[$cpt_caisse][$cpt_mode], 2, ".", "'"), 0, 0, "L");
          $pdf->SetXY($x, $y);
          $pdf->Cell(70, 4, "vente " . number_format($somme_vente[$cpt_caisse][$cpt_mode], 2, ".", "'"), 0, 0, "R");
          $pdf->SetXY($x, $y + 4);
          $pdf->Cell(70, 4, "achat " . number_format($somme_achat[$cpt_caisse][$cpt_mode], 2, ".", "'"), 0, 0, "L");
          $pdf->SetXY($x, $y + 4);
          $pdf->Cell(70, 4, "transfert " . number_format($somme_transfert[$cpt_caisse][$cpt_mode], 2, ".", "'"), 0, 0, "R");
          $pdf->SetFont("Helvetica", "", 8);
          $pdf->Line($x, $y, $x, $y + 8);
          $pdf->Line($x + 70, $y, $x + 70, $y + 8);
          $y += 8;
          $pdf->Line($x, $y, $x + 70, $y);
          $y += 4;
        }
      }
    }
    if ($Detail2 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(100, 4, "Détail vente articles", 0, 0, "L");
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(13, 4, "No commande", 0, 0, "L");
      $pdf->SetXY($x + 13, $y);
      $pdf->Cell(13, 4, "No client", 0, 0, "L");
      $pdf->SetXY($x + 26, $y);
      $pdf->Cell(14, 4, "Date", 0, 0, "L");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(30, 4, "No article", 0, 0, "L");
      $pdf->SetXY($x + 70, $y);
      $pdf->Cell(40, 4, "Description", 0, 0, "L");
      $pdf->SetXY($x + 110, $y);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->SetXY($x + 120, $y);
      $pdf->Cell(10, 4, "TVA", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      foreach ($tab_detail_vente_articles[0] as $pos => $nocommande) {
        $pdf->Line($x, $y, $x, $y + 4);
        $pdf->Line($x + 13, $y, $x + 13, $y + 4);
        $pdf->Line($x + 26, $y, $x + 26, $y + 4);
        $pdf->Line($x + 40, $y, $x + 40, $y + 4);
        $pdf->Line($x + 70, $y, $x + 70, $y + 4);
        $pdf->Line($x + 110, $y, $x + 110, $y + 4);
        $pdf->Line($x + 120, $y, $x + 120, $y + 4);
        $pdf->Line($x + 130, $y, $x + 130, $y + 4);
        $pdf->Line($x + 150, $y, $x + 150, $y + 4);
        $pdf->SetXY($x, $y);
        $pdf->Cell(13, 4, $nocommande, 0, 0, "L");
        $pdf->SetXY($x + 13, $y);
        $pdf->Cell(13, 4, $tab_detail_vente_articles[1][$pos], 0, 0, "L");
        $pdf->SetXY($x + 26, $y);
        $pdf->Cell(14, 4, $tab_detail_vente_articles[7][$pos], 0, 0, "L");
        $pdf->SetXY($x + 40, $y);
        $pdf->Cell(30, 4, $tab_detail_vente_articles[2][$pos], 0, 0, "L");
        $pdf->SetXY($x + 70, $y);
        $pdf->Cell(40, 4, $tab_detail_vente_articles[3][$pos], 0, 0, "L");
        $pdf->SetXY($x + 110, $y);
        $pdf->Cell(10, 4, $tab_detail_vente_articles[4][$pos], 0, 0, "L");
        $pdf->SetXY($x + 120, $y);
        $pdf->Cell(10, 4, $tab_detail_vente_articles[5][$pos], 0, 0, "L");
        $pdf->SetXY($x + 130, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_vente_articles[6][$pos], 2, ".", "'"), 0, 0, "R");
        $y += 4;
        $pdf->Line($x, $y, $x + 150, $y);
        if ($y > 250) {
          $pdf->AddPage();
          $pdf->SetXY(30, 18);
          $pdf->SetFont("Helvetica", "", 12);
          $pdf->Cell(200, 8, $txt, 0, 0, "L");
          $pdf->SetXY(150, 18);
          $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
          $no_page++;
          $pdf->SetFont("Helvetica", "", 8);
          $y = 30;
          $pdf->Line($x, $y, $x + 150, $y);
        }
      }
      $pdf->Line($x, $y, $x + 150, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, number_format($somme_detail_vente_articles, 2, ".", "'"), 0, 0, "R");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
    }
    if ($Detail3 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(30, 4, "GM Vente", 0, 0, "L");
      $y += 4;
      array_multisort($total_vente_gm_tva, SORT_ASC, SORT_NUMERIC);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $somme_vente_gm_tva = array();
      foreach ($total_vente_gm_tva as $taux => $somme) {
        $somme_vente_gm_tva[$taux] = 0;
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $zero = true;
        foreach ($total_vente_gm_tva as $taux => $somme) {
          if ($somme[$cpt] != 0) {
            $somme_vente_gm_tva[$taux] += $somme[$cpt];
            $zero = false;
          }
        }
        if (!$zero) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cpt, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_vente_gm_tva as $taux => $somme) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_vente_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_vente_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_vente_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->Cell(40, 4, "Comptes comptables vente", 0, 0, "L");
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "CC", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $total_cc_vente = array();
      foreach ($total_vente_gm_tva as $taux => $somme) {
        $total_cc_vente["$taux"] = array();
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $no_cc = 0;
        $resultat_cc = Compta::getByVenteAndGM(1, $cpt);
        if ($ligne_cc = $resultat_cc[0]) {
          $no_cc = $ligne_cc['Compte'];
        }
        foreach ($total_vente_gm_tva as $taux => $somme) {
          if (array_key_exists("$no_cc", $total_cc_vente["$taux"])) {
            $total_cc_vente["$taux"]["$no_cc"] += $total_vente_gm_tva["$taux"][$cpt];
          } else {
            $total_cc_vente["$taux"]["$no_cc"] = $total_vente_gm_tva["$taux"][$cpt];
          }
        }
      }
      if (count($total_cc_vente) != 0) {
        $lolo = array_keys($total_cc_vente);
        $lolo2 = $lolo[0];
        foreach ($total_cc_vente["$lolo2"] as $cc => $somme) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cc, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_cc_vente as $taux => $somme2) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_vente_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_vente_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_vente_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
    }
    if ($Detail8 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(100, 4, "Détail garantie articles", 0, 0, "L");
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(13, 4, "No cmd", 0, 0, "L");
      $pdf->SetXY($x + 13, $y);
      $pdf->Cell(13, 4, "No client", 0, 0, "L");
      $pdf->SetXY($x + 26, $y);
      $pdf->Cell(14, 4, "Date", 0, 0, "L");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(30, 4, "No article", 0, 0, "L");
      $pdf->SetXY($x + 70, $y);
      $pdf->Cell(40, 4, "Description", 0, 0, "L");
      $pdf->SetXY($x + 110, $y);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->SetXY($x + 120, $y);
      $pdf->Cell(10, 4, "TVA", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      foreach ($tab_detail_garantie_articles[0] as $pos => $nocommande) {
        $pdf->Line($x, $y, $x, $y + 4);
        $pdf->Line($x + 13, $y, $x + 13, $y + 4);
        $pdf->Line($x + 26, $y, $x + 26, $y + 4);
        $pdf->Line($x + 40, $y, $x + 40, $y + 4);
        $pdf->Line($x + 70, $y, $x + 70, $y + 4);
        $pdf->Line($x + 110, $y, $x + 110, $y + 4);
        $pdf->Line($x + 120, $y, $x + 120, $y + 4);
        $pdf->Line($x + 130, $y, $x + 130, $y + 4);
        $pdf->Line($x + 150, $y, $x + 150, $y + 4);
        $pdf->SetXY($x, $y);
        $pdf->Cell(13, 4, $nocommande, 0, 0, "L");
        $pdf->SetXY($x + 13, $y);
        $pdf->Cell(13, 4, $tab_detail_garantie_articles[1][$pos], 0, 0, "L");
        $pdf->SetXY($x + 26, $y);
        $pdf->Cell(14, 4, $tab_detail_garantie_articles[7][$pos], 0, 0, "L");
        $pdf->SetXY($x + 40, $y);
        $pdf->Cell(30, 4, $tab_detail_garantie_articles[2][$pos], 0, 0, "L");
        $pdf->SetXY($x + 70, $y);
        $pdf->Cell(40, 4, $tab_detail_garantie_articles[3][$pos], 0, 0, "L");
        $pdf->SetXY($x + 110, $y);
        $pdf->Cell(10, 4, $tab_detail_garantie_articles[4][$pos], 0, 0, "L");
        $pdf->SetXY($x + 120, $y);
        $pdf->Cell(10, 4, $tab_detail_garantie_articles[5][$pos], 0, 0, "L");
        $pdf->SetXY($x + 130, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_garantie_articles[6][$pos], 2, ".", "'"), 0, 0, "R");
        $y += 4;
        $pdf->Line($x, $y, $x + 150, $y);
        if ($y > 250) {
          $pdf->AddPage();
          $pdf->SetXY(30, 18);
          $pdf->SetFont("Helvetica", "", 12);
          $pdf->Cell(200, 8, $txt, 0, 0, "L");
          $pdf->SetXY(150, 18);
          $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
          $no_page++;
          $pdf->SetFont("Helvetica", "", 8);
          $y = 30;
          $pdf->Line($x, $y, $x + 150, $y);
        }
      }
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(13, 4, "Total", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, number_format($somme_detail_garantie_articles, 2, ".", "'"), 0, 0, "R");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
    }
    if ($Detail9 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(30, 4, "GM Garantie", 0, 0, "L");
      $y += 4;
      array_multisort($total_garantie_gm_tva, SORT_ASC, SORT_NUMERIC);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $somme_garantie_gm_tva = array();
      foreach ($total_garantie_gm_tva as $taux => $somme) {
        $somme_garantie_gm_tva[$taux] = 0;
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $zero = true;
        foreach ($total_garantie_gm_tva as $taux => $somme) {
          if ($somme[$cpt] != 0) {
            $somme_garantie_gm_tva[$taux] += $somme[$cpt];
            $zero = false;
          }
        }
        if (!$zero) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cpt, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_garantie_gm_tva as $taux => $somme) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_garantie_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_garantie_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_garantie_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->Cell(40, 4, "Comptes comptables garantie", 0, 0, "L");
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "CC", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $total_cc_garantie = array();
      foreach ($total_garantie_gm_tva as $taux => $somme) {
        $total_cc_garantie["$taux"] = array();
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $no_cc = 0;
        $resultat_cc = Compta::getByVenteAndGM(1, $cpt);
        if ($ligne_cc = $resultat_cc[0]) {
          $no_cc = $ligne_cc['Compte'];
        }
        foreach ($total_garantie_gm_tva as $taux => $somme) {
          if (array_key_exists("$no_cc", $total_cc_garantie["$taux"])) {
            $total_cc_garantie["$taux"]["$no_cc"] += $total_garantie_gm_tva["$taux"][$cpt];
          } else {
            $total_cc_garantie["$taux"]["$no_cc"] = $total_garantie_gm_tva["$taux"][$cpt];
          }
        }
      }
      if (count($total_cc_garantie) != 0) {
        $lolo = array_keys($total_cc_garantie);
        $lolo2 = $lolo[0];
        foreach ($total_cc_garantie["$lolo2"] as $cc => $somme) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cc, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_cc_garantie as $taux => $somme2) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_garantie_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_garantie_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_garantie_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
    }
    if ($Detail4 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(100, 4, "Détail achat articles", 0, 0, "L");
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(13, 4, "No cmd", 0, 0, "L");
      $pdf->SetXY($x + 13, $y);
      $pdf->Cell(13, 4, "No client", 0, 0, "L");
      $pdf->SetXY($x + 26, $y);
      $pdf->Cell(14, 4, "Date", 0, 0, "L");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(30, 4, "No article", 0, 0, "L");
      $pdf->SetXY($x + 70, $y);
      $pdf->Cell(40, 4, "Description", 0, 0, "L");
      $pdf->SetXY($x + 110, $y);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->SetXY($x + 120, $y);
      $pdf->Cell(10, 4, "TVA", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
      foreach ($tab_detail_achat_articles[0] as $pos => $nocommande) {
        $pdf->Line($x, $y, $x, $y + 4);
        $pdf->Line($x + 13, $y, $x + 13, $y + 4);
        $pdf->Line($x + 26, $y, $x + 26, $y + 4);
        $pdf->Line($x + 40, $y, $x + 40, $y + 4);
        $pdf->Line($x + 70, $y, $x + 70, $y + 4);
        $pdf->Line($x + 110, $y, $x + 110, $y + 4);
        $pdf->Line($x + 120, $y, $x + 120, $y + 4);
        $pdf->Line($x + 130, $y, $x + 130, $y + 4);
        $pdf->Line($x + 150, $y, $x + 150, $y + 4);
        $pdf->SetXY($x, $y);
        $pdf->Cell(13, 4, $nocommande, 0, 0, "L");
        $pdf->SetXY($x + 13, $y);
        $pdf->Cell(13, 4, $tab_detail_achat_articles[1][$pos], 0, 0, "L");
        $pdf->SetXY($x + 26, $y);
        $pdf->Cell(14, 4, $tab_detail_achat_articles[7][$pos], 0, 0, "L");
        $pdf->SetXY($x + 40, $y);
        $pdf->Cell(30, 4, $tab_detail_achat_articles[2][$pos], 0, 0, "L");
        $pdf->SetXY($x + 70, $y);
        $pdf->Cell(40, 4, $tab_detail_achat_articles[3][$pos], 0, 0, "L");
        $pdf->SetXY($x + 110, $y);
        $pdf->Cell(10, 4, $tab_detail_achat_articles[4][$pos], 0, 0, "L");
        $pdf->SetXY($x + 120, $y);
        $pdf->Cell(10, 4, $tab_detail_achat_articles[5][$pos], 0, 0, "L");
        $pdf->SetXY($x + 130, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_achat_articles[6][$pos], 2, ".", "'"), 0, 0, "R");
        $y += 4;
        $pdf->Line($x, $y, $x + 150, $y);
        if ($y > 250) {
          $pdf->AddPage();
          $pdf->SetXY(30, 18);
          $pdf->SetFont("Helvetica", "", 12);
          $pdf->Cell(200, 8, $txt, 0, 0, "L");
          $pdf->SetXY(150, 18);
          $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
          $no_page++;
          $pdf->SetFont("Helvetica", "", 8);
          $y = 30;
          $pdf->Line($x, $y, $x + 150, $y);
        }
      }
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 13, $y, $x + 13, $y + 4);
      $pdf->Line($x + 26, $y, $x + 26, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 70, $y, $x + 70, $y + 4);
      $pdf->Line($x + 110, $y, $x + 110, $y + 4);
      $pdf->Line($x + 120, $y, $x + 120, $y + 4);
      $pdf->Line($x + 130, $y, $x + 130, $y + 4);
      $pdf->Line($x + 150, $y, $x + 150, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(13, 4, "Total", 0, 0, "L");
      $pdf->SetXY($x + 130, $y);
      $pdf->Cell(20, 4, number_format($somme_detail_achat_articles, 2, ".", "'"), 0, 0, "R");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 150, $y);
    }
    if ($Detail5 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 30;
      $pdf->SetXY($x, $y);
      $pdf->Cell(30, 4, "GM Achat", 0, 0, "L");
      $y += 4;
      array_multisort($total_achat_gm_tva, SORT_ASC, SORT_NUMERIC);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "GM", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $somme_achat_gm_tva = array();
      foreach ($total_achat_gm_tva as $taux => $somme) {
        $somme_achat_gm_tva[$taux] = 0;
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $zero = true;
        foreach ($total_achat_gm_tva as $taux => $somme) {
          if ($somme[$cpt] != 0) {
            $somme_achat_gm_tva[$taux] += $somme[$cpt];
            $zero = false;
          }
        }
        if (!$zero) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cpt, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_achat_gm_tva as $taux => $somme) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme[$cpt] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_achat_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_achat_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_achat_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->Cell(40, 4, "Comptes comptables achat", 0, 0, "L");
      $y += 4;
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "CC", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      $total_cc_achat = array();
      foreach ($total_achat_gm_tva as $taux => $somme) {
        $total_cc_achat["$taux"] = array();
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(40, 4, "TOT ($taux%)", 0, 0, "L");
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
      for ($cpt = 0; $cpt < 300; $cpt++) {
        $no_cc = 0;
        $resultat_cc = Compta::getByVenteAndGM(0, $cpt);
        if ($ligne_cc = $resultat_cc[0]) {
          $no_cc = $ligne_cc['Compte'];
        }
        foreach ($total_achat_gm_tva as $taux => $somme) {
          if (array_key_exists("$no_cc", $total_cc_achat["$taux"])) {
            $total_cc_achat["$taux"]["$no_cc"] += $total_achat_gm_tva["$taux"][$cpt];
          } else {
            $total_cc_achat["$taux"]["$no_cc"] = $total_achat_gm_tva["$taux"][$cpt];
          }
        }
      }
      if (count($total_cc_achat) != 0) {
        $lolo = array_keys($total_cc_achat);
        $lolo2 = $lolo[0];
        foreach ($total_cc_achat["$lolo2"] as $cc => $somme) {
          $pdf->SetXY($x, $y);
          $pdf->Cell(10, 4, $cc, 0, 0, "L");
          $pdf->Line($x, $y, $x, $y + 4);
          $pdf->Line($x + 10, $y, $x + 10, $y + 4);
          $nb = 0;
          foreach ($total_cc_achat as $taux => $somme2) {
            $pdf->SetXY($x + 10 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc], 2, ".", "'"), 0, 0, "R");
            $pdf->SetXY($x + 30 + ($nb * 40), $y);
            $pdf->Cell(20, 4, number_format($somme2[$cc] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
            $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
            $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
            $nb++;
          }
          $y += 4;
          $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
        }
      }
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(10, 4, "Total", 0, 0, "L");
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 10, $y, $x + 10, $y + 4);
      $nb = 0;
      foreach ($total_achat_gm_tva as $taux => $somme) {
        $pdf->SetXY($x + 10 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_achat_gm_tva[$taux], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 30 + ($nb * 40), $y);
        $pdf->Cell(20, 4, number_format($somme_achat_gm_tva[$taux] * (1 - (1 / ((100 + $taux) / 100))), 2, ".", "'"), 0, 0, "R");
        $pdf->Line($x + 30 + ($nb * 40), $y, $x + 30 + ($nb * 40), $y + 4);
        $pdf->Line($x + 50 + ($nb * 40), $y, $x + 50 + ($nb * 40), $y + 4);
        $nb++;
      }
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 10 + (40 * $nb), $y);
    }
    if ($Detail6 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 20;
      $pdf->SetXY($x, $y);
      $pdf->Cell(60, 4, "Détails payements partiels vente", 0, 0, "L");
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 20, $y, $x + 20, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 60, $y, $x + 60, $y + 4);
      $pdf->Line($x + 80, $y, $x + 80, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(20, 4, "Date", 0, 0, "L");
      $pdf->SetXY($x + 20, $y);
      $pdf->Cell(20, 4, "Entrée", 0, 0, "L");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(20, 4, "Sortie", 0, 0, "L");
      $pdf->SetXY($x + 60, $y);
      $pdf->Cell(20, 4, "Commande", 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      foreach ($tab_detail_acompte[0] as $pos => $date) {
        $pdf->Line($x, $y, $x, $y + 4);
        $pdf->Line($x + 20, $y, $x + 20, $y + 4);
        $pdf->Line($x + 40, $y, $x + 40, $y + 4);
        $pdf->Line($x + 60, $y, $x + 60, $y + 4);
        $pdf->Line($x + 80, $y, $x + 80, $y + 4);
        $pdf->SetXY($x, $y);
        $pdf->Cell(20, 4, $date, 0, 0, "L");
        $pdf->SetXY($x + 20, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_acompte[1][$pos], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 40, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_acompte[2][$pos], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 60, $y);
        $pdf->Cell(20, 4, $tab_detail_acompte[3][$pos], 0, 0, "L");
        $y += 4;
        $pdf->Line($x, $y, $x + 80, $y);
        if ($y > 250) {
          if ($x > 20) {
            $pdf->AddPage();
            $pdf->SetXY(30, 18);
            $pdf->SetFont("Helvetica", "", 12);
            $pdf->Cell(200, 8, $txt, 0, 0, "L");
            $pdf->SetXY(150, 18);
            $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
            $no_page++;
            $pdf->SetFont("Helvetica", "", 8);
            $x = 20;
            $y = 30;
            $pdf->Line($x, $y, $x + 80, $y);
          } else {
            $x += 90;
            $y = 30;
            $pdf->Line($x, $y, $x + 80, $y);
          }
        }
      }
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 20, $y, $x + 20, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 60, $y, $x + 60, $y + 4);
      $pdf->Line($x + 80, $y, $x + 80, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetXY($x + 20, $y);
      $pdf->Cell(20, 4, number_format($acompteplus, 2, ".", "'"), 0, 0, "R");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(20, 4, number_format($acomptemoin, 2, ".", "'"), 0, 0, "R");
      $pdf->SetFont("Helvetica", "B", 9);
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      $pdf->SetXY($x, $y);
      $pdf->Cell(100, 4, "Différence Entrées-Sorties = " . number_format($acomptediff, 2, ".", "'"), 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
    }
    if ($Detail7 == 1) {
      $pdf->AddPage();
      $pdf->SetXY(30, 18);
      $pdf->SetFont("Helvetica", "", 12);
      $pdf->Cell(200, 8, $txt, 0, 0, "L");
      $pdf->SetXY(150, 18);
      $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
      $no_page++;
      $pdf->SetFont("Helvetica", "", 8);
      $y = 30;
      $x = 20;
      $pdf->SetXY($x, $y);
      $pdf->Cell(60, 4, "Détails payements partiels achat", 0, 0, "L");
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 20, $y, $x + 20, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 60, $y, $x + 60, $y + 4);
      $pdf->Line($x + 80, $y, $x + 80, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(20, 4, "Date", 0, 0, "L");
      $pdf->SetXY($x + 20, $y);
      $pdf->Cell(20, 4, "Entrée", 0, 0, "L");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(20, 4, "Sortie", 0, 0, "L");
      $pdf->SetXY($x + 60, $y);
      $pdf->Cell(20, 4, "Commande", 0, 0, "L");
      $pdf->SetFont("Helvetica", "B", 8);
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      foreach ($tab_detail_acompte_achat[0] as $pos => $date) {
        $pdf->Line($x, $y, $x, $y + 4);
        $pdf->Line($x + 20, $y, $x + 20, $y + 4);
        $pdf->Line($x + 40, $y, $x + 40, $y + 4);
        $pdf->Line($x + 60, $y, $x + 60, $y + 4);
        $pdf->Line($x + 80, $y, $x + 80, $y + 4);
        $pdf->SetXY($x, $y);
        $pdf->Cell(20, 4, $date, 0, 0, "L");
        $pdf->SetXY($x + 20, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_acompte_achat[1][$pos], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 40, $y);
        $pdf->Cell(20, 4, number_format($tab_detail_acompte_achat[2][$pos], 2, ".", "'"), 0, 0, "R");
        $pdf->SetXY($x + 60, $y);
        $pdf->Cell(20, 4, $tab_detail_acompte_achat[3][$pos], 0, 0, "L");
        $y += 4;
        $pdf->Line($x, $y, $x + 80, $y);
        if ($y > 250) {
          if ($x > 20) {
            $pdf->AddPage();
            $pdf->SetXY(30, 18);
            $pdf->SetFont("Helvetica", "", 12);
            $pdf->Cell(200, 8, $txt, 0, 0, "L");
            $pdf->SetXY(150, 18);
            $pdf->Cell(40, 8, "Page " . $no_page, 0, 0, "R");
            $no_page++;
            $pdf->SetFont("Helvetica", "", 8);
            $x = 20;
            $y = 30;
            $pdf->Line($x, $y, $x + 80, $y);
          } else {
            $x += 90;
            $y = 30;
            $pdf->Line($x, $y, $x + 80, $y);
          }
        }
      }
      $pdf->Line($x, $y, $x, $y + 4);
      $pdf->Line($x + 20, $y, $x + 20, $y + 4);
      $pdf->Line($x + 40, $y, $x + 40, $y + 4);
      $pdf->Line($x + 60, $y, $x + 60, $y + 4);
      $pdf->Line($x + 80, $y, $x + 80, $y + 4);
      $pdf->SetXY($x, $y);
      $pdf->SetFont("Helvetica", "B", 8);
      $pdf->Cell(20, 4, "Total", 0, 0, "L");
      $pdf->SetXY($x + 20, $y);
      $pdf->Cell(20, 4, number_format($acompteplus_achat, 2, ".", "'"), 0, 0, "R");
      $pdf->SetXY($x + 40, $y);
      $pdf->Cell(20, 4, number_format($acomptemoin_achat, 2, ".", "'"), 0, 0, "R");
      $pdf->SetFont("Helvetica", "B", 9);
      $y += 4;
      $pdf->Line($x, $y, $x + 80, $y);
      $pdf->SetXY($x, $y);
      $pdf->Cell(100, 4, "Différence Entrées-Sorties = " . number_format($acomptediff_achat, 2, ".", "'"), 0, 0, "L");
      $pdf->SetFont("Helvetica", "", 8);
    }
  }
  $pdf->Output();
  //echo "fin";
}
