</li>
		<li><?php 
echo round($commande->remise, 2);
?>
 <?php 
echo $devise->symbole;
?>
</li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php 
echo trad('Code_promo', 'admin');
?>
</li>
		<li><?php 
$promoutil = new Promoutil();
if ($promoutil->charger_commande($commande->id)) {
    $promo = new Promo();
    $promo->charger_id($promoutil->promo);
    if ($promoutil->code == $promo->code && $promoutil->type == $promo->type && $promoutil->valeur == $promo->valeur) {
        ?>
			<a href="promo_modifier.php?id=<?php 
        echo $promoutil->promo;
        ?>
"><?php 
        echo $promoutil->code;
        ?>
</a>
			<?php 
    } else {
        ?>
Example #2
0
function paiement($type_paiement)
{
    if (!$_SESSION['navig']->client->id || $_SESSION['navig']->panier->nbart < 1) {
        redirige(urlfond());
    }
    $total = 0;
    $nbart = 0;
    $poids = 0;
    $unitetr = 0;
    ActionsModules::instance()->appel_module("avantcommande");
    $modules = new Modules();
    $modules->charger_id($type_paiement);
    if (!$modules->actif) {
        return 0;
    }
    try {
        $modpaiement = ActionsModules::instance()->instancier($modules->nom);
        $commande = new Commande();
        $commande->transport = $_SESSION['navig']->commande->transport;
        $commande->client = $_SESSION['navig']->client->id;
        $commande->remise = 0;
        $devise = ActionsDevises::instance()->get_devise_courante();
        $commande->devise = $devise->id;
        $commande->taux = $devise->taux;
        $client = new Client();
        $client->charger_id($_SESSION['navig']->client->id);
        $adr = new Venteadr();
        $adr->raison = $client->raison;
        $adr->entreprise = $client->entreprise;
        $adr->nom = $client->nom;
        $adr->prenom = $client->prenom;
        $adr->adresse1 = $client->adresse1;
        $adr->adresse2 = $client->adresse2;
        $adr->adresse3 = $client->adresse3;
        $adr->cpostal = $client->cpostal;
        $adr->ville = $client->ville;
        $adr->tel = $client->telfixe . "  " . $client->telport;
        $adr->pays = $client->pays;
        $adrcli = $adr->add();
        $commande->adrfact = $adrcli;
        $adr = new Venteadr();
        $livraison = new Adresse();
        if ($livraison->charger($_SESSION['navig']->adresse)) {
            $adr->raison = $livraison->raison;
            $adr->entreprise = $livraison->entreprise;
            $adr->nom = $livraison->nom;
            $adr->prenom = $livraison->prenom;
            $adr->adresse1 = $livraison->adresse1;
            $adr->adresse2 = $livraison->adresse2;
            $adr->adresse3 = $livraison->adresse3;
            $adr->cpostal = $livraison->cpostal;
            $adr->ville = $livraison->ville;
            $adr->tel = $livraison->tel;
            $adr->pays = $livraison->pays;
        } else {
            $adr->raison = $client->raison;
            $adr->entreprise = $client->entreprise;
            $adr->nom = $client->nom;
            $adr->prenom = $client->prenom;
            $adr->adresse1 = $client->adresse1;
            $adr->adresse2 = $client->adresse2;
            $adr->adresse3 = $client->adresse3;
            $adr->cpostal = $client->cpostal;
            $adr->ville = $client->ville;
            $adr->tel = $client->telfixe . "  " . $client->telport;
            $adr->pays = $client->pays;
        }
        $adrlivr = $adr->add();
        $commande->adrlivr = $adrlivr;
        $commande->facture = 0;
        $commande->statut = Commande::NONPAYE;
        $commande->paiement = $type_paiement;
        $commande->lang = ActionsLang::instance()->get_id_langue_courante();
        $commande->id = $commande->add();
        $pays = new Pays();
        $pays->charger($adr->pays);
        $correspondanceParent = array(null);
        foreach ($_SESSION['navig']->panier->tabarticle as $pos => &$article) {
            $venteprod = new Venteprod();
            $dectexte = "\n";
            $produit = new Produit();
            $stock = new Stock();
            foreach ($article->perso as $perso) {
                $declinaison = new Declinaison();
                $declinaisondesc = new Declinaisondesc();
                if (is_numeric($perso->valeur) && $modpaiement->defalqcmd) {
                    // diminution des stocks de déclinaison si on est sur un module de paiement qui défalque de suite
                    $stock->charger($perso->valeur, $article->produit->id);
                    $stock->valeur -= $article->quantite;
                    $stock->maj();
                }
                $declinaison->charger($perso->declinaison);
                $declinaisondesc->charger($declinaison->id);
                // recup valeur declidisp ou string
                if ($declinaison->isDeclidisp($perso->declinaison)) {
                    $declidisp = new Declidisp();
                    $declidispdesc = new Declidispdesc();
                    $declidisp->charger($perso->valeur);
                    $declidispdesc->charger_declidisp($declidisp->id);
                    $dectexte .= "- " . $declinaisondesc->titre . " : " . $declidispdesc->titre . "\n";
                } else {
                    $dectexte .= "- " . $declinaisondesc->titre . " : " . $perso->valeur . "\n";
                }
            }
            // diminution des stocks classiques si on est sur un module de paiement qui défalque de suite
            $produit = new Produit($article->produit->ref);
            if ($modpaiement->defalqcmd) {
                $produit->stock -= $article->quantite;
                $produit->maj();
            }
            /* Gestion TVA */
            $prix = $article->produit->prix;
            $prix2 = $article->produit->prix2;
            $tva = $article->produit->tva;
            if ($pays->tva != "" && (!$pays->tva || $pays->tva && $_SESSION['navig']->client->intracom != "" && !$pays->boutique)) {
                $prix = round($prix / (1 + $tva / 100), 2);
                $prix2 = round($prix2 / (1 + $tva / 100), 2);
                $tva = 0;
            }
            $venteprod->quantite = $article->quantite;
            if (!$article->produit->promo) {
                $venteprod->prixu = $prix;
            } else {
                $venteprod->prixu = $prix2;
            }
            $venteprod->ref = $article->produit->ref;
            $venteprod->titre = $article->produitdesc->titre . " " . $dectexte;
            $venteprod->chapo = $article->produitdesc->chapo;
            $venteprod->description = $article->produitdesc->description;
            $venteprod->tva = $tva;
            $venteprod->commande = $commande->id;
            $venteprod->id = $venteprod->add();
            $correspondanceParent[] = $venteprod->id;
            // ajout dans ventedeclisp des declidisp associées au venteprod
            foreach ($article->perso as $perso) {
                $declinaison = new Declinaison();
                $declinaison->charger($perso->declinaison);
                // si declidisp (pas un champs libre)
                if ($declinaison->isDeclidisp($perso->declinaison)) {
                    $vdec = new Ventedeclidisp();
                    $vdec->venteprod = $venteprod->id;
                    $vdec->declidisp = $perso->valeur;
                    $vdec->add();
                }
            }
            ActionsModules::instance()->appel_module("apresVenteprod", $venteprod, $pos);
            $total += $venteprod->prixu * $venteprod->quantite;
            $nbart++;
            $poids += $article->produit->poids;
        }
        foreach ($correspondanceParent as $id_panier => $id_venteprod) {
            if ($_SESSION['navig']->panier->tabarticle[$id_panier]->parent >= 0) {
                $venteprod->charger($id_venteprod);
                $venteprod->parent = $correspondanceParent[$_SESSION['navig']->panier->tabarticle[$id_panier]->parent];
                $venteprod->maj();
            }
        }
        $pays = new Pays($_SESSION['navig']->client->pays);
        if ($_SESSION['navig']->client->pourcentage > 0) {
            $commande->remise = $total * $_SESSION['navig']->client->pourcentage / 100;
        }
        $total -= $commande->remise;
        if ($_SESSION['navig']->promo->id != "") {
            $commande->remise += calc_remise($total);
            $_SESSION['navig']->promo->utilise = 1;
            if (!empty($commande->remise)) {
                $commande->remise = round($commande->remise, 2);
            }
            $commande->maj();
            $temppromo = new Promo();
            $temppromo->charger_id($_SESSION['navig']->promo->id);
            $temppromo->utilise++;
            $temppromo->maj();
            $promoutil = new Promoutil();
            $promoutil->commande = $commande->id;
            $promoutil->promo = $temppromo->id;
            $promoutil->code = $temppromo->code;
            $promoutil->type = $temppromo->type;
            $promoutil->valeur = $temppromo->valeur;
            $promoutil->add();
        }
        if ($commande->remise > $total) {
            $commande->remise = $total;
        }
        $commande->port = port();
        if (intval($commande->port) <= 0) {
            $commande->port = 0;
        }
        $_SESSION['navig']->promo = new Promo();
        $_SESSION['navig']->commande = $commande;
        $commande->transaction = genid($commande->id, 6);
        $commande->maj();
        $total = $_SESSION['navig']->panier->total(1, $_SESSION['navig']->commande->remise) + $_SESSION['navig']->commande->port;
        if ($total < $_SESSION['navig']->commande->port) {
            $total = $_SESSION['navig']->commande->port;
        }
        $_SESSION['navig']->commande->total = $total;
        ActionsModules::instance()->appel_module("aprescommande", $commande);
        // Appeler la méthode mail du plugin de paiement...
        $modpaiement->mail($commande);
        // ... et la méthode paiement
        $modpaiement->paiement($commande);
    } catch (Exception $e) {
        // FIXME: Echec de commande -> cas à traiter ?
    }
}