dolibarr  7.0.0-beta
objectline_edit.tpl.php
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * Need to have following variables defined:
23  * $object (invoice, order, ...)
24  * $conf
25  * $langs
26  * $seller, $buyer
27  * $dateSelector
28  * $forceall (0 by default, 1 for supplier invoices/orders)
29  * $senderissupplier (0 by default, 1 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'))) $usemargins=1;
43 
44 global $forceall, $senderissupplier, $inputalsopricewithtax;
45 if (empty($dateSelector)) $dateSelector=0;
46 if (empty($forceall)) $forceall=0;
47 if (empty($senderissupplier)) $senderissupplier=0;
48 if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
49 
50 
51 // Define colspan for button Add
52 $colspan = 3; // Col total ht + col edit + col delete
53 if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
54 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
55 if (empty($user->rights->margins->creer)) $colspan++;
56 if (!empty($conf->multicurrency->enabled)) $colspan+=2;
57 ?>
58 
59 <!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
60 
61 <?php
62 $coldisplay=-1; // We remove first td
63 ?>
64 <tr <?php echo $bc[$var]; ?>>
65  <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>><?php $coldisplay+=(! empty($conf->global->MAIN_VIEW_LINE_NUMBER))?2:1; ?>
66  <div id="line_<?php echo $line->id; ?>"></div>
67 
68  <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
69  <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
70  <input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
71  <input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
72 
73  <?php if ($line->fk_product > 0) { ?>
74 
75  <a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
76  <?php
77  if ($line->product_type==1) echo img_object($langs->trans('ShowService'),'service');
78  else print img_object($langs->trans('ShowProduct'),'product');
79  echo ' '.$line->ref;
80  ?>
81  </a>
82  <?php
83  echo ' - '.nl2br($line->product_label);
84  ?>
85 
86  <br>
87 
88  <?php } ?>
89 
90  <?php
91  if (is_object($hookmanager))
92  {
93  $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line') : $line->fk_parent_line);
94  $parameters=array('line'=>$line,'fk_parent_line'=>$fk_parent_line,'var'=>$var,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer);
95  $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$this,$action);
96  }
97 
98  // Do not allow editing during a situation cycle
99  if (empty($this->situation_cycle_ref) || $this->situation_counter == 1)
100  {
101  // editeur wysiwyg
102  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
103  $nbrows=ROWS_2;
104  if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
105  $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
106  $toolbarname='dolibarr_details';
107  if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes';
108  $doleditor=new DolEditor('product_desc',$line->description,'',164,$toolbarname,'',false,true,$enable,$nbrows,'98%');
109  $doleditor->Create();
110  } else {
111  print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">' . $line->description . '</textarea>';
112  }
113  ?>
114  </td>
115 
116  <?php
117  if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
118  {
119  ?>
120  <td align="right"><input id="fourn_ref" name="fourn_ref" class="flat" value="<?php echo $line->ref_fourn; ?>" size="12"></td>
121  <?php
122  }
123 
124  $coldisplay++;
125  if ($this->situation_counter == 1 || !$this->situation_cycle_ref) {
126  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>';
127  } else {
128  print '<td align="right"><input size="1" type="text" class="flat right" name="tva_tx" value="' . price($line->tva_tx) . '" readonly />%</td>';
129  }
130 
131  $coldisplay++;
132  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)) . '"';
133  if ($this->situation_counter > 1) print ' readonly';
134  print '></td>';
135 
136  if (!empty($conf->multicurrency->enabled)) {
137  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>';
138  }
139 
140  if ($inputalsopricewithtax)
141  {
142  $coldisplay++;
143  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):'').'"';
144  if ($this->situation_counter > 1) print ' readonly';
145  print '></td>';
146  }
147  ?>
148  <td align="right"><?php $coldisplay++; ?>
149  <?php if (($line->info_bits & 2) != 2) {
150  // I comment this because it shows info even when not required
151  // 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
152  // must also not be output for most entities (proposal, intervention, ...)
153  //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
154  print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="' . $line->qty . '"';
155  if ($this->situation_counter > 1) print ' readonly';
156  print '>';
157  } else { ?>
158  &nbsp;
159  <?php } ?>
160  </td>
161 
162  <?php
163  if($conf->global->PRODUCT_USE_UNITS)
164  {
165  print '<td align="left">';
166  print $form->selectUnits($line->fk_unit, "units");
167  print '</td>';
168  }
169  ?>
170 
171  <td align="right" class="nowrap"><?php $coldisplay++; ?>
172  <?php if (($line->info_bits & 2) != 2) {
173  print '<input size="1" type="text" class="flat right" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '"';
174  if ($this->situation_counter > 1) print ' readonly';
175  print '>%';
176  } else { ?>
177  &nbsp;
178  <?php } ?>
179  </td>
180  <?php
181  if ($this->situation_cycle_ref) {
182  $coldisplay++;
183  print '<td align="right" class="nowrap"><input class="right" type="text" size="1" value="' . $line->situation_percent . '" name="progress">%</td>';
184  }
185  if (! empty($usemargins))
186  {
187  ?>
188  <?php if (!empty($user->rights->margins->creer)) { ?>
189  <td align="right" class="margininfos"><?php $coldisplay++; ?>
190  <!-- For predef product -->
191  <?php if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { ?>
192  <select id="fournprice_predef" name="fournprice_predef" class="flat right" style="display: none;"></select>
193  <?php } ?>
194  <!-- For free product -->
195  <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); ?>">
196  </td>
197  <?php } ?>
198  <?php if ($user->rights->margins->creer) {
199  if (! empty($conf->global->DISPLAY_MARGIN_RATES))
200  {
201  $margin_rate = (isset($_POST["np_marginRate"])?GETPOST("np_marginRate","alpha",2):(($line->pa_ht == 0)?'':price($line->marge_tx)));
202  // if credit note, dont allow to modify margin
203  if ($line->subprice < 0)
204  echo '<td align="right" class="nowrap margininfos">'.$margin_rate.'<span class="hideonsmartphone">%</span></td>';
205  else
206  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>';
207  $coldisplay++;
208  }
209  elseif (! empty($conf->global->DISPLAY_MARK_RATES))
210  {
211  $mark_rate = (isset($_POST["np_markRate"])?GETPOST("np_markRate",'alpha',2):price($line->marque_tx));
212  // if credit note, dont allow to modify margin
213  if ($line->subprice < 0)
214  echo '<td align="right" class="nowrap margininfos">'.$mark_rate.'<span class="hideonsmartphone">%</span></td>';
215  else
216  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>';
217  $coldisplay++;
218  }
219  }
220  }
221  ?>
222 
223  <!-- colspan=4 for this td because it replace total_ht+3 td for buttons -->
224  <td align="center" colspan="<?php echo $colspan; ?>" valign="middle"><?php $coldisplay+=4; ?>
225  <input type="submit" class="button" id="savelinebutton" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
226  <input type="submit" class="button" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
227  </td>
228 
229  <?php
230  //Line extrafield
231  if (!empty($extrafieldsline))
232  {
233  print $line->showOptionals($extrafieldsline,'edit',array('style'=>$bc[$var],'colspan'=>$coldisplay));
234  }
235  ?>
236 </tr>
237 
238 <?php if (! empty($conf->service->enabled) && $line->product_type == 1 && $dateSelector) { ?>
239 <tr id="service_duration_area" <?php echo $bc[$var]; ?>>
240  <td colspan="<?php echo 7+$colspan ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
241  <?php
242  $hourmin=(isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:'');
243  echo $form->select_date($line->date_start,'date_start',$hourmin,$hourmin,$line->date_start?0:1,"updateligne",1,0,1);
244  echo ' '.$langs->trans('to').' ';
245  echo $form->select_date($line->date_end,'date_end',$hourmin,$hourmin,$line->date_end?0:1,"updateligne",1,0,1);
246  print '<script type="text/javascript">';
247  if (!$line->date_start) {
248  if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
249  print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
250  }
251  if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
252  print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
253  }
254  }
255  if (!$line->date_end) {
256  if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
257  print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
258  }
259  if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
260  print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
261  }
262  }
263  print '</script>'
264  ?>
265  </td>
266 </tr>
267 <?php } ?>
268 
269 
270 <script type="text/javascript">
271 
272 jQuery(document).ready(function()
273 {
274  jQuery("#price_ht").keyup(function(event) {
275  // console.log(event.which); // discard event tag and arrows
276  if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
277  jQuery("#price_ttc").val('');
278  jQuery("#multicurrency_subprice").val('');
279  }
280  });
281  jQuery("#price_ttc").keyup(function(event) {
282  // console.log(event.which); // discard event tag and arrows
283  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
284  jQuery("#price_ht").val('');
285  jQuery("#multicurrency_subprice").val('');
286  }
287  });
288  jQuery("#multicurrency_subprice").keyup(function(event) {
289  // console.log(event.which); // discard event tag and arrows
290  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
291  jQuery("#price_ht").val('');
292  jQuery("#price_ttc").val('');
293  }
294  });
295 
296  <?php
297  if (! empty($conf->margin->enabled))
298  {
299  ?>
300  /* 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 */
301  jQuery("#tva_tx").click(function() { /* somtimes field is a text, sometimes a combo */
302  jQuery("input[name='np_marginRate']:first").val('');
303  jQuery("input[name='np_markRate']:first").val('');
304  });
305  jQuery("#tva_tx").keyup(function() { /* somtimes field is a text, sometimes a combo */
306  jQuery("input[name='np_marginRate']:first").val('');
307  jQuery("input[name='np_markRate']:first").val('');
308  });
309  jQuery("#price_ht").keyup(function() {
310  jQuery("input[name='np_marginRate']:first").val('');
311  jQuery("input[name='np_markRate']:first").val('');
312  });
313  jQuery("#qty").keyup(function() {
314  jQuery("input[name='np_marginRate']:first").val('');
315  jQuery("input[name='np_markRate']:first").val('');
316  });
317  jQuery("#remise_percent").keyup(function() {
318  jQuery("input[name='np_marginRate']:first").val('');
319  jQuery("input[name='np_markRate']:first").val('');
320  });
321  jQuery("#buying_price").keyup(function() {
322  jQuery("input[name='np_marginRate']:first").val('');
323  jQuery("input[name='np_markRate']:first").val('');
324  });
325 
326  /* Init field buying_price and fournprice */
327  $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
328  if (data && data.length > 0) {
329  var options = '';
330  var trouve=false;
331  $(data).each(function() {
332  options += '<option value="'+this.id+'" price="'+this.price+'"';
333  <?php if ($line->fk_fournprice > 0) { ?>
334  if (this.id == <?php echo $line->fk_fournprice; ?>) {
335  options += ' selected';
336  $("#buying_price").val(this.price);
337  trouve = true;
338  }
339  <?php } ?>
340  options += '>'+this.label+'</option>';
341  });
342  options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
343  $("#fournprice").html(options);
344  if (trouve) {
345  $("#buying_price").hide();
346  $("#fournprice").show();
347  } else {
348  $("#buying_price").show();
349  }
350  $("#fournprice").change(function() {
351  var selval = $(this).find('option:selected').attr("price");
352  if (selval)
353  $("#buying_price").val(selval).hide();
354  else
355  $('#buying_price').show();
356  });
357  } else {
358  $("#fournprice").hide();
359  $('#buying_price').show();
360  }
361  }, 'json');
362  <?php
363  }
364  ?>
365 });
366 
367 </script>
368 <!-- END PHP TEMPLATE objectline_edit.tpl.php -->
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
$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