Update cproductnature.class.php

This commit is contained in:
Frédéric FRANCE 2020-10-22 22:20:48 +02:00 committed by GitHub
parent f94e20c8ce
commit ed8bfa26fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,14 @@ class CProductNature // extends CommonObject
public $errors = array(); public $errors = array();
public $records = array(); public $records = array();
/**
* @var string element
*/
public $element='cproductnbature'; public $element='cproductnbature';
/**
* @var string table element
*/
public $table_element='c_product_nature'; public $table_element='c_product_nature';
/** /**
@ -52,13 +59,22 @@ class CProductNature // extends CommonObject
*/ */
public $id; public $id;
/**
* @var string code
*/
public $code; public $code;
/**
* @var string label
*/
public $label; public $label;
/**
* @var int active
*/
public $active; public $active;
/** /**
* Constructor * Constructor
* *
@ -87,7 +103,7 @@ class CProductNature // extends CommonObject
if (isset($this->id)) $this->id = (int) $this->id; if (isset($this->id)) $this->id = (int) $this->id;
if (isset($this->code)) $this->code = trim($this->code); if (isset($this->code)) $this->code = trim($this->code);
if (isset($this->label)) $this->libelle = trim($this->label); if (isset($this->label)) $this->libelle = trim($this->label);
if (isset($this->active)) $this->active = trim($this->active); if (isset($this->active)) $this->active = (int) ($this->active);
// Check parameters // Check parameters
// Put here code to add control on parameters values // Put here code to add control on parameters values
@ -102,31 +118,28 @@ class CProductNature // extends CommonObject
$sql .= " ".(!isset($this->id) ? 'NULL' : ((int) $this->id)) .","; $sql .= " ".(!isset($this->id) ? 'NULL' : ((int) $this->id)) .",";
$sql .= " ".(!isset($this->code) ? 'NULL' : ((int) $this->code)).","; $sql .= " ".(!isset($this->code) ? 'NULL' : ((int) $this->code)).",";
$sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").","; $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
$sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->db->escape($this->active))).","; $sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->active)).",";
$sql .= ")"; $sql .= ")";
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++;
if (!$error) $this->errors[] = "Error ".$this->db->lasterror();
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
$this->db->rollback(); $this->db->rollback();
return -1 * $error; return -1 * $error;
} else { } else {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
} }