dolibarr  x.y.z
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)) { ?>
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 (getDolGlobalInt('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)) {
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  <input type="text" name="qty" id="qty" class="flat width40 right" value="<?php echo (GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : 1); ?>">
425  </td>
426  <?php
427  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
428  $coldisplay++;
429  print '<td class="nobottom linecoluseunit left">';
430  print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, "units");
431  print '</td>';
432  }
433  $remise_percent = $buyer->remise_percent;
434  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
435  $remise_percent = $seller->remise_supplier_percent;
436  }
437  $coldisplay++;
438  ?>
439 
440  <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>
441  <?php
442  if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
443  $coldisplay++;
444  print '<td class="nobottom nowrap right"><input class="falt right" type="text" size="1" value="" name="progress"><span class="opacitymedium hideonsmartphone">%</span></td>';
445  $coldisplay++;
446  print '<td></td>';
447  }
448  if (!empty($usemargins)) {
449  if (!empty($user->rights->margins->creer)) {
450  $coldisplay++;
451  ?>
452  <td class="nobottom margininfos linecolmargin right">
453  <!-- For predef product -->
454  <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
455  <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp maxwidth150" style="display: none;"></select>
456  <?php } ?>
457  <!-- For free product -->
458  <input type="text" id="buying_price" name="buying_price" class="flat maxwidth75 right" value="<?php echo (GETPOSTISSET("buying_price") ? GETPOST("buying_price", 'alpha', 2) : ''); ?>">
459  </td>
460  <?php
461  if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
462  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>';
463  $coldisplay++;
464  }
465  if (!empty($conf->global->DISPLAY_MARK_RATES)) {
466  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>';
467  $coldisplay++;
468  }
469  }
470  }
471  $coldisplay += $colspan;
472  ?>
473  <td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>">
474  <input type="submit" class="button reposition" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
475  </td>
476 </tr>
477 
478 <?php
479 if ((isModEnabled("service") || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') { // We show date field if required
480  print '<tr id="trlinefordates" class="oddeven">'."\n";
481  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
482  print '<td></td>';
483  }
484  print '<td colspan="'.($coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1)).'">';
485  $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
486  $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
487 
488  $prefillDates = false;
489 
490  if (!empty($conf->global->MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE) && !empty($object->lines)) {
491  for ($i = count($object->lines) - 1; $i >= 0; $i--) {
492  $lastline = $object->lines[$i];
493 
494  if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
495  $date_start_prefill = $lastline->date_start;
496  $date_end_prefill = $lastline->date_end;
497 
498  $prefillDates = true;
499  break;
500  }
501  }
502  }
503 
504  if (!empty($object->element) && $object->element == 'contrat') {
505  print $langs->trans("DateStartPlanned").' ';
506  print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
507  print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
508  print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
509  } else {
510  print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
511  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);
512  print ' '.$langs->trans('to').' ';
513  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);
514  }
515 
516  if ($prefillDates) {
517  echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
518  }
519 
520  print '<script>';
521 
522  if ($prefillDates) {
523  ?>
524  function prefill_service_dates()
525  {
526  $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
527  $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
528 
529  return false; // Prevent default link behaviour (which is go to href URL)
530  }
531 
532  $(document).ready(function()
533  {
534  $('#prefill_service_dates').click(prefill_service_dates);
535  });
536 
537  <?php
538  }
539 
540  if (!$date_start) {
541  if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
542  print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
543  }
544  if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
545  print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
546  }
547  }
548  if (!$date_end) {
549  if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
550  print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
551  }
552  if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
553  print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
554  }
555  }
556  print '</script>';
557  print '</td>';
558  print '</tr>'."\n";
559 }
560 
561 
562 print "<script>\n";
563 if (!empty($usemargins) && $user->rights->margins->creer) {
564  ?>
565  /* Some js test when we click on button "Add" */
566  jQuery(document).ready(function() {
567  <?php
568  if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
569  $("input[name='np_marginRate']:first").blur(function(e) {
570  return checkFreeLine(e, "np_marginRate");
571  });
572  <?php
573  }
574  if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
575  $("input[name='np_markRate']:first").blur(function(e) {
576  return checkFreeLine(e, "np_markRate");
577  });
578  <?php
579  }
580  ?>
581  });
582 
583  /* TODO This does not work for number with thousand separator that is , */
584  function checkFreeLine(e, npRate)
585  {
586  var buying_price = $("input[name='buying_price']:first");
587  var remise = $("input[name='remise_percent']:first");
588 
589  var rate = $("input[name='"+npRate+"']:first");
590  if (rate.val() == '')
591  return true;
592 
593  if (! $.isNumeric(rate.val().replace(',','.')))
594  {
595  alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
596  e.stopPropagation();
597  setTimeout(function () { rate.focus() }, 50);
598  return false;
599  }
600  if (npRate == "np_markRate" && rate.val() >= 100)
601  {
602  alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
603  e.stopPropagation();
604  setTimeout(function () { rate.focus() }, 50);
605  return false;
606  }
607 
608  var price = 0;
609  remisejs=price2numjs(remise.val());
610 
611  if (remisejs != 100) // If a discount not 100 or no discount
612  {
613  if (remisejs == '') remisejs=0;
614 
615  bpjs=price2numjs(buying_price.val());
616  ratejs=price2numjs(rate.val());
617 
618  if (npRate == "np_marginRate")
619  price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
620  else if (npRate == "np_markRate")
621  price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
622  }
623 
624  $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
625 
626  return true;
627  }
628 
629  <?php
630 }
631 ?>
632 
633  /* JQuery for product free or predefined select */
634  jQuery(document).ready(function() {
635  jQuery("#price_ht").keyup(function(event) {
636  // console.log(event.which); // discard event tag and arrows
637  if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
638  jQuery("#price_ttc").val('');
639  jQuery("#multicurrency_subprice").val('');
640  }
641  });
642  jQuery("#price_ttc").keyup(function(event) {
643  // console.log(event.which); // discard event tag and arrows
644  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
645  jQuery("#price_ht").val('');
646  jQuery("#multicurrency_subprice").val('');
647  }
648  });
649  jQuery("#multicurrency_subprice").keyup(function(event) {
650  // console.log(event.which); // discard event tag and arrows
651  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
652  jQuery("#price_ht").val('');
653  jQuery("#price_ttc").val('');
654  }
655  });
656 
657  $("#prod_entry_mode_free").on( "click", function() {
658  setforfree();
659  });
660  $("#select_type").change(function()
661  {
662  setforfree();
663 
664  if (jQuery('#select_type').val() >= 0) {
665  console.log("Set focus on description field");
666  /* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
667  jQuery('#dp_desc').focus();
668  /* this focus code works for CKEDITOR */
669  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
670  var editor = CKEDITOR.instances['dp_desc'];
671  if (editor) {
672  editor.focus();
673  }
674  }
675  }
676 
677  console.log("Hide/show date according to product type");
678  if (jQuery('#select_type').val() == '0')
679  {
680  jQuery('#trlinefordates').hide();
681  jQuery('.divlinefordates').hide();
682  }
683  else
684  {
685  jQuery('#trlinefordates').show();
686  jQuery('.divlinefordates').show();
687  }
688  });
689 
690  $("#prod_entry_mode_predef").on( "click", function() {
691  console.log("click prod_entry_mode_predef");
692  setforpredef();
693  jQuery('#trlinefordates').show();
694  });
695 
696  <?php
697  if (!$freelines) { ?>
698  $("#prod_entry_mode_predef").click();
699  <?php
700  }
701 
702  if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
703  $("#date_start, #date_end").focusout(function() {
704  let type = $(this).attr('type');
705  let mandatoryP = $(this).attr('mandatoryperiod');
706  if (type == 1 && mandatoryP == 1) {
707  if ($(this).val() == '' && !$(this).hasClass('inputmandatory')) {
708  $(this).addClass('inputmandatory');
709  }else{
710  $(this).removeClass('inputmandatory');
711  }
712  }
713  });
714  <?php
715  } ?>
716  /* When changing predefined product, we reload list of supplier prices required for margin combo */
717  $("#idprod, #idprodfournprice").change(function()
718  {
719  console.log("objectline_create.tpl Call method change() after change on #idprod or #idprodfournprice (senderissupplier=<?php echo $senderissupplier; ?>). this.val = "+$(this).val());
720 
721  setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva(product)
722 
723  jQuery('#trlinefordates').show();
724 
725  <?php
726  if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier)) {
727  ?>
728  var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
729  if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
730 
731  if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
732  {
733  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");
734  } else {
735  <?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
736  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"); }
737  <?php } ?>
738  // Get the price for the product and display it
739  console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
740  $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
741  { 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>' },
742  function(data) {
743  console.log("objectline_create.tpl Load unit price end, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
744 
745  $('#date_start').removeAttr('type');
746  $('#date_end').removeAttr('type');
747  $('#date_start').attr('type', data.type);
748  $('#date_end').attr('type', data.type);
749 
750  $('#date_start').removeAttr('mandatoryperiod');
751  $('#date_end').removeAttr('mandatoryperiod');
752  $('#date_start').attr('mandatoryperiod', data.mandatory_period);
753  $('#date_end').attr('mandatoryperiod', data.mandatory_period);
754 
755  // service and we setted mandatory_period to true
756  if (data.mandatory_period == 1 && data.type == 1) {
757  jQuery('#date_start').addClass('inputmandatory');
758  jQuery('#date_end').addClass('inputmandatory');
759  } else {
760  jQuery('#date_start').removeClass('inputmandatory');
761  jQuery('#date_end').removeClass('inputmandatory');
762  }
763 
764  if (<?php echo (int) $inputalsopricewithtax; ?> == 1 && data.pricebasetype == 'TTC') {
765  console.log("objectline_create.tpl set content of price_ttc");
766  jQuery("#price_ttc").val(data.price_ttc);
767  } else {
768  console.log("objectline_create.tpl set content of price_ht");
769  jQuery("#price_ht").val(data.price_ht);
770  }
771 
772  var tva_tx = data.tva_tx;
773  var default_vat_code = data.default_vat_code;
774 
775  // Now set the VAT
776  var stringforvatrateselection = tva_tx;
777  if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
778  stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
779  }
780  // Set vat rate if field is an input box
781  $('#tva_tx').val(tva_tx);
782  // Set vat rate by selecting the combo
783  //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
784  $('#tva_tx option').removeAttr('selected');
785  console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
786  $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
787 
788  <?php
789  if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
790  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?>
791  var proddesc = data.desc_trans;
792  <?php
793  } else { ?>
794  var proddesc = data.desc;
795  <?php
796  } ?>
797  console.log("objectline_create.tpl Load desciption into text area : "+proddesc);
798  <?php
799  if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
800  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
801  {
802  var editor = CKEDITOR.instances['dp_desc'];
803  if (editor) {
804  editor.setData(proddesc);
805  }
806  }
807  <?php
808  } else { ?>
809  jQuery('#dp_desc').text(proddesc);
810  <?php
811  } ?>
812  <?php
813  } ?>
814  <?php
815  if (!empty($conf->global->PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES)) { ?>
816  jQuery.each(data.array_options, function( key, value ) {
817  jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value);
818  });
819  <?php
820  } ?>
821  },
822  'json'
823  );
824  }
825  <?php
826  }
827 
828  if (!empty($usemargins) && $user->rights->margins->creer) {
829  $langs->load('stocks');
830  ?>
831 
832  /* Code for margin */
833  $("#fournprice_predef").find("option").remove();
834  $("#fournprice_predef").hide();
835  $("#buying_price").val("").show();
836 
837  /* Call post to load content of combo list fournprice_predef */
838  var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
839  $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
840  if (data && data.length > 0)
841  {
842  var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
843 
844  var bestpriceid = 0; var bestpricevalue = 0;
845  var pmppriceid = 0; var pmppricevalue = 0;
846  var costpriceid = 0; var costpricevalue = 0;
847 
848  /* setup of margin calculation */
849  var defaultbuyprice = '<?php
850  if (isset($conf->global->MARGIN_TYPE)) {
851  if ($conf->global->MARGIN_TYPE == '1') {
852  print 'bestsupplierprice';
853  }
854  if ($conf->global->MARGIN_TYPE == 'pmp') {
855  print 'pmp';
856  }
857  if ($conf->global->MARGIN_TYPE == 'costprice') {
858  print 'costprice';
859  }
860  } ?>';
861  console.log("objectline_create.tpl we will set the field for margin. defaultbuyprice="+defaultbuyprice);
862 
863  var i = 0;
864  $(data).each(function() {
865  /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
866  if (this.id != 'pmpprice' && this.id != 'costprice')
867  {
868  i++;
869  this.price = parseFloat(this.price); // to fix when this.price >0
870  // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
871  //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
872  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
873  }
874  if (this.id == 'pmpprice')
875  {
876  // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
877  console.log("id="+this.id+"-price="+this.price);
878  if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
879  {
880  if (this.price > 0) {
881  defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
882  //console.log("pmppricevalue="+pmppricevalue);
883  }
884  }
885  }
886  if (this.id == 'costprice')
887  {
888  // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
889  console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
890  if ('costprice' == defaultbuyprice)
891  {
892  if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
893  else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
894  }
895  }
896  options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
897  });
898  options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice").'...'; ?></option>';
899 
900  console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
901 
902  $("#fournprice_predef").html(options).show();
903  if (defaultkey != '')
904  {
905  $("#fournprice_predef").val(defaultkey);
906  }
907 
908  /* At loading, no product are yet selected, so we hide field of buying_price */
909  $("#buying_price").hide();
910 
911  /* Define default price at loading */
912  var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
913  $("#buying_price").val(defaultprice);
914 
915  $("#fournprice_predef").change(function() {
916  console.log("change on fournprice_predef");
917  /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
918  var linevalue=$(this).find('option:selected').val();
919  var pricevalue = $(this).find('option:selected').attr("price");
920  if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
921  $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
922  }
923  if (linevalue == 'inputprice') {
924  $('#buying_price').show();
925  }
926  if (linevalue == 'pmpprice') {
927  $("#buying_price").val(pricevalue);
928  $('#buying_price').hide();
929  }
930  });
931  }
932  },
933  'json');
934 
935  <?php
936  }
937  ?>
938 
939  <?php
940  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
941  ?>
942  /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
943  var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
944  if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
945  var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
946  if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
947  var pbqbase = $('option:selected', this).attr('data-pbqbase');
948  if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
949  var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
950  if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
951  var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
952  if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
953 
954  if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
955  {
956  var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
957 
958  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);
959  jQuery("#pbq").val(pbq);
960  jQuery("#price_ht").val(pbqupht);
961  if (jQuery("#qty").val() < pbqqty)
962  {
963  jQuery("#qty").val(pbqqty);
964  }
965  if (jQuery("#remise_percent").val() < pbqpercent)
966  {
967  jQuery("#remise_percent").val(pbqpercent);
968  }
969  } else { jQuery("#pbq").val(''); }
970  <?php
971  }
972  ?>
973 
974 
975  // Deal with supplier ref price (idprodfournprice = int)
976  if (jQuery('#idprodfournprice').val() > 0)
977  {
978  console.log("objectline_create.tpl #idprodfournprice is is an ID > 0, so we set some properties into page");
979 
980  var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
981  if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
982 
983  var up_locale = $('option:selected', this).attr('data-up-locale'); // When select is done from HTML select
984  if (typeof up_locale === 'undefined') { up_locale = jQuery('#idprodfournprice').attr('data-up-locale');} // When select is done from HTML input with ajax autocomplete
985 
986  var qty = parseFloat($('option:selected', this).attr('data-qty'));
987  if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
988 
989  var discount = parseFloat($('option:selected', this).attr('data-discount'));
990  if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
991 
992  var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
993  if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
994 
995  var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
996  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
997 
998  var stringforvatrateselection = tva_tx;
999  if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1000  stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1001  }
1002 
1003  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());
1004 
1005  if (typeof up_locale === 'undefined') {
1006  jQuery("#price_ht").val(up);
1007  } else {
1008  jQuery("#price_ht").val(up_locale);
1009  }
1010 
1011  // Set vat rate if field is an input box
1012  $('#tva_tx').val(tva_tx);
1013  // Set vat rate by selecting the combo
1014  //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1015  $('#tva_tx option').removeAttr('selected');
1016  console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1017  $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1018 
1019  if (jQuery("#qty").val() < qty) {
1020  jQuery("#qty").val(qty);
1021  }
1022  if (jQuery("#remise_percent").val() < discount) {
1023  jQuery("#remise_percent").val(discount);
1024  }
1025 
1026  <?php
1027  if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
1028  ?>
1029  var description = $('option:selected', this).attr('data-description');
1030  if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
1031 
1032  console.log("Load desciption into text area : "+description);
1033  <?php
1034  if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
1035  ?>
1036  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1037  {
1038  var editor = CKEDITOR.instances['dp_desc'];
1039  if (editor) {
1040  editor.setData(description);
1041  }
1042  }
1043  <?php
1044  } else {
1045  ?>
1046  jQuery('#dp_desc').text(description);
1047  <?php
1048  }
1049  }
1050  ?>
1051  } else if (jQuery('#idprodfournprice').length > 0) {
1052  console.log("objectline_create.tpl #idprodfournprice is not an int but is a string so we set only few properties into page");
1053 
1054  var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
1055  if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
1056 
1057  var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
1058  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
1059 
1060  var stringforvatrateselection = tva_tx;
1061  if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1062  stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1063  }
1064 
1065  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());
1066 
1067  // Set vat rate if field is an input box
1068  $('#tva_tx').val(tva_tx);
1069  // Set vat rate by selecting the combo
1070  //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1071  $('#tva_tx option').removeAttr('selected');
1072  console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1073  $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1074 
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("#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