91 public function create($user, $notrigger = 0)
98 if (isset($this->code)) {
99 $this->code = trim($this->code);
101 if (isset($this->sortorder)) {
102 $this->sortorder = trim($this->sortorder);
104 if (isset($this->active)) {
105 $this->active = trim($this->active);
107 if (isset($this->libelle)) {
108 $this->libelle = trim($this->libelle);
110 if (isset($this->libelle_facture)) {
111 $this->libelle_facture = trim($this->libelle_facture);
113 if (isset($this->type_cdr)) {
114 $this->type_cdr = trim($this->type_cdr);
116 if (isset($this->nbjour)) {
117 $this->nbjour = trim($this->nbjour);
119 if (isset($this->decalage)) {
120 $this->decalage = trim($this->decalage);
128 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_payment_term(";
131 $sql .=
"sortorder,";
134 $sql .=
"libelle_facture,";
138 $sql .=
") VALUES (";
139 $sql .=
" ".(!isset($this->entity) ?
getEntity(
'c_payment_term') :
"'".$this->db->escape($this->entity).
"'").
",";
140 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
141 $sql .=
" ".(!isset($this->sortorder) ?
'NULL' :
"'".$this->db->escape($this->sortorder).
"'").
",";
142 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
143 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
144 $sql .=
" ".(!isset($this->libelle_facture) ?
'NULL' :
"'".$this->db->escape($this->libelle_facture).
"'").
",";
145 $sql .=
" ".(!isset($this->type_cdr) ?
'NULL' :
"'".$this->db->escape($this->type_cdr).
"'").
",";
146 $sql .=
" ".(!isset($this->nbjour) ?
'NULL' :
"'".$this->db->escape($this->nbjour).
"'").
",";
147 $sql .=
" ".(!isset($this->decalage) ?
'NULL' :
"'".$this->db->escape($this->decalage).
"'");
152 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
153 $resql = $this->db->query($sql);
156 $this->errors[] =
"Error ".$this->db->lasterror();
160 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"c_payment_term");
165 foreach ($this->errors as $errmsg) {
166 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
167 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
169 $this->db->rollback();
185 public function fetch($id, $code =
'')
189 $sql .=
" t.entity,";
191 $sql .=
" t.sortorder,";
192 $sql .=
" t.active,";
193 $sql .=
" t.libelle,";
194 $sql .=
" t.libelle_facture,";
195 $sql .=
" t.type_cdr,";
196 $sql .=
" t.nbjour,";
197 $sql .=
" t.decalage";
198 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
200 $sql .=
" WHERE t.rowid = ".((int) $id);
203 $sql .=
" WHERE t.code='".$this->db->escape($code).
"' AND t.entity IN (".
getEntity(
'payment_term').
")";
206 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
207 $resql = $this->db->query($sql);
209 if ($this->db->num_rows($resql)) {
210 $obj = $this->db->fetch_object($resql);
212 $this->
id = $obj->rowid;
214 $this->code = $obj->code;
215 $this->sortorder = $obj->sortorder;
216 $this->active = $obj->active;
217 $this->libelle = $obj->libelle;
218 $this->libelle_facture = $obj->libelle_facture;
219 $this->type_cdr = $obj->type_cdr;
220 $this->nbjour = $obj->nbjour;
221 $this->decalage = $obj->decalage;
223 $this->db->free($resql);
227 $this->error =
"Error ".$this->db->lasterror();
275 public function update($user =
null, $notrigger = 0)
277 global $conf, $langs;
283 if (isset($this->code)) {
284 $this->code = trim($this->code);
286 if (isset($this->sortorder)) {
287 $this->sortorder = trim($this->sortorder);
289 if (isset($this->active)) {
290 $this->active = trim($this->active);
292 if (isset($this->libelle)) {
293 $this->libelle = trim($this->libelle);
295 if (isset($this->libelle_facture)) {
296 $this->libelle_facture = trim($this->libelle_facture);
298 if (isset($this->type_cdr)) {
299 $this->type_cdr = trim($this->type_cdr);
301 if (isset($this->nbjour)) {
302 $this->nbjour = trim($this->nbjour);
304 if (isset($this->decalage)) {
305 $this->decalage = trim($this->decalage);
314 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_payment_term SET";
315 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
316 $sql .=
" sortorder=".(isset($this->sortorder) ? $this->sortorder :
"null").
",";
317 $sql .=
" active=".(isset($this->active) ? $this->active :
"null").
",";
318 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
319 $sql .=
" libelle_facture=".(isset($this->libelle_facture) ?
"'".$this->db->escape($this->libelle_facture).
"'" :
"null").
",";
320 $sql .=
" type_cdr=".(isset($this->type_cdr) ? $this->type_cdr :
"null").
",";
321 $sql .=
" nbjour=".(isset($this->nbjour) ? $this->nbjour :
"null").
",";
322 $sql .=
" decalage=".(isset($this->decalage) ? $this->decalage :
"null");
323 $sql .=
" WHERE rowid = ".((int) $this->
id);
327 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
328 $resql = $this->db->query($sql);
331 $this->errors[] =
"Error ".$this->db->lasterror();
336 foreach ($this->errors as $errmsg) {
337 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
338 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
340 $this->db->rollback();