dolibarr  20.0.0-beta
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 '@phan-var-force CommonObject $this
41  @phan-var-force CommonObject $object';
42 
43 global $forceall, $forcetoshowtitlelines, $filtertype;
44 
45 if (empty($forceall)) {
46  $forceall = 0;
47 }
48 
49 if (empty($filtertype)) {
50  $filtertype = 0;
51 }
52 if (!empty($object->element) && $object->element == 'contrat' && !getDolGlobalString('STOCK_SUPPORT_SERVICES')) {
53  $filtertype = -1;
54 }
55 
56 $formproduct = new FormProduct($object->db);
57 
58 // Define colspan for the button 'Add'
59 $colspan = 3; // Columns: total ht + col edit + col delete
60 //print $object->element;
61 
62 // Lines for extrafield
63 $objectline = new BOMLine($this->db);
64 
65 print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
66 
67 $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
68 
69 if ($nolinesbefore) {
70  print '<tr class="liste_titre nodrag nodrop">';
71  if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
72  print '<td class="linecolnum center"></td>';
73  }
74  print '<td class="linecoldescription minwidth500imp">';
75  print '<div id="add"></div><span class="hideonsmartphone">'.$langs->trans('AddNewLine').'</span>';
76  print '</td>';
77  print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
78 
79  if ($filtertype != 1) {
80  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
81  print '<td class="linecoluseunit left">';
82  print '<span id="title_units">';
83  print $langs->trans('Unit');
84  print '</span></td>';
85  }
86  print '<td class="linecolqtyfrozen right">' . $form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")) . '</td>';
87  print '<td class="linecoldisablestockchange right">' . $form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')) . '</td>';
88  print '<td class="linecollost right">' . $form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')) . '</td>';
89  } else {
90  print '<td class="linecolunit right">' . $form->textwithpicto($langs->trans('Unit'), '').'</td>';
91  if (isModEnabled('workstation')) {
92  print '<td class="linecolworkstation right">' . $form->textwithpicto($langs->trans('Workstation'), '') . '</td>';
93  }
94  print '<td class="linecoltotalcost right">' . $form->textwithpicto($langs->trans('TotalCost'), '') . '</td>';
95  }
96 
97  print '<td class="linecoledit" colspan="' . $colspan . '">&nbsp;</td>';
98  print '</tr>';
99 }
100 print '<tr class="pair nodrag nodrop nohoverpair'.(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create').'">';
101 $coldisplay = 0;
102 
103 // Adds a line numbering column
104 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
105  $coldisplay++;
106  echo '<td class="bordertop nobottom linecolnum center"></td>';
107 }
108 
109 $coldisplay++;
110 print '<td class="bordertop nobottom linecoldescription minwidth500imp">';
111 
112 // Predefined product/service
113 if (isModEnabled("product") || isModEnabled("service")) {
114  if ($filtertype == 1) {
115  print $langs->trans("Service");
116  } else {
117  print $langs->trans("Product");
118  }
119  echo '<span class="prod_entry_mode_predef">';
120  $statustoshow = -1;
121  if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
122  // hide products in closed warehouse, but show products for internal transfer
123  print $form->select_produits(GETPOSTINT('idprod'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, 'warehouseopen,warehouseinternal', GETPOSTINT('combinations'), 1);
124  } else {
125  print $form->select_produits(GETPOSTINT('idprod'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOSTINT('combinations'), 1);
126  }
127  $urltocreateproduct = DOL_URL_ROOT.'/product/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
128  print '<a href="'.$urltocreateproduct.'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProduct").'"></span></a>';
129 
130  echo '</span>';
131 }
132 if (getDolGlobalString('BOM_SUB_BOM') && $filtertype != 1) {
133  print '<br><span class="opacitymedium">'.$langs->trans("or").'</span><br>'.$langs->trans("BOM");
134  print $form->select_bom('', 'bom_id', 0, 1, 0, '1', '', 1);
135 }
136 
137 if (is_object($objectline)) {
138  $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
139 
140  if (!empty($temps)) {
141  print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
142  print $temps;
143  print '</div>';
144  }
145 }
146 
147 print '</td>';
148 
149 
150 $coldisplay++;
151 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).'">';
152 print '</td>';
153 
154 if ($filtertype != 1) {
155  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
156  $coldisplay++;
157  print '<td class="nobottom linecoluseunit left">';
158  print '</td>';
159  }
160 
161  $coldisplay++;
162  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"' : '') . '>';
163  print '</td>';
164 
165 
166  $coldisplay++;
167  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"' : '') . '">';
168  print '</td>';
169 
170  $coldisplay++;
171  print '<td class="bordertop nobottom nowrap linecollost right">';
172  print '<input type="text" size="2" name="efficiency" id="efficiency" class="flat right" value="' . ((GETPOSTISSET("efficiency") && $action == 'addline') ? GETPOST("efficiency", 'alpha') : 1) . '">';
173  print '</td>';
174 
175  $coldisplay++;
176  print '<td class="bordertop nobottom nowrap linecolcost right">';
177  print '&nbsp;';
178  print '</td>';
179 } else {
180  $coldisplay++;
181  require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
182  $cUnit = new CUnits($this->db);
183  $fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label', 'time');
184  print '<td class="bordertop nobottom nowrap linecolunit right">';
185  print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 0, 0);
186  print '</td>';
187 
188  $coldisplay++;
189  print '<td class="bordertop nobottom nowrap linecolworkstation right">';
190  print $formproduct->selectWorkstations('', 'idworkstations', 1);
191  print '</td>';
192 
193  $coldisplay++;
194  print '<td class="bordertop nobottom nowrap linecolcost right">';
195  print '&nbsp;';
196  print '</td>';
197 }
198 
199 $coldisplay += $colspan;
200 print '<td class="bordertop nobottom linecoledit right valignmiddle" colspan="' . $colspan . '">';
201 print '<input type="submit" class="button button-add small" name="addline" id="addline" value="' . $langs->trans('Add') . '">';
202 print '</td>';
203 print '</tr>';
204 
205 ?>
206 
207 <script>
208 
209 /* JQuery for product free or predefined select */
210 jQuery(document).ready(function() {
211  /* When changing predefined product, we reload list of supplier prices required for margin combo */
212  $("#idprod").change(function()
213  {
214  console.log("#idprod change triggered");
215 
216  /* To set focus */
217  if (jQuery('#idprod').val() > 0)
218  {
219  /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
220  jQuery('#dp_desc').focus();
221  /* focus if CKEDITOR */
222  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
223  {
224  var editor = CKEDITOR.instances['dp_desc'];
225  if (editor) { editor.focus(); }
226  }
227  }
228  });
229 
230  //change unit selected if we change service selected
231  <?php if ($filtertype == 1) { ?>
232  $('#idprodservice').change(function(){
233  var idproduct = $(this).val();
234 
235  $.ajax({
236  url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
237  ,type: 'POST'
238  ,data: {
239  'action': 'getDurationUnitByProduct'
240  ,'token' : "<?php echo newToken() ?>"
241  ,'idproduct' : idproduct
242  }
243  }).done(function(data) {
244 
245  console.log(data);
246  $("#fk_unit").val(data).change();
247  });
248 
249  $.ajax({
250  url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
251  ,type: 'POST'
252  ,data: {
253  'action': 'getWorkstationByProduct'
254  ,'token' : "<?php echo newToken() ?>"
255  ,'idproduct' : idproduct
256  }
257  }).done(function(data) {
258  $('#idworkstations').val(data.defaultWk).select2();
259  });
260  });
261  <?php } ?>
262 });
263 
264 </script>
265 
266 <!-- END PHP TEMPLATE objectline_create.tpl.php -->
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class for BOMLine.
Definition: bom.class.php:1662
Class of dictionary type of thirdparty (used by imports)
Class with static methods for building HTML components related to products Only components common to ...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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:123