78 global $user, $langs, $conf, $hookmanager;
82 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
83 $productstatic =
new Product($this->db);
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastProducts", $max));
87 if ($user->rights->produit->lire || $user->hasRight(
'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")