Correction gestion num commande fournisseur

This commit is contained in:
Laurent Destailleur 2006-11-07 23:39:29 +00:00
parent 3a47b0af19
commit 6597144a2e
7 changed files with 153 additions and 112 deletions

View File

@ -144,6 +144,50 @@ class Commande extends CommonObject
return $this->create($user); return $this->create($user);
} }
/**
* \brief Renvoie la référence de commande suivante non utilisée en fonction du module
* de numérotation actif défini dans COMMANDE_ADDON
* \param soc objet societe
* \return string reference libre pour la commande
*/
function getNextNumRef($soc)
{
global $db, $langs, $conf;
$langs->load("order");
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande/";
if (defined("COMMANDE_ADDON") && COMMANDE_ADDON)
{
$file = COMMANDE_ADDON.".php";
// Chargement de la classe de numérotation
$classname = $conf->global->COMMANDE_ADDON;
require_once($dir.$file);
$obj = new $classname();
$numref = "";
$numref = $obj->getNextValue($soc,$this);
if ( $numref != "")
{
return $numref;
}
else
{
dolibarr_print_error($db,"Commande::getNextNumRef ".$obj->error);
return "";
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined");
return "";
}
}
/** \brief Valide la commande /** \brief Valide la commande
* \param user Utilisateur qui valide * \param user Utilisateur qui valide
* \return int <=0 si ko, >0 si ok * \return int <=0 si ko, >0 si ok
@ -154,36 +198,21 @@ class Commande extends CommonObject
if ($user->rights->commande->valider) if ($user->rights->commande->valider)
{ {
if (defined('COMMANDE_ADDON'))
{
if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php'))
{
require_once DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php';
$this->db->begin(); $this->db->begin();
// Definition du nom de module de numerotation de commande // Definition du nom de module de numerotation de commande
// \todo Normer le nom des classes des modules de numérotation de ref de commande avec un nom du type NumRefCommandesXxxx
//
//$list=split('_',COMMANDE_ADDON);
//$numrefname=$list[2];
//$modName = 'NumRefCommandes'.ucfirst($numrefname);
$modName=$conf->global->COMMANDE_ADDON;
// Recuperation de la nouvelle reference
$objMod = new $modName($this->db);
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socid); $soc->fetch($this->socid);
$num=$this->getNextNumRef($soc);
// Classe la société rattachée comme client // Classe la société rattachée comme client
$result=$soc->set_as_client(); $result=$soc->set_as_client();
// on vérifie si la commande est en numérotation provisoire // on vérifie si la commande est en numérotation provisoire
$comref = substr($this->ref, 1, 4); $comref = substr($this->ref, 1, 4);
if ($comref == PROV) if ($comref == 'PROV')
{ {
$num = $objMod->commande_get_num($soc); $num = $this->getNextNumRef($soc);
} }
else else
{ {
@ -191,9 +220,10 @@ class Commande extends CommonObject
} }
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id"; $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0";
if ($this->db->query($sql) ) $resql=$this->db->query($sql);
if ($resql)
{ {
// On efface le répertoire de pdf provisoire // On efface le répertoire de pdf provisoire
$comref = sanitize_string($this->ref); $comref = sanitize_string($this->ref);
@ -239,18 +269,6 @@ class Commande extends CommonObject
return -1; return -1;
} }
} }
else
{
$this->error='Impossible de lire le module de numérotation';
return -1;
}
}
else
{
$this->error='Le module de numérotation n\'est pas défini';
return -1;
}
}
$this->error='Autorisation insuffisante'; $this->error='Autorisation insuffisante';
return -1; return -1;

View File

@ -22,19 +22,20 @@
*/ */
/** /**
\file htdocs/includes/modules/commande/mod_commande_muguet.php \file htdocs/four/commande/modules/mod_commande_fournisseur_muguet.php
\ingroup commande \ingroup commande
\brief Fichier contenant la classe du modèle de numérotation de référence de commande Muguet \brief Fichier contenant la classe du modèle de numérotation de référence de commande Muguet
\version $Revision$ \version $Revision$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/mod_commande_fournisseur_muguet.php");
/** \class mod_commande_marbre
/** \class mod_commande_fournisseur_muguet
\brief Classe du modèle de numérotation de référence de commande Marbre \brief Classe du modèle de numérotation de référence de commande Marbre
*/ */
class mod_commande_fournisseur_muguet extends ModeleNumRefCommandes class mod_commande_fournisseur_muguet extends ModeleNumRefCommandesSuppliers
{ {
var $prefix='CF'; var $prefix='CF';
var $error=''; var $error='';

View File

@ -135,6 +135,8 @@ class ModeleNumRefCommandesSuppliers
} }
} }
function commande_supplier_pdf_create($db, $comid, $modele='',$outputlangs='') function commande_supplier_pdf_create($db, $comid, $modele='',$outputlangs='')
{ {
global $langs; global $langs;

View File

@ -189,10 +189,24 @@ class CommandeFournisseur extends Commande
{ {
$this->db->begin(); $this->db->begin();
// Definition du nom de module de numerotation de commande
$soc = new Societe($this->db);
$soc->fetch($this->fourn_id);
$num=$this->getNextNumRef($soc); $num=$this->getNextNumRef($soc);
// on vérifie si la commande est en numérotation provisoire
$comref = substr($this->ref, 1, 4);
if ($comref == 'PROV')
{
$num = $this->getNextNumRef($soc);
}
else
{
$num = $this->ref;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id"; $sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -347,10 +361,25 @@ class CommandeFournisseur extends Commande
*/ */
function getNextNumRef($soc) function getNextNumRef($soc)
{ {
global $db, $langs; global $db, $langs, $conf;
$langs->load("orders"); $langs->load("orders");
$dir = DOL_DOCUMENT_ROOT .'/fourn/commande/modules'; $dir = DOL_DOCUMENT_ROOT .'/fourn/commande/modules';
$modelisok=0;
$liste=array();
// Positionne modele sur le nom du modele de commande à utiliser
$file = "pdf_".$modele.".modules.php";
if ($modele && file_exists($dir.$file)) $modelisok=1;
// Si model pas encore bon
if (! $modelisok)
{
if ($conf->global->COMMANDE_ADDON_PDF) $modele = $conf->global->COMMANDE_ADDON_PDF;
$file = "pdf_".$modele.".modules.php";
if (file_exists($dir.$file)) $modelisok=1;
}
if (defined('COMMANDE_SUPPLIER_ADDON')) if (defined('COMMANDE_SUPPLIER_ADDON'))
{ {

View File

@ -96,7 +96,7 @@ class mod_commande_marbre extends ModeleNumRefCommandes
/** \brief Renvoi prochaine valeur attribuée /** \brief Renvoi prochaine valeur attribuée
* \return string Valeur * \return string Valeur
*/ */
function getNextValue() function getNextValue($soc)
{ {
global $db; global $db;
@ -149,7 +149,7 @@ class mod_commande_marbre extends ModeleNumRefCommandes
*/ */
function commande_get_num($objsoc=0) function commande_get_num($objsoc=0)
{ {
return $this->getNextValue(); return $this->getNextValue($objsoc);
} }
} }

View File

@ -266,15 +266,6 @@ insert into llx_const (name, value, type, visible) values ('FICHEINTER_ADDON', '
alter table llx_propal_model_pdf rename to llx_document_model; alter table llx_propal_model_pdf rename to llx_document_model;
create table llx_document_model
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
nom varchar(50),
type varchar(20) NOT NULL,
libelle varchar(255),
description text
)type=innodb;
alter table llx_document_model DROP PRIMARY KEY; alter table llx_document_model DROP PRIMARY KEY;
alter table llx_document_model add column rowid integer AUTO_INCREMENT PRIMARY KEY FIRST; alter table llx_document_model add column rowid integer AUTO_INCREMENT PRIMARY KEY FIRST;
alter table llx_document_model add column type varchar(20) NOT NULL after nom; alter table llx_document_model add column type varchar(20) NOT NULL after nom;