dolibarr  16.0.5
commonincoterm.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
28 trait CommonIncoterm
29 {
34  public $fk_incoterms;
35 
40  public $label_incoterms;
41 
46  public $location_incoterms;
47 
48 
49  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
56  public function display_incoterms()
57  {
58  // phpcs:enable
59  $out = '';
60 
61  $this->label_incoterms = '';
62  if (!empty($this->fk_incoterms)) {
63  $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
64  $result = $this->db->query($sql);
65  if ($result) {
66  $res = $this->db->fetch_object($result);
67  if ($res) {
68  $out .= $res->code;
69  }
70  }
71  }
72 
73  $out .= (($out && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms;
74 
75  return $out;
76  }
77 
83  public function getIncotermsForPDF()
84  {
85  $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
86  $resql = $this->db->query($sql);
87  if ($resql) {
88  $num = $this->db->num_rows($resql);
89  if ($num > 0) {
90  $res = $this->db->fetch_object($resql);
91  if ($res) {
92  return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
93  } else {
94  return $res;
95  }
96  } else {
97  return '';
98  }
99  } else {
100  $this->errors[] = $this->db->lasterror();
101  return false;
102  }
103  }
104 
112  public function setIncoterms($id_incoterm, $location)
113  {
114  if ($this->id && $this->table_element) {
115  $sql = "UPDATE ".$this->db->prefix().$this->table_element;
116  $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null");
117  $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
118  $sql .= " WHERE rowid = ".((int) $this->id);
119  dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
120  $resql = $this->db->query($sql);
121  if ($resql) {
122  $this->fk_incoterms = $id_incoterm;
123  $this->location_incoterms = $location;
124 
125  $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
126  $res = $this->db->query($sql);
127  if ($res) {
128  $obj = $this->db->fetch_object($res);
129  $this->label_incoterms = $obj->label_incoterms;
130  }
131  return 1;
132  } else {
133  $this->errors[] = $this->db->lasterror();
134  return -1;
135  }
136  } else {
137  return -1;
138  }
139  }
140 }
db
$conf db
API class for accounts.
Definition: inc.php:41
getIncotermsForPDF
getIncotermsForPDF()
Return incoterms informations for pdf display.
Definition: commonincoterm.class.php:83
CommonIncoterm
trait CommonIncoterm
Superclass for incoterm classes.
Definition: commonincoterm.class.php:29
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
display_incoterms
display_incoterms()
Return incoterms informations TODO Use a cache for label get.
Definition: commonincoterm.class.php:56
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setIncoterms
setIncoterms($id_incoterm, $location)
Define incoterms values of current object.
Definition: commonincoterm.class.php:112