dolibarr  13.0.2
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  {
64  $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
65  $result = $this->db->query($sql);
66  if ($result)
67  {
68  $res = $this->db->fetch_object($result);
69  $out .= $res->code;
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 '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
86  $resql = $this->db->query($sql);
87  if ($resql)
88  {
89  $num = $this->db->num_rows($resql);
90  if ($num > 0)
91  {
92  $res = $this->db->fetch_object($resql);
93  return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
94  } else {
95  return '';
96  }
97  } else {
98  $this->errors[] = $this->db->lasterror();
99  return false;
100  }
101  }
102 
110  public function setIncoterms($id_incoterm, $location)
111  {
112  if ($this->id && $this->table_element)
113  {
114  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
115  $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null");
116  $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
117  $sql .= " WHERE rowid = ".$this->id;
118  dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
119  $resql = $this->db->query($sql);
120  if ($resql)
121  {
122  $this->fk_incoterms = $id_incoterm;
123  $this->location_incoterms = $location;
124 
125  $sql = 'SELECT libelle as label_incotermsFROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
126  $res = $this->db->query($sql);
127  if ($res)
128  {
129  $obj = $this->db->fetch_object($res);
130  $this->label_incoterms = $obj->label_incoterms;
131  }
132  return 1;
133  } else {
134  $this->errors[] = $this->db->lasterror();
135  return -1;
136  }
137  } else {
138  return -1;
139  }
140  }
141 }
display_incoterms()
Return incoterms informations TODO Use a cache for label get.
getIncotermsForPDF()
Return incoterms informations for pdf display.
$conf db
API class for accounts.
Definition: inc.php:54
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
trait CommonIncoterm
Superclass for incoterm classes.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
setIncoterms($id_incoterm, $location)
Define incoterms values of current object.