objectline_create.tpl.php 51 KB

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