dolibarr 20.0.0
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 *
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 $module;
39 public $label;
40 public $price_base_type;
41 public $accountancy_code_sell;
42 public $accountancy_code_buy;
43 public $targetmodule;
44 public $canvas;
45 public $card;
46
47 public $name;
48 public $definition;
49 public $fieldListName;
50 public $next_prev_filter;
51
53 public $object;
54
56 public $tpl = array();
57
58 // List of fields for action=list
59 public $field_list = array();
60
61 public $id;
62 public $ref;
63 public $description;
64 public $note;
65 public $price;
66 public $price_min;
67
71 public $error = '';
72
76 public $errors = array();
77
78
88 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
89 {
90 $this->db = $db;
91 $this->dirmodule = $dirmodule;
92 $this->targetmodule = $targetmodule;
93 $this->canvas = $canvas;
94 $this->card = $card;
95
96 $this->module = "service";
97 $this->name = "service";
98 $this->definition = "Services canvas";
99 $this->fieldListName = "product_service";
100 $this->next_prev_filter = "canvas='service'";
101 }
102
103
104 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
113 public function assign_values(&$action, $id = 0, $ref = '')
114 {
115 // phpcs:enable
116 global $conf, $langs, $user, $mysoc, $canvas;
117 global $form;
118
119 $tmpobject = new Product($this->db);
120 if (!empty($id) || !empty($ref)) {
121 $tmpobject->fetch($id, $ref);
122 }
123 $this->object = $tmpobject;
124
125 foreach ($this->object as $key => $value) {
126 $this->tpl[$key] = $value;
127 }
128
129 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
130
131 // canvas
132 $this->tpl['canvas'] = $this->canvas;
133
134 // id
135 $this->tpl['id'] = $this->id;
136
137 // Ref
138 $this->tpl['ref'] = $this->ref;
139
140 // Label
141 $this->tpl['label'] = $this->label;
142
143 // Description
144 $this->tpl['description'] = nl2br($this->description);
145
146 // Statut
147 $this->tpl['status'] = $this->object->getLibStatut(2);
148
149 // Note
150 $this->tpl['note'] = nl2br($this->note);
151
152 if ($action == 'create') {
153 // Price
154 $this->tpl['price'] = $this->price;
155 $this->tpl['price_min'] = $this->price_min;
156 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
157
158 // VAT
159 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
160 }
161
162 if ($action == 'view') {
163 $head = product_prepare_head($this->object);
164
165 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
166
167 $titre = $langs->trans("CardProduct".$this->object->type);
168 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
169 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
170 $this->tpl['showend'] = dol_get_fiche_end();
171
172 // Accountancy buy code
173 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
174 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
175
176 // Accountancy sell code
177 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
178 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
179 }
180
181 $this->tpl['finished'] = $this->object->finished;
182 $this->tpl['ref'] = $this->object->ref;
183 $this->tpl['label'] = $this->object->label;
184 $this->tpl['id'] = $this->object->id;
185 $this->tpl['type'] = $this->object->type;
186 $this->tpl['note'] = $this->object->note_private;
187 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
188
189 // Duration
190 $this->tpl['duration_value'] = $this->object->duration_value;
191
192 if ($action == 'create') {
193 // Title
194 $this->tpl['title'] = $langs->trans("NewService");
195 }
196
197 if ($action == 'edit') {
198 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
199 }
200
201 if ($action == 'create' || $action == 'edit') {
202 // Status
203 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
204 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
205
206 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
207 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
208
209 $this->tpl['description'] = $this->description;
210 $this->tpl['note'] = $this->note;
211
212 // Duration unit
213 // TODO creer fonction
214 $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
215 $duration_unit .= '&nbsp; ';
216 $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
217 $duration_unit .= '&nbsp; ';
218 $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
219 $duration_unit .= '&nbsp; ';
220 $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
221 $duration_unit .= '&nbsp; ';
222 $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
223 $this->tpl['duration_unit'] = $duration_unit;
224 }
225
226 if ($action == 'view') {
227 // Photo
228 $this->tpl['nblines'] = 4;
229 if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
230 $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
231 }
232
233 // Duration
234 $dur = array();
235 if ($this->object->duration_value > 1) {
236 $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
237 } elseif ($this->object->duration_value > 0) {
238 $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
239 }
240 $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
241
242 $this->tpl['fiche_end'] = dol_get_fiche_end();
243 }
244 }
245
246
252 private function getFieldListCanvas() // @phpstan-ignore-line
253 {
254 global $conf, $langs;
255
256 $this->field_list = array();
257
258 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
259 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
260 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
261 $sql .= " AND entity = ".$conf->entity;
262 $sql .= " ORDER BY rang ASC";
263
264 $resql = $this->db->query($sql);
265 if ($resql) {
266 $num = $this->db->num_rows($resql);
267
268 $i = 0;
269 while ($i < $num) {
270 $fieldlist = array();
271
272 $obj = $this->db->fetch_object($resql);
273
274 $fieldlist["id"] = $obj->rowid;
275 $fieldlist["name"] = $obj->name;
276 $fieldlist["alias"] = $obj->alias;
277 $fieldlist["title"] = $langs->trans($obj->title);
278 $fieldlist["align"] = $obj->align;
279 $fieldlist["sort"] = $obj->sort;
280 $fieldlist["search"] = $obj->search;
281 $fieldlist["visible"] = $obj->visible;
282 $fieldlist["enabled"] = verifCond($obj->enabled);
283 $fieldlist["order"] = $obj->rang;
284
285 array_push($this->field_list, $fieldlist);
286
287 $i++;
288 }
289 $this->db->free($resql);
290 } else {
291 dol_print_error($this->db, $sql);
292 }
293 }
294}
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...
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:142