dolibarr  x.y.z
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 
37 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
38 
39 // Protection to avoid direct call of template
40 if (empty($object) || !is_object($object)) {
41  print "Error, template page can't be called as URL";
42  exit;
43 }
44 
45 global $filtertype;
46 if (empty($filtertype)) $filtertype = 0;
47 
48 
49 global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
50 
51 if (empty($dateSelector)) {
52  $dateSelector = 0;
53 }
54 if (empty($forceall)) {
55  $forceall = 0;
56 }
57 if (empty($senderissupplier)) {
58  $senderissupplier = 0;
59 }
60 if (empty($inputalsopricewithtax)) {
61  $inputalsopricewithtax = 0;
62 }
63 if (empty($outputalsopricetotalwithtax)) {
64  $outputalsopricetotalwithtax = 0;
65 }
66 
67 // add html5 elements
68 if ($filtertype == 1) $domData = ' data-element="'.$line->element.'service"';
69 else $domData = ' data-element="'.$line->element.'"';
70 
71 $domData .= ' data-id="'.$line->id.'"';
72 $domData .= ' data-qty="'.$line->qty.'"';
73 $domData .= ' data-product_type="'.$line->product_type.'"';
74 
75 // Lines for extrafield
76 $objectline = new BOMLine($object->db);
77 
78 $coldisplay = 0;
79 print "<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
80 print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
81 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
82  print '<td class="linecolnum center">'.($i + 1).'</td>';
83  $coldisplay++;
84 }
85 print '<td class="linecoldescription minwidth300imp">';
86 print '<div id="line_'.$line->id.'"></div>';
87 $coldisplay++;
88 $tmpproduct = new Product($object->db);
89 $tmpproduct->fetch($line->fk_product);
90 $tmpbom = new BOM($object->db);
91 $res = $tmpbom->fetch($line->fk_bom_child);
92 if ($tmpbom->id > 0) {
93  print $tmpproduct->getNomUrl(1);
94  print ' '.$langs->trans("or").' ';
95  print $tmpbom->getNomUrl(1);
96  print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
97  print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? img_picto('', 'folder') : img_picto('', 'folder-open'));
98  print '</a>';
99 } else {
100  print $tmpproduct->getNomUrl(1);
101  print ' - '.$tmpproduct->label;
102 }
103 
104 // Line extrafield
105 if (!empty($extrafields)) {
106  $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
107  if (!empty($temps)) {
108  print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
109  print $temps;
110  print '</div>';
111  }
112 }
113 
114 print '</td>';
115 
116 print '<td class="linecolqty nowrap right">';
117 $coldisplay++;
118 echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
119 print '</td>';
120 
121 if ($filtertype != 1) {
122  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
123  print '<td class="linecoluseunit nowrap left">';
124  $label = $tmpproduct->getLabelOfUnit('long');
125  if ($label !== '') {
126  print $langs->trans($label);
127  }
128  print '</td>';
129  }
130 
131  print '<td class="linecolqtyfrozen nowrap right">';
132  $coldisplay++;
133  echo $line->qty_frozen ? yn($line->qty_frozen) : '';
134  print '</td>';
135  print '<td class="linecoldisablestockchange nowrap right">';
136  $coldisplay++;
137  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
138  print '</td>';
139 
140  print '<td class="linecolefficiency nowrap right">';
141  $coldisplay++;
142  echo $line->efficiency;
143  print '</td>';
144 } else {
145  //Unité
146  print '<td class="linecolunit nowrap right">';
147  $coldisplay++;
148 
149  if (!empty($line->fk_unit)) {
150  require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
151  $unit = new CUnits($this->db);
152  $unit->fetch($line->fk_unit);
153  print (isset($unit->label) ? "&nbsp;".$langs->trans(ucwords($unit->label))."&nbsp;" : '');
154  }
155 
156  print '</td>';
157 
158  // Work station
159  if (isModEnabled('workstation')) {
160  $workstation = new Workstation($object->db);
161  $res = $workstation->fetch($tmpproduct->fk_default_workstation);
162 
163  print '<td class="linecolunit nowrap right">';
164  $coldisplay++;
165  if ($res > 0) echo $workstation->getNomUrl();
166  print '</td>';
167  }
168 }
169 $total_cost = 0;
170 print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
171 $coldisplay++;
172 echo '<span class="amount">'.price($line->total_cost).'</span>';
173 print '</td>';
174 
175 if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') {
176  print '<td class="linecoledit center">';
177  $coldisplay++;
178  if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
179  } else {
180  print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
181  }
182  print '</td>';
183 
184  print '<td class="linecoldelete center">';
185  $coldisplay++;
186  if (($line->fk_prev_id == null) && empty($disableremove)) {
187  //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
188  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
189  print img_delete();
190  print '</a>';
191  }
192  print '</td>';
193 
194  if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
195  print '<td class="linecolmove tdlineupdown center">';
196  $coldisplay++;
197  if ($i > 0) {
198  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&token='.newToken().'&rowid='.$line->id.'">';
199  echo img_up('default', 0, 'imgupforline');
200  print '</a>';
201  }
202  if ($i < $num - 1) {
203  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&token='.newToken().'&rowid='.$line->id.'">';
204  echo img_down('default', 0, 'imgdownforline');
205  print '</a>';
206  }
207  print '</td>';
208  } else {
209  print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
210  $coldisplay++;
211  }
212 } else {
213  print '<td colspan="3"></td>';
214  $coldisplay = $coldisplay + 3;
215 }
216 
217 if ($action == 'selectlines') {
218  print '<td class="linecolcheck center">';
219  print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
220  print '</td>';
221 }
222 
223 print '</tr>';
224 
225 // Select of all the sub-BOM lines
226 // From this pont to the end of the file, we only take care of sub-BOM lines
227 $sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
228 $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
229 $resql = $object->db->query($sql);
230 
231 if ($resql) {
232  // Loop on all the sub-BOM lines if they exist
233  while ($obj = $object->db->fetch_object($resql)) {
234  $sub_bom_product = new Product($object->db);
235  $sub_bom_product->fetch($obj->fk_product);
236 
237  $sub_bom = new BOM($object->db);
238  if (!empty($obj->fk_bom_child)) {
239  $sub_bom->fetch($obj->fk_bom_child);
240  }
241 
242  $sub_bom_line = new BOMLine($object->db);
243  $sub_bom_line->fetch($obj->rowid);
244 
245  //If hidden conf is set, we show directly all the sub-BOM lines
246  if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
247  print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
248  } else {
249  print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
250  }
251 
252  // Product OR BOM
253  print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
254  if (!empty($obj->fk_bom_child)) {
255  print $sub_bom_product->getNomUrl(1);
256  print ' '.$langs->trans('or').' ';
257  print $sub_bom->getNomUrl(1);
258  } else {
259  print $sub_bom_product->getNomUrl(1);
260  print '</td>';
261  }
262 
263  // Qty
264  if ($sub_bom_line->qty_frozen > 0) {
265  print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
266  print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$langs->trans('Yes').'</td>';
267  } else {
268  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>';
269  print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
270  }
271 
272  // Disable stock change
273  if ($sub_bom_line->disable_stock_change > 0) {
274  print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
275  } else {
276  print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
277  }
278 
279  // Efficiency
280  print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
281 
282  // Cost
283  if (!empty($sub_bom->id)) {
284  $sub_bom->calculateCosts();
285  print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom->total_cost * $sub_bom_line->qty * $line->qty).'</span></td>';
286  $total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty;
287  } elseif ($sub_bom_product->cost_price > 0) {
288  print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty).'</span></td>';
289  $total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty;
290  } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
291  print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty).'</span></td>';
292  $total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
293  } else { // Minimum purchase price if cost price and PMP aren't defined
294  $sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
295  $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
296  $resql_supplier_price = $object->db->query($sql_supplier_price);
297  if ($resql_supplier_price) {
298  $obj = $object->db->fetch_object($resql_supplier_price);
299  $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty;
300 
301  print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($line_cost).'</span></td>';
302  $total_cost+= $line_cost;
303  }
304  }
305 
306  print '<td></td>';
307  print '<td></td>';
308  print '<td></td>';
309  }
310 }
311 
312 // Replace of the total_cost value by the sum of all sub-BOM lines total_cost
313 // TODO Remove this bad practice. We should not replace content of ouput using javascript but value should be good during generation of output.
314 if ($total_cost > 0) {
315  $line->total_cost = price($total_cost);
316  ?>
317  <script>
318  $('#costline_<?php echo $line->id?>').html('<?php echo "<span class=\"amount\">".price($total_cost)."</span>"; ?>');
319  </script>
320  <?php
321 }
322 
323 print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";
Class for BOM.
Definition: bom.class.php:36
Class for BOMLine.
Definition: bom.class.php:1567
Class of dictionary type of thirdparty (used by imports)
Class to manage products or services.
Class for Workstation.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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 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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
$conf db
API class for accounts.
Definition: inc.php:41