43 public $errors = array();
47 public $context = array();
58 public $libelle_facture;
84 public function create($user, $notrigger = 0)
91 if (isset($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);
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);
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;
224 $this->error =
"Error ".$this->db->lasterror();
243 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
244 $sql .=
" WHERE t.code = 'RECEP'";
245 $sql .=
" AND t.entity IN (".getEntity(
'c_payment_term').
")";
247 dol_syslog(get_class($this).
"::getDefaultId", LOG_DEBUG);
251 $obj = $this->
db->fetch_object(
$resql);
259 $this->error =
"Error ".$this->db->lasterror();
272 public function update($user =
null, $notrigger = 0)
274 global $conf, $langs;
280 if (isset($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);
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();
353 public function delete($user, $notrigger = 0)
355 global $conf, $langs;
358 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"c_payment_term";
359 $sql .=
" WHERE rowid = ".((int) $this->
id);
363 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
367 $this->errors[] =
"Error ".$this->db->lasterror();
372 foreach ($this->errors as $errmsg) {
373 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
374 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
376 $this->
db->rollback();
402 $object->fetch($fromid);
410 $object->context[
'createfromclone'] =
'createfromclone';
411 $result = $object->create($user);
415 $this->error = $object->error;
419 unset($object->context[
'createfromclone']);
426 $this->
db->rollback();
444 $this->sortorder =
'';
447 $this->libelle_facture =
'';
448 $this->type_cdr =
'';
450 $this->decalage =
'';
Class to manage Dolibarr database access.
Class to manage payment terms records in dictionary.
create($user, $notrigger=0)
Create in database.
__construct(DoliDB $db)
Constructor.
fetch($id, $code='')
Load object in memory from database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
getDefaultId()
Return id of default payment term.
initAsSpecimen()
Initialise an instance with random values.
update($user=null, $notrigger=0)
Update database.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$conf db
API class for accounts.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...