<!doctype html>
<html><head>
<meta charset="UTF-8">
<title>DEVIS</title>

	
<link rel="stylesheet" href="textedit.css" media="all" />
	<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
	<script src="js/jquery-2.1.0.min.js"></script>
	<script type="text/javascript" src="js/jquery.tablednd.js"></script>
	<script src="js/jquery-ui.js"></script>
	<script src="js/jquery.ui.touch-punch.js"></script>

	
	<script src="/js/moment.js"></script>
	<script src="/js/jquery.redirect.js"></script>
	
	</head>
<body onLoad="calculload()">


	<div class="gencont">
	
		<div id="logo" onclick="myFunction() "><img src= "logofac1.png" width="794"></div>	
		<div id="logo2" ><img src= "logofac3.png" width="487" height: "146"></div>
		<div id="logo3" ><img src= "logofac2.png" width="307" height: "26"></div>
	
	  <div id="company">
		<h2 class="name">Ypsoroof - Ipsotoit</h2>
        <h2 class="name2">135 rue montavaux, 7080, Frameries </h2>
        <h2 class="name2">065/793325. Entr.:BE0443870515</h2>
		  <h2 class="name2">Banque CPH IBAN:BBE75</h2>
		   <h2 class="name2">Compte: BE92 1262 1506 3723</h2>
      <!--  <div><a href="mailto:info@ypsoroof.com">info@ypsoroof.com</a></div> -->
      </div>
		 	
	
	
		<?php

		$NumeroIndexDevisP=$_POST['dnumdevis'];
		$NumeroIdxClient=$_POST['didxcli'];
	//	print "<br>".$NumeroIndexDevisP;	
	//	print "<br>".$NumeroIdxClient;	

// on se connecte à notre base pour devis

$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";
$sql = "SELECT * FROM tete WHERE idx=".$NumeroIndexDevisP." ";
//$sql = "SELECT * FROM tete WHERE idx=".intval($_POST['idxcli'])." ";
//print "<br>".$sql;	
			// print "<br>".$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()) {
		
$NUM=$row["num"];
$IDX=$row["idx"];
$DATE=$row["date"];
$OBJETT=$row["objet"];
$IDXCLI=$row["idxcli"];
$MEMO=$row["memo"];
$ETATC=$row["etat"];		
		$NumeroIdxClient=$row["idxcli"];;
$CHANTIER=$row["chantier"];
$TVA=$row["tva"];
$BANQUE=$row["banque"];
$REMARQUE=$row["remarque"];

    } 
    
	
	} 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();
		
		?>
	
		
<?php		
		
				
		// on se connecte aux client ******************************************
		
$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=".$NumeroIdxClient." ";
//$sql = "SELECT * FROM data WHERE id=".intval($_POST['idxcli'])." ";
//print "<br>".$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["fac1"];
$NOM2=$row["fac2"];
$NOM3=$row["fac3"];
$NOM4=$row["fac4"];
$NOM5=$row["fac5"];
$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();
					 
		
		
		
	?>			
	
	 
        
		  <div id="client">
			
        <!--   <div class="to">CLIENT:</div> 
            <h2 class="name"><php echo $NOM1 ?></h2>-->
             <div class="address"><?php echo $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>
		
		
				  
						 
	<div style="clear:both"></div>
        
			 
			  <div id="invoice"><br>
         Facture N°<?php echo $NUM ?>
				 
          <div id="datestyle" class="date" style="border-bottom: 1px solid black; border-left: 4px  solid #EFD61E; max-width:300px" contenteditable="true" ><?php echo $DATE ?> </div>
		 
		</div>  
	<div style="clear:both"></div>
			
	<table  cellspacing="0" cellpadding="-1" width="794px" border="0" valign="top" style="border-collapse: collapse;">
		<tbody >
			<tr >  
			<td width='17px' valign='top' align='left' bgcolor='#EFD61E' style="border-bottom: 1px solid black"> <div class='colh'  contenteditable='false' style='background:#EFD61E; max-width: 17px;  '></div> </td>
			<td  width='515px' valign='top' align='left' bgcolor='#EEEEEE' style="border-bottom: 1px solid black"> <div class='colh'  id='oobjet' contenteditable='true' style='background:#EEEEEE; max-width: 515px;  '><?php echo $OBJETT?></div> </td>
			<td width='60px' valign='bottom' align='center' bgcolor='#DDDDDD'style="border-bottom: 1px solid black" > <div class='colh'  contenteditable='true' style='background:#DDDDDD; max-width: 60px;  '>QT</div> </td>
				<td width='65px' valign='bottom' align='center' bgcolor='#EEEEEE'style="border-bottom: 1px solid black" ><div class='colh'  contenteditable='true' style='background:#EEEEEE; max-width: 65px;  '>PU</div> </td>
		
		<td width='40px' valign='bottom' align='center' bgcolor='#DDDDDD' style="border-bottom: 1px solid black;"> <div class='colh'  contenteditable='true' style='background:#DDDDDD; max-width: 40px; '>UM</div> </td> 
		
			<td width='95px' valign='bottom' align='center' bgcolor='#EFD61E' style="border-bottom: 1px solid black"> <div class='colh'    contenteditable='false' style='background:#EFD61E; max-width: 95px;  '>TOT</div> </td>
		</tr>
		</tbody>
		</table>	
		
	<div style="clear:both"></div>

	
	
	
	
	
	
		<table id="table-2"  cellspacing="0" cellpadding="-1" width="794px" border="0" valign="top" style="border-collapse: collapse;" >
		
		 <tbody id="items_table">
			 
		
			 
	<?php
		
				                            // on se connecte à notre base pour ligne devis

$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 corps WHERE numidxdevis= '".$NumeroIndexDevisP."' ORDER BY ordre ";
//$sql = "SELECT * FROM Modele WHERE type=".intval($_POST['idxm'])." ";
					// $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["des"];
$QT=$row["qt"];
$UNITE=trim($row["um"]);
$PRIX=$row["pu"];
		
$ii++;
		
		print"<tr class='yes' id='".$ii."'  >";  
		print"<td width='17px' valign='top' align='left' bgcolor='#EFD61E' > <div class='col' id='ligne1' contenteditable='false' style='background:#EFD61E; max-width: 17px;  '>".$ii."</div> </td>";
		
		print"<td  width='515px' valign='top' align='left' bgcolor='#EEEEEE'> <div class='col'  id='descriptionligne' contenteditable='true' style='background:#EEEEEE; max-width: 515px;  '>".$DES."</div> </td>"; 
		
		print"<td width='60px' valign='top' align='right' bgcolor='#DDDDDD' > <div class='col' id='qtcalc' contenteditable='true' style='background:#DDDDDD; max-width: 60px;  '>".$QT."</div> </td> ";
			
		print"<td width='65px' valign='top' align='right' bgcolor='#EEEEEE' ><div class='col' id='prixcalc' style='font-size: 1.5em;' contenteditable='true' style='background:#EEEEEE; max-width: 65px;  '>".$PRIX."</div> </td> ";
		
		print"<td width='40px' valign='top' align='center' bgcolor='#DDDDDD'  > <div class='col' id='umcalc' contenteditable='true' style='background:#DDDDDD; max-width: 40px; '>".$UNITE."</div> </td>"; 
		
			print"<td width='95px' valign='top' align='right' bgcolor='#EFD61E'> <div class='col' id='soustotal'   contenteditable='false' style='background:#EFD61E; max-width: 95px;  '>€</div> </td>"; 
		
		print "</tr>";
	   	
		
    } 
    
	
	} else {
  //  echo "0 results";
}



$conn->close();
	
	
		?>
	
	
	
	
	
	
	
		
			
			</tbody>
	
		</table>	
	
	
	<table  cellspacing="0" cellpadding="-1" width="794px" border="0" valign="top" style="border-collapse: collapse;">
  <tbody>
    <tr class="elastic">
		<td width="17px" bgcolor="#EFD61E" >&nbsp; </td> 
		<td width="515px" bgcolor="#EEEEEE">&nbsp; </td> 
		<td width="60px"  bgcolor="#DDDDDD" >&nbsp; </td> 
		<td width="65px"  bgcolor="#EEEEEE" >&nbsp; </td> 
		<td width="40px"  bgcolor="#DDDDDD" >&nbsp; </td> 
		<td width="95px"  bgcolor="#EFD61E">&nbsp; </td> 
     
    </tr>
  </tbody>
</table>
	
	
	
	
	
	
	<table  cellspacing="0" cellpadding="0" width="794px" border="0" valign="top">
		
		<tbody>
				<tr>  
			
			<td rowspan="2" style="border-top: 1px solid black;" width="460px" height="60px" valign="top"align="left" bgcolor="#EFD61E"> <div class="colt" id="cchantier" contenteditable="true" style="background:#EFD61E; max-width: 520px;  "><?php echo $CHANTIER ?></div> </td> 
			<td style="border-top: 1px solid black; border-bottom:  1px solid black;" colspan="4" width="100px" height="28px" valign="top" align="right" bgcolor="#EFD61E" ><div class="colt" id="totalhtval" contenteditable="false" style="background:#EFD61E; max-width: 100px;">TOTAL HTVA</div> </td> 
			<td width="95px" valign="top" align="right" bgcolor="#EFD61E"> <div class="colt" id="totalhtva" contenteditable="false" style="background:#EFD61E; max-width: 95px;  ">100.985,25€</div> </td> 
			
		</tr>
		
				<tr> 
			
		 <td style="border-bottom: 1px solid black;" colspan="4" width="460px" height="28px" valign="top"align="right" bgcolor="#EFD61E"> <div class="colt" id="tauxtva" contenteditable="true" style="background:#EFD61E; max-width: 520px;  "><?php echo $TVA ?></div> </td> 
			
			<td width="95px" valign="top" align="right" bgcolor="#EFD61E"> <div class="colt" id="totaltva" contenteditable="false" style="background:#EFD61E; max-width: 95px;  ">100.985,25€</div> </td> 
		</tr>
				<tr>  
			
			<td style="border-bottom:  1px solid black;"  colspan="4"  width="520px" height="28px" valign="top"align="left" bgcolor="#EFD61E"> <div class="colt" id="banque" contenteditable="true" style="background:#EFD61E; max-width: 580px; font-size: 0.8em;'  "><?php echo $BANQUE ?></div> </td> 
					
		
					<td style="border-bottom: 1px solid black;"   width="100px" valign="top" align="right" bgcolor="#EFD61E" ><div class="colt" contenteditable="false" style="background:#EFD61E; max-width: 100px;  ">TOTAL TVAC</div> </td> 
			<td style="border-bottom:  1px solid black;" width="95px" valign="top" align="right" bgcolor="#EFD61E"> <div class="colt" id="totaltvac" contenteditable="false" style="background:#EFD61E; max-width: 95px;  ">100.985,25€</div> </td> 
			 
		</tr>
			
			
		
			
		</tbody>
	
		</table>	
	

	<script type="text/javascript">
    function inline_sprintlist_ondrop(table, row) {
        var result = $(table).parent().find('.result'),
            pre = $('<pre class="prettyprint">');

        result.html(pre.text($.tableDnD.jsonize(true)));
        prettyPrint();
//            pre.text($(table).tableDnD.jsonize())
//        return true;
        //// '<div class="indent">&nbsp;</div>',
    }
</script>


<!--<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>-->
<script type="text/javascript" src="js/jquery.tablednd.js"></script>
	<script type="text/javascript">
	
    $(document).ready(function() {
        // Initialise the first table (as before)
        $("#table-1").tableDnD();
        // Make a nice striped effect on the table
        table_2 = $("#table-2");
        //table_2.find("tr:even").addClass("alt");
        // Initialise the second table specifying a dragClass and an onDrop function that will display an alert
        table_2.tableDnD({
            onDragClass: "myDragClass",
            onDrop: function(table, row) {
                var rows = table.tBodies[0].rows;
                var debugStr = "Row dropped was "+row.id+". New order: ";
                for (var i=0; i<rows.length; i++) {
                    debugStr += rows[i].id+" ";
					
                }
                $(table).parent().find('.result').text(debugStr);
				
				//alert("ok");
				calcul();
				
				
				
				
            },
            onDragStart: function(table, row) {
                $(table).parent().find('.result').text("Started dragging row "+row.id);
            }
        });

        $('#table-3').tableDnD({
            onDragStart: function(table, row) {
                $(table).parent().find('.result').text('');
            },
            onDrop: function(table, row) {
                $('#AjaxResult').load("server/ajaxTest.php?"+$.tableDnD.serialize())
                        .parent().find('.result').html($('<p>').append('Result of $.tableDnD.serialize() is url encoded: ')
                        .append($('<pre class="prettyprint">').text($.tableDnD.serialize()))
                        .append(' Which looks like this when decoded (decodeURI): ')
                        .append($('<pre class="prettyprint">').text(decodeURI($.tableDnD.serialize()))));
                prettyPrint();
            }
        });

        $('#table-4').tableDnD(); // no options currently

        $('#table-5').tableDnD({
            onDragStart: function(table, row) {
                $(table).parent().find('.result').text('');
            },
            onDrop: function(table, row) {
                var data = $(table).tableDnDSerialize();
                $(table).parent().find('.result').append(
                        $('<strong>').text('The urlencoded serialized string:'))
                        .append($('<pre class="prettyprint">').text(data))
                        .append($('<strong>').text('Which looks like this through decodeURIComponent:'))
                        .append($('<pre class="prettyprint">').text(decodeURIComponent(data)));
                prettyPrint();
            },
            dragHandle: ".dragHandle"
        });

        $("#table-5 ").find("tr").hover(function() {
            $(this.cells[0]).addClass('showDragHandle');
        }, function() {
            $(this.cells[0]).removeClass('showDragHandle');
        });

        $('#table-7').tableDnD({
            hierarchyLevel: 4,
            onDragStart: function(table, row) {
                $(table).parent().find('.result').text('');
            },
            onDrop: function(table, row) {
                $(table).parent().find('.result').append(
                        $('<strong>').text('JSON.stringify result of $.tableDnD.tableData()'))
                        .append($('<pre class="prettyprint">').text($.tableDnD.jsonize(true)));
                prettyPrint();
                $.post("server/ajaxJSONTest.php", $.tableDnD.jsonize(), function (data) {
                    $('#table-7-response').html('<br>'+ data);
                });
            }
        });

        $('.toggle-json6').toggle(function() {
          $(this).text('Show JSON');
          $('json6').hide();
          return false;
        },
        function() {
          $(this).text('Hide JSON');
          $('json6').show();
          return false;
        });
        $('.toggle-json7').toggle(function() {
                $(this).text('Show JSON');
                $('json7').hide();
                return false;
              },
              function() {
                $(this).text('Hide JSON');
                $('json7').show();
                return false;
              });

        $('#radio-button-test').tableDnD();

    });
</script>
	

		
	
	<br>
	<p></p>
  
		
</div>

		
		
		
		

	
	
	
	
	
	
	
	
	
	
	
	
<div id="mydiv">
  <div id="mydivheader">Outils</div>
  <p>Memo</p>
  
	<div class='memo' contenteditable="true"><?php echo $MEMO ?> </div>
	<br>
<!-- 	<input type="checkbox" name="etat" value="4" ?php if ($ETATC==4) { print" checked "; }?> ></input> Brouillon<br> -->
	<input type="checkbox" name="efface">Efface la ligne au click<br>
	
	 
	
	
	 <button class="bld" id="btsts">B</button>
<button class="itl" id="btsts">I</button>
<button class="UpZ" id="btsts">+</button>	
<button class="SmZ" id="btsts">-</button>	
<button class="udr" id="btsts">S</button><br>
<button class="pst" id="btst">Enregistrer</button>
<button class="swp" id="btst">Ajouter</button><br>
	<button class="cond" id="btst">Conditions generales</button>
<br>	<button class="lettre" id="btst">Lettre</button>
    <button class="rap" id="btst">Rappel</button>
	
	
	<p>---</p>
		<form action="index.html">
               <input class="form-control" id="btst" type="submit" value="HOME" />
	            </form>
	
</div>

	
	
	
	
	
	</div>
	
	
	<script>
			
 $( function() {
   
	 $("#mydiv" ).draggable().css("position", "fixed");
	 
	 $("#mydiv").draggable()
  .click(function() {
    $(this).draggable({ disabled: false });
}).dblclick(function() {
    $(this).draggable({ disabled: true });
});
	 
	 
  } );
	</script>	

  
	
<script type="text/javascript">   
	

	
	function formatnombre(valeur,decimal) {
	valeur=valeur.replace(',','.');	
	valeur=valeur.replace(' ','');		
	valeurnb=parseFloat(valeur);
        
              	
                 if (isNaN(valeurnb)) {
                   valeur='   ';      
                  // alert("nan");
                       return valeur;  
                    } 
                
        
        
        
	valeurnb=format((parseFloat(valeurnb)),decimal);
    valeur=valeurnb.toString();
	valeur=valeur.replace('.',',');		
	if (parseFloat(valeurnb)<0) {valeur=""+valeur;}
     if (parseFloat(valeurnb)==0) {valeur="0";}
		//alert(valeur);
	return valeur;
}
			
	
		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;
}
			
  $("div.col#prixcalc").blur(function() {	
	  //	alert("ok"+$(this).html());
	 // $( "p:last" ).text( "Contient: " +$(this).html()) ;
 $(this).html(formatnombre($(this).html(),2));
 });
	
	 
	
	$(".UpZ").on('click',function(){
	document.execCommand('fontSize', false,  '3')
  var a = $("#textarea").html();

});
			$(".SmZ").on('click',function(){
	document.execCommand('fontSize', false,  '2')
  var a = $("#textarea").html();

});
$(".bld").on('click',function(){
	document.execCommand('bold');
	
  var a = $("#textarea").html();

});

$(".itl").on('click',function(){
	document.execCommand('italic');
  var a = $("#textarea").html();
	
});
	$(".udr").on('click',function(){
	document.execCommand('underline');
  var a = $("#textarea").html();
	
});
	
	$(".cond").on('click',function(){
		$.redirect('textegenconfac.php', {'dnumdevis':<?php echo $NumeroIndexDevisP ?>,'didxcli':<?php echo $NumeroIdxClient ?>});
	
	});
	
		$(".lettre").on('click',function(){
		$.redirect('textelettrefac.php', {'dnumdevis':<?php echo $NumeroIndexDevisP ?>,'didxcli':<?php echo $NumeroIdxClient ?>});
	
	});
	
    		$(".rap").on('click',function(){
		$.redirect('textelettrerappel.php', {'dnumdevis':<?php echo $NumeroIndexDevisP ?>,'didxcli':<?php echo $NumeroIdxClient ?>});
	
	});
	
	$(".pst").on('click',function(){
		var des = Array();
		var desln = Array();
		var qtdes = Array();
		var pudes = Array();
		var umdes = Array();
		var ordredes = Array();
		
		var maxbcl=0;

		$("div.col").each(function(i, v){
        des[i] = $(this).html();
			ordredes[i]=i;
		
			});
		maxbcl=des.length;
//alert(maxbcl);
		
		i=-6;
		var cptattrib=-1;
		for (var i=0;i < maxbcl;i+= 6) {
			cptattrib++;
			ordredes[cptattrib]=des[i];
			desln[cptattrib]=des[i+1];
			qtdes[cptattrib]=des[i+2];
			pudes[cptattrib]=des[i+3];
			umdes[cptattrib]=des[i+4];
			
			
			//alert(desln[cptattrib]+'  '+cptattrib);
		
		}
	//	
		
		
		//alert(des[0]);
		//alert(des[1]);

	//	$.redirect('testpostrec.php', {'DES': des, 'QTE':qtdes, 'PRIX':pudes, 'UNITE':umdes', 'ORDRELIGNE':ordredes,'dnum':?php echo $NumeroIndexDevisP ?>,'didxcli':<php echo // $NumeroIdxClient ?> });

		//	$.redirect('testpostrec.php', {'DES': desln, 'QTE': qtdes, 'PRIX':pudes, 'UNITE':umdes, 'ORDRELIGNE': ordredes,
		//								   && 'dnum':?php echo $NumeroIndexDevisP ?>,'didxcli':?php echo $NumeroIdxClient ?>,'dnum':?php echo $NUM ?>,  
		//								   && 'ddate':$("div.date").html(),'object':$("div.colh#oobjet").html(),'dchantier':$("div.colt#cchantier").html(),
		//								   && 'dtva':$("div.colt#tauxtva").html(),'dbanque': $("div.colt#banque").html(),'montant': $("div.colt#totalhtva").html() });
		var ETATMENU=$( "input[type=checkbox][name=etat]:checked" ).val();
		if (ETATMENU ==4)
    		{ETATMENU=4;	}else {ETATMENU=0;}
		//
		var xnum=<?php echo chr(34).$NUM.chr(34) ?>;
		//alert( xnum );	
		
		$.redirect('testpostfacrec.php', {'DES': desln, 'QTE': qtdes, 'PRIX':pudes, 'UNITE':umdes, 'ORDRELIGNE': ordredes,'dnum':<?php echo $NumeroIndexDevisP ?>,'didxcli':<?php echo $NumeroIdxClient ?>,'ddate':$("div.date").html(),'object':$("div.colh#oobjet").html(),'dchantier':$("div.colt#cchantier").html(),'dtva':$("div.colt#tauxtva").html(),'dbanque': $("div.colt#banque").html(),'montant': $("div.colt#totalhtva").html(),'commande': $("div.colt#totaltvac").html(),'devisnum': xnum ,'dmemo': $("div.memo").html(),'etat':ETATMENU });
		
		
//alert($("div.memo").html());		
		
	});
	
	
	
	cptlign=2;
	$(".swp").on('click',function(){
		
	
		
		
//var p = $( "div.colt" );
//var position = p.position();
//$( "p:last" ).text( "left: " + position.left + ", top: " + position.top );
		
		cptlign=cptlign+1;
    var itemRow =
       '  <tr class="yes" id="'+cptlign+'" >  '+
		'<td width="17px" valign="top" align="left" bgcolor="#EFD61E" ><div class="col" id="ligne1" contenteditable="false" style="background:#EFD61E; max-width: 17px;  ">1</div>  </td> '+
		'<td width="515px" valign="top"align="left" bgcolor="#EEEEEE"> <div class="col"  id="descriptionligne" contenteditable="true" style="background:#EEEEEE; max-width: 515px;  ">F&pose ...</div></td> '+
			'<td class="non" width="60px" valign="top" align="right" bgcolor="#DDDDDD" > <div class="col" id="qtcalc" contenteditable="true" style="background:#DDDDDD; max-width: 60px;  "> -</div> </td> '+
			'<td width="65px" valign="top" align="right" bgcolor="#EEEEEE" > <div class="col" id="prixcalc" contenteditable="true" style="background:#EEEEEE; max-width: 65px;  ">-</div></td>'+ 
			'<td width="40px" valign="top" align="center" bgcolor="#DDDDDD" > <div class="col" id="umcalc" contenteditable="true" style="background:#DDDDDD; max-width: 40px;  ">- </div> </td> '+
			'<td width="95px" valign="top" align="right" bgcolor="#EFD61E"><div class="col" id="soustotal" contenteditable="false" style="background:#EFD61E; max-width: 95px;  "> &nbsp</div>'+ '</td></tr>';
		
    $("#items_table").append(itemRow);
	//	 $("#items_table").addClass('yes').after(itemRow);

		  $("#table-2").tableDnD();
		
			cpt=1;
			lnt=0;
			$("div.col#ligne1").each(function(i, v){
				if (i=cpt) {
					lnt++;
            $(this).html((lnt));cpt=cpt+6;
				}
			 
			})
		
   		calcul();
		
		
		
		
	
	});

	$( "table" ).delegate( "tr", "click", function() {
 //	$( "p:last" ).text( "class: " + $(this).attr('class') +"  "+ $('tr'));
		
		if( $('input[name=efface]').is(':checked') ){
         //alert("la liogne va ettre supprimée");
		
		
		if ($(this).hasClass('yes')) {
		$(this).remove();
			cptlign=cptlign-1;
			var rowCount = $("#items_table tr").length;
			//alert (rowCount);
			
			cpt=6;
		
			
			
			$("div.col#ligne1").each(function(i, v){
				if (i=cpt) {
					lnt++;
            $(this).html((lnt));cpt=cpt+6;	}
			})
			
	
			} 
	        
		calcul();
			
			}
							
});
	
	function comble()
{	
	var p = $( "div.colt" );
        var position = p.position();
        var p1 = $( ".elastic" );
        var position1 = p1.position();
    
		//alert(position1.top);
		
    if (position.top != 950){
		var height = 950-position1.top;//$(window).height();
		$('.elastic').css('height',height);
		//alert(height);
	}
       var position = p.position();
	//	$( "p:last" ).text( "left: " + position.left + ", top:icc " + position.top +"hautreur "+height );	
	
	};
	
	function calcul() {
	//alert("ok");
		
		comble();
		
			cptt=1;
			lnt=0;
			lntt=-1;
		
		var tempqt = Array();
			$("div.col#qtcalc").each(function(i, v){
				 tempqt[i]=$(this).text();
				//alert(tempqt[i]+' '+i);
				
			})
	
			var tempprix = Array();
			$("div.col#prixcalc").each(function(i, v){
				 tempprix[i]=$(this).text();
				tempprix[i]=tempprix[i].replace(' ','');	
				//alert(tempqt[i]+' '+i);
				
			})
	

			tothtva=0;
			var tempst = Array();
			$("div.col#soustotal").each(function(i, v){
											//alert("ok");
				//alert(tempqttempqt[i]);
				if (i=cptt) {
					lntt++;
                    
                    formatnombre(tempqt[lntt],2);
					tempqt[lntt]=tempqt[lntt].replace(',','.');	
					tempprix[lntt]=tempprix[lntt].replace(',','.');	
					//alert("ok");
					tempst[lntt]=parseFloat(tempqt[lntt])*parseFloat(tempprix[lntt]);
                    
                     if (isNaN(tempst[lntt])) {
                         
                    tempst[lntt]='  '; 
                    $(this).html(tempst[lntt]);cptt=cptt+6;
                         
                    } else {
				    
					tothtva=tothtva+tempst[lntt];
					
					tempst[lntt]=format((parseFloat(tempst[lntt])),2);
    				tempst[lntt]=tempst[lntt].toString();
					tempst[lntt]=tempst[lntt].replace('.',',');		
			        $(this).html(tempst[lntt]+"€");cptt=cptt+6;
                    }
				
                            }
			})

		//	alert(tothtva);
			temptothtva=tothtva;	
			tothtva=format((parseFloat(tothtva)),2);
			    
    				tothtva=tothtva.toString();
					tothtva=tothtva.replace('.',',');		
				$("div.colt#totalhtva").html(tothtva+"€");
			
			tva=$("div.colt#tauxtva").text();
			var r = /[-+]?[0-9]*\.?[0-9]+/g;
			tva=tva.replace(',','.');
	        tva=(tva.match(r))[0];
			//alert(tva);
			tottva=parseFloat(temptothtva)*(parseFloat(tva)/100);
            tottva=Math.round(tottva*100)/100;
      
        
			temptva=tottva;
			tottva=format((parseFloat(tottva)),2);
			tottva=tottva.toString();
					tottva=tottva.replace('.',',');		
				$("div.colt#totaltva").html(tottva+"€");
			
			tempotottvac=temptva+temptothtva;
			tempotottvac=format((parseFloat(tempotottvac)),2);
			tempotottvac=tempotottvac.toString();
					tempotottvac=tempotottvac.replace('.',',');		
			
			$("div.colt#totaltvac").html(tempotottvac+"€");
			
			//alert(tottva);
		
		    cpt=1;
			lnt=0;
			$("div.col#ligne1").each(function(i, v){
				if (i=cpt) {
					lnt++;
            $(this).html((lnt));cpt=cpt+6;	
				}
			 
			})

					
		   
			 
		
		
			} 
	
	function calculload()
{	calcul();
 
	$("div.col#prixcalc").each(function(i, v){
			//	alert("ok"+$(this).html());
           $(this).html(formatnombre($(this).html(),2));	
			 
			})

} 
	
	
	function myFunction() {
    var x = document.getElementById("mydiv");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}
	
	
		
$("div.date").dblclick(function()
 { 
 	var tempdate;
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();
	tempdate=$("div.date").html();
	//alert(tempdate);
	tempdate=tempdate.substring(17,tempdate.length);
	// set a variable
     var today = moment().format('DD/MM/YYYY');
	tempdate="Date: "+today+" "+tempdate;
	//alert(tempdate);
	$("div.date").html(tempdate);  
	//alert("ok");
	
  
 });
	var inc=0;
	$("div#tauxtva").dblclick(function()
 { 
 	
		inc=inc+1;
    //alert(inc);  
		switch (inc) {
    case 1:
      			$("div#tauxtva").html("Tva 6%, maison de plus de 10 ans.");
				calcul();
				break;
    case 2:
        			$("div#tauxtva").html("Tva 21%.");
				calcul();
        		break;
    case 3:
					$("div#tauxtva").html("Tva 0%, autoliquidation.");
				calcul();
    			inc=0;
    
}
	
  
 });

        $("div#tauxtva").keyup(function()
 { 
 	
	
				calcul();
    		
    

  
 });
    
    

		$.fn.selectText = function(){
    var doc = document;
    var element = this[0];
    //console.log(this, element);
    if (doc.body.createTextRange) {
        var range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        var selection = window.getSelection();        
        var range = document.createRange();
        range.selectNodeContents(element);
        selection.removeAllRanges();
        selection.addRange(range);
    }
		};

	
	
	//************************      gestion keyup ***********************************
	
	
			$("div").delegate("#umcalc","keyup",function(e)
	
{
		  
			var tempof = Array();
			$("div.col#umcalc").each(function(i, v){
				tempof[i]=$(this).is(":focus");
				
				//alert(tempof[i]);
				if (tempof[i]=== true) {
					lignecourante=i;}
				// if (!($("div.col#qtcalc").is(":focus"))) {
				//	alert("ok"+i+' '+tempof[i]);	}
				
			})
			
				
        if (e.keyCode == 40) 
        {  
           // alert("bas");
			lignecourante++;
			 $("div.col#umcalc")[lignecourante].focus();
			
		
        }
        if(e.keyCode==38)
        {
           // alert("haut");
			lignecourante--;
			 $("div.col#umcalc")[lignecourante].focus();
			
			
        }
//calcul();
});
	
	
	
	
	
	
	
	
	
	

			$("div").delegate("#descriptionligne","keyup",function(e)
	
{
		  
			var tempof = Array();
			$("div.col#descriptionligne").each(function(i, v){
				tempof[i]=$(this).is(":focus");
				
				//alert(tempof[i]);
				if (tempof[i]=== true) {
					lignecourante=i;}
				// if (!($("div.col#qtcalc").is(":focus"))) {
				//	alert("ok"+i+' '+tempof[i]);	}
			})
			
				
        if (e.keyCode == 40) 
        {  
           // alert("bas");
			lignecourante++;
			 $("div.col#descriptionligne")[lignecourante].focus();
			
		
        }
        if(e.keyCode==38)
        {
           // alert("haut");
			lignecourante--;
			 $("div.col#descriptionligne")[lignecourante].focus();
			
			
        }
//calcul();
});
	
	
		$("div").delegate("#prixcalc","keyup",function(e)
	
{
		
			var tempof = Array();
			$("div.col#prixcalc").each(function(i, v){
				tempof[i]=$(this).is(":focus");
				//alert(tempof[i]);
				if (tempof[i]=== true) {
					lignecourante=i;}
				// if (!($("div.col#qtcalc").is(":focus"))) {
				//	alert("ok"+i+' '+tempof[i]);	}
			})
			
				
        if (e.keyCode == 40) 
        {  
           // alert("bas");
			lignecourante++;
			 $("div.col#prixcalc")[lignecourante].focus();
		
        }
        if(e.keyCode==38)
        {
           // alert("haut");
			lignecourante--;
			 $("div.col#prixcalc")[lignecourante].focus();
			
			
        }
calcul();
});
	
	$("div").delegate("#qtcalc","keyup",function(e)
	
{
		
			var tempof = Array();
			$("div.col#qtcalc").each(function(i, v){
				tempof[i]=$(this).is(":focus");
				//alert(tempof[i]);
				if (tempof[i]=== true) {
					lignecourante=i;}
				// if (!($("div.col#qtcalc").is(":focus"))) {
				//	alert("ok"+i+' '+tempof[i]);	}
			})
			
		//$( "p:last" ).text( "change  " + $(this).text() );
		//calcul();	
		
        if (e.keyCode == 40) 
        {  
           // alert("bas");
			lignecourante++;
			 $("div.col#qtcalc")[lignecourante].focus();
		
        }
        if(e.keyCode==38)
        {
           // alert("haut");
			lignecourante--;
			 $("div.col#qtcalc")[lignecourante].focus();
			
			
        }
calcul();
			//$( "p:last" ).text( "fini  "  );
});
	
	
	
	$("div.col#qtcalc").click( function() {
	 $(this).selectText();
	

 });
	
	$( "div" ).delegate( "#prixcalc", "click", function() {
	  $(this).selectText();
		
	
 });
	
	$( "div" ).delegate( "#umcalc", "click", function() {
	 $(this).selectText();

 });

	
	
			
	</script>
	

</body>		

</html>
