<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title>Bordereau MCDF</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
</head>
<body bgcolor="#FFFFFF">
<img src="logo_bp.png" alt="" title="logo_bp" width="762" height="82" border="0" />
<br><br>


<?
echo('
<p align="center">
<table width="73%" border="1">
<tr>
   <td  align="center">
   Nom B&eacute;n&eacute;ficiaire
   </td>
   <td  align="center">
   N&deg; Compte
   </td>
   <td  align="center">
    Banque
   </td>
   <td " align="center">
   Centre Financier
   </td>
</tr>
<tr>
   <td  align="center">
   <b>M&eacute;hari Club De France<b>
   </td>
   <td  align="center">
   <b>0055174C020</b>
   </td>
   <td  align="center">
   <b>Banque Postal</b>
   </td>
   <td align="center">
   <b>PARIS</b>
   </td>
</tr>
<tr>
   <td  align="center" colspan="2">
    Signature
    <br><br><br><br><br><br><br>
   </td>
   <td  align="center" colspan="2">
   Date de remise
   <br><br><br><br><br><br><br>
   </td>
</tr>
</table>
</p>
<br><br>
');
//print_r($_FILES);echo('***<br>');
//$tempname=$_FILES['file']['tmp_name'];
//echo( $tempname);
move_uploaded_file($_FILES['file']['tmp_name'], "bordereau.csv");
  // Your code here
       $row = 1;$total=0;
       $somme=array();
       $nom=array();
       $banque=array();
       $ID=array();
       $bordereau="";
if (($handle = fopen("bordereau.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
        $num = count($data); // echo($num."-------.<br>");
        //echo "<p> $num champs &agrave; la ligne $row: <br /></p>\n";
        //$row++;
        /*for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        } */
        //echo ($data[9] ."<br>");

        if(($data[9]>0)&&($data[2]!="")&&(strpos($data[6],"Cheque")>0)){
        //detection bordereau
        if ($bordereau==""){$bordereau=$data[11];}
        //Nom
        if(is_produit($data)){
            $nom[$row]=get_nom_produit($data); //echo ($row.'--'.$nom[$row]."--");
            }
          else{
            $nom[$row]=get_nom_libre($data);
            }
      //Banque
      $banque[$row]=get_banque($data);  //echo($banque[$row]."--");

      //ID
      $ID[$row]=$data[2];
      //Somme
      $somme[$row]=number_format ($data[9],2,","," ")." &euro;";
      //echo($somme[$row]."<br>");
      $total=$total+$data[9];
      $row++;
            }
            }
    }
    fclose($handle);unlink("bordereau.csv");


/*print_r($somme);echo("<br>");
print_r($nom);;echo("<br>");
print_r($banque);;echo("<br>");
echo("<br>".number_format ($total,2,","," "));
echo('<button onclick="window.print()">Print this page</button>');
*/
//liste cheques
//echo('<table width="73%" border="1"><tr><td align="center">N&deg;</td><td align="center">&Eacute;METTEUR DU CHEQUE</td><td align="center">BANQUE DE L\'&Eacute;METTEUR</td><td align="center">MONTANT EN &euro;<td>ID</td></tr>');
echo('<table width="73%" border="1"><tr><td align="center">N&deg;</td><td align="center">BANQUE DE L\'&Eacute;METTEUR</td><td align="center">&Eacute;METTEUR DU CHEQUE</td><td align="center">MONTANT EN &euro;<td>ID</td></tr>');
for($kligne=1;$kligne<=25;$kligne++)
{
  echo('<tr><td>'.$kligne.'</td>');
  //echo('<td>'.$nom[$kligne].'</td>');
  // echo('<td><input type="text" name="nom" value="'.$nom[$kligne].'" size="50" /></td>');
  //<input type="text" name="nom" value="valeur" size="20" />

  //echo('<td>'.$banque[$kligne].'</td>');
   echo('<td><input type="text" name="nom" value="'.$banque[$kligne].'" size="50" /></td>');
   echo('<td><input type="text" name="nom" value="'.$nom[$kligne].'" size="50" /></td>');
  echo('<td>'.$somme[$kligne].'</td>');
  echo('<td>'.$ID[$kligne].'</td>');
  echo('</tr>');
}
echo("</table>");
echo("<br><br><br><br>");
$row=$row-1;if ($row>25){$row=25;}
echo('<table width="73%" border="1"><tr><td align="center"width="50%">NOMBRE DE CHEQUES<br>'.$row.'</td><td align="center" width="50%">MONTANT TOTAL DE LA REMISE<br>'.number_format ($total,2,","," ").' &euro;</td></tr>');
echo('<tr><td colspan="2" align="center">R&eacute;ference interne : '.$bordereau.'</td></tr>');
echo("</table>");
echo('<button onclick="window.print()">Impression</button>');




function is_produit($ligne)
{
if(strpos($ligne[3],"tisation")>1){return (true);}
//if(strpos($ligne[3],"Repas")>1){return (true);}
//if(strpos($ligne[3],"Acti")>1){return (true);}
return (false);
}
function get_nom_produit($ligne)
{
$id=$ligne[3];
//echo($id."<br>");
$id=str_replace($ligne[11],"",$id);
$id=substr($id,strpos($id,"-")+1);
//echo($id);
if(strpos($id,"-"))
{
$act=substr($id,strpos($id,"-")-1);
$id=str_replace($act,"",$id);
}
//echo($id);
return($id);
}
function get_banque($ligne)
{
$banque=$ligne[6];
$banque=str_replace("Cheque ","",$banque);
return($banque);
}
function get_nom_libre($ligne)
{
$id=$ligne[3];
$id=str_replace($ligne[12],"",$id);
if(strpos($id,"-")===false){return($id);}  //*****************************
else{
$id=str_replace($ligne[12],"",$id);
$id=substr($id,0,strpos($id,"-"));
return($id);
}
}
//str_replace ("Cheque","",$data[7])

/*$contents = file_get_contents('bdd/script.sql');
mysql_query($contents) or die(mysql_error());
*/
/*
DROP TABLE `activity`, `affectation`, `bill`, `card`, `channel`, `compte`, `exercice`, `fee`, `id_d`, `member`, `note`, `organisation`, `product`, `purchase`, `reference`, `view`, `wooLink`, `wooOrder`;
*/
?>
</body>

</html>