<?php
        switch($Etape)
        {
          case 0:
           echo "<form name='info'>";
       echo "<TABLE border=1><TR><TH>Date</TH><TD>".Cree_Entree_Type("intervalle",2,0,"",RECHERCHE)."</TD></TR><TR><TH>Detail</TH><TD><INPUT type='checkbox' name='Detail' value='1' checked></TD></TR></TABLE>";
             echo "<input type='hidden' name='Type' value=$Type>";
             echo "<input type='hidden' name='Sous_Type' value=$Sous_Type>";
             echo "<input type='hidden' name='Etape' value='1'>";
     echo "<script language=JavaScript>\n";
     echo "force_submit=true;\n";
     echo "this.document.forms['info'].elements[0].focus();\n";
     echo "</script>\n";
             echo "<button type='button' onClick='submit_ok(this.form);'>Rechercher</button>";
       echo "</form>";
          break;
          case 1:
            if(!isset($Detail))
            {
              $Detail=0;
        }
            if($ligne=Caisse::getOneLesserDate(substr(Decode_Entree_Type($intervalle,2),0,10)))
            {
              $resultat2=DBCash::getByPeriod($ligne['Date'].' 23:59:59', substr(Decode_Entree_Type($intervalle,2),0,10).' 00:00:00');
              $somme=0;
              foreach($resultat2 as $ligne2)
              {
                $somme+=$ligne2['Somme'];
        }
        $total=round($ligne['Montant']+$somme,2);
                echo "<big>Montant en caisse ouverture $total</big><BR>";
                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";
        }
        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";
        }
              $resultat2=Connection::executeRawQueryWithfetchAll($requette2);
              $somme=0;
              foreach($resultat2 as $ligne2)
              {
                $somme+=$ligne2['Somme'];
        }
        $total=round($ligne['Montant']+$somme,2);
                echo "<big>Montant en caisse clôture $total</big><BR>";
        }
           $requettea="SELECT * FROM dbcash".ID_GARAGE." WHERE ".Requette_Recherche("Date",18,$intervalle)." ORDER BY ModePayement, Date";
           $resultata=Connection::executeRawQueryWithfetchAll($requettea);
           $listeerr="";
           $somme=0;
           $sommec=0;
           $sommeg=0;
           $sommeg2=0;
           $sommeg3=0;
           $sommecc=0;
           $sommevente=0;
           $sommeachat=0;
           $sommetransfert=0;
           $totsommevente=0;
           $totsommeachat=0;
           $totsommetransfert=0;
           $acompteplus=0;
           $acomptemoin=0;
           $first=true;
           $typepa=0;
           $outc="";
           $outa="<TABLE border=1><TR><TH>Date</TH><TH>acompte entree</TH><TH>acompte sortie</TH><TH>NoCommande</TH></TR>\n";
           foreach($resultata as $lignea)
           {
             if($first)
             {
               $lignen=ModePayement::getModePaymentByNoMode($lignea['ModePayement']);
               $outc="<BIG>".$lignen['Description']."</BIG><BR><TABLE border=1><TR><TH>Date</TH><TH>Somme</TH><TH>NoCommande</TH></TR>\n";
               $first=false;
               $last_mode_payement=$lignea['ModePayement'];
               $typepa=$lignen['Type'];
        }
             if($lignea['ModePayement']!=$last_mode_payement)
             {
               $last_mode_payement=$lignea['ModePayement'];
               $lignen=ModePayement::getModePaymentByNoMode($lignea['ModePayement']);
            $outc.="<TR><TD>&nbsp;</TD><TH>$sommec vente $sommevente achat $sommeachat transfert $sommetransfert</TH><TD>&nbsp;</TD></TR></TABLE>\n<BIG>".$lignen['Description']."</BIG><BR><TABLE border=1><TR><TH>Date</TH><TH>Somme</TH><TH>NoCommande</TH></TR>\n";
            $totsommevente+=$sommevente;
            $totsommeachat+=$sommeachat;
            $totsommetransfert+=$sommetransfert;
            $sommevente=0;
            $sommeachat=0;
            $sommetransfert=0;
            if($typepa==1)
            {
              $sommecc+=$sommec;
          }
            $sommec=0;
               $typepa=$lignen['Type'];
        }
        if($lignea['NoFacture']<760000)
        {
          $sommevente+=$lignea['Somme'];
        }
        else if($lignea['NoFacture']<930000)
        {
          $sommeachat+=$lignea['Somme'];
        }
        else if($lignea['NoFacture']<950000)
        {
          $sommetransfert+=$lignea['Somme'];
        }
        else
        {
          $sommeachat+=$lignea['Somme'];
        }
             $outc.="<TR><TD>".Cree_Entree_Type("",18,0,$lignea['Date'],AFFICHAGE)."</TD><TD>".$lignea['Somme']."</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
             $sommec+=$lignea['Somme'];
             if($ligneb=Commande::getCommandeByNoCommande($lignea['NoFacture']) && $ligneb["Paye"] == 'O')
             {
                $resultatc=Commande::getCommandeByNoCommandeAndDatePayement($lignea['NoFacture'], substr($lignea['Date'],0,10));
                 if($lignec=$resultatc[0])
                  {
                  }
                  else
                  {
                    $outa.="<TR><TD>".Cree_Entree_Type("",2,0,$lignea['Date'],AFFICHAGE)."</TD><TD>".$lignea['Somme']."</TD><TD>0</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
                          $acompteplus+=$lignea['Somme'];
                  }
        }
        else
        {
                $acompteplus+=$lignea['Somme'];
          $outa.="<TR><TD>".Cree_Entree_Type("",2,0,$lignea['Date'],AFFICHAGE)."</TD><TD>".$lignea['Somme']."</TD><TD>0</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
        }
             $somme+=$lignea['Somme'];
       }
       if($typepa==1)
       {
         $sommecc+=$sommec;
       }
       echo "<BIG>Total cartes de crédit $sommecc</BIG><BR>\n";
           $requette="SELECT * FROM commande".ID_GARAGE." WHERE Genre='F' AND Paye='O' AND ".Requette_Recherche("DatePayement",2,$intervalle)." ORDER BY DatePayement";
           $resultat=Connection::executeRawQueryWithfetchAll($requette);
           $total=array();
           $tax=array();
           $tax3=array();
       $out1="<TABLE border=1><TR><TH>NoCommande</TH></TR>\n";
       $out2="<TABLE border=1><TR><TH>NoCommande</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
       $out4="<TABLE border=1><TR><TH>NoCommande</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
           foreach($resultat as $ligne)
           {
             $resultata=DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'].' 00:00:00');
             foreach($resultata as $lignea)
             {
               $acomptemoin+=$lignea['Somme'];
          $outa.="<TR><TD>".Cree_Entree_Type("",2,0,$ligne['DatePayement'],AFFICHAGE)."</TD><TD>0</TD><TD>".$lignea['Somme']."</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
        }
             $out1 .= "<TR><TD>".$ligne['NoCommande']."</TD></TR>\n";
             if($lignea=DBCash::getSumByNoFacture($ligne['NoCommande']))
             {
               if($lignea[0]!=$ligne['MontantTotal'])
               {
               $listeerr.=$ligne['NoCommande']." ";
              }
            }
             $resultat2=CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
             foreach($resultat2 as $ligne2)
             {
               if($ligne2['TypeData']==0)
               {
            $tva=$ligne2['TVA'];
                      $tva2=abs($tva);
                 $out2 .= "<TR><TD>".$ligne2['NoCommande']."</TD><TD>".$ligne2['NoArticle']."</TD><TD>".$ligne2['Description']."</TD><TD>".$ligne2['GM']."</TD><TD>".$tva2."</TD><TD>".$ligne2['PrixMulti']."</TD></TR>";
//                 echo $ligne2['Position'] . " " . $ligne2['Description'] . " " . $ligne2['GM'] . " " . $ligne2['PrixMulti'] . "<BR>";
            $sommeg+=$ligne2['PrixMulti'];
                      if($tva!=0)
                      {
                        if(!array_key_exists("$tva2",$tax))
                        {
                          $tax["$tva2"]=0;
//                          echo "$tva2<BR>";
              }
              $tax["$tva2"]+=$ligne2['PrixMulti'];
            }
            if(!array_key_exists("$tva2",$total))
            {
              $total["$tva2"]=array();
              for($cpt=0;$cpt<300;$cpt++)
                   {
                     $total["$tva2"][$cpt]=0.0;
               }
            }
                 $total["$tva2"][$ligne2['GM']]+=$ligne2['PrixMulti'];
               }
               if($ligne2['TypeData']==3)
               {
            $tva=$ligne2['TVA'];
                      $tva2=abs($tva);
                 $out4 .= "<TR><TD>".$ligne2['NoCommande']."</TD><TD>".$ligne2['NoArticle']."</TD><TD>".$ligne2['Description']."</TD><TD>".$ligne2['GM']."</TD><TD>".$tva2."</TD><TD>".$ligne2['PrixMulti']."</TD></TR>";
//                 echo $ligne2['Position'] . " " . $ligne2['Description'] . " " . $ligne2['GM'] . " " . $ligne2['PrixMulti'] . "<BR>";
            $sommeg3+=$ligne2['PrixMulti'];
                      if($tva!=0)
                      {
                        if(!array_key_exists("$tva2",$tax3))
                        {
                          $tax3["$tva2"]=0;
//                          echo "$tva2<BR>";
              }
              $tax3["$tva2"]+=$ligne2['PrixMulti'];
            }
//            if(!array_key_exists("$tva2",$total))
//            {
//              $total["$tva2"]=array();
//              for($cpt=0;$cpt<200;$cpt++)
//                   {
//                     $total["$tva2"][$cpt]=0.0;
//               }
//            }
//                 $total["$tva2"][$ligne2['GM']]+=$ligne2['PrixMulti'];
               }
        }
       }
           $resultat=Connection::executeRawQueryWithfetchAll($requette);
           foreach($resultat as $ligne)
           {
             $resultata=DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'].' 00:00:00');
             foreach($resultata as $lignea)
             {
               $acomptemoin-=$lignea['Somme'];
          $outa.="<TR><TD>".Cree_Entree_Type("",2,0,$ligne['DatePayement'],AFFICHAGE)."</TD><TD>0</TD><TD>".(-$lignea['Somme'])."</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
        }
             $out1 .= "<TR><TD>".$ligne['NoCommande']."</TD></TR>\n";
             $resultat2=CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
             foreach($resultat2 as $ligne2)
             {
               if($ligne2['TypeData']==0)
               {
            $tva=$ligne2['TVA'];
                      $tva2=abs($tva);
                 $out2 .= "<TR><TD>".$ligne2['NoCommande']."</TD><TD>".$ligne2['NoArticle']."</TD><TD>".$ligne2['Description']."</TD><TD>".$ligne2['GM']."</TD><TD>".$tva2."</TD><TD>".(-$ligne2['PrixMulti'])."</TD></TR>";
//                 echo $ligne2['Position'] . " " . $ligne2['Description'] . " " . $ligne2['GM'] . " " . $ligne2['PrixMulti'] . "<BR>";
            $sommeg-=$ligne2['PrixMulti'];
                      if($tva!=0)
                      {
                        if(!array_key_exists("$tva2",$tax))
                        {
                          $tax["$tva2"]=0;
//                          echo "$tva2<BR>";
              }
              $tax["$tva2"]-=$ligne2['PrixMulti'];
            }
            if(!array_key_exists("$tva2",$total))
            {
              $total["$tva2"]=array();
              for($cpt=0;$cpt<300;$cpt++)
                   {
                     $total["$tva2"][$cpt]=0.0;
               }
            }
                 $total["$tva2"][$ligne2['GM']]-=$ligne2['PrixMulti'];
               }
               if($ligne2['TypeData']==3)
               {
            $tva=$ligne2['TVA'];
                      $tva2=abs($tva);
                 $out4 .= "<TR><TD>".$ligne2['NoCommande']."</TD><TD>".$ligne2['NoArticle']."</TD><TD>".$ligne2['Description']."</TD><TD>".$ligne2['GM']."</TD><TD>".$tva2."</TD><TD>".(-$ligne2['PrixMulti'])."</TD></TR>";
            $sommeg3-=$ligne2['PrixMulti'];
                      if($tva!=0)
                      {
                        if(!array_key_exists("$tva2",$tax3))
                        {
                          $tax3["$tva2"]=0;
              }
              $tax3["$tva2"]-=$ligne2['PrixMulti'];
            }
               }
        }
       }
           $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);
           $total2=array();
           $tax2=array();
       $out3="<TABLE border=1><TR><TH>NoCommande</TH><TH>NoArticle</TH><TH>Description</TH><TH>GM</TH><TH>TVA</TH><TH>Total</TH></TR>\n";
           foreach($resultat as $ligne)
           {
             $resultata=DBCash::getDBCashByNoFactureAndLesserDate($ligne['NoCommande'], $ligne['DatePayement'].' 00:00:00');
             foreach($resultata as $lignea)
             {
               $acomptemoin+=$lignea['Somme'];
          $outa.="<TR><TD>".Cree_Entree_Type("",2,0,$ligne['DatePayement'],AFFICHAGE)."</TD><TD>0</TD><TD>".$lignea['Somme']."</TD><TD>".$lignea['NoFacture']."</TD></TR>\n";
        }
            $resultat2=CommandeArticle::getCommandeArticleByNoCommande($ligne['NoCommande']);
            foreach($resultat2 as $ligne2)
             {
               if($ligne2['TypeData']!=1)
               {
            $tva=$ligne2['TVA'];
                      $tva2=abs($tva);
                 $out3 .= "<TR><TD>".$ligne2['NoCommande']."</TD><TD>".$ligne2['NoArticle']."</TD><TD>".$ligne2['Description']."</TD><TD>".$ligne2['GM']."</TD><TD>".$tva2."</TD><TD>".$ligne2['PrixMulti']."</TD></TR>";
//                 echo $ligne2['Position'] . " " . $ligne2['Description'] . " " . $ligne2['GM'] . " " . $ligne2['PrixMulti'] . "<BR>";
            $sommeg2+=$ligne2['PrixMulti'];
                      if($tva!=0)
                      {
                        if(!array_key_exists("$tva2",$tax2))
                        {
                          $tax2["$tva2"]=0;
//                          echo "$tva2<BR>";
              }
              $tax2["$tva2"]+=$ligne2['PrixMulti'];
            }
            if(!array_key_exists("$tva2",$total2))
            {
              $total2["$tva2"]=array();
              for($cpt=0;$cpt<300;$cpt++)
                   {
                     $total2["$tva2"][$cpt]=0.0;
               }
            }
                 $total2["$tva2"][$ligne2['GM']]+=$ligne2['PrixMulti'];
               }
        }
       }
       if(!$first)
       $outc .= "<TR><TD>&nbsp;</TD><TH>$sommec vente $sommevente achat $sommeachat transfert $sommetransfert</TH><TD>&nbsp;</TD></TR></TABLE>\n";
       $totsommevente+=$sommevente;
       $totsommeachat+=$sommeachat;
       $totsommetransfert+=$sommetransfert;
       $acomptediff=$acompteplus-$acomptemoin;
       $outa .= "<TR><TD>&nbsp;</TD><TH>$acompteplus</TH><TH>$acomptemoin</TH><TD>&nbsp;</TD></TR></TABLE>\n";
       $out1 .= "</TABLE>\n";
       $out2 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$sommeg</TH></TR></TABLE>\n";
       $out4 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$sommeg3</TH></TR></TABLE>\n";
//       $out2 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>Acomptes entrants</TD><TD>&nbsp;</TD><TD>7.6</TD><TH>$acompteplus</TH></TR>\n";
//       $out2 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>Acomptes sortants</TD><TD>&nbsp;</TD><TD>7.6</TD><TH>-$acomptemoin</TH></TR>\n";
//       $out2 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>".($sommeg-$acomptemoin+$acompteplus)."</TH></TR></TABLE>\n";
       $out3 .= "<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TH>$sommeg2</TH></TR></TABLE>\n";
//       echo "$somme<BR>$acompteplus<BR>$acomptemoin<BR>";
       echo $outc;
       echo "<BIG>Acomptes</BIG><BR>".$outa;
//       echo $out1;
//echo "<TABLE border=5 align='left'><TR><TD>";
             if($Detail==1)
       echo "<BIG>Articles vente</BIG><BR>".$out2;
             if($Detail==1)
       echo "<BIG>TVA Marges</BIG><BR>".$out4;
//echo "</TD><TD>";
             if($Detail==1)
       echo "<BIG>Articles achat</BIG><BR>".$out3;
//echo "</TD></TR><TR><TD>";
       echo "<BIG>GM vente</BIG><BR>"."<TABLE border=1><TR><TH>GM</TH>\n";
       array_multisort($total,SORT_ASC,SORT_NUMERIC);
       foreach($total 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 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=array();
       foreach($total as $taux => $somme)
       {
          $total_cc["$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 as $taux => $somme)
        {
          if(array_key_exists("$no_cc",$total_cc["$taux"]))
          {
            $total_cc["$taux"]["$no_cc"]+=$total["$taux"][$cpt];
          }
          else
          {
            $total_cc["$taux"]["$no_cc"]=$total["$taux"][$cpt];
          }
         }
       }
       if(count($total_cc)!=0)
       {
         $lolo=array_keys($total_cc);
         $lolo2=$lolo[0];
         foreach($total_cc["$lolo2"] as $cc => $somme)
         {
         echo "<TR><TH>$cc</TH>";
         foreach($total_cc as $taux => $somme2)
         {
           echo "<TD>".$somme2[$cc]."</TD><TD>".Arrondi_2_Dec($somme2[$cc]*(1-(1/((100+$taux)/100))))."</TD>";
        }
        echo "</TR>";
         }
       }
//       foreach($total)
       echo "</TABLE>";
//       print_r(array_keys($total_cc));
//echo "</TD><TD>";
       echo "<BIG>GM achat</BIG><BR>"."<TABLE border=1><TR><TH>GM</TH>\n";
       array_multisort($total2,SORT_ASC,SORT_NUMERIC);
       foreach($total2 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($total2 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";
       $total2_cc=array();
       foreach($total2 as $taux => $somme)
       {
        $total2_cc["$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($total2 as $taux => $somme)
        {
          if(array_key_exists("$no_cc",$total2_cc["$taux"]))
          {
            $total2_cc["$taux"]["$no_cc"]+=$total2["$taux"][$cpt];
          }
          else
          {
            $total2_cc["$taux"]["$no_cc"]=$total2["$taux"][$cpt];
          }
         }
       }
       if(count($total2_cc)!=0)
       {
         $lolo=array_keys($total2_cc);
         $lolo2=$lolo[0];
         foreach($total2_cc["$lolo2"] as $cc => $somme)
         {
         echo "<TR><TH>$cc</TH>";
         foreach($total2_cc as $taux => $somme2)
         {
           echo "<TD>".$somme2[$cc]."</TD><TD>".Arrondi_2_Dec($somme2[$cc]*(1-(1/((100+$taux)/100))))."</TD>";
        }
        echo "</TR>";
         }
       }
//       foreach($total)
       echo "</TABLE>";
//echo "</TD></TR><TR><TD>";
       echo "<BIG>Tax vente</BIG><BR>"."<TABLE border=1><TR><TH>Taux</TH><TH>Total TTC</TH><TH>Tax</TH></TR>\n";
       array_multisort($tax,SORT_ASC,SORT_NUMERIC);
       foreach($tax as $taux => $somme)
       {
         echo "<TR><TD>$taux</TD><TD>$somme</TD><TD>".Arrondi_2_Dec($somme-($somme/(($taux+100.0)/100.0)))."</TD></TR>";
       }
       echo "</TABLE>";
       echo "<BIG>TVA Marge</BIG><BR>"."<TABLE border=1><TR><TH>Taux</TH><TH>Total TTC</TH><TH>Tax</TH></TR>\n";
       array_multisort($tax3,SORT_ASC,SORT_NUMERIC);
       foreach($tax3 as $taux => $somme)
       {
         echo "<TR><TD>$taux</TD><TD>$somme</TD><TD>".Arrondi_2_Dec($somme-($somme/(($taux+100.0)/100.0)))."</TD></TR>";
       }
       echo "</TABLE>";
       $somme=$acomptediff;
       echo "<BIG>TAX Acompte</BIG><BR>"."<TABLE border=1><TR><TH>Taux</TH><TH>Total TTC</TH><TH>Tax</TH></TR>\n";
       echo "<TR><TD>".get_config('TVA')."</TD><TD>$somme</TD><TD>".Arrondi_2_Dec($somme-($somme/((get_config('TVA')+100.0)/100.0)))."</TD></TR>";
       echo "</TABLE>";
//echo "</TD><TD>";
       echo "<BIG>Tax achat</BIG><BR>"."<TABLE border=1><TR><TH>Taux</TH><TH>Total TTC</TH><TH>Tax</TH></TR>\n";
       array_multisort($tax2,SORT_ASC,SORT_NUMERIC);
       foreach($tax2 as $taux => $somme)
       {
         echo "<TR><TD>$taux</TD><TD>$somme</TD><TD>".Arrondi_2_Dec($somme-($somme/(($taux+100.0)/100.0)))."</TD></TR>";
       }
       echo "</TABLE>";
       $titi=$acomptediff+$sommeg;
       $toto=$totsommevente - $titi;
       echo "Somme entrées = $totsommevente<BR>Diff acompte = $acomptediff<BR>Somme vente = $sommeg<BR>$totsommevente - $titi = ".round($toto,2)."<BR>";
       echo "$listeerr<BR>";
       $tata=round($totsommeachat+$sommeg2,2);
       echo "Somme sorties $totsommeachat<BR>Somme achats $sommeg2<BR>diff = $tata<BR>";
//echo "</TD></TR></TABLE>";
          break;
          case 2:
          break;
          }
  
?>
