161 lines
7.3 KiB
PHP
161 lines
7.3 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* */
|
|
/* Plugin pour Thelia */
|
|
/* */
|
|
/* Alerte stock par produit */
|
|
/* Version 1.1 */
|
|
/* */
|
|
/* Copyright (c) Informatique Prog */
|
|
/* email : contact@informatiqueprog.net */
|
|
/* */
|
|
/* This program is free software; you can redistribute it and/or modify */
|
|
/* it under the terms of the GNU General Public License as published by */
|
|
/* the Free Software Foundation; either version 2 of the License, or */
|
|
/* (at your option) any later version. */
|
|
/* */
|
|
/* This program is distributed in the hope that it will be useful, */
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
/* GNU General Public License for more details. */
|
|
/* */
|
|
/* You should have received a copy of the GNU General Public License */
|
|
/* along with this program; if not, write to the Free Software */
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
/* */
|
|
/*************************************************************************************/
|
|
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Variable.class.php");
|
|
|
|
class Alertstockprod extends PluginsClassiques{
|
|
var $id;
|
|
var $mini;
|
|
var $table = 'alertstockprod';
|
|
var $bddvars = array('id', 'mini');
|
|
|
|
function Alertstockprod(){
|
|
$this->PluginsClassiques('alertstockprod');
|
|
}
|
|
|
|
function init(){
|
|
$cnx = new Cnx();
|
|
$query = "CREATE TABLE `$this->table` ("
|
|
. " `id` int(11) NOT NULL"
|
|
. ", `mini` float NOT NULL DEFAULT '0'"
|
|
. ", PRIMARY KEY (`id`)"
|
|
. ")";
|
|
$result = mysql_query($query, $cnx->link);
|
|
$variable = new Variable();
|
|
if(!$variable->charger('alertstock_defaut')){
|
|
$variable->nom = 'alertstock_defaut';
|
|
$variable->valeur = '0';
|
|
$variable->add();
|
|
}
|
|
if(!$variable->charger('alertstock_caracteristique')){
|
|
$variable->nom = 'alertstock_caracteristique';
|
|
$variable->valeur = '0';
|
|
$variable->add();
|
|
}
|
|
}
|
|
|
|
function destroy(){
|
|
}
|
|
|
|
function controleProduits($listeProduits){
|
|
/*
|
|
* INFORMATIONS GOLBALS
|
|
*/
|
|
$alertstock_defaut = new Variable();
|
|
$alertstock_defaut->charger('alertstock_defaut');
|
|
$mailMessage = '';
|
|
/*
|
|
* BOUCLE SUR LES PRODUITS
|
|
*/
|
|
foreach($listeProduits as $produit){
|
|
if(isset($produit['Alertstock']) && $produit['Alertstock'] != '')
|
|
$alertstockProduit = (int)$produit['Alertstock'];
|
|
else if(isset($produit['Alertstock2']) && $produit['Alertstock2'] != '')
|
|
$alertstockProduit = (int)$produit['Alertstock2'];
|
|
else
|
|
$alertstockProduit = (int)$alertstock_defaut->valeur;
|
|
if($produit['Stock'] <= $alertstockProduit)
|
|
$mailMessage .= 'Ref : ' . $produit['Ref'] . ' ( ' . $produit['Titre'] . ' ), Stock actuel => ' . $produit['Stock'] . ', Alerte stock =>' . $alertstockProduit . "\n";
|
|
}
|
|
/*
|
|
* MAIL
|
|
*/
|
|
if (!empty($mailMessage)){
|
|
$contact = new Variable();
|
|
$contact->charger('emailcontact');
|
|
$urlsite = new Variable();
|
|
$urlsite->charger('urlsite');
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Mail.class.php");
|
|
$mail = new Mail();
|
|
$mail->IsMail();
|
|
$mail->From = $contact->valeur;
|
|
$mail->FromName = $urlsite->valeur;
|
|
$mail->Subject = 'Alerte stock pour le site : ' . $urlsite->valeur;
|
|
$mail->AltBody = $mailMessage;
|
|
$mail->MsgHTML(nl2br($mailMessage));
|
|
$mail->AddAddress($contact->valeur);
|
|
$mail->send();
|
|
return 'Email envoyé';
|
|
} else
|
|
return 'Aucune alerte stock';
|
|
}
|
|
|
|
function aprescommande($commande){
|
|
$caracteristique = new Variable();
|
|
$caracteristique->charger('alertstock_caracteristique');
|
|
$listeProduits = array();
|
|
/*
|
|
* PRODUITS DE LA COMMANDE
|
|
*/
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Caracval.class.php");
|
|
$caracval = new Caracval();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Caracdispdesc.class.php");
|
|
$caracdispdesc = new Caracdispdesc();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Venteprod.class.php");
|
|
$venteprod = new Venteprod();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Produit.class.php");
|
|
$produit = new Produit();
|
|
$query = "SELECT tVentP.ref Ref, tVentP.titre Titre, tProd.stock Stock, tCaracDispDesc.titre Alertstock, tCaracVal.valeur Alertstock2 FROM $venteprod->table tVentP"
|
|
. " JOIN $produit->table tProd ON tVentP.ref=tProd.ref"
|
|
. " LEFT JOIN $caracval->table tCaracVal ON tProd.id=tCaracVal.produit AND tCaracVal.caracteristique=$caracteristique->valeur"
|
|
. " LEFT JOIN $caracdispdesc->table tCaracDispDesc ON tCaracVal.caracdisp=tCaracDispDesc.caracdisp"
|
|
. " WHERE commande=$commande->id";
|
|
$result = mysql_query($query, $venteprod->link);
|
|
while($row = mysql_fetch_assoc($result)){
|
|
$listeProduits[] = $row;
|
|
}
|
|
$this->controleProduits($listeProduits);
|
|
}
|
|
|
|
function chargerTousLesProduits(){
|
|
$caracteristique = new Variable();
|
|
$caracteristique->charger('alertstock_caracteristique');
|
|
$listeProduits = array();
|
|
/*
|
|
* TOUS LES PRODUITS
|
|
*/
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Caracval.class.php");
|
|
$caracval = new Caracval();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Caracdispdesc.class.php");
|
|
$caracdispdesc = new Caracdispdesc();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Produit.class.php");
|
|
$produit = new Produit();
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Produitdesc.class.php");
|
|
$produitdesc = new Produitdesc();
|
|
$query = "SELECT tProd.ref Ref, tProdDesc.titre Titre, tProd.stock Stock, tCaracDispDesc.titre Alertstock, tCaracVal.valeur Alertstock2 FROM $produit->table tProd"
|
|
. " JOIN $produitdesc->table tProdDesc ON tProd.id=tProdDesc.produit AND tProdDesc.lang=1"
|
|
. " LEFT JOIN $caracval->table tCaracVal ON tProd.id=tCaracVal.produit AND tCaracVal.caracteristique=$caracteristique->valeur"
|
|
. " LEFT JOIN $caracdispdesc->table tCaracDispDesc ON tCaracVal.caracdisp=tCaracDispDesc.caracdisp";
|
|
$result = mysql_query($query, $produit->link);
|
|
while($row = mysql_fetch_assoc($result)){
|
|
$listeProduits[] = $row;
|
|
}
|
|
return $this->controleProduits($listeProduits);
|
|
}
|
|
}
|
|
?>
|