260 lines
6.5 KiB
PHP
260 lines
6.5 KiB
PHP
|
<?php
|
||
|
if (!defined("LIBPRODUITS_INC")){
|
||
|
define(LIBPRODUITS_INC,1);
|
||
|
|
||
|
function getFamilleFromAcheteur($id){
|
||
|
$famille=-1;
|
||
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
if($connexion) {
|
||
|
$requete="SELECT reference_fam "
|
||
|
."FROM Famille_de_produit "
|
||
|
."WHERE id_acheteur='$id' "
|
||
|
."LIMIT 0,1";
|
||
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion);
|
||
|
if ($result){
|
||
|
$row=mysql_fetch_object($result);
|
||
|
$famille=$row->reference_fam;
|
||
|
} else {
|
||
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
||
|
}
|
||
|
mysql_close($connexion);
|
||
|
}else {
|
||
|
echo "<span class='error'>".mysql_error($connexion)."</span>";
|
||
|
}
|
||
|
return $famille;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* classe qui represente les produits internes
|
||
|
* avec le stock courant et les differents seuils
|
||
|
*/
|
||
|
class ProduitInterne {
|
||
|
var $_ref_in;
|
||
|
var $_stock;
|
||
|
var $_seuil_min;
|
||
|
var $_seuil_max;
|
||
|
var $_id_site;
|
||
|
|
||
|
function ProduitInterne($reference, $id_site) {
|
||
|
$this->_ref_in=$reference;
|
||
|
$this->_stock=0;
|
||
|
$this->_seuil_min=0;
|
||
|
$this->_seuil_max=0;
|
||
|
$this->_id_site=$id_site;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* fonction qui insere les infos d'un produit
|
||
|
* ds la BD lorsque celui-ci n'est pas connu
|
||
|
*/
|
||
|
function insereInfos(){
|
||
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
|
||
|
if(!$connexion) {
|
||
|
echo "<span class='error'>".mysql_error($connexion)."</span>";
|
||
|
}
|
||
|
|
||
|
$requete="INSERT INTO Stocker (id_site, "
|
||
|
."reference_interne, "
|
||
|
."stock, "
|
||
|
."seuil_min, "
|
||
|
."seuil_max) "
|
||
|
."VALUES ('".$this->_id_site."', "
|
||
|
."'".$this->_ref_in."', "
|
||
|
."'".$this->_stock."', "
|
||
|
."'".$this->_seuil_min."', "
|
||
|
."'".$this->_seuil_max."')";
|
||
|
|
||
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
||
|
or die(mysql_error($connexion));
|
||
|
|
||
|
mysql_close($connexion);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
* fonction qui insere les nouvelles valeurs
|
||
|
* des seuils et du stock ds la BD
|
||
|
*/
|
||
|
function modifSeuils(){
|
||
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
|
||
|
if(!$connexion) {
|
||
|
echo "Erreur serveur mysql $connexion";
|
||
|
}
|
||
|
|
||
|
$requete="UPDATE Stocker "
|
||
|
."SET stock='".$this->_stock."', "
|
||
|
."seuil_min='".$this->_seuil_min."', "
|
||
|
."seuil_max='".$this->_seuil_max."' "
|
||
|
."WHERE id_site='".$this->_id_site."' "
|
||
|
."AND reference_interne='".$this->_ref_in."' ";
|
||
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
||
|
or die(mysql_error($connexion));
|
||
|
mysql_close($connexion);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
* fonction qui permet l'effacement d'un produit de la table stocker
|
||
|
*/
|
||
|
function supprProStck(){
|
||
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
|
||
|
if(!$connexion) {
|
||
|
echo "Erreur serveur mysql $connexion";
|
||
|
}
|
||
|
|
||
|
$requete="DELETE FROM Stocker "
|
||
|
."WHERE reference_interne='".$this->_ref_in."' "
|
||
|
."AND id_site='".$this->_id_site."' ";
|
||
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
||
|
or die(mysql_error($connexion));
|
||
|
mysql_close($connexion);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
* fonction qui permet de savoir si le produit
|
||
|
* est deja insere dans la table Stocker
|
||
|
*/
|
||
|
function exists() {
|
||
|
// TODO: regarder dans la table Stocker si le produit y est
|
||
|
// si oui: return TRUE, else FALSE
|
||
|
$connexion=@mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
|
||
|
if(!$connexion) {
|
||
|
echo "Erreur serveur mysql $connexion";
|
||
|
}
|
||
|
|
||
|
$requete="SELECT reference_interne FROM Stocker "
|
||
|
."WHERE reference_interne='".$this->_ref_in."' "
|
||
|
."AND id_site='".$this->_id_site."' "
|
||
|
."LIMIT 0,1";
|
||
|
|
||
|
$result=mysql_db_query(SQL_BASE,$requete,$connexion);
|
||
|
|
||
|
$row=mysql_fetch_object($result);
|
||
|
|
||
|
mysql_close($connexion);
|
||
|
|
||
|
if($row) {
|
||
|
return 1;
|
||
|
}
|
||
|
else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
* fonction qui remplie l'objet produit avec les valeurs dans la base
|
||
|
* ou dans le cas d'un nouveau produit les initialisent a zero
|
||
|
*/
|
||
|
function rempliVals() {
|
||
|
if($this->exists()) {
|
||
|
$connexion=@mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
||
|
|
||
|
if(!$connexion) {
|
||
|
echo "Erreur serveur mysql $connexion";
|
||
|
}
|
||
|
|
||
|
$requete="SELECT stock, seuil_min, seuil_max FROM Stocker "
|
||
|
."WHERE reference_interne='".$this->_ref_in."' "
|
||
|
."AND id_site='".$this->_id_site."' "
|
||
|
."LIMIT 0,1";
|
||
|
|
||
|
$result=mysql_db_query(SQL_BASE,$requete,$connexion);
|
||
|
|
||
|
$row=mysql_fetch_object($result);
|
||
|
|
||
|
// on rempli les champs avec les resultats de la requete
|
||
|
$this->_stock=$row->stock;
|
||
|
$this->_seuil_min=$row->seuil_min;
|
||
|
$this->_seuil_max=$row->seuil_max;
|
||
|
|
||
|
mysql_close($connexion);
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
$this->_stock=0;
|
||
|
$this->_seuil_min=0;
|
||
|
$this->_seuil_max=0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function toHTML(){
|
||
|
$content.="<fieldset>";
|
||
|
$content.="<legend>\n";
|
||
|
$content.="Modifier les informations du produit ".$this->_ref_in."</legend>\n";
|
||
|
$content.="<p>\n";
|
||
|
$content.="Stock ";
|
||
|
$content.="<input type=\"text\" name=\"stock\" value=\"".$this->_stock."\" />";
|
||
|
$content.="</p>\n";
|
||
|
$content.="<p>\n";
|
||
|
$content.="Seuil minimum ";
|
||
|
$content.="<input type=\"text\" name=\"seuil_min\" value=\"".$this->_seuil_min."\" />";
|
||
|
$content.="</p>\n";
|
||
|
$content.="<p>\n";
|
||
|
$content.="Seuil maximum ";
|
||
|
$content.="<input type=\"text\" name=\"seuil_max\" value=\"".$this->_seuil_max."\" />";
|
||
|
$content.="</p>\n";
|
||
|
$content.="<br />";
|
||
|
$content.="</fieldset>";
|
||
|
$content.="<br />";
|
||
|
$content.="<p>";
|
||
|
$content.="<input type=\"submit\" name=\"action\" value=\"Supprimer\" />";
|
||
|
$content.="<input type=\"submit\" name=\"action\" value=\"Accepter\" />";
|
||
|
$content.="</p>";
|
||
|
$content.="<br />";
|
||
|
|
||
|
return $content;
|
||
|
}
|
||
|
|
||
|
}// FIN classe ProduitInterne
|
||
|
|
||
|
class ProduitFournisseur {
|
||
|
var $_ref_fo;
|
||
|
var $_desig;
|
||
|
var $_prix;
|
||
|
var $_unite;
|
||
|
var $_id_fo;
|
||
|
var $_ref_in;
|
||
|
|
||
|
function ProduitFournisseur(
|
||
|
$ref_fo,
|
||
|
$desig,
|
||
|
$prix,
|
||
|
$unite,
|
||
|
$id_fo,
|
||
|
$ref_in){
|
||
|
$this->_ref_fo=$ref_fo;
|
||
|
$this->_desig=$desig;
|
||
|
$this->_prix=$prix;
|
||
|
$this->_unite=$unite;
|
||
|
$this->_id_fo=$id_fo;
|
||
|
$this->_ref_in=$ref_in;
|
||
|
}
|
||
|
function toHTML($editable=0){
|
||
|
$content="";
|
||
|
if ($editable){
|
||
|
$content.="<input type=\"checkbox\" "
|
||
|
."name=\"prod_id[]\" id=\"prod_id[]\" "
|
||
|
."value=\"".$this->_ref_fo."\" />\n";
|
||
|
}
|
||
|
$content.="<span class=\"refFo\" >".$this->_ref_fo."</span> \n";
|
||
|
$content.="<span class=\"desig\" >".$this->_desig."</span> \n";
|
||
|
$content.="<span class=\"prix\" >".$this->_prix."</span> \n";
|
||
|
$content.="<span class=\"unite\" >".$this->_unite."</span> \n";
|
||
|
$content.="<span class=\"idFo\" >".$this->_id_fo."</span> \n";
|
||
|
$content.="<span class=\"refIn\" >".$this->_ref_in."</span > \n";
|
||
|
return $content;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
?>
|