90 public function create($user, $notrigger = 0)
97 if (isset($this->code)) {
98 $this->code = trim($this->code);
100 if (isset($this->sortorder)) {
101 $this->sortorder = trim($this->sortorder);
103 if (isset($this->active)) {
104 $this->active = trim($this->active);
106 if (isset($this->libelle)) {
107 $this->libelle = trim($this->libelle);
109 if (isset($this->libelle_facture)) {
110 $this->libelle_facture = trim($this->libelle_facture);
112 if (isset($this->type_cdr)) {
113 $this->type_cdr = trim($this->type_cdr);
115 if (isset($this->nbjour)) {
116 $this->nbjour = trim($this->nbjour);
118 if (isset($this->decalage)) {
119 $this->decalage = trim($this->decalage);
127 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_payment_term(";
130 $sql .=
"sortorder,";
133 $sql .=
"libelle_facture,";
137 $sql .=
") VALUES (";
138 $sql .=
" ".(!isset($this->entity) ?
getEntity(
'c_payment_term') :
"'".$this->db->escape($this->entity).
"'").
",";
139 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
140 $sql .=
" ".(!isset($this->sortorder) ?
'NULL' :
"'".$this->db->escape($this->sortorder).
"'").
",";
141 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
142 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
143 $sql .=
" ".(!isset($this->libelle_facture) ?
'NULL' :
"'".$this->db->escape($this->libelle_facture).
"'").
",";
144 $sql .=
" ".(!isset($this->type_cdr) ?
'NULL' :
"'".$this->db->escape($this->type_cdr).
"'").
",";
145 $sql .=
" ".(!isset($this->nbjour) ?
'NULL' :
"'".$this->db->escape($this->nbjour).
"'").
",";
146 $sql .=
" ".(!isset($this->decalage) ?
'NULL' :
"'".$this->db->escape($this->decalage).
"'");
151 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
152 $resql = $this->db->query($sql);
155 $this->errors[] =
"Error ".$this->db->lasterror();
159 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"c_payment_term");
164 foreach ($this->errors as $errmsg) {
165 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
166 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
168 $this->db->rollback();
184 public function fetch($id, $code =
'')
188 $sql .=
" t.entity,";
190 $sql .=
" t.sortorder,";
191 $sql .=
" t.active,";
192 $sql .=
" t.libelle,";
193 $sql .=
" t.libelle_facture,";
194 $sql .=
" t.type_cdr,";
195 $sql .=
" t.nbjour,";
196 $sql .=
" t.decalage";
197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
199 $sql .=
" WHERE t.rowid = ".((int) $id);
202 $sql .=
" WHERE t.code='".$this->db->escape($code).
"' AND t.entity IN (".
getEntity(
'payment_term').
")";
205 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
206 $resql = $this->db->query($sql);
208 if ($this->db->num_rows($resql)) {
209 $obj = $this->db->fetch_object($resql);
211 $this->
id = $obj->rowid;
213 $this->code = $obj->code;
214 $this->sortorder = $obj->sortorder;
215 $this->active = $obj->active;
216 $this->libelle = $obj->libelle;
217 $this->libelle_facture = $obj->libelle_facture;
218 $this->type_cdr = $obj->type_cdr;
219 $this->nbjour = $obj->nbjour;
220 $this->decalage = $obj->decalage;
222 $this->db->free($resql);
226 $this->error =
"Error ".$this->db->lasterror();
274 public function update($user =
null, $notrigger = 0)
276 global $conf, $langs;
282 if (isset($this->code)) {
283 $this->code = trim($this->code);
285 if (isset($this->sortorder)) {
286 $this->sortorder = trim($this->sortorder);
288 if (isset($this->active)) {
289 $this->active = trim($this->active);
291 if (isset($this->libelle)) {
292 $this->libelle = trim($this->libelle);
294 if (isset($this->libelle_facture)) {
295 $this->libelle_facture = trim($this->libelle_facture);
297 if (isset($this->type_cdr)) {
298 $this->type_cdr = trim($this->type_cdr);
300 if (isset($this->nbjour)) {
301 $this->nbjour = trim($this->nbjour);
303 if (isset($this->decalage)) {
304 $this->decalage = trim($this->decalage);
313 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_payment_term SET";
314 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
315 $sql .=
" sortorder=".(isset($this->sortorder) ? $this->sortorder :
"null").
",";
316 $sql .=
" active=".(isset($this->active) ? $this->active :
"null").
",";
317 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
318 $sql .=
" libelle_facture=".(isset($this->libelle_facture) ?
"'".$this->db->escape($this->libelle_facture).
"'" :
"null").
",";
319 $sql .=
" type_cdr=".(isset($this->type_cdr) ? $this->type_cdr :
"null").
",";
320 $sql .=
" nbjour=".(isset($this->nbjour) ? $this->nbjour :
"null").
",";
321 $sql .=
" decalage=".(isset($this->decalage) ? $this->decalage :
"null");
322 $sql .=
" WHERE rowid = ".((int) $this->
id);
326 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
327 $resql = $this->db->query($sql);
330 $this->errors[] =
"Error ".$this->db->lasterror();
335 foreach ($this->errors as $errmsg) {
336 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
337 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
339 $this->db->rollback();