This commit is contained in:
Laurent Destailleur 2020-04-03 15:48:54 +02:00
parent e9bddf5c26
commit 372d719693

View File

@ -551,29 +551,31 @@ class MyObject extends CommonObject
} }
$this->newref = $num; $this->newref = $num;
// Validate if (! empty($num)) {
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; // Validate
$sql .= " SET ref = '".$this->db->escape($num)."',"; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " status = ".self::STATUS_VALIDATED; $sql .= " SET ref = '".$this->db->escape($num)."',";
if (! empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',"; $sql .= " status = ".self::STATUS_VALIDATED;
if (! empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id; if (! empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',";
$sql .= " WHERE rowid = ".$this->id; if (! empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id;
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::validate()", LOG_DEBUG); dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql)
{ {
dol_print_error($this->db); dol_print_error($this->db);
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$error++; $error++;
} }
if (!$error && !$notrigger) if (!$error && !$notrigger)
{ {
// Call trigger // Call trigger
$result = $this->call_trigger('MYOBJECT_VALIDATE', $user); $result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
}
} }
if (!$error) if (!$error)
@ -946,23 +948,28 @@ class MyObject extends CommonObject
return ''; return '';
} }
$obj = new $classname(); if (class_exists($classname)) {
$numref = $obj->getNextValue($this); $obj = new $classname();
$numref = $obj->getNextValue($this);
if ($numref != "") if ($numref != "")
{ {
return $numref; return $numref;
} }
else else
{ {
$this->error = $obj->error; $this->error = $obj->error;
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
return "";
}
} else {
print $langs->trans("Error")." ".$langs->trans("ClassNotFound");
return ""; return "";
} }
} }
else else
{ {
print $langs->trans("Error")." ".$langs->trans("Error_MYMODULE_MYOBJECT_ADDON_NotDefined"); print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
return ""; return "";
} }
} }