Merge branch 'develop' into NEW_deposit_payment_terms

This commit is contained in:
Laurent Destailleur
2021-10-04 19:06:42 +02:00
committed by GitHub
181 changed files with 2314 additions and 907 deletions

View File

@@ -1671,7 +1671,7 @@ abstract class CommonObject
return 0;
}
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1';
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1";
$query = $this->db->query($sql);
@@ -2911,7 +2911,7 @@ abstract class CommonObject
// Count number of lines to reorder (according to choice $renum)
$nl = 0;
$sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = "SELECT count(rowid) FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
if (!$renum) {
$sql .= ' AND rang = 0';
@@ -2933,7 +2933,7 @@ abstract class CommonObject
$rows = array();
// We first search all lines that are parent lines (for multilevel details lines)
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
if ($fk_parent_line) {
$sql .= ' AND fk_parent_line IS NULL';
@@ -2981,7 +2981,7 @@ abstract class CommonObject
{
$rows = array();
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= ' AND fk_parent_line = '.((int) $id);
$sql .= ' ORDER BY rang ASC';
@@ -3049,7 +3049,7 @@ abstract class CommonObject
*
* @param int $rowid Id of line
* @param int $rang Position
* @return void
* @return int <0 if KO, >0 if OK
*/
public function updateRangOfLine($rowid, $rang)
{
@@ -3065,10 +3065,13 @@ abstract class CommonObject
dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG);
if (!$this->db->query($sql)) {
dol_print_error($this->db);
return -1;
} else {
$parameters=array('rowid'=>$rowid, 'rang'=>$rang, 'fieldposition' => $fieldposition);
$action='';
$reshook = $hookmanager->executeHooks('afterRankOfLineUpdate', $parameters, $this, $action);
return 1;
}
$parameters=array('rowid'=>$rowid, 'rang'=>$rang, 'fieldposition' => $fieldposition);
$action='';
$reshook = $hookmanager->executeHooks('afterRankOfLineUpdate', $parameters, $this, $action);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -3156,8 +3159,8 @@ abstract class CommonObject
*/
public function getRangOfLine($rowid)
{
$sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE rowid ='.((int) $rowid);
$sql = "SELECT rang FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE rowid = ".((int) $rowid);
dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -3175,9 +3178,9 @@ abstract class CommonObject
*/
public function getIdOfLine($rang)
{
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= ' AND rang = '.((int) $rang);
$sql .= " AND rang = ".((int) $rang);
$resql = $this->db->query($sql);
if ($resql) {
$row = $this->db->fetch_row($resql);
@@ -3204,7 +3207,7 @@ abstract class CommonObject
if ($fk_parent_line) {
$sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= ' AND fk_parent_line = '.((int) $fk_parent_line);
$sql .= " AND fk_parent_line = ".((int) $fk_parent_line);
dol_syslog(get_class($this)."::line_max", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -3420,7 +3423,7 @@ abstract class CommonObject
$sql .= ', situation_percent';
}
$sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
if ($exclspec) {
$product_field = 'product_type';
@@ -3580,7 +3583,7 @@ abstract class CommonObject
}
if (empty($nodatabaseupdate)) {
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.' SET';
$sql .= " ".$fieldht." = ".((float) price2num($this->total_ht)).",";
$sql .= " ".$fieldtva." = ".((float) price2num($this->total_tva)).",";
$sql .= " ".$fieldlocaltax1." = ".((float) price2num($this->total_localtax1)).",";
@@ -4275,8 +4278,8 @@ abstract class CommonObject
*/
public function getSpecialCode($lineid)
{
$sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE rowid = '.((int) $lineid);
$sql = "SELECT special_code FROM ".MAIN_DB_PREFIX.$this->table_element_line;
$sql .= " WHERE rowid = ".((int) $lineid);
$resql = $this->db->query($sql);
if ($resql) {
$row = $this->db->fetch_row($resql);
@@ -5332,7 +5335,7 @@ abstract class CommonObject
$ecmfile->gen_or_uploaded = 'generated';
$ecmfile->description = ''; // indexed content
$ecmfile->keywords = ''; // keyword content
$ecmfile->src_object_type = $this->table_element;
$ecmfile->src_object_type = $this->table_element.(empty($this->module) ? '' : '@'.$this->module);
$ecmfile->src_object_id = $this->id;
$result = $ecmfile->create($user);
@@ -6695,8 +6698,8 @@ abstract class CommonObject
}
$sqlwhere = '';
$sql = 'SELECT '.$keyList;
$sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
$sql = "SELECT ".$keyList;
$sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0];
if (!empty($InfoFieldList[4])) {
// can use SELECT request
if (strpos($InfoFieldList[4], '$SEL$') !== false) {
@@ -6847,7 +6850,7 @@ abstract class CommonObject
}
$sqlwhere = '';
$sql = 'SELECT '.$keyList;
$sql = "SELECT ".$keyList;
$sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
if (!empty($InfoFieldList[4])) {
// can use SELECT request
@@ -7208,7 +7211,7 @@ abstract class CommonObject
$keyList .= implode(', ', $fields_label);
}
$sql = 'SELECT '.$keyList;
$sql = "SELECT ".$keyList;
$sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
if (strpos($InfoFieldList[4], 'extra') !== false) {
$sql .= ' as main';
@@ -7291,7 +7294,7 @@ abstract class CommonObject
$keyList .= implode(', ', $fields_label);
}
$sql = 'SELECT '.$keyList;
$sql = "SELECT ".$keyList;
$sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0];
if (strpos($InfoFieldList[4], 'extra') !== false) {
$sql .= ' as main';
@@ -8228,7 +8231,7 @@ abstract class CommonObject
$return .= '<br>';
// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) {
$return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>';
$return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&token='.newToken().'&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>';
}
// Special cas for product
if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) {
@@ -8690,7 +8693,7 @@ abstract class CommonObject
// If field is an implicit foreign key field
if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) {
if (isset($this->fields[$key]['default'])) {
$values[$key] = $this->fields[$key]['default'];
$values[$key] = ((int) $this->fields[$key]['default']);
} else {
$values[$key] = 'null';
}
@@ -8707,9 +8710,9 @@ abstract class CommonObject
$this->db->begin();
if (!$error) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' ('.implode(", ", $keys).')';
$sql .= ' VALUES ('.implode(", ", $values).')';
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " (".implode(", ", $keys).')';
$sql .= " VALUES (".implode(", ", $values).")"; // $values can contains 'abc' or 123
$res = $this->db->query($sql);
if ($res === false) {
@@ -8725,7 +8728,7 @@ abstract class CommonObject
// If we have a field ref with a default value of (PROV)
if (!$error) {
if (key_exists('ref', $this->fields) && $this->fields['ref']['notnull'] > 0 && key_exists('default', $this->fields['ref']) && $this->fields['ref']['default'] == '(PROV)') {
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref = '(PROV".$this->id.")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id);
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id);
$resqlupdate = $this->db->query($sql);
if ($resqlupdate === false) {
@@ -9413,6 +9416,11 @@ abstract class CommonObject
*/
public function setCategoriesCommon($categories, $type_categ = '', $remove_existing = true)
{
// Handle single category
if (!is_array($categories)) {
$categories = array($categories);
}
dol_syslog(get_class($this)."::setCategoriesCommon Oject Id:".$this->id.' type_categ:'.$type_categ.' nb tag add:'.count($categories), LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
@@ -9422,11 +9430,6 @@ abstract class CommonObject
return -1;
}
// Handle single category
if (!is_array($categories)) {
$categories = array($categories);
}
// Get current categories
$c = new Categorie($this->db);
$existing = $c->containing($this->id, $type_categ, 'id');