Fix: Validation of contract lose the new ref into trigger.
Fix: Validation of contract was not using transaction Fix: Validation of contract did not renamed uploaded directory.
This commit is contained in:
parent
a8f784083c
commit
e5bc7d29d0
@ -1788,8 +1788,8 @@ class Facture extends CommonInvoice
|
|||||||
// Rename directory if dir was a temporary ref
|
// Rename directory if dir was a temporary ref
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||||
{
|
{
|
||||||
// On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
|
// Rename of object directory ($this->ref = old ref, $num = new ref)
|
||||||
// afin de ne pas perdre les fichiers attaches
|
// to not lose the linked files
|
||||||
$facref = dol_sanitizeFileName($this->ref);
|
$facref = dol_sanitizeFileName($this->ref);
|
||||||
$snumfa = dol_sanitizeFileName($num);
|
$snumfa = dol_sanitizeFileName($num);
|
||||||
$dirsource = $conf->facture->dir_output.'/'.$facref;
|
$dirsource = $conf->facture->dir_output.'/'.$facref;
|
||||||
|
|||||||
@ -277,51 +277,60 @@ class Contrat extends CommonObject
|
|||||||
* Validate a contract
|
* Validate a contract
|
||||||
*
|
*
|
||||||
* @param User $user Objet User
|
* @param User $user Objet User
|
||||||
|
* @param string $force_number Reference to force on contract (not implemented yet)
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function validate($user)
|
function validate($user, $force_number='')
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
global $langs, $conf;
|
global $langs, $conf;
|
||||||
|
|
||||||
|
$now=dol_now();
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number);
|
||||||
|
|
||||||
// Definition du nom de module de numerotation de commande
|
|
||||||
$soc = new Societe($this->db);
|
|
||||||
$soc->fetch($this->socid);
|
|
||||||
|
|
||||||
// Class of company linked to order
|
$this->db->begin();
|
||||||
$result=$soc->set_as_client();
|
|
||||||
|
$this->fetch_thirdparty();
|
||||||
|
|
||||||
|
// A contract is validated so we can move thirdparty to status customer
|
||||||
|
$result=$this->thirdparty->set_as_client();
|
||||||
|
|
||||||
// Define new ref
|
// Define new ref
|
||||||
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
|
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
|
||||||
{
|
{
|
||||||
$num = $this->getNextNumRef($soc);
|
$num = $this->getNextNumRef($this->thirdparty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$num = $this->ref;
|
$num = $this->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($num)
|
||||||
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1";
|
||||||
|
//$sql.= ", fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'";
|
||||||
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
|
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::validate sql=".$sql);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
dol_syslog(get_class($this)."::validate Echec update - 10 - sql=".$sql, LOG_ERR);
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
dol_print_error($this->db);
|
||||||
$interface=new Interfaces($this->db);
|
$error++;
|
||||||
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
|
}
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
|
||||||
// Fin appel triggers
|
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
$this->oldref = '';
|
||||||
|
|
||||||
// Rename directory if dir was a temporary ref
|
// Rename directory if dir was a temporary ref
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||||
{
|
{
|
||||||
// Rename of propal directory ($this->ref = old ref, $num = new ref)
|
// Rename of object directory ($this->ref = old ref, $num = new ref)
|
||||||
// to not lose the linked files
|
// to not lose the linked files
|
||||||
$facref = dol_sanitizeFileName($this->ref);
|
$facref = dol_sanitizeFileName($this->ref);
|
||||||
$snumfa = dol_sanitizeFileName($num);
|
$snumfa = dol_sanitizeFileName($num);
|
||||||
@ -333,25 +342,53 @@ class Contrat extends CommonObject
|
|||||||
|
|
||||||
if (@rename($dirsource, $dirdest))
|
if (@rename($dirsource, $dirdest))
|
||||||
{
|
{
|
||||||
|
$this->oldref = $facref;
|
||||||
|
|
||||||
dol_syslog("Rename ok");
|
dol_syslog("Rename ok");
|
||||||
// Deleting old PDF in new rep
|
// Deleting old PDF in new rep
|
||||||
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*');
|
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new ref and define current statut
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->ref = $num;
|
||||||
|
$this->statut=1;
|
||||||
|
$this->brouillon=0;
|
||||||
|
$this->date_validation=$now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger calls
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
|
||||||
|
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||||
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->error();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user