Files
le-matelot/client/plugins/mventes/Mventes.class.php
2020-01-27 08:56:08 +01:00

107 lines
2.5 KiB
PHP

<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Venteprod.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Commande.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Produit.class.php");
class Mventes extends PluginsClassiques{
var $id;
var $ref;
var $nb_ventes;
var $table="mventes";
var $bddvars = array("id", "ref", "nb_ventes");
function Mventes(){
$this->Baseobj();
}
function charger($ref){
return $this->getVars("select * from $this->table where ref=\"$ref\"");
}
function init(){
$cnx = new Cnx();
$query_mventes = "CREATE TABLE IF NOT EXISTS `mventes` (
`id` int(11) NOT NULL auto_increment,
`ref` text NOT NULL,
`nb_ventes` int(11) NOT NULL,
PRIMARY KEY (`id`)
) AUTO_INCREMENT=1 ;
";
$resul_mventes = mysql_query($query_mventes, $cnx->link);
}
function boucle($texte, $args){
// récupération des arguments
$num = lireTag($args, "num");
$classement = lireTag($args, "classement");
$exclusion = lireTag($args, "exclusion");
$search ="";
$res="";
if($classement == "inverse")
$ordre = "ASC";
else $ordre = "DESC";
if($exclusion != "")
$search .= " and ref not in($exclusion)";
$query_mventes = "select * from $this->table where ref<>'' $search order by nb_ventes $ordre limit 0,$num ";
$resul_mventes = mysql_query($query_mventes, $this->link);
if(! mysql_num_rows($resul_mventes))
return "";
while( $row = mysql_fetch_object($resul_mventes)){
$temp = str_replace("#ID", "$row->id", $texte);
$temp = str_replace("#REF", "$row->ref", $temp);
$temp = str_replace("#NB", "$row->nb_ventes", $temp);
$res .= $temp;
}
return $res;
}
function statut($commande){
if($commande->statut != 2){
$venteprod = new Venteprod();
$query = "select * from $venteprod->table where commande=" . $commande->id;
$resul = mysql_query($query, $venteprod->link);
while($row = mysql_fetch_object($resul)){
if($this->charger($row->ref)){
$this->nb_ventes += $row->quantite;
$this->maj();
} else {
$this->ref = $row->ref;
$this->nb_ventes = 1;
$this->add();
}
}
}
}
function confirmation($commande){
$this->statut($commande);
}
}
?>