New use numbering mask on validate
This commit is contained in:
parent
9eeacd8982
commit
4c5bf88492
@ -1048,46 +1048,71 @@ class ExpenseReport extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function setValidate($fuser, $notrigger=0)
|
function setValidate($fuser, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs,$user;
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
// Protection
|
||||||
|
if ($this->statut == self::STATUS_VALIDATED)
|
||||||
|
{
|
||||||
|
dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define new ref
|
||||||
|
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
|
||||||
|
{
|
||||||
|
$num = $this->getNextNumRef();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$num = $this->ref;
|
||||||
|
}
|
||||||
|
$this->newref = $num;
|
||||||
|
|
||||||
|
$now = dol_now();
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
|
||||||
|
$sql.= " SET ref = '".$num."',";
|
||||||
|
$sql.= " fk_statut = ".self::STATUS_VALIDATED.",";
|
||||||
|
$sql.= " date_valid='".$this->db->idate($now)."',";
|
||||||
|
$sql.= " fk_user_valid = ".$user->id;
|
||||||
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
if (!$notrigger)
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('EXPENSE_REPORT_VALIDATE',$fuser);
|
||||||
|
|
||||||
|
if ($result < 0) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$this->oldref = $this->ref;
|
$this->oldref = $this->ref;
|
||||||
$expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
|
|
||||||
|
|
||||||
// Sélection de la date de début de la NDF
|
|
||||||
$sql = 'SELECT date_debut';
|
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
|
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
$objp = $this->db->fetch_object($result);
|
|
||||||
$this->date_debut = $this->db->jdate($objp->date_debut);
|
|
||||||
|
|
||||||
$update_number_int = false;
|
|
||||||
|
|
||||||
// Create next ref if ref is PROVxx
|
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
// Sélection du numéro de ref suivant
|
|
||||||
$ref_next = $this->getNextNumRef();
|
|
||||||
$ref_number_int = ($this->ref+1)-1;
|
|
||||||
$update_number_int = true;
|
|
||||||
// Création du ref_number suivant
|
|
||||||
if($ref_next)
|
|
||||||
{
|
|
||||||
$prefix="ER";
|
|
||||||
if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX;
|
|
||||||
$this->ref = str_replace(' ','_', $this->user_author_infos).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d');
|
|
||||||
}
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
// We rename directory in order to avoid losing the attachments
|
|
||||||
$oldref = dol_sanitizeFileName($this->oldref);
|
// On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref)
|
||||||
$newref = dol_sanitizeFileName($this->ref);
|
// in order not to lose the attachments
|
||||||
|
$oldref = dol_sanitizeFileName($this->ref);
|
||||||
|
$newref = dol_sanitizeFileName($num);
|
||||||
$dirsource = $conf->expensereport->dir_output.'/'.$oldref;
|
$dirsource = $conf->expensereport->dir_output.'/'.$oldref;
|
||||||
$dirdest = $conf->expensereport->dir_output.'/'.$newref;
|
$dirdest = $conf->expensereport->dir_output.'/'.$newref;
|
||||||
if (file_exists($dirsource))
|
if (file_exists($dirsource))
|
||||||
{
|
{
|
||||||
dol_syslog(get_class($this)."::setValidate() rename dir ".$dirsource." into ".$dirdest);
|
dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
|
||||||
|
|
||||||
if (@rename($dirsource, $dirdest))
|
if (@rename($dirsource, $dirdest))
|
||||||
{
|
{
|
||||||
@ -1105,30 +1130,13 @@ class ExpenseReport extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->fk_statut != 2)
|
|
||||||
{
|
|
||||||
$now = dol_now();
|
|
||||||
$this->db->begin();
|
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
|
|
||||||
$sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."'";
|
|
||||||
if ($update_number_int) {
|
|
||||||
$sql.= ", ref_number_int = ".$ref_number_int;
|
|
||||||
}
|
}
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
// Set new ref and current status
|
||||||
if ($resql)
|
if (! $error)
|
||||||
{
|
{
|
||||||
if (!$notrigger)
|
$this->ref = $num;
|
||||||
{
|
$this->statut = self::STATUS_VALIDATED;
|
||||||
// Call trigger
|
|
||||||
$result=$this->call_trigger('EXPENSE_REPORT_VALIDATE',$fuser);
|
|
||||||
|
|
||||||
if ($result < 0) {
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
// End call triggers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($error))
|
if (empty($error))
|
||||||
@ -1149,11 +1157,6 @@ class ExpenseReport extends CommonObject
|
|||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::setValidate expensereport already with validated status", LOG_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user