Ajout gestion des triggers suivants:

ORDER_CREATE
ORDER_SUPPLIER_CREATE
ORDER_VALIDATE
ORDER_SUPPLIER_VALIDATE
This commit is contained in:
Laurent Destailleur 2006-08-02 20:10:22 +00:00
parent da49885a43
commit ad6494eb30
3 changed files with 206 additions and 134 deletions

View File

@ -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'))
@ -158,21 +159,23 @@ class Commande extends CommonObject
if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php')) if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php'))
{ {
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
// //
//$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);
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socidp); $soc->fetch($this->socidp);
// 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)
@ -183,57 +186,71 @@ class Commande extends CommonObject
{ {
$num = $this->ref; $num = $this->ref;
} }
$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) ) 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)) if (!dol_delete_file($file))
{ {
commande_delete_preview($this->db, $this->id, $this->ref); $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
$this->db->rollback();
if (!dol_delete_file($file)) return 0;
{ }
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file); }
return 0; if (file_exists($dir))
} {
} if (!dol_delete_dir($dir))
if (file_exists($dir)) {
{ $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
if (!dol_delete_dir($dir)) $this->db->rollback();
{ return 0;
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); }
return 0; }
} }
}
} // Appel des triggers
$result = 1; 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;
} }
/** /**
@ -446,8 +463,14 @@ class Commande extends CommonObject
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); $this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
} }
} }
// 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(); $this->db->commit();
return $this->id; return $this->id;
} }
else else
@ -1697,61 +1720,69 @@ 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) )
{ {
$err++; $err++;
} }
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = $this->id;"; $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = $this->id;";
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
$err++; $err++;
} }
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."co_pr WHERE fk_commande = $this->id;"; $sql = 'DELETE FROM '.MAIN_DB_PREFIX."co_pr WHERE fk_commande = $this->id;";
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
$err++; $err++;
} }
// 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 ; $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);
if (!dol_delete_file($file))
{ {
commande_delete_preview($this->db, $this->id, $this->ref); $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
$this->db->rollback();
if (!dol_delete_file($file)) return 0;
{ }
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file); }
return 0; if (file_exists($dir))
} {
} if (!dol_delete_dir($dir))
if (file_exists($dir)) {
{ $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
if (!dol_delete_dir($dir)) $this->db->rollback();
{ return 0;
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); }
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;
} }

View File

@ -178,66 +178,84 @@ 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
$modName=COMMANDE_SUPPLIER_ADDON; $modName=COMMANDE_SUPPLIER_ADDON;
// Recuperation de la nouvelle reference // Recuperation de la nouvelle reference
$objMod = new $modName($this->db); $objMod = new $modName($this->db);
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socidp); $soc->fetch($this->socidp);
$num = $objMod->commande_get_num($soc); $num = $objMod->commande_get_num($soc);
$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();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ;
if (! $this->db->query($sql) )
{
$err++;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id;
if (! $this->db->query($sql) )
{
$err++;
}
if ($err == 0)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->begin(); dolibarr_syslog("CommandeFournisseur::delete : Success");
$this->db->commit();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ; return 1;
if (! $this->db->query($sql) ) }
{ else
$err++; {
} $this->db->rollback();
return -1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id; }
if (! $this->db->query($sql) ) }
{
$err++;
}
if ($err == 0)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
/** /**
* \brief Positionne modele derniere generation * \brief Positionne modele derniere generation

View File

@ -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");
} }