dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Vincent Maury <vmaury@timgroup.fr>
12 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 *
27 * Need to have the following variables defined:
28 * $object (invoice, order, ...)
29 * $conf
30 * $langs
31 * $forceall (0 by default, 1 for supplier invoices/orders)
32 */
33
34require_once DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php";
35
36// Protection to avoid direct call of template
37if (empty($object) || !is_object($object)) {
38 print "Error: this template page cannot be called directly as an URL";
39 exit;
40}
41
42'
43@phan-var-force CommonObject $this
44@phan-var-force CommonObject $object
45@phan-var-force Societe $buyer
46';
47
48global $forceall, $forcetoshowtitlelines, $filtertype;
49
50if (empty($forceall)) {
51 $forceall = 0;
52}
53
54if (empty($filtertype)) {
55 $filtertype = 0;
56}
57if (!empty($object->element) && $object->element == 'contrat' && !getDolGlobalString('STOCK_SUPPORT_SERVICES')) {
58 $filtertype = -1;
59}
60
61$formproduct = new FormProduct($object->db);
62
63// Define colspan for the button 'Add'
64$colspan = 3; // Columns: total ht + col edit + col delete
65//print $object->element;
66
67// Lines for extrafield
68$objectline = new BOMLine($this->db);
69
70print "<!-- BEGIN PHP TEMPLATE bom/tpl/objectline_create.tpl.php -->\n";
71
72$nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
73
74if ($nolinesbefore) {
75 print '<tr class="liste_titre nodrag nodrop">';
76 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
77 print '<td class="linecolnum center"></td>';
78 }
79 print '<td class="linecoldescription minwidth500imp">';
80 print '<div id="add"></div><span class="hideonsmartphone">'.$langs->trans('AddNewLine').'</span>';
81 print '</td>';
82 print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
83
84 if ($filtertype != 1) { // Product
85 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
86 print '<td class="linecoluseunit left">';
87 print '<span id="title_units">';
88 print $langs->trans('Unit');
89 print '</span></td>';
90 }
91 } else { // Service
92 print '<td class="linecolunit left">' . $form->textwithpicto($langs->trans('Unit'), '').'</td>';
93 }
94 if ($filtertype != 1 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Product or stock support for Services is active
95 // Qty frozen
96 print '<td class="linecolqtyfrozen right">' . $form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")) . '</td>';
97
98 // Disable stock change
99 print '<td class="linecoldisablestockchange right">' . $form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')) . '</td>';
100
101 // Efficiency
102 print '<td class="linecollost right">' . $form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')) . '</td>';
103 }
104
105 // Service and workstations are active
106 if ($filtertype == 1 && isModEnabled('workstation')) {
107 print '<td class="linecolworkstation right">' . $form->textwithpicto($langs->trans('Workstation'), '') . '</td>';
108 }
109 // Cost
110 print '<td class="linecoltotalcost right">' . $form->textwithpicto($langs->trans('TotalCost'), '') . '</td>';
111
112 print '<td class="linecoledit" colspan="' . $colspan . '">&nbsp;</td>';
113 print '</tr>';
114}
115
116print '<tr class="pair nodrag nodrop nohoverpair'.(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create').'">';
117$coldisplay = 0;
118
119// Adds a line numbering column
120if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
121 $coldisplay++;
122 echo '<td class="bordertop nobottom linecolnum center"></td>';
123}
124
125$coldisplay++;
126print '<td class="bordertop nobottom linecoldescription bomline minwidth500imp">';
127
128// Predefined product/service
129if (isModEnabled("product") || isModEnabled("service")) {
130 if ($filtertype == 1) {
131 print $langs->trans("Service");
132 } else {
133 print $langs->trans("Product");
134 }
135
136 echo '<span class="prod_entry_mode_predef nowraponall">';
137
138 $statustoshow = -1;
139 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
140 // hide products in closed warehouse, but show products for internal transfer
141 print $form->select_produits(GETPOSTINT('idprod'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, getDolGlobalInt('PRODUIT_LIMIT_SIZE'), 0, $statustoshow, 2, '', 1, array(), 0, '1', 0, 'maxwidth500 widthcentpercentminusx', 0, 'warehouseopen,warehouseinternal', GETPOSTINT('combinations'), 1);
142 } else {
143 print $form->select_produits(GETPOSTINT('idprod'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, getDolGlobalInt('PRODUIT_LIMIT_SIZE'), 0, $statustoshow, 2, '', 1, array(), 0, '1', 0, 'maxwidth500 widthcentpercentminusx', 0, '', GETPOSTINT('combinations'), 1);
144 }
145 $urltocreateproduct = DOL_URL_ROOT.'/product/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
146 print '<a href="'.$urltocreateproduct.'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProduct").'"></span></a>';
147
148 echo '</span>';
149}
150if (getDolGlobalString('BOM_SUB_BOM') && $filtertype != 1) {
151 print '<br><span class="opacitymedium">'.$langs->trans("or").'</span><br>'.$langs->trans("BOM");
152 print $form->select_bom('', 'bom_id', 0, 1, 0, '1', '', 1);
153}
154
155if (is_object($objectline)) {
156 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
157
158 if (!empty($temps)) {
159 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
160 print $temps;
161 print '</div>';
162 }
163}
164
165print '</td>';
166
167
168$coldisplay++;
169print '<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).'">';
170print '</td>';
171
172if ($filtertype != 1) { // Product
173 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
174 $coldisplay++;
175 print '<td class="nobottom linecoluseunit">';
176 print '</td>';
177 }
178} else { // Service
179 $coldisplay++;
180 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
181 $cUnit = new CUnits($this->db);
182 $fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label', 'time');
183 print '<td class="bordertop nobottom nowrap linecolunit">';
184 print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 1);
185 print '</td>';
186}
187if ($filtertype != 1 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Product or stock support for Services is active
188 // Qty frozen
189 $coldisplay++;
190 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"' : '') . '>';
191 print '</td>';
192
193 // Disable stock change
194 $coldisplay++;
195 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"' : '') . '">';
196 print '</td>';
197
198 // Efficiency
199 $coldisplay++;
200 print '<td class="bordertop nobottom nowrap linecollost right">';
201 print '<input type="text" size="2" name="efficiency" id="efficiency" class="flat right" value="' . ((GETPOSTISSET("efficiency") && $action == 'addline') ? GETPOST("efficiency", 'alpha') : 1) . '">';
202 print '</td>';
203}
204// Service and workstations are active
205if ($filtertype == 1 && isModEnabled('workstation')) {
206 $coldisplay++;
207 print '<td class="bordertop nobottom nowrap linecolworkstation">';
208 print $formproduct->selectWorkstations('', 'idworkstations', 1);
209 print '</td>';
210}
211
212// Cost
213$coldisplay++;
214print '<td class="bordertop nobottom nowrap linecolcost right">';
215print '&nbsp;';
216print '</td>';
217
218
219$coldisplay += $colspan;
220print '<td class="bordertop nobottom linecoledit right valignmiddle" colspan="' . $colspan . '">';
221print '<input type="submit" class="button button-add small" name="addline" id="addline" value="' . $langs->trans('Add') . '">';
222print '</td>';
223print '</tr>';
224
225?>
226
227<script>
228
229/* JQuery for product free or predefined select */
230jQuery(document).ready(function() {
231 /* When changing predefined product, we reload list of supplier prices required for margin combo */
232 $("#idprod").change(function()
233 {
234 console.log("#idprod change triggered");
235
236 /* To set focus */
237 if (jQuery('#idprod').val() > 0)
238 {
239 /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
240 jQuery('#dp_desc').focus();
241 /* focus if CKEDITOR */
242 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
243 {
244 var editor = CKEDITOR.instances['dp_desc'];
245 if (editor) { editor.focus(); }
246 }
247 }
248 });
249
250 //change unit selected if we change service selected
251 <?php if ($filtertype == 1) { ?>
252 $('#idprodservice').change(function(){
253 var idproduct = $(this).val();
254
255 $.ajax({
256 url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
257 ,type: 'POST'
258 ,data: {
259 'action': 'getDurationUnitByProduct'
260 ,'token' : "<?php echo newToken() ?>"
261 ,'idproduct' : idproduct
262 }
263 }).done(function(data) {
264
265 console.log(data);
266 $("#fk_unit").val(data).change();
267 });
268
269 $.ajax({
270 url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
271 ,type: 'POST'
272 ,data: {
273 'action': 'getWorkstationByProduct'
274 ,'token' : "<?php echo newToken() ?>"
275 ,'idproduct' : idproduct
276 }
277 }).done(function(data) {
278 $('#idworkstations').val(data.defaultWk).select2();
279 });
280 });
281 <?php } ?>
282});
283
284</script>
285
286<!-- END PHP TEMPLATE objectline_create.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class for BOMLine.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137