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