Correction gestion num commande fournisseur
This commit is contained in:
parent
3a47b0af19
commit
6597144a2e
@ -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,100 +198,74 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
if ($user->rights->commande->valider)
|
if ($user->rights->commande->valider)
|
||||||
{
|
{
|
||||||
if (defined('COMMANDE_ADDON'))
|
$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);
|
||||||
|
|
||||||
|
// 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')
|
||||||
{
|
{
|
||||||
if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php'))
|
$num = $this->getNextNumRef($soc);
|
||||||
{
|
|
||||||
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->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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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='';
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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'))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,11 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/includes/modules/commande/modules_commande.php
|
\file htdocs/includes/modules/commande/modules_commande.php
|
||||||
\ingroup commande
|
\ingroup commande
|
||||||
\brief Fichier contenant la classe mère de generation des commandes en PDF
|
\brief Fichier contenant la classe mère de generation des commandes en PDF
|
||||||
et la classe mère de numérotation des commandes
|
et la classe mère de numérotation des commandes
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(FPDF_PATH.'fpdf.php');
|
require_once(FPDF_PATH.'fpdf.php');
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user