<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Liste des Notes de crédit </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
			
       


// on se connecte à notre base pour facture

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

// 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'>";
           
            print " <button class='swp2 fa fa-angle-double-down btn btn-secondary ' data-toggle='collapse' href='#collapse".$NUM."' role='button' aria-expanded='false' aria-controls='collapseExample' state='0' >";
             print " Note de crédit n° ".$NUM." ".$tempsoc."  ".$tempnom1." ".$row1['nom1'];
           // print "<i class='fa fa-angle-double-down' >&nbsp;</i><
            print"</button> ";
            
         //    print "<div style='float:right;'><form method='post' action='textedit.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='texteditnc.php' name='demande'>";
            print "<button name='dnumdevis' class='btn btn-success' type='submit' value='". $IDX."'>Note de crédit</button>";
			print "</form> </div>";
           
        
        // print "<div style='float:right;'><form method='post' action='texteditfacconcatcompta.php' name='demande'>";
          //  print "<button name='dnumdevis'  type='submit' class='btn btn-info' value='". $IDX."'>Facture compta </button></td>";
//			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 + doc</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";
}




$conn->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 ? "swp2 btn btn-secondary collapsed" : "swp2 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>