69 global $user, $langs, $conf, $hookmanager;
73 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
74 $productstatic =
new Product($this->db);
76 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleProductsAlertStock", $max));
78 if (($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire')) && $user->hasRight(
'stock',
'lire')) {
79 $sql =
"SELECT p.rowid, p.label, p.price, p.ref, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.barcode, p.seuil_stock_alerte, p.entity,";
80 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
81 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
82 $sql .=
" SUM(".$this->db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
") as total_stock";
83 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
84 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_stock as s on p.rowid = s.fk_product";
85 $sql .=
' WHERE p.entity IN ('.getEntity($productstatic->element).
')';
86 $sql .=
" AND p.seuil_stock_alerte > 0";
87 if (!$user->hasRight(
'produit',
'lire')) {
88 $sql .=
' AND p.fk_product_type <> 0';
90 if (!$user->hasRight(
'service',
'lire')) {
91 $sql .=
' AND p.fk_product_type <> 1';
94 if (is_object($hookmanager)) {
95 $parameters = array(
'boxproductalertstocklist' => 1,
'boxcode' => $this->boxcode);
96 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $productstatic);
97 $sql .= $hookmanager->resPrint;
99 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.barcode, p.seuil_stock_alerte, p.entity,";
100 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
101 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export";
102 $sql .=
" HAVING SUM(".$this->db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
") < p.seuil_stock_alerte";
103 $sql .= $this->db->order(
'p.seuil_stock_alerte',
'DESC');
104 $sql .= $this->db->plimit($max, 0);
106 $result = $this->db->query($sql);
108 $langs->load(
"stocks");
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);
115 $price_base_type =
'';
119 $sqld =
"SELECT label";
120 $sqld .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
121 $sqld .=
" WHERE fk_product = ".((int) $objp->rowid);
122 $sqld .=
" AND lang = '".$this->db->escape($langs->getDefaultLang()).
"'";
125 $resultd = $this->db->query($sqld);
127 $objtp = $this->db->fetch_object($resultd);
128 if (isset($objtp->label) && $objtp->label !=
'') {
129 $objp->label = $objtp->label;
133 $productstatic->id = $objp->rowid;
134 $productstatic->ref = $objp->ref;
135 $productstatic->type = $objp->fk_product_type;
136 $productstatic->label = $objp->label;
137 $productstatic->entity = $objp->entity;
138 $productstatic->barcode = $objp->barcode;
139 $productstatic->status = $objp->tosell;
140 $productstatic->status_buy = $objp->tobuy;
141 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
142 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
143 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
144 $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
145 $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
146 $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
148 $this->info_box_contents[$line][] = array(
150 'text' => $productstatic->getNomUrl(1),
154 $this->info_box_contents[$line][] = array(
155 'td' =>
'class="tdoverflowmax100 maxwidth150onsmartphone"',
156 'text' => $objp->label,
159 if (!isModEnabled(
'dynamicprices') || empty($objp->fk_price_expression)) {
160 $price_base_type = $langs->trans($objp->price_base_type);
161 $price = ($objp->price_base_type ==
'HT') ?
price($objp->price) : $price =
price($objp->price_ttc);
163 $productstatic->fetch($objp->rowid,
'',
'', 1);
165 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
167 $price_result = $priceparser->parseProduct($productstatic);
168 if ($price_result >= 0) {
169 if ($objp->price_base_type ==
'HT') {
170 $price_base_type = $langs->trans(
"HT");
172 $price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
173 $price_base_type = $langs->trans(
"TTC");
175 $price =
price($price_result);
184 $this->info_box_contents[$line][] = array(
185 'td' =>
'class="center nowraponall"',
186 'text' =>
price2num($objp->total_stock,
'MS').
' / '.$objp->seuil_stock_alerte,
187 'text2'=>
img_warning($langs->transnoentitiesnoconv(
"StockLowerThanLimit", $objp->seuil_stock_alerte)),
190 $this->info_box_contents[$line][] = array(
191 'td' =>
'class="right" width="18"',
192 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).
'</span>',
196 $this->info_box_contents[$line][] = array(
197 'td' =>
'class="right" width="18"',
198 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).
'</span>',
205 $this->info_box_contents[$line][0] = array(
206 'td' =>
'class="center"',
207 'text'=>$langs->trans(
"NoTooLowStockProducts"),
211 $this->db->free($result);
213 $this->info_box_contents[0][0] = array(
216 'text' => ($this->db->error().
' sql='.$sql),
220 $this->info_box_contents[0][0] = array(
221 'td' =>
'class="nohover left"',
222 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'