objectline_edit.tpl.php 16 KB

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