objectline_edit.tpl.php 16 KB

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