2
0
forked from Wavyzz/dolibarr

Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into NEW_deposit_payment_terms

This commit is contained in:
Marc de Lima Lucio
2021-10-28 15:54:18 +02:00
858 changed files with 13581 additions and 21333 deletions

View File

@@ -1851,7 +1851,7 @@ abstract class CommonObject
$result = false;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table;
$sql .= " WHERE ".$field." = '".$key."'";
$sql .= " WHERE ".$field." = '".$this->db->escape($key)."'";
if (!empty($element)) {
$sql .= " AND entity IN (".getEntity($element).")";
} else {
@@ -2048,19 +2048,19 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
} elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
}
if ($restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
}
$sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND sc.fk_user = ".((int) $user->id);
}
if ($restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND (sc.fk_user = ".((int) $user->id).' OR te.fk_soc IS NULL)';
}
if (!empty($filter)) {
@@ -2072,7 +2072,7 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= " AND te.".$tmparray[0]." = ".($tmparray[1] == "societe" ? "s" : "parenttable").".rowid"; // If we need to link to this table to limit select to entity
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
}
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
@@ -2118,19 +2118,19 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
} elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
}
if ($restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
}
$sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND sc.fk_user = ".((int) $user->id);
}
if ($restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND (sc.fk_user = ".((int) $user->id).' OR te.fk_soc IS NULL)';
}
if (!empty($filter)) {
@@ -2142,7 +2142,7 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= " AND te.".$tmparray[0]." = ".($tmparray[1] == "societe" ? "s" : "parenttable").".rowid"; // If we need to link to this table to limit select to entity
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
} elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
}
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
@@ -6091,7 +6091,6 @@ abstract class CommonObject
}
$sql .= ")";
$resql = $this->db->query($sql);
if (!$resql) {
$this->error = $this->db->lasterror();
@@ -6345,6 +6344,11 @@ abstract class CommonObject
$this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]);
}
break;
case 'boolean':
if (empty($this->array_options["options_".$key])) {
$this->array_options["options_".$key] = null;
}
break;
/*
case 'link':
$param_list = array_keys($attributeParam['options']);
@@ -6499,7 +6503,7 @@ abstract class CommonObject
$out = '';
$type = '';
$isDependList=0;
$isDependList = 0;
$param = array();
$param['options'] = array();
$reg = array();
@@ -6807,7 +6811,7 @@ abstract class CommonObject
if (!empty($InfoFieldList[3]) && $parentField) {
$parent = $parentName.':'.$obj->{$parentField};
$isDependList=1;
$isDependList = 1;
}
$out .= '<option value="'.$obj->rowid.'"';
@@ -6962,7 +6966,7 @@ abstract class CommonObject
if (!empty($InfoFieldList[3]) && $parentField) {
$parent = $parentName.':'.$obj->{$parentField};
$isDependList=1;
$isDependList = 1;
}
$data[$obj->rowid] = $labeltoshow;
@@ -7704,7 +7708,7 @@ abstract class CommonObject
$langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
}
$colspan = '';
$colspan = 0;
if (is_array($params) && count($params) > 0 && $display_type=='card') {
if (array_key_exists('cols', $params)) {
$colspan = $params['cols'];
@@ -7717,6 +7721,7 @@ abstract class CommonObject
}
}
}
$colspan = intval($colspan);
switch ($mode) {
case "view":
@@ -7783,7 +7788,7 @@ abstract class CommonObject
$html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
if ($display_type=='card') {
if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
$colspan = '0';
$colspan = 0;
}
if ($action == 'selectlines') {
@@ -9067,10 +9072,15 @@ abstract class CommonObject
$className = str_replace('@', '', $deleteFromObject[0]);
$filePath = $deleteFromObject[1];
$columnName = $deleteFromObject[2];
$TMoreSQL = array();
$more_sql = $deleteFromObject[3];
if (!empty($more_sql)) {
$TMoreSQL['customsql'] = $more_sql;
}
if (dol_include_once($filePath)) {
$childObject = new $className($this->db);
if (method_exists($childObject, 'deleteByParentField')) {
$result = $childObject->deleteByParentField($this->id, $columnName);
$result = $childObject->deleteByParentField($this->id, $columnName, $TMoreSQL);
if ($result < 0) {
$error++;
$this->errors[] = $childObject->error;
@@ -9152,10 +9162,12 @@ abstract class CommonObject
*
* @param int $parentId Parent Id
* @param string $parentField Name of Foreign key parent column
* @param array $filter an array filter
* @param string $filtermode AND or OR
* @return int <0 if KO, >0 if OK
* @throws Exception
*/
public function deleteByParentField($parentId = 0, $parentField = '')
public function deleteByParentField($parentId = 0, $parentField = '', $filter = array(), $filtermode = "AND")
{
global $user;
@@ -9168,6 +9180,23 @@ abstract class CommonObject
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " WHERE ".$parentField." = ".(int) $parentId;
// Manage filters
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key == 'customsql') {
$sqlwhere[] = $value;
} elseif (strpos($value, '%') === false) {
$sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
} else {
$sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
}
}
}
if (count($sqlwhere) > 0) {
$sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
}
$resql = $this->db->query($sql);
if (!$resql) {
$this->errors[] = $this->db->lasterror();
@@ -9472,7 +9501,7 @@ abstract class CommonObject
}
$error = 0;
$ok=0;
$ok = 0;
// Process
foreach ($to_del as $del) {
@@ -9484,7 +9513,7 @@ abstract class CommonObject
$this->errors = $c->errors;
break;
} else {
$ok+=$result;
$ok += $result;
}
}
}
@@ -9497,7 +9526,7 @@ abstract class CommonObject
$this->errors = $c->errors;
break;
} else {
$ok+=$result;
$ok += $result;
}
}
}