<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Liste des factures</title>
	<script src="js/jquery-3.3.1.min.js"></script>
     <link rel="stylesheet" href="css/bootstrap.css" media="all" />
      <script src="js/bootstrap.min.js"></script>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  </head>
  <body >
    
    </header>
    <main>
     <div class="container">
    <br>
		
		
	
	
				

			
<?php
			
       // *********************    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);
								} 

			//print $_POST['client'];
								$sql1 = "SELECT * FROM data WHERE nom1 LIKE '%".$_POST['client']."%' ";
								//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'];
                                    $tempoindexcli=$row1['id'];
									//print "<br>".$tempnom1." id=".$tempoindexcli;
                                    
                                    
                                    
                                    
                                    // 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);
} 


										
									
$sql = "SELECT * FROM tete WHERE idxcli=".$tempoindexcli." ";
	// 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"];
        
       //  print "<br>Fac n° ".$row['num']." ".$tempnom1;      
        
        
 // *********************    connection clients *************************
		
								$servername1c = "localhost:8889";
								$username1c = "root";
								$password1c = "root";
								$dbname1c = "devis";

								// Create connection
								$conn1c = new mysqli($servername1c, $username1c, $password1c, $dbname1c);
								// Check connection
								if ($conn1c->connect_error) {
								die("Connection failed: " . $conn1c->connect_error);
								} 

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




$conn1c->close();						
		
							
        	       
        
        
        
        
        
        
        
        
           print "<div class='card'>";
            print " <div class='card-header text-white bg-secondary'>";
           
            print " <button class=' btn btn-secondary ' data-toggle='collapse' href='#collapse".$NUM."' role='button' aria-expanded='false' aria-controls='collapseExample' state='0' >";
             print " Facture n° ".$NUM." ".$tempsoc."  ".$tempnom1;
           // print "<i class='fa fa-angle-double-down' >&nbsp;</i><
            print"</button> ";
            
             print "<div style='float:right;'><form method='post' action='texteditconc.php' name='demande'>";
		    print "<button name='dnumdevis' class='btn btn-warning' type='submit' value='". $VRAIIDXDEVIS."'>Devis </button>";
			print "</form></div>";
		
		    print "<div style='float:right;'><form method='post' action='texteditfacres.php' name='demande'>";
            print "<button name='dnumdevis' class='btn btn-success' 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-info' value='". $IDX."'>Facture + Docs</button></td>";
			print "</form></div>";
         print"<div style='float:right;'><button class='swp btn btn-light ' state='0' >Montrer détail <i class='fa fa-angle-double-down'></i></button></div>";
        
            
            
            
            print"</div>";
        

           
 print"<div class='collapse' id='collapse".$NUM."' >";
  print"<div class='card card-body'>";

        Print $tempsoc."  ".$tempnom1." ".$row1['nom1']."Montant facture HTVA : ".$MONTANTHTVA." <p style='font-size:14px'>(Devis N° : ".$NUMEROSDEREFDEVIS." de ".$MONTANTDEREFDEVIS.")" ;
           // print "<form method='post' action='texteditfac.php' name='demande'>";
        
        
        
		    print "<br>". $OBJET. " </p><p style='font-size:12px'> ".$DATE."</p>";
        print "</div></div>";
        
		 print "<div class='card-footer text-muted'>";
 
		   
            print "</div></div>";
        
        
        
                                    
             }                        
                                    
            } else {
    //echo "0 results";
}                        
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
    
                                } 
                             	} else {
   // echo "0 results";
                                    
    //********************************* *recherche par numeros -********************************************                                
             
                                    $servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "facture";

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

                                    
//print "numsearch";
    $sql = "SELECT * FROM tete WHERE num LIKE '%".$_POST['client']."%' ";
	// print "<br>".$sql;	
		
$resultNum = $connNum->query($sql);

  
         
         
if ($resultNum->num_rows > 0) {
    // output data of each row
    while($row = $resultNum->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 *************************
		
								$servername1cn = "localhost:8889";
								$username1cn = "root";
								$password1cn = "root";
								$dbname1cn = "devis";

								// Create connection
								$conn1cn = new mysqli($servername1cn, $username1cn, $password1cn, $dbname1cn);
								// Check connection
								if ($conn1cn->connect_error) {
								die("Connection failed: " . $conn1cn->connect_error);
								} 

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




$conn1cn->close();	
        
        
                
         // *********************    connection clients pour nom *************************
		
								$servername1cn = "localhost:8889";
								$username1cn = "root";
								$password1cn = "root";
								$dbname1cn = "clients";

								// Create connection
								$conn1cn = new mysqli($servername1cn, $username1cn, $password1cn, $dbname1cn);
								// Check connection
								if ($conn1cn->connect_error) {
								die("Connection failed: " . $conn1cn->connect_error);
								} 

			
								$sql1cn = "SELECT * FROM data WHERE id=".$IDXCLI." ";
								//print "<br>".$sql1;	
		 
								$result1cn = $conn1cn->query($sql1cn);
		
								if ($result1cn->num_rows > 0) {
    							// output data of each row
								while($row1c = $result1cn->fetch_assoc()) {
								//print "echo <br>".$row1['societe']."  ".$row1['nom1'];
									$tempsoc=$row1c['societe'];
									$tempnom1=$row1c['nom1'];
								//print "ici".$NUMEROSDEREFDEVIS." ".$MONTANTDEREFDEVIS;
									    } 
    
	
									} else {
										// echo "0 results";
									}




$conn1cn->close();	
        
        
        
        
        
        
        
        
        
        
         //print "<br>Fac n° ".$row['num']." ".$tempnom1;     
        
            
           print "<div class='card'>";
            print " <div class='card-header text-white bg-secondary'>";
           
            print " <button class=' btn btn-secondary ' data-toggle='collapse' href='#collapse".$NUM."' role='button' aria-expanded='false' aria-controls='collapseExample' state='0' >";
             print " Facture n° ".$NUM." ".$tempsoc."  ".$tempnom1;
           // print "<i class='fa fa-angle-double-down' >&nbsp;</i><
            print"</button> ";
            
             print "<div style='float:right;'><form method='post' action='texteditconc.php' name='demande'>";
		    print "<button name='dnumdevis' class='btn btn-warning' type='submit' value='". $VRAIIDXDEVIS."'>Devis </button>";
			print "</form></div>";
		
		    print "<div style='float:right;'><form method='post' action='texteditfacres.php' name='demande'>";
            print "<button name='dnumdevis' class='btn btn-success' 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-info' value='". $IDX."'>Facture + Docs</button></td>";
			print "</form></div>";
         print"<div style='float:right;'><button class='swp btn btn-light ' state='0' >Montrer détail <i class='fa fa-angle-double-down'></i></button></div>";
        
            
            
            
            print"</div>";
        

           
 print"<div class='collapse' id='collapse".$NUM."' >";
  print"<div class='card card-body'>";

        Print $tempsoc."  ".$tempnom1." ".$row1['nom1']."Montant facture HTVA : ".$MONTANTHTVA." <p style='font-size:14px'>(Devis N° : ".$NUMEROSDEREFDEVIS." de ".$MONTANTDEREFDEVIS.")" ;
           // print "<form method='post' action='texteditfac.php' name='demande'>";
        
        
        
		    print "<br>". $OBJET. " </p><p style='font-size:12px'> ".$DATE."</p>";
        print "</div></div>";
        
		 print "<div class='card-footer text-muted'>";
 
		   
            print "</div></div>";
        
        
        
        
        
        
        
        
      }
       
  
                                    
$connNum->close();                                    
                                    
}
     } // ***************** fin recherh par numeroes  
                           
$conn1->close();
		
       

		?>	
		
       <script type="text/javascript"> 
          
     	$(".swp").on('click',function(){
	//alert("ok");
     
         
             $(".swp").each(function(i, v){
                 var newstate = $(this).attr('state') ^ 1,
           // icon = newstate ? "minus" : "plus",
            text = newstate ? "Cacher " : "Montrer ",
            texticon=newstate ? "<i class='fa fa-angle-double-up'>&nbsp;</i>":"<i class='fa fa-angle-double-down'>&nbsp;</i>";
               
                 if ( $(this).attr('state')==="0" ) {
       
                    $("div.collapse").each(function(i, v){$(this).collapse('show'); });  
          // $(this).find('div.collapse:not(.in)').collapse('show');
        }
        // otherwise, collapse all the divs
        else {
            
           // $(this).find('div.collapse.in').collapse('hide');
         
             $("div.collapse").each(function(i, v){$(this).collapse('hide'); });  
        }

        $(this).html( text +" détail "+texticon);

        $(this).attr('state',newstate)
                 
                });
                    
            });
           
          
  	$(".swp2").on('click',function(){
	//alert("ok");
     
         
            
                 var newstate = $(this).attr('state') ^ 1,
           // icon = newstate ? "minus" : "plus",
            text = newstate ? " btn btn-secondary collapsed" : " btn btn-secondary",
            text2= newstate ?  "false" : "true",
            texticon=newstate ? "<i class='fa fa-angle-double-up'></i>":"<i class='fa fa-angle-double-down'></i>";
               
         // $(this).html( $(this).text()+texticon);

        $(this).attr('state',newstate)
                 
                      
                 if ( $(this).attr('state')==="0" ) {
                //$(this).toggleClass('fa-angle-double-down fa-angle-double-up');
                 //  $("div.collapse").$(this).collapse('show'); 
                // $(this).find('div.collapse:not(.in)').collapse('show');
        }
        // otherwise, collapse all the divs
        else {
            
            //$(this).find('div.collapse.in').collapse('hide');
           // $(this).toggleClass('fa-angle-double-up fa-angle-double-down');
            // $("div.collapse").$(this).collapse('hide'); 
        }

        
    

      
             
                    
            });
         
             
         </script>
           
         
   
      </div>
    </main>
  
  </body>
</html>