|
@@ -746,7 +746,7 @@ class ExpenseReport extends CommonObject
|
|
|
$sql.= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,';
|
|
|
$sql.= ' p.ref as ref_projet, p.title as title_projet';
|
|
|
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de';
|
|
|
- $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
|
|
|
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
|
|
|
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid';
|
|
|
$sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id;
|
|
|
|
|
@@ -776,7 +776,7 @@ class ExpenseReport extends CommonObject
|
|
|
$deplig->total_tva = $objp->total_tva;
|
|
|
$deplig->total_ttc = $objp->total_ttc;
|
|
|
|
|
|
- $deplig->type_fees_code = $objp->code_type_fees;
|
|
|
+ $deplig->type_fees_code = empty($objp->code_type_fees)?'TF_OTHER':$objp->code_type_fees;
|
|
|
$deplig->type_fees_libelle = $objp->libelle_type_fees;
|
|
|
$deplig->tva_tx = $objp->tva_tx;
|
|
|
$deplig->vatrate = $objp->tva_tx;
|
|
@@ -850,12 +850,9 @@ class ExpenseReport extends CommonObject
|
|
|
{
|
|
|
global $conf,$langs;
|
|
|
|
|
|
+ $this->oldref = $this->ref;
|
|
|
$expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
|
|
|
|
|
|
- // Sélection du numéro de ref suivant
|
|
|
- $ref_next = $this->getNextNumRef();
|
|
|
- $ref_number_int = ($this->ref+1)-1;
|
|
|
-
|
|
|
// Sélection de la date de début de la NDF
|
|
|
$sql = 'SELECT date_debut';
|
|
|
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
|
|
@@ -864,21 +861,59 @@ class ExpenseReport extends CommonObject
|
|
|
$objp = $this->db->fetch_object($result);
|
|
|
$this->date_debut = $this->db->jdate($objp->date_debut);
|
|
|
|
|
|
- // Création du ref_number suivant
|
|
|
- if($ref_next)
|
|
|
+ $update_number_int = false;
|
|
|
+
|
|
|
+ // Create next ref if ref is PROVxx
|
|
|
+ // Rename directory if dir was a temporary ref
|
|
|
+ if (preg_match('/^[\(]?PROV/i', $this->ref))
|
|
|
{
|
|
|
- $prefix="ER";
|
|
|
- if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX;
|
|
|
- $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d');
|
|
|
+ // 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 = strtoupper($fuser->login).$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';
|
|
|
+ // We rename directory in order to avoid losing the attachments
|
|
|
+ $oldref = dol_sanitizeFileName($this->oldref);
|
|
|
+ $newref = dol_sanitizeFileName($this->ref);
|
|
|
+ $dirsource = $conf->expensereport->dir_output.'/'.$oldref;
|
|
|
+ $dirdest = $conf->expensereport->dir_output.'/'.$newref;
|
|
|
+ if (file_exists($dirsource))
|
|
|
+ {
|
|
|
+ dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
|
|
|
+
|
|
|
+ if (@rename($dirsource, $dirdest))
|
|
|
+ {
|
|
|
+ dol_syslog("Rename ok");
|
|
|
+ // Rename docs starting with $oldref with $newref
|
|
|
+ $listoffiles=dol_dir_list($conf->expensereport->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
|
|
|
+ foreach($listoffiles as $fileentry)
|
|
|
+ {
|
|
|
+ $dirsource=$fileentry['name'];
|
|
|
+ $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
|
|
|
+ $dirsource=$fileentry['path'].'/'.$dirsource;
|
|
|
+ $dirdest=$fileentry['path'].'/'.$dirdest;
|
|
|
+ @rename($dirsource, $dirdest);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if ($this->fk_statut != 2)
|
|
|
{
|
|
|
$now = dol_now();
|
|
|
-
|
|
|
+
|
|
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
|
|
|
- $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."',";
|
|
|
- $sql.= " ref_number_int = ".$ref_number_int;
|
|
|
+ $sql.= " SET ref = '".$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);
|
|
@@ -1265,7 +1300,9 @@ class ExpenseReport extends CommonObject
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
|
|
|
$sql.= " WHERE p.rowid = ".$projet_id;
|
|
|
$result = $this->db->query($sql);
|
|
|
- $objp_projet = $this->db->fetch_object($result);
|
|
|
+ if ($result) {
|
|
|
+ $objp_projet = $this->db->fetch_object($result);
|
|
|
+ }
|
|
|
$ligne->projet_ref = $objp_projet->ref_projet;
|
|
|
$ligne->projet_title = $objp_projet->title_projet;
|
|
|
|