29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35$langs->loadLangs(array(
'mrp',
'products',
'companies'));
41$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
42$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
44 $socid = $user->socid;
48$hookmanager->initHooks(array(
'productstatsbom'));
54$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
55$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
57if (empty($page) || $page == -1) {
60$offset = $limit * $page;
67 $sortfield =
"b.date_valid";
72$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
81if ($id > 0 || !empty($ref)) {
83 $result = $product->fetch($id, $ref);
87 $parameters = array(
'id' => $id);
88 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
93 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'',
'mod-product page-stats_bom');
97 $titre = $langs->trans(
"CardProduct".$product->type);
101 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
102 print $hookmanager->resPrint;
107 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
110 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
114 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
116 print
'<div class="fichecenter">';
118 print
'<div class="underbanner clearboth"></div>';
119 print
'<table class="border tableforfield centpercent">';
126 print
'<div class="clearboth"></div>';
133 $total_qty_toconsume = 0;
134 $total_qty_toproduce = 0;
135 $product_cache = array();
136 $bom_data_result = array();
139 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
140 $sql .=
" b.qty as qty_toproduce";
141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
143 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
144 $sql .=
" AND b.fk_product = ".((int) $product->id);
145 $sql .= $db->order($sortfield, $sortorder);
148 $totalofrecords =
'';
150 $result = $db->query($sql);
152 $totalofrecords = $db->num_rows($result);
153 while ($objp = $db->fetch_object($result)) {
154 $total_qty_toproduce += $objp->qty_toproduce;
160 $sql .= $db->plimit($limit + 1, $offset);
162 $result = $db->query($sql);
164 $bomtmp =
new BOM($db);
165 $num = $db->num_rows($result);
168 while ($i < min($num, $limit)) {
169 $objp = $db->fetch_object($result);
170 $bomtmp->id = $objp->rowid;
171 $bomtmp->ref = $objp->ref;
173 if (!empty($objp->fk_product)) {
174 if (!array_key_exists($product->id, $product_cache)) {
175 $resultFetch = $product->fetch($objp->fk_product);
176 if ($resultFetch < 0) {
179 $product_cache[$product->id] = $product;
183 $bomtmp->fk_product = $objp->fk_product;
184 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
185 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
186 if (empty($bom_data_result[$objp->rowid][
'qty_toproduce'])) {
187 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
189 $bom_data_result[$objp->rowid][
'qty_toproduce'] += ($objp->qty_toproduce > 0 ? $objp->qty_toproduce : 0);
190 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
191 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
192 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
202 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
203 $sql .=
" SUM(bl.qty) as qty_toconsume";
204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
205 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bom_bomline as bl ON bl.fk_bom=b.rowid";
206 $sql .=
" WHERE b.entity IN (".getEntity(
'bom').
")";
207 $sql .=
" AND bl.fk_product = ".((int) $product->id);
208 $sql .=
" GROUP BY b.rowid, b.ref, b.status, b.date_valid, b.fk_product";
209 $sql .= $db->order($sortfield, $sortorder);
212 $totalofrecords =
'';
214 $result = $db->query($sql);
216 $totalofrecords = $db->num_rows($result);
217 while ($objp = $db->fetch_object($result)) {
218 $total_qty_toconsume += $objp->qty_toconsume;
224 $sql .= $db->plimit($limit + 1, $offset);
226 $result = $db->query($sql);
228 $bomtmp =
new BOM($db);
229 $num = $db->num_rows($result);
232 while ($i < min($num, $limit)) {
233 $objp = $db->fetch_object($result);
234 $bomtmp->id = $objp->rowid;
235 $bomtmp->ref = $objp->ref;
237 if (!empty($objp->fk_product)) {
238 if (!array_key_exists($product->id, $product_cache)) {
239 $resultFetch = $product->fetch($objp->fk_product);
240 if ($resultFetch < 0) {
243 $product_cache[$product->id] = $product;
247 $bomtmp->fk_product = $objp->fk_product;
249 if (!array_key_exists($objp->rowid, $bom_data_result)) {
250 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
251 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
252 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
253 if (empty($bom_data_result[$objp->rowid][
'qty_toconsume'])) {
254 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
256 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
257 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
258 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
260 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
270 $option .=
'&id='.$product->id;
272 if ($limit > 0 && $limit != $conf->liste_limit) {
273 $option .=
'&limit='.((int) $limit);
275 if (!empty($search_month)) {
276 $option .=
'&search_month='.urlencode((
string) $search_month);
278 if (!empty($search_year)) {
279 $option .=
'&search_year='.urlencode((
string) $search_year);
282 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
283 print
'<input type="hidden" name="token" value="'.newToken().
'">';
284 if (!empty($sortfield)) {
285 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
287 if (!empty($sortorder)) {
288 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
291 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);
294 $option .=
'&page='.urlencode((
string) ($page));
297 print
'<div class="div-table-responsive">';
298 print
'<table class="tagtable liste listwithfilterbefore centpercent">';
300 print
'<tr class="liste_titre">';
301 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"b.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
302 print_liste_field_titre(
"Product", $_SERVER[
"PHP_SELF"],
"b.fk_product",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
303 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"b.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
304 print_liste_field_titre(
"RowMaterial", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
305 print_liste_field_titre(
"Finished", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
306 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
309 if (!empty($bom_data_result)) {
310 foreach ($bom_data_result as $data) {
311 print
'<tr class="oddeven">';
316 print $data[
'product'];
318 print
"<td align=\"center\">";
319 print $data[
'date_valid'].
"</td>";
320 print
'<td class="center">'.$data[
'qty_toconsume'].
'</td>';
321 print
'<td class="center">'.$data[
'qty_toproduce'].
'</td>';
322 print
'<td class="right">'.$data[
'status'].
'</td>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $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.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 a product.
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.