mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Merge branch '8.0' of git@github.com:Dolibarr/dolibarr.git into 9.0
This commit is contained in:
commit
5f2439bf0a
|
|
@ -558,15 +558,24 @@ class ImportCsv extends ModeleImports
|
|||
if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
|
||||
{
|
||||
// If test is "Must exist in a field@table"
|
||||
if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
|
||||
if (preg_match('/^(.+)@([^:]+)(:.+)?$/',$objimport->array_import_regex[0][$val],$reg))
|
||||
{
|
||||
$field=$reg[1];
|
||||
$table=$reg[2];
|
||||
$filter=!empty($reg[3])?substr($reg[3], 1):'';
|
||||
|
||||
$cachekey = $field.'@'.$table;
|
||||
if(! empty($filter)) $cachekey.= ':'.$filter;
|
||||
|
||||
// Load content of field@table into cache array
|
||||
if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
|
||||
if (! is_array($this->cachefieldtable[$cachekey])) // If content of field@table not already loaded into cache
|
||||
{
|
||||
$sql="SELECT ".$field." as aliasfield FROM ".$table;
|
||||
if(! empty($filter))
|
||||
{
|
||||
$sql.= ' WHERE ' . $filter;
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
|
|
@ -575,7 +584,7 @@ class ImportCsv extends ModeleImports
|
|||
while ($i < $num)
|
||||
{
|
||||
$obj=$this->db->fetch_object($resql);
|
||||
if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
|
||||
if ($obj) $this->cachefieldtable[$cachekey][]=$obj->aliasfield;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
|
@ -586,9 +595,11 @@ class ImportCsv extends ModeleImports
|
|||
}
|
||||
|
||||
// Now we check cache is not empty (should not) and key is into cache
|
||||
if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
|
||||
if (! is_array($this->cachefieldtable[$cachekey]) || ! in_array($newval,$this->cachefieldtable[$cachekey]))
|
||||
{
|
||||
$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
|
||||
$tableforerror = $table;
|
||||
if(! empty($filter)) $tableforerror.= ':'.$filter;
|
||||
$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$tableforerror);
|
||||
$this->errors[$error]['type']='FOREIGNKEY';
|
||||
$errorforthistable++;
|
||||
$error++;
|
||||
|
|
|
|||
|
|
@ -585,15 +585,24 @@ class ImportXlsx extends ModeleImports
|
|||
if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
|
||||
{
|
||||
// If test is "Must exist in a field@table"
|
||||
if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
|
||||
if (preg_match('/^(.+)@([^:]+)(:.+)?$/',$objimport->array_import_regex[0][$val],$reg))
|
||||
{
|
||||
$field=$reg[1];
|
||||
$table=$reg[2];
|
||||
$filter=!empty($reg[3])?substr($reg[3], 1):'';
|
||||
|
||||
$cachekey = $field.'@'.$table;
|
||||
if(! empty($filter)) $cachekey.= ':'.$filter;
|
||||
|
||||
// Load content of field@table into cache array
|
||||
if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
|
||||
if (! is_array($this->cachefieldtable[$cachekey])) // If content of field@table not already loaded into cache
|
||||
{
|
||||
$sql="SELECT ".$field." as aliasfield FROM ".$table;
|
||||
if(! empty($filter))
|
||||
{
|
||||
$sql.= ' WHERE ' . $filter;
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
|
|
@ -602,7 +611,7 @@ class ImportXlsx extends ModeleImports
|
|||
while ($i < $num)
|
||||
{
|
||||
$obj=$this->db->fetch_object($resql);
|
||||
if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
|
||||
if ($obj) $this->cachefieldtable[$cachekey][]=$obj->aliasfield;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
|
@ -613,9 +622,11 @@ class ImportXlsx extends ModeleImports
|
|||
}
|
||||
|
||||
// Now we check cache is not empty (should not) and key is into cache
|
||||
if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
|
||||
if (! is_array($this->cachefieldtable[$cachekey]) || ! in_array($newval,$this->cachefieldtable[$cachekey]))
|
||||
{
|
||||
$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
|
||||
$tableforerror = $table;
|
||||
if(! empty($filter)) $tableforerror.= ':'.$filter;
|
||||
$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$tableforerror);
|
||||
$this->errors[$error]['type']='FOREIGNKEY';
|
||||
$errorforthistable++;
|
||||
$error++;
|
||||
|
|
|
|||
|
|
@ -422,8 +422,8 @@ class modCategorie extends DolibarrModules
|
|||
$this->import_icon[$r]=$this->picto;
|
||||
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
|
||||
$this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product');
|
||||
$this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*"
|
||||
);
|
||||
$this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*");
|
||||
$this->import_regex_array[$r]=array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=0');
|
||||
|
||||
$this->import_convertvalue_array[$r]=array(
|
||||
'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
|
||||
|
|
@ -441,7 +441,10 @@ class modCategorie extends DolibarrModules
|
|||
$this->import_icon[$r]=$this->picto;
|
||||
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
|
||||
$this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
|
||||
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*"
|
||||
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*");
|
||||
$this->import_regex_array[$r]=array(
|
||||
'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=2',
|
||||
'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:client>0'
|
||||
);
|
||||
|
||||
$this->import_convertvalue_array[$r]=array(
|
||||
|
|
@ -460,7 +463,10 @@ class modCategorie extends DolibarrModules
|
|||
$this->import_icon[$r]=$this->picto;
|
||||
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
|
||||
$this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
|
||||
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*"
|
||||
$this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*");
|
||||
$this->import_regex_array[$r]=array(
|
||||
'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=1',
|
||||
'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:fournisseur>0'
|
||||
);
|
||||
|
||||
$this->import_convertvalue_array[$r]=array(
|
||||
|
|
|
|||
|
|
@ -1438,45 +1438,30 @@ class Holiday extends CommonObject
|
|||
$result = $this->db->query($sql);
|
||||
|
||||
$typeleaves=$this->getTypes(1,1);
|
||||
foreach($typeleaves as $key => $val)
|
||||
{
|
||||
// On ajoute x jours à chaque utilisateurs
|
||||
$nb_holiday = $val['newByMonth'];
|
||||
if (empty($nb_holiday)) $nb_holiday=0;
|
||||
|
||||
if ($nb_holiday > 0)
|
||||
// Update each user counter
|
||||
foreach ($users as $userCounter) {
|
||||
$nbDaysToAdd = $typeleaves[$userCounter['type']]['newByMonth'];
|
||||
if(empty($nbDaysToAdd)) continue;
|
||||
|
||||
dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
|
||||
|
||||
$nowHoliday = $userCounter['nb_holiday'];
|
||||
$newSolde = $nowHoliday + $nbDaysToAdd;
|
||||
|
||||
// We add a log for each user
|
||||
$this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $newSolde, $userCounter['type']);
|
||||
|
||||
$result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type'], $langs->trans('HolidaysMonthlyUpdate'));
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
dol_syslog("We update leavefor everybody for type ".$key, LOG_DEBUG);
|
||||
|
||||
$i = 0;
|
||||
while ($i < $nbUser)
|
||||
{
|
||||
$now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
|
||||
$new_solde = $now_holiday + $nb_holiday;
|
||||
|
||||
// We add a log for each user
|
||||
$this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Now we update counter for all users at once
|
||||
$sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
|
||||
$sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
|
||||
$sql2.= " WHERE fk_type = ".$val['rowid'];
|
||||
|
||||
$result= $this->db->query($sql2);
|
||||
|
||||
if (! $result)
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
break;
|
||||
}
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
else dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
|
||||
}
|
||||
|
||||
if ($result)
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
|
|
@ -1799,7 +1784,7 @@ class Holiday extends CommonObject
|
|||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$tab_result[$i]['rowid'] = $obj->rowid;
|
||||
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
||||
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
||||
$tab_result[$i]['lastname'] = $obj->lastname;
|
||||
$tab_result[$i]['firstname'] = $obj->firstname;
|
||||
|
|
@ -1807,7 +1792,7 @@ class Holiday extends CommonObject
|
|||
$tab_result[$i]['status'] = $obj->statut;
|
||||
$tab_result[$i]['employee'] = $obj->employee;
|
||||
$tab_result[$i]['photo'] = $obj->photo;
|
||||
$tab_result[$i]['fk_user'] = $obj->fk_user;
|
||||
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
||||
//$tab_result[$i]['type'] = $obj->type;
|
||||
//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
||||
|
||||
|
|
@ -1826,7 +1811,7 @@ class Holiday extends CommonObject
|
|||
else
|
||||
{
|
||||
// List of vacation balance users
|
||||
$sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
||||
$sql = "SELECT cpu.fk_user as rowid, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE cpu.fk_user = u.rowid";
|
||||
if ($filters) $sql.=$filters;
|
||||
|
|
@ -1845,7 +1830,7 @@ class Holiday extends CommonObject
|
|||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$tab_result[$i]['rowid'] = $obj->fk_user;
|
||||
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
|
||||
$tab_result[$i]['name'] = $obj->lastname; // deprecated
|
||||
$tab_result[$i]['lastname'] = $obj->lastname;
|
||||
$tab_result[$i]['firstname'] = $obj->firstname;
|
||||
|
|
@ -1853,9 +1838,9 @@ class Holiday extends CommonObject
|
|||
$tab_result[$i]['status'] = $obj->statut;
|
||||
$tab_result[$i]['employee'] = $obj->employee;
|
||||
$tab_result[$i]['photo'] = $obj->photo;
|
||||
$tab_result[$i]['fk_user'] = $obj->fk_user;
|
||||
$tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
|
||||
|
||||
$tab_result[$i]['type'] = $obj->type;
|
||||
$tab_result[$i]['type'] = $obj->fk_type;
|
||||
$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
|
||||
|
||||
$i++;
|
||||
|
|
|
|||
|
|
@ -450,6 +450,11 @@ if ($action == "set")
|
|||
$buffer=trim($buffer);
|
||||
if ($buffer)
|
||||
{
|
||||
// Replace the prefix in table names
|
||||
if ($dolibarr_main_db_prefix != 'llx_')
|
||||
{
|
||||
$buffer=preg_replace('/llx_/i',$dolibarr_main_db_prefix,$buffer);
|
||||
}
|
||||
dolibarr_install_syslog("step2: request: " . $buffer);
|
||||
print "<!-- Insert line : ".$buffer."<br>-->\n";
|
||||
$resql=$db->query($buffer,0,'dml');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user