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