dolibarr  9.0.0
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  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  *
24  * Need to have following variables defined:
25  * $object (invoice, order, ...)
26  * $conf
27  * $langs
28  * $dateSelector
29  * $forceall (0 by default, 1 for supplier invoices/orders)
30  * $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
31  * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
32  */
33 
34 // Protection to avoid direct call of template
35 if (empty($object) || ! is_object($object))
36 {
37  print "Error, template page can't be called as URL";
38  exit;
39 }
40 
41 
42 $usemargins=0;
43 if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande')))
44 {
45  $usemargins=1;
46 }
47 
48 if (! isset($dateSelector)) global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
49 global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
50 
51 if (! isset($dateSelector)) $dateSelector=1; // For backward compatibility
52 elseif (empty($dateSelector)) $dateSelector=0;
53 if (empty($forceall)) $forceall=0;
54 if (empty($senderissupplier)) $senderissupplier=0;
55 if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
56 
57 
58 // Define colspan for button Add
59 $colspan = 3; // Col total ht + col edit + col delete
60 if (in_array($object->element,array('propal','commande','order','facture','facturerec','invoice','supplier_proposal','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
61 //print $object->element;
62 
63 // Lines for extrafield
64 $objectline = null;
65 if (!empty($extrafieldsline))
66 {
67  if ($this->table_element_line=='commandedet') {
68  $objectline = new OrderLine($this->db);
69  }
70  elseif ($this->table_element_line=='propaldet') {
71  $objectline = new PropaleLigne($this->db);
72  }
73  elseif ($this->table_element_line=='supplier_proposaldet') {
74  $objectline = new SupplierProposalLine($this->db);
75  }
76  elseif ($this->table_element_line=='facturedet') {
77  $objectline = new FactureLigne($this->db);
78  }
79  elseif ($this->table_element_line=='contratdet') {
80  $objectline = new ContratLigne($this->db);
81  }
82  elseif ($this->table_element_line=='commande_fournisseurdet') {
83  $objectline = new CommandeFournisseurLigne($this->db);
84  }
85  elseif ($this->table_element_line=='facture_fourn_det') {
86  $objectline = new SupplierInvoiceLine($this->db);
87  }
88  elseif ($this->table_element_line=='facturedet_rec') {
89  $objectline = new FactureLigneRec($this->db);
90  }
91 }
92 
93 ?>
94 
95 <!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->
96 <?php
97 $nolinesbefore=(count($this->lines) == 0 || $forcetoshowtitlelines);
98 if ($nolinesbefore) {
99 ?>
100 <tr class="liste_titre<?php echo (($nolinesbefore || $object->element=='contrat')?'':' liste_titre_add_') ?> nodrag nodrop">
101  <?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
102  <td class="linecolnum" align="center"></td>
103  <?php } ?>
104  <td class="linecoldescription minwidth500imp">
105  <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span><?php // echo $langs->trans("FreeZone"); ?>
106  </td>
107  <?php
108  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
109  {
110  ?>
111  <td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
112  <?php } ?>
113  <td class="linecolvat" align="right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
114  <td class="linecoluht" align="right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
115  <?php if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { $colspan++;?>
116  <td class="linecoluht_currency" align="right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
117  <?php } ?>
118  <?php if (! empty($inputalsopricewithtax)) { ?>
119  <td class="linecoluttc" align="right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
120  <?php } ?>
121  <td class="linecolqty" align="right"><?php echo $langs->trans('Qty'); ?></td>
122  <?php
123  if($conf->global->PRODUCT_USE_UNITS)
124  {
125  print '<td class="linecoluseunit" align="left">';
126  print '<span id="title_units">';
127  print $langs->trans('Unit');
128  print '</span></td>';
129  }
130  ?>
131  <td class="linecoldiscount" align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
132  <?php
133  if ($this->situation_cycle_ref) {
134  print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
135  }
136  if (! empty($usemargins))
137  {
138  if (!empty($user->rights->margins->creer)) {
139  ?>
140  <td align="right" class="margininfos linecolmargin1">
141  <?php
142  }
143  else $colspan++;
144 
145  if ($conf->global->MARGIN_TYPE == "1")
146  echo $langs->trans('BuyingPrice');
147  else
148  echo $langs->trans('CostPrice');
149  ?>
150  </td>
151  <?php
152  if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
153  if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
154  }
155  ?>
156  <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
157 </tr>
158 <?php
159 }
160 ?>
161 <tr class="pair nodrag nodrop nohoverpair<?php echo ($nolinesbefore || $object->element=='contrat')?'':' liste_titre_create'; ?>">
162 <?php
163 // Adds a line numbering column
164 if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
165  $coldisplay=2;
166  ?>
167  <td class="nobottom linecolnum" align="center" width="5"></td>
168  <?php
169 }
170 else {
171  $coldisplay=0;
172 }
173 ?>
174 
175  <td class="nobottom linecoldescription minwidth500imp">
176 
177  <?php
178 
179  $freelines = false;
180  if (empty($conf->global->MAIN_DISABLE_FREE_LINES))
181  {
182  $freelines = true;
183  $forceall=1; // We always force all type for free lines (module product or service means we use predefined product or service)
184  if ($object->element == 'contrat')
185  {
186  if (empty($conf->product->enabled) && empty($conf->service->enabled) && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $forceall=-1; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
187  else $forceall=0;
188  }
189 
190  // Free line
191  echo '<span class="prod_entry_mode_free">';
192  // Show radio free line
193  if ($forceall >= 0 && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
194  {
195  echo '<label for="prod_entry_mode_free">';
196  echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
197  //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (empty($conf->product->enabled) || empty($conf->service->enabled)))?' checked':'') );
198  echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : '');
199  echo '> ';
200  // Show type selector
201  echo $langs->trans("FreeLineOfType");
202  echo '</label>';
203  echo ' ';
204  }
205  else
206  {
207  echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
208  // Show type selector
209  if ($forceall >= 0)
210  {
211  if (empty($conf->product->enabled) || empty($conf->service->enabled)) echo $langs->trans("Type");
212  else echo $langs->trans("FreeLineOfType");
213  echo ' ';
214  }
215  }
216 
217  echo $form->select_type_of_lines(isset($_POST["type"])?GETPOST("type",'alpha',2):-1,'type',1,1,$forceall);
218 
219  echo '</span>';
220  }
221 
222  // Predefined product/service
223  if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
224  {
225  if ($forceall >= 0 && $freelines) echo '<br>';
226  echo '<span class="prod_entry_mode_predef">';
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  if (empty($senderissupplier))
230  {
231  if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToSell');
232  else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToSell');
233  else echo $langs->trans('PredefinedProductsAndServicesToSell');
234  }
235  else
236  {
237  if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToPurchase');
238  else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToPurchase');
239  else echo $langs->trans('PredefinedProductsAndServicesToPurchase');
240  }
241  echo '</label>';
242  echo ' ';
243 
244  $filtertype='';
245  if (! empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $filtertype='1';
246 
247  if (empty($senderissupplier))
248  {
249  if (! empty($conf->global->ENTREPOT_EXTRA_STATUS))
250  {
251  // hide products in closed warehouse, but show products for internal transfer
252  $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth300', 0, 'warehouseopen,warehouseinternal', GETPOST('combinations', 'array'));
253  }
254  else
255  {
256  $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth300', 0, '', GETPOST('combinations', 'array'));
257  }
258  }
259  else
260  {
261  // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum
262  if ($senderissupplier != 2)
263  {
264  $ajaxoptions=array(
265  'update' => array('qty'=>'qty','remise_percent' => 'discount','idprod' => 'idprod'), // html id tags that will be edited with which ajax json response key
266  'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
267  'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for exemple shown we select a disabled option into combo)
268  );
269  $alsoproductwithnosupplierprice=0;
270  }
271  else
272  {
273  $ajaxoptions = array();
274  $alsoproductwithnosupplierprice=1;
275  }
276 
277  $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'maxwidth300');
278  }
279  echo '<input type="hidden" name="pbq" id="pbq" value="">';
280  echo '</span>';
281  }
282 
283  if (is_object($hookmanager) && empty($senderissupplier))
284  {
285  $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int'));
286  $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action);
287  if (!empty($hookmanager->resPrint)) {
288  print $hookmanager->resPrint;
289  }
290  }
291  if (is_object($hookmanager) && ! empty($senderissupplier))
292  {
293  $parameters=array('htmlname'=>'addproduct');
294  $reshook=$hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action);
295  if (!empty($hookmanager->resPrint)) {
296  print $hookmanager->resPrint;
297  }
298  }
299 
300 
301  if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) {
302 
303  if (!empty($conf->variants->enabled)) {
304  echo '<div id="attributes_box"></div>';
305  }
306 
307  echo '<br>';
308  }
309 
310  // Editor wysiwyg
311  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
312  $nbrows=ROWS_2;
313  $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
314  if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
315  $toolbarname='dolibarr_details';
316  if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes';
317  $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,$toolbarname,'',false,true,$enabled,$nbrows,'98%');
318  $doleditor->Create();
319 
320  // Show autofill date for recuring invoices
321  if (! empty($conf->service->enabled) && $object->element == 'facturerec')
322  {
323  echo '<div class="divlinefordates"><br>';
324  echo $langs->trans('AutoFillDateFrom').' ';
325  echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
326  echo ' - ';
327  echo $langs->trans('AutoFillDateTo').' ';
328  echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
329  echo '</div>';
330  }
331  ?>
332  </td>
333 
334  <?php
335  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
336  {
337  ?>
338  <td class="nobottom linecolresupplier"><input id="fourn_ref" name="fourn_ref" class="flat maxwidth75" value="<?php echo (isset($_POST["fourn_ref"])?GETPOST("fourn_ref",'alpha',2):''); ?>"></td>
339  <?php } ?>
340 
341  <td class="nobottom linecolvat" align="right"><?php
342  if ($seller->tva_assuj == "0") echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
343  else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?GETPOST("tva_tx",'alpha',2):-1), $seller, $buyer, 0, 0, '', false, 1);
344  ?>
345  </td>
346  <td class="nobottom linecoluht" align="right">
347  <input type="text" size="5" name="price_ht" id="price_ht" class="flat right" value="<?php echo (isset($_POST["price_ht"])?GETPOST("price_ht",'alpha',2):''); ?>">
348  </td>
349 
350  <?php if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { $colspan++;?>
351  <td class="nobottom linecoluht_currency" align="right">
352  <input type="text" size="5" name="multicurrency_price_ht" id="multicurrency_price_ht" class="flat right" value="<?php echo (isset($_POST["multicurrency_price_ht"])?GETPOST("multicurrency_price_ht",'alpha',2):''); ?>">
353  </td>
354  <?php } ?>
355 
356  <?php if (! empty($inputalsopricewithtax)) { ?>
357  <td class="nobottom linecoluttc" align="right">
358  <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat" value="<?php echo (isset($_POST["price_ttc"])?GETPOST("price_ttc",'alpha',2):''); ?>">
359  </td>
360  <?php } ?>
361  <td class="nobottom linecolqty" align="right"><input type="text" size="2" name="qty" id="qty" class="flat right" value="<?php echo (isset($_POST["qty"])?GETPOST("qty",'alpha',2):1); ?>">
362  </td>
363  <?php
364  if($conf->global->PRODUCT_USE_UNITS)
365  {
366  print '<td class="nobottom linecoluseunit" align="left">';
367  print $form->selectUnits($line->fk_unit, "units");
368  print '</td>';
369  }
370  $remise_percent = $buyer->remise_percent;
371  if($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
372  $remise_percent = $seller->remise_supplier_percent;
373  }
374  ?>
375  <td class="nobottom nowrap linecoldiscount" align="right"><input type="text" size="1" name="remise_percent" id="remise_percent" class="flat right" value="<?php echo (isset($_POST["remise_percent"])?GETPOST("remise_percent",'alpha',2):$remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
376  <?php
377  if ($this->situation_cycle_ref) {
378  $coldisplay++;
379  print '<td class="nobottom nowrap" align="right"><input class="falt right" type="text" size="1" value="0" name="progress">%</td>';
380  }
381  if (! empty($usemargins))
382  {
383  if (!empty($user->rights->margins->creer)) {
384  ?>
385  <td align="right" class="nobottom margininfos linecolmargin">
386  <!-- For predef product -->
387  <?php if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { ?>
388  <select id="fournprice_predef" name="fournprice_predef" class="flat" style="display: none;"></select>
389  <?php } ?>
390  <!-- For free product -->
391  <input type="text" size="5" id="buying_price" name="buying_price" class="flat right" value="<?php echo (isset($_POST["buying_price"])?GETPOST("buying_price",'alpha',2):''); ?>">
392  </td>
393  <?php
394  $coldisplay++;
395  }
396 
397  if ($user->rights->margins->creer)
398  {
399  if (! empty($conf->global->DISPLAY_MARGIN_RATES))
400  {
401  echo '<td align="right" class="nobottom nowrap margininfos"><input class="flat right" type="text" size="2" id="np_marginRate" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?GETPOST("np_marginRate",'alpha',2):'').'"><span class="np_marginRate hideonsmartphone">%</span></td>';
402  $coldisplay++;
403  }
404  if (! empty($conf->global->DISPLAY_MARK_RATES))
405  {
406  echo '<td align="right" class="nobottom nowrap margininfos"><input class="flat right" type="text" size="2" id="np_markRate" name="np_markRate" value="'.(isset($_POST["np_markRate"])?GETPOST("np_markRate",'alpha',2):'').'"><span class="np_markRate hideonsmartphone">%</span></td>';
407  $coldisplay++;
408  }
409  }
410  else
411  {
412  if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $coldisplay++;
413  if (! empty($conf->global->DISPLAY_MARK_RATES)) $coldisplay++;
414  }
415  }
416  ?>
417  <td class="nobottom linecoledit" align="center" valign="middle" colspan="<?php echo $colspan; ?>">
418  <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
419  </td>
420 </tr>
421 
422 <?php
423 if (is_object($objectline)) {
424  print $objectline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1);
425 }
426 ?>
427 
428 <?php
429 if ((! empty($conf->service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required
430 {
431  $colspan = 6;
432 
433  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
434  {
435  $colspan++;
436  }
437  if ($this->situation_cycle_ref) {
438  $colspan++;
439  }
440  // We add 1 if col total ttc
441  if (!empty($inputalsopricewithtax)) {
442  $colspan++;
443  }
444  if ($conf->global->PRODUCT_USE_UNITS) {
445  $colspan++;
446  }
447  if (count($object->lines)) {
448  //There will be an edit and a delete button
449  $colspan += 2;
450 
451  // With this, there is a column move button ONLY if lines > 1
452  if (in_array($object->element, array(
453  'propal',
454  'supplier_proposal',
455  'facture',
456  'facturerec',
457  'invoice',
458  'commande',
459  'order',
460  'order_supplier',
461  'invoice_supplier'
462  ))) {
463  $colspan++;
464  }
465  }
466 
467  if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan+=2;
468 
469  if (! empty($usemargins))
470  {
471  if (!empty($user->rights->margins->creer)) $colspan++; // For the buying price
472  if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
473  if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
474  }
475  ?>
476 
477  <tr id="trlinefordates" <?php echo $bcnd[$var]; ?>>
478  <?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print '<td></td>'; } ?>
479  <td colspan="<?php echo $colspan; ?>">
480  <?php
481  $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
482  $date_end=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
483  if (! empty($object->element) && $object->element == 'contrat')
484  {
485  print $langs->trans("DateStartPlanned").' ';
486  print $form->selectDate($date_start,"date_start",$usehm,$usehm,1,"addproduct");
487  print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
488  print $form->selectDate($date_end,"date_end",$usehm,$usehm,1,"addproduct");
489  }
490  else
491  {
492  echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
493  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);
494  echo ' '.$langs->trans('to').' ';
495  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);
496  };
497  print '<script type="text/javascript">';
498  if (!$date_start) {
499  if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
500  print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
501  }
502  if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
503  print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
504  }
505  }
506  if (!$date_end) {
507  if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
508  print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
509  }
510  if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
511  print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
512  }
513  }
514  print '</script>'
515  ?>
516  </td>
517  </tr>
518 <?php
519 }
520 ?>
521 
522 <script type="text/javascript">
523 
524 <?php
525 if (! empty($usemargins) && $user->rights->margins->creer)
526 {
527 ?>
528 
529  /* Some js test when we click on button "Add" */
530  jQuery(document).ready(function() {
531  <?php
532  if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
533  $("input[name='np_marginRate']:first").blur(function(e) {
534  return checkFreeLine(e, "np_marginRate");
535  });
536  <?php
537  }
538  if (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
539  $("input[name='np_markRate']:first").blur(function(e) {
540  return checkFreeLine(e, "np_markRate");
541  });
542  <?php
543  }
544  ?>
545  });
546 
547  /* TODO This does not work for number with thousand separator that is , */
548  function checkFreeLine(e, npRate)
549  {
550  var buying_price = $("input[name='buying_price']:first");
551  var remise = $("input[name='remise_percent']:first");
552 
553  var rate = $("input[name='"+npRate+"']:first");
554  if (rate.val() == '')
555  return true;
556 
557  if (! $.isNumeric(rate.val().replace(',','.')))
558  {
559  alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
560  e.stopPropagation();
561  setTimeout(function () { rate.focus() }, 50);
562  return false;
563  }
564  if (npRate == "np_markRate" && rate.val() >= 100)
565  {
566  alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
567  e.stopPropagation();
568  setTimeout(function () { rate.focus() }, 50);
569  return false;
570  }
571 
572  var price = 0;
573  remisejs=price2numjs(remise.val());
574 
575  if (remisejs != 100) // If a discount not 100 or no discount
576  {
577  if (remisejs == '') remisejs=0;
578 
579  bpjs=price2numjs(buying_price.val());
580  ratejs=price2numjs(rate.val());
581 
582  if (npRate == "np_marginRate")
583  price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
584  else if (npRate == "np_markRate")
585  price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
586  }
587  $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
588 
589  return true;
590  }
591 
592 <?php
593 }
594 ?>
595 
596 /* JQuery for product free or predefined select */
597 jQuery(document).ready(function() {
598  $("#prod_entry_mode_free").on( "click", function() {
599  setforfree();
600  });
601  $("#select_type").change(function()
602  {
603  setforfree();
604  if (jQuery('#select_type').val() >= 0)
605  {
606  /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
607  jQuery('#dp_desc').focus();
608  /* focus if CKEDITOR */
609  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
610  {
611  var editor = CKEDITOR.instances['dp_desc'];
612  if (editor) { editor.focus(); }
613  }
614  }
615  console.log("Hide/show date according to product type");
616  if (jQuery('#select_type').val() == '0')
617  {
618  jQuery('#trlinefordates').hide();
619  jQuery('.divlinefordates').hide();
620  }
621  else
622  {
623  jQuery('#trlinefordates').show();
624  jQuery('.divlinefordates').show();
625  }
626  });
627 
628  $("#prod_entry_mode_predef").on( "click", function() {
629  console.log("click prod_entry_mode_predef");
630  setforpredef();
631  jQuery('#trlinefordates').show();
632  });
633 
634  <?php
635  if(!$freelines) { ?>
636  $("#prod_entry_mode_predef").click();
637  <?php
638  }
639  ?>
640 
641  /* When changing predefined product, we reload list of supplier prices required for margin combo */
642  $("#idprod, #idprodfournprice").change(function()
643  {
644  console.log("#idprod, #idprodfournprice change triggered");
645 
646  setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
647 
648  jQuery('#trlinefordates').show();
649 
650  <?php
651  if (! empty($usemargins) && $user->rights->margins->creer)
652  {
653  $langs->load('stocks');
654  ?>
655 
656  /* Code for margin */
657  $("#fournprice_predef").find("option").remove();
658  $("#fournprice_predef").hide();
659  $("#buying_price").val("").show();
660  /* Call post to load content of combo list fournprice_predef */
661  $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val() }, function(data) {
662  if (data && data.length > 0)
663  {
664  var options = '';
665  var defaultkey = '';
666  var defaultprice = '';
667  var bestpricefound = 0;
668 
669  var bestpriceid = 0; var bestpricevalue = 0;
670  var pmppriceid = 0; var pmppricevalue = 0;
671  var costpriceid = 0; var costpricevalue = 0;
672 
673  /* setup of margin calculation */
674  var defaultbuyprice = '<?php
675  if (isset($conf->global->MARGIN_TYPE))
676  {
677  if ($conf->global->MARGIN_TYPE == '1') print 'bestsupplierprice';
678  if ($conf->global->MARGIN_TYPE == 'pmp') print 'pmp';
679  if ($conf->global->MARGIN_TYPE == 'costprice') print 'costprice';
680  } ?>';
681  console.log("we will set the field for margin. defaultbuyprice="+defaultbuyprice);
682 
683  var i = 0;
684  $(data).each(function() {
685  if (this.id != 'pmpprice' && this.id != 'costprice')
686  {
687  i++;
688  this.price = parseFloat(this.price); // to fix when this.price >0
689  // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
690  //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
691  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
692  }
693  if (this.id == 'pmpprice')
694  {
695  // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
696  //console.log("id="+this.id+"-price="+this.price);
697  if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
698  {
699  if (this.price > 0) {
700  defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
701  //console.log("pmppricevalue="+pmppricevalue);
702  }
703  }
704  }
705  if (this.id == 'costprice')
706  {
707  // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
708  //console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
709  if ('costprice' == defaultbuyprice)
710  {
711  if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
712  else if (pmppricevalue > 0) { defaultkey = pmppriceid; defaultprice = pmppricevalue; }
713  }
714  }
715  options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
716  });
717  options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
718 
719  console.log("finally selected defaultkey="+defaultkey+" defaultprice="+defaultprice);
720 
721  $("#fournprice_predef").html(options).show();
722  if (defaultkey != '')
723  {
724  $("#fournprice_predef").val(defaultkey);
725  }
726 
727  /* At loading, no product are yet selected, so we hide field of buying_price */
728  $("#buying_price").hide();
729 
730  /* Define default price at loading */
731  var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
732  $("#buying_price").val(defaultprice);
733 
734  $("#fournprice_predef").change(function() {
735  console.log("change on fournprice_predef");
736  /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
737  var linevalue=$(this).find('option:selected').val();
738  var pricevalue = $(this).find('option:selected').attr("price");
739  if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
740  $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
741  }
742  if (linevalue == 'inputprice') {
743  $('#buying_price').show();
744  }
745  if (linevalue == 'pmpprice') {
746  $("#buying_price").val(pricevalue);
747  $('#buying_price').hide();
748  }
749  });
750  }
751  },
752  'json');
753 
754  <?php
755  }
756  ?>
757 
758  /* To process customer price per quantity */
759  var pbq = parseInt($('option:selected', this).attr('data-pbq'));
760  var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
761  var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
762 
763  if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && typeof pbq !== "undefined")
764  {
765  console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
766  jQuery("#pbq").val(pbq);
767  if (jQuery("#qty").val() < pbqqty)
768  {
769  jQuery("#qty").val(pbqqty);
770  }
771  if (jQuery("#remise_percent").val() < pbqpercent)
772  {
773  jQuery("#remise_percent").val(pbqpercent);
774  }
775  }
776  else
777  {
778  jQuery("#pbq").val('');
779  }
780 
781  /* To set focus */
782  if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
783  {
784  /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
785  jQuery('#dp_desc').focus();
786  /* focus if CKEDITOR */
787  if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
788  {
789  var editor = CKEDITOR.instances['dp_desc'];
790  if (editor) { editor.focus(); }
791  }
792  }
793  });
794 
795  <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
796  setforpredef();
797  <?php } ?>
798 
799 });
800 
801 /* Function to set fields from choice */
802 function setforfree() {
803  console.log("Call setforfree. We show most fields");
804  jQuery("#search_idprod").val('');
805  jQuery("#idprod").val('');
806  jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
807  jQuery("#search_idprodfournprice").val('');
808  jQuery("#prod_entry_mode_free").prop('checked',true).change();
809  jQuery("#prod_entry_mode_predef").prop('checked',false).change();
810  jQuery("#price_ht").show();
811  jQuery("#multicurrency_price_ht").show();
812  jQuery("#price_ttc").show(); // May no exists
813  jQuery("#fourn_ref").show();
814  jQuery("#tva_tx").show();
815  jQuery("#buying_price").val('').show();
816  jQuery("#fournprice_predef").hide();
817  jQuery("#title_vat").show();
818  jQuery("#title_up_ht").show();
819  jQuery("#title_up_ht_currency").show();
820  jQuery("#title_up_ttc").show();
821  jQuery("#title_up_ttc_currency").show();
822  jQuery("#np_marginRate").show(); // May no exists
823  jQuery("#np_markRate").show(); // May no exists
824  jQuery(".np_marginRate").show(); // May no exists
825  jQuery(".np_markRate").show(); // May no exists
826  jQuery("#units, #title_units").show();
827 }
828 function setforpredef() {
829  console.log("Call setforpredef. We hide some fields and show dates");
830  jQuery("#select_type").val(-1);
831 
832  jQuery("#prod_entry_mode_free").prop('checked',false).change();
833  jQuery("#prod_entry_mode_predef").prop('checked',true).change();
834  jQuery("#price_ht").val('').hide();
835  jQuery("#multicurrency_price_ht").hide();
836  jQuery("#price_ttc").hide(); // May no exists
837  jQuery("#fourn_ref").hide();
838  jQuery("#tva_tx").hide();
839  jQuery("#buying_price").show();
840  jQuery("#title_vat").hide();
841  jQuery("#title_up_ht").hide();
842  jQuery("#title_up_ht_currency").hide();
843  jQuery("#title_up_ttc").hide();
844  jQuery("#title_up_ttc_currency").hide();
845  jQuery("#np_marginRate").hide(); // May no exists
846  jQuery("#np_markRate").hide(); // May no exists
847  jQuery(".np_marginRate").hide(); // May no exists
848  jQuery(".np_markRate").hide(); // May no exists
849  jQuery("#units, #title_units").hide();
850 
851  jQuery('#trlinefordates').show();
852  jQuery('.divlinefordates').show();
853 }
854 
855 </script>
856 
857 <!-- END PHP TEMPLATE objectline_create.tpl.php -->
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
Class to manage invoice lines of templates.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage line invoices.
Classe permettant la gestion des lignes de contrats.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Class to manage order lines.
price2numjs(amount)
Function similar to PHP price2num()
type
Definition: viewcat.php:284
Class to manage commercial proposal lines.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
Class to manage supplier_proposal lines.
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...
Class to manage a WYSIWYG editor.
Class to manage invoice lines.
Class to manage line orders.