Ajout gestion des triggers suivants:
ORDER_CREATE ORDER_SUPPLIER_CREATE ORDER_VALIDATE ORDER_SUPPLIER_VALIDATE
This commit is contained in:
parent
da49885a43
commit
ad6494eb30
@ -144,13 +144,14 @@ class Commande extends CommonObject
|
|||||||
return $this->create($user);
|
return $this->create($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \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
|
||||||
|
*/
|
||||||
function valid($user)
|
function valid($user)
|
||||||
{
|
{
|
||||||
$result = 0;
|
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
if ($user->rights->commande->valider)
|
if ($user->rights->commande->valider)
|
||||||
{
|
{
|
||||||
if (defined('COMMANDE_ADDON'))
|
if (defined('COMMANDE_ADDON'))
|
||||||
@ -159,6 +160,8 @@ class Commande extends CommonObject
|
|||||||
{
|
{
|
||||||
require_once 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
|
// 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
|
// \todo Normer le nom des classes des modules de numérotation de ref de commande avec un nom du type NumRefCommandesXxxx
|
||||||
@ -166,7 +169,7 @@ class Commande extends CommonObject
|
|||||||
//$list=split('_',COMMANDE_ADDON);
|
//$list=split('_',COMMANDE_ADDON);
|
||||||
//$numrefname=$list[2];
|
//$numrefname=$list[2];
|
||||||
//$modName = 'NumRefCommandes'.ucfirst($numrefname);
|
//$modName = 'NumRefCommandes'.ucfirst($numrefname);
|
||||||
$modName=COMMANDE_ADDON;
|
$modName=$conf->global->COMMANDE_ADDON;
|
||||||
|
|
||||||
// Recuperation de la nouvelle reference
|
// Recuperation de la nouvelle reference
|
||||||
$objMod = new $modName($this->db);
|
$objMod = new $modName($this->db);
|
||||||
@ -189,51 +192,65 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
// 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);
|
||||||
if ($conf->commande->dir_output)
|
if ($conf->commande->dir_output)
|
||||||
|
{
|
||||||
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||||
|
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||||
|
if (file_exists($file))
|
||||||
{
|
{
|
||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
commande_delete_preview($this->db, $this->id, $this->ref);
|
||||||
$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))
|
if (!dol_delete_file($file))
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
||||||
return 0;
|
$this->db->rollback();
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
if (file_exists($dir))
|
}
|
||||||
{
|
if (file_exists($dir))
|
||||||
if (!dol_delete_dir($dir))
|
{
|
||||||
{
|
if (!dol_delete_dir($dir))
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
{
|
||||||
return 0;
|
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
||||||
}
|
$this->db->rollback();
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
$result = 1;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
else
|
||||||
{
|
{
|
||||||
$result = -1;
|
$this->db->rollback();
|
||||||
dolibarr_print_error($this->db);
|
$this->error=$this->db->error();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print 'Impossible de lire le module de numérotation';
|
$this->error='Impossible de lire le module de numérotation';
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print 'Le module de numérotation n\'est pas défini' ;
|
$this->error='Le module de numérotation n\'est pas défini';
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result ;
|
|
||||||
|
$this->error='Autorisation insuffisante';
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -447,7 +464,13 @@ class Commande extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1697,15 +1720,15 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime la commande
|
* \brief Supprime la commande
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
global $conf, $lang;
|
global $conf, $lang;
|
||||||
|
|
||||||
$err = 0;
|
$err = 0;
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
@ -1728,30 +1751,38 @@ class Commande extends CommonObject
|
|||||||
$comref = sanitize_string($this->ref);
|
$comref = sanitize_string($this->ref);
|
||||||
if ($conf->commande->dir_output)
|
if ($conf->commande->dir_output)
|
||||||
{
|
{
|
||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||||
if (file_exists($file))
|
if (file_exists($file))
|
||||||
{
|
{
|
||||||
commande_delete_preview($this->db, $this->id, $this->ref);
|
commande_delete_preview($this->db, $this->id, $this->ref);
|
||||||
|
|
||||||
if (!dol_delete_file($file))
|
if (!dol_delete_file($file))
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
||||||
return 0;
|
$this->db->rollback();
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
if (file_exists($dir))
|
}
|
||||||
{
|
if (file_exists($dir))
|
||||||
if (!dol_delete_dir($dir))
|
{
|
||||||
{
|
if (!dol_delete_dir($dir))
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
{
|
||||||
return 0;
|
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
||||||
}
|
$this->db->rollback();
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($err == 0)
|
if ($err == 0)
|
||||||
{
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,22 +178,23 @@ class CommandeFournisseur extends Commande
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valide la commande
|
* \brief Valide la commande
|
||||||
*
|
* \param user Utilisateur qui valide
|
||||||
*
|
*/
|
||||||
*/
|
function valid($user)
|
||||||
function valid($user)
|
|
||||||
{
|
{
|
||||||
dolibarr_syslog("CommandeFournisseur::Valid");
|
dolibarr_syslog("CommandeFournisseur::Valid");
|
||||||
$result = 0;
|
$result = 0;
|
||||||
if ($user->rights->fournisseur->commande->valider)
|
if ($user->rights->fournisseur->commande->valider)
|
||||||
{
|
{
|
||||||
if (defined('COMMANDE_SUPPLIER_ADDON'))
|
if (defined('COMMANDE_SUPPLIER_ADDON'))
|
||||||
{
|
{
|
||||||
if (is_readable(DOL_DOCUMENT_ROOT .'/fourn/commande/modules/'.COMMANDE_SUPPLIER_ADDON.'.php'))
|
if (is_readable(DOL_DOCUMENT_ROOT .'/fourn/commande/modules/'.COMMANDE_SUPPLIER_ADDON.'.php'))
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT .'/fourn/commande/modules/'.COMMANDE_SUPPLIER_ADDON.'.php';
|
$this->db->begin();
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT .'/fourn/commande/modules/'.COMMANDE_SUPPLIER_ADDON.'.php';
|
||||||
|
|
||||||
// Definition du nom de module de numerotation de commande fournisseur
|
// Definition du nom de module de numerotation de commande fournisseur
|
||||||
|
|
||||||
@ -208,36 +209,53 @@ class CommandeFournisseur extends Commande
|
|||||||
$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 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
$result = 1;
|
$result = 1;
|
||||||
$this->log($user, 1, time());
|
$this->log($user, 1, time());
|
||||||
$this->ref = $num;
|
$this->ref = $num;
|
||||||
$this->_NotifyApprobator($user);
|
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('ORDER_SUPPLIER_VALIDATE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
|
$this->_NotifyApprobator($user); // \todo a gerer par trigger
|
||||||
|
|
||||||
|
dolibarr_syslog("CommandeFournisseur::valid Success");
|
||||||
|
$this->db->begin();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$result = -1;
|
$this->error=$this->db->error();
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_syslog("CommandeFournisseur::valid ".$this->error);
|
||||||
dolibarr_syslog("CommandeFournisseur::Valid Error -1");
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print 'Impossible de lire le module de numérotation';
|
$this->error='Impossible de lire le module de numérotation';
|
||||||
|
dolibarr_syslog("CommandeFournisseur::valid ".$this->error);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print 'Le module de numérotation n\'est pas défini' ;
|
$this->error='Le module de numérotation n\'est pas défini' ;
|
||||||
|
dolibarr_syslog("CommandeFournisseur::valid ".$this->error);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_syslog("CommandeFournisseur::Valid Not Authorized");
|
$this->error='Not Authorized';
|
||||||
}
|
dolibarr_syslog("CommandeFournisseur::valid ".$this->error);
|
||||||
return $result ;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -561,6 +579,12 @@ class CommandeFournisseur extends Commande
|
|||||||
// On logue creation pour historique
|
// On logue creation pour historique
|
||||||
$this->log($user, 0, time());
|
$this->log($user, 0, time());
|
||||||
|
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
dolibarr_syslog("CommandeFournisseur::Create : Success");
|
dolibarr_syslog("CommandeFournisseur::Create : Success");
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -746,38 +770,45 @@ class CommandeFournisseur extends Commande
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime la commande
|
* \brief Supprime la commande
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ;
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id;
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($err == 0)
|
if ($err == 0)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
// Appel des triggers
|
||||||
return 1;
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
}
|
$interface=new Interfaces($this->db);
|
||||||
else
|
$result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf);
|
||||||
{
|
// Fin appel triggers
|
||||||
$this->db->rollback();
|
|
||||||
return -1;
|
dolibarr_syslog("CommandeFournisseur::delete : Success");
|
||||||
}
|
$this->db->commit();
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Positionne modele derniere generation
|
* \brief Positionne modele derniere generation
|
||||||
|
|||||||
@ -144,15 +144,25 @@ class InterfaceDemo
|
|||||||
{
|
{
|
||||||
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
}
|
}
|
||||||
|
// Customer orders
|
||||||
elseif ($action == 'ORDER_CREATE')
|
elseif ($action == 'ORDER_CREATE')
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
}
|
}
|
||||||
elseif ($action == 'ORDER_MODIFY')
|
elseif ($action == 'ORDER_VALIDATE')
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
}
|
}
|
||||||
elseif ($action == 'ORDER_DELETE')
|
elseif ($action == 'ORDER_DELETE')
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
|
}
|
||||||
|
// Supplier orders
|
||||||
|
elseif ($action == 'ORDER_SUPPLIER_CREATE')
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
|
}
|
||||||
|
elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user