29 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
30 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38 var $boxcode=
"productsalertstock";
39 var $boximg=
"object_product";
40 var $boxlabel=
"BoxProductsAlertStock";
41 var $depends = array(
"produit");
50 var $info_box_head = array();
51 var $info_box_contents = array();
66 $listofmodulesforexternal=explode(
',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
67 $tmpentry=array(
'enabled'=>((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && ! empty($conf->stock->enabled)),
'perms'=>($user->rights->stock->lire),
'module'=>
'product|service|stock');
68 $showmode=
isVisibleToUserType(($user->societe_id > 0 ? 1 : 0), $tmpentry, $listofmodulesforexternal);
69 $this->hidden=($showmode != 1);
80 global $user, $langs, $db, $conf, $hookmanager;
84 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
85 $productstatic=
new Product($db);
87 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleProductsAlertStock",$max));
89 if (($user->rights->produit->lire || $user->rights->service->lire) && $user->rights->stock->lire)
91 $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.seuil_stock_alerte, p.entity,";
92 $sql.=
" SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
") as total_stock";
93 $sql.=
" FROM ".MAIN_DB_PREFIX.
"product as p";
94 $sql.=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_stock as s on p.rowid = s.fk_product";
95 $sql.=
' WHERE p.entity IN ('.getEntity($productstatic->element).
')';
96 $sql.=
" AND p.tosell = 1 AND p.seuil_stock_alerte > 0";
97 if (empty($user->rights->produit->lire)) $sql.=
' AND p.fk_product_type != 0';
98 if (empty($user->rights->service->lire)) $sql.=
' AND p.fk_product_type != 1';
100 if (is_object($hookmanager))
102 $parameters=array(
'boxproductalertstocklist'=>1);
103 $reshook=$hookmanager->executeHooks(
'printFieldListWhere',$parameters);
104 $sql.=$hookmanager->resPrint;
106 $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.seuil_stock_alerte, p.entity";
107 $sql.=
" HAVING SUM(".$db->ifsql(
"s.reel IS NULL",
"0",
"s.reel").
") < p.seuil_stock_alerte";
108 $sql.= $db->order(
'p.seuil_stock_alerte',
'DESC');
109 $sql.= $db->plimit($max, 0);
111 $result = $db->query($sql);
114 $langs->load(
"stocks");
115 $num = $db->num_rows($result);
117 while ($line < $num) {
118 $objp = $db->fetch_object($result);
119 $datem=$db->jdate($objp->tms);
122 if (! empty($conf->global->MAIN_MULTILANGS))
124 $sqld =
"SELECT label";
125 $sqld.=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
126 $sqld.=
" WHERE fk_product=".$objp->rowid;
127 $sqld.=
" AND lang='". $langs->getDefaultLang() .
"'";
130 $resultd = $db->query($sqld);
133 $objtp = $db->fetch_object($resultd);
134 if (isset($objtp->label) && $objtp->label !=
'')
135 $objp->label = $objtp->label;
138 $productstatic->id = $objp->rowid;
139 $productstatic->ref = $objp->ref;
140 $productstatic->type = $objp->fk_product_type;
141 $productstatic->label = $objp->label;
142 $productstatic->entity = $objp->entity;
144 $this->info_box_contents[$line][] = array(
146 'text' => $productstatic->getNomUrl(1),
150 $this->info_box_contents[$line][] = array(
151 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
152 'text' => $objp->label,
155 if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression))
157 $price_base_type=$langs->trans($objp->price_base_type);
158 $price=($objp->price_base_type ==
'HT')?
price($objp->price):$price=
price($objp->price_ttc);
162 $productstatic->fetch($objp->rowid,
'',
'', 1);
164 $price_result = $priceparser->parseProduct($productstatic);
165 if ($price_result >= 0) {
166 if ($objp->price_base_type ==
'HT')
168 $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);
179 $this->info_box_contents[$line][] = array(
180 'td' =>
'class="right"',
184 $this->info_box_contents[$line][] = array(
185 'td' =>
'class="nowrap"',
186 'text' => $price_base_type,
189 $this->info_box_contents[$line][] = array(
190 'td' =>
'align="center"',
191 'text' => $objp->total_stock .
' / '.$objp->seuil_stock_alerte,
192 'text2'=>
img_warning($langs->transnoentitiesnoconv(
"StockLowerThanLimit", $objp->seuil_stock_alerte)));
194 $this->info_box_contents[$line][] = array(
195 'td' =>
'align="right" width="18"',
196 'text' =>
'<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell,3,0).
'<span>',
200 $this->info_box_contents[$line][] = array(
201 'td' =>
'align="right" width="18"',
202 'text' =>
'<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy,3,0).
'<span>',
209 $this->info_box_contents[$line][0] = array(
210 'td' =>
'align="center"',
211 'text'=>$langs->trans(
"NoTooLowStockProducts"),
218 $this->info_box_contents[0][0] = array(
221 'text' => ($db->error().
' sql='.$sql),
226 $this->info_box_contents[0][0] = array(
227 'td' =>
'align="left" class="nohover opacitymedium"',
228 'text' => $langs->trans(
"ReadPermissionNotAllowed")
241 function showBox($head = null, $contents = null, $nooutput=0)
243 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
img_warning($titlealt='default', $moreatt='')
Show warning logo.
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.
__construct($db, $param='')
Constructor.
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...
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage the box to show too low stocks products.