function port($type = 0, $_pays = false, $_cpostal = "") { if ($_SESSION['navig']->commande->transport == "" && !$type) { return -1; } if ($_SESSION['navig']->adresse != 0) { $chadr = 1; } else { $chadr = 0; } $modules = new Modules(); if (!$type) { $modules->charger_id($_SESSION['navig']->commande->transport); } else { $modules->charger_id($type); } if ($modules->type != Modules::TRANSPORT || !$modules->actif) { return -1; } $p = new Pays(); if ($chadr) { $adr = new adresse(); $adr->charger($_SESSION['navig']->adresse); $p->charger($adr->pays); $cpostal = $adr->cpostal; } else { $p->charger($_SESSION['navig']->client->pays); $cpostal = $_SESSION['navig']->client->cpostal; } // Prise en compte des infos passée, si aucune des infos précédentes n'est pertinente. if (empty($p->id) && $_pays) { $p->charger($_pays); } if (empty($cpostal) && $_cpostal != "") { $cpostal = $_cpostal; } $zone = new Zone(); $zone->charger($p->zone); try { $port = ActionsModules::instance()->instancier($modules->nom); $port->nbart = $_SESSION['navig']->panier->nbart(); $port->poids = $_SESSION['navig']->panier->poids(); $port->total = $_SESSION['navig']->panier->total(); $port->zone = $p->zone; $port->pays = $p->id; $port->unitetr = $zone->unite; $port->cpostal = $cpostal; $frais = $port->calcule(); ActionsModules::instance()->appel_module("port", $frais); return $frais; } catch (exception $e) { return -1; } }
function edition() { $id = intval(lireParam('pays', 'int')); $maj = $id > 0; $pays = new Pays(); if ($maj) { $pays->charger($id); } else { $pays->lang = 0; $pays->defaut = 0; } $pays->tva = intval($_REQUEST['tva']) != 0 ? 1 : 0; $pays->zone = intval($_REQUEST['zone']); $pays->isocode = intval($_REQUEST['isocode']); $pays->isoalpha2 = $_REQUEST['isoalpha2']; $pays->isoalpha3 = $_REQUEST['isoalpha3']; if ($maj) { $pays->maj(); } else { $id = $pays->add(); } if ($id > 0) { foreach ($_REQUEST['langue'] as $langue) { $paysdesc = new Paysdesc(); if ($maj) { $paysdesc->charger($id, $langue); } $paysdesc->pays = $id; $paysdesc->lang = $langue; $paysdesc->titre = $_REQUEST['titre'][$langue]; $paysdesc->chapo = $_REQUEST['chapo'][$langue]; $paysdesc->description = $_REQUEST['description'][$langue]; if ($maj) { $paysdesc->maj(); } else { $paysdesc->add(); } } } }
exit; } // Compatibilité 1.4 -> On utilise le modèle PDF si il existe if (file_exists(__DIR__ . '/modeles/facture.php')) { include_once __DIR__ . "/../../classes/Commande.class.php"; include_once __DIR__ . "/../../classes/Client.class.php"; include_once __DIR__ . "/../../classes/Venteprod.class.php"; include_once __DIR__ . "/../../classes/Produit.class.php"; include_once __DIR__ . "/../../classes/Adresse.class.php"; include_once __DIR__ . "/../../classes/Zone.class.php"; include_once __DIR__ . "/../../classes/Pays.class.php"; include_once __DIR__ . "/../../fonctions/divers.php"; $client = new Client(); $client->charger_id($commande->client); $pays = new Pays(); $pays->charger($client->pays); $zone = new Zone(); $zone->charger($pays->zone); include_once __DIR__ . "/modeles/facture.php"; $facture = new Facture(); $facture->creer($_GET['ref']); exit; } // Le moteur ne sortira pas le contenu de $res $sortie = false; // Le fond est le template de facture. $reptpl = __DIR__ . "/template/"; $fond = "facture.html"; $lang = $commande->lang; // Compatibilité avec le moteur. $_REQUEST['commande'] = $_GET['ref'];
function boucleTransport($texte, $args) { // récupération des arguments $id = lireTag($args, "id", "int_list"); $nom = lireTag($args, "nom", "string"); $exclusion = lireTag($args, "exclusion", "string_list"); $idpays = intval(lireTag($args, "pays", "int")); $cpostal = intval(lireTag($args, "cpostal", "string")); $montantmini = intval(lireTag($args, "montantmini", "float")); $search = ""; $res = ""; if ($id != "") { $search .= "and id in ({$id})"; } if ($nom != "") { $search .= "and nom=\"{$nom}\""; } if ($exclusion != "") { $liste = ""; $tabexcl = explode(",", $exclusion); for ($i = 0; $i < count($tabexcl); $i++) { $liste .= "'" . $tabexcl[$i] . "'" . ","; } $liste = rtrim($liste, ","); $search .= " and nom not in ({$liste})"; } $modules = new Modules(); $query = "select * from {$modules->table} where type='2' and actif='1' {$search} order by classement"; $resul = CacheBase::getCache()->query($query); if (empty($resul)) { return ""; } $pays = new Pays(); if ($idpays > 0) { $pays->charger($idpays); } else { if ($_SESSION['navig']->adresse != "" && $_SESSION['navig']->adresse != 0) { $adr = new Adresse(); $adr->charger($_SESSION['navig']->adresse); $pays->charger($adr->pays); } else { $pays->charger($_SESSION['navig']->client->pays); } } $transzone = new Transzone(); $compt = 0; foreach ($resul as $row) { if (!$transzone->charger($row->id, $pays->zone)) { continue; } $compt++; $modules = new Modules(); $modules->charger_id($row->id); try { $instance = ActionsModules::instance()->instancier($modules->nom); $port = round(port($row->id, $pays->id, $cpostal), 2); $titre = $instance->getTitre(); $chapo = $instance->getChapo(); $description = $instance->getDescription(); } catch (Exception $ex) { $titre = $chapo = $description = ''; } if ($port < $montantmini) { continue; } // Chercher le logo $exts = array('png', 'gif', 'jpeg', 'jpg'); $logo = false; foreach ($exts as $ext) { $tmp = ActionsModules::instance()->lire_chemin_base() . "/{$row->nom}/logo.{$ext}"; if (file_exists($tmp)) { $logo = ActionsModules::instance()->lire_url_base() . "/{$row->nom}/logo.{$ext}"; break; } } $temp = str_replace("#NOM", $row->nom, $texte); $temp = str_replace("#TITRE", "{$titre}", $temp); $temp = str_replace("#CHAPO", "{$chapo}", $temp); $temp = str_replace("#DESCRIPTION", "{$description}", $temp); $temp = str_replace("#URLCMD", urlfond("commande", "action=transport&id=" . $row->id, true), $temp); $temp = str_replace("#ID", "{$row->id}", $temp); $temp = str_replace("#LOGO", $logo, $temp); $temp = str_replace("#PORT", formatter_somme($port), $temp); $temp = str_replace("#COMPT", "{$compt}", $temp); $res .= $temp; } return $res; }
} } } /* Afficher la forme de modif/creation de pays */ $langues = array(); $langue = new Lang(); $result = $langue->query("select * from " . $langue->table . " order by id"); while ($result && ($row = $langue->fetch_object($result))) { $langues[] = $row; } $pays = new Pays(); $paysdesc = new Paysdesc(); $id = intval(lireParam('pays', 'int')); $pays->id = $id; if ($id > 0) { $pays->charger($id); } ?> <div class="entete_config" style="width: auto; float: none;"> <div class="titre"><?php echo trad('EDITION', 'admin'); ?> </div> <div class="fonction_valider"><a href="#" onclick="$('#pays_edit_form').submit(); return false;"><?php echo trad('VALIDER_LES_MODIFICATIONS', 'admin'); ?> </a></div> </div> <div class="flottant"> <form method="post" action="pays.php" id="pays_edit_form">
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 ? } }
function substitpanier($texte) { $total = 0; $totalht = 0; $totaleco = 0; $totaltaxe = 0; $allItemCount = $nb_article = 0; if ($_SESSION['navig']->adresse) { $adr = new Adresse(); $adr->charger($_SESSION['navig']->adresse); $idpays = $adr->pays; } else { $idpays = $_SESSION['navig']->client->pays; } $pays = new Pays(); $pays->charger($idpays); $total = $_SESSION['navig']->panier->total(); $totalht = $_SESSION['navig']->panier->total(0); $totaleco = $_SESSION['navig']->panier->totalecotaxe(); $tva = $total - $totalht; $nb_article = $_SESSION['navig']->panier->nbart; foreach ($_SESSION['navig']->panier->tabarticle as $anItem) { $allItemCount += $anItem->quantite; } unset($anItem); $port = port(); if ($port < 0) { $port = 0; } $totcmdport = $total + $port; $remise = $remise_client = $remise_promo = 0; if ($_SESSION['navig']->client->pourcentage > 0) { $remise_client = $total * $_SESSION['navig']->client->pourcentage / 100; } $remise_promo += calc_remise($total); $remise = $remise_promo + $remise_client; $totcmdport -= $remise; $totremise = $total - $remise; if ($totcmdport < $port) { $totcmdport = $port; } $totcmdportht = $totalht + $port; $totalht = formatter_somme($totalht); $total = formatter_somme($total); $totaleco = formatter_somme($totaleco); $totaltaxe = formatter_somme($totaltaxe); $port = formatter_somme($port); $totcmdport = formatter_somme($totcmdport); $remise = formatter_somme($remise); $totremise = formatter_somme($totremise); $totcmdportht = formatter_somme($totcmdportht); $tva = formatter_somme($tva, 2, ".", ""); $remise_client = formatter_somme($remise_client); $remise_promo = formatter_somme($remise_promo); $totpoids = $_SESSION['navig']->panier->poids(); $texte = str_replace("#PANIER_TOTALHT", "{$totalht}", $texte); $texte = str_replace("#PANIER_TOTALECO", "{$totaleco}", $texte); $texte = str_replace("#PANIER_TOTALTVA", "{$tva}", $texte); // total TVA du panier = #PANIER_TVA $texte = str_replace("#PANIER_TOTAL", "{$total}", $texte); $texte = str_replace("#PANIER_PORT", "{$port}", $texte); $texte = str_replace("#PANIER_TOTPORTHT", "{$totcmdportht}", $texte); $texte = str_replace("#PANIER_TOTPORT", "{$totcmdport}", $texte); $texte = str_replace("#PANIER_TOTREMISE", "{$totremise}", $texte); $texte = str_replace("#PANIER_REMISE_CLIENT", "{$remise_client}", $texte); $texte = str_replace("#PANIER_REMISE_PROMO", "{$remise_promo}", $texte); $texte = str_replace("#PANIER_REMISE", "{$remise}", $texte); $texte = str_replace("#PANIER_NBART_TOTAL", $allItemCount, $texte); $texte = str_replace("#PANIER_NBART", "" . $nb_article . "", $texte); $texte = str_replace("#PANIER_POIDS", "{$totpoids}", $texte); $texte = str_replace("#PANIER_TVA", "{$tva}", $texte); // total TVA du panier return $texte; }
function total($tva = 1, $remise = 0) { $total = 0; $taxe = 0; $pays = new Pays(); if ($_SESSION['navig']->adresse != "" && $_SESSION['navig']->adresse != 0) { $adr = new Adresse(); $adr->charger($_SESSION['navig']->adresse); $pays->charger($adr->pays); } else { $pays->charger($_SESSION['navig']->client->pays); } foreach ($this->tabarticle as $art) { $prix = $art->produit->promo ? $art->produit->prix2 : $art->produit->prix; $taxe += ($prix - $prix / (1 + $art->produit->tva / 100)) * $art->quantite; $total += $prix * $art->quantite; } if ($tva && $pays->tva != "" && !$pays->tva) { $total -= $taxe; } else { if ($tva == 0) { $total -= $taxe; } } $total -= $remise; ActionsModules::instance()->appel_module("totalPanier", $total); return round($total, 2); }