84 public function create($user, $notrigger = 0)
91 if (isset($this->code)) {
92 $this->code = trim($this->code);
94 if (isset($this->sortorder)) {
95 $this->sortorder = trim($this->sortorder);
97 if (isset($this->active)) {
98 $this->active = trim($this->active);
100 if (isset($this->libelle)) {
101 $this->libelle = trim($this->libelle);
103 if (isset($this->libelle_facture)) {
104 $this->libelle_facture = trim($this->libelle_facture);
106 if (isset($this->type_cdr)) {
107 $this->type_cdr = trim($this->type_cdr);
109 if (isset($this->nbjour)) {
110 $this->nbjour = trim($this->nbjour);
112 if (isset($this->decalage)) {
113 $this->decalage = trim($this->decalage);
121 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_payment_term(";
124 $sql .=
"sortorder,";
127 $sql .=
"libelle_facture,";
131 $sql .=
") VALUES (";
132 $sql .=
" ".(!isset($this->entity) ?
getEntity(
'c_payment_term') :
"'".$this->db->escape($this->entity).
"'").
",";
133 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
134 $sql .=
" ".(!isset($this->sortorder) ?
'NULL' :
"'".$this->db->escape($this->sortorder).
"'").
",";
135 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
136 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
137 $sql .=
" ".(!isset($this->libelle_facture) ?
'NULL' :
"'".$this->db->escape($this->libelle_facture).
"'").
",";
138 $sql .=
" ".(!isset($this->type_cdr) ?
'NULL' :
"'".$this->db->escape($this->type_cdr).
"'").
",";
139 $sql .=
" ".(!isset($this->nbjour) ?
'NULL' :
"'".$this->db->escape($this->nbjour).
"'").
",";
140 $sql .=
" ".(!isset($this->decalage) ?
'NULL' :
"'".$this->db->escape($this->decalage).
"'");
145 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
146 $resql = $this->db->query($sql);
149 $this->errors[] =
"Error ".$this->db->lasterror();
153 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"c_payment_term");
158 foreach ($this->errors as $errmsg) {
159 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
160 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
162 $this->db->rollback();
178 public function fetch($id, $code =
'')
183 $sql .=
" t.entity,";
186 $sql .=
" t.sortorder,";
187 $sql .=
" t.active,";
188 $sql .=
" t.libelle,";
189 $sql .=
" t.libelle_facture,";
190 $sql .=
" t.type_cdr,";
191 $sql .=
" t.nbjour,";
192 $sql .=
" t.decalage";
195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
197 $sql .=
" WHERE t.rowid = ".((int) $id);
200 $sql .=
" WHERE t.code='".$this->db->escape($code).
"' AND t.entity IN (".
getEntity(
'payment_term').
")";
203 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
204 $resql = $this->db->query($sql);
206 if ($this->db->num_rows($resql)) {
207 $obj = $this->db->fetch_object($resql);
209 $this->
id = $obj->rowid;
211 $this->code = $obj->code;
212 $this->sortorder = $obj->sortorder;
213 $this->active = $obj->active;
214 $this->libelle = $obj->libelle;
215 $this->libelle_facture = $obj->libelle_facture;
216 $this->type_cdr = $obj->type_cdr;
217 $this->nbjour = $obj->nbjour;
218 $this->decalage = $obj->decalage;
220 $this->db->free($resql);
224 $this->error =
"Error ".$this->db->lasterror();
272 public function update($user =
null, $notrigger = 0)
274 global $conf, $langs;
280 if (isset($this->code)) {
281 $this->code = trim($this->code);
283 if (isset($this->sortorder)) {
284 $this->sortorder = trim($this->sortorder);
286 if (isset($this->active)) {
287 $this->active = trim($this->active);
289 if (isset($this->libelle)) {
290 $this->libelle = trim($this->libelle);
292 if (isset($this->libelle_facture)) {
293 $this->libelle_facture = trim($this->libelle_facture);
295 if (isset($this->type_cdr)) {
296 $this->type_cdr = trim($this->type_cdr);
298 if (isset($this->nbjour)) {
299 $this->nbjour = trim($this->nbjour);
301 if (isset($this->decalage)) {
302 $this->decalage = trim($this->decalage);
311 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_payment_term SET";
312 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
313 $sql .=
" sortorder=".(isset($this->sortorder) ? $this->sortorder :
"null").
",";
314 $sql .=
" active=".(isset($this->active) ? $this->active :
"null").
",";
315 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
316 $sql .=
" libelle_facture=".(isset($this->libelle_facture) ?
"'".$this->db->escape($this->libelle_facture).
"'" :
"null").
",";
317 $sql .=
" type_cdr=".(isset($this->type_cdr) ? $this->type_cdr :
"null").
",";
318 $sql .=
" nbjour=".(isset($this->nbjour) ? $this->nbjour :
"null").
",";
319 $sql .=
" decalage=".(isset($this->decalage) ? $this->decalage :
"null");
320 $sql .=
" WHERE rowid = ".((int) $this->
id);
324 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
325 $resql = $this->db->query($sql);
328 $this->errors[] =
"Error ".$this->db->lasterror();
333 foreach ($this->errors as $errmsg) {
334 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
335 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
337 $this->db->rollback();