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