Debut debuggage fonction commandes fournisseurs

This commit is contained in:
Laurent Destailleur 2005-10-10 19:48:22 +00:00
parent 7b61f28c59
commit f2d42cce82
4 changed files with 298 additions and 249 deletions

View File

@ -29,19 +29,21 @@
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
// Sécurité accés client // Sécurité accés client
$socidp=0;
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socidp = $user->societe_id; $socidp = $user->societe_id;
} }
/* /*
* *
*/ */
@ -79,7 +81,7 @@ if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->cree
if ($_POST["p_idprod"] > 0) if ($_POST["p_idprod"] > 0)
{ {
$result = $comf->addline("DESC", $result = $comf->addline($_POST["desc"],
$_POST["pu"], $_POST["pu"],
$_POST["pqty"], $_POST["pqty"],
$_POST["tva_tx"], $_POST["tva_tx"],
@ -96,6 +98,7 @@ if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->cree
$_POST["remise_percent"]); $_POST["remise_percent"]);
} }
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer)
@ -122,7 +125,7 @@ if ($_GET["action"] == 'deleteline' && $user->rights->fournisseur->commande->cre
$result = $comf->delete_line($_GET["lineid"]); $result = $comf->delete_line($_GET["lineid"]);
} }
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->valider) if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->valider)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
@ -130,17 +133,19 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->ri
$soc->fetch($commande->soc_id); $soc->fetch($commande->soc_id);
$result = $commande->valid($user); $result = $commande->valid($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->approve($user); $result = $commande->approve($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
@ -148,21 +153,23 @@ if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->r
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
} }
if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->commander) if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]); $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->creer ) if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->creer )
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->id = $_GET["id"]; $commande->id = $_GET["id"];
$commande->delete(); $commande->delete();
Header("Location: index.php"); Header("Location: index.php");
exit;
} }
if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
@ -174,6 +181,7 @@ if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->rec
$result = $commande->Livraison($user, $date_liv, $_POST["type"]); $result = $commande->Livraison($user, $date_liv, $_POST["type"]);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
@ -183,6 +191,7 @@ if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->r
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->cancel($user); $result = $commande->cancel($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
/* /*
@ -194,10 +203,16 @@ if ($_GET["action"] == 'create')
$fourn = new Fournisseur($db); $fourn = new Fournisseur($db);
$fourn->fetch($_GET["socid"]); $fourn->fetch($_GET["socid"]);
if ($fourn->create_commande($user) == 0) if ($fourn->create_commande($user) > 0)
{ {
$idc = $fourn->single_open_commande; $idc = $fourn->single_open_commande;
Header("Location:fiche.php?id=".$idc); Header("Location:fiche.php?id=".$idc);
exit;
}
else
{
$mesg=$fourn->error;
print "x $mesg x";
} }
} }
@ -305,7 +320,8 @@ if ($_GET["id"] > 0)
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Supplier")."</td>"; print '<tr><td width="20%">'.$langs->trans("Supplier")."</td>";
print '<td colspan="5">'; print '<td colspan="5">';
print '<b><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>'; print '<b><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$soc->id.'">';
print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'</a></b></td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
@ -387,7 +403,7 @@ if ($_GET["id"] > 0)
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td>".$objp->ref."</td>\n"; print '<td><a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</td>';
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
print '<td>'; print '<td>';
@ -465,7 +481,7 @@ if ($_GET["id"] > 0)
$html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre); $html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre);
print '</td>'; print '</td>';
print '<td align="center"><input type="text" size="2" name="pqty" value="1"></td>'; print '<td align="center"><input type="text" size="2" name="pqty" value="1"></td>';
print '<td align="right"><input type="text" size="4" name="premise" value="0"> %</td>'; print '<td align="right"><input type="text" size="3" name="premise" value="0">%</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>'; print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
print "</tr>\n"; print "</tr>\n";
@ -476,7 +492,7 @@ if ($_GET["id"] > 0)
print "</table>"; print "</table>";
print '</div>'; print '</div>';
/* /**
* Boutons actions * Boutons actions
*/ */
if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid') if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid')

View File

@ -104,26 +104,26 @@ if ($_GET["id"] > 0)
print "</td></tr>"; print "</td></tr>";
} }
// Auteur
print '<tr><td>'.$langs->trans("Author").'</td><td colspan="2">'.$author->fullname.'</td>';
print '<td width="50%">&nbsp;</td></tr>';
print "</table>\n"; print "</table>\n";
print "<br>";
/* /*
* Historique * Suivi historique
* * Date - Statut - Auteur
*/ */
echo '<br><table class="border" width="100%">'; print '<table class="noborder" width="100%">';
$sql = "SELECT l.fk_statut, ".$db->pdate("l.datelog") ."as dl, u.firstname, u.name"; print '<tr class="liste_titre"><td>'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("Status").'</td><td>'.$langs->trans("Author").'</td>';
print '</tr>';
$sql = "SELECT l.fk_statut, ".$db->pdate("l.datelog") ."as dl, u.rowid, u.code, u.firstname, u.name";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_log as l "; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_log as l ";
$sql .= " , ".MAIN_DB_PREFIX."user as u "; $sql .= " , ".MAIN_DB_PREFIX."user as u ";
$sql .= " WHERE l.fk_commande = ".$commande->id." AND u.rowid = l.fk_user"; $sql .= " WHERE l.fk_commande = ".$commande->id." AND u.rowid = l.fk_user";
$sql .= " ORDER BY l.rowid DESC"; $sql .= " ORDER BY l.rowid DESC";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
@ -132,22 +132,22 @@ if ($_GET["id"] > 0)
$var=True; $var=True;
while ($i < $num) while ($i < $num)
{ {
$var=!$var;
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td width="20%">'.dolibarr_print_date($obj->dl,"%a %d %b %Y %H:%M:%S")."</td>\n"; print '<td width="20%">'.dolibarr_print_date($obj->dl,"%a %d %b %Y %H:%M:%S")."</td>\n";
print '<td width="10%"><img src="statut'.$obj->fk_statut.'.png">&nbsp;'; print '<td width="100px"><img src="statut'.$obj->fk_statut.'.png">&nbsp;';
print $commande->statuts[$obj->fk_statut]."</td>\n"; print $commande->statuts[$obj->fk_statut]."</td>\n";
print '<td width="70%">'.$obj->firstname. " " . $obj->name.'</td>'; print '<td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->rowid.'">';
print img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'</td>';
print "</tr>"; print '</tr>';
$i++; $i++;
$var=!$var;
} }
$db->free($resql); $db->free($resql);
} }
@ -155,8 +155,8 @@ if ($_GET["id"] > 0)
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
} }
print "</table>"; print "</table>";
print '</div>'; print '</div>';
} }
else else

View File

@ -103,29 +103,32 @@ class Fournisseur extends Societe {
} }
/**
* \brief Créé la commande au statut brouillon
* \param user Utilisateur qui crée
* \return int <0 si ko, id de la commande créée si ok
*/
function create_commande($user) function create_commande($user)
{ {
$result = -1;
dolibarr_syslog("Fournisseur::Create_Commande"); dolibarr_syslog("Fournisseur::Create_Commande");
$comm = new CommandeFournisseur($this->db); $comm = new CommandeFournisseur($this->db);
$comm->soc_id = $this->id; $comm->soc_id = $this->id;
if ( $comm->create($user) == 0 ) if ($comm->create($user) > 0)
{ {
dolibarr_syslog("Fournisseur::Create_Commande : Success"); dolibarr_syslog("Fournisseur::Create_Commande : Success");
$this->single_open_commande = $comm->id; $this->single_open_commande = $comm->id;
$result = 0; return $comm->id;
} }
else else
{ {
dolibarr_syslog("Fournisseur::Create_Commande : Failed"); dolibarr_syslog("Fournisseur::Create_Commande : Failed");
$result = -2; return -1;
}
} }
return $result;
}
function ProductCommande($user, $product_id) function ProductCommande($user, $product_id)
{ {

View File

@ -123,9 +123,13 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
return $result ; return $result ;
} }
/** /**
* Log * \brief Insère ligne de log
* * \param user Utilisateur qui modifie la commande
* \param statut Statut de la commande
* \param datelog Date de modification
* \return int <0 si ko, >0 si ok
*/ */
function log($user, $statut, $datelog) function log($user, $statut, $datelog)
{ {
@ -134,9 +138,14 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
return 0; return 1;
}
else
{
return -1;
} }
} }
/** /**
* Valide la commande * Valide la commande
* *
@ -395,14 +404,18 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
} }
return $result ; return $result ;
} }
/** /**
* Créé la commande * \brief Créé la commande au statut brouillon
* * \param user Utilisateur qui crée
* \return int <0 si ko, >0 si ok
*/ */
function create($user) function create($user)
{ {
dolibarr_syslog("CommandeFournisseur::Create");
dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id); dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id);
$this->db->begin();
/* On positionne en mode brouillon la commande */ /* On positionne en mode brouillon la commande */
$this->brouillon = 1; $this->brouillon = 1;
@ -413,42 +426,57 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET ref='(PROV".$this->id.")'";
$sql.= " WHERE rowid=".$this->id;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// On logue creation pour historique
$this->log($user, 0, time());
/*
*
*
*/
dolibarr_syslog("CommandeFournisseur::Create : Success"); dolibarr_syslog("CommandeFournisseur::Create : Success");
return 0; $this->db->commit();
return 1;
} }
else else
{ {
dolibarr_syslog("CommandeFournisseur::Create : Failed 2"); $this->error=$this->db->error()." - ".$sql;
dolibarr_syslog("CommandeFournisseur::Create: Failed -2 - ".$this->error);
$this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
dolibarr_syslog("CommandeFournisseur::Create : Failed 1"); $this->error=$this->db->error()." - ".$sql;
dolibarr_syslog("CommandeFournisseur::Create : ".$this->db->error()); dolibarr_syslog("CommandeFournisseur::Create: Failed -1 - ".$this->error);
dolibarr_syslog("CommandeFournisseur::Create : ".$sql); $this->db->rollback();
return -1; return -1;
} }
} }
/** /**
* Ajoute une ligne de commande * \brief Ajoute une ligne de commande
* * \param desc Description
* \param pu Prix unitaire
* \param qty Quantité
* \param txtva Taux tva
* \param fk_product Id produit
* \param remise_percent Remise
* \param int <0 si ko, >0 si ok
*/ */
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{ {
$qty = ereg_replace(",",".",$qty); $qty = ereg_replace(",",".",$qty);
$pu = ereg_replace(",",".",$pu); $pu = ereg_replace(",",".",$pu);
$desc=trim($desc);
if ($this->brouillon && strlen(trim($desc))) dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
if ($this->brouillon)
{ {
$this->db->begin();
if (strlen(trim($qty))==0) if (strlen(trim($qty))==0)
{ {
$qty=1; $qty=1;
@ -459,12 +487,12 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
$prod = new Product($this->db, $fk_product); $prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0) if ($prod->fetch($fk_product) > 0)
{ {
$desc = $prod->libelle;
$txtva = $prod->tva_tx;
$prod->get_buyprice($this->fourn_id,$qty); $prod->get_buyprice($this->fourn_id,$qty);
$desc = $prod->libelle;
$txtva = $prod->tva_tx;
$pu = $prod->buyprice/$qty; $pu = $prod->buyprice/$qty;
$ref = $prod->ref;
} }
} }
@ -483,11 +511,13 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
{ {
$this->update_price(); $this->update_price();
return 0;
$this->db->commit();
return 1;
} }
else else
{ {
$this->db->rollback();
return -1; return -1;
} }
} }