27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 $langs->loadLangs(array(
'mrp',
'products',
'companies'));
39 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
40 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
41 if ($user->socid) $socid = $user->socid;
42 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
45 $hookmanager->initHooks(array(
'productstatscontract'));
51 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
52 $sortfield =
GETPOST(
"sortfield",
'alpha');
53 $sortorder =
GETPOST(
"sortorder",
'alpha');
55 if (empty($page) || $page == -1) { $page = 0; }
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 if (!$sortorder) $sortorder =
"DESC";
60 if (!$sortfield) $sortfield =
"b.date_valid";
67 $form =
new Form($db);
69 if ($id > 0 || !empty($ref))
72 $result = $product->fetch($id, $ref);
76 $parameters = array(
'id'=>$id);
77 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
78 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
80 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
85 $titre = $langs->trans(
"CardProduct".$product->type);
89 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
90 print $hookmanager->resPrint;
91 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
93 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
96 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
100 print '<div class="fichecenter">';
102 print '<div class="underbanner clearboth"></div>';
103 print '<table class="border tableforfield" width="100%">';
110 print '<div style="clear:both"></div>';
117 $total_qty_toconsume = 0;
118 $total_qty_toproduce = 0;
119 $bom_data_result = array();
123 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid,";
124 $sql .=
" b.qty as qty_toproduce";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
127 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
128 $sql .=
" AND b.fk_product =".$product->id;
129 $sql .= $db->order($sortfield, $sortorder);
132 $totalofrecords =
'';
133 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
135 $result = $db->query($sql);
137 $totalofrecords = $db->num_rows($result);
138 while ($objp = $db->fetch_object($result)) {
139 $total_qty_toproduce += $objp->qty_toproduce;
145 $sql .= $db->plimit($limit + 1, $offset);
147 $result = $db->query($sql);
149 $bomtmp =
new BOM($db);
150 $num = $db->num_rows($result);
153 while ($i < min($num, $limit)) {
154 $objp = $db->fetch_object($result);
155 $bomtmp->id = $objp->rowid;
156 $bomtmp->ref = $objp->ref;
157 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
158 $bom_data_result[$objp->rowid][
'qty_toproduce'] += ($objp->qty_toproduce > 0 ? $objp->qty_toproduce : 0);
159 $bom_data_result[$objp->rowid][
'qty_toconsume'] = 0;
160 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
161 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
171 $sql =
"SELECT b.rowid as rowid, b.ref, b.status, b.date_valid,";
172 $sql .=
" SUM(bl.qty) as qty_toconsume";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bom_bom as b";
174 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bom_bomline as bl ON bl.fk_bom=b.rowid";
176 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
177 $sql .=
" AND bl.fk_product=".$product->id;
178 $sql .=
" GROUP BY b.rowid, b.ref, b.date_valid, b.status";
179 $sql .= $db->order($sortfield, $sortorder);
182 $totalofrecords =
'';
183 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
185 $result = $db->query($sql);
187 $totalofrecords = $db->num_rows($result);
188 while ($objp = $db->fetch_object($result)) {
189 $total_qty_toconsume += $objp->qty_toconsume;
195 $sql .= $db->plimit($limit + 1, $offset);
197 $result = $db->query($sql);
199 $bomtmp =
new BOM($db);
200 $num = $db->num_rows($result);
203 while ($i < min($num, $limit)) {
204 $objp = $db->fetch_object($result);
205 $bomtmp->id = $objp->rowid;
206 $bomtmp->ref = $objp->ref;
208 if (!array_key_exists($objp->rowid, $bom_data_result)) {
209 $bom_data_result[$objp->rowid][
'link'] = $bomtmp->getNomUrl(1,
'production');
210 $bom_data_result[$objp->rowid][
'qty_toproduce'] = 0;
211 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
212 $bom_data_result[$objp->rowid][
'date_valid'] =
dol_print_date($db->jdate($objp->date_valid),
'dayhour');
213 $bom_data_result[$objp->rowid][
'status'] = $bomtmp->LibStatut($objp->status, 5);
215 $bom_data_result[$objp->rowid][
'qty_toconsume'] += ($objp->qty_toconsume > 0 ? $objp->qty_toconsume : 0);
226 if ($limit > 0 && $limit != $conf->liste_limit) $option .=
'&limit='.urlencode($limit);
227 if (!empty($id)) $option .=
'&id='.$product->id;
228 if (!empty($search_month)) $option .=
'&search_month='.urlencode($search_month);
229 if (!empty($search_year)) $option .=
'&search_year='.urlencode($search_year);
231 print '<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
232 if (!empty($sortfield))
233 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
234 if (!empty($sortorder))
235 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
237 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);
239 if (!empty($page)) $option .=
'&page='.urlencode($page);
241 print '<div class="div-table-responsive">';
242 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
244 print '<tr class="liste_titre">';
245 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"b.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
246 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"b.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
247 print_liste_field_titre(
"RowMaterial", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
248 print_liste_field_titre(
"Finished", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
249 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
252 if (!empty($bom_data_result)) {
253 foreach ($bom_data_result as $data)
255 print '<tr class="oddeven">';
259 print "<td align=\"center\">";
260 print $data[
'date_valid'].
"</td>";
261 print '<td class="center">'.$data[
'qty_toconsume'].
'</td>';
262 print '<td class="center">'.$data[
'qty_toproduce'].
'</td>';
263 print '<td class="center">'.$data[
'status'].
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
const TYPE_SERVICE
Service.
show_stats_for_company($product, $socid)
Show stats for company.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
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_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_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.
product_prepare_head($object)
Prepare array with list of tabs.