dolibarr  9.0.0
objectline_edit.tpl.php
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
5  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
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  * $seller, $buyer
28  * $dateSelector
29  * $forceall (0 by default, 1 for supplier invoices/orders)
30  * $senderissupplier (0 by default, 1 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'))) $usemargins=1;
44 
45 global $forceall, $senderissupplier, $inputalsopricewithtax;
46 if (empty($dateSelector)) $dateSelector=0;
47 if (empty($forceall)) $forceall=0;
48 if (empty($senderissupplier)) $senderissupplier=0;
49 if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
50 
51 
52 // Define colspan for button Add
53 $colspan = 3; // Col total ht + col edit + col delete
54 if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
55 if (in_array($object->element,array('propal','supplier_proposal','facture','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
56 if (empty($user->rights->margins->creer)) $colspan++;
57 if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan+=2;
58 ?>
59 
60 <!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
61 
62 <?php
63 $coldisplay=-1; // We remove first td
64 ?>
65 <tr <?php echo $bc[$var]; ?>>
66  <?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
67  <td class="linecolnum" align="center"><?php $coldisplay++; ?><?php echo ($i+1); ?></td>
68  <?php } ?>
69  <td>
70  <div id="line_<?php echo $line->id; ?>"></div>
71 
72  <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
73  <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
74  <input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
75  <input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
76 
77  <?php if ($line->fk_product > 0) { ?>
78 
79  <a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
80  <?php
81  if ($line->product_type==1) echo img_object($langs->trans('ShowService'),'service');
82  else print img_object($langs->trans('ShowProduct'),'product');
83  echo ' '.$line->ref;
84  ?>
85  </a>
86  <?php
87  echo ' - '.nl2br($line->product_label);
88  ?>
89 
90  <br><br>
91 
92  <?php } ?>
93 
94  <?php
95  if (is_object($hookmanager))
96  {
97  $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line') : $line->fk_parent_line);
98  $parameters=array('line'=>$line,'fk_parent_line'=>$fk_parent_line,'var'=>$var,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer);
99  $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$this,$action);
100  }
101 
102  // Do not allow editing during a situation cycle
103  if ($line->fk_prev_id == null )
104  {
105  // editeur wysiwyg
106  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
107  $nbrows=ROWS_2;
108  if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
109  $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
110  $toolbarname='dolibarr_details';
111  if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes';
112  $doleditor=new DolEditor('product_desc',$line->description,'',164,$toolbarname,'',false,true,$enable,$nbrows,'98%');
113  $doleditor->Create();
114  } else {
115  print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">' . $line->description . '</textarea>';
116  }
117 
118  // Show autofill date for recuring invoices
119  if (! empty($conf->service->enabled) && $line->product_type == 1 && $line->element == 'facturedetrec')
120  {
121  echo '<br>';
122  echo $langs->trans('AutoFillDateFrom').' ';
123  echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
124  echo ' - ';
125  echo $langs->trans('AutoFillDateTo').' ';
126  echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
127  }
128 
129  ?>
130  </td>
131 
132  <?php
133  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
134  {
135  ?>
136  <td align="right"><input id="fourn_ref" name="fourn_ref" class="flat minwidth75" value="<?php echo ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn); ?>"></td>
137  <?php
138  }
139 
140  $coldisplay++;
141  if ($line->fk_prev_id == null ) {
142  print '<td align="right">' . $form->load_tva('tva_tx', $line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1) . '</td>';
143  } else {
144  print '<td align="right"><input size="1" type="text" class="flat right" name="tva_tx" value="' . price($line->tva_tx) . '" readonly />%</td>';
145  }
146 
147  $coldisplay++;
148  print '<td align="right"><input type="text" class="flat right" size="5" id="price_ht" name="price_ht" value="' . (isset($line->pu_ht)?price($line->pu_ht,0,'',0):price($line->subprice,0,'',0)) . '"';
149  if ($line->fk_prev_id != null ) print ' readonly';
150  print '></td>';
151 
152  if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
153  print '<td align="right"><input rel="'.$object->multicurrency_tx.'" type="text" class="flat right" size="5" id="multicurrency_subprice" name="multicurrency_subprice" value="'.price($line->multicurrency_subprice).'" /></td>';
154  }
155 
156  if ($inputalsopricewithtax)
157  {
158  $coldisplay++;
159  print '<td align="right"><input type="text" class="flat right" size="5" id="price_ttc" name="price_ttc" value="'.(isset($line->pu_ttc)?price($line->pu_ttc,0,'',0):'').'"';
160  if ($line->fk_prev_id != null ) print ' readonly';
161  print '></td>';
162  }
163  ?>
164  <td align="right"><?php $coldisplay++; ?>
165  <?php if (($line->info_bits & 2) != 2) {
166  // I comment this because it shows info even when not required
167  // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
168  // must also not be output for most entities (proposal, intervention, ...)
169  //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
170  print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="' . $line->qty . '"';
171  if ($line->fk_prev_id != null ) print ' readonly';
172  print '>';
173  } else { ?>
174  &nbsp;
175  <?php } ?>
176  </td>
177 
178  <?php
179  if($conf->global->PRODUCT_USE_UNITS)
180  {
181  print '<td align="left">';
182  print $form->selectUnits($line->fk_unit, "units");
183  print '</td>';
184  }
185  ?>
186 
187  <td align="right" class="nowrap"><?php $coldisplay++; ?>
188  <?php if (($line->info_bits & 2) != 2) {
189  print '<input size="1" type="text" class="flat right" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '"';
190  if ($line->fk_prev_id != null ) print ' readonly';
191  print '>%';
192  } else { ?>
193  &nbsp;
194  <?php } ?>
195  </td>
196  <?php
197  if ($this->situation_cycle_ref) {
198  $coldisplay++;
199  print '<td align="right" class="nowrap"><input class="right" type="text" size="1" value="' . $line->situation_percent . '" name="progress">%</td>';
200  }
201  if (! empty($usemargins))
202  {
203  ?>
204  <?php if (!empty($user->rights->margins->creer)) { ?>
205  <td align="right" class="margininfos"><?php $coldisplay++; ?>
206  <!-- For predef product -->
207  <?php if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { ?>
208  <select id="fournprice_predef" name="fournprice_predef" class="flat right" style="display: none;"></select>
209  <?php } ?>
210  <!-- For free product -->
211  <input class="flat right" type="text" size="5" id="buying_price" name="buying_price" class="hideobject" value="<?php echo price($line->pa_ht,0,'',0); ?>">
212  </td>
213  <?php } ?>
214  <?php if ($user->rights->margins->creer) {
215  if (! empty($conf->global->DISPLAY_MARGIN_RATES))
216  {
217  $margin_rate = (isset($_POST["np_marginRate"])?GETPOST("np_marginRate","alpha",2):(($line->pa_ht == 0)?'':price($line->marge_tx)));
218  // if credit note, dont allow to modify margin
219  if ($line->subprice < 0)
220  echo '<td align="right" class="nowrap margininfos">'.$margin_rate.'<span class="hideonsmartphone">%</span></td>';
221  else
222  echo '<td align="right" class="nowrap margininfos"><input class="right" type="text" size="2" name="np_marginRate" value="'.$margin_rate.'"><span class="hideonsmartphone">%</span></td>';
223  $coldisplay++;
224  }
225  elseif (! empty($conf->global->DISPLAY_MARK_RATES))
226  {
227  $mark_rate = (isset($_POST["np_markRate"])?GETPOST("np_markRate",'alpha',2):price($line->marque_tx));
228  // if credit note, dont allow to modify margin
229  if ($line->subprice < 0)
230  echo '<td align="right" class="nowrap margininfos">'.$mark_rate.'<span class="hideonsmartphone">%</span></td>';
231  else
232  echo '<td align="right" class="nowrap margininfos"><input class="right" type="text" size="2" name="np_markRate" value="'.$mark_rate.'"><span class="hideonsmartphone">%</span></td>';
233  $coldisplay++;
234  }
235  }
236  }
237  ?>
238 
239  <!-- colspan=4 for this td because it replace total_ht+3 td for buttons -->
240  <td align="center" colspan="<?php echo $colspan; ?>" valign="middle"><?php $coldisplay+=4; ?>
241  <input type="submit" class="button" id="savelinebutton" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
242  <input type="submit" class="button" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
243  </td>
244 </tr>
245 
246 <?php
247 //Line extrafield
248 if (!empty($extrafieldsline))
249 {
250  print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var],'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1);
251 }
252 ?>
253 
254 <?php if (! empty($conf->service->enabled) && $line->product_type == 1 && $dateSelector) { ?>
255 <tr id="service_duration_area" <?php echo $bc[$var]; ?>>
256  <?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
257  <td class="linecolnum" align="center"><?php $coldisplay++; ?></td>
258  <?php } ?>
259  <td colspan="<?php echo 7+$colspan ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
260  <?php
261  $hourmin=(isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:'');
262  print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start?0:1, "updateline", 1, 0);
263  print ' '.$langs->trans('to').' ';
264  print $form->selectDate($line->date_end, 'date_end', $hourmin, $hourmin, $line->date_end?0:1, "updateline", 1, 0);
265  print '<script type="text/javascript">';
266  if (!$line->date_start) {
267  if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
268  print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
269  }
270  if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
271  print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
272  }
273  }
274  if (!$line->date_end) {
275  if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
276  print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
277  }
278  if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
279  print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
280  }
281  }
282  print '</script>'
283  ?>
284  </td>
285 </tr>
286 <?php }
287 ?>
288 
289 
290 <script type="text/javascript">
291 
292 jQuery(document).ready(function()
293 {
294  jQuery("#price_ht").keyup(function(event) {
295  // console.log(event.which); // discard event tag and arrows
296  if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
297  jQuery("#price_ttc").val('');
298  jQuery("#multicurrency_subprice").val('');
299  }
300  });
301  jQuery("#price_ttc").keyup(function(event) {
302  // console.log(event.which); // discard event tag and arrows
303  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
304  jQuery("#price_ht").val('');
305  jQuery("#multicurrency_subprice").val('');
306  }
307  });
308  jQuery("#multicurrency_subprice").keyup(function(event) {
309  // console.log(event.which); // discard event tag and arrows
310  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
311  jQuery("#price_ht").val('');
312  jQuery("#price_ttc").val('');
313  }
314  });
315 
316  <?php
317  if (! empty($conf->margin->enabled))
318  {
319  ?>
320  /* Add rule to clear margin when we change some data, so when we change sell or buy price, margin will be recalculated after submitting form */
321  jQuery("#tva_tx").click(function() { /* somtimes field is a text, sometimes a combo */
322  jQuery("input[name='np_marginRate']:first").val('');
323  jQuery("input[name='np_markRate']:first").val('');
324  });
325  jQuery("#tva_tx").keyup(function() { /* somtimes field is a text, sometimes a combo */
326  jQuery("input[name='np_marginRate']:first").val('');
327  jQuery("input[name='np_markRate']:first").val('');
328  });
329  jQuery("#price_ht").keyup(function() {
330  jQuery("input[name='np_marginRate']:first").val('');
331  jQuery("input[name='np_markRate']:first").val('');
332  });
333  jQuery("#qty").keyup(function() {
334  jQuery("input[name='np_marginRate']:first").val('');
335  jQuery("input[name='np_markRate']:first").val('');
336  });
337  jQuery("#remise_percent").keyup(function() {
338  jQuery("input[name='np_marginRate']:first").val('');
339  jQuery("input[name='np_markRate']:first").val('');
340  });
341  jQuery("#buying_price").keyup(function() {
342  jQuery("input[name='np_marginRate']:first").val('');
343  jQuery("input[name='np_markRate']:first").val('');
344  });
345 
346  /* Init field buying_price and fournprice */
347  $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
348  if (data && data.length > 0) {
349  var options = '';
350  var trouve=false;
351  $(data).each(function() {
352  options += '<option value="'+this.id+'" price="'+this.price+'"';
353  <?php if ($line->fk_fournprice > 0) { ?>
354  if (this.id == <?php echo $line->fk_fournprice; ?>) {
355  options += ' selected';
356  $("#buying_price").val(this.price);
357  trouve = true;
358  }
359  <?php } ?>
360  options += '>'+this.label+'</option>';
361  });
362  options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
363  $("#fournprice").html(options);
364  if (trouve) {
365  $("#buying_price").hide();
366  $("#fournprice").show();
367  } else {
368  $("#buying_price").show();
369  }
370  $("#fournprice").change(function() {
371  var selval = $(this).find('option:selected').attr("price");
372  if (selval)
373  $("#buying_price").val(selval).hide();
374  else
375  $('#buying_price').show();
376  });
377  } else {
378  $("#fournprice").hide();
379  $('#buying_price').show();
380  }
381  }, 'json');
382  <?php
383  }
384  ?>
385 });
386 
387 </script>
388 <!-- END PHP TEMPLATE objectline_edit.tpl.php -->
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
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
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
type
Definition: viewcat.php:284
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)