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