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