dolibarr 19.0.3
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 *
23 * Need to have following variables defined:
24 * $object (invoice, order, ...)
25 * $conf
26 * $langs
27 * $forceall (0 by default, 1 for supplier invoices/orders)
28 * $element (used to test $user->rights->$element->creer)
29 * $permtoedit (used to replace test $user->rights->$element->creer)
30 * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
31 * $object_rights->creer initialized from = $object->getRights()
32 * $disableedit, $disablemove, $disableremove
33 *
34 * $type, $text, $description, $line
35 */
36
39require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
40
41// Protection to avoid direct call of template
42if (empty($object) || !is_object($object)) {
43 print "Error, template page can't be called as URL";
44 exit;
45}
46
47global $filtertype;
48if (empty($filtertype)) {
49 $filtertype = 0;
50}
51
52
53global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
54
55if (empty($dateSelector)) {
56 $dateSelector = 0;
57}
58if (empty($forceall)) {
59 $forceall = 0;
60}
61if (empty($senderissupplier)) {
62 $senderissupplier = 0;
63}
64if (empty($inputalsopricewithtax)) {
65 $inputalsopricewithtax = 0;
66}
67if (empty($outputalsopricetotalwithtax)) {
68 $outputalsopricetotalwithtax = 0;
69}
70
71// add html5 elements
72if ($filtertype == 1) {
73 $domData = ' data-element="'.$line->element.'service"';
74} else {
75 $domData = ' data-element="'.$line->element.'"';
76}
77
78$domData .= ' data-id="'.$line->id.'"';
79$domData .= ' data-qty="'.$line->qty.'"';
80$domData .= ' data-product_type="'.$line->product_type.'"';
81
82// Lines for extrafield
83$objectline = new BOMLine($object->db);
84
85$coldisplay = 0;
86print "<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
87print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
88
89// Line nb
90if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
91 print '<td class="linecolnum center">'.($i + 1).'</td>';
92 $coldisplay++;
93}
94
95// Product
96print '<td class="linecoldescription minwidth300imp">';
97print '<div id="line_'.$line->id.'"></div>';
98$coldisplay++;
99$tmpproduct = new Product($object->db);
100$tmpproduct->fetch($line->fk_product);
101$tmpbom = new BOM($object->db);
102$res = $tmpbom->fetch($line->fk_bom_child);
103if ($tmpbom->id > 0) {
104 print $tmpproduct->getNomUrl(1);
105 print ' '.$langs->trans("or").' ';
106 print $tmpbom->getNomUrl(1);
107 print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
108 print(!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT') ? img_picto('', 'folder') : img_picto('', 'folder-open'));
109 print '</a>';
110} else {
111 print $tmpproduct->getNomUrl(1);
112 print ' - '.$tmpproduct->label;
113}
114
115// Line extrafield
116if (!empty($extrafields)) {
117 $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
118 if (!empty($temps)) {
119 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
120 print $temps;
121 print '</div>';
122 }
123}
124
125print '</td>';
126
127// Qty
128print '<td class="linecolqty nowrap right">';
129$coldisplay++;
130echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
131print '</td>';
132
133if ($filtertype != 1) {
134 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
135 print '<td class="linecoluseunit nowrap left">';
136 $label = measuringUnitString($line->fk_unit, '', '', 1);
137 if ($label !== '') {
138 print $langs->trans($label);
139 }
140 print '</td>';
141 }
142
143 print '<td class="linecolqtyfrozen nowrap right">';
144 $coldisplay++;
145 echo $line->qty_frozen ? yn($line->qty_frozen) : '';
146 print '</td>';
147 print '<td class="linecoldisablestockchange nowrap right">';
148 $coldisplay++;
149 echo $line->disable_stock_change ? yn($line->disable_stock_change) : ''; // Yes, it is a quantity, not a price, but we just want the formating role of function price
150 print '</td>';
151
152 print '<td class="linecolefficiency nowrap right">';
153 $coldisplay++;
154 echo $line->efficiency;
155 print '</td>';
156} else {
157 // Unit
158 print '<td class="linecolunit nowrap right">';
159 $coldisplay++;
160
161 if (!empty($line->fk_unit)) {
162 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
163 $unit = new CUnits($this->db);
164 $unit->fetch($line->fk_unit);
165 print(isset($unit->label) ? "&nbsp;".$langs->trans(ucwords($unit->label))."&nbsp;" : '');
166 }
167
168 print '</td>';
169
170 // Work station
171 if (isModEnabled('workstation')) {
172 $workstation = new Workstation($object->db);
173 $res = $workstation->fetch($line->fk_default_workstation);
174
175 print '<td class="linecolworkstation nowrap right">';
176 $coldisplay++;
177 if ($res > 0) {
178 echo $workstation->getNomUrl(1);
179 }
180 print '</td>';
181 }
182}
183
184// Cost
185$total_cost = 0;
186$tmpbom->calculateCosts();
187print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
188$coldisplay++;
189if (!empty($line->fk_bom_child)) {
190 echo '<span class="amount">'.price($tmpbom->total_cost * $line->qty).'</span>';
191} else {
192 echo '<span class="amount">'.price($line->total_cost).'</span>';
193}
194print '</td>';
195
196if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') {
197 print '<td class="linecoledit center">';
198 $coldisplay++;
199 if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
200 } else {
201 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
202 }
203 print '</td>';
204
205 print '<td class="linecoldelete center">';
206 $coldisplay++;
207 if (($line->fk_prev_id == null) && empty($disableremove)) {
208 //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
209 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
210 print img_delete();
211 print '</a>';
212 }
213 print '</td>';
214
215 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
216 print '<td class="linecolmove tdlineupdown center">';
217 $coldisplay++;
218 if ($i > 0) {
219 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&token='.newToken().'&rowid='.$line->id.'">';
220 echo img_up('default', 0, 'imgupforline');
221 print '</a>';
222 }
223 if ($i < $num - 1) {
224 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&token='.newToken().'&rowid='.$line->id.'">';
225 echo img_down('default', 0, 'imgdownforline');
226 print '</a>';
227 }
228 print '</td>';
229 } else {
230 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
231 $coldisplay++;
232 }
233} else {
234 print '<td colspan="3"></td>';
235 $coldisplay = $coldisplay + 3;
236}
237
238if ($action == 'selectlines') {
239 print '<td class="linecolcheck center">';
240 print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
241 print '</td>';
242}
243
244print '</tr>';
245
246// Select of all the sub-BOM lines
247// From this pont to the end of the file, we only take care of sub-BOM lines
248$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
249$sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
250$resql = $object->db->query($sql);
251
252if ($resql) {
253 // Loop on all the sub-BOM lines if they exist
254 while ($obj = $object->db->fetch_object($resql)) {
255 $sub_bom_product = new Product($object->db);
256 $sub_bom_product->fetch($obj->fk_product);
257
258 $sub_bom = new BOM($object->db);
259 if (!empty($obj->fk_bom_child)) {
260 $sub_bom->fetch($obj->fk_bom_child);
261 }
262
263 $sub_bom_line = new BOMLine($object->db);
264 $sub_bom_line->fetch($obj->rowid);
265
266 //If hidden conf is set, we show directly all the sub-BOM lines
267 if (!getDolGlobalString('BOM_SHOW_ALL_BOM_BY_DEFAULT')) {
268 print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
269 } else {
270 print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
271 }
272
273 // Product OR BOM
274 print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
275 if (!empty($obj->fk_bom_child)) {
276 print $sub_bom_product->getNomUrl(1);
277 print ' '.$langs->trans('or').' ';
278 print $sub_bom->getNomUrl(1);
279 } else {
280 print $sub_bom_product->getNomUrl(1);
281 print '</td>';
282 }
283
284 // Qty
285 $label = $sub_bom_product->getLabelOfUnit('long');
286 if ($sub_bom_line->qty_frozen > 0) {
287 print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
288 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
289 print '<td class="linecoluseunit nowrap left">';
290 if ($label !== '') {
291 print $langs->trans($label);
292 }
293 print '</td>';
294 }
295 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$langs->trans('Yes').'</td>';
296 } else {
297 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>';
298 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
299 print '<td class="linecoluseunit nowrap left">';
300 if ($label !== '') {
301 print $langs->trans($label);
302 }
303 print '</td>';
304 }
305
306 print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
307 }
308
309 // Disable stock change
310 if ($sub_bom_line->disable_stock_change > 0) {
311 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
312 } else {
313 print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
314 }
315
316 // Efficiency
317 print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
318
319 // Cost
320 if (!empty($sub_bom->id)) {
321 $sub_bom->calculateCosts();
322 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 * $line->qty, 'MT')).'</span></td>';
323 $total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty;
324 } elseif ($sub_bom_product->type == Product::TYPE_SERVICE && isModEnabled('workstation') && !empty($sub_bom_product->fk_default_workstation)) {
325 //Convert qty to hour
326 $unit = measuringUnitString($sub_bom_line->fk_unit, '', '', 1);
327 $qty = convertDurationtoHour($sub_bom_line->qty, $unit);
328 $workstation = new Workstation($this->db);
329 $res = $workstation->fetch($sub_bom_product->fk_default_workstation);
330 if ($res > 0) {
331 $sub_bom_line->total_cost = price2num($qty * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated), 'MT');
332 }
333
334 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>';
335 $this->total_cost += $line->total_cost;
336 } elseif ($sub_bom_product->cost_price > 0) {
337 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
338 print '<span class="amount">'.price(price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
339 $total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty;
340 } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
341 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">';
342 print '<span class="amount">'.price(price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
343 $total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
344 } else { // Minimum purchase price if cost price and PMP aren't defined
345 $sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
346 $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
347 $resql_supplier_price = $object->db->query($sql_supplier_price);
348 if ($resql_supplier_price) {
349 $obj = $object->db->fetch_object($resql_supplier_price);
350 if (!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) {
351 $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty;
352 } else {
353 $line_cost = $obj->min_price;
354 }
355 print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($line_cost, 'MT').'</span></td>';
356 $total_cost+= $line_cost;
357 }
358 }
359
360 print '<td></td>';
361 print '<td></td>';
362 print '<td></td>';
363 }
364}
365
366
367print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
Class for BOM.
Definition bom.class.php:43
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.
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
Definition date.lib.php:335
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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 '.
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.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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.