dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
26
27
32{
36 public $db;
37
41 public $dirmodule;
45 public $targetmodule;
49 public $canvas;
53 public $card;
54
58 public $name;
62 public $definition;
66 public $description;
70 public $price_base_type;
74 public $accountancy_code_sell;
78 public $accountancy_code_buy;
82 public $fieldListName;
86 public $next_prev_filter;
87
91 public $object;
92
96 public $tpl = array();
97
101 public $field_list = array();
102
106 public $error = '';
107
111 public $errors = array();
112
113
123 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
124 {
125 $this->db = $db;
126 $this->dirmodule = $dirmodule;
127 $this->targetmodule = $targetmodule;
128 $this->canvas = $canvas;
129 $this->card = $card;
130
131 $this->name = "product";
132 $this->definition = "Product canvas (default)";
133 $this->fieldListName = "product_default";
134 $this->next_prev_filter = "canvas='product'";
135 }
136
137
138 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
147 public function assign_values(&$action, $id = 0, $ref = '')
148 {
149 // phpcs:enable
150 global $conf, $langs, $user, $mysoc, $canvas;
151 global $form, $formproduct;
152
153 '@phan-var-force Form $form';
154 '@phan-var-force FormProduct $formproduct';
155
156 $tmpobject = new Product($this->db);
157 if (!empty($id) || !empty($ref)) {
158 $tmpobject->fetch($id, $ref);
159 }
160 $this->object = $tmpobject;
161
162 foreach ($this->object as $key => $value) {
163 $this->tpl[$key] = $value;
164 }
165
166 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
167
168 // canvas
169 $this->tpl['canvas'] = $this->canvas;
170
171 // id
172 $this->tpl['id'] = $this->object->id;
173
174 // Ref
175 $this->tpl['ref'] = $this->object->ref;
176
177 // Label
178 $this->tpl['label'] = $this->object->label;
179
180 // Description
181 $this->tpl['description'] = nl2br($this->description);
182
183 // Statut
184 $this->tpl['status'] = $this->object->getLibStatut(2);
185
186 // Note
187 $this->tpl['note'] = $this->object->note_private;
188
189 if ($action == 'create') {
190 // Price
191 $this->tpl['price'] = $this->object->price;
192 $this->tpl['price_min'] = $this->object->price_min;
193 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
194
195 // VAT
196 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, null);
197 }
198
199 if ($action == 'view') {
200 $head = product_prepare_head($this->object);
201
202 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
203
204 $titre = $langs->trans("CardProduct".$this->object->type);
205 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
206 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
207 $this->tpl['showend'] = dol_get_fiche_end();
208
209 // Accountancy buy code
210 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
211 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
212
213 // Accountancy sell code
214 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
215 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
216 }
217
218 $this->tpl['finished'] = $this->object->finished;
219 $this->tpl['ref'] = $this->object->ref;
220 $this->tpl['label'] = $this->object->label;
221 $this->tpl['id'] = $this->object->id;
222 $this->tpl['type'] = $this->object->type;
223 $this->tpl['note'] = $this->object->note_private;
224 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
225
226 if ($action == 'create') {
227 // Title
228 $this->tpl['title'] = $langs->trans("NewProduct");
229 }
230
231 if ($action == 'edit') {
232 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref;
233 }
234
235 if ($action == 'create' || $action == 'edit') {
236 // Status
237 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
238 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
239
240 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
241 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
242
243 $this->tpl['description'] = $this->object->description;
244 $this->tpl['note'] = $this->object->note_private;
245
246 // Finished
247 $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
248 $this->tpl['finished'] = $form->selectarray('finished', $statutarray, $this->object->finished);
249
250 // Weight
251 $this->tpl['weight'] = $this->object->weight;
252 $this->tpl['weight_units'] = $formproduct->selectMeasuringUnits("weight_units", "weight", $this->object->weight_units, 0, 2);
253
254 // Length
255 $this->tpl['length'] = $this->object->length;
256 $this->tpl['length_units'] = $formproduct->selectMeasuringUnits("length_units", "size", $this->object->length_units, 0, 2);
257
258 // Surface
259 $this->tpl['surface'] = $this->object->surface;
260 $this->tpl['surface_units'] = $formproduct->selectMeasuringUnits("surface_units", "surface", $this->object->surface_units, 0, 2);
261
262 // Volume
263 $this->tpl['volume'] = $this->object->volume;
264 $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2);
265 }
266
267 if ($action == 'view') {
268 // Photo
269 $this->tpl['nblines'] = 4;
270 if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
271 $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
272 }
273
274 // Nature
275 $this->tpl['finished'] = $this->object->getLibFinished();
276
277 // Weight
278 if ($this->object->weight != '') {
279 $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units);
280 }
281
282 // Length
283 if ($this->object->length != '') {
284 $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units);
285 }
286
287 // Surface
288 if ($this->object->surface != '') {
289 $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units);
290 }
291
292 // Volume
293 if ($this->object->volume != '') {
294 $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units);
295 }
296
297 $this->tpl['fiche_end'] = dol_get_fiche_end();
298 }
299 }
300
301
307 private function getFieldListCanvas() // @phpstan-ignore-line
308 {
309 global $conf, $langs;
310
311 $this->field_list = array();
312
313 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
314 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
315 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
316 $sql .= " AND entity = ".$conf->entity;
317 $sql .= " ORDER BY rang ASC";
318
319 $resql = $this->db->query($sql);
320 if ($resql) {
321 $num = $this->db->num_rows($resql);
322
323 $i = 0;
324 while ($i < $num) {
325 $fieldlist = array();
326
327 $obj = $this->db->fetch_object($resql);
328
329 $fieldlist["id"] = $obj->rowid;
330 $fieldlist["name"] = $obj->name;
331 $fieldlist["alias"] = $obj->alias;
332 $fieldlist["title"] = $langs->trans($obj->title);
333 $fieldlist["align"] = $obj->align;
334 $fieldlist["sort"] = $obj->sort;
335 $fieldlist["search"] = $obj->search;
336 $fieldlist["visible"] = $obj->visible;
337 $fieldlist["enabled"] = verifCond($obj->enabled);
338 $fieldlist["order"] = $obj->rang;
339 array_push($this->field_list, $fieldlist);
340
341 $i++;
342 }
343 $this->db->free($resql);
344 } else {
345 dol_print_error($this->db, $sql);
346 }
347 }
348}
$id
Definition account.php:39
Class with controller methods for product canvas.
getFieldListCanvas()
Fetch field list.
$field_list
array<array{id:int,name:string,alias:string,title:string,align:string,sort:string,...
__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