119 public function create($user, $notrigger = 0)
121 global $conf, $langs;
126 if (isset($this->code)) {
127 $this->code = trim($this->code);
129 if (isset($this->sortorder)) {
130 $this->sortorder = trim($this->sortorder);
132 if (isset($this->active)) {
133 $this->active = trim($this->active);
135 if (isset($this->libelle)) {
136 $this->libelle = trim($this->libelle);
138 if (isset($this->libelle_facture)) {
139 $this->libelle_facture = trim($this->libelle_facture);
141 if (isset($this->type_cdr)) {
142 $this->type_cdr = trim($this->type_cdr);
144 if (isset($this->nbjour)) {
145 $this->nbjour = trim($this->nbjour);
147 if (isset($this->decalage)) {
148 $this->decalage = trim($this->decalage);
156 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_payment_term(";
159 $sql .=
"sortorder,";
162 $sql .=
"libelle_facture,";
166 $sql .=
") VALUES (";
167 $sql .=
" ".(!isset($this->entity) ?
getEntity(
'c_payment_term') :
"'".$this->db->escape($this->entity).
"'").
",";
168 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
169 $sql .=
" ".(!isset($this->sortorder) ?
'NULL' :
"'".$this->db->escape($this->sortorder).
"'").
",";
170 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
171 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
172 $sql .=
" ".(!isset($this->libelle_facture) ?
'NULL' :
"'".$this->db->escape($this->libelle_facture).
"'").
",";
173 $sql .=
" ".(!isset($this->type_cdr) ?
'NULL' :
"'".$this->db->escape($this->type_cdr).
"'").
",";
174 $sql .=
" ".(!isset($this->nbjour) ?
'NULL' :
"'".$this->db->escape($this->nbjour).
"'").
",";
175 $sql .=
" ".(!isset($this->decalage) ?
'NULL' :
"'".$this->db->escape($this->decalage).
"'");
180 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
181 $resql = $this->db->query($sql);
184 $this->errors[] =
"Error ".$this->db->lasterror();
188 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"c_payment_term");
193 foreach ($this->errors as $errmsg) {
194 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
195 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
197 $this->db->rollback();
213 public function fetch($id, $code =
'')
217 $sql .=
" t.entity,";
219 $sql .=
" t.sortorder,";
220 $sql .=
" t.active,";
221 $sql .=
" t.libelle,";
222 $sql .=
" t.libelle_facture,";
223 $sql .=
" t.type_cdr,";
224 $sql .=
" t.nbjour,";
225 $sql .=
" t.decalage";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
228 $sql .=
" WHERE t.rowid = ".((int) $id);
231 $sql .=
" WHERE t.code='".$this->db->escape($code).
"' AND t.entity IN (".
getEntity(
'payment_term').
")";
234 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
235 $resql = $this->db->query($sql);
237 if ($this->db->num_rows($resql)) {
238 $obj = $this->db->fetch_object($resql);
240 $this->
id = $obj->rowid;
242 $this->code = $obj->code;
243 $this->sortorder = $obj->sortorder;
244 $this->active = $obj->active;
245 $this->libelle = $obj->libelle;
246 $this->libelle_facture = $obj->libelle_facture;
247 $this->type_cdr = $obj->type_cdr;
248 $this->nbjour = $obj->nbjour;
249 $this->decalage = $obj->decalage;
251 $this->db->free($resql);
255 $this->error =
"Error ".$this->db->lasterror();
303 public function update($user =
null, $notrigger = 0)
305 global $conf, $langs;
311 if (isset($this->code)) {
312 $this->code = trim($this->code);
314 if (isset($this->sortorder)) {
315 $this->sortorder = trim($this->sortorder);
317 if (isset($this->active)) {
318 $this->active = trim($this->active);
320 if (isset($this->libelle)) {
321 $this->libelle = trim($this->libelle);
323 if (isset($this->libelle_facture)) {
324 $this->libelle_facture = trim($this->libelle_facture);
326 if (isset($this->type_cdr)) {
327 $this->type_cdr = trim($this->type_cdr);
329 if (isset($this->nbjour)) {
330 $this->nbjour = trim($this->nbjour);
332 if (isset($this->decalage)) {
333 $this->decalage = trim($this->decalage);
342 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_payment_term SET";
343 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
344 $sql .=
" sortorder=".(isset($this->sortorder) ? $this->sortorder :
"null").
",";
345 $sql .=
" active=".(isset($this->active) ? $this->active :
"null").
",";
346 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
347 $sql .=
" libelle_facture=".(isset($this->libelle_facture) ?
"'".$this->db->escape($this->libelle_facture).
"'" :
"null").
",";
348 $sql .=
" type_cdr=".(isset($this->type_cdr) ? $this->type_cdr :
"null").
",";
349 $sql .=
" nbjour=".(isset($this->nbjour) ? $this->nbjour :
"null").
",";
350 $sql .=
" decalage=".(isset($this->decalage) ? $this->decalage :
"null");
351 $sql .=
" WHERE rowid = ".((int) $this->
id);
355 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
356 $resql = $this->db->query($sql);
359 $this->errors[] =
"Error ".$this->db->lasterror();
364 foreach ($this->errors as $errmsg) {
365 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
366 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
368 $this->db->rollback();