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