70 global $user, $langs,
$conf, $hookmanager;
74 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
75 $productstatic =
new Product($this->db);
77 $this->info_box_head = array(
78 'text' => $langs->trans(
"BoxTitleLastProducts", $max).
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/product/list.php?sortfield=p.tms&sortorder=DESC"><span class="badge">...</span></a>',
81 if ($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire')) {
82 $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";
83 $sql .=
", p.accountancy_code_sell";
84 $sql .=
", p.accountancy_code_sell_intra";
85 $sql .=
", p.accountancy_code_sell_export";
86 $sql .=
", p.accountancy_code_buy";
87 $sql .=
", p.accountancy_code_buy_intra";
88 $sql .=
", p.accountancy_code_buy_export";
89 $sql .=
', p.barcode';
90 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
91 $sql .=
' WHERE p.entity IN ('.getEntity($productstatic->element).
')';
92 if (!$user->hasRight(
'produit',
'lire')) {
93 $sql .=
' AND p.fk_product_type != 0';
95 if (!$user->hasRight(
'service',
'lire')) {
96 $sql .=
' AND p.fk_product_type != 1';
99 if (is_object($hookmanager)) {
100 $parameters = array(
'boxproductlist' => 1,
'boxcode' => $this->boxcode);
101 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $productstatic);
102 $sql .= $hookmanager->resPrint;
104 $sql .= $this->db->order(
'p.datec',
'DESC');
105 $sql .= $this->db->plimit($max, 0);
107 $result = $this->db->query($sql);
109 $num = $this->db->num_rows($result);
111 while ($line < $num) {
112 $objp = $this->db->fetch_object($result);
113 $datem = $this->db->jdate($objp->tms);
117 $sqld =
"SELECT label";
118 $sqld .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
119 $sqld .=
" WHERE fk_product = ".((int) $objp->rowid);
120 $sqld .=
" AND lang = '".$this->db->escape($langs->getDefaultLang()).
"'";
123 $resultd = $this->db->query($sqld);
125 $objtp = $this->db->fetch_object($resultd);
126 if (isset($objtp->label) && $objtp->label !=
'') {
127 $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;
136 $productstatic->status = $objp->tosell;
137 $productstatic->status_buy = $objp->tobuy;
138 $productstatic->barcode = $objp->barcode;
139 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
140 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
141 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
142 $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
143 $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
144 $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
145 $productstatic->date_modification = $datem;
147 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') ? $user->hasRight(
'product',
'product_advance',
'read_prices') : $user->hasRight(
'product',
'read');
148 if ($productstatic->isService()) {
149 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') ? $user->hasRight(
'service',
'service_advance',
'read_prices') : $user->hasRight(
'service',
'read');
152 $this->info_box_contents[$line][] = array(
153 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
154 'text' => $productstatic->getNomUrl(1),
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="tdoverflowmax100 maxwidth100onsmartphone"',
160 'text' => $objp->label,
163 $price_base_type =
'';
164 if ($usercancreadprice) {
165 if (!isModEnabled(
'dynamicprices') || 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 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
174 $price_result = $priceparser->parseProduct($productstatic);
175 if ($price_result >= 0) {
176 if ($objp->price_base_type ==
'HT') {
177 $price_base_type = $langs->trans(
"HT");
179 $price_result *= (1 + ($productstatic->tva_tx / 100));
180 $price_base_type = $langs->trans(
"TTC");
182 $price =
price($price_result);
186 $this->info_box_contents[$line][] = array(
187 'td' =>
'class="nowraponall right amount"',
191 $this->info_box_contents[$line][] = array(
192 'td' =>
'class="nowrap"',
193 'text' => $price_base_type,
196 $this->info_box_contents[$line][] = array(
201 $this->info_box_contents[$line][] = array(
202 'td' =>
'class="right" width="18"',
203 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).
'</span>',
207 $this->info_box_contents[$line][] = array(
208 'td' =>
'class="right" width="18"',
209 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).
'</span>',
222 $this->db->free($result);
224 $this->info_box_contents[0][0] = array(
227 'text' => ($this->db->error().
' sql='.$sql),
231 $this->info_box_contents[0][0] = array(
232 'td' =>
'class="nohover left"',
233 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'