27 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
28 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 var $boxcode=
"lastproducts";
37 var $boximg=
"object_product";
38 var $boxlabel=
"BoxLastProducts";
39 var $depends = array(
"produit");
48 var $info_box_head = array();
49 var $info_box_contents = array();
64 $listofmodulesforexternal=explode(
',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
65 $tmpentry=array(
'enabled'=>(! empty($conf->product->enabled) || ! empty($conf->service->enabled)),
'perms'=>(! empty($user->rights->produit->lire) || ! empty($user->rights->service->lire)),
'module'=>
'product|service');
66 $showmode=
isVisibleToUserType(($user->societe_id > 0 ? 1 : 0), $tmpentry, $listofmodulesforexternal);
67 $this->hidden=($showmode != 1);
78 global $user, $langs, $db, $conf, $hookmanager;
82 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
83 $productstatic=
new Product($db);
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastProducts",$max));
87 if ($user->rights->produit->lire || $user->rights->service->lire)
89 $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";
90 $sql.=
" FROM ".MAIN_DB_PREFIX.
"product as p";
91 $sql.=
' WHERE p.entity IN ('.getEntity($productstatic->element).
')';
92 if (empty($user->rights->produit->lire)) $sql.=
' AND p.fk_product_type != 0';
93 if (empty($user->rights->service->lire)) $sql.=
' AND p.fk_product_type != 1';
95 if (is_object($hookmanager))
97 $parameters=array(
'boxproductlist'=>1);
98 $reshook=$hookmanager->executeHooks(
'printFieldListWhere',$parameters);
99 $sql.=$hookmanager->resPrint;
101 $sql.= $db->order(
'p.datec',
'DESC');
102 $sql.= $db->plimit($max, 0);
104 $result = $db->query($sql);
107 $num = $db->num_rows($result);
111 $objp = $db->fetch_object($result);
112 $datem=$db->jdate($objp->tms);
115 if (! empty($conf->global->MAIN_MULTILANGS))
117 $sqld =
"SELECT label";
118 $sqld.=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
119 $sqld.=
" WHERE fk_product=".$objp->rowid;
120 $sqld.=
" AND lang='". $langs->getDefaultLang() .
"'";
123 $resultd = $db->query($sqld);
126 $objtp = $db->fetch_object($resultd);
127 if (isset($objtp->label) && $objtp->label !=
'')
128 $objp->label = $objtp->label;
131 $productstatic->id = $objp->rowid;
132 $productstatic->ref = $objp->ref;
133 $productstatic->type = $objp->fk_product_type;
134 $productstatic->label = $objp->label;
135 $productstatic->entity = $objp->entity;
137 $this->info_box_contents[$line][] = array(
138 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
139 'text' => $productstatic->getNomUrl(1),
143 $this->info_box_contents[$line][] = array(
144 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
145 'text' => $objp->label,
148 if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
149 $price_base_type=$langs->trans($objp->price_base_type);
150 $price=($objp->price_base_type ==
'HT')?
price($objp->price):$price=
price($objp->price_ttc);
154 $productstatic->fetch($objp->rowid,
'',
'', 1);
156 $price_result = $priceparser->parseProduct($productstatic);
157 if ($price_result >= 0) {
158 if ($objp->price_base_type ==
'HT')
160 $price_base_type=$langs->trans(
"HT");
164 $price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
165 $price_base_type=$langs->trans(
"TTC");
167 $price=
price($price_result);
170 $this->info_box_contents[$line][] = array(
171 'td' =>
'class="right"',
175 $this->info_box_contents[$line][] = array(
176 'td' =>
'class="nowrap"',
177 'text' => $price_base_type,
180 $this->info_box_contents[$line][] = array(
181 'td' =>
'class="right"',
185 $this->info_box_contents[$line][] = array(
186 'td' =>
'align="right" width="18"',
187 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell,3,0).
'<span>',
191 $this->info_box_contents[$line][] = array(
192 'td' =>
'align="right" width="18"',
193 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy,3,1).
'</span>',
200 $this->info_box_contents[$line][0] = array(
201 'td' =>
'align="center"',
202 'text'=>$langs->trans(
"NoRecordedProducts"),
207 $this->info_box_contents[0][0] = array(
210 'text' => ($db->error().
' sql='.$sql),
214 $this->info_box_contents[0][0] = array(
215 'td' =>
'align="left" class="nohover opacitymedium"',
216 'text' => $langs->trans(
"ReadPermissionNotAllowed")
229 function showBox($head = null, $contents = null, $nooutput=0)
231 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
__construct($db, $param)
Constructor.
Class to parse product price expressions.
Class to manage products or services.
loadBox($max=5)
Load data into info_box_contents array to show array later.
isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
Function to test if an entry is enabled or not.
Class to manage the box to show last products.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.