dolibarr 18.0.6
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 Frédéric France <frederic.france@netlogic.fr>
10 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
12 * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
13 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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 * Need to have following variables defined:
29 * $object (invoice, order, ...)
30 * $conf
31 * $langs
32 * $dateSelector
33 * $forceall (0 by default, 1 for supplier invoices/orders)
34 * $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
35 * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
36 */
37
38// Protection to avoid direct call of template
39if (empty($object) || !is_object($object)) {
40 print "Error: this template page cannot be called directly as an URL";
41 exit;
42}
43
44$usemargins = 0;
45if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
46 $usemargins = 1;
47}
48if (!isset($dateSelector)) {
49 global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
50}
51global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
52global $mysoc;
53
54if (!isset($dateSelector)) {
55 $dateSelector = 1; // For backward compatibility
56} elseif (empty($dateSelector)) {
57 $dateSelector = 0;
58}
59if (empty($forceall)) {
60 $forceall = 0;
61}
62if (empty($senderissupplier)) {
63 $senderissupplier = 0;
64}
65if (empty($inputalsopricewithtax)) {
66 $inputalsopricewithtax = 0;
67}
68// Define colspan for the button 'Add'
69$colspan = 3; // Columns: total ht + col edit + col delete
70if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
71 $colspan++; //Add column for Total (currency) if required
72}
73if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
74 $colspan++; // With this, there is a column move button
75}
76if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
77 $colspan++;
78}
79
80//print $object->element;
81// Lines for extrafield
82$objectline = null;
83if (!empty($extrafields)) {
84 if ($this->table_element_line == 'commandedet') {
85 $objectline = new OrderLine($this->db);
86 } elseif ($this->table_element_line == 'propaldet') {
87 $objectline = new PropaleLigne($this->db);
88 } elseif ($this->table_element_line == 'supplier_proposaldet') {
89 $objectline = new SupplierProposalLine($this->db);
90 } elseif ($this->table_element_line == 'facturedet') {
91 $objectline = new FactureLigne($this->db);
92 } elseif ($this->table_element_line == 'contratdet') {
93 $objectline = new ContratLigne($this->db);
94 } elseif ($this->table_element_line == 'commande_fournisseurdet') {
95 $objectline = new CommandeFournisseurLigne($this->db);
96 } elseif ($this->table_element_line == 'facture_fourn_det') {
97 $objectline = new SupplierInvoiceLine($this->db);
98 } elseif ($this->table_element_line == 'facturedet_rec') {
99 $objectline = new FactureLigneRec($this->db);
100 } elseif ($this->table_element_line == 'facture_fourn_det_rec') {
101 $objectline = new FactureFournisseurLigneRec($this->db);
102 }
103}
104print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
105$nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
106if ($nolinesbefore) {
107 ?>
108 <tr class="liste_titre<?php echo (($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_add_') ?> nodrag nodrop">
109 <?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
110 <td class="linecolnum center"></td>
111 <?php } ?>
112 <td class="linecoldescription minwidth400imp">
113 <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span>
114 </td>
115 <?php
116 if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
117 ?>
118 <td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
119 <?php
120 }
121 ?>
122 <td class="linecolvat right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
123 <td class="linecoluht right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
124 <?php if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) { ?>
125 <td class="linecoluht_currency right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
126 <?php } ?>
127 <?php if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) { ?>
128 <td class="linecoluttc right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
129 <?php } ?>
130 <td class="linecolqty right"><?php echo $langs->trans('Qty'); ?></td>
131 <?php
132 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
133 print '<td class="linecoluseunit left">';
134 print '<span id="title_units">';
135 print $langs->trans('Unit');
136 print '</span></td>';
137 }
138 ?>
139 <td class="linecoldiscount right"><?php echo $langs->trans('ReductionShort'); ?></td>
140 <?php
141 // Fields for situation invoice
142 if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
143 print '<td class="linecolcycleref right">'.$langs->trans('Progress').'</td>';
144 print '<td class="linecolcycleref2 right"></td>';
145 }
146 if (!empty($usemargins)) {
147 if (empty($user->rights->margins->creer)) {
148 $colspan++;
149 } else {
150 print '<td class="margininfos linecolmargin1 right">';
151 if ($conf->global->MARGIN_TYPE == "1") {
152 echo $langs->trans('BuyingPrice');
153 } else {
154 echo $langs->trans('CostPrice');
155 }
156 echo '</td>';
157 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
158 echo '<td class="margininfos linecolmargin2 right"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
159 }
160 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
161 echo '<td class="margininfos linecolmargin2 right"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
162 }
163 }
164 }
165 ?>
166 <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
167 </tr>
168 <?php
169}
170?>
171<tr class="pair nodrag nodrop nohoverpair<?php echo ($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create'; ?>">
172 <?php
173 $coldisplay = 0;
174 // Adds a line numbering column
175 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
176 $coldisplay++;
177 echo '<td class="nobottom linecolnum center"></td>';
178 }
179 $coldisplay++;
180 ?>
181 <td class="nobottom linecoldescription minwidth400imp">
182 <?php
183 $freelines = false;
184 if (empty($conf->global->MAIN_DISABLE_FREE_LINES)) {
185 $freelines = true;
186 $forceall = 1; // We always force all type for free lines (module product or service means we use predefined product or service)
187 if ($object->element == 'contrat') {
188 if (!isModEnabled('product') && !isModEnabled('service') && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
189 $forceall = -1; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
190 } elseif (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
191 $forceall = 3;
192 }
193 }
194 // Free line
195 echo '<span class="prod_entry_mode_free">';
196 // Show radio free line
197 if ($forceall >= 0 && (isModEnabled("product") || isModEnabled("service"))) {
198 echo '<label for="prod_entry_mode_free">';
199 echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
200 //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (!isModEnabled('product') || !isModEnabled('service')))?' checked':'') );
201 echo ((GETPOST('prod_entry_mode', 'alpha') == 'free' || !empty($conf->global->MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT)) ? ' checked' : '');
202 echo '> ';
203 // Show type selector
204 echo '<span class="textradioforitem">'.$langs->trans("FreeLineOfType").'</span>';
205 echo '</label>';
206 echo ' ';
207 } else {
208 echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
209 // Show type selector
210 if ($forceall >= 0) {
211 if (!isModEnabled('product') || !isModEnabled('service')) {
212 echo $langs->trans("Type");
213 } else {
214 echo $langs->trans("FreeLineOfType");
215 }
216 echo ' ';
217 }
218 }
219 $form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', 1, 1, $forceall);
220 echo '</span>';
221 }
222 // Predefined product/service
223 if (isModEnabled("product") || isModEnabled("service")) {
224 if ($forceall >= 0 && $freelines) {
225 echo '<br><span class="prod_entry_mode_predef paddingtop">';
226 } else {
227 echo '<span class="prod_entry_mode_predef">';
228 }
229 echo '<label for="prod_entry_mode_predef">';
230 echo '<input type="radio" class="prod_entry_mode_predef" name="prod_entry_mode" id="prod_entry_mode_predef" value="predef"'.(GETPOST('prod_entry_mode') == 'predef' ? ' checked' : '').'> ';
231 $labelforradio = '';
232 if (empty($conf->dol_optimize_smallscreen)) {
233 if (empty($senderissupplier)) {
234 if (isModEnabled("product") && !isModEnabled('service')) {
235 $labelforradio = $langs->trans('PredefinedProductsToSell');
236 } elseif ((!isModEnabled('product') && isModEnabled('service')) || ($object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS))) {
237 $labelforradio = $langs->trans('PredefinedServicesToSell');
238 } else {
239 $labelforradio = $langs->trans('PredefinedProductsAndServicesToSell');
240 }
241 } else {
242 if (isModEnabled("product") && !isModEnabled('service')) {
243 $labelforradio = $langs->trans('PredefinedProductsToPurchase');
244 } elseif (!isModEnabled('product') && isModEnabled('service')) {
245 $labelforradio = $langs->trans('PredefinedServicesToPurchase');
246 } else {
247 $labelforradio = $langs->trans('PredefinedProductsAndServicesToPurchase');
248 }
249 }
250 } else {
251 $labelforradio = $langs->trans('PredefinedItem');
252 }
253 print '<span class="textradioforitem">'.$labelforradio.'</span>';
254 echo '</label>';
255 echo ' ';
256 $filtertype = '';
257 if (!empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
258 $filtertype = '1';
259 }
260 if (empty($senderissupplier)) {
261 $statustoshow = 1;
262 $statuswarehouse = 'warehouseopen,warehouseinternal';
263 if (!empty($conf->global->ENTREPOT_WAREHOUSEINTERNAL_NOT_SELL)) $statuswarehouse = 'warehouseopen';
264 if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
265 // hide products in closed warehouse, but show products for internal transfer
266 $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, $statuswarehouse, GETPOST('combinations', 'array'));
267 } else {
268 $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOST('combinations', 'array'));
269 }
270 if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS)) {
271 ?>
272 <script>
273 $(document).ready(function(){
274 // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
275 $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
276 console.log('focus on a select2');
277 if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
278 {
279 console.log('open combo');
280 $('#idprod').select2('open');
281 }
282 });
283 });
284 </script>
285 <?php
286 }
287 } else {
288 // $senderissupplier=2 is the same as 1 but disables test on minimum qty, disable autofill qty with minimum and autofill unit price
289 if ($senderissupplier != 2) {
290 $ajaxoptions = array(
291 'update' => array('qty'=>'qty', 'remise_percent' => 'discount', 'idprod' => 'idprod'), // html id tags that will be edited with each ajax json response key
292 'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
293 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for example shown we select a disabled option into combo)
294 );
295 $alsoproductwithnosupplierprice = 0;
296 } else {
297 $ajaxoptions = array(
298 // Disabled: This is useless because setting discount and price_ht after a selection is already managed
299 // by ths page itself with a .change on the combolist '#idprodfournprice'
300 //'update' => array('remise_percent' => 'discount', 'price_ht' => 'price_ht') // html id tags that will be edited with each ajax json response key
301 );
302 $alsoproductwithnosupplierprice = 1;
303 }
304 $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'minwidth300imp maxwidth500');
305 if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS)) {
306 ?>
307 <script>
308 $(document).ready(function(){
309 // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
310 $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
311 //console.log('focus on a select2');
312 if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
313 {
314 $('#idprodfournprice').select2('open');
315 }
316 });
317 });
318 </script>
319 <?php
320 }
321 }
322 echo '<input type="hidden" name="pbq" id="pbq" value="">';
323 echo '</span>';
324 }
325
326 if (!empty($conf->global->MAIN_ADD_LINE_AT_POSITION)) {
327 echo '<br>'.$langs->trans('AddLineOnPosition').' : <input type="number" name="rank" step="1" min="0" style="width: 5em;">';
328 }
329
330 if (is_object($hookmanager) && empty($senderissupplier)) {
331 $parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
332 $reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
333 if (!empty($hookmanager->resPrint)) {
334 print $hookmanager->resPrint;
335 }
336 }
337 if (is_object($hookmanager) && !empty($senderissupplier)) {
338 $parameters = array('htmlname'=>'addproduct');
339 $reshook = $hookmanager->executeHooks('formCreateProductSupplierOptions', $parameters, $object, $action);
340 if (!empty($hookmanager->resPrint)) {
341 print $hookmanager->resPrint;
342 }
343 }
344 if (isModEnabled("product") || isModEnabled("service")) {
345 echo '<br>';
346 if (isModEnabled('variants')) {
347 echo '<div id="attributes_box"></div>';
348 }
349 }
350 // Editor wysiwyg
351 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
352 $nbrows = ROWS_2;
353 $enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
354 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
355 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
356 }
357 $toolbarname = 'dolibarr_details';
358 if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
359 $toolbarname = 'dolibarr_notes';
360 }
361 $doleditor = new DolEditor('dp_desc', GETPOST('dp_desc', 'restricthtml'), '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 100 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%');
362 $doleditor->Create();
363 // Show autofill date for recurring invoices
364 if (isModEnabled("service") && ($object->element == 'facturerec' || $object->element == 'invoice_supplier_rec')) {
365 echo '<div class="divlinefordates"><br>';
366 echo $langs->trans('AutoFillDateFrom').' ';
367 if (!empty($conf->global->INVOICE_REC_DATE_TO_YES)) {
368 $line->date_start_fill = 1;
369 $line->date_end_fill = 1;
370 }
371 echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
372 echo ' - ';
373 echo $langs->trans('AutoFillDateTo').' ';
374 echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
375 echo '</div>';
376 }
377 if (is_object($objectline)) {
378 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
379
380 if (!empty($temps)) {
381 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
382 print $temps;
383 print '</div>';
384 }
385 }
386 echo '</td>';
387 if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
388 $coldisplay++;
389 ?>
390 <td class="nobottom linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth100 maxwidth125onsmartphone" value="<?php echo (GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>
391 <?php }
392 print '<td class="nobottom linecolvat right">';
393 $coldisplay++;
394 if ($seller->tva_assuj == "0") {
395 echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
396 } else {
397 echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
398 }
399 ?>
400 </td>
401
402 <td class="nobottom linecoluht right"><?php $coldisplay++; ?>
403 <input type="text" size="5" name="price_ht" id="price_ht" class="flat right" value="<?php echo (GETPOSTISSET("price_ht") ? GETPOST("price_ht", 'alpha', 2) : ''); ?>">
404 </td>
405
406 <?php
407 if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
408 $coldisplay++;
409 ?>
410 <td class="nobottom linecoluht_currency right">
411 <input type="text" size="5" name="multicurrency_price_ht" id="multicurrency_price_ht" class="flat right" value="<?php echo (GETPOSTISSET("multicurrency_price_ht") ? GETPOST("multicurrency_price_ht", 'alpha', 2) : ''); ?>">
412 </td>
413 <?php
414 }
415 if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
416 $coldisplay++;
417 ?>
418 <td class="nobottom linecoluttc right">
419 <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat right" value="<?php echo (GETPOSTISSET("price_ttc") ? GETPOST("price_ttc", 'alpha', 2) : ''); ?>">
420 </td>
421 <?php
422 }
423 $coldisplay++;
424 ?>
425 <td class="nobottom linecolqty right">
426 <?php $default_qty = (empty($conf->global->MAIN_OBJECTLINE_CREATE_EMPTY_QTY_BY_DEFAULT) ? 1 : ''); ?>
427 <input type="text" name="qty" id="qty" class="flat width40 right" value="<?php echo (GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : $default_qty); ?>">
428 </td>
429 <?php
430 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
431 $coldisplay++;
432 print '<td class="nobottom linecoluseunit left">';
433 print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, "units");
434 print '</td>';
435 }
436 $remise_percent = $buyer->remise_percent;
437 if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
438 $remise_percent = $seller->remise_supplier_percent;
439 }
440 $coldisplay++;
441 ?>
442
443 <td class="nobottom nowrap linecoldiscount right"><input type="text" name="remise_percent" id="remise_percent" class="flat width40 right" value="<?php echo (GETPOSTISSET("remise_percent") ? GETPOST("remise_percent", 'alpha', 2) : ($remise_percent ? $remise_percent : '')); ?>"><span class="opacitymedium hideonsmartphone">%</span></td>
444 <?php
445 if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
446 $coldisplay++;
447 print '<td class="nobottom nowrap right"><input class="falt right" type="text" size="1" value="" name="progress"><span class="opacitymedium hideonsmartphone">%</span></td>';
448 $coldisplay++;
449 print '<td></td>';
450 }
451 if (!empty($usemargins)) {
452 if (!empty($user->rights->margins->creer)) {
453 $coldisplay++;
454 ?>
455 <td class="nobottom margininfos linecolmargin right">
456 <!-- For predef product -->
457 <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
458 <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp maxwidth150" style="display: none;"></select>
459 <?php } ?>
460 <!-- For free product -->
461 <input type="text" id="buying_price" name="buying_price" class="flat maxwidth75 right" value="<?php echo (GETPOSTISSET("buying_price") ? GETPOST("buying_price", 'alpha', 2) : ''); ?>">
462 </td>
463 <?php
464 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
465 echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_marginRate" name="np_marginRate" value="'.(GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", 'alpha', 2) : '').'"><span class="np_marginRate opacitymedium hideonsmartphone">%</span></td>';
466 $coldisplay++;
467 }
468 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
469 echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_markRate" name="np_markRate" value="'.(GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : '').'"><span class="np_markRate opacitymedium hideonsmartphone">%</span></td>';
470 $coldisplay++;
471 }
472 }
473 }
474 $coldisplay += $colspan;
475 ?>
476 <td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>">
477 <input type="submit" class="button reposition" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
478 </td>
479</tr>
480
481<?php
482if ((isModEnabled("service") || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') { // We show date field if required
483 print '<tr id="trlinefordates" class="oddeven">'."\n";
484 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
485 print '<td></td>';
486 }
487 print '<td colspan="'.($coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1)).'">';
488 $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
489 $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
490
491 $prefillDates = false;
492
493 if (!empty($conf->global->MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE) && !empty($object->lines)) {
494 for ($i = count($object->lines) - 1; $i >= 0; $i--) {
495 $lastline = $object->lines[$i];
496
497 if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
498 $date_start_prefill = $lastline->date_start;
499 $date_end_prefill = $lastline->date_end;
500
501 $prefillDates = true;
502 break;
503 }
504 }
505 }
506
507 if (!empty($object->element) && $object->element == 'contrat') {
508 print $langs->trans("DateStartPlanned").' ';
509 print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
510 print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
511 print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
512 } else {
513 print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
514 print $form->selectDate($date_start, 'date_start', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
515 print ' '.$langs->trans('to').' ';
516 print $form->selectDate($date_end, 'date_end', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
517 }
518
519 if ($prefillDates) {
520 echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
521 }
522
523 print '<script>';
524
525 if ($prefillDates) {
526 ?>
527 function prefill_service_dates()
528 {
529 $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
530 $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
531
532 return false; // Prevent default link behaviour (which is go to href URL)
533 }
534
535 $(document).ready(function()
536 {
537 $('#prefill_service_dates').click(prefill_service_dates);
538 });
539
540 <?php
541 }
542
543 if (!$date_start) {
544 if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
545 print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
546 }
547 if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
548 print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
549 }
550 }
551 if (!$date_end) {
552 if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
553 print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
554 }
555 if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
556 print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
557 }
558 }
559 print '</script>';
560 print '</td>';
561 print '</tr>'."\n";
562}
563
564
565print "<script>\n";
566if (!empty($usemargins) && $user->rights->margins->creer) {
567 ?>
568 /* Some js test when we click on button "Add" */
569 jQuery(document).ready(function() {
570 <?php
571 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
572 $("input[name='np_marginRate']:first").blur(function(e) {
573 return checkFreeLine(e, "np_marginRate");
574 });
575 <?php
576 }
577 if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
578 $("input[name='np_markRate']:first").blur(function(e) {
579 return checkFreeLine(e, "np_markRate");
580 });
581 <?php
582 }
583 ?>
584 });
585
586 /* TODO This does not work for number with thousand separator that is , */
587 function checkFreeLine(e, npRate)
588 {
589 var buying_price = $("input[name='buying_price']:first");
590 var remise = $("input[name='remise_percent']:first");
591
592 var rate = $("input[name='"+npRate+"']:first");
593 if (rate.val() == '')
594 return true;
595
596 if (! $.isNumeric(rate.val().replace(',','.')))
597 {
598 alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
599 e.stopPropagation();
600 setTimeout(function () { rate.focus() }, 50);
601 return false;
602 }
603 if (npRate == "np_markRate" && rate.val() >= 100)
604 {
605 alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
606 e.stopPropagation();
607 setTimeout(function () { rate.focus() }, 50);
608 return false;
609 }
610
611 var price = 0;
612 remisejs=price2numjs(remise.val());
613
614 if (remisejs != 100) // If a discount not 100 or no discount
615 {
616 if (remisejs == '') remisejs=0;
617
618 bpjs=price2numjs(buying_price.val());
619 ratejs=price2numjs(rate.val());
620
621 if (npRate == "np_marginRate")
622 price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
623 else if (npRate == "np_markRate")
624 price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
625 }
626
627 $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
628
629 return true;
630 }
631
632 <?php
633}
634?>
635
636 /* JQuery for product free or predefined select */
637 jQuery(document).ready(function() {
638 jQuery("#price_ht").keyup(function(event) {
639 // console.log(event.which); // discard event tag and arrows
640 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
641 jQuery("#price_ttc").val('');
642 jQuery("#multicurrency_subprice").val('');
643 }
644 });
645 jQuery("#price_ttc").keyup(function(event) {
646 // console.log(event.which); // discard event tag and arrows
647 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
648 jQuery("#price_ht").val('');
649 jQuery("#multicurrency_subprice").val('');
650 }
651 });
652 jQuery("#multicurrency_subprice").keyup(function(event) {
653 // console.log(event.which); // discard event tag and arrows
654 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
655 jQuery("#price_ht").val('');
656 jQuery("#price_ttc").val('');
657 }
658 });
659
660 $("#prod_entry_mode_free").on( "click", function() {
661 setforfree();
662 });
663 $("#select_type").change(function()
664 {
665 setforfree();
666
667 if (jQuery('#select_type').val() >= 0) {
668 console.log("Set focus on description field");
669 /* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
670 jQuery('#dp_desc').focus();
671 /* this focus code works for CKEDITOR */
672 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
673 var editor = CKEDITOR.instances['dp_desc'];
674 if (editor) {
675 editor.focus();
676 }
677 }
678 }
679
680 console.log("Hide/show date according to product type");
681 if (jQuery('#select_type').val() == '0')
682 {
683 jQuery('#trlinefordates').hide();
684 jQuery('.divlinefordates').hide();
685 }
686 else
687 {
688 jQuery('#trlinefordates').show();
689 jQuery('.divlinefordates').show();
690 }
691 });
692
693 $("#prod_entry_mode_predef").on( "click", function() {
694 console.log("click prod_entry_mode_predef");
695 setforpredef();
696 jQuery('#trlinefordates').show();
697 });
698
699 <?php
700 if (!$freelines) { ?>
701 $("#prod_entry_mode_predef").click();
702 <?php
703 }
704
705 if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
706 $("#date_start, #date_end").focusout(function() {
707 let type = $(this).attr('type');
708 let mandatoryP = $(this).attr('mandatoryperiod');
709 if (type == 1 && mandatoryP == 1) {
710 if ($(this).val() == '' && !$(this).hasClass('inputmandatory')) {
711 $(this).addClass('inputmandatory');
712 }else{
713 $(this).removeClass('inputmandatory');
714 }
715 }
716 });
717 <?php
718 } ?>
719 /* When changing predefined product, we reload list of supplier prices required for margin combo */
720 $("#idprod, #idprodfournprice").change(function()
721 {
722 console.log("objectline_create.tpl Call method change() after change on #idprod or #idprodfournprice (senderissupplier=<?php echo $senderissupplier; ?>). this.val = "+$(this).val());
723
724 setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva(product)
725
726 jQuery('#trlinefordates').show();
727
728 <?php
729 if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier)) {
730 ?>
731 var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
732 if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
733
734 if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
735 {
736 console.log("objectline_create.tpl We are in a price per qty context, we do not call ajax/product, init of fields is done few lines later");
737 } else {
738 <?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
739 if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we could not get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
740 <?php } ?>
741 // Get the price for the product and display it
742 console.log("Load unit price and set it into #price_ht or #price_ttc for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
743 $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
744 { 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>', 'addalsovatforthirdpartyid': 1 },
745 function(data) {
746 console.log("objectline_create.tpl Load unit price ends, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
747
748 $('#date_start').removeAttr('type');
749 $('#date_end').removeAttr('type');
750 $('#date_start').attr('type', data.type);
751 $('#date_end').attr('type', data.type);
752
753 $('#date_start').removeAttr('mandatoryperiod');
754 $('#date_end').removeAttr('mandatoryperiod');
755 $('#date_start').attr('mandatoryperiod', data.mandatory_period);
756 $('#date_end').attr('mandatoryperiod', data.mandatory_period);
757
758 // service and we setted mandatory_period to true
759 if (data.mandatory_period == 1 && data.type == 1) {
760 jQuery('#date_start').addClass('inputmandatory');
761 jQuery('#date_end').addClass('inputmandatory');
762 } else {
763 jQuery('#date_start').removeClass('inputmandatory');
764 jQuery('#date_end').removeClass('inputmandatory');
765 }
766
767 if (<?php echo (int) $inputalsopricewithtax; ?> == 1 && data.pricebasetype == 'TTC' && <?php print getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX') ? 'false' : 'true'; ?>) {
768 console.log("objectline_create.tpl set content of price_ttc");
769 jQuery("#price_ttc").val(data.price_ttc);
770 } else {
771 console.log("objectline_create.tpl set content of price_ht");
772 jQuery("#price_ht").val(data.price_ht);
773 }
774
775 var tva_tx = data.tva_tx;
776 var default_vat_code = data.default_vat_code;
777
778 // Now set the VAT
779 var stringforvatrateselection = tva_tx;
780 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
781 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
782 <?php
783 // Special case for India
784 if (getDolGlobalString('MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
785 ?>
786 console.log("MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA is on so we check if we need to autoswith the vat code");
787 console.log("mysoc->country_code=<?php echo $mysoc->country_code; ?> thirdparty->country_code=<?php echo $object->thirdparty->country_code; ?>");
788 new_default_vat_code = default_vat_code;
789 <?php
790 if ($mysoc->country_code == 'IN' && !empty($object->thirdparty) && $object->thirdparty->country_code == 'IN' && $mysoc->state_code == $object->thirdparty->state_code) {
791 // We are in India and states are same, we revert the vat code "I-x" into "CS-x"
792 ?>
793 console.log("Countries are both IN and states are same, so we revert I into CS in default_vat_code="+default_vat_code);
794 new_default_vat_code = default_vat_code.replace(/^I\-/, 'C+S-');
795 <?php
796 } elseif ($mysoc->country_code == 'IN' && !empty($object->thirdparty) && $object->thirdparty->country_code == 'IN' && $mysoc->state_code != $object->thirdparty->state_code) {
797 // We are in India and states differs, we revert the vat code "CS-x" into "I-x"
798 ?>
799 console.log("Countries are both IN and states differs, so we revert CS into I in default_vat_code="+default_vat_code);
800 new_default_vat_code = default_vat_code.replace(/^C\+S\-/, 'I-');
801 <?php
802 }
803 ?>
804 if (new_default_vat_code != default_vat_code && jQuery('#tva_tx option:contains("'+new_default_vat_code+'")').val()) {
805 console.log("We found en entry into VAT with new default_vat_code, we will use it");
806 stringforvatrateselection = jQuery('#tva_tx option:contains("'+new_default_vat_code+'")').val();
807 }
808 <?php
809 }
810 ?>
811 }
812 // Set vat rate if field is an input box
813 $('#tva_tx').val(tva_tx);
814 // Set vat rate by selecting the combo
815 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
816 $('#tva_tx option').removeAttr('selected');
817 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
818 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
819
820 <?php
821 if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
822 if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?>
823 var proddesc = data.desc_trans;
824 <?php
825 } else { ?>
826 var proddesc = data.desc;
827 <?php
828 } ?>
829 console.log("objectline_create.tpl Load desciption into text area : "+proddesc);
830 <?php
831 if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
832 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
833 {
834 var editor = CKEDITOR.instances['dp_desc'];
835 if (editor) {
836 editor.setData(proddesc);
837 }
838 }
839 <?php
840 } else { ?>
841 jQuery('#dp_desc').text(proddesc);
842 <?php
843 } ?>
844 <?php
845 } ?>
846 <?php
847 if (!empty($conf->global->PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES)) { ?>
848 jQuery.each(data.array_options, function( key, value ) {
849 jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value);
850 });
851 <?php
852 } ?>
853 },
854 'json'
855 );
856 }
857 <?php
858 }
859
860 if (!empty($usemargins) && $user->rights->margins->creer) {
861 $langs->load('stocks');
862 ?>
863
864 /* Code for margin */
865 $("#fournprice_predef").find("option").remove();
866 $("#fournprice_predef").hide();
867 $("#buying_price").val("").show();
868
869 /* Call post to load content of combo list fournprice_predef */
870 var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
871 $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
872 if (data && data.length > 0)
873 {
874 var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
875
876 var bestpriceid = 0; var bestpricevalue = 0;
877 var pmppriceid = 0; var pmppricevalue = 0;
878 var costpriceid = 0; var costpricevalue = 0;
879
880 /* setup of margin calculation */
881 var defaultbuyprice = '<?php
882 if (isset($conf->global->MARGIN_TYPE)) {
883 if ($conf->global->MARGIN_TYPE == '1') {
884 print 'bestsupplierprice';
885 }
886 if ($conf->global->MARGIN_TYPE == 'pmp') {
887 print 'pmp';
888 }
889 if ($conf->global->MARGIN_TYPE == 'costprice') {
890 print 'costprice';
891 }
892 } ?>';
893 console.log("objectline_create.tpl we will set the field for margin. defaultbuyprice="+defaultbuyprice);
894
895 var i = 0;
896 $(data).each(function() {
897 /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
898 if (this.id != 'pmpprice' && this.id != 'costprice')
899 {
900 i++;
901 this.price = parseFloat(this.price); // to fix when this.price >0
902 // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
903 //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
904 if (bestpricefound == 0 && this.price > 0) { defaultkey = this.id; defaultprice = this.price; bestpriceid = this.id; bestpricevalue = this.price; bestpricefound=1; } // bestpricefound is used to take the first price > 0
905 }
906 if (this.id == 'pmpprice')
907 {
908 // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
909 console.log("id="+this.id+"-price="+this.price);
910 if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
911 {
912 if (this.price > 0) {
913 defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
914 //console.log("pmppricevalue="+pmppricevalue);
915 }
916 }
917 }
918 if (this.id == 'costprice')
919 {
920 // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
921 console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
922 if ('costprice' == defaultbuyprice)
923 {
924 if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
925 else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
926 }
927 }
928 options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
929 });
930 options += '<option value="inputprice" price="'+defaultprice+'"><?php echo dol_escape_js($langs->trans("InputPrice").'...'); ?></option>';
931
932 console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
933
934 $("#fournprice_predef").html(options).show();
935 if (defaultkey != '')
936 {
937 $("#fournprice_predef").val(defaultkey);
938 }
939
940 /* At loading, no product are yet selected, so we hide field of buying_price */
941 $("#buying_price").hide();
942
943 /* Define default price at loading */
944 var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
945 $("#buying_price").val(defaultprice);
946
947 $("#fournprice_predef").change(function() {
948 console.log("change on fournprice_predef");
949 /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
950 var linevalue=$(this).find('option:selected').val();
951 var pricevalue = $(this).find('option:selected').attr("price");
952 if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
953 $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
954 }
955 if (linevalue == 'inputprice') {
956 $('#buying_price').show();
957 }
958 if (linevalue == 'pmpprice') {
959 $("#buying_price").val(pricevalue);
960 $('#buying_price').hide();
961 }
962 });
963 }
964 },
965 'json');
966
967 <?php
968 }
969 ?>
970
971 <?php
972 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
973 ?>
974 /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
975 var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
976 if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
977 var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
978 if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
979 var pbqbase = $('option:selected', this).attr('data-pbqbase');
980 if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
981 var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
982 if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
983 var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
984 if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
985
986 if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
987 {
988 var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
989
990 console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty upht = "+pbqupht+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
991 jQuery("#pbq").val(pbq);
992 jQuery("#price_ht").val(pbqupht);
993 if (jQuery("#qty").val() < pbqqty)
994 {
995 jQuery("#qty").val(pbqqty);
996 }
997 if (jQuery("#remise_percent").val() < pbqpercent)
998 {
999 jQuery("#remise_percent").val(pbqpercent);
1000 }
1001 } else { jQuery("#pbq").val(''); }
1002 <?php
1003 }
1004 ?>
1005
1006
1007 // Deal with supplier ref price (idprodfournprice = int)
1008 if (jQuery('#idprodfournprice').val() > 0)
1009 {
1010 console.log("objectline_create.tpl #idprodfournprice is an ID > 0, so we set some properties into page");
1011
1012 var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
1013 if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
1014
1015 var up_locale = $('option:selected', this).attr('data-up-locale'); // When select is done from HTML select
1016 if (typeof up_locale === 'undefined') { up_locale = jQuery('#idprodfournprice').attr('data-up-locale');} // When select is done from HTML input with ajax autocomplete
1017
1018 var qty = parseFloat($('option:selected', this).attr('data-qty'));
1019 if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
1020
1021 var discount = parseFloat($('option:selected', this).attr('data-discount'));
1022 if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
1023
1024 var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
1025 if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
1026
1027 var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
1028 if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
1029
1030 var stringforvatrateselection = tva_tx;
1031 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1032 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1033 }
1034
1035 var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
1036 if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref');} // When select is done from HTML input with ajax autocomplete
1037
1038 console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", supplier_ref = "+supplier_ref+" qty = "+qty+", tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+", discount = "+discount+" for product supplier ref id = "+jQuery('#idprodfournprice').val());
1039
1040 if (typeof up_locale === 'undefined') {
1041 jQuery("#price_ht").val(up);
1042 } else {
1043 jQuery("#price_ht").val(up_locale);
1044 }
1045
1046 // Set supplier_ref
1047 $('#fourn_ref').val(supplier_ref);
1048 // Set vat rate if field is an input box
1049 $('#tva_tx').val(tva_tx);
1050 // Set vat rate by selecting the combo
1051 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1052 $('#tva_tx option').removeAttr('selected');
1053 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1054 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1055
1056 if (jQuery("#qty").val() < qty) {
1057 jQuery("#qty").val(qty);
1058 }
1059 if (jQuery("#remise_percent").val() < discount) {
1060 jQuery("#remise_percent").val(discount);
1061 }
1062
1063 <?php
1064 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
1065 ?>
1066 var description = $('option:selected', this).attr('data-description');
1067 if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
1068
1069 console.log("Load desciption into text area : "+description);
1070 <?php
1071 if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
1072 ?>
1073 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1074 {
1075 var editor = CKEDITOR.instances['dp_desc'];
1076 if (editor) {
1077 editor.setData(description);
1078 }
1079 }
1080 <?php
1081 } else {
1082 ?>
1083 jQuery('#dp_desc').text(description);
1084 <?php
1085 }
1086 }
1087 ?>
1088 } else if (jQuery('#idprodfournprice').length > 0) {
1089 console.log("objectline_create.tpl #idprodfournprice is not an int but is a string so we set only few properties into page");
1090
1091 var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
1092 if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
1093
1094 var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
1095 if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
1096
1097 var stringforvatrateselection = tva_tx;
1098 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1099 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1100 }
1101
1102 console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
1103
1104 // Set vat rate if field is an input box
1105 $('#tva_tx').val(tva_tx);
1106 // Set vat rate by selecting the combo
1107 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1108 $('#tva_tx option').removeAttr('selected');
1109 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1110 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1111 <?php
1112 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
1113 if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
1114 ?>
1115 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1116 {
1117 var editor = CKEDITOR.instances['dp_desc'];
1118 if (editor) {
1119 editor.setData('');
1120 }
1121 }
1122 <?php
1123 } else {
1124 ?>
1125 jQuery('#dp_desc').text('');
1126 <?php
1127 }
1128 }
1129 ?>
1130 }
1131
1132
1133 /* To set focus */
1134 if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
1135 {
1136 /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
1137 jQuery('#dp_desc').focus();
1138 /* focus if CKEDITOR */
1139 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1140 {
1141 var editor = CKEDITOR.instances['dp_desc'];
1142 if (editor) { editor.focus(); }
1143 }
1144 }
1145 });
1146
1147 <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
1148 setforpredef();
1149 <?php } ?>
1150 });
1151
1152 /* Function to set fields visibility after selecting a free product */
1153 function setforfree() {
1154 console.log("objectline_create.tpl::setforfree. We show most fields");
1155 jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
1156 jQuery("#prod_entry_mode_free").prop('checked',true).change();
1157 jQuery("#prod_entry_mode_predef").prop('checked',false).change();
1158 jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
1159 jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #multicurrency_price_ttc, #fourn_ref, #tva_tx, #buying_price, #title_fourn_ref, #title_vat, #title_up_ht, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").show();
1160 jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
1161 jQuery("#fournprice_predef").hide();
1162 }
1163
1164 function setforpredef() {
1165 console.log("objectline_create.tpl::setforpredef We hide some fields, show dates");
1166 jQuery("#select_type").val(-1);
1167 jQuery("#prod_entry_mode_free").prop('checked',false).change();
1168 jQuery("#prod_entry_mode_predef").prop('checked',true).change();
1169 <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
1170 jQuery("#price_ht").val('').show();
1171 jQuery("#multicurrency_price_ht").val('').show();
1172 jQuery("#title_up_ht, #title_up_ht_currency").show();
1173 <?php } else { ?>
1174 //jQuery("#price_ht").val('').hide();
1175 jQuery("#multicurrency_price_ht").val('').hide();
1176 jQuery("#title_up_ht, #title_up_ht_currency").hide();
1177 <?php } ?>
1178 <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICETTC)) { ?>
1179 jQuery("#price_ttc").val('').show();
1180 jQuery("#multicurrency_price_ttc").val('').show();
1181 jQuery("#title_up_ttc, #title_up_ttc_currency").show();
1182 <?php } else { ?>
1183 jQuery("#price_ttc").val('').hide();
1184 jQuery("#multicurrency_price_ttc").val('').hide();
1185 jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
1186 <?php } ?>
1187 /* jQuery("#tva_tx, #title_vat").hide(); */
1188 /* jQuery("#title_fourn_ref").hide(); */
1189 jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
1190 jQuery("#buying_price").show();
1191 jQuery('#trlinefordates, .divlinefordates').show();
1192 }
1193
1194<?php
1195
1196print '</script>';
1197
1198print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";
Class to manage lines of contracts.
Class to manage a WYSIWYG editor.
Class to manage supplier invoice lines of templates.
Class to manage invoice lines.
Class to manage invoice lines of templates.
Class to manage order lines.
const TYPE_SERVICE
Service.
Class to manage commercial proposal lines.
Class to manage line invoices.
Class to manage supplier_proposal lines.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return 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 dolibarr global constant string value.
price2numjs(amount)
Function similar to PHP price2num()
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123