objectline_edit.tpl.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2010-2022 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. * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. *
  24. * Need to have following variables defined:
  25. * $object (invoice, order, ...)
  26. * $conf
  27. * $langs
  28. * $seller, $buyer
  29. * $dateSelector
  30. * $forceall (0 by default, 1 for supplier invoices/orders)
  31. * $senderissupplier (0 by default, 1 for supplier invoices/orders)
  32. * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
  33. * $canchangeproduct (0 by default, 1 to allow to change the product if it is a predefined product)
  34. */
  35. // Protection to avoid direct call of template
  36. if (empty($object) || !is_object($object)) {
  37. print "Error, template page can't be called as URL";
  38. exit;
  39. }
  40. $usemargins = 0;
  41. if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
  42. $usemargins = 1;
  43. }
  44. global $forceall, $senderissupplier, $inputalsopricewithtax, $canchangeproduct;
  45. if (empty($dateSelector)) {
  46. $dateSelector = 0;
  47. }
  48. if (empty($forceall)) {
  49. $forceall = 0;
  50. }
  51. if (empty($senderissupplier)) {
  52. $senderissupplier = 0;
  53. }
  54. if (empty($inputalsopricewithtax)) {
  55. $inputalsopricewithtax = 0;
  56. }
  57. if (empty($canchangeproduct)) {
  58. $canchangeproduct = 0;
  59. }
  60. // Define colspan for the button 'Add'
  61. $colspan = 3; // Col total ht + col edit + col delete
  62. if (!empty($inputalsopricewithtax)) {
  63. $colspan++; // We add 1 if col total ttc
  64. }
  65. if (in_array($object->element, array('propal', 'supplier_proposal', 'facture', 'facturerec', 'invoice', 'commande', 'order', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
  66. $colspan++; // With this, there is a column move button
  67. }
  68. if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
  69. $colspan += 2;
  70. }
  71. if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
  72. $colspan++;
  73. }
  74. print "<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->\n";
  75. $coldisplay = 0;
  76. ?>
  77. <tr class="oddeven tredited">
  78. <?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
  79. <td class="linecolnum center"><?php $coldisplay++; ?><?php echo ($i + 1); ?></td>
  80. <?php }
  81. $coldisplay++;
  82. ?>
  83. <td class="linecoldesc minwidth250onall">
  84. <div id="line_<?php echo $line->id; ?>"></div>
  85. <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
  86. <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
  87. <input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
  88. <input type="hidden" id="fk_parent_line" name="fk_parent_line" value="<?php echo $line->fk_parent_line; ?>">
  89. <?php if ($line->fk_product > 0) { ?>
  90. <?php
  91. if (empty($canchangeproduct)) {
  92. if ($line->fk_parent_line > 0) {
  93. echo img_picto('', 'rightarrow');
  94. }
  95. ?>
  96. <a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
  97. <?php
  98. if ($line->product_type == 1) {
  99. echo img_object($langs->trans('ShowService'), 'service');
  100. } else {
  101. print img_object($langs->trans('ShowProduct'), 'product');
  102. }
  103. echo ' '.$line->ref;
  104. ?>
  105. </a>
  106. <?php
  107. echo ' - '.nl2br($line->product_label);
  108. print '<input type="hidden" id="product_id" name="productid" value="'.(!empty($line->fk_product) ? $line->fk_product : 0).'">';
  109. } else {
  110. if ($senderissupplier) {
  111. $form->select_produits_fournisseurs(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
  112. } else {
  113. print $form->select_produits(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
  114. }
  115. }
  116. ?>
  117. <br><br>
  118. <?php } ?>
  119. <?php
  120. if (is_object($hookmanager)) {
  121. $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line', 'int') : $line->fk_parent_line);
  122. $parameters = array('line'=>$line, 'fk_parent_line'=>$fk_parent_line, 'var'=>$var, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer);
  123. $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action);
  124. }
  125. $situationinvoicelinewithparent = 0;
  126. if ($line->fk_prev_id != null && in_array($object->element, array('facture', 'facturedet'))) {
  127. if ($object->type == $object::TYPE_SITUATION) { // The constant TYPE_SITUATION exists only for object invoice
  128. // Set constant to disallow editing during a situation cycle
  129. $situationinvoicelinewithparent = 1;
  130. }
  131. }
  132. // Do not allow editing during a situation cycle
  133. if (!$situationinvoicelinewithparent) {
  134. // editor wysiwyg
  135. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  136. $nbrows = ROWS_2;
  137. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
  138. $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  139. }
  140. $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
  141. $toolbarname = 'dolibarr_details';
  142. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
  143. $toolbarname = 'dolibarr_notes';
  144. }
  145. $doleditor = new DolEditor('product_desc', GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description, '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 164 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enable, $nbrows, '98%');
  146. $doleditor->Create();
  147. } else {
  148. print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">';
  149. print GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description;
  150. print '</textarea>';
  151. }
  152. //Line extrafield
  153. if (!empty($extrafields)) {
  154. $temps = $line->showOptionals($extrafields, 'edit', array('class'=>'tredited'), '', '', 1, 'line');
  155. if (!empty($temps)) {
  156. print '<div style="padding-top: 10px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
  157. print $temps;
  158. print '</div>';
  159. }
  160. }
  161. // Show autofill date for recuring invoices
  162. if (isModEnabled("service") && $line->product_type == 1 && ($line->element == 'facturedetrec' || $line->element == 'invoice_supplier_det_rec')) {
  163. if ($line->element == 'invoice_supplier_det_rec') {
  164. $line->date_start_fill = $line->date_start;
  165. $line->date_end_fill = $line->date_end;
  166. }
  167. echo '<br>';
  168. echo $langs->trans('AutoFillDateFrom').' ';
  169. echo $form->selectyesno('date_start_fill', GETPOSTISSET('date_start_fill') ? GETPOST('date_start_fill', 'int') : $line->date_start_fill, 1);
  170. echo ' - ';
  171. echo $langs->trans('AutoFillDateTo').' ';
  172. echo $form->selectyesno('date_end_fill', GETPOSTISSET('date_end_fill') ? GETPOST('date_end_fill', 'int') : $line->date_end_fill, 1);
  173. }
  174. ?>
  175. </td>
  176. <?php
  177. if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
  178. $coldisplay++;
  179. ?>
  180. <td class="right linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth100 maxwidth125onsmartphone" value="<?php echo GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref') : ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn); ?>"></td>
  181. <?php
  182. print '<input type="hidden" id="fournprice" name="fournprice" class="" value="'.$line->fk_fournprice.'">';
  183. }
  184. // VAT Rate
  185. $coldisplay++;
  186. if (!$situationinvoicelinewithparent) {
  187. print '<td class="right">';
  188. print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : ($line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : '')), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1);
  189. print '</td>';
  190. } else {
  191. print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="'.price($line->tva_tx).'" readonly />%</td>';
  192. }
  193. $coldisplay++;
  194. print '<td class="right"><input type="text" class="flat right" size="5" id="price_ht" name="price_ht" value="'.(GETPOSTISSET('price_ht') ? GETPOST('price_ht', 'alpha') : (isset($line->pu_ht) ? price($line->pu_ht, 0, '', 0) : price($line->subprice, 0, '', 0))).'"';
  195. if ($situationinvoicelinewithparent) {
  196. print ' readonly';
  197. }
  198. print '></td>';
  199. if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
  200. $coldisplay++;
  201. print '<td class="right"><input rel="'.$object->multicurrency_tx.'" type="text" class="flat right" size="5" id="multicurrency_subprice" name="multicurrency_subprice" value="'.(GETPOSTISSET('multicurrency_subprice') ? GETPOST('multicurrency_subprice', 'alpha') : price($line->multicurrency_subprice)).'" /></td>';
  202. }
  203. if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
  204. $coldisplay++;
  205. $upinctax = isset($line->pu_ttc) ? $line->pu_ttc : null;
  206. if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES')) {
  207. $upinctax = price2num($line->total_ttc / $line->qty, 'MU');
  208. }
  209. print '<td class="right"><input type="text" class="flat right" size="5" id="price_ttc" name="price_ttc" value="'.(GETPOSTISSET('price_ttc') ? GETPOST('price_ttc') : (isset($upinctax) ? price($upinctax, 0, '', 0) : '')).'"';
  210. if ($line->fk_prev_id != null) {
  211. print ' readonly';
  212. }
  213. print '></td>';
  214. }
  215. ?>
  216. <td class="right">
  217. <?php $coldisplay++;
  218. if (($line->info_bits & 2) != 2) {
  219. // I comment warning of stock because it shows the info even when it should not.
  220. // 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
  221. // must also not be output for most entities (proposal, intervention, ...)
  222. //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
  223. print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="'.(GETPOSTISSET('qty') ? GETPOST('qty') : $line->qty).'"';
  224. if ($situationinvoicelinewithparent) { // Do not allow editing during a situation cycle
  225. print ' readonly';
  226. }
  227. print '>';
  228. } else { ?>
  229. &nbsp;
  230. <?php } ?>
  231. </td>
  232. <?php
  233. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  234. $unit_type = false;
  235. // limit unit select to unit type
  236. if (!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)) {
  237. include_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  238. $cUnit = new CUnits($line->db);
  239. if ($cUnit->fetch($line->fk_unit) > 0) {
  240. if (!empty($cUnit->unit_type)) {
  241. $unit_type = $cUnit->unit_type;
  242. }
  243. }
  244. }
  245. $coldisplay++;
  246. print '<td class="left">';
  247. print $form->selectUnits(GETPOSTISSET('units') ? GETPOST('units') : $line->fk_unit, "units", 0, $unit_type);
  248. print '</td>';
  249. }
  250. ?>
  251. <td class="nowraponall right linecoldiscount">
  252. <?php
  253. // Discount
  254. $coldisplay++;
  255. if (($line->info_bits & 2) != 2) {
  256. print '<input type="text" class="flat right width40" name="remise_percent" id="remise_percent" value="'.(GETPOSTISSET('remise_percent') ? GETPOST('remise_percent') : ($line->remise_percent ? $line->remise_percent : '')).'"';
  257. if ($situationinvoicelinewithparent) {
  258. print ' readonly';
  259. }
  260. print '><span class="hideonsmartphone opacitymedium">%</span>';
  261. } else { ?>
  262. &nbsp;
  263. <?php } ?>
  264. </td>
  265. <?php
  266. // Progession for situation invoices
  267. if ($object->situation_cycle_ref) {
  268. $coldisplay++;
  269. print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="'.(GETPOSTISSET('progress') ? GETPOST('progress') : $line->situation_percent).'" name="progress">%</td>';
  270. $coldisplay++;
  271. print '<td></td>';
  272. }
  273. if (!empty($usemargins)) {
  274. if (!empty($user->rights->margins->creer)) {
  275. $coldisplay++;
  276. ?>
  277. <td class="margininfos right">
  278. <!-- For predef product -->
  279. <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
  280. <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp right" style="display: none;"></select>
  281. <?php } ?>
  282. <!-- For free product -->
  283. <input class="flat maxwidth75 right" type="text" id="buying_price" name="buying_price" class="hideobject" value="<?php echo (GETPOSTISSET('buying_price') ? GETPOST('buying_price') : price($line->pa_ht, 0, '', 0)); ?>">
  284. </td>
  285. <?php }
  286. if ($user->rights->margins->creer) {
  287. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
  288. $margin_rate = (GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", "alpha", 2) : (($line->pa_ht == 0) ? '' : price($line->marge_tx)));
  289. // if credit note, dont allow to modify margin
  290. if ($line->subprice < 0) {
  291. echo '<td class="right nowrap margininfos">'.$margin_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
  292. } else {
  293. echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_marginRate" value="'.$margin_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
  294. }
  295. $coldisplay++;
  296. }
  297. if (!empty($conf->global->DISPLAY_MARK_RATES)) {
  298. $mark_rate = (GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : price($line->marque_tx));
  299. // if credit note, dont allow to modify margin
  300. if ($line->subprice < 0) {
  301. echo '<td class="right nowrap margininfos">'.$mark_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
  302. } else {
  303. echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_markRate" value="'.$mark_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
  304. }
  305. $coldisplay++;
  306. }
  307. }
  308. }
  309. ?>
  310. <!-- colspan for this td because it replace total_ht+3 td for buttons+... -->
  311. <td class="center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay += $colspan; ?>
  312. <input type="submit" class="reposition button buttongen marginbottomonly button-save" id="savelinebutton marginbottomonly" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
  313. <input type="submit" class="reposition button buttongen marginbottomonly button-cancel" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
  314. </td>
  315. </tr>
  316. <?php if (isModEnabled("service") && $line->product_type == 1 && $dateSelector) { ?>
  317. <tr id="service_duration_area" class="treditedlinefordate">
  318. <?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
  319. <td class="linecolnum center"></td>
  320. <?php } ?>
  321. <td colspan="<?php echo $coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1) ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
  322. <?php
  323. $hourmin = (isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : '');
  324. print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start ? 0 : 1, "updateline", 1, 0);
  325. print ' '.$langs->trans('to').' ';
  326. print $form->selectDate($line->date_end, 'date_end', $hourmin, $hourmin, $line->date_end ? 0 : 1, "updateline", 1, 0);
  327. print '<script>';
  328. if (!$line->date_start) {
  329. if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
  330. print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
  331. }
  332. if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
  333. print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
  334. }
  335. $res = $line->fetch_product();
  336. if ($res > 0 ) {
  337. if ( $line->product->isMandatoryPeriod() && $line->product->isService()) {
  338. print 'jQuery("#date_start").addClass("error");';
  339. }
  340. }
  341. }
  342. if (!$line->date_end) {
  343. if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
  344. print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
  345. }
  346. if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
  347. print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
  348. }
  349. $res = $line->fetch_product();
  350. // on doit fetch le product là !!! pour connaître le type
  351. if ($res > 0 ) {
  352. if ($line->product->isMandatoryperiod() && $line->product->isService()) {
  353. print 'jQuery("#date_end").addClass("error");';
  354. }
  355. }
  356. }
  357. print '</script>'
  358. ?>
  359. </td>
  360. </tr>
  361. <?php }
  362. ?>
  363. <script>
  364. <?php
  365. if (!empty($usemargins) && $user->rights->margins->creer) {
  366. ?>
  367. /* Some js test when we click on button "Add" */
  368. jQuery(document).ready(function() {
  369. <?php
  370. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
  371. ?>
  372. $("input[name='np_marginRate']:first").blur(function(e) {
  373. return checkFreeLine(e, "np_marginRate");
  374. });
  375. <?php
  376. }
  377. if (!empty($conf->global->DISPLAY_MARK_RATES)) {
  378. ?>
  379. $("input[name='np_markRate']:first").blur(function(e) {
  380. return checkFreeLine(e, "np_markRate");
  381. });
  382. <?php
  383. }
  384. ?>
  385. });
  386. /* TODO This does not work for number with thousand separator that is , */
  387. function checkFreeLine(e, npRate)
  388. {
  389. var buying_price = $("input[name='buying_price']:first");
  390. var remise = $("input[name='remise_percent']:first");
  391. var rate = $("input[name='"+npRate+"']:first");
  392. if (rate.val() == '')
  393. return true;
  394. var ratejs = price2numjs(rate.val());
  395. if (! $.isNumeric(ratejs))
  396. {
  397. alert('<?php echo dol_escape_js($langs->transnoentities("rateMustBeNumeric")); ?>');
  398. e.stopPropagation();
  399. setTimeout(function () { rate.focus() }, 50);
  400. return false;
  401. }
  402. if (npRate == "np_markRate" && rate.val() >= 100)
  403. {
  404. alert('<?php echo dol_escape_js($langs->transnoentities("markRateShouldBeLesserThan100")); ?>');
  405. e.stopPropagation();
  406. setTimeout(function () { rate.focus() }, 50);
  407. return false;
  408. }
  409. var price = 0;
  410. remisejs=price2numjs(remise.val());
  411. if (remisejs != 100) // If a discount not 100 or no discount
  412. {
  413. if (remisejs == '') remisejs=0;
  414. bpjs=price2numjs(buying_price.val());
  415. ratejs=price2numjs(rate.val());
  416. if (npRate == "np_marginRate")
  417. price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
  418. else if (npRate == "np_markRate")
  419. price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
  420. }
  421. $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
  422. return true;
  423. }
  424. <?php
  425. }
  426. ?>
  427. jQuery(document).ready(function()
  428. {
  429. jQuery("#price_ht").keyup(function(event) {
  430. // console.log(event.which); // discard event tag and arrows
  431. if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
  432. jQuery("#price_ttc").val('');
  433. jQuery("#multicurrency_subprice").val('');
  434. }
  435. });
  436. jQuery("#price_ttc").keyup(function(event) {
  437. // console.log(event.which); // discard event tag and arrows
  438. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  439. jQuery("#price_ht").val('');
  440. jQuery("#multicurrency_subprice").val('');
  441. }
  442. });
  443. jQuery("#multicurrency_subprice").keyup(function(event) {
  444. // console.log(event.which); // discard event tag and arrows
  445. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  446. jQuery("#price_ht").val('');
  447. jQuery("#price_ttc").val('');
  448. }
  449. });
  450. <?php if (in_array($object->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
  451. $("#date_start, #date_end").focusout(function() {
  452. if ( $(this).val() == '' && !$(this).hasClass('inputmandatory') ) {
  453. $(this).addClass('inputmandatory');
  454. } else {
  455. $(this).removeClass('inputmandatory');
  456. }
  457. });
  458. <?php
  459. }
  460. if (isModEnabled('margin')) {
  461. ?>
  462. /* 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 */
  463. jQuery("#tva_tx").click(function() { /* somtimes field is a text, sometimes a combo */
  464. jQuery("input[name='np_marginRate']:first").val('');
  465. jQuery("input[name='np_markRate']:first").val('');
  466. });
  467. jQuery("#tva_tx").keyup(function() { /* somtimes field is a text, sometimes a combo */
  468. jQuery("input[name='np_marginRate']:first").val('');
  469. jQuery("input[name='np_markRate']:first").val('');
  470. });
  471. jQuery("#price_ht").keyup(function() {
  472. jQuery("input[name='np_marginRate']:first").val('');
  473. jQuery("input[name='np_markRate']:first").val('');
  474. });
  475. jQuery("#qty").keyup(function() {
  476. jQuery("input[name='np_marginRate']:first").val('');
  477. jQuery("input[name='np_markRate']:first").val('');
  478. });
  479. jQuery("#remise_percent").keyup(function() {
  480. jQuery("input[name='np_marginRate']:first").val('');
  481. jQuery("input[name='np_markRate']:first").val('');
  482. });
  483. jQuery("#buying_price").keyup(function() {
  484. jQuery("input[name='np_marginRate']:first").val('');
  485. jQuery("input[name='np_markRate']:first").val('');
  486. });
  487. /* Init field buying_price and fournprice */
  488. var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
  489. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product ? $line->fk_product : 0; ?>, 'token': token }, function(data) {
  490. if (data && data.length > 0) {
  491. var options = '';
  492. var trouve=false;
  493. $(data).each(function() {
  494. options += '<option value="'+this.id+'" price="'+this.price+'"';
  495. <?php if ($line->fk_fournprice > 0) { ?>
  496. if (this.id == <?php echo $line->fk_fournprice; ?>) {
  497. options += ' selected';
  498. $("#buying_price").val(this.price);
  499. trouve = true;
  500. }
  501. <?php } ?>
  502. options += '>'+this.label+'</option>';
  503. });
  504. options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
  505. $("#fournprice").html(options);
  506. if (trouve) {
  507. $("#buying_price").hide();
  508. $("#fournprice").show();
  509. } else {
  510. $("#buying_price").show();
  511. }
  512. $("#fournprice").change(function() {
  513. var selval = $(this).find('option:selected').attr("price");
  514. if (selval)
  515. $("#buying_price").val(selval).hide();
  516. else
  517. $('#buying_price').show();
  518. });
  519. } else {
  520. $("#fournprice").hide();
  521. $('#buying_price').show();
  522. }
  523. }, 'json');
  524. <?php
  525. }
  526. ?>
  527. });
  528. </script>
  529. <!-- END PHP TEMPLATE objectline_edit.tpl.php -->