dolibarr 22.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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
37trait CommonIncoterm
38{
43 public $fk_incoterms;
44
49 public $label_incoterms;
50
55 public $location_incoterms;
56
57
58 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
65 public function display_incoterms()
66 {
67 // phpcs:enable
68 $out = '';
69
70 $this->label_incoterms = '';
71 if (!empty($this->fk_incoterms)) {
72 $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
73 $result = $this->db->query($sql);
74 if ($result) {
75 $res = $this->db->fetch_object($result);
76 if ($res) {
77 $out .= $res->code;
78 }
79 }
80 }
81
82 $out .= (($out && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms;
83
84 return $out;
85 }
86
92 public function getIncotermsForPDF()
93 {
94 global $langs;
95
96 $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
97 $resql = $this->db->query($sql);
98 if ($resql) {
99 $num = $this->db->num_rows($resql);
100 if ($num > 0) {
101 $res = $this->db->fetch_object($resql);
102 if ($res) {
103 return $langs->trans("IncotermLabel").': '.$res->code.' - '.$this->location_incoterms;
104 } else {
105 return $res;
106 }
107 } else {
108 return '';
109 }
110 } else {
111 $this->errors[] = $this->db->lasterror();
112 return false;
113 }
114 }
115
123 public function setIncoterms($id_incoterm, $location)
124 {
125 if ($this->id && $this->table_element) {
126 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
127 $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null");
128 $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
129 $sql .= " WHERE rowid = ".((int) $this->id);
130 dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
131 $resql = $this->db->query($sql);
132 if ($resql) {
133 $this->fk_incoterms = $id_incoterm;
134 $this->location_incoterms = $location;
135
136 $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
137 $res = $this->db->query($sql);
138 if ($res) {
139 $obj = $this->db->fetch_object($res);
140 $this->label_incoterms = $obj->label_incoterms;
141 }
142 return 1;
143 } else {
144 $this->errors[] = $this->db->lasterror();
145 return -1;
146 }
147 } else {
148 return -1;
149 }
150 }
151}
getIncotermsForPDF()
Return incoterms information for pdf display.
display_incoterms()
Return incoterms information 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.