1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
// Le code de mon controle nommée "C_Accepter_Commande.php"
<?php
session_start();
$IdClt=$_COOKIE["siteweb_php"]; // Création du cookie
$date=date("Y")."-".date("m")."-".date("d"); // Variable permettant de gérer une date
//$LeClt=DAO_client::ChargerUnClient($IdClt); // Permet le chargement d'un client dans la variable "LeClt"
$i=0;
// Pour chaque article appartenant à la variable de session 'commander' on appel la fonction 'AjouterLigneCommande via la variable "MaCde"
foreach($_SESSION['Commander'] as $article)
{
$NvCde=DAO_Commande::NouvelleCde();
$i=$i+1;
$LaCde=new commande();
$PrixHT = $LaCde->retournePrixTotalTTC();
$PrixTVA = $LaCde->retourneTVA();
$PrixTTC = $LaCde->retournePrixTotalAPayer();
$MaCde=new commande ($NvCde, $IdClt, $date, $PrixHT, $PrixTVA, $PrixTTC);
$Cde=$MaCde->AjouterLigneCommande($article,$_POST['quantite'.$i]);
}
// Appel de la fonction 'Sauvegarder_UneCommande' via la variable "MaCde"
$MaCommande=DAO_Commande::SauvegarderCommande($MaCde);
unset($_SESSION["panier"]);
?>
<!-- Message de fin de commande -->
<div id="finCommande">
<?php
echo "<h1>votre commande a bien été prise en compte</h1>";
?>
</div>
// Voici le code de la classe commande
<?php
class commande
{
private $port=4; // Le port est une constante : 4 ¤ de frais de port pour chaque commande
private $Int_numligne; // Le numero de la ligne de commande
private $Int_idCde; // Le numéro de la commande
private $Date_DateCde; // La date de la commande
private $Obj_client; // Objet client
private $Dec_montantHT; // Le montant HT de la commande
private $Dec_montantTVA;
private $Dec_montatTTC;
private $Col_lesLignesCommandes; // Collection de LigneCommande
// Le constructeur
public function commande( $leidCde=null, $leClient=null, $laDateCde=null, $LemontantHT=null, $LemontantTVA=null, $LemontantTTC=null)
{
$this->Int_numligne=1;
$this->Int_idCde=$leidCde;
$this->Date_DateCde = $laDateCde;
$this->Obj_client = $leClient;
$this->Col_lesLignesCommandes = new collection();
$this->Dec_montantHT = $LemontantHT;
$this->Dec_montantTVA = $LemontantTVA;
$this->Dec_montantTTC = $LemontantTTC;
}
// Les getteurs
public function get_idCde()
{
return $this->Int_idCde;
}
public function get_Date_Cde()
{
return $this->Date_DateCde;
}
public function get_client()
{
return $this->Obj_client;
}
public function get_LesLignesCommandes()
{
return $this->Col_lesLignesCommandes;
}
public function get_numligne()
{
return $this->Int_numligne;
}
public function get_montantHT()
{
return $this->Dec_montantHT;
}
public function get_montantTVA()
{
return $this->Dec_montantTVA;
}
public function get_montantTTC()
{
return $this->Dec_montantTTC;
}
// Les setteurs
public function set_idCde($leidCde)
{
$this->Int_idCde =$leidCde;
}
public function set_Date_Cde($laDateCde)
{
$this->Date_DateCde =$laDateCde;
}
public function set_client($leClient)
{
$this ->Obj_client =$leClient;
}
public function set_lesLignesCommandes($lesLignes)
{
$Col_lesLignesCommandes = $lesLignes;
}
public function set_numligne($Numligne)
{
$this->Int_numligne=$Numligne;
}
public function set_montantHT($LemontantHT)
{
$this->Dec_montantHT=$LemontantHT;
}
public function set_montantTVA($LemontantTVA)
{
$this->Dec_montantTVA=$LemontantTVA;
}
public function set_montantTTC($LemontantTTC)
{
$this->Dec_montantTTC=$LemontantTTC;
}
// Méthodes : afficher
public function Afficher() {
$ch=$this->get_idCde()." ".$this->get_Date_Cde()." ".$this->get_client()." ".$this->get_montantTotal()->Afficher();
return $ch;
}
// Méthodes : Ajouter une ligne de commande
public function AjouterLigneCommande($Article, $Qte) {
$ligneCde=new ligne_commande($this,$Article,$Qte,$this->numligne, $this->Dec_montantHT);
$this->set_numligne($this->numligne+1);
$this->Col_lesLignesCommandes->add($ligneCde);
}
// Méthodes : retourner les lignes de commandes
public function retournerLesLignes() {
//retourne tout les objets contenu dans ligne de commande
$tableau = $this->get_LesLignesCommandes()->getAll();
return $tableau;
}
// Méthodes : retourner le nombre de ligne de commande
public function retournerNombreLignes() {
//retourne le nombre de ligne de commande
$tableau = $this->get_lesLignesCommandes()->getAll();
return count($tableau); //on utilise la fonction count
}
// Méthodes : retourne la TVA
public function retourneTVA(){
$TauxVA=$this->retournePrixTotalTTC()-$this->retournePrixTotalHT();
return $TauxVA;
}
// Méthodes : retourner le frais de port
public function retourneFraisPort(){
$FraisPort=$this->port;
return $FraisPort;
}
// Méthodes : retourner le prix total Toute taxe comprise
public function retournePrixTotalTTC(){
$tableau=$this->retournerLesLignes();
$résultat=0;
foreach($tableau as $o) {
$résultat=$résultat + $o->get_Article()->get_prixHT() * $o->get_Qte();
}
return $résultat;
}
// Méthodes : retourner le prix total hors taxe
public function retournePrixTotalHT(){
$PrixTTC=$this->retournePrixTotalTTC();
$PrixHT=$PrixTTC/1.196;
return $PrixHT;
}
// Méthodes : retourner le prix total à payer
public function retournePrixTotalAPayer(){
$PrixTTC=$this->retournePrixTotalTTC();
$résultat=$PrixTTC + $this->port;
return $résultat;
}
}
?>
// Voici le code de la méthode SauvegarderCommande($objCommande)
public static function SauvegarderCommande($objCommande)
{
$IdCde=$objCommande->get_idCde();
$client=$objCommande->get_client();
$DateCde=$objCommande->get_Date_Cde();
$MontantHT=$objCommande->get_montantHT();
$MontantTVA=$objCommande->get_montantTVA();
$MontantTTC=$objCommande->get_montantTTC();
if (DAO_commande::existe_UneCommande($IdCde))
{
$req="UPDATE commande SET";
$req=$req." ID_CDE=$IdCde";
$req=$req." IDclient=$client";
$req=$req.", DateCmde='$DateCde'";
$req=$req.", Co_MontantHT='$MontantHT'";
$req=$req.", Co_MontantTVA='$MontantTVA'";
$req=$req.", Co_MontantTTC='$MontantTTC'";
$req=$req." WHERE ID_CDE=$IdCde";
//echo $req;
$res = mysql_query($req);
}
else
{
$req="INSERT INTO commande VALUES ($IdCde,'$client','$DateCde','$MontantHT','$MontantTVA','$MontantTTC')";
echo $req. "<br/>";
//$res = mysql_query($req);
}
} |