37 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstation.class.php';
40 if (empty($object) || !is_object($object)) {
41 print
"Error, template page can't be called as URL";
46 if (empty($filtertype)) $filtertype = 0;
49 global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
51 if (empty($dateSelector)) {
54 if (empty($forceall)) {
57 if (empty($senderissupplier)) {
58 $senderissupplier = 0;
60 if (empty($inputalsopricewithtax)) {
61 $inputalsopricewithtax = 0;
63 if (empty($outputalsopricetotalwithtax)) {
64 $outputalsopricetotalwithtax = 0;
68 if ($filtertype == 1) $domData =
' data-element="'.$line->element.
'service"';
69 else $domData =
' data-element="'.$line->element.
'"';
71 $domData .=
' data-id="'.$line->id.
'"';
72 $domData .=
' data-qty="'.$line->qty.
'"';
73 $domData .=
' data-product_type="'.$line->product_type.
'"';
76 $objectline =
new BOMLine($object->db);
79 print
"<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
80 print
'<tr id="row-'.$line->id.
'" class="drag drop oddeven" '.$domData.
' >';
83 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
84 print
'<td class="linecolnum center">'.($i + 1).
'</td>';
89 print
'<td class="linecoldescription minwidth300imp">';
90 print
'<div id="line_'.$line->id.
'"></div>';
92 $tmpproduct =
new Product($object->db);
93 $tmpproduct->fetch($line->fk_product);
94 $tmpbom =
new BOM($object->db);
95 $res = $tmpbom->fetch($line->fk_bom_child);
96 if ($tmpbom->id > 0) {
97 print $tmpproduct->getNomUrl(1);
98 print
' '.$langs->trans(
"or").
' ';
99 print $tmpbom->getNomUrl(1);
100 print
' <a class="collapse_bom" id="collapse-'.$line->id.
'" href="#">';
101 print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ?
img_picto(
'',
'folder') :
img_picto(
'',
'folder-open'));
104 print $tmpproduct->getNomUrl(1);
105 print
' - '.$tmpproduct->label;
109 if (!empty($extrafields)) {
110 $temps = $line->showOptionals($extrafields,
'view', array(),
'',
'', 1,
'line');
111 if (!empty($temps)) {
112 print
'<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.
'" name="extrafield_lines_area_'.$line->id.
'">';
121 print
'<td class="linecolqty nowrap right">';
123 echo
price($line->qty, 0,
'', 0, 0);
126 if ($filtertype != 1) {
127 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
128 print
'<td class="linecoluseunit nowrap left">';
129 $label = $tmpproduct->getLabelOfUnit(
'long');
131 print $langs->trans($label);
136 print
'<td class="linecolqtyfrozen nowrap right">';
138 echo $line->qty_frozen ?
yn($line->qty_frozen) :
'';
140 print
'<td class="linecoldisablestockchange nowrap right">';
142 echo $line->disable_stock_change ?
yn($line->disable_stock_change) :
'';
145 print
'<td class="linecolefficiency nowrap right">';
147 echo $line->efficiency;
151 print
'<td class="linecolunit nowrap right">';
154 if (!empty($line->fk_unit)) {
155 require_once DOL_DOCUMENT_ROOT.
'/core/class/cunits.class.php';
157 $unit->fetch($line->fk_unit);
158 print (isset($unit->label) ?
" ".$langs->trans(ucwords($unit->label)).
" " :
'');
166 $res = $workstation->fetch($tmpproduct->fk_default_workstation);
168 print
'<td class="linecolunit nowrap right">';
170 if ($res > 0) echo $workstation->getNomUrl();
177 $tmpbom->calculateCosts();
178 print
'<td id="costline_'.$line->id.
'" class="linecolcost nowrap right">';
180 if (!empty($line->fk_bom_child)) {
181 echo
'<span class="amount">'.price($tmpbom->total_cost * $line->qty).
'</span>';
183 echo
'<span class="amount">'.price($line->total_cost).
'</span>';
187 if ($this->status == 0 && ($object_rights->write) && $action !=
'selectlines') {
188 print
'<td class="linecoledit center">';
190 if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
192 print
'<a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=editline&token='.
newToken().
'&lineid='.$line->id.
'">'.
img_edit().
'</a>';
196 print
'<td class="linecoldelete center">';
198 if (($line->fk_prev_id ==
null) && empty($disableremove)) {
200 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=deleteline&token='.
newToken().
'&lineid='.$line->id.
'">';
206 if ($num > 1 && $conf->browser->layout !=
'phone' && empty($disablemove)) {
207 print
'<td class="linecolmove tdlineupdown center">';
210 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=up&token='.
newToken().
'&rowid='.$line->id.
'">';
211 echo
img_up(
'default', 0,
'imgupforline');
215 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=down&token='.
newToken().
'&rowid='.$line->id.
'">';
216 echo
img_down(
'default', 0,
'imgdownforline');
221 print
'<td '.(($conf->browser->layout !=
'phone' && empty($disablemove)) ?
' class="linecolmove tdlineupdown center"' :
' class="linecolmove center"').
'></td>';
225 print
'<td colspan="3"></td>';
226 $coldisplay = $coldisplay + 3;
229 if ($action ==
'selectlines') {
230 print
'<td class="linecolcheck center">';
231 print
'<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).
']" value="'.$line->id.
'" >';
239 $sql =
'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.
'bom_bomline AS bl';
240 $sql.=
' WHERE fk_bom ='. (int) $tmpbom->id;
241 $resql = $object->db->query($sql);
245 while ($obj = $object->db->fetch_object(
$resql)) {
246 $sub_bom_product =
new Product($object->db);
247 $sub_bom_product->fetch($obj->fk_product);
249 $sub_bom =
new BOM($object->db);
250 if (!empty($obj->fk_bom_child)) {
251 $sub_bom->fetch($obj->fk_bom_child);
254 $sub_bom_line =
new BOMLine($object->db);
255 $sub_bom_line->fetch($obj->rowid);
258 if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
259 print
'<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.
'">';
261 print
'<tr class="sub_bom_lines" parentid="'.$line->id.
'">';
265 print
'<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.
'">';
266 if (!empty($obj->fk_bom_child)) {
267 print $sub_bom_product->getNomUrl(1);
268 print
' '.$langs->trans(
'or').
' ';
269 print $sub_bom->getNomUrl(1);
271 print $sub_bom_product->getNomUrl(1);
276 $label = $sub_bom_product->getLabelOfUnit(
'long');
277 if ($sub_bom_line->qty_frozen > 0) {
278 print
'<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.
'">'.
price($sub_bom_line->qty, 0,
'', 0, 0).
'</td>';
279 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
280 print
'<td class="linecoluseunit nowrap left">';
281 if ($label !==
'') print $langs->trans($label);
284 print
'<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.
'">'.$langs->trans(
'Yes').
'</td>';
286 print
'<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.
'">'.
price($sub_bom_line->qty * $line->qty, 0,
'', 0, 0).
'</td>';
287 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
288 print
'<td class="linecoluseunit nowrap left">';
289 if ($label !==
'') print $langs->trans($label);
293 print
'<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.
'"> </td>';
297 if ($sub_bom_line->disable_stock_change > 0) {
298 print
'<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.
'">'.$sub_bom_line->disable_stock_change.
'</td>';
300 print
'<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.
'"> </td>';
304 print
'<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.
'">'.$sub_bom_line->efficiency.
'</td>';
307 if (!empty($sub_bom->id)) {
308 $sub_bom->calculateCosts();
309 print
'<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.
'"><span class="amount">'.
price(
price2num($sub_bom->total_cost * $sub_bom_line->qty * $line->qty,
'MT')).
'</span></td>';
310 $total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty;
316 $res = $workstation->fetch($sub_bom_product->fk_default_workstation);
317 if ($res > 0) $sub_bom_line->total_cost =
price2num($qty * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated),
'MT');
319 print
'<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.
'"><span class="amount">'.
price(
price2num($sub_bom_line->total_cost,
'MT')).
'</span></td>';
320 $this->total_cost += $line->total_cost;
321 } elseif ($sub_bom_product->cost_price > 0) {
322 print
'<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.
'">';
323 print
'<span class="amount">'.price(
price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty,
'MT')).
'</span></td>';
324 $total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty;
325 } elseif ($sub_bom_product->pmp > 0) {
326 print
'<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.
'">';
327 print
'<span class="amount">'.price(
price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty,
'MT')).
'</span></td>';
328 $total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
330 $sql_supplier_price =
'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
331 $sql_supplier_price.=
' WHERE fk_product = '. (int) $sub_bom_product->id;
332 $resql_supplier_price = $object->db->query($sql_supplier_price);
333 if ($resql_supplier_price) {
334 $obj = $object->db->fetch_object($resql_supplier_price);
335 $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty;
337 print
'<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.
'"><span class="amount">'.
price2num($line_cost,
'MT').
'</span></td>';
338 $total_cost+= $line_cost;
349 print
"<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";