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