<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Liste des factures</title>
	
     <link rel="stylesheet" href="css/bootstrap.css" media="all" />
       <script src="js/bootstrap.min.js"> </script>  
      
      <style>
      .glyph-icon svg {
width:16px;
height:16px;
}
      </style>     
  </head>
  <body >
    
    </header>
    <main>
     <div class="container">
    <br>
		
		
     <img src="svg/si-glyph-bed.svg" width="32px" height="32px" />
		

				
			
				

			
<?php
			
       


// on se connecte à notre base pour facture

$servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "facture";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

	 if(isset($_POST['update'])) {
		 $sql = "SELECT * FROM tete WHERE ";
		 
		 
	 		

		 	if($positionradio==0) {	
				$sqletat = " etat>0 ";
				 } else {
 				$sqletat = " etat='".$positionradio."' ";
				}

		 $sql=$sql.$sqletat;
		 
		 print $sql.'<br>';
	 } else {
										
									
$sql = "SELECT * FROM tete WHERE etat>='0'";
	// print "<br>".$sql;	
		 }

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
				
		$NUM=$row["num"];
$IDX=$row["idx"];
$DATE=$row["date"];
$OBJET=$row["objet"];
$IDXCLI=$row["idxcli"];
$MEMO=$row["memo"];
$NumeroIdxClient=$row["idxcli"];;
$CHANTIER=$row["chantier"];
$TVA=$row["tva"];
$BANQUE=$row["banque"];
$REMARQUE=$row["remarque"];
$ETATC=$row["etat"];
$MONTANTHTVA=$row["montant"];
$VRAIIDXDEVIS=$row["idxdevis"];
		
		// *********************    connection clients *************************
		
								$servername1 = "localhost:8889";
								$username1 = "root";
								$password1 = "root";
								$dbname1 = "Clients";

								// Create connection
								$conn1 = new mysqli($servername1, $username1, $password1, $dbname1);
								// Check connection
								if ($conn1->connect_error) {
								die("Connection failed: " . $conn1->connect_error);
								} 

			
								$sql1 = "SELECT * FROM data WHERE id=".$NumeroIdxClient." ";
								//print "<br>".$sql1;	
		 
								$result1 = $conn1->query($sql1);
		
								if ($result1->num_rows > 0) {
    							// output data of each row
								while($row1 = $result1->fetch_assoc()) {
								//print "echo <br>".$row1['societe']."  ".$row1['nom1'];
									$tempsoc=$row1['societe'];
									$tempnom1=$row1['nom1'];
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1->close();
									
					// *********************    connection clients *************************
		
								$servername1 = "localhost:8889";
								$username1 = "root";
								$password1 = "root";
								$dbname1 = "devis";

								// Create connection
								$conn1 = new mysqli($servername1, $username1, $password1, $dbname1);
								// Check connection
								if ($conn1->connect_error) {
								die("Connection failed: " . $conn1->connect_error);
								} 

			
								$sql1 = "SELECT num,montant FROM tete WHERE idx=".$VRAIIDXDEVIS." ";
								//print "<br>".$sql1;	
		 
								$result1 = $conn1->query($sql1);
		
								if ($result1->num_rows > 0) {
    							// output data of each row
								while($row1 = $result1->fetch_assoc()) {
								//print "echo <br>".$row1['societe']."  ".$row1['nom1'];
									$NUMEROSDEREFDEVIS=$row1['num'];
									$MONTANTDEREFDEVIS=$row1['montant'];
								
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1->close();						
		
		
            
		    print "<div class='card'>";
            print " <div class='card-header text-white bg-secondary'>Facture n° ".$NUM." ".$tempsoc."  ".$tempnom1." ".$row1['nom1']."<div style='display: inline-block;float:right;' class='text-white '> Montant facture HTVA : ".$MONTANTHTVA."</div></div>" ;
           // print "<form method='post' action='texteditfac.php' name='demande'>";
		   // print "<br></div>";
		 print "<div class='card-footer text-muted'>";
 
		    print "<div style='float:left;'><form method='post' action='textedit.php' name='demande'>";
		    print "<button name='dnumdevis' class='btn btn-primary' type='submit' value='". $VRAIIDXDEVIS."'>Devis </button>";
			print "</form></div>";
		
		    print "<div style='float:right;'><form method='post' action='texteditfac.php' name='demande'>";
            print "<button name='dnumdevis' class='btn btn-primary' type='submit' value='". $IDX."'>Facture</button>";
			print "</form> </div>";
           
          print "<div style='float:right;'><form method='post' action='texteditfacconcat.php' name='demande'>";
            print "<button name='dnumdevis'  type='submit' class='btn btn-primary' value='". $IDX."'>Facture + Docs</button></td>";
			print "</form></div>";
        print "<div style='float:right;'><form method='post' action='listefac.php' name='demande'>";
            print "<button name='dnumdevis'  type='submit' class='btn btn-primary' value='". $IDX."'>liste complete</button></td>";
			print "</form></div>";
        
            print "</div></div>";

    } 
    
	
	} else {
   // echo "0 results";
}




$conn->close();
		

		?>	
			
     
      
      </div>
    </main>
  
  </body>
</html>