dolibarr  17.0.4
objectline_create.tpl.php
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2010-2014 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) 2014 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8  * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
10  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  *
25  * Need to have following variables defined:
26  * $object (invoice, order, ...)
27  * $conf
28  * $langs
29  * $forceall (0 by default, 1 for supplier invoices/orders)
30  */
31 
32 require_once DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php";
33 
34 // Protection to avoid direct call of template
35 if (empty($object) || !is_object($object)) {
36  print "Error: this template page cannot be called directly as an URL";
37  exit;
38 }
39 
40 
41 global $forceall, $forcetoshowtitlelines, $filtertype;
42 
43 if (empty($forceall)) {
44  $forceall = 0;
45 }
46 
47 if (empty($filtertype)) $filtertype = 0;
48 if (!empty($object->element) && $object->element == 'contrat' && empty($conf->global->STOCK_SUPPORT_SERVICES)) {
49  $filtertype = -1;
50 }
51 
52 $formproduct = new FormProduct($object->db);
53 
54 // Define colspan for the button 'Add'
55 $colspan = 3; // Columns: total ht + col edit + col delete
56 //print $object->element;
57 
58 // Lines for extrafield
59 $objectline = new BOMLine($this->db);
60 
61 print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
62 
63 $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
64 
65 if ($nolinesbefore) {
66  print '<tr class="liste_titre nodrag nodrop">';
67  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
68  print '<td class="linecolnum center"></td>';
69  }
70  print '<td class="linecoldescription minwidth500imp">';
71  print '<div id="add"></div><span class="hideonsmartphone">'.$langs->trans('AddNewLine').'</span>';
72  print '</td>';
73  print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
74 
75  if ($filtertype != 1) {
76  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
77  print '<td class="linecoluseunit left">';
78  print '<span id="title_units">';
79  print $langs->trans('Unit');
80  print '</span></td>';
81  }
82  print '<td class="linecolqtyfrozen right">' . $form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")) . '</td>';
83  print '<td class="linecoldisablestockchange right">' . $form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')) . '</td>';
84  print '<td class="linecollost right">' . $form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')) . '</td>';
85  } else {
86  print '<td class="linecolunit right">' . $form->textwithpicto($langs->trans('Unit'), '').'</td>';
87  if (isModEnabled('workstation')) print '<td class="linecolworkstation right">' . $form->textwithpicto($langs->trans('Workstation'), '') . '</td>';
88  print '<td class="linecoltotalcost right">' . $form->textwithpicto($langs->trans('TotalCost'), '') . '</td>';
89  }
90 
91  print '<td class="linecoledit" colspan="' . $colspan . '">&nbsp;</td>';
92  print '</tr>';
93 }
94 print '<tr class="pair nodrag nodrop nohoverpair'.(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create').'">';
95 $coldisplay = 0;
96 
97 // Adds a line numbering column
98 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
99  $coldisplay++;
100  echo '<td class="bordertop nobottom linecolnum center"></td>';
101 }
102 
103 $coldisplay++;
104 print '<td class="bordertop nobottom linecoldescription minwidth500imp">';
105 
106 // Predefined product/service
107 if (isModEnabled("product") || isModEnabled("service")) {
108  if ($filtertype == 1) {
109  print $langs->trans("Service");
110  } else {
111  print $langs->trans("Product");
112  }
113  echo '<span class="prod_entry_mode_predef">';
114  $statustoshow = -1;
115  if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
116  // hide products in closed warehouse, but show products for internal transfer
117  $form->select_produits(GETPOST('idprod', 'int'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, 'warehouseopen,warehouseinternal', GETPOST('combinations', 'array'));
118  } else {
119  $form->select_produits(GETPOST('idprod', 'int'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOST('combinations', 'array'));
120  }
121 
122  echo '</span>';
123 }
124 if (!empty($conf->global->BOM_SUB_BOM) && $filtertype!=1) {
125  print '<br><span class="opacitymedium">'.$langs->trans("or").'</span><br>'.$langs->trans("BOM");
126  // TODO Add component to select a BOM
127  $form->select_bom();
128 }
129 
130 if (is_object($objectline)) {
131  $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
132 
133  if (!empty($temps)) {
134  print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
135  print $temps;
136  print '</div>';
137  }
138 }
139 
140 print '</td>';
141 
142 
143 $coldisplay++;
144 print '<td class="bordertop nobottom linecolqty right"><input type="text" size="2" name="qty" id="qty" class="flat right" value="'.(GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : 1).'">';
145 print '</td>';
146 
147 if ($filtertype != 1) {
148  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
149  $coldisplay++;
150  print '<td class="nobottom linecoluseunit left">';
151  print '</td>';
152  }
153 
154  $coldisplay++;
155  print '<td class="bordertop nobottom linecolqtyfrozen right"><input type="checkbox" name="qty_frozen" id="qty_frozen" class="flat right" value="1"' . (GETPOST("qty_frozen", 'alpha') ? ' checked="checked"' : '') . '>';
156  print '</td>';
157 
158 
159  $coldisplay++;
160  print '<td class="bordertop nobottom linecoldisablestockchange right"><input type="checkbox" name="disable_stock_change" id="disable_stock_change" class="flat right" value="1"' . (GETPOST("disable_stock_change", 'alpha') ? ' checked="checked"' : '') . '">';
161  print '</td>';
162 
163  $coldisplay++;
164  print '<td class="bordertop nobottom nowrap linecollost right">';
165  print '<input type="text" size="2" name="efficiency" id="efficiency" class="flat right" value="' . ((GETPOSTISSET("efficiency") && $action == 'addline') ? GETPOST("efficiency", 'alpha') : 1) . '">';
166  print '</td>';
167 
168  $coldisplay++;
169  print '<td class="bordertop nobottom nowrap linecolcost right">';
170  print '&nbsp;';
171  print '</td>';
172 } else {
173  $coldisplay++;
174  require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
175  $cUnit = new CUnits($this->db);
176  $fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label', 'time');
177  print '<td class="bordertop nobottom nowrap linecolunit right">';
178  print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 0, 0);
179  print '</td>';
180 
181  $coldisplay++;
182  print '<td class="bordertop nobottom nowrap linecolworkstation right">';
183  print '&nbsp;';
184  print '</td>';
185 
186  $coldisplay++;
187  print '<td class="bordertop nobottom nowrap linecolcost right">';
188  print '&nbsp;';
189  print '</td>';
190 }
191 
192  $coldisplay += $colspan;
193  print '<td class="bordertop nobottom linecoledit center valignmiddle" colspan="' . $colspan . '">';
194  print '<input type="submit" class="button button-add" name="addline" id="addline" value="' . $langs->trans('Add') . '">';
195  print '</td>';
196  print '</tr>';
197 
198 ?>
199 
200 <script>
201 
202 /* JQuery for product free or predefined select */
203 jQuery(document).ready(function() {
204  /* When changing predefined product, we reload list of supplier prices required for margin combo */
205  $("#idprod").change(function()
206  {
207  console.log("#idprod change triggered");
208 
209  /* To set focus */
210  if (jQuery('#idprod').val() > 0)
211  {
212  /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
213  jQuery('#dp_desc').focus();
214  /* focus if CKEDITOR */
215  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
216  {
217  var editor = CKEDITOR.instances['dp_desc'];
218  if (editor) { editor.focus(); }
219  }
220  }
221  });
222 
223  //change unit selected if we change service selected
224  <?php if ($filtertype == 1) { ?>
225  $('#idprodservice').change(function(){
226  var idproduct = $(this).val();
227 
228  $.ajax({
229  url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
230  ,type: 'POST'
231  ,data: {
232  'action': 'getDurationUnitByProduct'
233  ,'idproduct' : idproduct
234  }
235  }).done(function(data) {
236 
237  console.log(data);
238  var data = JSON.parse(data);
239  $("#fk_unit").val(data).change();
240  });
241  });
242  <?php } ?>
243 });
244 
245 </script>
246 
247 <!-- END PHP TEMPLATE objectline_create.tpl.php -->
Class for BOMLine.
Definition: bom.class.php:1545
Class of dictionary type of thirdparty (used by imports)
Class with static methods for building HTML components related to products Only components common to ...
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db
API class for accounts.
Definition: inc.php:41