dolibarr 21.0.0-beta
actions_card_service.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 $module;
49 public $label;
53 public $price_base_type;
57 public $accountancy_code_sell;
61 public $accountancy_code_buy;
65 public $targetmodule;
69 public $canvas;
73 public $card;
74
78 public $name;
82 public $definition;
86 public $fieldListName;
90 public $next_prev_filter;
91
95 public $object;
96
98 public $tpl = array();
99
100 // List of fields for action=list
101 public $field_list = array();
102
106 public $id;
110 public $ref;
114 public $description;
118 public $note;
122 public $price;
126 public $price_min;
127
131 public $error = '';
132
136 public $errors = array();
137
138
148 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
149 {
150 $this->db = $db;
151 $this->dirmodule = $dirmodule;
152 $this->targetmodule = $targetmodule;
153 $this->canvas = $canvas;
154 $this->card = $card;
155
156 $this->module = "service";
157 $this->name = "service";
158 $this->definition = "Services canvas";
159 $this->fieldListName = "product_service";
160 $this->next_prev_filter = "canvas:=:'service'";
161 }
162
163
164 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
173 public function assign_values(&$action, $id = 0, $ref = '')
174 {
175 // phpcs:enable
176 global $conf, $langs, $user, $mysoc, $canvas;
177 global $form;
178
179 $tmpobject = new Product($this->db);
180 if (!empty($id) || !empty($ref)) {
181 $tmpobject->fetch($id, $ref);
182 }
183 $this->object = $tmpobject;
184
185 foreach ($this->object as $key => $value) {
186 $this->tpl[$key] = $value;
187 }
188
189 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
190
191 // canvas
192 $this->tpl['canvas'] = $this->canvas;
193
194 // id
195 $this->tpl['id'] = $this->id;
196
197 // Ref
198 $this->tpl['ref'] = $this->ref;
199
200 // Label
201 $this->tpl['label'] = $this->label;
202
203 // Description
204 $this->tpl['description'] = nl2br($this->description);
205
206 // Statut
207 $this->tpl['status'] = $this->object->getLibStatut(2);
208
209 // Note
210 $this->tpl['note'] = nl2br($this->note);
211
212 if ($action == 'create') {
213 // Price
214 $this->tpl['price'] = $this->price;
215 $this->tpl['price_min'] = $this->price_min;
216 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
217
218 // VAT
219 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, null);
220 }
221
222 if ($action == 'view') {
223 $head = product_prepare_head($this->object);
224
225 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
226
227 $titre = $langs->trans("CardProduct".$this->object->type);
228 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
229 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
230 $this->tpl['showend'] = dol_get_fiche_end();
231
232 // Accountancy buy code
233 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
234 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
235
236 // Accountancy sell code
237 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
238 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
239 }
240
241 $this->tpl['finished'] = $this->object->finished;
242 $this->tpl['ref'] = $this->object->ref;
243 $this->tpl['label'] = $this->object->label;
244 $this->tpl['id'] = $this->object->id;
245 $this->tpl['type'] = $this->object->type;
246 $this->tpl['note'] = $this->object->note_private;
247 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
248
249 // Duration
250 $this->tpl['duration_value'] = $this->object->duration_value;
251
252 if ($action == 'create') {
253 // Title
254 $this->tpl['title'] = $langs->trans("NewService");
255 }
256
257 if ($action == 'edit') {
258 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
259 }
260
261 if ($action == 'create' || $action == 'edit') {
262 // Status
263 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
264 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
265
266 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
267 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
268
269 $this->tpl['description'] = $this->description;
270 $this->tpl['note'] = $this->note;
271
272 // Duration unit
273 // TODO creer fonction
274 $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
275 $duration_unit .= '&nbsp; ';
276 $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
277 $duration_unit .= '&nbsp; ';
278 $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
279 $duration_unit .= '&nbsp; ';
280 $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
281 $duration_unit .= '&nbsp; ';
282 $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
283 $this->tpl['duration_unit'] = $duration_unit;
284 }
285
286 if ($action == 'view') {
287 // Photo
288 $this->tpl['nblines'] = 4;
289 if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
290 $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
291 }
292
293 // Duration
294 $dur = array();
295 if ($this->object->duration_value > 1) {
296 $dur = array("h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years"));
297 } elseif ($this->object->duration_value > 0) {
298 $dur = array("h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year"));
299 }
300 $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
301
302 $this->tpl['fiche_end'] = dol_get_fiche_end();
303 }
304 }
305
306
312 private function getFieldListCanvas() // @phpstan-ignore-line
313 {
314 global $conf, $langs;
315
316 $this->field_list = array();
317
318 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
319 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
320 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
321 $sql .= " AND entity = ".$conf->entity;
322 $sql .= " ORDER BY rang ASC";
323
324 $resql = $this->db->query($sql);
325 if ($resql) {
326 $num = $this->db->num_rows($resql);
327
328 $i = 0;
329 while ($i < $num) {
330 $fieldlist = array();
331
332 $obj = $this->db->fetch_object($resql);
333
334 $fieldlist["id"] = $obj->rowid;
335 $fieldlist["name"] = $obj->name;
336 $fieldlist["alias"] = $obj->alias;
337 $fieldlist["title"] = $langs->trans($obj->title);
338 $fieldlist["align"] = $obj->align;
339 $fieldlist["sort"] = $obj->sort;
340 $fieldlist["search"] = $obj->search;
341 $fieldlist["visible"] = $obj->visible;
342 $fieldlist["enabled"] = verifCond($obj->enabled);
343 $fieldlist["order"] = $obj->rang;
344
345 array_push($this->field_list, $fieldlist);
346
347 $i++;
348 }
349 $this->db->free($resql);
350 } else {
351 dol_print_error($this->db, $sql);
352 }
353 }
354}
Class with controller methods for service canvas.
__construct($db, $dirmodule, $targetmodule, $canvas, $card)
Constructor.
getFieldListCanvas()
Fetch field list.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
product_prepare_head($object)
Prepare array with list of tabs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152