dolibarr 18.0.6
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
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}
getIncotermsForPDF()
Return incoterms informations for pdf display.
trait CommonIncoterm
Superclass for incoterm classes.
display_incoterms()
Return incoterms informations TODO Use a cache for label get.
setIncoterms($id_incoterm, $location)
Define incoterms values of current object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.