28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34$langs->loadLangs(array(
'mrp',
'products',
'companies'));
40$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
41$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
43 $socid = $user->socid;
47$hookmanager->initHooks(array(
'productstatsbom'));
53$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
54$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
55$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
56$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
57if (empty($page) || $page == -1) {
60$offset = $limit * $page;
67 $sortfield =
"b.date_valid";
70$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
79if ($id > 0 || !empty($ref)) {
81 $result = $product->fetch($id, $ref);
85 $parameters = array(
'id'=>$id);
86 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
91 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
95 $titre = $langs->trans(
"CardProduct".$product->type);
99 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
100 print $hookmanager->resPrint;
105 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
108 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
114 print
'<div class="fichecenter">';
116 print
'<div class="underbanner clearboth"></div>';
117 print
'<table class="border tableforfield" width="100%">';
124 print
'<div class="clearboth"></div>';
131 $total_qty_toconsume = 0;
132 $total_qty_toproduce = 0;
133 $product_cache=array();
134 $bom_data_result = array();
137 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
138 $sql .=
" b.qty as qty_toproduce";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
141 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
142 $sql .=
" AND b.fk_product = ".((int) $product->id);
143 $sql .= $db->order($sortfield, $sortorder);
146 $totalofrecords =
'';
148 $result = $db->query($sql);
150 $totalofrecords = $db->num_rows($result);
151 while ($objp = $db->fetch_object($result)) {
152 $total_qty_toproduce += $objp->qty_toproduce;
158 $sql .= $db->plimit($limit + 1, $offset);
160 $result = $db->query($sql);
162 $bomtmp =
new BOM($db);
163 $num = $db->num_rows($result);
166 while ($i < min($num, $limit)) {
167 $objp = $db->fetch_object($result);
168 $bomtmp->id = $objp->rowid;
169 $bomtmp->ref = $objp->ref;
171 if (!empty($objp->fk_product)) {
172 if (!array_key_exists($product->id, $product_cache)) {
173 $resultFetch = $product->fetch($objp->fk_product);
174 if ($resultFetch < 0) {
177 $product_cache[$product->id] = $product;
181 $bomtmp->fk_product = $objp->fk_product;
182 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
183 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
184 $bom_data_result[$objp->rowid][
'qty_toproduce'] += ($objp->qty_toproduce > 0 ? $objp->qty_toproduce : 0);
185 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
186 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
187 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
197 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
198 $sql .=
" SUM(bl.qty) as qty_toconsume";
199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
200 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bom_bomline as bl ON bl.fk_bom=b.rowid";
201 $sql .=
" WHERE b.entity IN (".getEntity(
'bom').
")";
202 $sql .=
" AND bl.fk_product = ".((int) $product->id);
203 $sql .=
" GROUP BY b.rowid, b.ref, b.status, b.date_valid, b.fk_product";
204 $sql .= $db->order($sortfield, $sortorder);
207 $totalofrecords =
'';
209 $result = $db->query($sql);
211 $totalofrecords = $db->num_rows($result);
212 while ($objp = $db->fetch_object($result)) {
213 $total_qty_toconsume += $objp->qty_toconsume;
219 $sql .= $db->plimit($limit + 1, $offset);
221 $result = $db->query($sql);
223 $bomtmp =
new BOM($db);
224 $num = $db->num_rows($result);
227 while ($i < min($num, $limit)) {
228 $objp = $db->fetch_object($result);
229 $bomtmp->id = $objp->rowid;
230 $bomtmp->ref = $objp->ref;
232 if (!empty($objp->fk_product)) {
233 if (!array_key_exists($product->id, $product_cache)) {
234 $resultFetch = $product->fetch($objp->fk_product);
235 if ($resultFetch < 0) {
238 $product_cache[$product->id] = $product;
242 $bomtmp->fk_product = $objp->fk_product;
244 if (!array_key_exists($objp->rowid, $bom_data_result)) {
245 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
246 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
247 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
248 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
249 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
250 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
252 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
262 $option .=
'&id='.$product->id;
264 if ($limit > 0 && $limit != $conf->liste_limit) {
265 $option .=
'&limit='.((int) $limit);
267 if (!empty($search_month)) {
268 $option .=
'&search_month='.urlencode($search_month);
270 if (!empty($search_year)) {
271 $option .=
'&search_year='.urlencode($search_year);
274 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
275 print
'<input type="hidden" name="token" value="'.newToken().
'">';
276 if (!empty($sortfield)) {
277 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
279 if (!empty($sortorder)) {
280 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
283 print_barre_liste($langs->trans(
"BOMs"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', count($bom_data_result), count($bom_data_result),
'', 0,
'',
'', $limit, 0, 0, 1);
286 $option .=
'&page='.urlencode($page);
289 print
'<div class="div-table-responsive">';
290 print
'<table class="tagtable liste listwithfilterbefore centpercent">';
292 print
'<tr class="liste_titre">';
293 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"b.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
294 print_liste_field_titre(
"Product", $_SERVER[
"PHP_SELF"],
"b.fk_product",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
295 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"b.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
296 print_liste_field_titre(
"RowMaterial", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
297 print_liste_field_titre(
"Finished", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
298 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
301 if (!empty($bom_data_result)) {
302 foreach ($bom_data_result as $data) {
303 print
'<tr class="oddeven">';
308 print $data[
'product'];
310 print
"<td align=\"center\">";
311 print $data[
'date_valid'].
"</td>";
312 print
'<td class="center">'.$data[
'qty_toconsume'].
'</td>';
313 print
'<td class="center">'.$data[
'qty_toproduce'].
'</td>';
314 print
'<td class="right">'.$data[
'status'].
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage products or services.
const TYPE_SERVICE
Service.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
product_prepare_head($object)
Prepare array with list of tabs.
show_stats_for_company($product, $socid)
Show stats for company.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.