<?php
require 'main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/tcpdf/tcpdf.php';

$pdf = new TCPDF('P', 'pt', 'A4', true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetFont('helvetica','',10);
$pdf->AddPage();



//$def = array();
$result = array();
//$sql = "SELECT ref, label,description, price, stock";
//$sql.= " FROM ".MAIN_DB_PREFIX."product";
//$resql=$db->query($sql);
$sql = 'SELECT';
$sql.= ' f.rowid as id, f.facnumber as ref, f.total as total,';
$sql.= ' f.datef as df, f.paye as etat,';
$sql.= ' s.rowid as socid, s.nom as name';
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
if(isset($_POST["date"]));
//$sql.= "WHERE  f.datef BETWEEN '".$_POST["date"]."' AND '".$_POST["date"]."'";
//$sql.= "GROUP BY s.nom";
$resql=$db->query($sql);
if($_POST["search"]){
if ($resql)
{
	$i = 0;
	$num_rows=$db->num_rows($resql);
	while ($i < $num_rows)
	{
		$result[] = $db->fetch_object($resql);
               
//                die(var_dump($result[$i]));
                
		$i++;
	}
}

ob_start();
?>
<style type="text/css">
<!--
table
{
    width:  100%;
    border:none;
    border-collapse: collapse;
}
th
{
    text-align: center;
    border: solid 1px #eee;
    background: #f8f8f8;
}
td
{
    text-align: center;
    border: solid 1px #eee;
}
-->
</style>
<table>
<col style="width: 33%">
    <col style="width: 33%">
    <col style="width: 33%">
<tr>
<th>Nom client</th>
<th>Reférence facture</th>
<th>Prix total</th>
<th>Date création</th>
<th>Etat de la facture</th>
</tr>
    <?php 
//    die(var_dump($result));
    foreach ($result as $key => $value)
    {
//        die(var_dump($value));
//            die(var_dump($result[$key]));
            ?>
        <tr>
            <td><?php print $value->name ?></td>
            <td><?php print $value->ref ?></td>
            <td><?php print price(price2num($value->total,'MT'),0,$langs,0,0,-1,$conf->currency) ?></td>
            <td><?php print  $value->df?></td>
            <td><?php
                if($value->etat ==0) 
                    print "pas de paiement";
                else print "payé comptent";
                ?>
            </td>
        </tr>
            <?php
    }
?>
</table>
<?php
$content = ob_get_clean();
$pdf->writeHTML($content, true, 0, true, 0);
$pdf->Output('test.pdf', 'D');
}
?>
<link rel="stylesheet" href="includes/jquery/css/base/jquery-ui.css">
<script src="includes/jquery/js/jquery.js"></script>
  <script src="includes/jquery/js/jquery-ui.js"></script>
<form action="" method="post">
    <input type="submit" name="search">
    <p>Date du: <input type="text" name="date" id="datepicker"></p>
    <p>Date au: <input type="text" name="date" id="datepicker"></p>
</form>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' }).val();
  } );
  </script>
 