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