dolibarr 21.0.0-beta
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 * Copyright (C) 2024 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
47'
48@phan-var-force CommonObjectLine $line
49@phan-var-force int $num
50@phan-var-force int $i
51@phan-var-force CommonObject $this
52@phan-var-force CommonObject $object
53';
54
55require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
56
57// Protection to avoid direct call of template
58if (empty($object) || !is_object($object)) {
59 print "Error, template page can't be called as URL";
60 exit(1);
61}
62
63
64global $filtertype;
65if (empty($filtertype)) {
66 $filtertype = 0;
67}
68
69
70global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
71
72if (empty($dateSelector)) {
73 $dateSelector = 0;
74}
75if (empty($forceall)) {
76 $forceall = 0;
77}
78if (empty($senderissupplier)) {
79 $senderissupplier = 0;
80}
81if (empty($inputalsopricewithtax)) {
82 $inputalsopricewithtax = 0;
83}
84if (empty($outputalsopricetotalwithtax)) {
85 $outputalsopricetotalwithtax = 0;
86}
87
88// add html5 elements
89if ($filtertype == 1) {
90 $domData = ' data-element="'.$line->element.'service"';
91} else {
92 $domData = ' data-element="'.$line->element.'"';
93}
94
95$domData .= ' data-id="'.$line->id.'"';
96$domData .= ' data-qty="'.$line->qty.'"';
97$domData .= ' data-product_type="'.$line->product_type.'"';
98
99// Lines for extrafield
100$objectline = new BOMLine($object->db);
101
102$coldisplay = 0;
103print "<!-- BEGIN PHP TEMPLATE bom/tpl/objectline_view.tpl.php -->\n";
104print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
105
106// Line nb
107if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
108 print '<td class="linecolnum center">'.($i + 1).'</td>';
109 $coldisplay++;
110}
111
112// Product
113print '<td class="linecoldescription bomline minwidth300imp tdoverflowmax300">';
114print '<div id="line_'.$line->id.'"></div>';
115$coldisplay++;
116$tmpproduct = new Product($object->db);
117$tmpproduct->fetch($line->fk_product);
118$tmpbom = new BOM($object->db);
119$res = $tmpbom->fetch($line->fk_bom_child);
120if ($tmpbom->id > 0) {
121 print $tmpproduct->getNomUrl(1);
122 print ' '.$langs->trans("or").' ';
123 print $tmpbom->getNomUrl(1);
124 print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
125 print(!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT') ? img_picto('', 'folder') : img_picto('', 'folder-open'));
126 print '</a>';
127} else {
128 print $tmpproduct->getNomUrl(1);
129 print ' - '.$tmpproduct->label;
130}
131
132// Line extrafield
133if (!empty($extrafields)) {
134 $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
135 if (!empty($temps)) {
136 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
137 print $temps;
138 print '</div>';
139 }
140}
141
142print '</td>';
143
144// Qty
145print '<td class="linecolqty nowrap right">';
146$coldisplay++;
147echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formatting role of function price
148print '</td>';
149
150if ($filtertype != 1) { // Product
151 if (getDolGlobalInt('PRODUCT_USE_UNITS')) { // For product, unit is shown only if option PRODUCT_USE_UNITS is on
152 print '<td class="linecoluseunit nowrap">';
153 $label = measuringUnitString($line->fk_unit, '', '', 1);
154 if ($label !== '') {
155 print $langs->trans($label);
156 }
157 print '</td>';
158 }
159} else { // Service
160 // Unit // For services, units are always enabled
161 print '<td class="linecolunit nowrap">';
162 $coldisplay++;
163
164 if (!empty($line->fk_unit)) {
165 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
166 $unit = new CUnits($this->db);
167 $unit->fetch($line->fk_unit);
168 print(isset($unit->label) ? "&nbsp;".$langs->trans(ucwords($unit->label))."&nbsp;" : '');
169 }
170
171 print '</td>';
172}
173if ($filtertype != 1 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Product or stock support for Services is active
174 // Qty frozen
175 print '<td class="linecolqtyfrozen nowrap right">';
176 $coldisplay++;
177 echo $line->qty_frozen ? yn($line->qty_frozen) : '';
178 print '</td>';
179
180 // Disable stock change
181 print '<td class="linecoldisablestockchange nowrap right">';
182 $coldisplay++;
183 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
184 print '</td>';
185
186 // Efficiency
187 print '<td class="linecolefficiency nowrap right">';
188 $coldisplay++;
189 echo $line->efficiency;
190 print '</td>';
191}
192
193// Service and workstations are active
194if ($filtertype == 1 && isModEnabled('workstation')) {
195 $workstation = new Workstation($object->db);
196 $res = $workstation->fetch($line->fk_default_workstation);
197
198 print '<td class="linecolworkstation nowrap">';
199 $coldisplay++;
200 if ($res > 0) {
201 $unit = new CUnits($object->db);
202 $fk_defaultUnit = $unit->getUnitFromCode('h', 'short_label', 'time');
203 $nbPlannedHour = $unit->unitConverter($line->qty, $line->fk_unit, $fk_defaultUnit);
204 $line->total_cost = 0;
205 if ($workstation->thm_machine_estimated) {
206 $line->total_cost += $nbPlannedHour * $workstation->thm_machine_estimated;
207 }
208 if ($workstation->thm_operator_estimated) {
209 $line->total_cost += $nbPlannedHour * $workstation->thm_operator_estimated;
210 }
211 echo $workstation->getNomUrl(1);
212 }
213 print '</td>';
214}
215
216// Cost
217$total_cost = 0;
218
219$tmpbom->calculateCosts();
220print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
221$coldisplay++;
222if (!empty($line->fk_bom_child)) {
223 echo '<span class="amount">'.price($tmpbom->total_cost * (float) $line->qty).'</span>';
224} else {
225 echo '<span class="amount">'.price($line->total_cost).'</span>';
226}
227print '</td>';
228
229if ($this->status == 0 && $user->hasRight('bom', 'write') && $action != 'selectlines') {
230 print '<td class="linecoledit center">';
231 $coldisplay++;
232 if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
233 } else {
234 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
235 }
236 print '</td>';
237
238 print '<td class="linecoldelete center">';
239 $coldisplay++;
240 if (($line->fk_prev_id == null) && empty($disableremove)) {
241 //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
242 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
243 print img_delete();
244 print '</a>';
245 }
246 print '</td>';
247
248 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
249 print '<td class="linecolmove tdlineupdown center">';
250 $coldisplay++;
251 if ($i > 0) {
252 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&token='.newToken().'&rowid='.$line->id.'">';
253 echo img_up('default', 0, 'imgupforline');
254 print '</a>';
255 }
256 if ($i < $num - 1) {
257 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&token='.newToken().'&rowid='.$line->id.'">';
258 echo img_down('default', 0, 'imgdownforline');
259 print '</a>';
260 }
261 print '</td>';
262 } else {
263 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
264 $coldisplay++;
265 }
266} else {
267 print '<td colspan="3"></td>';
268 $coldisplay += 3;
269}
270
271if ($action == 'selectlines') {
272 print '<td class="linecolcheck center">';
273 print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
274 print '</td>';
275}
276
277print '</tr>';
278
279// Select of all the sub-BOM lines
280// From this point to the end of the file, we only take care of sub-BOM lines
281$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
282$sql .= ' WHERE fk_bom ='. (int) $tmpbom->id;
283$resql = $object->db->query($sql);
284
285if ($resql) {
286 // Loop on all the sub-BOM lines if they exist
287 while ($obj = $object->db->fetch_object($resql)) {
288 $sub_bom_product = new Product($object->db);
289 $sub_bom_product->fetch($obj->fk_product);
290
291 $sub_bom = new BOM($object->db);
292 if (!empty($obj->fk_bom_child)) {
293 $sub_bom->fetch($obj->fk_bom_child);
294 }
295
296 $sub_bom_line = new BOMLine($object->db);
297 $sub_bom_line->fetch($obj->rowid);
298
299 //If hidden conf is set, we show directly all the sub-BOM lines
300 if (!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT')) {
301 print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
302 } else {
303 print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
304 }
305
306 // Product OR BOM
307 print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
308 if (!empty($obj->fk_bom_child)) {
309 print $sub_bom_product->getNomUrl(1);
310 print ' '.$langs->trans('or').' ';
311 print $sub_bom->getNomUrl(1);
312 } else {
313 print $sub_bom_product->getNomUrl(1);
314 print '</td>';
315 }
316
317 // Qty
318 $label = $sub_bom_product->getLabelOfUnit('long');
319 if ($sub_bom_line->qty_frozen > 0) {
320 print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
321 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
322 print '<td class="linecoluseunit nowrap left">';
323 if ($label !== '') {
324 print $langs->trans($label);
325 }
326 print '</td>';
327 }
328 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$langs->trans('Yes').'</td>';
329 } else {
330 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>';
331 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
332 print '<td class="linecoluseunit nowrap left">';
333 if ($label !== '') {
334 print $langs->trans($label);
335 }
336 print '</td>';
337 }
338
339 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
340 }
341
342 // Disable stock change
343 if ($sub_bom_line->disable_stock_change > 0) {
344 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
345 } else {
346 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
347 }
348
349 // Efficiency
350 print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
351
352 // Cost
353 if (!empty($sub_bom->id)) {
354 $sub_bom->calculateCosts();
355 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>';
356 $total_cost += $sub_bom->total_cost * $sub_bom_line->qty * (float) $line->qty;
357 } elseif ($sub_bom_product->type == Product::TYPE_SERVICE && isModEnabled('workstation') && !empty($sub_bom_product->fk_default_workstation)) {
358 //Convert qty to hour
359 $unit = measuringUnitString($sub_bom_line->fk_unit, '', '', 1);
360 $qty = convertDurationtoHour($sub_bom_line->qty, $unit);
361 $workstation = new Workstation($this->db);
362 $res = $workstation->fetch($sub_bom_product->fk_default_workstation);
363 if ($res > 0) {
364 $sub_bom_line->total_cost = (float) price2num($qty * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated), 'MT');
365 }
366
367 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>';
368 $this->total_cost += $line->total_cost;
369 } elseif ($sub_bom_product->cost_price > 0) {
370 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
371 print '<span class="amount">'.price(price2num($sub_bom_product->cost_price * $sub_bom_line->qty * (float) $line->qty, 'MT')).'</span></td>';
372 $total_cost += $sub_bom_product->cost_price * $sub_bom_line->qty * (float) $line->qty;
373 } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
374 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
375 print '<span class="amount">'.price(price2num($sub_bom_product->pmp * $sub_bom_line->qty * (float) $line->qty, 'MT')).'</span></td>';
376 $total_cost .= $sub_bom_product->pmp * $sub_bom_line->qty * (float) $line->qty;
377 } else { // Minimum purchase price if cost price and PMP aren't defined
378 $sql_supplier_price = "SELECT MIN(price) AS min_price, quantity AS qty FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
379 $sql_supplier_price .= " WHERE fk_product = ". (int) $sub_bom_product->id;
380 $sql_supplier_price .= " GROUP BY quantity ORDER BY quantity ASC";
381 $resql_supplier_price = $object->db->query($sql_supplier_price);
382 if ($resql_supplier_price) {
383 $obj = $object->db->fetch_object($resql_supplier_price); // Take first value so the ref with the smaller minimum quantity
384 if (!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) {
385 $line_cost = $obj->min_price / $obj->qty * $sub_bom_line->qty * (float) $line->qty;
386 } else {
387 $line_cost = $obj->min_price;
388 }
389 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($line_cost, 'MT').'</span></td>';
390 $total_cost += $line_cost;
391 }
392 }
393
394 print '<td></td>';
395 print '<td></td>';
396 print '<td></td>';
397 }
398}
399
400
401print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:338
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)
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
measuringUnitString($unitid, $measuring_style='', $unitscale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.