objectline_create.tpl.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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 (!empty($conf->margin->enabled) && !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 (!empty($conf->multicurrency->enabled) && $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 (!empty($conf->asset->enabled) && $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 minwidth500imp">
  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 (!empty($conf->multicurrency->enabled) && $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)) { ?>
  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 minwidth500imp">
  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 (empty($conf->product->enabled) && empty($conf->service->enabled) && 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 && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
  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) && (empty($conf->product->enabled) || empty($conf->service->enabled)))?' 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 (empty($conf->product->enabled) || empty($conf->service->enabled)) {
  207. echo $langs->trans("Type");
  208. } else {
  209. echo $langs->trans("FreeLineOfType");
  210. }
  211. echo ' ';
  212. }
  213. }
  214. echo $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 (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  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 (!empty($conf->product->enabled) && empty($conf->service->enabled)) {
  230. $labelforradio = $langs->trans('PredefinedProductsToSell');
  231. } elseif ((empty($conf->product->enabled) && !empty($conf->service->enabled)) || ($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 (!empty($conf->product->enabled) && empty($conf->service->enabled)) {
  238. $labelforradio = $langs->trans('PredefinedProductsToPurchase');
  239. } elseif (empty($conf->product->enabled) && !empty($conf->service->enabled)) {
  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. if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
  258. // hide products in closed warehouse, but show products for internal transfer
  259. $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, 'warehouseopen,warehouseinternal', GETPOST('combinations', 'array'));
  260. } else {
  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, '', GETPOST('combinations', 'array'));
  262. }
  263. // Added by MMI Mathieu Moulin iProspective
  264. if (!empty($conf->global->MAIN_SHOW_ADDED_PRODUCT_LABEL))
  265. echo '<span id="added_labelprod"></span>';
  266. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS)) {
  267. ?>
  268. <script>
  269. $(document).ready(function(){
  270. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  271. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  272. console.log('focus on a select2');
  273. if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
  274. {
  275. console.log('open combo');
  276. $('#idprod').select2('open');
  277. }
  278. });
  279. });
  280. </script>
  281. <?php
  282. }
  283. } else {
  284. // $senderissupplier=2 is the same as 1 but disables test on minimum qty, disable autofill qty with minimum and autofill unit price
  285. if ($senderissupplier != 2) {
  286. $ajaxoptions = array(
  287. 'update' => array('qty'=>'qty', 'remise_percent' => 'discount', 'idprod' => 'idprod'), // html id tags that will be edited with each ajax json response key
  288. 'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
  289. 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for example shown we select a disabled option into combo)
  290. );
  291. $alsoproductwithnosupplierprice = 0;
  292. } else {
  293. $ajaxoptions = array(
  294. // Disabled: This is useless because setting discount and price_ht after a selection is already managed
  295. // by ths page itself with a .change on the combolist '#idprodfournprice'
  296. //'update' => array('remise_percent' => 'discount', 'price_ht' => 'price_ht') // html id tags that will be edited with each ajax json response key
  297. );
  298. $alsoproductwithnosupplierprice = 1;
  299. }
  300. $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'minwidth300imp maxwidth500');
  301. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS)) {
  302. ?>
  303. <script>
  304. $(document).ready(function(){
  305. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  306. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  307. //console.log('focus on a select2');
  308. if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
  309. {
  310. $('#idprodfournprice').select2('open');
  311. }
  312. });
  313. });
  314. </script>
  315. <?php
  316. }
  317. }
  318. echo '<input type="hidden" name="pbq" id="pbq" value="">';
  319. echo '</span>';
  320. }
  321. if (!empty($conf->global->MAIN_ADD_LINE_AT_POSITION)) {
  322. echo '<br>'.$langs->trans('AddLineOnPosition').' : <input type="number" name="rank" step="1" min="0" style="width: 5em;">';
  323. }
  324. if (is_object($hookmanager) && empty($senderissupplier)) {
  325. $parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
  326. $reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
  327. if (!empty($hookmanager->resPrint)) {
  328. print $hookmanager->resPrint;
  329. }
  330. }
  331. if (is_object($hookmanager) && !empty($senderissupplier)) {
  332. $parameters = array('htmlname'=>'addproduct');
  333. $reshook = $hookmanager->executeHooks('formCreateProductSupplierOptions', $parameters, $object, $action);
  334. if (!empty($hookmanager->resPrint)) {
  335. print $hookmanager->resPrint;
  336. }
  337. }
  338. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  339. echo '<br>';
  340. if (!empty($conf->variants->enabled)) {
  341. echo '<div id="attributes_box"></div>';
  342. }
  343. }
  344. // Editor wysiwyg
  345. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  346. $nbrows = ROWS_2;
  347. $enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
  348. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
  349. $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  350. }
  351. $toolbarname = 'dolibarr_details';
  352. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
  353. $toolbarname = 'dolibarr_notes';
  354. }
  355. $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%');
  356. $doleditor->Create();
  357. // Show autofill date for recurring invoices
  358. if (!empty($conf->service->enabled) && ($object->element == 'facturerec' || $object->element == 'invoice_supplier_rec')) {
  359. echo '<div class="divlinefordates"><br>';
  360. echo $langs->trans('AutoFillDateFrom').' ';
  361. if (!empty($conf->global->INVOICE_REC_DATE_TO_YES)) {
  362. $line->date_start_fill = 1;
  363. $line->date_end_fill = 1;
  364. }
  365. echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
  366. echo ' - ';
  367. echo $langs->trans('AutoFillDateTo').' ';
  368. echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
  369. echo '</div>';
  370. }
  371. if (is_object($objectline)) {
  372. $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
  373. if (!empty($temps)) {
  374. print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
  375. print $temps;
  376. print '</div>';
  377. }
  378. }
  379. echo '</td>';
  380. 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
  381. $coldisplay++;
  382. ?>
  383. <td class="nobottom linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth125 maxwidth125onsmartphone" value="<?php echo (GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>
  384. <?php }
  385. print '<td class="nobottom linecolvat right">';
  386. $coldisplay++;
  387. if ($seller->tva_assuj == "0") {
  388. echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
  389. } else {
  390. echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
  391. }
  392. ?>
  393. </td>
  394. <td class="nobottom linecoluht right"><?php $coldisplay++; ?>
  395. <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) : ''); ?>">
  396. </td>
  397. <?php
  398. if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
  399. $coldisplay++;
  400. ?>
  401. <td class="nobottom linecoluht_currency right">
  402. <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) : ''); ?>">
  403. </td>
  404. <?php
  405. }
  406. if (!empty($inputalsopricewithtax)) {
  407. $coldisplay++;
  408. ?>
  409. <td class="nobottom linecoluttc right">
  410. <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat" value="<?php echo (GETPOSTISSET("price_ttc") ? GETPOST("price_ttc", 'alpha', 2) : ''); ?>">
  411. </td>
  412. <?php
  413. }
  414. $coldisplay++;
  415. ?>
  416. <td class="nobottom linecolqty right"><input type="text" size="2" name="qty" id="qty" class="flat 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" size="1" name="remise_percent" id="remise_percent" class="flat right" value="<?php echo (GETPOSTISSET("remise_percent") ? GETPOST("remise_percent", 'alpha', 2) : $remise_percent); ?>"><span class="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="0" name="progress">%</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 (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { ?>
  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" type="text" size="2" id="np_marginRate" name="np_marginRate" value="'.(GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", 'alpha', 2) : '').'"><span class="np_marginRate 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" type="text" size="2" id="np_markRate" name="np_markRate" value="'.(GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : '').'"><span class="np_markRate 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 ((!empty($conf->service->enabled) || ($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, '%d/%m/%Y')); ?>").trigger('change');
  509. $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, '%d/%m/%Y')); ?>").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. <?php
  676. // Added by MMI Mathieu Moulin iProspective
  677. if (!empty($conf->global->MAIN_SHOW_ADDED_PRODUCT_LABEL)) { ?>
  678. $("#idprod").change(function()
  679. {
  680. var label = $(this).attr('data-label');
  681. $("#added_labelprod").html(label);
  682. });
  683. <?php
  684. }
  685. ?>
  686. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  687. $("#idprod, #idprodfournprice").change(function()
  688. {
  689. console.log("objectline_create.tpl Call method change() after change on #idprod or #idprodfournprice (senderissupplier=<?php echo $senderissupplier; ?>). this.val = "+$(this).val());
  690. setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
  691. jQuery('#trlinefordates').show();
  692. <?php
  693. if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier)) {
  694. ?>
  695. var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
  696. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
  697. if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
  698. {
  699. 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");
  700. } else {
  701. <?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
  702. 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"); }
  703. <?php } ?>
  704. // Get the HT price for the product and display it
  705. console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
  706. $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
  707. { 'id': $(this).val(), 'socid': <?php print $object->socid; ?> },
  708. function(data) {
  709. console.log("objectline_create.tpl Load unit price end, we got value "+data.price_ht);
  710. $('#date_start').removeAttr('type');
  711. $('#date_end').removeAttr('type');
  712. $('#date_start').attr('type', data.type);
  713. $('#date_end').attr('type', data.type);
  714. $('#date_start').removeAttr('mandatoryperiod');
  715. $('#date_end').removeAttr('mandatoryperiod');
  716. $('#date_start').attr('mandatoryperiod', data.mandatory_period);
  717. $('#date_end').attr('mandatoryperiod', data.mandatory_period);
  718. // service and we setted mandatory_period to true
  719. if (data.mandatory_period == 1 && data.type == 1) {
  720. jQuery('#date_start').addClass('inputmandatory');
  721. jQuery('#date_end').addClass('inputmandatory');
  722. }else{
  723. jQuery('#date_start').removeClass('inputmandatory');
  724. jQuery('#date_end').removeClass('inputmandatory');
  725. }
  726. console.log("objectline_create.tpl set content of price_ht");
  727. jQuery("#price_ht").val(data.price_ht);
  728. <?php
  729. if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
  730. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?>
  731. var proddesc = data.desc_trans;
  732. <?php
  733. } else { ?>
  734. var proddesc = data.desc;
  735. <?php
  736. } ?>
  737. console.log("objectline_create.tpl Load desciption into text area : "+proddesc);
  738. <?php
  739. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  740. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  741. {
  742. var editor = CKEDITOR.instances['dp_desc'];
  743. if (editor) {
  744. editor.setData(proddesc);
  745. }
  746. }
  747. <?php
  748. } else { ?>
  749. jQuery('#dp_desc').text(proddesc);
  750. <?php
  751. } ?>
  752. <?php
  753. } ?>
  754. <?php
  755. if (!empty($conf->global->PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES)) { ?>
  756. jQuery.each(data.array_options, function( key, value ) {
  757. jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value);
  758. });
  759. <?php
  760. } ?>
  761. },
  762. 'json'
  763. );
  764. }
  765. <?php
  766. }
  767. if (!empty($usemargins) && $user->rights->margins->creer) {
  768. $langs->load('stocks');
  769. ?>
  770. /* Code for margin */
  771. $("#fournprice_predef").find("option").remove();
  772. $("#fournprice_predef").hide();
  773. $("#buying_price").val("").show();
  774. /* Call post to load content of combo list fournprice_predef */
  775. var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
  776. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
  777. if (data && data.length > 0)
  778. {
  779. var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
  780. var bestpriceid = 0; var bestpricevalue = 0;
  781. var pmppriceid = 0; var pmppricevalue = 0;
  782. var costpriceid = 0; var costpricevalue = 0;
  783. /* setup of margin calculation */
  784. var defaultbuyprice = '<?php
  785. if (isset($conf->global->MARGIN_TYPE)) {
  786. if ($conf->global->MARGIN_TYPE == '1') {
  787. print 'bestsupplierprice';
  788. }
  789. if ($conf->global->MARGIN_TYPE == 'pmp') {
  790. print 'pmp';
  791. }
  792. if ($conf->global->MARGIN_TYPE == 'costprice') {
  793. print 'costprice';
  794. }
  795. } ?>';
  796. console.log("objectline_create.tpl we will set the field for margin. defaultbuyprice="+defaultbuyprice);
  797. var i = 0;
  798. $(data).each(function() {
  799. /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
  800. if (this.id != 'pmpprice' && this.id != 'costprice')
  801. {
  802. i++;
  803. this.price = parseFloat(this.price); // to fix when this.price >0
  804. // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
  805. //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
  806. 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
  807. }
  808. if (this.id == 'pmpprice')
  809. {
  810. // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
  811. console.log("id="+this.id+"-price="+this.price);
  812. if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
  813. {
  814. if (this.price > 0) {
  815. defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
  816. //console.log("pmppricevalue="+pmppricevalue);
  817. }
  818. }
  819. }
  820. if (this.id == 'costprice')
  821. {
  822. // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
  823. console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
  824. if ('costprice' == defaultbuyprice)
  825. {
  826. if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
  827. else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
  828. }
  829. }
  830. options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
  831. });
  832. options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
  833. console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
  834. $("#fournprice_predef").html(options).show();
  835. if (defaultkey != '')
  836. {
  837. $("#fournprice_predef").val(defaultkey);
  838. }
  839. /* At loading, no product are yet selected, so we hide field of buying_price */
  840. $("#buying_price").hide();
  841. /* Define default price at loading */
  842. var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
  843. $("#buying_price").val(defaultprice);
  844. $("#fournprice_predef").change(function() {
  845. console.log("change on fournprice_predef");
  846. /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
  847. var linevalue=$(this).find('option:selected').val();
  848. var pricevalue = $(this).find('option:selected').attr("price");
  849. if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
  850. $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
  851. }
  852. if (linevalue == 'inputprice') {
  853. $('#buying_price').show();
  854. }
  855. if (linevalue == 'pmpprice') {
  856. $("#buying_price").val(pricevalue);
  857. $('#buying_price').hide();
  858. }
  859. });
  860. }
  861. },
  862. 'json');
  863. <?php
  864. }
  865. ?>
  866. <?php
  867. if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {?>
  868. /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
  869. var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
  870. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
  871. var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
  872. if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
  873. var pbqbase = $('option:selected', this).attr('data-pbqbase');
  874. if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
  875. var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
  876. if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
  877. var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
  878. if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
  879. if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
  880. {
  881. var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
  882. 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);
  883. jQuery("#pbq").val(pbq);
  884. jQuery("#price_ht").val(pbqupht);
  885. if (jQuery("#qty").val() < pbqqty)
  886. {
  887. jQuery("#qty").val(pbqqty);
  888. }
  889. if (jQuery("#remise_percent").val() < pbqpercent)
  890. {
  891. jQuery("#remise_percent").val(pbqpercent);
  892. }
  893. } else { jQuery("#pbq").val(''); }
  894. <?php
  895. }
  896. ?>
  897. // Deal with supplier
  898. if (jQuery('#idprodfournprice').val() > 0)
  899. {
  900. console.log("objectline_create.tpl #idprodfournprice is > 0, so we set some properties into page");
  901. var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
  902. if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
  903. var up_locale = $('option:selected', this).attr('data-up-locale'); // When select is done from HTML select
  904. if (typeof up_locale === 'undefined') { up_locale = jQuery('#idprodfournprice').attr('data-up-locale');} // When select is done from HTML input with ajax autocomplete
  905. var qty = parseFloat($('option:selected', this).attr('data-qty'));
  906. if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
  907. var discount = parseFloat($('option:selected', this).attr('data-discount'));
  908. if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
  909. var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
  910. if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
  911. console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", qty = "+qty+", tva_tx = "+tva_tx+", discount = "+discount+" for product "+jQuery('#idprodfournprice').val());
  912. if (typeof up_locale === 'undefined') {
  913. jQuery("#price_ht").val(up);
  914. } else {
  915. jQuery("#price_ht").val(up_locale);
  916. }
  917. /* $('#tva_tx option').removeAttr('selected').filter('[value='+tva_tx+']').prop('selected', true); */
  918. $('#tva_tx option').val(tva_tx);
  919. if (jQuery("#qty").val() < qty) {
  920. jQuery("#qty").val(qty);
  921. }
  922. if (jQuery("#remise_percent").val() < discount) {
  923. jQuery("#remise_percent").val(discount);
  924. }
  925. <?php
  926. if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
  927. ?>
  928. var description = $('option:selected', this).attr('data-description');
  929. if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
  930. console.log("Load desciption into text area : "+description);
  931. <?php
  932. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  933. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  934. {
  935. var editor = CKEDITOR.instances['dp_desc'];
  936. if (editor) {
  937. editor.setData(description);
  938. }
  939. }
  940. <?php
  941. } else { ?>
  942. jQuery('#dp_desc').text(description);
  943. <?php
  944. }
  945. }?>
  946. } else if (jQuery('#idprodfournprice').length > 0) {
  947. <?php
  948. if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
  949. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  950. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  951. {
  952. var editor = CKEDITOR.instances['dp_desc'];
  953. if (editor) {
  954. editor.setData('');
  955. }
  956. }
  957. <?php
  958. } else { ?>
  959. jQuery('#dp_desc').text('');
  960. <?php
  961. }
  962. }?>
  963. }
  964. /* To set focus */
  965. if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
  966. {
  967. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  968. jQuery('#dp_desc').focus();
  969. /* focus if CKEDITOR */
  970. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  971. {
  972. var editor = CKEDITOR.instances['dp_desc'];
  973. if (editor) { editor.focus(); }
  974. }
  975. }
  976. });
  977. <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
  978. setforpredef();
  979. <?php } ?>
  980. });
  981. /* Function to set fields from choice */
  982. function setforfree() {
  983. console.log("objectline_create.tpl::setforfree. We show most fields");
  984. jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
  985. jQuery("#prod_entry_mode_free").prop('checked',true).change();
  986. jQuery("#prod_entry_mode_predef").prop('checked',false).change();
  987. jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
  988. 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();
  989. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
  990. jQuery("#fournprice_predef").hide();
  991. }
  992. function setforpredef() {
  993. console.log("objectline_create.tpl::setforpredef We hide some fields, show dates");
  994. jQuery("#select_type").val(-1);
  995. jQuery("#prod_entry_mode_free").prop('checked',false).change();
  996. jQuery("#prod_entry_mode_predef").prop('checked',true).change();
  997. <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
  998. jQuery("#price_ht").val('').show();
  999. jQuery("#multicurrency_price_ht").val('').show();
  1000. jQuery("#title_up_ht, #title_up_ht_currency").show();
  1001. <?php } else { ?>
  1002. //jQuery("#price_ht").val('').hide();
  1003. jQuery("#multicurrency_price_ht").val('').hide();
  1004. jQuery("#title_up_ht, #title_up_ht_currency").hide();
  1005. <?php } ?>
  1006. <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICETTC)) { ?>
  1007. jQuery("#price_ttc").val('').show();
  1008. jQuery("#multicurrency_price_ttc").val('').show();
  1009. jQuery("#title_up_ttc, #title_up_ttc_currency").show();
  1010. <?php } else { ?>
  1011. jQuery("#price_ttc").val('').hide();
  1012. jQuery("#multicurrency_price_ttc").val('').hide();
  1013. jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
  1014. <?php } ?>
  1015. jQuery("#fourn_ref, #tva_tx, #title_vat").hide();
  1016. /* jQuery("#title_fourn_ref").hide(); */
  1017. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
  1018. jQuery("#buying_price").show();
  1019. jQuery('#trlinefordates, .divlinefordates').show();
  1020. }
  1021. <?php
  1022. print '</script>';
  1023. print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";