dolibarr  20.0.0-beta
box_produits.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2023 Frederic France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
29 
30 
35 {
36  public $boxcode = "lastproducts";
37  public $boximg = "object_product";
38  public $boxlabel = "BoxLastProducts";
39  public $depends = array("produit");
40 
47  public function __construct($db, $param)
48  {
49  global $user;
50 
51  $this->db = $db;
52 
53  $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
54  $tmpentry = array('enabled'=>(isModEnabled("product") || isModEnabled("service")), 'perms'=>($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire')), 'module'=>'product|service');
55  $showmode = isVisibleToUserType(($user->socid > 0 ? 1 : 0), $tmpentry, $listofmodulesforexternal);
56  $this->hidden = ($showmode != 1);
57  }
58 
65  public function loadBox($max = 5)
66  {
67  global $user, $langs, $conf, $hookmanager;
68 
69  $this->max = $max;
70 
71  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
72  $productstatic = new Product($this->db);
73 
74  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastProducts", $max));
75 
76  if ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire')) {
77  $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.fk_price_expression, p.entity";
78  $sql .= ", p.accountancy_code_sell";
79  $sql .= ", p.accountancy_code_sell_intra";
80  $sql .= ", p.accountancy_code_sell_export";
81  $sql .= ", p.accountancy_code_buy";
82  $sql .= ", p.accountancy_code_buy_intra";
83  $sql .= ", p.accountancy_code_buy_export";
84  $sql .= ', p.barcode';
85  $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
86  $sql .= ' WHERE p.entity IN ('.getEntity($productstatic->element).')';
87  if (!$user->hasRight('produit', 'lire')) {
88  $sql .= ' AND p.fk_product_type != 0';
89  }
90  if (!$user->hasRight('service', 'lire')) {
91  $sql .= ' AND p.fk_product_type != 1';
92  }
93  // Add where from hooks
94  if (is_object($hookmanager)) {
95  $parameters = array('boxproductlist' => 1, 'boxcode' => $this->boxcode);
96  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $productstatic); // Note that $action and $object may have been modified by hook
97  $sql .= $hookmanager->resPrint;
98  }
99  $sql .= $this->db->order('p.datec', 'DESC');
100  $sql .= $this->db->plimit($max, 0);
101 
102  $result = $this->db->query($sql);
103  if ($result) {
104  $num = $this->db->num_rows($result);
105  $line = 0;
106  while ($line < $num) {
107  $objp = $this->db->fetch_object($result);
108  $datem = $this->db->jdate($objp->tms);
109 
110  // Multilangs
111  if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
112  $sqld = "SELECT label";
113  $sqld .= " FROM ".MAIN_DB_PREFIX."product_lang";
114  $sqld .= " WHERE fk_product = ".((int) $objp->rowid);
115  $sqld .= " AND lang = '".$this->db->escape($langs->getDefaultLang())."'";
116  $sqld .= " LIMIT 1";
117 
118  $resultd = $this->db->query($sqld);
119  if ($resultd) {
120  $objtp = $this->db->fetch_object($resultd);
121  if (isset($objtp->label) && $objtp->label != '') {
122  $objp->label = $objtp->label;
123  }
124  }
125  }
126  $productstatic->id = $objp->rowid;
127  $productstatic->ref = $objp->ref;
128  $productstatic->type = $objp->fk_product_type;
129  $productstatic->label = $objp->label;
130  $productstatic->entity = $objp->entity;
131  $productstatic->status = $objp->tosell;
132  $productstatic->status_buy = $objp->tobuy;
133  $productstatic->barcode = $objp->barcode;
134  $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
135  $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
136  $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
137  $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
138  $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
139  $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
140  $productstatic->date_modification = $datem;
141 
142  $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('product', 'product_advance', 'read_prices') : $user->hasRight('product', 'read');
143  if ($productstatic->isService()) {
144  $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS') ? $user->hasRight('service', 'service_advance', 'read_prices') : $user->hasRight('service', 'read');
145  }
146 
147  $this->info_box_contents[$line][] = array(
148  'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
149  'text' => $productstatic->getNomUrl(1),
150  'asis' => 1,
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
155  'text' => $objp->label,
156  );
157  $price = '';
158  $price_base_type = '';
159  if ($usercancreadprice) {
160  if (!isModEnabled('dynamicprices') || empty($objp->fk_price_expression)) {
161  $price_base_type = $langs->trans($objp->price_base_type);
162  $price = ($objp->price_base_type == 'HT') ? price($objp->price) : $price = price($objp->price_ttc);
163  } else {
164  //Parse the dynamic price
165  $productstatic->fetch($objp->rowid, '', '', 1);
166 
167  require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
168  $priceparser = new PriceParser($this->db);
169  $price_result = $priceparser->parseProduct($productstatic);
170  if ($price_result >= 0) {
171  if ($objp->price_base_type == 'HT') {
172  $price_base_type = $langs->trans("HT");
173  } else {
174  $price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
175  $price_base_type = $langs->trans("TTC");
176  }
177  $price = price($price_result);
178  }
179  }
180  }
181  $this->info_box_contents[$line][] = array(
182  'td' => 'class="nowraponall right amount"',
183  'text' => $price,
184  );
185 
186  $this->info_box_contents[$line][] = array(
187  'td' => 'class="nowrap"',
188  'text' => $price_base_type,
189  );
190 
191  $this->info_box_contents[$line][] = array(
192  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
193  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
194  );
195 
196  $this->info_box_contents[$line][] = array(
197  'td' => 'class="right" width="18"',
198  'text' => '<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).'</span>',
199  'asis' => 1
200  );
201 
202  $this->info_box_contents[$line][] = array(
203  'td' => 'class="right" width="18"',
204  'text' => '<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).'</span>',
205  'asis' => 1
206  );
207 
208  $line++;
209  }
210  if ($num == 0) {
211  $this->info_box_contents[$line][0] = array(
212  'td' => 'class="center"',
213  'text'=>$langs->trans("NoRecordedProducts"),
214  );
215  }
216 
217  $this->db->free($result);
218  } else {
219  $this->info_box_contents[0][0] = array(
220  'td' => '',
221  'maxlength'=>500,
222  'text' => ($this->db->error().' sql='.$sql),
223  );
224  }
225  } else {
226  $this->info_box_contents[0][0] = array(
227  'td' => 'class="nohover left"',
228  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
229  );
230  }
231  }
232 
241  public function showBox($head = null, $contents = null, $nooutput = 0)
242  {
243  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
244  }
245 }
Class ModeleBoxes.
Class to parse product price expressions.
Class to manage products or services.
Class to manage the box to show last products.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
Function to test if an entry is enabled or not.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...