<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Facture</title>
  <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
  <link rel="stylesheet" href="stylei.css" media="all" />
	  
<script src="/js/jquery-2.1.0.min.js"></script>
	  <script src="/js/moment.js"></script>
	
<script src='../dist/autosize.js'></script>

	<script>
		autosize(document.querySelectorAll('textarea'));
		
	</script>
	  
	  	<script type="text/javascript">
			
				
			
    $(document).ready(function () {
    var $textareas = jQuery('textarea');

    // set init (default) state   
    $textareas.data('x', $textareas.outerWidth());
    $textareas.data('y', $textareas.outerHeight());

    $textareas.mouseup(function () {

        var $this = $(this);
		
		
		
        if ($this.outerWidth() != $this.data('x') || $this.outerHeight() != $this.data('y')) {
            //alert($this.outerWidth() + ' - ' + $this.data('x') + '\n' + $this.outerHeight() + ' - ' + $this.data('y'));
        }

	
		
		//alert(myDiv.clientHeight);
		//alert(test);
		//myDiv.clientHeight.value=myDiv.clientHeight.value+8;
		//alert(test);
	    
		var n = document.getElementsByClassName('yel0c');
    m = Number.NEGATIVE_INFINITY,
    i = 0,
    j = n.length;
	for (;i<j;i++) {
    m = Math.max(n[i].id,m);
	}

		 for (idx = 1; idx <= n.length; idx++) { 
			 var myDiv = document.getElementById('des'+idx).clientHeight; //get #myDiv
		test=myDiv.clientHeight+9;
	    test0=myDiv.clientHeight+0;
		document.getElementById('rTableCell0'+idx).setAttribute("style","height:"+test0+"px"); 
		document.getElementById('rTableCell2'+idx).setAttribute("style","height:"+test+"px"); 
		document.getElementById('rTableCell3'+idx).setAttribute("style","height:"+test+"px"); 
		document.getElementById('rTableCell4'+idx).setAttribute("style","height:"+test+"px"); 
		document.getElementById('rTableCell5'+idx).setAttribute("style","height:"+test+"px"); 
		}
		
			
		// set new height/width
       $this.data('x', $this.outerWidth());
       $this.data('y', $this.outerHeight());
		
       
    });
});


			
			
			
			
		
	function format(valeur,decimal) {
	separateur=" " ;
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

		
			
			function DateAuto()
{
var tempdate;
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();
	tempdate=document.getElementById("datetete").value;
	tempdate=tempdate.substring(17,tempdate.length);
	// set a variable
     var today = moment().format('DD/MM/YYYY');
	tempdate="Date: "+today+" "+tempdate;
	document.getElementById("datetete").value= tempdate;   
	
		}

			
		
			
			
					function hauteur()
{
	var myDiv = document.getElementById('rTableCell1'); //get #myDiv
	alert(myDiv.clientHeight);
	
	document.getElementById('rTableCell2').setAttribute("style","height:"+myDiv.clientHeight+"px"); 
	
		}

			
			
			
			
			
			
			
		function calcTotal()
{

	$(document).on('focus', 'textarea', function (e) {
	var element = $(this)[0];
	
	$(window).one('keyup', function (e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		if (code == 9 && document.activeElement == element ) {
			element.select();
		}
	});
});
	
	    
	
	var totVal=["Banana", "Orange", "Apple", "Mango"];
	
  	var idx=1;
	var res;
	var restva;
	var resfinal;
	var totfin ;
	var totaltva;
	var totalfinal;
	var tva;
	tva=document.getElementById("tva").value;
	var r = /[-+]?[0-9]*\.?[0-9]+/g
   
	
	totfin=0;
	
	var n = document.getElementsByClassName('yel0c');
    m = Number.NEGATIVE_INFINITY,
    i = 0,
    j = n.length;
	for (;i<j;i++) {
    m = Math.max(n[i].id,m);
	}
	//alert(n.length);
	
    for (idx = 1; idx <= n.length; idx++) { 
    //alert(totVal[1]);
    totVal[idx] = parseFloat(document.getElementById("qt"+idx).value.replace(',','.'))*parseFloat(document.getElementById("prix"+idx).value.replace(',', '.'));
   	totfin=totfin+totVal[idx];
	totVal[idx]=format((parseFloat(totVal[idx])),2);
    totVal[idx]=totVal[idx].toString();
	totVal[idx]=totVal[idx].replace('.',',');		
	document.getElementById("stot"+idx).value= totVal[idx]+"€";   
	
	
  	// var totVal2 = parseFloat(document.getElementById("qt2").value.replace(',', '.'))+parseFloat(document.getElementById("prix2").value.replace(',', '.'));
   	//totfin=totfin+totVal2;
	//totVal2=totVal2.toString();
	//totVal2=totVal2.replace('.',',');
	//document.getElementById("stot2").value= totVal2;   
	}
	tva=tva.replace(',','.');
	tva=(tva.match(r))[0];
	totaltva=totfin*(tva/100);
	totalfinal=totfin+totaltva;
	totfin=format((parseFloat([totfin])),2);
	res=totfin.toString();
	res=res.replace('.',',');
	document.getElementById("total").value= res+"€";  
	
    totaltva=format((parseFloat([totaltva])),2);
	restva=totaltva.toString();
	restva=restva.replace('.',',');
	document.getElementById("totaltva").value= restva+"€";  
	
	totalfinal=format((parseFloat([totalfinal])),2);
	resfinal=totalfinal.toString();
	resfinal=resfinal.replace('.',',');
	document.getElementById("totalfinal").value= resfinal+"€";  
    
	//catch(e)
    //{}
}
</script>	
	  
	  
	  
  </head>
 <body onload="calcTotal()" >
	 <header class="clearfix">
      <div id="logo">
        <img src="logo.png">
      </div>
      <div id="company">
        <h2 class="name">Ypsoroot - Ipsotoit</h2>
        <div>135 rue montavaux, 7080, Frameries </div>
        <div>065/793325. Entr.:BE0443870515</div>
        <div><a href="mailto:info@ypsoroof.com">info@ypsoroof.com</a></div>
      </div>
      </div>
    </header>
	
	<div class="rTable"> 
			<div class="rTableRow"> 
				<div class="rTableHead0"><strong></strong></div> 
				<div class="rTableHead1"><Textarea class='yelbj' onkeyup='calcTotal()' cols=40 rows=2 id='objectt' name='object'>Object : <?php echo $O1." ".$O2." ".$O3 ?></textarea><br><br><br><br> regh kjeh kjen <br> </div> 
				<div class="rTableHead2"><h3>QT</h3></div> 
				<div class="rTableHead3"><h3>PU</h3></div> 
				<div class="rTableHead4"><h3>UM</h3></div> 
				<div class="rTableHead5"><h3>TOTAL</h3></div> 
			</div> 
			
			
			<div class="rTable"> 
				<div class="rTableRow"> 
					<div class="rTableCell0"> </div>
					<div class="rTableCell1" id="rTableCell1">
			<Textarea class='yel1' onkeyup='calcTotal()' cols=40 rows=2 id='objectt' name='object'>Object : <?php echo $O1." ".$O2." ".$O3 ?></textarea> <br> </div> 
						
			
					<div class="rTableCell2" id="rTableCell2">
			<Textarea class='yel01' onkeyup='calcTotal()' onclick='this.focus();this.select()'  cols=40 rows=2 id='objectt' name='object'>Object : <?php echo $O1." ".$O2." ".$O3 ?></textarea> <br> </div> 																														  
																																	  
																																	
			</div>
																																	  
																																	  
		</div>
	<?php
	
$SOC=" ";
$NOM1=" ";
$NOM2=" ";
$NOM3=" ";
$NOM4=" ";
$NOM5=" ";
$TITRE=" ";
$PUB=" ";
$AC1=" ";
$AC2=" ";
$O1=" ";
$O2=" ";
$O3=" ";
$MAIL=" ";
$GSM=" ";
$TEL=" ";
$SIDXCLI=" ";

// on se connecte à notre base pour client

$servername = "localhost:8889";
$username = "test";
$password = "test";
$dbname = "Clients";

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

$SIDXCLI = htmlentities($_POST['idxcli']);
	// print "dans la boite<br>";

    
	

					 $sql = "SELECT * FROM data";
//$sql = "SELECT * FROM data WHERE id=3";
$sql = "SELECT * FROM data WHERE id=".intval($_POST['idxcli'])." ";
//print $sql;					 
					// $sql = "UPDATE\n". "  `data`\n"." SET\n". " societe = \'testoooyeahhh\'\n". "WHERE\n". " id = 3";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
		
$SOC=$row["societe"];
$NOM1=$row["nom1"];
$NOM2=$row["nom2"];
$NOM3=$row["nom3"];
$NOM4=$row["nom4"];
$NOM5=$row["nom5"];
$TITRE=$row["titre"];
$PUB=$row["pub"];
$AC1=$row["ac1"];
$AC2=$row["ac2"];
$O1=$row["o1"];
$O2=$row["o2"];
$O3=$row["o3"];
$MAIL=$row["mail"];
$GSM=$row["gsm"];
$TEL=$row["tel"];
$SIDXCLI =$row["id"];
        //echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. " - idx: " . $row["id"]. " " . $row["nom2"]. "<br>";
		//echo "Soc: " . $row["societe"]. " - Nom: " . $row["nom1"]. "  " . $row["nom2"]. "<br>";
    } 
    
	
	} else {
    echo "0 results";
}

//$sql = "INSERT INTO data (societe,nom1,nom2,nom3,nom4,nom5,titre,ac1,ac2,o1,o2,o3,mail,tel,gsm,pub,jour)
//VALUES ('$SOC' , '$NOM1', '$NOM2', '$NOM3', '$NOM4', '$NOM5', '$TITRE', '$AC1', '$AC2', '$O1', '$O2', '$O3', '$MAIL', '$TEL', '$GSM', '$PUB', //'$today')";


$conn->close();
					 
	?>			
	
	
	
	
	
    <main>
      <div id="details" class="clearfix" style='border: 0px solid black;'>
        
		  <div id="client">
			
        <!--   <div class="to">CLIENT:</div> -->
          <h2 class="name"><?php echo $SOC ?></h2>
			<div class="address"><?php echo $TITRE.$NOM1 ?></div>
          <div class="address"><?php echo $NOM2 ?></div>
			<div class="address"><?php echo $NOM3 ?></div>
			<div class="address"><?php echo $NOM4?></div>
			<div class="address"><?php echo $NOM5?></div>
			
         <!-- <div class="email"><a href="mailto:john@example.com">john@example.com</a></div> -->
			
        </div>
		  
        <div id="invoice">
          <h1>FACTURE N°1</h1>
          <div class="date"><textarea ondblclick="DateAuto()" class='tete' rows=3 cols=40 id='datetete'>Date: 01/06/2018 
Vos ref:
V.TVA:</textarea> </div>
		 
        </div> 
		 
      </div>
		
	<!------------------------------------------->
		



		
		
		
		
		
		
		
		
		<div class="rTable"> 
			<div class="rTableRow"> 
				<div class="rTableHead0"><strong></strong></div> 
				<div class="rTableHead1"><Textarea class='yelbj' onkeyup='calcTotal()' cols=40 rows=2 id='objectt' name='object'>Object : <?php echo $O1." ".$O2." ".$O3 ?></textarea></div> 
				<div class="rTableHead2"><h3>QT</h3></div> 
				<div class="rTableHead3"><h3>PU</h3></div> 
				<div class="rTableHead4"><h3>UM</h3></div> 
				<div class="rTableHead5"><h3>TOTAL</h3></div> 
			</div> 
			
	<!--	</div> -->
		
		
	
      
			
         <?php 
			
		
		
			
			
			
			
				// on se connecte à notre base pour ligne devis

$servername = "localhost:8889";
$username = "test";
$password = "test";
$dbname = "Clients";

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

$sql = "SELECT * FROM data";
$sql = "SELECT * FROM Modele WHERE type=1";
					// $sql = "UPDATE\n". "  `data`\n"." SET\n". " societe = \'testoooyeahhh\'\n". "WHERE\n". " id = 3";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
	$ii=0;
    while($row = $result->fetch_assoc()) {
		
$DES=$row["description"];
$PRIX=$row["prix"];
$UNITE=$row["unite"];
$SYMTOT=$PRIX*2;
$ii++;
		
		
			print "<div class='rTableRow'>"; 
			//print "	<div class='rTableCell0' id='rTableCell0' >$ii</div>";
		    print "	<div class='rTableCell0' id=".chr(34)."rTableCell0".$ii.chr(34)." ></div>";
		
			print "	<div class='rTableCell1' id=".chr(34)."rTableCell1".$ii.chr(34)." ><textarea class='yel0c' 'onkeyup='calcTotal()' cols=57 rows=1 id=".chr(34)."des".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >".$DES."</textarea></div>";  
		
			print "	<div class='rTableCell2' id=".chr(34)."rTableCell2".$ii.chr(34)." ><textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' onkeyup='this.select()'cols=4 rows=1 id=".chr(34)."qt".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >0</textarea></div> ";
		
			print "	<div class='rTableCell3' id=".chr(34)."rTableCell3".$ii.chr(34)." ><textarea class='g1'  onkeyup='calcTotal()' onclick='this.focus();this.select()'cols=5 rows=1 id=".chr(34)."prix".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >".$PRIX."</textarea></div> ";
		
			print "	<div class='rTableCell4' id=".chr(34)."rTableCell4".$ii.chr(34)." ><textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' cols=2 rows=1 id=".chr(34)."um".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >".$UNITE."</textarea></div> ";
		
			print "	<div class='rTableCell5' id=".chr(34)."rTableCell5".$ii.chr(34)." ><textarea disabled class='yel1'  onkeyup='calcTotal()' cols=7 rows=1  id=".chr(34)."stot".$ii.chr(34)." name=".chr(34)."stot".$ii.chr(34)." >0</textarea></div> ";
			print "</div> ";
		
	   		//print"<tr>";
            //print"<th class='no'>$ii</th>";
            //print"<th class='desc'><textarea class='yel0c'  onkeyup='calcTotal()' cols=65 rows=1 id=".chr(34)."des".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >".$DES."</textarea></th>";
		
			//print"<th class='qty'><textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' onkeyup='this.select()'cols=6 rows=1 id=".chr(34)."qt".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >0</textarea></th>";
		
            //print"<th class='unit'><textarea class='g1'  onkeyup='calcTotal()' onclick='this.focus();this.select()'cols=6 rows=1 id=".chr(34)."prix".$ii.chr(34)." name=".chr(34)."qt".$ii.chr(34)." >".$PRIX."</textarea></th>";
		
            //print"<th class='um'><textarea class='yel' onkeyup='calcTotal()' onclick='this.focus();this.select()' cols=2 rows=1 id=".chr(34)."um".$ii.chr(34)." name=".chr(34)."prix".$ii.chr(34)." >".$UNITE."</textarea></th>";
		
            //print"<th class='total'><textarea disabled class='yel1'  onkeyup='calcTotal()' cols=7 rows=1  id=".chr(34)."stot".$ii.chr(34)." name=".chr(34)."stot".$ii.chr(34)." >0</textarea>";
	
          //print"</tr>";
	
	
	
	
    } 
    
	
	} else {
    echo "0 results";
}

//$sql = "INSERT INTO data (societe,nom1,nom2,nom3,nom4,nom5,titre,ac1,ac2,o1,o2,o3,mail,tel,gsm,pub,jour)
//VALUES ('$SOC' , '$NOM1', '$NOM2', '$NOM3', '$NOM4', '$NOM5', '$TITRE', '$AC1', '$AC2', '$O1', '$O2', '$O3', '$MAIL', '$TEL', '$GSM', '$PUB', //'$today')";


$conn->close();
	
	
		?>
			  
			  
			  
			  
		
			
				
				
			<div class='rTableCell0'></div>
			<div class='rTableCell1c'><textarea class='chantier' cols=79 rows=1 id='chantier' >Chantier :   </textarea></div>  
			<div class='rTableCell2c'>TOTAL</div>
			<div class='rTableCell3c'><textarea class='yel1' cols=9 rows=1 name='total' id='total'>0</textarea></div>
			<!--<div class='rTableCell3'><textarea onkeyup='calcTotal()' class='yel1' id='tva' cols=80 rows=1 >TVA 6% </textarea></div> 
			<div class='rTableCell4'>TVA</textarea></div>
			<div class='rTableCell5'><textarea class='yel1' cols=9 rows=1 name='totaltva' id='totaltva'>0</textarea></div> -->
			</div>
			
			
			
			<div class='rTableRow'> 
			<div class='rTableCell0'></div>
			<div class='rTableCell1c'><textarea onkeyup='calcTotal()' class='yel1' id='tva' cols=79 rows=1 >TVA 6% </textarea></div> 
			<div class='rTableCell2c'>TVA</textarea></div>  
			<div class='rTableCell3c'><textarea class='yel1' cols=9 rows=1 name='totaltva' id='totaltva'>0</textarea></div>
			<!--<div class='rTableCell3'><textarea onkeyup='calcTotal()' class='yel1' id='tva' cols=80 rows=1 >TVA 6% </textarea></div> 
			<div class='rTableCell4'>TVA</textarea></div>
			<div class='rTableCell5'><textarea class='yel1' cols=9 rows=1 name='totaltva' id='totaltva'>0</textarea></div> -->
			</div>
			
			
			
			  
			<div class='rTableRow'> 
			<div class='rTableCell0'></div>
			<div class='rTableCell1c'><textarea class='chantier' cols=79 rows=1 id='banque' >Paiement au grand comptant. Banque CPH IBAN:BBE75 Compte: BE92 1262 1506 3723</textarea></div>  
			<div class='rTableCell2c'>TOTAL TVAC</div>
			<div class='rTableCell3c'><textarea class='yel1' cols=9 rows=1 name='totalfinal' id='totalfinal'>0</textarea></div> 
			
			</div>
		
		
			</div>  
			
			
			


		
			
		
        
       <!-- </tbody>
        <tfoot> -->
      
         
     
	
		
	
      <!-- <div id="thanks">Thank you!</div> -->
   <!--     <div id="notices">
        <div>NOTICE:</div>
        <div class="notice">A finance charge of 1.5% will be made on unpaid balances after 30 days.</div>
      </div> -->
    </main>
     <footer>
      Conditions générales de vente au verso ou sur http://www.ypsoroof.com
    </footer> 
  </body>
</html>