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