dolibarr  17.0.3
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 
23 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
24 
25 
30 {
31  public $targetmodule;
32  public $canvas;
33  public $card;
34 
36  public $tpl = array();
37 
38  // List of fiels for action=list
39  public $field_list = array();
40 
41  public $id;
42  public $ref;
43  public $description;
44  public $note;
45  public $price;
46  public $price_min;
47 
48 
57  public function __construct($db, $targetmodule, $canvas, $card)
58  {
59  $this->db = $db;
60  $this->targetmodule = $targetmodule;
61  $this->canvas = $canvas;
62  $this->card = $card;
63 
64  $this->module = "service";
65  $this->name = "service";
66  $this->definition = "Services canvas";
67  $this->fieldListName = "product_service";
68  $this->next_prev_filter = "canvas='service'";
69  }
70 
71 
72  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
81  public function assign_values(&$action, $id = 0, $ref = '')
82  {
83  // phpcs:enable
84  global $limit, $offset, $sortfield, $sortorder;
85  global $conf, $langs, $user, $mysoc, $canvas;
86  global $form, $formproduct;
87 
88  $tmpobject = new Product($this->db);
89  if (!empty($id) || !empty($ref)) {
90  $tmpobject->fetch($id, $ref);
91  }
92  $this->object = $tmpobject;
93 
94  foreach ($this->object as $key => $value) {
95  $this->tpl[$key] = $value;
96  }
97 
98  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
99 
100  // canvas
101  $this->tpl['canvas'] = $this->canvas;
102 
103  // id
104  $this->tpl['id'] = $this->id;
105 
106  // Ref
107  $this->tpl['ref'] = $this->ref;
108 
109  // Label
110  $this->tpl['label'] = $this->label;
111 
112  // Description
113  $this->tpl['description'] = nl2br($this->description);
114 
115  // Statut
116  $this->tpl['status'] = $this->object->getLibStatut(2);
117 
118  // Note
119  $this->tpl['note'] = nl2br($this->note);
120 
121  if ($action == 'create') {
122  // Price
123  $this->tpl['price'] = $this->price;
124  $this->tpl['price_min'] = $this->price_min;
125  $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
126 
127  // VAT
128  $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
129  }
130 
131  if ($action == 'view') {
132  $head = product_prepare_head($this->object);
133 
134  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
135 
136  $titre = $langs->trans("CardProduct".$this->object->type);
137  $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
138  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
139  $this->tpl['showend'] = dol_get_fiche_end();
140 
141  // Accountancy buy code
142  $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
143  $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
144 
145  // Accountancy sell code
146  $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
147  $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
148  }
149 
150  $this->tpl['finished'] = $this->object->finished;
151  $this->tpl['ref'] = $this->object->ref;
152  $this->tpl['label'] = $this->object->label;
153  $this->tpl['id'] = $this->object->id;
154  $this->tpl['type'] = $this->object->type;
155  $this->tpl['note'] = $this->object->note;
156  $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
157 
158  // Duration
159  $this->tpl['duration_value'] = $this->object->duration_value;
160 
161  if ($action == 'create') {
162  // Title
163  $this->tpl['title'] = $langs->trans("NewService");
164  }
165 
166  if ($action == 'edit') {
167  $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
168  }
169 
170  if ($action == 'create' || $action == 'edit') {
171  // Status
172  $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
173  $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
174 
175  $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
176  $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
177 
178  $this->tpl['description'] = $this->description;
179  $this->tpl['note'] = $this->note;
180 
181  // Duration unit
182  // TODO creer fonction
183  $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
184  $duration_unit .= '&nbsp; ';
185  $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
186  $duration_unit .= '&nbsp; ';
187  $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
188  $duration_unit .= '&nbsp; ';
189  $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
190  $duration_unit .= '&nbsp; ';
191  $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
192  $this->tpl['duration_unit'] = $duration_unit;
193  }
194 
195  if ($action == 'view') {
196  // Photo
197  $this->tpl['nblines'] = 4;
198  if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
199  $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
200  }
201 
202  // Duration
203  $dur = array();
204  if ($this->object->duration_value > 1) {
205  $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
206  } elseif ($this->object->duration_value > 0) {
207  $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
208  }
209  $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
210 
211  $this->tpl['fiche_end'] = dol_get_fiche_end();
212  }
213  }
214 
215 
221  private function getFieldListCanvas()
222  {
223  global $conf, $langs;
224 
225  $this->field_list = array();
226 
227  $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
228  $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
229  $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
230  $sql .= " AND entity = ".$conf->entity;
231  $sql .= " ORDER BY rang ASC";
232 
233  $resql = $this->db->query($sql);
234  if ($resql) {
235  $num = $this->db->num_rows($resql);
236 
237  $i = 0;
238  while ($i < $num) {
239  $fieldlist = array();
240 
241  $obj = $this->db->fetch_object($resql);
242 
243  $fieldlist["id"] = $obj->rowid;
244  $fieldlist["name"] = $obj->name;
245  $fieldlist["alias"] = $obj->alias;
246  $fieldlist["title"] = $langs->trans($obj->title);
247  $fieldlist["align"] = $obj->align;
248  $fieldlist["sort"] = $obj->sort;
249  $fieldlist["search"] = $obj->search;
250  $fieldlist["visible"] = $obj->visible;
251  $fieldlist["enabled"] = verifCond($obj->enabled);
252  $fieldlist["order"] = $obj->rang;
253 
254  array_push($this->field_list, $fieldlist);
255 
256  $i++;
257  }
258  $this->db->free($resql);
259  } else {
260  dol_print_error($this->db, $sql);
261  }
262  }
263 }
db
$conf db
API class for accounts.
Definition: inc.php:41
get_htmloutput_errors
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
Definition: functions.lib.php:8610
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
verifCond
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
Definition: functions.lib.php:8927
product_prepare_head
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
ActionsCardService
Class with controller methods for product canvas.
Definition: actions_card_service.class.php:29
ActionsCardService\__construct
__construct($db, $targetmodule, $canvas, $card)
Constructor.
Definition: actions_card_service.class.php:57
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
name
$conf db name
Definition: repair.php:122
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
ActionsCardService\assign_values
assign_values(&$action, $id=0, $ref='')
Assign custom values for canvas (for example into this->tpl to be used by templates)
Definition: actions_card_service.class.php:81
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1858
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
Product
Class to manage products or services.
Definition: product.class.php:46
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:546
ActionsCardService\getFieldListCanvas
getFieldListCanvas()
Fetch field list.
Definition: actions_card_service.class.php:221
ActionsCardService\$tpl
$tpl
Template container.
Definition: actions_card_service.class.php:36