mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 17:18:13 +01:00
NEW Can include tag {uuu} into some numbering masks to replace with user
This commit is contained in:
@@ -707,9 +707,10 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti
|
||||
* @param string $date Date to use for the {y},{m},{d} tags.
|
||||
* @param string $mode 'next' for next value or 'last' for last value
|
||||
* @param bool $bentityon Activate the entity filter. Default is true (for modules not compatible with multicompany)
|
||||
* @param User $objuser Object user we need data from.
|
||||
* @return string New value (numeric) or error message
|
||||
*/
|
||||
function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$mode='next', $bentityon=true)
|
||||
function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$mode='next', $bentityon=true, $objuser=null)
|
||||
{
|
||||
global $conf,$user;
|
||||
|
||||
@@ -780,6 +781,22 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$masktype_value='';
|
||||
}
|
||||
|
||||
// Extract value for user
|
||||
if (preg_match('/\{(u+)\}/i',$mask,$regType))
|
||||
{
|
||||
$lastname = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
|
||||
if (is_object($objuser)) $lastname = $objuser->lastname;
|
||||
|
||||
$maskuser=$regType[1];
|
||||
$maskuser_value=substr($lastname,0,dol_strlen($regType[1]));// get n first characters of user firstname (where n is length in mask)
|
||||
$maskuser_value=str_pad($maskuser_value,dol_strlen($regType[1]),"#",STR_PAD_RIGHT); // we fill on right with # to have same number of char than into mask
|
||||
}
|
||||
else
|
||||
{
|
||||
$maskuser='';
|
||||
$maskuser_value='';
|
||||
}
|
||||
|
||||
// Personalized field {XXX-1} à {XXX-9}
|
||||
/*$maskperso=array();
|
||||
$maskpersonew=array();
|
||||
@@ -805,6 +822,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode);
|
||||
$maskwithonlyymcode=preg_replace('/\{(c+)(0*)\}/i',$maskrefclient,$maskwithonlyymcode);
|
||||
$maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode);
|
||||
$maskwithonlyymcode=preg_replace('/\{(u+)\}/i',$maskuser_value,$maskwithonlyymcode);
|
||||
/*foreach($maskperso as $key => $val)
|
||||
{
|
||||
$maskwithonlyymcode=preg_replace('/'.$val.'/i', $maskpersonew[$key], $maskwithonlyymcode);
|
||||
@@ -951,6 +969,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",dol_strlen($maskcounter),"_"),$maskLike);
|
||||
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
|
||||
if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
|
||||
if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
|
||||
|
||||
// Get counter in database
|
||||
$counter=0;
|
||||
@@ -994,6 +1013,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike);
|
||||
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
|
||||
if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
|
||||
if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
|
||||
|
||||
$ref='';
|
||||
$sql = "SELECT ".$field." as ref";
|
||||
@@ -1114,6 +1134,14 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$masktype_maskafter=$masktype_value;
|
||||
$numFinal = str_replace($masktype_maskbefore,$masktype_maskafter,$numFinal);
|
||||
}
|
||||
|
||||
// Now we replace the user
|
||||
if ($maskuser)
|
||||
{
|
||||
$maskuser_maskbefore='{'.$maskuser.'}';
|
||||
$maskuser_maskafter=$maskuser_value;
|
||||
$numFinal = str_replace($maskuser_maskbefore,$maskuser_maskafter,$numFinal);
|
||||
}
|
||||
}
|
||||
|
||||
dol_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG);
|
||||
|
||||
@@ -118,11 +118,16 @@ class mod_expensereport_jade extends ModeleNumRefExpenseReport
|
||||
else
|
||||
{
|
||||
dol_syslog("mod_expensereport_jade::getNextValue", LOG_DEBUG);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$date=$object->date_valid; // $object->date does not exists
|
||||
if (empty($date))
|
||||
{
|
||||
$this->error = 'Date valid not defined';
|
||||
return 0;
|
||||
}
|
||||
|
||||
//$date=time();
|
||||
$date=$object->date;
|
||||
$yymm = strftime("%y%m",$date);
|
||||
|
||||
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is
|
||||
|
||||
@@ -82,12 +82,13 @@ class mod_expensereport_sand extends ModeleNumRefExpenseReport
|
||||
*/
|
||||
function getExample()
|
||||
{
|
||||
global $conf,$langs,$mysoc;
|
||||
global $conf,$langs,$user;
|
||||
|
||||
$old_code_client=$mysoc->code_client;
|
||||
$mysoc->code_client='CCCCCCCCCC';
|
||||
$numExample = $this->getNextValue($mysoc,'');
|
||||
$mysoc->code_client=$old_code_client;
|
||||
$exp=new ExpenseReport($this->db);
|
||||
$exp->initAsSpecimen();
|
||||
$exp->fk_user_author = $user->id;
|
||||
|
||||
$numExample = $this->getNextValue($exp);
|
||||
|
||||
if (! $numExample)
|
||||
{
|
||||
@@ -99,11 +100,10 @@ class mod_expensereport_sand extends ModeleNumRefExpenseReport
|
||||
/**
|
||||
* Return next free value
|
||||
*
|
||||
* @param Societe $objsoc Object thirdparty
|
||||
* @param Object $object Object we need next value for
|
||||
* @return string Value if KO, <0 if KO
|
||||
*/
|
||||
function getNextValue($objsoc,$object)
|
||||
function getNextValue($object)
|
||||
{
|
||||
global $db,$conf;
|
||||
|
||||
@@ -118,7 +118,21 @@ class mod_expensereport_sand extends ModeleNumRefExpenseReport
|
||||
return 0;
|
||||
}
|
||||
|
||||
$numFinal=get_next_value($db,$mask,'expensereport','ref','',$objsoc,$object->date);
|
||||
$date=$object->date_valid; // $object->date does not exists
|
||||
if (empty($date))
|
||||
{
|
||||
$this->error = 'Date valid not defined';
|
||||
return 0;
|
||||
}
|
||||
|
||||
$fuser = null;
|
||||
if ($object->fk_user_author > 0)
|
||||
{
|
||||
$fuser=new User($db);
|
||||
$fuser->fetch($object->fk_user_author);
|
||||
}
|
||||
|
||||
$numFinal=get_next_value($db,$mask,'expensereport','ref','',null, $date, 'next', true, $fuser);
|
||||
|
||||
return $numFinal;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,13 @@ class modExpenseReport extends DolibarrModules
|
||||
$this->const[$r][4] = 0;
|
||||
$r++;
|
||||
|
||||
$this->const[$r][0] = "EXPENSEREPORT_ADDON";
|
||||
$this->const[$r][1] = "chaine";
|
||||
$this->const[$r][2] = "mod_expensereport_jade";
|
||||
$this->const[$r][3] = 'Name of manager to generate expense report ref number';
|
||||
$this->const[$r][4] = 0;
|
||||
$r++;
|
||||
|
||||
$this->const[$r][0] = "MAIN_DELAY_EXPENSEREPORTS";
|
||||
$this->const[$r][1] = "chaine";
|
||||
$this->const[$r][2] = "15";
|
||||
|
||||
@@ -730,6 +730,7 @@ class ExpenseReport extends CommonObject
|
||||
$this->date_create = $now;
|
||||
$this->date_debut = $now;
|
||||
$this->date_fin = $now;
|
||||
$this->date_valid = $now;
|
||||
$this->date_approve = $now;
|
||||
|
||||
$type_fees_id = 2; // TF_TRIP
|
||||
@@ -1060,14 +1061,17 @@ class ExpenseReport extends CommonObject
|
||||
global $conf,$langs,$user;
|
||||
|
||||
$error = 0;
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
// Protection
|
||||
if ($this->statut == self::STATUS_VALIDATED)
|
||||
{
|
||||
dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$this->date_valid = $now; // Required for the getNextNum later.
|
||||
|
||||
// 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
|
||||
{
|
||||
@@ -1077,16 +1081,17 @@ class ExpenseReport extends CommonObject
|
||||
{
|
||||
$num = $this->ref;
|
||||
}
|
||||
if (empty($num)) return -1;
|
||||
|
||||
$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.= " date_valid='".$this->db->idate($this->date_valid)."',";
|
||||
$sql.= " fk_user_valid = ".$user->id;
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
@@ -1112,7 +1117,7 @@ class ExpenseReport extends CommonObject
|
||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
|
||||
// On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref)
|
||||
// in order not to lose the attachments
|
||||
$oldref = dol_sanitizeFileName($this->ref);
|
||||
@@ -1122,7 +1127,7 @@ class ExpenseReport extends CommonObject
|
||||
if (file_exists($dirsource))
|
||||
{
|
||||
dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
|
||||
|
||||
|
||||
if (@rename($dirsource, $dirdest))
|
||||
{
|
||||
dol_syslog("Rename ok");
|
||||
@@ -1505,13 +1510,14 @@ class ExpenseReport extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$obj->error;
|
||||
$this->errors=$obj->errors;
|
||||
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined");
|
||||
print $langs->trans("Error")." ".$langs->trans("Error_EXPENSEREPORT_ADDON_NotDefined");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user