27 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
28 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 public $boxcode =
"lastproducts";
37 public $boximg =
"object_product";
38 public $boxlabel =
"BoxLastProducts";
39 public $depends = array(
"produit");
48 public $info_box_head = array();
49 public $info_box_contents = array();
64 $listofmodulesforexternal = explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
65 $tmpentry = array(
'enabled'=>(
isModEnabled(
"product") ||
isModEnabled(
"service")),
'perms'=>(!empty($user->rights->produit->lire) || !empty($user->rights->service->lire)),
'module'=>
'product|service');
66 $showmode =
isVisibleToUserType(($user->socid > 0 ? 1 : 0), $tmpentry, $listofmodulesforexternal);
67 $this->hidden = ($showmode != 1);
78 global $user, $langs, $conf, $hookmanager;
82 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastProducts", $max));
87 if ($user->rights->produit->lire || $user->rights->service->lire) {
88 $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";
89 $sql .=
", p.accountancy_code_sell";
90 $sql .=
", p.accountancy_code_sell_intra";
91 $sql .=
", p.accountancy_code_sell_export";
92 $sql .=
", p.accountancy_code_buy";
93 $sql .=
", p.accountancy_code_buy_intra";
94 $sql .=
", p.accountancy_code_buy_export";
95 $sql .=
', p.barcode';
96 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
97 $sql .=
' WHERE p.entity IN ('.getEntity($productstatic->element).
')';
98 if (empty($user->rights->produit->lire)) {
99 $sql .=
' AND p.fk_product_type != 0';
101 if (empty($user->rights->service->lire)) {
102 $sql .=
' AND p.fk_product_type != 1';
105 if (is_object($hookmanager)) {
106 $parameters = array(
'boxproductlist' => 1,
'boxcode' => $this->boxcode);
107 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $productstatic);
108 $sql .= $hookmanager->resPrint;
110 $sql .= $this->
db->order(
'p.datec',
'DESC');
111 $sql .= $this->
db->plimit($max, 0);
113 $result = $this->
db->query($sql);
115 $num = $this->
db->num_rows($result);
117 while ($line < $num) {
118 $objp = $this->
db->fetch_object($result);
119 $datem = $this->
db->jdate($objp->tms);
123 $sqld =
"SELECT label";
124 $sqld .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
125 $sqld .=
" WHERE fk_product = ".((int) $objp->rowid);
126 $sqld .=
" AND lang = '".$this->db->escape($langs->getDefaultLang()).
"'";
129 $resultd = $this->
db->query($sqld);
131 $objtp = $this->
db->fetch_object($resultd);
132 if (isset($objtp->label) && $objtp->label !=
'') {
133 $objp->label = $objtp->label;
137 $productstatic->id = $objp->rowid;
138 $productstatic->ref = $objp->ref;
139 $productstatic->type = $objp->fk_product_type;
140 $productstatic->label = $objp->label;
141 $productstatic->entity = $objp->entity;
142 $productstatic->status = $objp->tosell;
143 $productstatic->status_buy = $objp->tobuy;
144 $productstatic->barcode = $objp->barcode;
145 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
146 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
147 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
148 $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
149 $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
150 $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
151 $productstatic->date_modification = $datem;
153 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS')?$user->hasRight(
'product',
'product_advance',
'read_prices'):$user->hasRight(
'product',
'read');
154 if ($productstatic->isService()) {
155 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS')?$user->hasRight(
'service',
'service_advance',
'read_prices'):$user->hasRight(
'service',
'read');
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
160 'text' => $productstatic->getNomUrl(1),
164 $this->info_box_contents[$line][] = array(
165 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
166 'text' => $objp->label,
169 $price_base_type =
'';
170 if ($usercancreadprice) {
171 if (!
isModEnabled(
'dynamicprices') || empty($objp->fk_price_expression)) {
172 $price_base_type = $langs->trans($objp->price_base_type);
173 $price = ($objp->price_base_type ==
'HT') ?
price($objp->price) : $price =
price($objp->price_ttc);
176 $productstatic->fetch($objp->rowid,
'',
'', 1);
178 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
180 $price_result = $priceparser->parseProduct($productstatic);
181 if ($price_result >= 0) {
182 if ($objp->price_base_type ==
'HT') {
183 $price_base_type = $langs->trans(
"HT");
185 $price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
186 $price_base_type = $langs->trans(
"TTC");
188 $price =
price($price_result);
192 $this->info_box_contents[$line][] = array(
193 'td' =>
'class="nowraponall right amount"',
197 $this->info_box_contents[$line][] = array(
198 'td' =>
'class="nowrap"',
199 'text' => $price_base_type,
202 $this->info_box_contents[$line][] = array(
207 $this->info_box_contents[$line][] = array(
208 'td' =>
'class="right" width="18"',
209 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).
'</span>',
213 $this->info_box_contents[$line][] = array(
214 'td' =>
'class="right" width="18"',
215 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).
'</span>',
222 $this->info_box_contents[$line][0] = array(
223 'td' =>
'class="center"',
224 'text'=>$langs->trans(
"NoRecordedProducts"),
228 $this->
db->free($result);
230 $this->info_box_contents[0][0] = array(
233 'text' => ($this->
db->error().
' sql='.$sql),
237 $this->info_box_contents[0][0] = array(
238 'td' =>
'class="nohover opacitymedium left"',
239 'text' => $langs->trans(
"ReadPermissionNotAllowed")
252 public function showBox($head =
null, $contents =
null, $nooutput = 0)
254 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db
API class for accounts.