152 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
155 $this->dirmodule = $dirmodule;
156 $this->targetmodule = $targetmodule;
157 $this->canvas = $canvas;
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'";
183 $tmpobject =
new Product($this->db);
184 if (!empty($id) || !empty($ref)) {
185 $tmpobject->fetch($id, $ref);
187 $this->
object = $tmpobject;
189 foreach ($this->
object as $key => $value) {
190 $this->tpl[$key] = $value;
196 $this->tpl[
'canvas'] = $this->canvas;
199 $this->tpl[
'id'] = $this->id;
202 $this->tpl[
'ref'] = $this->ref;
205 $this->tpl[
'label'] = $this->label;
208 $this->tpl[
'description'] = nl2br($this->
description);
211 $this->tpl[
'status'] = $this->
object->getLibStatut(2);
214 $this->tpl[
'note'] = nl2br($this->note);
216 if ($action ==
'create') {
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");
223 $this->tpl[
'tva_tx'] = $form->load_tva(
"tva_tx", -1,
$mysoc,
null);
226 if ($action ==
'view') {
229 $this->tpl[
'showrefnav'] = $form->showrefnav($this->
object,
'ref',
'', 1,
'ref');
231 $titre = $langs->trans(
"CardProduct".$this->object->type);
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);
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);
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;
254 $this->tpl[
'duration_value'] = $this->
object->duration_value;
256 if ($action ==
'create') {
258 $this->tpl[
'title'] = $langs->trans(
"NewService");
261 if ($action ==
'edit') {
262 $this->tpl[
'title'] = $langs->trans(
'Modify').
' '.$langs->trans(
'Service').
' : '.$this->
object->ref;
265 if ($action ==
'create' || $action ==
'edit') {
267 $statutarray = array(
'1' => $langs->trans(
"OnSell"),
'0' => $langs->trans(
"NotOnSell"));
268 $this->tpl[
'status'] = $form->selectarray(
'statut', $statutarray, $this->object->status);
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);
273 $this->tpl[
'description'] = $this->description;
274 $this->tpl[
'note'] = $this->note;
278 $duration_unit =
'<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit ==
'h' ?
' checked' :
'').
'>'.$langs->trans(
"Hour");
279 $duration_unit .=
' ';
280 $duration_unit .=
'<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit ==
'd' ?
' checked' :
'').
'>'.$langs->trans(
"Day");
281 $duration_unit .=
' ';
282 $duration_unit .=
'<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit ==
'w' ?
' checked' :
'').
'>'.$langs->trans(
"Week");
283 $duration_unit .=
' ';
284 $duration_unit .=
'<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit ==
'm' ?
' checked' :
'').
'>'.$langs->trans(
"Month");
285 $duration_unit .=
' ';
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;
290 if ($action ==
'view') {
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);
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"));
304 $this->tpl[
'duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
318 global
$conf, $langs;
320 $this->field_list = array();
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";
328 $resql = $this->db->query($sql);
330 $num = $this->db->num_rows($resql);
334 $fieldlist = array();
336 $obj = $this->db->fetch_object($resql);
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;
349 array_push($this->field_list, $fieldlist);
353 $this->db->free($resql);