dolibarr 20.0.0
originproductline.tpl.php
1<?php
2/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20// Protection to avoid direct call of template
21if (empty($conf) || !is_object($conf)) {
22 print "Error, template page can't be called as URL";
23 exit(1);
24}
25
26'@phan-var-force CommonObject $this';
27
28global $db, $langs;
29
30if (empty($form) || !is_object($form)) {
31 $form = new Form($db);
32}
33
34$qtytoconsumeforline = $this->tpl['qty'] / (!empty($this->tpl['efficiency']) ? $this->tpl['efficiency'] : 1);
35/*if ((empty($this->tpl['qty_frozen']) && $this->tpl['qty_bom'] > 1)) {
36 $qtytoconsumeforline = $qtytoconsumeforline / $this->tpl['qty_bom'];
37}*/
38$qtytoconsumeforline = price2num($qtytoconsumeforline, 'MS');
39
40$tmpproduct = new Product($db);
41if ($line->fk_product > 0) {
42 $tmpproduct->fetch($line->fk_product);
43}
44$tmpbom = new BOM($db);
45if ($line->fk_bom_child > 0) {
46 $res = $tmpbom->fetch($line->fk_bom_child);
47}
48
49?>
50
51<!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
52<?php
53print '<tr class="oddeven'.(empty($this->tpl['strike']) ? '' : ' strikefordisabled').'">';
54// Ref or label
55print '<td>';
56if ($res) {
57 print $tmpproduct->getNomUrl(1);
58 if ($tmpbom->id) {
59 print ' ' . $langs->trans("or") . ' ';
60 print $tmpbom->getNomUrl(1);
61 print ' <a class="collapse_bom" id="collapse-' . $line->id . '" href="#">';
62 print(!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT') ? img_picto('', 'folder') : img_picto('', 'folder-open'));
63 }
64 print '</a>';
65} else {
66 print $this->tpl['label'];
67}
68print '</td>';
69// Qty
70print '<td class="right">'.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').'</td>';
71// Unit
72print '<td class="right">'.measuringUnitString($this->tpl['fk_unit'], '', '', 1).'</td>';
73// Stock
74print '<td class="center">';
75if ($tmpproduct->isStockManaged()) {
76 print(empty($this->tpl['stock']) ? 0 : price2num($this->tpl['stock'], 'MS'));
77 if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) {
78 print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte']));
79 }
80}
81print '</td>';
82print '<td class="center">';
83if ($tmpproduct->isStockManaged()) {
84 print((empty($this->tpl['virtual_stock']) ? 0 : price2num($this->tpl['virtual_stock'], 'MS')));
85 if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['virtual_stock'] < $this->tpl['seuil_stock_alerte'])) {
86 print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte']));
87 }
88}
89print '</td>';
90print '<td class="center">'.($this->tpl['qty_frozen'] ? yn($this->tpl['qty_frozen']) : '').'</td>';
91print '<td class="center">'.($this->tpl['disable_stock_change'] ? yn($this->tpl['disable_stock_change']) : '').'</td>';
92//print '<td class="right">'.$this->tpl['efficiency'].'</td>';
93
94$selected = 1;
95if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) {
96 $selected = 0;
97}
98
99if ($tmpbom->id > 0) {
100 print '<td class="center">';
101 print '<input type="checkbox" name="bomlineid[]" value="' . $line->id . '">';
102 print '</td>';
103} else {
104 print '<td class="center"></td>';
105}
106
107//print '<td class="center">';
108//print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
109//print '</td>';
110
111print '</tr>'."\n";
112
113// Select of all the sub-BOM lines
114$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
115$sql .= ' WHERE fk_bom ='. (int) $tmpbom->id;
116$resql = $db->query($sql);
117
118if ($resql) {
119 // Loop on all the sub-BOM lines if they exist
120 while ($obj = $db->fetch_object($resql)) {
121 $sub_bom_product = new Product($db);
122 $sub_bom_product->fetch($obj->fk_product);
123 $sub_bom_product->load_stock();
124
125 $sub_bom = new BOM($db);
126 $sub_bom->fetch($obj->fk_bom_child);
127
128 $sub_bom_line = new BOMLine($db);
129 $sub_bom_line->fetch($obj->rowid);
130
131 //If hidden conf is set, we show directly all the sub-BOM lines
132 if (!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT')) {
133 print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
134 } else {
135 print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
136 }
137
138 // Product OR BOM
139 print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
140 if (!empty($obj->fk_bom_child)) {
141 print $sub_bom_product->getNomUrl(1);
142 print ' '.$langs->trans('or').' ';
143 print $sub_bom->getNomUrl(1);
144 } else {
145 print $sub_bom_product->getNomUrl(1);
146 print '</td>';
147 }
148
149 // Qty
150 if ($sub_bom_line->qty_frozen > 0) {
151 print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
152 } else {
153 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>';
154 }
155
156 // Unit
157 print '<td class="linecolunit nowrap right" id="sub_bom_unit_'.$sub_bom_line->id.'">'.measuringUnitString($sub_bom_line->fk_unit, '', '', 1).'</td>';
158
159 // Stock réel
160 if ($sub_bom_product->stock_reel > 0) {
161 print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">'.$sub_bom_product->stock_reel.'</td>';
162 } else {
163 print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">&nbsp;</td>';
164 }
165
166 // Stock virtuel
167 if ($sub_bom_product->stock_theorique > 0) {
168 print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">'.$sub_bom_product->stock_theorique.'</td>';
169 } else {
170 print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">&nbsp;</td>';
171 }
172
173 // Frozen qty
174 if ($sub_bom_line->qty_frozen > 0) {
175 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">'.$langs->trans('Yes').'</td>';
176 } else {
177 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">&nbsp;</td>';
178 }
179
180 // Disable stock change
181 if ($sub_bom_line->disable_stock_change > 0) {
182 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.yn($sub_bom_line->disable_stock_change).'</td>';
183 } else {
184 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
185 }
186
187 print '<td></td>';
188 print '<td></td>';
189 }
190}
191
192?>
193<!-- END PHP TEMPLATE originproductline.tpl.php -->
Class for BOM.
Definition bom.class.php:45
Class for BOMLine.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
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 '.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.