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');
53 $socid = $user->socid;
57$hookmanager->initHooks(array(
'productstatsbom'));
63$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
64$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
66if (empty($page) || $page == -1) {
69$offset = $limit * $page;
76 $sortfield =
"b.date_valid";
81$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
90if ($id > 0 || !empty($ref)) {
92 $result = $product->fetch($id, $ref);
96 $parameters = array(
'id' => $id);
97 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
102 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'',
'mod-product page-stats_bom');
106 $titre = $langs->trans(
"CardProduct".$product->type);
110 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
111 print $hookmanager->resPrint;
116 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
119 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
123 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
125 print
'<div class="fichecenter">';
127 print
'<div class="underbanner clearboth"></div>';
128 print
'<table class="border tableforfield centpercent">';
135 print
'<div class="clearboth"></div>';
142 $total_qty_toconsume = 0;
143 $total_qty_toproduce = 0;
144 $product_cache = array();
145 $bom_data_result = array();
148 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
149 $sql .=
" b.qty as qty_toproduce";
150 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
152 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
153 $sql .=
" AND b.fk_product = ".((int) $product->id);
154 $sql .= $db->order($sortfield, $sortorder);
157 $totalofrecords =
'';
159 $result = $db->query($sql);
161 $totalofrecords = $db->num_rows($result);
162 while ($objp = $db->fetch_object($result)) {
163 $total_qty_toproduce += $objp->qty_toproduce;
169 $sql .= $db->plimit($limit + 1, $offset);
171 $result = $db->query($sql);
173 $bomtmp =
new BOM($db);
174 $num = $db->num_rows($result);
177 while ($i < min($num, $limit)) {
178 $objp = $db->fetch_object($result);
179 $bomtmp->id = $objp->rowid;
180 $bomtmp->ref = $objp->ref;
182 if (!empty($objp->fk_product)) {
183 if (!array_key_exists($product->id, $product_cache)) {
184 $resultFetch = $product->fetch($objp->fk_product);
185 if ($resultFetch < 0) {
188 $product_cache[$product->id] = $product;
192 $bomtmp->fk_product = $objp->fk_product;
193 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
194 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
195 if (empty($bom_data_result[$objp->rowid][
'qty_toproduce'])) {
196 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
198 $bom_data_result[$objp->rowid][
'qty_toproduce'] += ($objp->qty_toproduce > 0 ? $objp->qty_toproduce : 0);
199 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
200 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
201 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
211 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid, b.fk_product,";
212 $sql .=
" SUM(bl.qty) as qty_toconsume";
213 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
214 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bom_bomline as bl ON bl.fk_bom=b.rowid";
215 $sql .=
" WHERE b.entity IN (".getEntity(
'bom').
")";
216 $sql .=
" AND bl.fk_product = ".((int) $product->id);
217 $sql .=
" GROUP BY b.rowid, b.ref, b.status, b.date_valid, b.fk_product";
218 $sql .= $db->order($sortfield, $sortorder);
221 $totalofrecords =
'';
223 $result = $db->query($sql);
225 $totalofrecords = $db->num_rows($result);
226 while ($objp = $db->fetch_object($result)) {
227 $total_qty_toconsume += $objp->qty_toconsume;
233 $sql .= $db->plimit($limit + 1, $offset);
235 $result = $db->query($sql);
237 $bomtmp =
new BOM($db);
238 $num = $db->num_rows($result);
241 while ($i < min($num, $limit)) {
242 $objp = $db->fetch_object($result);
243 $bomtmp->id = $objp->rowid;
244 $bomtmp->ref = $objp->ref;
246 if (!empty($objp->fk_product)) {
247 if (!array_key_exists($product->id, $product_cache)) {
248 $resultFetch = $product->fetch($objp->fk_product);
249 if ($resultFetch < 0) {
252 $product_cache[$product->id] = $product;
256 $bomtmp->fk_product = $objp->fk_product;
258 if (!array_key_exists($objp->rowid, $bom_data_result)) {
259 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
260 $bom_data_result[$objp->rowid][
'product'] = (array_key_exists($objp->fk_product, $product_cache) ? $product_cache[$objp->fk_product]->getNomUrl(1) :
'');
261 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
262 if (empty($bom_data_result[$objp->rowid][
'qty_toconsume'])) {
263 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
265 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
266 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
267 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
269 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
279 $option .=
'&id='.$product->id;
281 if ($limit > 0 && $limit !=
$conf->liste_limit) {
282 $option .=
'&limit='.((int) $limit);
284 if (!empty($search_month)) {
285 $option .=
'&search_month='.urlencode((
string) $search_month);
287 if (!empty($search_year)) {
288 $option .=
'&search_year='.urlencode((
string) $search_year);
291 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
292 print
'<input type="hidden" name="token" value="'.newToken().
'">';
293 if (!empty($sortfield)) {
294 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
296 if (!empty($sortorder)) {
297 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
300 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);
303 $option .=
'&page='.urlencode((
string) ($page));
306 print
'<div class="div-table-responsive">';
307 print
'<table class="tagtable liste listwithfilterbefore centpercent">';
309 print
'<tr class="liste_titre">';
310 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"b.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
311 print_liste_field_titre(
"Product", $_SERVER[
"PHP_SELF"],
"b.fk_product",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
312 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"b.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
313 print_liste_field_titre(
"RowMaterial", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
314 print_liste_field_titre(
"Finished", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
315 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
318 if (!empty($bom_data_result)) {
319 foreach ($bom_data_result as $data) {
320 print
'<tr class="oddeven">';
325 print $data[
'product'];
327 print
"<td align=\"center\">";
328 print $data[
'date_valid'].
"</td>";
329 print
'<td class="center">'.$data[
'qty_toconsume'].
'</td>';
330 print
'<td class="center">'.$data[
'qty_toproduce'].
'</td>';
331 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($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_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)
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.
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.