dolibarr 21.0.0-beta
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 $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
95 $resql = $this->db->query($sql);
96 if ($resql) {
97 $num = $this->db->num_rows($resql);
98 if ($num > 0) {
99 $res = $this->db->fetch_object($resql);
100 if ($res) {
101 return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
102 } else {
103 return $res;
104 }
105 } else {
106 return '';
107 }
108 } else {
109 $this->errors[] = $this->db->lasterror();
110 return false;
111 }
112 }
113
121 public function setIncoterms($id_incoterm, $location)
122 {
123 if ($this->id && $this->table_element) {
124 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
125 $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null");
126 $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null");
127 $sql .= " WHERE rowid = ".((int) $this->id);
128 dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG);
129 $resql = $this->db->query($sql);
130 if ($resql) {
131 $this->fk_incoterms = $id_incoterm;
132 $this->location_incoterms = $location;
133
134 $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms;
135 $res = $this->db->query($sql);
136 if ($res) {
137 $obj = $this->db->fetch_object($res);
138 $this->label_incoterms = $obj->label_incoterms;
139 }
140 return 1;
141 } else {
142 $this->errors[] = $this->db->lasterror();
143 return -1;
144 }
145 } else {
146 return -1;
147 }
148 }
149}
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.