dolibarr  13.0.2
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 
51  public function __construct($db, $targetmodule, $canvas, $card)
52  {
53  $this->db = $db;
54  $this->targetmodule = $targetmodule;
55  $this->canvas = $canvas;
56  $this->card = $card;
57 
58  $this->module = "service";
59  $this->name = "service";
60  $this->definition = "Services canvas";
61  $this->fieldListName = "product_service";
62  $this->next_prev_filter = "canvas='service'";
63  }
64 
65 
66  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
75  public function assign_values(&$action, $id = 0, $ref = '')
76  {
77  // phpcs:enable
78  global $limit, $offset, $sortfield, $sortorder;
79  global $conf, $langs, $user, $mysoc, $canvas;
80  global $form, $formproduct;
81 
82  $tmpobject = new Product($this->db);
83  if (!empty($id) || !empty($ref)) $tmpobject->fetch($id, $ref);
84  $this->object = $tmpobject;
85 
86  //parent::assign_values($action);
87 
88  foreach ($this->object as $key => $value)
89  {
90  $this->tpl[$key] = $value;
91  }
92 
93  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
94 
95  // canvas
96  $this->tpl['canvas'] = $this->canvas;
97 
98  // id
99  $this->tpl['id'] = $this->id;
100 
101  // Ref
102  $this->tpl['ref'] = $this->ref;
103 
104  // Label
105  $this->tpl['label'] = $this->label;
106 
107  // Description
108  $this->tpl['description'] = nl2br($this->description);
109 
110  // Statut
111  $this->tpl['status'] = $this->object->getLibStatut(2);
112 
113  // Note
114  $this->tpl['note'] = nl2br($this->note);
115 
116  if ($action == 'create')
117  {
118  // Price
119  $this->tpl['price'] = $this->price;
120  $this->tpl['price_min'] = $this->price_min;
121  $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
122 
123  // VAT
124  $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
125  }
126 
127  if ($action == 'view')
128  {
129  $head = product_prepare_head($this->object);
130 
131  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
132 
133  $titre = $langs->trans("CardProduct".$this->object->type);
134  $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
135  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
136  $this->tpl['showend'] = dol_get_fiche_end();
137 
138  // Accountancy buy code
139  $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
140  $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
141 
142  // Accountancy sell code
143  $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
144  $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
145  }
146 
147  $this->tpl['finished'] = $this->object->finished;
148  $this->tpl['ref'] = $this->object->ref;
149  $this->tpl['label'] = $this->object->label;
150  $this->tpl['id'] = $this->object->id;
151  $this->tpl['type'] = $this->object->type;
152  $this->tpl['note'] = $this->object->note;
153  $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
154 
155  // Duration
156  $this->tpl['duration_value'] = $this->object->duration_value;
157 
158  if ($action == 'create')
159  {
160  // Title
161  $this->tpl['title'] = $langs->trans("NewService");
162  }
163 
164  if ($action == 'edit')
165  {
166  $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
167  }
168 
169  if ($action == 'create' || $action == 'edit')
170  {
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  {
197  // Photo
198  $this->tpl['nblines'] = 4;
199  if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity]))
200  {
201  $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
202  }
203 
204  // Duration
205  if ($this->object->duration_value > 1)
206  {
207  $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
208  } elseif ($this->object->duration_value > 0)
209  {
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  {
219  $this->LoadListDatas($limit, $offset, $sortfield, $sortorder);
220  }
221  }
222 
223 
229  private function getFieldList()
230  {
231  global $conf, $langs;
232 
233  $this->field_list = array();
234 
235  $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
236  $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
237  $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
238  $sql .= " AND entity = ".$conf->entity;
239  $sql .= " ORDER BY rang ASC";
240 
241  $resql = $this->db->query($sql);
242  if ($resql)
243  {
244  $num = $this->db->num_rows($resql);
245 
246  $i = 0;
247  while ($i < $num)
248  {
249  $fieldlist = array();
250 
251  $obj = $this->db->fetch_object($resql);
252 
253  $fieldlist["id"] = $obj->rowid;
254  $fieldlist["name"] = $obj->name;
255  $fieldlist["alias"] = $obj->alias;
256  $fieldlist["title"] = $langs->trans($obj->title);
257  $fieldlist["align"] = $obj->align;
258  $fieldlist["sort"] = $obj->sort;
259  $fieldlist["search"] = $obj->search;
260  $fieldlist["visible"] = $obj->visible;
261  $fieldlist["enabled"] = verifCond($obj->enabled);
262  $fieldlist["order"] = $obj->rang;
263 
264  array_push($this->field_list, $fieldlist);
265 
266  $i++;
267  }
268  $this->db->free($resql);
269  } else {
270  dol_print_error($this->db, $sql);
271  }
272  }
273 
274  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
284  public function LoadListDatas($limit, $offset, $sortfield, $sortorder)
285  {
286  // phpcs:enable
287  global $conf;
288  global $search_categ, $sall, $sref, $search_barcode, $snom, $catid;
289 
290  $this->getFieldList();
291 
292  $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
293  $sql .= ' p.fk_product_type, p.tms as datem,';
294  $sql .= ' p.duration, p.tosell as statut, p.seuil_stock_alerte';
295  $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
296  // We'll need this table joined to the select in order to filter by categ
297  if ($search_categ) $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp";
298  if (GETPOST("fourn_id", 'int') > 0)
299  {
300  $fourn_id = GETPOST("fourn_id", 'int');
301  $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
302  }
303  $sql .= " WHERE p.entity IN (".getEntity('product').")";
304  if ($search_categ) $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
305  if ($sall)
306  {
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) $sql .= " AND p.ref LIKE '%".$sref."%'";
310  if ($search_barcode) $sql .= " AND p.barcode LIKE '%".$search_barcode."%'";
311  if ($snom) $sql .= " AND p.label LIKE '%".$this->db->escape($snom)."%'";
312  if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0)
313  {
314  $sql .= " AND p.tosell = ".$this->db->escape($_GET["tosell"]);
315  }
316  if (isset($_GET["canvas"]) && dol_strlen($_GET["canvas"]) > 0)
317  {
318  $sql .= " AND p.canvas = '".$this->db->escape($_GET["canvas"])."'";
319  }
320  if ($catid)
321  {
322  $sql .= " AND cp.fk_categorie = ".$catid;
323  }
324  if ($fourn_id > 0)
325  {
326  $sql .= " AND p.rowid = pfp.fk_product AND pfp.fk_soc = ".$fourn_id;
327  }
328  // Insert categ filter
329  if ($search_categ)
330  {
331  $sql .= " AND cp.fk_categorie = ".$this->db->escape($search_categ);
332  }
333  $sql .= $this->db->order($sortfield, $sortorder);
334  $sql .= $this->db->plimit($limit + 1, $offset);
335 
336  $this->list_datas = array();
337 
338  $resql = $this->db->query($sql);
339  if ($resql)
340  {
341  $num = $this->db->num_rows($resql);
342 
343  $i = 0;
344  while ($i < min($num, $limit))
345  {
346  $datas = array();
347  $obj = $this->db->fetch_object($resql);
348 
349  $datas["id"] = $obj->rowid;
350  $datas["ref"] = $obj->ref;
351  $datas["label"] = $obj->label;
352  $datas["barcode"] = $obj->barcode;
353  $datas["statut"] = $obj->statut;
354 
355  array_push($this->list_datas, $datas);
356 
357  $i++;
358  }
359  $this->db->free($resql);
360  } else {
361  print $sql;
362  }
363  }
364 }
verifCond($strRights)
Verify if condition in string is ok or not.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class with controller methods for product canvas.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
getFieldList()
Fetch field list.
Class to manage products or services.
get_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
const TYPE_SERVICE
Service.
assign_values(&$action, $id=0, $ref= '')
Assign custom values for canvas (for example into this-&gt;tpl to be used by templates) ...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db, $targetmodule, $canvas, $card)
Constructor.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
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.
LoadListDatas($limit, $offset, $sortfield, $sortorder)
Fetch datas list and save into -&gt;list_datas.
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
if(!empty($search_group)) natural_search(array("g.nom"g note
Definition: list.php:122