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