dolibarr 20.0.2
actions_card_product.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2018 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
24include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
25
26
31{
35 public $db;
36
37 public $dirmodule;
38 public $targetmodule;
39 public $canvas;
40 public $card;
41
42 public $name;
43 public $definition;
44 public $description;
45 public $price_base_type;
46 public $accountancy_code_sell;
47 public $accountancy_code_buy;
48 public $fieldListName;
49 public $next_prev_filter;
50
52 public $object;
53
55 public $tpl = array();
56
57 // List of fields for action=list
58 public $field_list = array();
59
63 public $error = '';
64
68 public $errors = array();
69
70
80 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
81 {
82 $this->db = $db;
83 $this->dirmodule = $dirmodule;
84 $this->targetmodule = $targetmodule;
85 $this->canvas = $canvas;
86 $this->card = $card;
87
88 $this->name = "product";
89 $this->definition = "Product canvas (default)";
90 $this->fieldListName = "product_default";
91 $this->next_prev_filter = "canvas='product'";
92 }
93
94
95 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
104 public function assign_values(&$action, $id = 0, $ref = '')
105 {
106 // phpcs:enable
107 global $conf, $langs, $user, $mysoc, $canvas;
108 global $form, $formproduct;
109
110 $tmpobject = new Product($this->db);
111 if (!empty($id) || !empty($ref)) {
112 $tmpobject->fetch($id, $ref);
113 }
114 $this->object = $tmpobject;
115
116 foreach ($this->object as $key => $value) {
117 $this->tpl[$key] = $value;
118 }
119
120 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
121
122 // canvas
123 $this->tpl['canvas'] = $this->canvas;
124
125 // id
126 $this->tpl['id'] = $this->object->id;
127
128 // Ref
129 $this->tpl['ref'] = $this->object->ref;
130
131 // Label
132 $this->tpl['label'] = $this->object->label;
133
134 // Description
135 $this->tpl['description'] = nl2br($this->description);
136
137 // Statut
138 $this->tpl['status'] = $this->object->getLibStatut(2);
139
140 // Note
141 $this->tpl['note'] = $this->object->note_private;
142
143 if ($action == 'create') {
144 // Price
145 $this->tpl['price'] = $this->object->price;
146 $this->tpl['price_min'] = $this->object->price_min;
147 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
148
149 // VAT
150 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
151 }
152
153 if ($action == 'view') {
154 $head = product_prepare_head($this->object);
155
156 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
157
158 $titre = $langs->trans("CardProduct".$this->object->type);
159 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
160 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
161 $this->tpl['showend'] = dol_get_fiche_end();
162
163 // Accountancy buy code
164 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
165 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
166
167 // Accountancy sell code
168 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
169 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
170 }
171
172 $this->tpl['finished'] = $this->object->finished;
173 $this->tpl['ref'] = $this->object->ref;
174 $this->tpl['label'] = $this->object->label;
175 $this->tpl['id'] = $this->object->id;
176 $this->tpl['type'] = $this->object->type;
177 $this->tpl['note'] = $this->object->note_private;
178 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
179
180 if ($action == 'create') {
181 // Title
182 $this->tpl['title'] = $langs->trans("NewProduct");
183 }
184
185 if ($action == 'edit') {
186 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref;
187 }
188
189 if ($action == 'create' || $action == 'edit') {
190 // Status
191 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
192 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
193
194 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
195 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
196
197 $this->tpl['description'] = $this->object->description;
198 $this->tpl['note'] = $this->object->note_private;
199
200 // Finished
201 $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
202 $this->tpl['finished'] = $form->selectarray('finished', $statutarray, $this->object->finished);
203
204 // Weight
205 $this->tpl['weight'] = $this->object->weight;
206 $this->tpl['weight_units'] = $formproduct->selectMeasuringUnits("weight_units", "weight", $this->object->weight_units, 0, 2);
207
208 // Length
209 $this->tpl['length'] = $this->object->length;
210 $this->tpl['length_units'] = $formproduct->selectMeasuringUnits("length_units", "size", $this->object->length_units, 0, 2);
211
212 // Surface
213 $this->tpl['surface'] = $this->object->surface;
214 $this->tpl['surface_units'] = $formproduct->selectMeasuringUnits("surface_units", "surface", $this->object->surface_units, 0, 2);
215
216 // Volume
217 $this->tpl['volume'] = $this->object->volume;
218 $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2);
219 }
220
221 if ($action == 'view') {
222 // Photo
223 $this->tpl['nblines'] = 4;
224 if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
225 $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
226 }
227
228 // Nature
229 $this->tpl['finished'] = $this->object->getLibFinished();
230
231 // Weight
232 if ($this->object->weight != '') {
233 $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units);
234 }
235
236 // Length
237 if ($this->object->length != '') {
238 $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units);
239 }
240
241 // Surface
242 if ($this->object->surface != '') {
243 $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units);
244 }
245
246 // Volume
247 if ($this->object->volume != '') {
248 $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units);
249 }
250
251 $this->tpl['fiche_end'] = dol_get_fiche_end();
252 }
253 }
254
255
261 private function getFieldListCanvas() // @phpstan-ignore-line
262 {
263 global $conf, $langs;
264
265 $this->field_list = array();
266
267 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
268 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
269 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
270 $sql .= " AND entity = ".$conf->entity;
271 $sql .= " ORDER BY rang ASC";
272
273 $resql = $this->db->query($sql);
274 if ($resql) {
275 $num = $this->db->num_rows($resql);
276
277 $i = 0;
278 while ($i < $num) {
279 $fieldlist = array();
280
281 $obj = $this->db->fetch_object($resql);
282
283 $fieldlist["id"] = $obj->rowid;
284 $fieldlist["name"] = $obj->name;
285 $fieldlist["alias"] = $obj->alias;
286 $fieldlist["title"] = $langs->trans($obj->title);
287 $fieldlist["align"] = $obj->align;
288 $fieldlist["sort"] = $obj->sort;
289 $fieldlist["search"] = $obj->search;
290 $fieldlist["visible"] = $obj->visible;
291 $fieldlist["enabled"] = verifCond($obj->enabled);
292 $fieldlist["order"] = $obj->rang;
293
294 array_push($this->field_list, $fieldlist);
295
296 $i++;
297 }
298 $this->db->free($resql);
299 } else {
300 dol_print_error($this->db, $sql);
301 }
302 }
303}
Class with controller methods for product canvas.
getFieldListCanvas()
Fetch field list.
__construct($db, $dirmodule, $targetmodule, $canvas, $card)
Constructor.
assign_values(&$action, $id=0, $ref='')
Assign custom values for canvas (for example into this->tpl to be used by templates)
Class to manage products or services.
const TYPE_SERVICE
Service.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formatted error messages to output (Used to show messages on html output).
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
product_prepare_head($object)
Prepare array with list of tabs.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140