30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44$langs->loadLangs(array(
'mrp',
'products',
'companies'));
50$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
51$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
54 $socid = $user->socid;
58$hookmanager->initHooks(array(
'productstatsbom'));
64$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
65$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67if (empty($page) || $page == -1) {
70$offset = $limit * $page;
77 $sortfield =
"b.date_valid";
80$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
89if ($id > 0 || !empty($ref)) {
91 $result = $product->fetch($id, $ref);
95 $parameters = array(
'id' => $id);
96 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
101 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'',
'mod-product page-stats_bom');
105 $titre = $langs->trans(
"CardProduct".$product->type);
109 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
110 print $hookmanager->resPrint;
115 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
118 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
122 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
124 print
'<div class="fichecenter">';
126 print
'<div class="underbanner clearboth"></div>';
127 print
'<table class="border tableforfield centpercent">';
134 print
'<div class="clearboth"></div>';
141 $total_qty_toconsume = 0;
142 $total_qty_toproduce = 0;
143 $product_cache = array();
144 $bom_data_result = array();
147 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
148 $sql .=
" b.qty as qty_toproduce";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
151 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
152 $sql .=
" AND b.fk_product = ".((int) $product->id);
153 $sql .= $db->order($sortfield, $sortorder);
156 $totalofrecords =
'';
158 $result = $db->query($sql);
160 $totalofrecords = $db->num_rows($result);
161 while ($objp = $db->fetch_object($result)) {
162 $total_qty_toproduce += $objp->qty_toproduce;
168 $sql .= $db->plimit($limit + 1, $offset);
170 $result = $db->query($sql);
172 $bomtmp =
new BOM($db);
173 $num = $db->num_rows($result);
176 while ($i < min($num, $limit)) {
177 $objp = $db->fetch_object($result);
178 $bomtmp->id = $objp->rowid;
179 $bomtmp->ref = $objp->ref;
181 if (!empty($objp->fk_product)) {
182 if (!array_key_exists($product->id, $product_cache)) {
183 $resultFetch = $product->fetch($objp->fk_product);
184 if ($resultFetch < 0) {
187 $product_cache[$product->id] = $product;
191 $bomtmp->fk_product = $objp->fk_product;
192 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
193 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
194 if (empty($bom_data_result[$objp->rowid][
'qty_toproduce'])) {
195 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
197 $bom_data_result[$objp->rowid][
'qty_toproduce'] += ($objp->qty_toproduce > 0 ? $objp->qty_toproduce : 0);
198 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
199 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
200 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
210 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
211 $sql .=
" SUM(bl.qty) as qty_toconsume";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
213 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bom_bomline as bl ON bl.fk_bom=b.rowid";
214 $sql .=
" WHERE b.entity IN (".getEntity(
'bom').
")";
215 $sql .=
" AND bl.fk_product = ".((int) $product->id);
216 $sql .=
" GROUP BY b.rowid, b.ref, b.status, b.date_valid, b.fk_product";
217 $sql .= $db->order($sortfield, $sortorder);
220 $totalofrecords =
'';
222 $result = $db->query($sql);
224 $totalofrecords = $db->num_rows($result);
225 while ($objp = $db->fetch_object($result)) {
226 $total_qty_toconsume += $objp->qty_toconsume;
232 $sql .= $db->plimit($limit + 1, $offset);
234 $result = $db->query($sql);
236 $bomtmp =
new BOM($db);
237 $num = $db->num_rows($result);
240 while ($i < min($num, $limit)) {
241 $objp = $db->fetch_object($result);
242 $bomtmp->id = $objp->rowid;
243 $bomtmp->ref = $objp->ref;
245 if (!empty($objp->fk_product)) {
246 if (!array_key_exists($objp->fk_product, $product_cache)) {
247 $resultFetch = $product->fetch($objp->fk_product);
248 if ($resultFetch < 0) {
251 $product_cache[$product->id] = $product;
255 $bomtmp->fk_product = $objp->fk_product;
257 if (!array_key_exists($objp->rowid, $bom_data_result)) {
258 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
259 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
260 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
261 if (empty($bom_data_result[$objp->rowid][
'qty_toconsume'])) {
262 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
264 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
265 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
266 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
268 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
278 $option .=
'&id='.$product->id;
280 if ($limit > 0 && $limit !=
$conf->liste_limit) {
281 $option .=
'&limit='.((int) $limit);
283 if (!empty($search_month)) {
284 $option .=
'&search_month='.urlencode((
string) $search_month);
286 if (!empty($search_year)) {
287 $option .=
'&search_year='.urlencode((
string) $search_year);
290 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
291 print
'<input type="hidden" name="token" value="'.newToken().
'">';
292 if (!empty($sortfield)) {
293 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
295 if (!empty($sortorder)) {
296 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
299 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);
302 $option .=
'&page='.urlencode((
string) ($page));
305 print
'<div class="div-table-responsive">';
306 print
'<table class="tagtable liste listwithfilterbefore centpercent">';
308 print
'<tr class="liste_titre">';
309 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"b.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
310 print_liste_field_titre(
"Product", $_SERVER[
"PHP_SELF"],
"b.fk_product",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
311 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"b.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
312 print_liste_field_titre(
"RowMaterial", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
313 print_liste_field_titre(
"Finished", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
314 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
317 if (!empty($bom_data_result)) {
318 foreach ($bom_data_result as $data) {
319 print
'<tr class="oddeven">';
324 print $data[
'product'];
326 print
"<td align=\"center\">";
327 print $data[
'date_valid'].
"</td>";
328 print
'<td class="center">'.$data[
'qty_toconsume'].
'</td>';
329 print
'<td class="center">'.$data[
'qty_toproduce'].
'</td>';
330 print
'<td class="right">'.$data[
'status'].
'</td>';
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage products or services.
const TYPE_SERVICE
Service.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $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, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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, $morecssdiv='')
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).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.