diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 3aa90758f50..c70b5bc25d0 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -144,6 +144,50 @@ class Commande extends CommonObject 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 * \param user Utilisateur qui valide * \return int <=0 si ko, >0 si ok @@ -154,100 +198,74 @@ class Commande extends CommonObject 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(); - - // 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->fetch($this->socid); - - // Classe la société rattachée comme client - $result=$soc->set_as_client(); - - // on vérifie si la commande est en numérotation provisoire - $comref = substr($this->ref, 1, 4); - if ($comref == PROV) - { - $num = $objMod->commande_get_num($soc); - } - else - { - $num = $this->ref; - } - - $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 ;"; - - if ($this->db->query($sql) ) - { - // On efface le répertoire de pdf provisoire - $comref = sanitize_string($this->ref); - if ($conf->commande->dir_output) - { - $dir = $conf->commande->dir_output . "/" . $comref ; - $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; - if (file_exists($file)) - { - commande_delete_preview($this->db, $this->id, $this->ref); - - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - $this->db->rollback(); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - $this->db->rollback(); - return 0; - } - } - } - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_VALIDATE',$this,$user,$langs,$conf); - // Fin appel triggers + $this->db->begin(); + + // Definition du nom de module de numerotation de commande + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $num=$this->getNextNumRef($soc); - $this->db->commit(); - return $this->id; - } - else - { - $this->db->rollback(); - $this->error=$this->db->error(); - return -1; - } - } - else - { - $this->error='Impossible de lire le module de numérotation'; - return -1; - } + // Classe la société rattachée comme client + $result=$soc->set_as_client(); + + // 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 { - $this->error='Le module de numérotation n\'est pas défini'; + $num = $this->ref; + } + + $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"; + + $resql=$this->db->query($sql); + if ($resql) + { + // On efface le répertoire de pdf provisoire + $comref = sanitize_string($this->ref); + if ($conf->commande->dir_output) + { + $dir = $conf->commande->dir_output . "/" . $comref ; + $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; + if (file_exists($file)) + { + commande_delete_preview($this->db, $this->id, $this->ref); + + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + $this->db->rollback(); + return 0; + } + } + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_VALIDATE',$this,$user,$langs,$conf); + // Fin appel triggers + + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + $this->error=$this->db->error(); return -1; } } diff --git a/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php b/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php index fe91300eea3..faf20401744 100644 --- a/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php +++ b/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php @@ -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 \brief Fichier contenant la classe du modèle de numérotation de référence de commande Muguet \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 */ -class mod_commande_fournisseur_muguet extends ModeleNumRefCommandes +class mod_commande_fournisseur_muguet extends ModeleNumRefCommandesSuppliers { var $prefix='CF'; var $error=''; diff --git a/htdocs/fourn/commande/modules/modules_commandefournisseur.php b/htdocs/fourn/commande/modules/modules_commandefournisseur.php index 984350a7de1..0a2480388bf 100644 --- a/htdocs/fourn/commande/modules/modules_commandefournisseur.php +++ b/htdocs/fourn/commande/modules/modules_commandefournisseur.php @@ -135,6 +135,8 @@ class ModeleNumRefCommandesSuppliers } } + + function commande_supplier_pdf_create($db, $comid, $modele='',$outputlangs='') { global $langs; diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index bdef11361e7..200f0e590ee 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -189,10 +189,24 @@ class CommandeFournisseur extends Commande { $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); + // 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 .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; + $sql .= " WHERE rowid = $this->id AND fk_statut = 0"; $resql=$this->db->query($sql); if ($resql) @@ -347,10 +361,25 @@ class CommandeFournisseur extends Commande */ function getNextNumRef($soc) { - global $db, $langs; + global $db, $langs, $conf; $langs->load("orders"); $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')) { diff --git a/htdocs/includes/modules/commande/mod_commande_marbre.php b/htdocs/includes/modules/commande/mod_commande_marbre.php index 2b35d982e91..381a5bb8b1d 100644 --- a/htdocs/includes/modules/commande/mod_commande_marbre.php +++ b/htdocs/includes/modules/commande/mod_commande_marbre.php @@ -96,7 +96,7 @@ class mod_commande_marbre extends ModeleNumRefCommandes /** \brief Renvoi prochaine valeur attribuée * \return string Valeur */ - function getNextValue() + function getNextValue($soc) { global $db; @@ -149,7 +149,7 @@ class mod_commande_marbre extends ModeleNumRefCommandes */ function commande_get_num($objsoc=0) { - return $this->getNextValue(); + return $this->getNextValue($objsoc); } } diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index 6f842086d87..285b0d26283 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -25,11 +25,11 @@ */ /** - \file htdocs/includes/modules/commande/modules_commande.php - \ingroup commande - \brief Fichier contenant la classe mère de generation des commandes en PDF - et la classe mère de numérotation des commandes - \version $Revision$ + \file htdocs/includes/modules/commande/modules_commande.php + \ingroup commande + \brief Fichier contenant la classe mère de generation des commandes en PDF + et la classe mère de numérotation des commandes + \version $Revision$ */ require_once(FPDF_PATH.'fpdf.php'); diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 458e637ee92..967a0854310 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -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; -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 add column rowid integer AUTO_INCREMENT PRIMARY KEY FIRST; alter table llx_document_model add column type varchar(20) NOT NULL after nom;