dolibarr  16.0.5
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  public $list_datas = array();
41 
42  public $id;
43  public $ref;
44  public $description;
45  public $note;
46  public $price;
47  public $price_min;
48 
49 
58  public function __construct($db, $targetmodule, $canvas, $card)
59  {
60  $this->db = $db;
61  $this->targetmodule = $targetmodule;
62  $this->canvas = $canvas;
63  $this->card = $card;
64 
65  $this->module = "service";
66  $this->name = "service";
67  $this->definition = "Services canvas";
68  $this->fieldListName = "product_service";
69  $this->next_prev_filter = "canvas='service'";
70  }
71 
72 
73  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
82  public function assign_values(&$action, $id = 0, $ref = '')
83  {
84  // phpcs:enable
85  global $limit, $offset, $sortfield, $sortorder;
86  global $conf, $langs, $user, $mysoc, $canvas;
87  global $form, $formproduct;
88 
89  $tmpobject = new Product($this->db);
90  if (!empty($id) || !empty($ref)) {
91  $tmpobject->fetch($id, $ref);
92  }
93  $this->object = $tmpobject;
94 
95  //parent::assign_values($action);
96 
97  foreach ($this->object as $key => $value) {
98  $this->tpl[$key] = $value;
99  }
100 
101  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
102 
103  // canvas
104  $this->tpl['canvas'] = $this->canvas;
105 
106  // id
107  $this->tpl['id'] = $this->id;
108 
109  // Ref
110  $this->tpl['ref'] = $this->ref;
111 
112  // Label
113  $this->tpl['label'] = $this->label;
114 
115  // Description
116  $this->tpl['description'] = nl2br($this->description);
117 
118  // Statut
119  $this->tpl['status'] = $this->object->getLibStatut(2);
120 
121  // Note
122  $this->tpl['note'] = nl2br($this->note);
123 
124  if ($action == 'create') {
125  // Price
126  $this->tpl['price'] = $this->price;
127  $this->tpl['price_min'] = $this->price_min;
128  $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
129 
130  // VAT
131  $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
132  }
133 
134  if ($action == 'view') {
135  $head = product_prepare_head($this->object);
136 
137  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
138 
139  $titre = $langs->trans("CardProduct".$this->object->type);
140  $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
141  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
142  $this->tpl['showend'] = dol_get_fiche_end();
143 
144  // Accountancy buy code
145  $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
146  $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
147 
148  // Accountancy sell code
149  $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
150  $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
151  }
152 
153  $this->tpl['finished'] = $this->object->finished;
154  $this->tpl['ref'] = $this->object->ref;
155  $this->tpl['label'] = $this->object->label;
156  $this->tpl['id'] = $this->object->id;
157  $this->tpl['type'] = $this->object->type;
158  $this->tpl['note'] = $this->object->note;
159  $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
160 
161  // Duration
162  $this->tpl['duration_value'] = $this->object->duration_value;
163 
164  if ($action == 'create') {
165  // Title
166  $this->tpl['title'] = $langs->trans("NewService");
167  }
168 
169  if ($action == 'edit') {
170  $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
171  }
172 
173  if ($action == 'create' || $action == 'edit') {
174  // Status
175  $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
176  $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
177 
178  $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
179  $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
180 
181  $this->tpl['description'] = $this->description;
182  $this->tpl['note'] = $this->note;
183 
184  // Duration unit
185  // TODO creer fonction
186  $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
187  $duration_unit .= '&nbsp; ';
188  $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
189  $duration_unit .= '&nbsp; ';
190  $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
191  $duration_unit .= '&nbsp; ';
192  $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
193  $duration_unit .= '&nbsp; ';
194  $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
195  $this->tpl['duration_unit'] = $duration_unit;
196  }
197 
198  if ($action == 'view') {
199  // Photo
200  $this->tpl['nblines'] = 4;
201  if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
202  $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
203  }
204 
205  // Duration
206  $dur = array();
207  if ($this->object->duration_value > 1) {
208  $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
209  } elseif ($this->object->duration_value > 0) {
210  $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
211  }
212  $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
213 
214  $this->tpl['fiche_end'] = dol_get_fiche_end();
215  }
216 
217  if ($action == 'list') {
218  $this->LoadListDatas($limit, $offset, $sortfield, $sortorder);
219  }
220  }
221 
222 
228  private function getFieldListCanvas()
229  {
230  global $conf, $langs;
231 
232  $this->field_list = array();
233 
234  $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
235  $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
236  $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
237  $sql .= " AND entity = ".$conf->entity;
238  $sql .= " ORDER BY rang ASC";
239 
240  $resql = $this->db->query($sql);
241  if ($resql) {
242  $num = $this->db->num_rows($resql);
243 
244  $i = 0;
245  while ($i < $num) {
246  $fieldlist = array();
247 
248  $obj = $this->db->fetch_object($resql);
249 
250  $fieldlist["id"] = $obj->rowid;
251  $fieldlist["name"] = $obj->name;
252  $fieldlist["alias"] = $obj->alias;
253  $fieldlist["title"] = $langs->trans($obj->title);
254  $fieldlist["align"] = $obj->align;
255  $fieldlist["sort"] = $obj->sort;
256  $fieldlist["search"] = $obj->search;
257  $fieldlist["visible"] = $obj->visible;
258  $fieldlist["enabled"] = verifCond($obj->enabled);
259  $fieldlist["order"] = $obj->rang;
260 
261  array_push($this->field_list, $fieldlist);
262 
263  $i++;
264  }
265  $this->db->free($resql);
266  } else {
267  dol_print_error($this->db, $sql);
268  }
269  }
270 
271  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
281  public function LoadListDatas($limit, $offset, $sortfield, $sortorder)
282  {
283  // phpcs:enable
284  global $conf;
285  global $search_categ, $sall, $sref, $search_barcode, $snom, $catid;
286 
287  $this->getFieldListCanvas();
288 
289  $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
290  $sql .= ' p.fk_product_type, p.tms as datem,';
291  $sql .= ' p.duration, p.tosell as statut, p.seuil_stock_alerte';
292  $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
293  // We'll need this table joined to the select in order to filter by categ
294  if ($search_categ) {
295  $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp";
296  }
297  $fourn_id = 0;
298  if (GETPOST("fourn_id", 'int') > 0) {
299  $fourn_id = GETPOST("fourn_id", 'int');
300  $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
301  }
302  $sql .= " WHERE p.entity IN (".getEntity('product').")";
303  if ($search_categ) {
304  $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
305  }
306  if ($sall) {
307  $sql .= " AND (p.ref LIKE '%".$this->db->escape($sall)."%' OR p.label LIKE '%".$this->db->escape($sall)."%' OR p.description LIKE '%".$this->db->escape($sall)."%' OR p.note LIKE '%".$this->db->escape($sall)."%')";
308  }
309  if ($sref) {
310  $sql .= " AND p.ref LIKE '%".$this->db->escape($sref)."%'";
311  }
312  if ($search_barcode) {
313  $sql .= " AND p.barcode LIKE '%".$this->db->escape($search_barcode)."%'";
314  }
315  if ($snom) {
316  $sql .= " AND p.label LIKE '%".$this->db->escape($snom)."%'";
317  }
318  if (GETPOSTISSET("tosell")) {
319  $sql .= " AND p.tosell = ".((int) GETPOST("tosell", 'int'));
320  }
321  if (GETPOSTISSET("canvas")) {
322  $sql .= " AND p.canvas = '".$this->db->escape(GETPOST("canvas"))."'";
323  }
324  if ($catid) {
325  $sql .= " AND cp.fk_categorie = ".((int) $catid);
326  }
327  if ($fourn_id > 0) {
328  $sql .= " AND p.rowid = pfp.fk_product AND pfp.fk_soc = ".((int) $fourn_id);
329  }
330  // Insert categ filter
331  if ($search_categ) {
332  $sql .= " AND cp.fk_categorie = ".((int) $search_categ);
333  }
334  $sql .= $this->db->order($sortfield, $sortorder);
335  $sql .= $this->db->plimit($limit + 1, $offset);
336 
337  $this->list_datas = array();
338 
339  $resql = $this->db->query($sql);
340  if ($resql) {
341  $num = $this->db->num_rows($resql);
342 
343  $i = 0;
344  while ($i < min($num, $limit)) {
345  $datas = array();
346  $obj = $this->db->fetch_object($resql);
347 
348  $datas["id"] = $obj->rowid;
349  $datas["ref"] = $obj->ref;
350  $datas["label"] = $obj->label;
351  $datas["barcode"] = $obj->barcode;
352  $datas["statut"] = $obj->statut;
353 
354  array_push($this->list_datas, $datas);
355 
356  $i++;
357  }
358  $this->db->free($resql);
359  } else {
360  print $sql;
361  }
362  }
363 }
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:8267
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
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:4830
verifCond
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
Definition: functions.lib.php:8568
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:58
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
name
$conf db name
Definition: repair.php:122
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:82
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:1808
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2004
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Product
Class to manage products or services.
Definition: product.class.php:46
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
ActionsCardService\LoadListDatas
LoadListDatas($limit, $offset, $sortfield, $sortorder)
Fetch datas list and save into ->list_datas.
Definition: actions_card_service.class.php:281
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:504
ActionsCardService\getFieldListCanvas
getFieldListCanvas()
Fetch field list.
Definition: actions_card_service.class.php:228
ActionsCardService\$tpl
$tpl
Template container.
Definition: actions_card_service.class.php:36