<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
	$ligne = Commande::getCommandeByNoCommande($NoCommande);
	if ($mode == 1) {
		$Dest = "Stock";
		if ($ligne2 = Client::getClientByNoClient($ligne['NoClient'])) {
			$Dest = $ligne2['Nom'];
		}
	}
	if ($resultat = CommandeArticle::getCommandeArticleByNoCommande($NoCommande)) {
		echo "document.info.Texte_libre.value='Impotation commande no $NoCommande';\n";
		echo "add_new_text();\n";
		foreach ($resultat as $ligne) {
			switch ($ligne['TypeData']) {
				case 0:
					echo "document.info.NoArticle.value='" . addslashes($ligne['NoArticle']) . "';\n";
					echo "document.info.Description.value='" . addslashes($ligne['Description']) . "';\n";
					echo "document.info.Prix.value ='" . $ligne['PrixBase']  . "';\n";
					echo "document.info.TVA.value = '" . $ligne['TVA']  . "';\n";
					echo "document.info.GM.value = '" . $ligne['GM'] . "';\n";
					if ($mode == 1) {
						if ($ligne2 = addslashes(addslashes($ligne['NoArticle']))) {
							echo "document.info.Rabais.value = '-" . $ligne2['Rabais'] . "';\n";
						} else {
							echo "document.info.Rabais.value = '" . $ligne['Rabais'] . "';\n";
						}
					} else {
						echo "document.info.Rabais.value = '" . $ligne['Rabais'] . "';\n";
					}
					echo "document.info.Quantite.value = '" . $ligne['Quantite'] . "';\n";
					if ($mode == 1) {
						echo "document.info.Destinataire.value = '" . addslashes($Dest) . "';\n";
					}
					echo "add_new(false);\n";
					break;
				case 2:
					echo "tot_inter();\n";
					break;
			}
		}
	}
}
