340 lines
11 KiB
PHP
340 lines
11 KiB
PHP
<?php
|
|
if (!defined("LIBCOMMANDES_INC")){
|
|
define(LIBCOMMANDES_INC,1);
|
|
|
|
class LigneCommande {
|
|
var $_prod_in;
|
|
var $_prod_four;
|
|
var $_LDAtab; //Liste Demande Achat
|
|
var $_LLDAtab;
|
|
var $_prix;
|
|
|
|
function LigneCommande($refprod,&$LDAtab,$ref_fourn){
|
|
$this->_prod_in=$refprod;
|
|
$this->_prod_four=$ref_fourn;
|
|
$this->_LDAtab=$LDAtab;
|
|
$this->getLLDA();
|
|
}
|
|
|
|
function getLLDA(){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if ($connexion){
|
|
$this->_LLDAtab=array();
|
|
for ($i=0;$i<count($this->_LDAtab);$i++){
|
|
$numDA=$this->_LDAtab[$i];
|
|
$requete="SELECT LDA.numero_lda AS num_lda "
|
|
."FROM Ligne_d_achat AS LDA, Etats_LA AS ELA "
|
|
."WHERE LDA.numero_lda=ELA.numero_LDA "
|
|
."AND Libelle='CREE' "
|
|
."AND numero_da='$numDA' "
|
|
."AND reference_interne='".$this->_prod_in."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion);
|
|
if ($resultat){
|
|
$row=mysql_fetch_object($resultat);
|
|
array_push($this->_LLDAtab,$row->num_lda);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
} // for
|
|
mysql_close($connexion);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
}
|
|
|
|
function save($uid){
|
|
$this->getLLDA();
|
|
//TODO : auto-increment
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if ($connexion){
|
|
$requete="INSERT INTO Ligne_de_commande "
|
|
."(numero_com,reference_fournisseur,quantite) "
|
|
."VALUES ('-$uid','".$this->_prod_four."','".$this->getQte()."')";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die(mysql_error($connexion));
|
|
$numero_ldc=mysql_insert_id();
|
|
|
|
// updater l'état des lda
|
|
|
|
for ($i=0;$i<count($this->_LLDAtab);$i++){
|
|
$requete="UPDATE Etats_LA "
|
|
."SET numero_ldc='$numero_ldc',Libelle='COMM' "
|
|
."WHERE numero_lda='".$this->_LLDAtab[$i]."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die(mysql_error($connexion));
|
|
}
|
|
mysql_close($connexion);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
}
|
|
|
|
function getQte(){
|
|
//TODO:
|
|
// fait la somme des quantités des LDA
|
|
}
|
|
function getPrix(){
|
|
//TODO:
|
|
// qua
|
|
}
|
|
|
|
function toHTML(){
|
|
$content="";
|
|
$content.=$this->_prod_in;
|
|
$content.=" - ";
|
|
$content.=$this->_prod_four;
|
|
return $content;
|
|
}
|
|
}
|
|
|
|
class Commande {
|
|
var $_lignes;
|
|
var $_userID;
|
|
|
|
function Commande($userId){
|
|
$this->_userID=$userId;
|
|
}
|
|
|
|
function valideLC(){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if (!$connexion){
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
// 1 .faire la liste des fournisseurs chez
|
|
// qui des commandes sont en attente
|
|
$requete="SELECT id_fournisseur "
|
|
."FROM Ligne_de_commande AS LDC, ProduitFour AS PF "
|
|
."WHERE LDC.reference_fournisseur=PF.reference_fournisseur "
|
|
."AND numero_com='-".$this->_userID."' "
|
|
."GROUP BY id_fournisseur";
|
|
$resultatf=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
// 2 .pour chaque fournisseur :
|
|
while($fournisseur=mysql_fetch_object($resultatf)){
|
|
// - créer une nouvelle commande
|
|
$date = date("Y")."-".date("m")."-".date("d");
|
|
$requete="INSERT INTO Commande "
|
|
."(date,id_acheteur,id_fournisseur) "
|
|
."VALUES ('$date',"
|
|
."'".$this->_userID."',"
|
|
."'".$fournisseur->id_fournisseur."')";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
$cmd_id=mysql_insert_id($connexion);
|
|
print ("<span class='error'>Id commande : $cmd_id</span>");
|
|
// - associer les lignes de commandes à la commande
|
|
// ( changer l'etat )
|
|
$requete="UPDATE Ligne_de_commande "
|
|
."SET numero_com='$cmd_id' "
|
|
."WHERE numero_com='-".$this->_userID."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
}
|
|
mysql_close($connexion);
|
|
}
|
|
|
|
function supprimeLC($Cases_supp){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if (!$connexion){
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
if (!is_array($Cases_supp)){
|
|
die ("$Cases_supp must be an array !");
|
|
}
|
|
$LDCtab=array();
|
|
while( list($case,$val) = each($Cases_supp) ){
|
|
// on supprime les lignes selectionnees
|
|
$LDCtab[]=$val;
|
|
}
|
|
|
|
for ($i=0;$i<count($LDCtab);$i++){
|
|
//restaure l'état des lignes demande achat
|
|
$requete="UPDATE Etats_LA "
|
|
."SET numero_ldc=NULL,Libelle='CREE' "
|
|
."WHERE numero_ldc='".$LDCtab[$i]."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
|
|
//supprime la ligne de commande
|
|
$requete="DELETE FROM Ligne_de_commande "
|
|
."WHERE numero_ldc='".$LDCtab[$i]."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
}
|
|
|
|
mysql_close($connexion);
|
|
}
|
|
|
|
function ajouteLC($refprod,&$LDAtab,$ref_fourn){
|
|
$ligneCom=new LigneCommande($refprod,$LDAtab,$ref_fourn);
|
|
$ligneCom->save($this->_userID);
|
|
}
|
|
|
|
|
|
function toHTML(){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if (!$connexion){
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
// on récupere les lignes d'achats en cours
|
|
$requete="SELECT numero_ldc,reference_fournisseur "
|
|
."FROM Ligne_de_commande AS LDC "
|
|
."WHERE LDC.numero_com='-".$this->_userID."'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
$LDCtab=array();
|
|
$LDCInfoTab=array();
|
|
while ($row=mysql_fetch_object($resultat)){
|
|
array_push($LDCtab,$row->numero_ldc);
|
|
array_push($LDCInfoTab,$row->reference_fournisseur);
|
|
}
|
|
|
|
$content="";
|
|
for ($i=0;$i<count($LDCtab);$i++){
|
|
$content.="<dl class=\"ligne".($i%2)."\" >";
|
|
$content.="<dt><input type=\"checkbox\" "
|
|
."name=\"ligneCom[]\" id=\"ligneCom[]\" "
|
|
."value=\"".$LDCtab[$i]."\" />";
|
|
$content.="LDC°".$LDCtab[$i]." - ";
|
|
$content.="Ref fournisseur: ".$LDCInfoTab[$i];
|
|
$content.="</dt>";
|
|
$requete="SELECT numero_da,LDA.reference_interne,"
|
|
."PI.designation,PI.unite,quantite "
|
|
."FROM Etats_LA AS ELA, Ligne_d_achat as LDA, "
|
|
."Produit_Interne AS PI "
|
|
."WHERE numero_ldc='".$LDCtab[$i]."' "
|
|
."AND LDA.reference_interne=PI.reference_interne "
|
|
."AND ELA.numero_lda=LDA.numero_lda";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete,$connexion) or
|
|
die ("<span class='error'>".mysql_error($connexion)."</span>");
|
|
while($row=mysql_fetch_object($resultat)){
|
|
$content.="<dd>\n";
|
|
$content.="<span class='id_da'>DA°".$row->numero_da."</span> - \n";
|
|
$content.="<span class='ref_in'>".$row->reference_interne."</span> : \n";
|
|
$content.="<span class='designation'>".$row->designation."</span> - \n";
|
|
$content.="<span class='quantite'>Qté: ".$row->quantite."</span> \n";
|
|
$content.="<span class='unite'>(".$row->unite.")</span> \n";
|
|
$content.="</dd>\n";
|
|
}
|
|
$content.="</dl>";
|
|
}
|
|
$content.="<br />";
|
|
$content.="<input type=\"submit\" name=\"action\" id=\"action\" "
|
|
." value=\"Supprimer\" />";
|
|
mysql_close($connexion);
|
|
return $content;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class CmdTool {
|
|
var $_famille;
|
|
var $_ref_in;
|
|
var $_lda;
|
|
|
|
function CmdTool($famille){
|
|
$this->_famille=$famille;
|
|
}
|
|
|
|
function FournToHTML($ref){
|
|
$content="";
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if ($connexion){
|
|
$requete="SELECT nom,F.id_fournisseur as idf,reference_fournisseur,prix,unite "
|
|
."FROM ProduitFour AS PF,Fournisseur as F "
|
|
."WHERE PF.id_fournisseur=F.id_fournisseur "
|
|
."AND reference_interne='$ref'";
|
|
$result=mysql_db_query(SQL_BASE,$requete,$connexion);
|
|
if ($result){
|
|
$content.="<select name=\"fourn_$ref\" id=\"fourn_$ref\" "
|
|
.">\n";
|
|
while($row=mysql_fetch_object($result)){
|
|
$content.="<option value=\"".$row->reference_fournisseur."\">\n";
|
|
$content.=$row->nom." - ";
|
|
$content.="Ref. ".$row->reference_fournisseur;
|
|
$content.=" - ".$row->prix." € / ".$row->unite;
|
|
$content.="</option>\n";
|
|
}
|
|
$content.="</select>\n";
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
mysql_close($connexion);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
return $content;
|
|
|
|
}
|
|
|
|
function LDAtoHTML($ref){
|
|
$content="";
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if ($connexion){
|
|
$requete="SELECT numero_da, LDA.numero_lda, quantite, Date "
|
|
."FROM Ligne_d_achat AS LDA , Etats_LA AS ELA "
|
|
."WHERE LDA.numero_lda=ELA.numero_lda "
|
|
."AND Libelle='CREE' "
|
|
."AND reference_interne='$ref'";
|
|
$result=mysql_db_query(SQL_BASE,$requete,$connexion);
|
|
if ($result){
|
|
$content.="<select name=\"da_".$ref."[]\" id=\"da_".$ref."[]\" "
|
|
."multiple=\"multiple\" >\n";
|
|
while($row=mysql_fetch_object($result)){
|
|
$content.="<option value=\"".$row->numero_da."\">\n";
|
|
$content.="Le ".$row->Date;
|
|
$content.=", DA°".$row->numero_da." - ";
|
|
$content.="Qté : ".$row->quantite;
|
|
$content.="</option>\n";
|
|
}
|
|
$content.="</select>\n";
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
mysql_close($connexion);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
function ReftoHTML(){
|
|
$content="";
|
|
for ($i=0;$i<count($this->_ref_in);$i++){
|
|
if ($i==0){
|
|
$content.="<option value=\"".$this->_ref_in[$i]."\">(Selectionner une reference)</option>\n";
|
|
}
|
|
$content.="<option>".$this->_ref_in[$i]."</option>\n";
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
|
|
function chargeRef(){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if ($connexion){
|
|
$requete="SELECT LDA.reference_interne AS ref_in "
|
|
."FROM Ligne_d_achat AS LDA, Etats_LA as ELA, Produit_Interne as PI "
|
|
."WHERE LDA.numero_lda=ELA.numero_lda "
|
|
."AND LDA.reference_interne=PI.reference_interne "
|
|
."AND Libelle='CREE' "
|
|
."AND reference_fam='".$this->_famille."' "
|
|
."GROUP BY LDA.reference_interne";
|
|
$result=mysql_db_query(SQL_BASE,$requete,$connexion);
|
|
if ($result){
|
|
$this->_ref_in=array();
|
|
while($row=mysql_fetch_object($result)){
|
|
array_push($this->_ref_in,$row->ref_in);
|
|
}
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
mysql_close($connexion);
|
|
} else {
|
|
print "<span class='error'>".mysql_error($connexion)."</span>";
|
|
}
|
|
} //function
|
|
} // class
|
|
}
|
|
?>
|