dolibarr 19.0.4
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 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
24
25
30{
34 public $db;
35
36 public $dirmodule;
37 public $module;
38 public $label;
39 public $price_base_type;
40 public $accountancy_code_sell;
41 public $accountancy_code_buy;
42 public $targetmodule;
43 public $canvas;
44 public $card;
45
46 public $name;
47 public $definition;
48 public $fieldListName;
49 public $next_prev_filter;
50
52 public $object;
53
55 public $tpl = array();
56
57 // List of fiels for action=list
58 public $field_list = array();
59
60 public $id;
61 public $ref;
62 public $description;
63 public $note;
64 public $price;
65 public $price_min;
66
70 public $error = '';
71
75 public $errors = array();
76
77
87 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
88 {
89 $this->db = $db;
90 $this->dirmodule = $dirmodule;
91 $this->targetmodule = $targetmodule;
92 $this->canvas = $canvas;
93 $this->card = $card;
94
95 $this->module = "service";
96 $this->name = "service";
97 $this->definition = "Services canvas";
98 $this->fieldListName = "product_service";
99 $this->next_prev_filter = "canvas='service'";
100 }
101
102
103 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
112 public function assign_values(&$action, $id = 0, $ref = '')
113 {
114 // phpcs:enable
115 global $conf, $langs, $user, $mysoc, $canvas;
116 global $form;
117
118 $tmpobject = new Product($this->db);
119 if (!empty($id) || !empty($ref)) {
120 $tmpobject->fetch($id, $ref);
121 }
122 $this->object = $tmpobject;
123
124 foreach ($this->object as $key => $value) {
125 $this->tpl[$key] = $value;
126 }
127
128 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
129
130 // canvas
131 $this->tpl['canvas'] = $this->canvas;
132
133 // id
134 $this->tpl['id'] = $this->id;
135
136 // Ref
137 $this->tpl['ref'] = $this->ref;
138
139 // Label
140 $this->tpl['label'] = $this->label;
141
142 // Description
143 $this->tpl['description'] = nl2br($this->description);
144
145 // Statut
146 $this->tpl['status'] = $this->object->getLibStatut(2);
147
148 // Note
149 $this->tpl['note'] = nl2br($this->note);
150
151 if ($action == 'create') {
152 // Price
153 $this->tpl['price'] = $this->price;
154 $this->tpl['price_min'] = $this->price_min;
155 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
156
157 // VAT
158 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
159 }
160
161 if ($action == 'view') {
162 $head = product_prepare_head($this->object);
163
164 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
165
166 $titre = $langs->trans("CardProduct".$this->object->type);
167 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
168 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
169 $this->tpl['showend'] = dol_get_fiche_end();
170
171 // Accountancy buy code
172 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
173 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
174
175 // Accountancy sell code
176 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
177 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
178 }
179
180 $this->tpl['finished'] = $this->object->finished;
181 $this->tpl['ref'] = $this->object->ref;
182 $this->tpl['label'] = $this->object->label;
183 $this->tpl['id'] = $this->object->id;
184 $this->tpl['type'] = $this->object->type;
185 $this->tpl['note'] = $this->object->note_private;
186 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
187
188 // Duration
189 $this->tpl['duration_value'] = $this->object->duration_value;
190
191 if ($action == 'create') {
192 // Title
193 $this->tpl['title'] = $langs->trans("NewService");
194 }
195
196 if ($action == 'edit') {
197 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
198 }
199
200 if ($action == 'create' || $action == 'edit') {
201 // Status
202 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
203 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
204
205 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
206 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
207
208 $this->tpl['description'] = $this->description;
209 $this->tpl['note'] = $this->note;
210
211 // Duration unit
212 // TODO creer fonction
213 $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
214 $duration_unit .= '&nbsp; ';
215 $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
216 $duration_unit .= '&nbsp; ';
217 $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
218 $duration_unit .= '&nbsp; ';
219 $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
220 $duration_unit .= '&nbsp; ';
221 $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
222 $this->tpl['duration_unit'] = $duration_unit;
223 }
224
225 if ($action == 'view') {
226 // Photo
227 $this->tpl['nblines'] = 4;
228 if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
229 $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
230 }
231
232 // Duration
233 $dur = array();
234 if ($this->object->duration_value > 1) {
235 $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
236 } elseif ($this->object->duration_value > 0) {
237 $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
238 }
239 $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
240
241 $this->tpl['fiche_end'] = dol_get_fiche_end();
242 }
243 }
244
245
251 private function getFieldListCanvas()
252 {
253 global $conf, $langs;
254
255 $this->field_list = array();
256
257 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
258 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
259 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
260 $sql .= " AND entity = ".$conf->entity;
261 $sql .= " ORDER BY rang ASC";
262
263 $resql = $this->db->query($sql);
264 if ($resql) {
265 $num = $this->db->num_rows($resql);
266
267 $i = 0;
268 while ($i < $num) {
269 $fieldlist = array();
270
271 $obj = $this->db->fetch_object($resql);
272
273 $fieldlist["id"] = $obj->rowid;
274 $fieldlist["name"] = $obj->name;
275 $fieldlist["alias"] = $obj->alias;
276 $fieldlist["title"] = $langs->trans($obj->title);
277 $fieldlist["align"] = $obj->align;
278 $fieldlist["sort"] = $obj->sort;
279 $fieldlist["search"] = $obj->search;
280 $fieldlist["visible"] = $obj->visible;
281 $fieldlist["enabled"] = verifCond($obj->enabled);
282 $fieldlist["order"] = $obj->rang;
283
284 array_push($this->field_list, $fieldlist);
285
286 $i++;
287 }
288 $this->db->free($resql);
289 } else {
290 dol_print_error($this->db, $sql);
291 }
292 }
293}
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.
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 formated error messages to output (Used to show messages on html output).
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
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:124