<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>

<head>
	<title>Title here!</title>
</head>

<body>
	<?php
	set_time_limit(600);
	require 'database.inc.php';
	$requette = "UPDATE articles SET TVA = -8 WHERE TVA = -7.6";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "UPDATE articles SET TVA = 8 WHERE TVA = 7.6";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "UPDATE articles SET TVA = -2.5 WHERE TVA = -2.4";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "UPDATE articles SET TVA = 2.5 WHERE TVA = 2.4";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "UPDATE config" . ID_GARAGE . " SET valeur = '8.0' WHERE champ = 'TVA'";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "UPDATE config" . ID_GARAGE . " SET valeur = '-8.0' WHERE champ = 'TVA_MARGES'";
	echo "$requette<BR>\n";
	Connection::executeRawQuery($requette);
	$requette = "SELECT NoCommande, Type, APayer FROM commande" . ID_GARAGE . " WHERE Genre = 'F' AND Paye != 'O' AND NoCommande >= 100000 AND APayer > 0 AND Type != 'FI' AND Type != 'GG'";
	$resultat = Connection::executeRawQueryWithfetchAll($requette);
	foreach ($resultat as $ligne) {
		$requette2 = "SELECT * FROM commandearticles" . ID_GARAGE . " WHERE NoCommande = " . $ligne['NoCommande'] . " AND TypeData = 0 AND (TVA = -7.6 OR TVA = 7.6) AND PrixMulti != 0";
		$resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
		if ($ligne2 = $resultat2[0]) {
			$nouveau_a_payer = $ligne['APayer'] * 1.08 / 1.076;
			$nouveau_a_payer = round(ceil($nouveau_a_payer * 20) / 20, 2);
			$difference =  round($nouveau_a_payer - $ligne['APayer'], 2);
			$requette3 = "UPDATE commande" . ID_GARAGE . " SET APayer = $nouveau_a_payer WHERE NoCommande = " . $ligne['NoCommande'];
			echo "$requette3<BR>\n";
			Connection::executeRawQuery($requette3);
			$requette4 = "SELECT MAX(Position) FROM commandearticles" . ID_GARAGE . " WHERE NoCommande = " . $ligne['NoCommande'];
			$resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
			if ($ligne4 = $resultat4[0]) {
				$requette5 = "INSERT INTO commandearticles" . ID_GARAGE . " (NoCommande, Position, TypeData, NoArticle, Description, TVA, NoCompte, GM, Quantite, PrixBase, Rabais, C, T, PrixUnit, PrixMulti, PrixTotal) values (" . $ligne['NoCommande'] . ", " . ($ligne4[0] + 1) . ", 4, 'TVA', 'Correction TVA 7.6% à 8.0%', 8, 0, 0, 1, $difference, 0, 0, 0, $difference, $difference, $difference)";
				echo "$requette5<BR>\n";
				Connection::executeRawQuery($requette5);
			}
		}
	}

	?>
</body>

</html>