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