dolibarr 23.0.3
objectline_view.tpl.php
1<?php
2/* Copyright (C) 2010-2013 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 *
25 * Need to have the following variables defined:
26 * $object (invoice, order, ...)
27 * $conf
28 * $langs
29 * $forceall (0 by default, 1 for supplier invoices/orders)
30 * $element (used to test $user->hasRight($element, 'creer'))
31 * $permtoedit (used to replace test $user->hasRight($element, 'creer'))
32 * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
33 * $disableedit, $disablemove, $disableremove
34 *
35 * $type, $text, $description, $line
36 */
37
52'
53@phan-var-force int $i
54@phan-var-force int $num
55@phan-var-force BOMLine $line
56@phan-var-force CommonObject $this
57@phan-var-force CommonObject $object
58';
59
60require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
61
62// Protection to avoid direct call of template
63if (empty($object) || !is_object($object)) {
64 print "Error, template page can't be called as URL";
65 exit(1);
66}
67
68
69global $filtertype;
70if (empty($filtertype)) {
71 $filtertype = 0;
72}
73
74
75global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
76
77if (empty($forceall)) {
78 $forceall = 0;
79}
80if (empty($senderissupplier)) {
81 $senderissupplier = 0;
82}
83if (empty($inputalsopricewithtax)) {
84 $inputalsopricewithtax = 0;
85}
86if (empty($outputalsopricetotalwithtax)) {
87 $outputalsopricetotalwithtax = 0;
88}
89
90// add html5 elements
91if ($filtertype == 1) {
92 $domData = ' data-element="'.$line->element.'service"';
93} else {
94 $domData = ' data-element="'.$line->element.'"';
95}
96
97$domData .= ' data-id="'.$line->id.'"';
98$domData .= ' data-qty="'.$line->qty.'"';
99$domData .= ' data-product_type="'.$line->product_type.'"';
100
101// Lines for extrafield
102$objectline = new BOMLine($object->db);
103
104$coldisplay = 0;
105print "<!-- BEGIN PHP TEMPLATE bom/tpl/objectline_view.tpl.php -->\n";
106print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
107
108// Line nb
109if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
110 print '<td class="linecolnum center">'.($i + 1).'</td>';
111 $coldisplay++;
112}
113
114// Product
115print '<td class="linecoldescription bomline minwidth300imp tdoverflowmax300">';
116print '<div id="line_'.$line->id.'"></div>';
117$coldisplay++;
118
119$tmpproduct = new Product($object->db);
120$tmpproduct->fetch($line->fk_product);
121$tmpbom = new BOM($object->db);
122$res = $tmpbom->fetch((int) $line->fk_bom_child);
123if ($tmpbom->id > 0) {
124 print $tmpproduct->getNomUrl(1);
125 print ' '.$langs->trans("or").' ';
126 print $tmpbom->getNomUrl(1);
127 print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
128 print(!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT') ? img_picto('', 'folder') : img_picto('', 'folder-open'));
129 print '</a>';
130} else {
131 print $tmpproduct->getNomUrl(1);
132 print ' - '.$tmpproduct->label;
133}
134
135// Line extrafield
136if (!empty($extrafields)) {
137 $temps = $line->showOptionals($extrafields, 'view', array(), '', '', '1', 'line');
138 if (!empty($temps)) {
139 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
140 print $temps;
141 print '</div>';
142 }
143}
144
145print '</td>';
146
147// Qty
148print '<td class="linecolqty nowrap right">';
149$coldisplay++;
150echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formatting role of function price
151print '</td>';
152
153if ($filtertype != 1) { // Product
154 if (getDolGlobalInt('PRODUCT_USE_UNITS')) { // For product, unit is shown only if option PRODUCT_USE_UNITS is on
155 print '<td class="linecoluseunit nowrap">';
156 $label = measuringUnitString((int) $line->fk_unit, '', null, 1);
157 if ($label !== '') {
158 print $langs->trans($label);
159 }
160 print '</td>';
161 }
162} else { // Service
163 // Unit // For services, units are always enabled
164 print '<td class="linecolunit nowrap">';
165 $coldisplay++;
166
167 if (!empty($line->fk_unit)) {
168 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
169 $unit = new CUnits($this->db);
170 $unit->fetch($line->fk_unit);
171 print(isset($unit->label) ? "&nbsp;".$langs->trans(ucwords((string) $unit->label))."&nbsp;" : '');
172 }
173
174 print '</td>';
175}
176if ($filtertype != 1 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Product or stock support for Services is active
177 // Qty frozen
178 print '<td class="linecolqtyfrozen nowrap right">';
179 $coldisplay++;
180 echo $line->qty_frozen ? yn($line->qty_frozen) : '';
181 print '</td>';
182
183 // Disable stock change
184 print '<td class="linecoldisablestockchange nowrap right">';
185 $coldisplay++;
186 echo $line->disable_stock_change ? yn($line->disable_stock_change) : ''; // Yes, it is a quantity, not a price, but we just want the formatting role of function price
187 print '</td>';
188
189 // Efficiency
190 print '<td class="linecolefficiency nowrap right">';
191 $coldisplay++;
192 echo $line->efficiency;
193 print '</td>';
194}
195
196// Service and workstations are active
197if ($filtertype == 1 && isModEnabled('workstation')) {
198 $workstation = new Workstation($object->db);
199 $res = $workstation->fetch($line->fk_default_workstation);
200
201 print '<td class="linecolworkstation nowrap">';
202 $coldisplay++;
203 if ($res > 0) {
204 $unit = new CUnits($object->db);
205 $fk_defaultUnit = $unit->getUnitFromCode('h', 'short_label', 'time');
206 $nbPlannedHour = $unit->unitConverter($line->qty, $line->fk_unit, $fk_defaultUnit);
207 $line->total_cost = 0;
208 if ($workstation->thm_machine_estimated) {
209 $line->total_cost += $nbPlannedHour * $workstation->thm_machine_estimated;
210 }
211 if ($workstation->thm_operator_estimated) {
212 $line->total_cost += $nbPlannedHour * $workstation->thm_operator_estimated;
213 }
214 echo $workstation->getNomUrl(1);
215 }
216 print '</td>';
217}
218
219// Cost
220$total_cost = 0;
221
222$tmpbom->calculateCosts();
223print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
224
225$line->qty = (float) $line->qty;
226if ($tmpbom->id > 0) $line->qty /= $tmpbom->qty;
227
228$coldisplay++;
229if (!empty($line->fk_bom_child)) {
230 echo '<span class="amount">'.price(price2num($tmpbom->total_cost * $line->qty, 'MT')).'</span>';
231} else {
232 echo '<span class="amount">'.price($line->total_cost).'</span>';
233}
234print '</td>';
235
236if ($this->status == 0 && $user->hasRight('bom', 'write') && $action != 'selectlines') {
237 print '<td class="linecoledit center">';
238 $coldisplay++;
239 if (((int) $line->info_bits & 2) == 2 || !empty($disableedit)) {
240 } else {
241 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
242 }
243 print '</td>';
244
245 print '<td class="linecoldelete center">';
246 $coldisplay++;
247 if (empty($disableremove)) {
248 //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
249 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
250 print img_delete();
251 print '</a>';
252 }
253 print '</td>';
254
255 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
256 print '<td class="linecolmove tdlineupdown center">';
257 $coldisplay++;
258 if ($i > 0) {
259 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&token='.newToken().'&rowid='.$line->id.'">';
260 echo img_up('default', 0, 'imgupforline');
261 print '</a>';
262 }
263 if ($i < $num - 1) {
264 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&token='.newToken().'&rowid='.$line->id.'">';
265 echo img_down('default', 0, 'imgdownforline');
266 print '</a>';
267 }
268 print '</td>';
269 } else {
270 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
271 $coldisplay++;
272 }
273} else {
274 print '<td colspan="3"></td>';
275 $coldisplay += 3;
276}
277
278if ($action == 'selectlines') {
279 print '<td class="linecolcheck center">';
280 print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
281 print '</td>';
282}
283
284print '</tr>';
285
286// Select of all the sub-BOM lines
287// From this point to the end of the file, we only take care of sub-BOM lines
288$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
289$sql .= ' WHERE fk_bom ='. (int) $tmpbom->id;
290$resql = $object->db->query($sql);
291
292if ($resql) {
293 $j = 0; // sub bom line number
294 // Loop on all the sub-BOM lines if they exist
295 while ($obj = $object->db->fetch_object($resql)) {
296 $sub_bom_product = new Product($object->db);
297 $sub_bom_product->fetch($obj->fk_product);
298
299 $sub_bom = new BOM($object->db);
300 if (!empty($obj->fk_bom_child)) {
301 $sub_bom->fetch($obj->fk_bom_child);
302 }
303
304 $sub_bom_line = new BOMLine($object->db);
305 $sub_bom_line->fetch($obj->rowid);
306
307 //If hidden conf is set, we show directly all the sub-BOM lines
308 if (!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT')) {
309 print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
310 } else {
311 print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
312 }
313
314 // Line nb
315 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
316 print '<td class="linecolnum center">'.($i + 1).'.'.($j + 1).'</td>';
317 $coldisplay++;
318 }
319
320 // Product OR BOM
321 print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
322 if (!empty($obj->fk_bom_child)) {
323 print $sub_bom_product->getNomUrl(1);
324 print ' '.$langs->trans('or').' ';
325 print $sub_bom->getNomUrl(1);
326 } else {
327 print $sub_bom_product->getNomUrl(1);
328 print '</td>';
329 }
330
331 // Qty
332 $label = $sub_bom_product->getLabelOfUnit('long', $langs);
333 if ($sub_bom_line->qty_frozen > 0) {
334 print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price(price2num($sub_bom_line->qty, 'MS'), 0, '', 0, 0).'</td>';
335 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
336 print '<td class="linecoluseunit nowrap left">';
337 print $label;
338 print '</td>';
339 }
340 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$langs->trans('Yes').'</td>';
341 } else {
342 print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price(price2num($sub_bom_line->qty * $line->qty, 'MS'), 0, '', 0, 0).'</td>';
343 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
344 print '<td class="linecoluseunit nowrap left">';
345 print $label;
346 print '</td>';
347 }
348
349 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
350 }
351
352 // Disable stock change
353 if ($sub_bom_line->disable_stock_change > 0) {
354 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
355 } else {
356 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
357 }
358
359 // Efficiency
360 print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
361
362 // Cost
363 if (!empty($sub_bom->id)) {
364 $sub_bom->calculateCosts();
365 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price(price2num($sub_bom_line->qty * $line->qty * $sub_bom->unit_cost, 'MS')).'</span></td>';
366 } elseif ($sub_bom_product->type == Product::TYPE_SERVICE && isModEnabled('workstation') && !empty($sub_bom_product->fk_default_workstation)) {
367 //Convert qty to hour
368 $unit = measuringUnitString($sub_bom_line->fk_unit, '', null, 1);
369 $qty = convertDurationtoHour($sub_bom_line->qty, $unit);
370 $workstation = new Workstation($this->db);
371 $res = $workstation->fetch($sub_bom_product->fk_default_workstation);
372 if ($res > 0) {
373 $sub_bom_line->total_cost = (float) price2num($qty * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated), 'MT');
374 }
375
376 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>';
377 } elseif ($sub_bom_product->cost_price > 0) {
378 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
379 print '<span class="amount">'.price(price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
380 } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
381 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
382 print '<span class="amount">'.price(price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
383 } else { // Minimum purchase price if cost price and PMP aren't defined
384 $sql_supplier_price = "SELECT MIN(price) AS min_price, quantity AS qty FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
385 $sql_supplier_price .= " WHERE fk_product = ". (int) $sub_bom_product->id;
386 $sql_supplier_price .= " GROUP BY quantity ORDER BY quantity ASC";
387 $resql_supplier_price = $object->db->query($sql_supplier_price);
388 if ($resql_supplier_price) {
389 $obj = $object->db->fetch_object($resql_supplier_price); // Take first value so the ref with the smaller minimum quantity
390 if (!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) {
391 $line_cost = $obj->min_price / $obj->qty * $sub_bom_line->qty * $line->qty;
392 } else {
393 $line_cost = $obj->min_price;
394 }
395 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($line_cost, 'MT').'</span></td>';
396 }
397 }
398
399 print '<td></td>';
400 print '<td></td>';
401 print '<td></td>';
402 print '</tr>';
403 $j++;
404 }
405}
406
407
408print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class for BOM.
Definition bom.class.php:42
Class for BOMLine.
Class of dictionary type of thirdparty (used by imports)
Class to manage products or services.
const TYPE_SERVICE
Service.
Class for Workstation.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
Definition date.lib.php:341
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.