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'=>(!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->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);
122 if (!empty($conf->global->MAIN_MULTILANGS)) {
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 $this->info_box_contents[$line][] = array(
154 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
155 'text' => $productstatic->getNomUrl(1),
159 $this->info_box_contents[$line][] = array(
160 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
161 'text' => $objp->label,
164 $price_base_type =
'';
165 if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
166 $price_base_type = $langs->trans($objp->price_base_type);
167 $price = ($objp->price_base_type ==
'HT') ?
price($objp->price) : $price =
price($objp->price_ttc);
170 $productstatic->fetch($objp->rowid,
'',
'', 1);
172 $price_result = $priceparser->parseProduct($productstatic);
173 if ($price_result >= 0) {
174 if ($objp->price_base_type ==
'HT') {
175 $price_base_type = $langs->trans(
"HT");
177 $price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
178 $price_base_type = $langs->trans(
"TTC");
180 $price =
price($price_result);
183 $this->info_box_contents[$line][] = array(
184 'td' =>
'class="nowraponall right amount"',
188 $this->info_box_contents[$line][] = array(
189 'td' =>
'class="nowrap"',
190 'text' => $price_base_type,
193 $this->info_box_contents[$line][] = array(
198 $this->info_box_contents[$line][] = array(
199 'td' =>
'class="right" width="18"',
200 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).
'</span>',
204 $this->info_box_contents[$line][] = array(
205 'td' =>
'class="right" width="18"',
206 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).
'</span>',
213 $this->info_box_contents[$line][0] = array(
214 'td' =>
'class="center"',
215 'text'=>$langs->trans(
"NoRecordedProducts"),
219 $this->
db->free($result);
221 $this->info_box_contents[0][0] = array(
224 'text' => ($this->
db->error().
' sql='.$sql),
228 $this->info_box_contents[0][0] = array(
229 'td' =>
'class="nohover opacitymedium left"',
230 'text' => $langs->trans(
"ReadPermissionNotAllowed")
243 public function showBox($head =
null, $contents =
null, $nooutput = 0)
245 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);