objectline_create.tpl.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
  5. * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  11. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  12. * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
  13. * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. *
  28. * Need to have following variables defined:
  29. * $object (invoice, order, ...)
  30. * $conf
  31. * $langs
  32. * $dateSelector
  33. * $forceall (0 by default, 1 for supplier invoices/orders)
  34. * $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
  35. * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
  36. */
  37. // Protection to avoid direct call of template
  38. if (empty($object) || !is_object($object)) {
  39. print "Error: this template page cannot be called directly as an URL";
  40. exit;
  41. }
  42. $usemargins = 0;
  43. if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
  44. $usemargins = 1;
  45. }
  46. if (!isset($dateSelector)) {
  47. global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
  48. }
  49. global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
  50. if (!isset($dateSelector)) {
  51. $dateSelector = 1; // For backward compatibility
  52. } elseif (empty($dateSelector)) {
  53. $dateSelector = 0;
  54. }
  55. if (empty($forceall)) {
  56. $forceall = 0;
  57. }
  58. if (empty($senderissupplier)) {
  59. $senderissupplier = 0;
  60. }
  61. if (empty($inputalsopricewithtax)) {
  62. $inputalsopricewithtax = 0;
  63. }
  64. // Define colspan for the button 'Add'
  65. $colspan = 3; // Columns: total ht + col edit + col delete
  66. if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
  67. $colspan++; //Add column for Total (currency) if required
  68. }
  69. if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
  70. $colspan++; // With this, there is a column move button
  71. }
  72. if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
  73. $colspan++;
  74. }
  75. //print $object->element;
  76. // Lines for extrafield
  77. $objectline = null;
  78. if (!empty($extrafields)) {
  79. if ($this->table_element_line == 'commandedet') {
  80. $objectline = new OrderLine($this->db);
  81. } elseif ($this->table_element_line == 'propaldet') {
  82. $objectline = new PropaleLigne($this->db);
  83. } elseif ($this->table_element_line == 'supplier_proposaldet') {
  84. $objectline = new SupplierProposalLine($this->db);
  85. } elseif ($this->table_element_line == 'facturedet') {
  86. $objectline = new FactureLigne($this->db);
  87. } elseif ($this->table_element_line == 'contratdet') {
  88. $objectline = new ContratLigne($this->db);
  89. } elseif ($this->table_element_line == 'commande_fournisseurdet') {
  90. $objectline = new CommandeFournisseurLigne($this->db);
  91. } elseif ($this->table_element_line == 'facture_fourn_det') {
  92. $objectline = new SupplierInvoiceLine($this->db);
  93. } elseif ($this->table_element_line == 'facturedet_rec') {
  94. $objectline = new FactureLigneRec($this->db);
  95. } elseif ($this->table_element_line == 'facture_fourn_det_rec') {
  96. $objectline = new FactureFournisseurLigneRec($this->db);
  97. }
  98. }
  99. print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
  100. $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
  101. if ($nolinesbefore) {
  102. ?>
  103. <tr class="liste_titre<?php echo (($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_add_') ?> nodrag nodrop">
  104. <?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
  105. <td class="linecolnum center"></td>
  106. <?php } ?>
  107. <td class="linecoldescription minwidth400imp">
  108. <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span>
  109. </td>
  110. <?php
  111. 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
  112. ?>
  113. <td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
  114. <?php
  115. }
  116. ?>
  117. <td class="linecolvat right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
  118. <td class="linecoluht right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
  119. <?php if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) { ?>
  120. <td class="linecoluht_currency right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
  121. <?php } ?>
  122. <?php if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) { ?>
  123. <td class="linecoluttc right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
  124. <?php } ?>
  125. <td class="linecolqty right"><?php echo $langs->trans('Qty'); ?></td>
  126. <?php
  127. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  128. print '<td class="linecoluseunit left">';
  129. print '<span id="title_units">';
  130. print $langs->trans('Unit');
  131. print '</span></td>';
  132. }
  133. ?>
  134. <td class="linecoldiscount right"><?php echo $langs->trans('ReductionShort'); ?></td>
  135. <?php
  136. // Fields for situation invoice
  137. if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
  138. print '<td class="linecolcycleref right">'.$langs->trans('Progress').'</td>';
  139. print '<td class="linecolcycleref2 right"></td>';
  140. }
  141. if (!empty($usemargins)) {
  142. if (empty($user->rights->margins->creer)) {
  143. $colspan++;
  144. } else {
  145. print '<td class="margininfos linecolmargin1 right">';
  146. if ($conf->global->MARGIN_TYPE == "1") {
  147. echo $langs->trans('BuyingPrice');
  148. } else {
  149. echo $langs->trans('CostPrice');
  150. }
  151. echo '</td>';
  152. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
  153. echo '<td class="margininfos linecolmargin2 right"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
  154. }
  155. if (!empty($conf->global->DISPLAY_MARK_RATES)) {
  156. echo '<td class="margininfos linecolmargin2 right"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
  157. }
  158. }
  159. }
  160. ?>
  161. <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
  162. </tr>
  163. <?php
  164. }
  165. ?>
  166. <tr class="pair nodrag nodrop nohoverpair<?php echo ($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create'; ?>">
  167. <?php
  168. $coldisplay = 0;
  169. // Adds a line numbering column
  170. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  171. $coldisplay++;
  172. echo '<td class="nobottom linecolnum center"></td>';
  173. }
  174. $coldisplay++;
  175. ?>
  176. <td class="nobottom linecoldescription minwidth400imp">
  177. <?php
  178. $freelines = false;
  179. if (empty($conf->global->MAIN_DISABLE_FREE_LINES)) {
  180. $freelines = true;
  181. $forceall = 1; // We always force all type for free lines (module product or service means we use predefined product or service)
  182. if ($object->element == 'contrat') {
  183. if (!isModEnabled('product') && !isModEnabled('service') && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
  184. $forceall = -1; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
  185. } elseif (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
  186. $forceall = 3;
  187. }
  188. }
  189. // Free line
  190. echo '<span class="prod_entry_mode_free">';
  191. // Show radio free line
  192. if ($forceall >= 0 && (isModEnabled("product") || isModEnabled("service"))) {
  193. echo '<label for="prod_entry_mode_free">';
  194. echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
  195. //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (!isModEnabled('product') || !isModEnabled('service')))?' checked':'') );
  196. echo ((GETPOST('prod_entry_mode', 'alpha') == 'free' || !empty($conf->global->MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT)) ? ' checked' : '');
  197. echo '> ';
  198. // Show type selector
  199. echo '<span class="textradioforitem">'.$langs->trans("FreeLineOfType").'</span>';
  200. echo '</label>';
  201. echo ' ';
  202. } else {
  203. echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
  204. // Show type selector
  205. if ($forceall >= 0) {
  206. if (!isModEnabled('product') || !isModEnabled('service')) {
  207. echo $langs->trans("Type");
  208. } else {
  209. echo $langs->trans("FreeLineOfType");
  210. }
  211. echo ' ';
  212. }
  213. }
  214. $form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', 1, 1, $forceall);
  215. echo '</span>';
  216. }
  217. // Predefined product/service
  218. if (isModEnabled("product") || isModEnabled("service")) {
  219. if ($forceall >= 0 && $freelines) {
  220. echo '<br><span class="prod_entry_mode_predef paddingtop">';
  221. } else {
  222. echo '<span class="prod_entry_mode_predef">';
  223. }
  224. echo '<label for="prod_entry_mode_predef">';
  225. echo '<input type="radio" class="prod_entry_mode_predef" name="prod_entry_mode" id="prod_entry_mode_predef" value="predef"'.(GETPOST('prod_entry_mode') == 'predef' ? ' checked' : '').'> ';
  226. $labelforradio = '';
  227. if (empty($conf->dol_optimize_smallscreen)) {
  228. if (empty($senderissupplier)) {
  229. if (isModEnabled("product") && !isModEnabled('service')) {
  230. $labelforradio = $langs->trans('PredefinedProductsToSell');
  231. } elseif ((!isModEnabled('product') && isModEnabled('service')) || ($object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS))) {
  232. $labelforradio = $langs->trans('PredefinedServicesToSell');
  233. } else {
  234. $labelforradio = $langs->trans('PredefinedProductsAndServicesToSell');
  235. }
  236. } else {
  237. if (isModEnabled("product") && !isModEnabled('service')) {
  238. $labelforradio = $langs->trans('PredefinedProductsToPurchase');
  239. } elseif (!isModEnabled('product') && isModEnabled('service')) {
  240. $labelforradio = $langs->trans('PredefinedServicesToPurchase');
  241. } else {
  242. $labelforradio = $langs->trans('PredefinedProductsAndServicesToPurchase');
  243. }
  244. }
  245. } else {
  246. $labelforradio = $langs->trans('PredefinedItem');
  247. }
  248. print '<span class="textradioforitem">'.$labelforradio.'</span>';
  249. echo '</label>';
  250. echo ' ';
  251. $filtertype = '';
  252. if (!empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
  253. $filtertype = '1';
  254. }
  255. if (empty($senderissupplier)) {
  256. $statustoshow = 1;
  257. $statuswarehouse = 'warehouseopen,warehouseinternal';
  258. if (!empty($conf->global->ENTREPOT_WAREHOUSEINTERNAL_NOT_SELL)) $statuswarehouse = 'warehouseopen';
  259. if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
  260. // hide products in closed warehouse, but show products for internal transfer
  261. $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, $statuswarehouse, GETPOST('combinations', 'array'));
  262. } else {
  263. $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOST('combinations', 'array'));
  264. }
  265. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS)) {
  266. ?>
  267. <script>
  268. $(document).ready(function(){
  269. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  270. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  271. console.log('focus on a select2');
  272. if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
  273. {
  274. console.log('open combo');
  275. $('#idprod').select2('open');
  276. }
  277. });
  278. });
  279. </script>
  280. <?php
  281. }
  282. } else {
  283. // $senderissupplier=2 is the same as 1 but disables test on minimum qty, disable autofill qty with minimum and autofill unit price
  284. if ($senderissupplier != 2) {
  285. $ajaxoptions = array(
  286. 'update' => array('qty'=>'qty', 'remise_percent' => 'discount', 'idprod' => 'idprod'), // html id tags that will be edited with each ajax json response key
  287. 'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
  288. 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for example shown we select a disabled option into combo)
  289. );
  290. $alsoproductwithnosupplierprice = 0;
  291. } else {
  292. $ajaxoptions = array(
  293. // Disabled: This is useless because setting discount and price_ht after a selection is already managed
  294. // by ths page itself with a .change on the combolist '#idprodfournprice'
  295. //'update' => array('remise_percent' => 'discount', 'price_ht' => 'price_ht') // html id tags that will be edited with each ajax json response key
  296. );
  297. $alsoproductwithnosupplierprice = 1;
  298. }
  299. $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'minwidth300imp maxwidth500');
  300. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS)) {
  301. ?>
  302. <script>
  303. $(document).ready(function(){
  304. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  305. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  306. //console.log('focus on a select2');
  307. if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
  308. {
  309. $('#idprodfournprice').select2('open');
  310. }
  311. });
  312. });
  313. </script>
  314. <?php
  315. }
  316. }
  317. echo '<input type="hidden" name="pbq" id="pbq" value="">';
  318. echo '</span>';
  319. }
  320. if (!empty($conf->global->MAIN_ADD_LINE_AT_POSITION)) {
  321. echo '<br>'.$langs->trans('AddLineOnPosition').' : <input type="number" name="rank" step="1" min="0" style="width: 5em;">';
  322. }
  323. if (is_object($hookmanager) && empty($senderissupplier)) {
  324. $parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
  325. $reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
  326. if (!empty($hookmanager->resPrint)) {
  327. print $hookmanager->resPrint;
  328. }
  329. }
  330. if (is_object($hookmanager) && !empty($senderissupplier)) {
  331. $parameters = array('htmlname'=>'addproduct');
  332. $reshook = $hookmanager->executeHooks('formCreateProductSupplierOptions', $parameters, $object, $action);
  333. if (!empty($hookmanager->resPrint)) {
  334. print $hookmanager->resPrint;
  335. }
  336. }
  337. if (isModEnabled("product") || isModEnabled("service")) {
  338. echo '<br>';
  339. if (isModEnabled('variants')) {
  340. echo '<div id="attributes_box"></div>';
  341. }
  342. }
  343. // Editor wysiwyg
  344. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  345. $nbrows = ROWS_2;
  346. $enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
  347. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
  348. $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  349. }
  350. $toolbarname = 'dolibarr_details';
  351. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
  352. $toolbarname = 'dolibarr_notes';
  353. }
  354. $doleditor = new DolEditor('dp_desc', GETPOST('dp_desc', 'restricthtml'), '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 100 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%');
  355. $doleditor->Create();
  356. // Show autofill date for recurring invoices
  357. if (isModEnabled("service") && ($object->element == 'facturerec' || $object->element == 'invoice_supplier_rec')) {
  358. echo '<div class="divlinefordates"><br>';
  359. echo $langs->trans('AutoFillDateFrom').' ';
  360. if (!empty($conf->global->INVOICE_REC_DATE_TO_YES)) {
  361. $line->date_start_fill = 1;
  362. $line->date_end_fill = 1;
  363. }
  364. echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
  365. echo ' - ';
  366. echo $langs->trans('AutoFillDateTo').' ';
  367. echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
  368. echo '</div>';
  369. }
  370. if (is_object($objectline)) {
  371. $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
  372. if (!empty($temps)) {
  373. print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
  374. print $temps;
  375. print '</div>';
  376. }
  377. }
  378. echo '</td>';
  379. 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
  380. $coldisplay++;
  381. ?>
  382. <td class="nobottom linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth100 maxwidth125onsmartphone" value="<?php echo (GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>
  383. <?php }
  384. print '<td class="nobottom linecolvat right">';
  385. $coldisplay++;
  386. if ($seller->tva_assuj == "0") {
  387. echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
  388. } else {
  389. echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
  390. }
  391. ?>
  392. </td>
  393. <td class="nobottom linecoluht right"><?php $coldisplay++; ?>
  394. <input type="text" size="5" name="price_ht" id="price_ht" class="flat right" value="<?php echo (GETPOSTISSET("price_ht") ? GETPOST("price_ht", 'alpha', 2) : ''); ?>">
  395. </td>
  396. <?php
  397. if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
  398. $coldisplay++;
  399. ?>
  400. <td class="nobottom linecoluht_currency right">
  401. <input type="text" size="5" name="multicurrency_price_ht" id="multicurrency_price_ht" class="flat right" value="<?php echo (GETPOSTISSET("multicurrency_price_ht") ? GETPOST("multicurrency_price_ht", 'alpha', 2) : ''); ?>">
  402. </td>
  403. <?php
  404. }
  405. if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
  406. $coldisplay++;
  407. ?>
  408. <td class="nobottom linecoluttc right">
  409. <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat right" value="<?php echo (GETPOSTISSET("price_ttc") ? GETPOST("price_ttc", 'alpha', 2) : ''); ?>">
  410. </td>
  411. <?php
  412. }
  413. $coldisplay++;
  414. ?>
  415. <td class="nobottom linecolqty right">
  416. <input type="text" name="qty" id="qty" class="flat width40 right" value="<?php echo (GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : 1); ?>">
  417. </td>
  418. <?php
  419. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  420. $coldisplay++;
  421. print '<td class="nobottom linecoluseunit left">';
  422. print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, "units");
  423. print '</td>';
  424. }
  425. $remise_percent = $buyer->remise_percent;
  426. if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
  427. $remise_percent = $seller->remise_supplier_percent;
  428. }
  429. $coldisplay++;
  430. ?>
  431. <td class="nobottom nowrap linecoldiscount right"><input type="text" name="remise_percent" id="remise_percent" class="flat width40 right" value="<?php echo (GETPOSTISSET("remise_percent") ? GETPOST("remise_percent", 'alpha', 2) : ($remise_percent ? $remise_percent : '')); ?>"><span class="opacitymedium hideonsmartphone">%</span></td>
  432. <?php
  433. if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
  434. $coldisplay++;
  435. print '<td class="nobottom nowrap right"><input class="falt right" type="text" size="1" value="" name="progress"><span class="opacitymedium hideonsmartphone">%</span></td>';
  436. $coldisplay++;
  437. print '<td></td>';
  438. }
  439. if (!empty($usemargins)) {
  440. if (!empty($user->rights->margins->creer)) {
  441. $coldisplay++;
  442. ?>
  443. <td class="nobottom margininfos linecolmargin right">
  444. <!-- For predef product -->
  445. <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
  446. <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp maxwidth150" style="display: none;"></select>
  447. <?php } ?>
  448. <!-- For free product -->
  449. <input type="text" id="buying_price" name="buying_price" class="flat maxwidth75 right" value="<?php echo (GETPOSTISSET("buying_price") ? GETPOST("buying_price", 'alpha', 2) : ''); ?>">
  450. </td>
  451. <?php
  452. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
  453. echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_marginRate" name="np_marginRate" value="'.(GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", 'alpha', 2) : '').'"><span class="np_marginRate opacitymedium hideonsmartphone">%</span></td>';
  454. $coldisplay++;
  455. }
  456. if (!empty($conf->global->DISPLAY_MARK_RATES)) {
  457. echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_markRate" name="np_markRate" value="'.(GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : '').'"><span class="np_markRate opacitymedium hideonsmartphone">%</span></td>';
  458. $coldisplay++;
  459. }
  460. }
  461. }
  462. $coldisplay += $colspan;
  463. ?>
  464. <td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>">
  465. <input type="submit" class="button reposition" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
  466. </td>
  467. </tr>
  468. <?php
  469. if ((isModEnabled("service") || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') { // We show date field if required
  470. print '<tr id="trlinefordates" class="oddeven">'."\n";
  471. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  472. print '<td></td>';
  473. }
  474. print '<td colspan="'.($coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1)).'">';
  475. $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  476. $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  477. $prefillDates = false;
  478. if (!empty($conf->global->MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE) && !empty($object->lines)) {
  479. for ($i = count($object->lines) - 1; $i >= 0; $i--) {
  480. $lastline = $object->lines[$i];
  481. if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
  482. $date_start_prefill = $lastline->date_start;
  483. $date_end_prefill = $lastline->date_end;
  484. $prefillDates = true;
  485. break;
  486. }
  487. }
  488. }
  489. if (!empty($object->element) && $object->element == 'contrat') {
  490. print $langs->trans("DateStartPlanned").' ';
  491. print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
  492. print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
  493. print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
  494. } else {
  495. print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
  496. print $form->selectDate($date_start, 'date_start', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
  497. print ' '.$langs->trans('to').' ';
  498. print $form->selectDate($date_end, 'date_end', empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? 0 : 1, 1, "addproduct", 1, 0);
  499. };
  500. if ($prefillDates) {
  501. echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
  502. }
  503. print '<script>';
  504. if ($prefillDates) {
  505. ?>
  506. function prefill_service_dates()
  507. {
  508. $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
  509. $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
  510. return false; // Prevent default link behaviour (which is go to href URL)
  511. }
  512. $(document).ready(function()
  513. {
  514. $('#prefill_service_dates').click(prefill_service_dates);
  515. });
  516. <?php
  517. }
  518. if (!$date_start) {
  519. if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
  520. print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
  521. }
  522. if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
  523. print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
  524. }
  525. }
  526. if (!$date_end) {
  527. if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
  528. print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
  529. }
  530. if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
  531. print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
  532. }
  533. }
  534. print '</script>';
  535. print '</td>';
  536. print '</tr>'."\n";
  537. }
  538. print "<script>\n";
  539. if (!empty($usemargins) && $user->rights->margins->creer) {
  540. ?>
  541. /* Some js test when we click on button "Add" */
  542. jQuery(document).ready(function() {
  543. <?php
  544. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
  545. $("input[name='np_marginRate']:first").blur(function(e) {
  546. return checkFreeLine(e, "np_marginRate");
  547. });
  548. <?php
  549. }
  550. if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
  551. $("input[name='np_markRate']:first").blur(function(e) {
  552. return checkFreeLine(e, "np_markRate");
  553. });
  554. <?php
  555. }
  556. ?>
  557. });
  558. /* TODO This does not work for number with thousand separator that is , */
  559. function checkFreeLine(e, npRate)
  560. {
  561. var buying_price = $("input[name='buying_price']:first");
  562. var remise = $("input[name='remise_percent']:first");
  563. var rate = $("input[name='"+npRate+"']:first");
  564. if (rate.val() == '')
  565. return true;
  566. if (! $.isNumeric(rate.val().replace(',','.')))
  567. {
  568. alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
  569. e.stopPropagation();
  570. setTimeout(function () { rate.focus() }, 50);
  571. return false;
  572. }
  573. if (npRate == "np_markRate" && rate.val() >= 100)
  574. {
  575. alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
  576. e.stopPropagation();
  577. setTimeout(function () { rate.focus() }, 50);
  578. return false;
  579. }
  580. var price = 0;
  581. remisejs=price2numjs(remise.val());
  582. if (remisejs != 100) // If a discount not 100 or no discount
  583. {
  584. if (remisejs == '') remisejs=0;
  585. bpjs=price2numjs(buying_price.val());
  586. ratejs=price2numjs(rate.val());
  587. if (npRate == "np_marginRate")
  588. price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
  589. else if (npRate == "np_markRate")
  590. price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
  591. }
  592. $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
  593. return true;
  594. }
  595. <?php
  596. }
  597. ?>
  598. /* JQuery for product free or predefined select */
  599. jQuery(document).ready(function() {
  600. jQuery("#price_ht").keyup(function(event) {
  601. // console.log(event.which); // discard event tag and arrows
  602. if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
  603. jQuery("#price_ttc").val('');
  604. jQuery("#multicurrency_subprice").val('');
  605. }
  606. });
  607. jQuery("#price_ttc").keyup(function(event) {
  608. // console.log(event.which); // discard event tag and arrows
  609. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  610. jQuery("#price_ht").val('');
  611. jQuery("#multicurrency_subprice").val('');
  612. }
  613. });
  614. jQuery("#multicurrency_subprice").keyup(function(event) {
  615. // console.log(event.which); // discard event tag and arrows
  616. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  617. jQuery("#price_ht").val('');
  618. jQuery("#price_ttc").val('');
  619. }
  620. });
  621. $("#prod_entry_mode_free").on( "click", function() {
  622. setforfree();
  623. });
  624. $("#select_type").change(function()
  625. {
  626. setforfree();
  627. if (jQuery('#select_type').val() >= 0) {
  628. console.log("Set focus on description field");
  629. /* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
  630. jQuery('#dp_desc').focus();
  631. /* this focus code works for CKEDITOR */
  632. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
  633. var editor = CKEDITOR.instances['dp_desc'];
  634. if (editor) {
  635. editor.focus();
  636. }
  637. }
  638. }
  639. console.log("Hide/show date according to product type");
  640. if (jQuery('#select_type').val() == '0')
  641. {
  642. jQuery('#trlinefordates').hide();
  643. jQuery('.divlinefordates').hide();
  644. }
  645. else
  646. {
  647. jQuery('#trlinefordates').show();
  648. jQuery('.divlinefordates').show();
  649. }
  650. });
  651. $("#prod_entry_mode_predef").on( "click", function() {
  652. console.log("click prod_entry_mode_predef");
  653. setforpredef();
  654. jQuery('#trlinefordates').show();
  655. });
  656. <?php
  657. if (!$freelines) { ?>
  658. $("#prod_entry_mode_predef").click();
  659. <?php
  660. }
  661. if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
  662. $("#date_start, #date_end").focusout(function() {
  663. let type = $(this).attr('type');
  664. let mandatoryP = $(this).attr('mandatoryperiod');
  665. if (type == 1 && mandatoryP == 1) {
  666. if ($(this).val() == '' && !$(this).hasClass('inputmandatory')) {
  667. $(this).addClass('inputmandatory');
  668. }else{
  669. $(this).removeClass('inputmandatory');
  670. }
  671. }
  672. });
  673. <?php
  674. } ?>
  675. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  676. $("#idprod, #idprodfournprice").change(function()
  677. {
  678. console.log("objectline_create.tpl Call method change() after change on #idprod or #idprodfournprice (senderissupplier=<?php echo $senderissupplier; ?>). this.val = "+$(this).val());
  679. setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva(product)
  680. jQuery('#trlinefordates').show();
  681. <?php
  682. if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier)) {
  683. ?>
  684. var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
  685. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
  686. if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
  687. {
  688. console.log("objectline_create.tpl We are in a price per qty context, we do not call ajax/product, init of fields is done few lines later");
  689. } else {
  690. <?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
  691. if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we could not get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
  692. <?php } ?>
  693. // Get the price for the product and display it
  694. console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
  695. $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
  696. { 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>' },
  697. function(data) {
  698. console.log("objectline_create.tpl Load unit price end, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
  699. $('#date_start').removeAttr('type');
  700. $('#date_end').removeAttr('type');
  701. $('#date_start').attr('type', data.type);
  702. $('#date_end').attr('type', data.type);
  703. $('#date_start').removeAttr('mandatoryperiod');
  704. $('#date_end').removeAttr('mandatoryperiod');
  705. $('#date_start').attr('mandatoryperiod', data.mandatory_period);
  706. $('#date_end').attr('mandatoryperiod', data.mandatory_period);
  707. // service and we setted mandatory_period to true
  708. if (data.mandatory_period == 1 && data.type == 1) {
  709. jQuery('#date_start').addClass('inputmandatory');
  710. jQuery('#date_end').addClass('inputmandatory');
  711. } else {
  712. jQuery('#date_start').removeClass('inputmandatory');
  713. jQuery('#date_end').removeClass('inputmandatory');
  714. }
  715. if (<?php echo (int) $inputalsopricewithtax; ?> == 1 && data.pricebasetype == 'TTC') {
  716. console.log("objectline_create.tpl set content of price_ttc");
  717. jQuery("#price_ttc").val(data.price_ttc);
  718. } else {
  719. console.log("objectline_create.tpl set content of price_ht");
  720. jQuery("#price_ht").val(data.price_ht);
  721. }
  722. var tva_tx = data.tva_tx;
  723. var default_vat_code = data.default_vat_code;
  724. // Now set the VAT
  725. var stringforvatrateselection = tva_tx;
  726. if (typeof default_vat_code != 'undefined' && default_vat_code != null) {
  727. stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
  728. }
  729. // Set vat rate if field is an input box
  730. $('#tva_tx').val(tva_tx);
  731. // Set vat rate by selecting the combo
  732. //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
  733. $('#tva_tx option').removeAttr('selected');
  734. console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
  735. $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
  736. <?php
  737. if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
  738. if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?>
  739. var proddesc = data.desc_trans;
  740. <?php
  741. } else { ?>
  742. var proddesc = data.desc;
  743. <?php
  744. } ?>
  745. console.log("objectline_create.tpl Load desciption into text area : "+proddesc);
  746. <?php
  747. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  748. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  749. {
  750. var editor = CKEDITOR.instances['dp_desc'];
  751. if (editor) {
  752. editor.setData(proddesc);
  753. }
  754. }
  755. <?php
  756. } else { ?>
  757. jQuery('#dp_desc').text(proddesc);
  758. <?php
  759. } ?>
  760. <?php
  761. } ?>
  762. <?php
  763. if (!empty($conf->global->PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES)) { ?>
  764. jQuery.each(data.array_options, function( key, value ) {
  765. jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value);
  766. });
  767. <?php
  768. } ?>
  769. },
  770. 'json'
  771. );
  772. }
  773. <?php
  774. }
  775. if (!empty($usemargins) && $user->rights->margins->creer) {
  776. $langs->load('stocks');
  777. ?>
  778. /* Code for margin */
  779. $("#fournprice_predef").find("option").remove();
  780. $("#fournprice_predef").hide();
  781. $("#buying_price").val("").show();
  782. /* Call post to load content of combo list fournprice_predef */
  783. var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
  784. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
  785. if (data && data.length > 0)
  786. {
  787. var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
  788. var bestpriceid = 0; var bestpricevalue = 0;
  789. var pmppriceid = 0; var pmppricevalue = 0;
  790. var costpriceid = 0; var costpricevalue = 0;
  791. /* setup of margin calculation */
  792. var defaultbuyprice = '<?php
  793. if (isset($conf->global->MARGIN_TYPE)) {
  794. if ($conf->global->MARGIN_TYPE == '1') {
  795. print 'bestsupplierprice';
  796. }
  797. if ($conf->global->MARGIN_TYPE == 'pmp') {
  798. print 'pmp';
  799. }
  800. if ($conf->global->MARGIN_TYPE == 'costprice') {
  801. print 'costprice';
  802. }
  803. } ?>';
  804. console.log("objectline_create.tpl we will set the field for margin. defaultbuyprice="+defaultbuyprice);
  805. var i = 0;
  806. $(data).each(function() {
  807. /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
  808. if (this.id != 'pmpprice' && this.id != 'costprice')
  809. {
  810. i++;
  811. this.price = parseFloat(this.price); // to fix when this.price >0
  812. // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
  813. //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
  814. if (bestpricefound == 0 && this.price > 0) { defaultkey = this.id; defaultprice = this.price; bestpriceid = this.id; bestpricevalue = this.price; bestpricefound=1; } // bestpricefound is used to take the first price > 0
  815. }
  816. if (this.id == 'pmpprice')
  817. {
  818. // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
  819. console.log("id="+this.id+"-price="+this.price);
  820. if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
  821. {
  822. if (this.price > 0) {
  823. defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
  824. //console.log("pmppricevalue="+pmppricevalue);
  825. }
  826. }
  827. }
  828. if (this.id == 'costprice')
  829. {
  830. // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
  831. console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
  832. if ('costprice' == defaultbuyprice)
  833. {
  834. if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
  835. else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
  836. }
  837. }
  838. options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
  839. });
  840. options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice").'...'; ?></option>';
  841. console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
  842. $("#fournprice_predef").html(options).show();
  843. if (defaultkey != '')
  844. {
  845. $("#fournprice_predef").val(defaultkey);
  846. }
  847. /* At loading, no product are yet selected, so we hide field of buying_price */
  848. $("#buying_price").hide();
  849. /* Define default price at loading */
  850. var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
  851. $("#buying_price").val(defaultprice);
  852. $("#fournprice_predef").change(function() {
  853. console.log("change on fournprice_predef");
  854. /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
  855. var linevalue=$(this).find('option:selected').val();
  856. var pricevalue = $(this).find('option:selected').attr("price");
  857. if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
  858. $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
  859. }
  860. if (linevalue == 'inputprice') {
  861. $('#buying_price').show();
  862. }
  863. if (linevalue == 'pmpprice') {
  864. $("#buying_price").val(pricevalue);
  865. $('#buying_price').hide();
  866. }
  867. });
  868. }
  869. },
  870. 'json');
  871. <?php
  872. }
  873. ?>
  874. <?php
  875. if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
  876. ?>
  877. /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
  878. var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
  879. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
  880. var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
  881. if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
  882. var pbqbase = $('option:selected', this).attr('data-pbqbase');
  883. if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
  884. var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
  885. if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
  886. var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
  887. if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
  888. if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
  889. {
  890. var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
  891. console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty upht = "+pbqupht+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
  892. jQuery("#pbq").val(pbq);
  893. jQuery("#price_ht").val(pbqupht);
  894. if (jQuery("#qty").val() < pbqqty)
  895. {
  896. jQuery("#qty").val(pbqqty);
  897. }
  898. if (jQuery("#remise_percent").val() < pbqpercent)
  899. {
  900. jQuery("#remise_percent").val(pbqpercent);
  901. }
  902. } else { jQuery("#pbq").val(''); }
  903. <?php
  904. }
  905. ?>
  906. // Deal with supplier ref price (idprodfournprice = int)
  907. if (jQuery('#idprodfournprice').val() > 0)
  908. {
  909. console.log("objectline_create.tpl #idprodfournprice is is an ID > 0, so we set some properties into page");
  910. var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
  911. if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
  912. var up_locale = $('option:selected', this).attr('data-up-locale'); // When select is done from HTML select
  913. if (typeof up_locale === 'undefined') { up_locale = jQuery('#idprodfournprice').attr('data-up-locale');} // When select is done from HTML input with ajax autocomplete
  914. var qty = parseFloat($('option:selected', this).attr('data-qty'));
  915. if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
  916. var discount = parseFloat($('option:selected', this).attr('data-discount'));
  917. if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
  918. var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
  919. if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
  920. var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
  921. if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
  922. var stringforvatrateselection = tva_tx;
  923. if (typeof default_vat_code != 'undefined' && default_vat_code != null) {
  924. stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
  925. }
  926. console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", qty = "+qty+", tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+", discount = "+discount+" for product supplier ref id = "+jQuery('#idprodfournprice').val());
  927. if (typeof up_locale === 'undefined') {
  928. jQuery("#price_ht").val(up);
  929. } else {
  930. jQuery("#price_ht").val(up_locale);
  931. }
  932. // Set vat rate if field is an input box
  933. $('#tva_tx').val(tva_tx);
  934. // Set vat rate by selecting the combo
  935. //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
  936. $('#tva_tx option').removeAttr('selected');
  937. console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
  938. $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
  939. if (jQuery("#qty").val() < qty) {
  940. jQuery("#qty").val(qty);
  941. }
  942. if (jQuery("#remise_percent").val() < discount) {
  943. jQuery("#remise_percent").val(discount);
  944. }
  945. <?php
  946. if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
  947. ?>
  948. var description = $('option:selected', this).attr('data-description');
  949. if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
  950. console.log("Load desciption into text area : "+description);
  951. <?php
  952. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
  953. ?>
  954. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  955. {
  956. var editor = CKEDITOR.instances['dp_desc'];
  957. if (editor) {
  958. editor.setData(description);
  959. }
  960. }
  961. <?php
  962. } else {
  963. ?>
  964. jQuery('#dp_desc').text(description);
  965. <?php
  966. }
  967. }
  968. ?>
  969. } else if (jQuery('#idprodfournprice').length > 0) {
  970. console.log("objectline_create.tpl #idprodfournprice is not an int but is a string so we set only few properties into page");
  971. var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
  972. if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
  973. var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
  974. if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
  975. var stringforvatrateselection = tva_tx;
  976. if (typeof default_vat_code != 'undefined' && default_vat_code != null) {
  977. stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
  978. }
  979. console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
  980. // Set vat rate if field is an input box
  981. $('#tva_tx').val(tva_tx);
  982. // Set vat rate by selecting the combo
  983. //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
  984. $('#tva_tx option').removeAttr('selected');
  985. console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
  986. $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
  987. <?php
  988. if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
  989. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
  990. ?>
  991. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  992. {
  993. var editor = CKEDITOR.instances['dp_desc'];
  994. if (editor) {
  995. editor.setData('');
  996. }
  997. }
  998. <?php
  999. } else {
  1000. ?>
  1001. jQuery('#dp_desc').text('');
  1002. <?php
  1003. }
  1004. }
  1005. ?>
  1006. }
  1007. /* To set focus */
  1008. if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
  1009. {
  1010. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  1011. jQuery('#dp_desc').focus();
  1012. /* focus if CKEDITOR */
  1013. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  1014. {
  1015. var editor = CKEDITOR.instances['dp_desc'];
  1016. if (editor) { editor.focus(); }
  1017. }
  1018. }
  1019. });
  1020. <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
  1021. setforpredef();
  1022. <?php } ?>
  1023. });
  1024. /* Function to set fields from choice */
  1025. function setforfree() {
  1026. console.log("objectline_create.tpl::setforfree. We show most fields");
  1027. jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
  1028. jQuery("#prod_entry_mode_free").prop('checked',true).change();
  1029. jQuery("#prod_entry_mode_predef").prop('checked',false).change();
  1030. jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
  1031. jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #multicurrency_price_ttc, #fourn_ref, #tva_tx, #buying_price, #title_fourn_ref, #title_vat, #title_up_ht, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").show();
  1032. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
  1033. jQuery("#fournprice_predef").hide();
  1034. }
  1035. function setforpredef() {
  1036. console.log("objectline_create.tpl::setforpredef We hide some fields, show dates");
  1037. jQuery("#select_type").val(-1);
  1038. jQuery("#prod_entry_mode_free").prop('checked',false).change();
  1039. jQuery("#prod_entry_mode_predef").prop('checked',true).change();
  1040. <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
  1041. jQuery("#price_ht").val('').show();
  1042. jQuery("#multicurrency_price_ht").val('').show();
  1043. jQuery("#title_up_ht, #title_up_ht_currency").show();
  1044. <?php } else { ?>
  1045. //jQuery("#price_ht").val('').hide();
  1046. jQuery("#multicurrency_price_ht").val('').hide();
  1047. jQuery("#title_up_ht, #title_up_ht_currency").hide();
  1048. <?php } ?>
  1049. <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICETTC)) { ?>
  1050. jQuery("#price_ttc").val('').show();
  1051. jQuery("#multicurrency_price_ttc").val('').show();
  1052. jQuery("#title_up_ttc, #title_up_ttc_currency").show();
  1053. <?php } else { ?>
  1054. jQuery("#price_ttc").val('').hide();
  1055. jQuery("#multicurrency_price_ttc").val('').hide();
  1056. jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
  1057. <?php } ?>
  1058. jQuery("#fourn_ref, #tva_tx, #title_vat").hide();
  1059. /* jQuery("#title_fourn_ref").hide(); */
  1060. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
  1061. jQuery("#buying_price").show();
  1062. jQuery('#trlinefordates, .divlinefordates').show();
  1063. }
  1064. <?php
  1065. print '</script>';
  1066. print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";