objectline_create.tpl.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. *
  26. * Need to have following variables defined:
  27. * $object (invoice, order, ...)
  28. * $conf
  29. * $langs
  30. * $dateSelector
  31. * $forceall (0 by default, 1 for supplier invoices/orders)
  32. * $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
  33. * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
  34. */
  35. // Protection to avoid direct call of template
  36. if (empty($object) || !is_object($object)) {
  37. print "Error: this template page cannot be called directly as an URL";
  38. exit;
  39. }
  40. $usemargins = 0;
  41. if (!empty($conf->margin->enabled) && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande')))
  42. {
  43. $usemargins = 1;
  44. }
  45. if (!isset($dateSelector)) global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
  46. global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
  47. if (!isset($dateSelector)) $dateSelector = 1; // For backward compatibility
  48. elseif (empty($dateSelector)) $dateSelector = 0;
  49. if (empty($forceall)) $forceall = 0;
  50. if (empty($senderissupplier)) $senderissupplier = 0;
  51. if (empty($inputalsopricewithtax)) $inputalsopricewithtax = 0;
  52. // Define colspan for the button 'Add'
  53. $colspan = 3; // Columns: total ht + col edit + col delete
  54. if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan++; //Add column for Total (currency) if required
  55. if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier'))) $colspan++; // With this, there is a column move button
  56. //print $object->element;
  57. // Lines for extrafield
  58. $objectline = null;
  59. if (!empty($extrafields))
  60. {
  61. if ($this->table_element_line == 'commandedet') {
  62. $objectline = new OrderLine($this->db);
  63. } elseif ($this->table_element_line == 'propaldet') {
  64. $objectline = new PropaleLigne($this->db);
  65. } elseif ($this->table_element_line == 'supplier_proposaldet') {
  66. $objectline = new SupplierProposalLine($this->db);
  67. } elseif ($this->table_element_line == 'facturedet') {
  68. $objectline = new FactureLigne($this->db);
  69. } elseif ($this->table_element_line == 'contratdet') {
  70. $objectline = new ContratLigne($this->db);
  71. } elseif ($this->table_element_line == 'commande_fournisseurdet') {
  72. $objectline = new CommandeFournisseurLigne($this->db);
  73. } elseif ($this->table_element_line == 'facture_fourn_det') {
  74. $objectline = new SupplierInvoiceLine($this->db);
  75. } elseif ($this->table_element_line == 'facturedet_rec') {
  76. $objectline = new FactureLigneRec($this->db);
  77. }
  78. }
  79. print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
  80. $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
  81. if ($nolinesbefore) {
  82. ?>
  83. <tr class="liste_titre<?php echo (($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_add_') ?> nodrag nodrop">
  84. <?php if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
  85. <td class="linecolnum center"></td>
  86. <?php } ?>
  87. <td class="linecoldescription minwidth500imp">
  88. <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span>
  89. </td>
  90. <?php
  91. if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
  92. {
  93. ?>
  94. <td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
  95. <?php
  96. }
  97. ?>
  98. <td class="linecolvat right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
  99. <td class="linecoluht right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
  100. <?php if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?>
  101. <td class="linecoluht_currency right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
  102. <?php } ?>
  103. <?php if (!empty($inputalsopricewithtax)) { ?>
  104. <td class="linecoluttc right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
  105. <?php } ?>
  106. <td class="linecolqty right"><?php echo $langs->trans('Qty'); ?></td>
  107. <?php
  108. if (!empty($conf->global->PRODUCT_USE_UNITS))
  109. {
  110. print '<td class="linecoluseunit left">';
  111. print '<span id="title_units">';
  112. print $langs->trans('Unit');
  113. print '</span></td>';
  114. }
  115. ?>
  116. <td class="linecoldiscount right"><?php echo $langs->trans('ReductionShort'); ?></td>
  117. <?php
  118. // Fields for situation invoice
  119. if ($this->situation_cycle_ref) {
  120. print '<td class="linecolcycleref right">'.$langs->trans('Progress').'</td>';
  121. print '<td class="linecolcycleref2 right"></td>';
  122. }
  123. if (!empty($usemargins))
  124. {
  125. if (empty($user->rights->margins->creer)) {
  126. $colspan++;
  127. } else {
  128. print '<td class="margininfos linecolmargin1 right">';
  129. if ($conf->global->MARGIN_TYPE == "1")
  130. echo $langs->trans('BuyingPrice');
  131. else echo $langs->trans('CostPrice');
  132. echo '</td>';
  133. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) echo '<td class="margininfos linecolmargin2 right"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
  134. if (!empty($conf->global->DISPLAY_MARK_RATES)) echo '<td class="margininfos linecolmargin2 right"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
  135. }
  136. }
  137. ?>
  138. <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
  139. </tr>
  140. <?php
  141. }
  142. ?>
  143. <tr class="pair nodrag nodrop nohoverpair<?php echo ($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create'; ?>">
  144. <?php
  145. $coldisplay = 0;
  146. // Adds a line numbering column
  147. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  148. $coldisplay++;
  149. echo '<td class="nobottom linecolnum center"></td>';
  150. }
  151. $coldisplay++;
  152. ?>
  153. <td class="nobottom linecoldescription minwidth500imp">
  154. <?php
  155. $freelines = false;
  156. if (empty($conf->global->MAIN_DISABLE_FREE_LINES))
  157. {
  158. $freelines = true;
  159. $forceall = 1; // We always force all type for free lines (module product or service means we use predefined product or service)
  160. if ($object->element == 'contrat')
  161. {
  162. if (empty($conf->product->enabled) && empty($conf->service->enabled) && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $forceall = -1; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
  163. elseif (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $forceall = 3;
  164. }
  165. // Free line
  166. echo '<span class="prod_entry_mode_free">';
  167. // Show radio free line
  168. if ($forceall >= 0 && (!empty($conf->product->enabled) || !empty($conf->service->enabled)))
  169. {
  170. echo '<label for="prod_entry_mode_free">';
  171. echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
  172. //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (empty($conf->product->enabled) || empty($conf->service->enabled)))?' checked':'') );
  173. echo ((GETPOST('prod_entry_mode', 'alpha') == 'free' || !empty($conf->global->MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT)) ? ' checked' : '');
  174. echo '> ';
  175. // Show type selector
  176. echo $langs->trans("FreeLineOfType");
  177. echo '</label>';
  178. echo ' ';
  179. } else {
  180. echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
  181. // Show type selector
  182. if ($forceall >= 0)
  183. {
  184. if (empty($conf->product->enabled) || empty($conf->service->enabled)) echo $langs->trans("Type");
  185. else echo $langs->trans("FreeLineOfType");
  186. echo ' ';
  187. }
  188. }
  189. echo $form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', 1, 1, $forceall);
  190. echo '</span>';
  191. }
  192. // Predefined product/service
  193. if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
  194. {
  195. if ($forceall >= 0 && $freelines) echo '<br>';
  196. echo '<span class="prod_entry_mode_predef">';
  197. echo '<label for="prod_entry_mode_predef">';
  198. 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' : '').'> ';
  199. if (empty($senderissupplier))
  200. {
  201. if (!empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToSell');
  202. elseif ((empty($conf->product->enabled) && !empty($conf->service->enabled)) || ($object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS))) echo $langs->trans('PredefinedServicesToSell');
  203. else echo $langs->trans('PredefinedProductsAndServicesToSell');
  204. } else {
  205. if (!empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToPurchase');
  206. elseif (empty($conf->product->enabled) && !empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToPurchase');
  207. else echo $langs->trans('PredefinedProductsAndServicesToPurchase');
  208. }
  209. echo '</label>';
  210. echo ' ';
  211. $filtertype = '';
  212. if (!empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $filtertype = '1';
  213. if (empty($senderissupplier))
  214. {
  215. $statustoshow = 1;
  216. if (!empty($conf->global->ENTREPOT_EXTRA_STATUS))
  217. {
  218. // hide products in closed warehouse, but show products for internal transfer
  219. $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'));
  220. } else {
  221. $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'));
  222. }
  223. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS))
  224. {
  225. ?>
  226. <script>
  227. $(document).ready(function(){
  228. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  229. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  230. console.log('focus on a select2');
  231. if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
  232. {
  233. console.log('open combo');
  234. $('#idprod').select2('open');
  235. }
  236. });
  237. });
  238. </script>
  239. <?php
  240. }
  241. } else {
  242. // $senderissupplier=2 is the same as 1 but disables test on minimum qty and disable autofill qty with minimum
  243. if ($senderissupplier != 2)
  244. {
  245. $ajaxoptions = array(
  246. 'update' => array('qty'=>'qty', 'remise_percent' => 'discount', 'idprod' => 'idprod'), // html id tags that will be edited with each ajax json response key
  247. 'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
  248. 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for example shown we select a disabled option into combo)
  249. );
  250. $alsoproductwithnosupplierprice = 0;
  251. } else {
  252. $ajaxoptions = array(
  253. 'update' => array('remise_percent' => 'discount') // html id tags that will be edited with each ajax json response key
  254. );
  255. $alsoproductwithnosupplierprice = 1;
  256. }
  257. $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'maxwidth500');
  258. if (!empty($conf->global->MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS))
  259. {
  260. ?>
  261. <script>
  262. $(document).ready(function(){
  263. // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
  264. $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  265. //console.log('focus on a select2');
  266. if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
  267. {
  268. $('#idprodfournprice').select2('open');
  269. }
  270. });
  271. });
  272. </script>
  273. <?php
  274. }
  275. }
  276. echo '<input type="hidden" name="pbq" id="pbq" value="">';
  277. echo '</span>';
  278. }
  279. if (is_object($hookmanager) && empty($senderissupplier))
  280. {
  281. $parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
  282. $reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
  283. if (!empty($hookmanager->resPrint)) {
  284. print $hookmanager->resPrint;
  285. }
  286. }
  287. if (is_object($hookmanager) && !empty($senderissupplier))
  288. {
  289. $parameters = array('htmlname'=>'addproduct');
  290. $reshook = $hookmanager->executeHooks('formCreateProductSupplierOptions', $parameters, $object, $action);
  291. if (!empty($hookmanager->resPrint)) {
  292. print $hookmanager->resPrint;
  293. }
  294. }
  295. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  296. if (!empty($conf->variants->enabled)) {
  297. echo '<div id="attributes_box"></div>';
  298. }
  299. echo '<br>';
  300. }
  301. // Editor wysiwyg
  302. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  303. $nbrows = ROWS_2;
  304. $enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
  305. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  306. $toolbarname = 'dolibarr_details';
  307. if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname = 'dolibarr_notes';
  308. $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%');
  309. $doleditor->Create();
  310. // Show autofill date for recurring invoices
  311. if (!empty($conf->service->enabled) && $object->element == 'facturerec')
  312. {
  313. echo '<div class="divlinefordates"><br>';
  314. echo $langs->trans('AutoFillDateFrom').' ';
  315. echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
  316. echo ' - ';
  317. echo $langs->trans('AutoFillDateTo').' ';
  318. echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
  319. echo '</div>';
  320. }
  321. echo '</td>';
  322. if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
  323. {
  324. $coldisplay++;
  325. ?>
  326. <td class="nobottom linecolresupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth150" value="<?php echo (GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>
  327. <?php }
  328. print '<td class="nobottom linecolvat right">';
  329. $coldisplay++;
  330. if ($seller->tva_assuj == "0") echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
  331. else echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
  332. ?>
  333. </td>
  334. <td class="nobottom linecoluht right"><?php $coldisplay++; ?>
  335. <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) : ''); ?>">
  336. </td>
  337. <?php
  338. if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
  339. $coldisplay++;
  340. ?>
  341. <td class="nobottom linecoluht_currency right">
  342. <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) : ''); ?>">
  343. </td>
  344. <?php
  345. }
  346. if (!empty($inputalsopricewithtax)) {
  347. $coldisplay++;
  348. ?>
  349. <td class="nobottom linecoluttc right">
  350. <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat" value="<?php echo (GETPOSTISSET("price_ttc") ? GETPOST("price_ttc", 'alpha', 2) : ''); ?>">
  351. </td>
  352. <?php
  353. }
  354. $coldisplay++;
  355. ?>
  356. <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); ?>">
  357. </td>
  358. <?php
  359. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  360. $coldisplay++;
  361. print '<td class="nobottom linecoluseunit left">';
  362. print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, "units");
  363. print '</td>';
  364. }
  365. $remise_percent = $buyer->remise_percent;
  366. if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
  367. $remise_percent = $seller->remise_supplier_percent;
  368. }
  369. $coldisplay++;
  370. ?>
  371. <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>
  372. <?php
  373. if ($this->situation_cycle_ref) {
  374. $coldisplay++;
  375. print '<td class="nobottom nowrap right"><input class="falt right" type="text" size="1" value="0" name="progress">%</td>';
  376. $coldisplay++;
  377. print '<td></td>';
  378. }
  379. if (!empty($usemargins)) {
  380. if (!empty($user->rights->margins->creer)) {
  381. $coldisplay++;
  382. ?>
  383. <td class="nobottom margininfos linecolmargin right">
  384. <!-- For predef product -->
  385. <?php if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { ?>
  386. <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp" style="display: none;"></select>
  387. <?php } ?>
  388. <!-- For free product -->
  389. <input type="text" id="buying_price" name="buying_price" class="flat maxwidth75 right" value="<?php echo (GETPOSTISSET("buying_price") ? GETPOST("buying_price", 'alpha', 2) : ''); ?>">
  390. </td>
  391. <?php
  392. if (!empty($conf->global->DISPLAY_MARGIN_RATES))
  393. {
  394. echo '<td class="nobottom nowrap 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>';
  395. $coldisplay++;
  396. }
  397. if (!empty($conf->global->DISPLAY_MARK_RATES))
  398. {
  399. echo '<td class="nobottom nowrap 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>';
  400. $coldisplay++;
  401. }
  402. }
  403. }
  404. $coldisplay += $colspan;
  405. ?>
  406. <td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>">
  407. <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
  408. </td>
  409. </tr>
  410. <?php
  411. if (is_object($objectline)) {
  412. print $objectline->showOptionals($extrafields, 'edit', array('colspan'=>$coldisplay), '', '', 1);
  413. }
  414. if ((!empty($conf->service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required
  415. {
  416. print '<tr id="trlinefordates" class="oddeven">'."\n";
  417. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  418. print '<td></td>';
  419. }
  420. print '<td colspan="'.($coldisplay - (empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? 0 : 1)).'">';
  421. $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  422. $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  423. $prefillDates = false;
  424. if (!empty($conf->global->MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE) && !empty($object->lines))
  425. {
  426. for ($i = count($object->lines) - 1; $i >= 0; $i--)
  427. {
  428. $lastline = $object->lines[$i];
  429. if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end)))
  430. {
  431. $date_start_prefill = $lastline->date_start;
  432. $date_end_prefill = $lastline->date_end;
  433. $prefillDates = true;
  434. break;
  435. }
  436. }
  437. }
  438. if (!empty($object->element) && $object->element == 'contrat')
  439. {
  440. print $langs->trans("DateStartPlanned").' ';
  441. print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
  442. print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
  443. print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
  444. } else {
  445. print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
  446. 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);
  447. print ' '.$langs->trans('to').' ';
  448. 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);
  449. };
  450. if ($prefillDates)
  451. {
  452. echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
  453. }
  454. print '<script>';
  455. if ($prefillDates)
  456. {
  457. ?>
  458. function prefill_service_dates()
  459. {
  460. $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, '%d/%m/%Y')); ?>").trigger('change');
  461. $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, '%d/%m/%Y')); ?>").trigger('change');
  462. return false; // Prevent default link behaviour (which is go to href URL)
  463. }
  464. $(document).ready(function()
  465. {
  466. $('#prefill_service_dates').click(prefill_service_dates);
  467. });
  468. <?php
  469. }
  470. if (!$date_start) {
  471. if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
  472. print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
  473. }
  474. if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
  475. print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
  476. }
  477. }
  478. if (!$date_end) {
  479. if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
  480. print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
  481. }
  482. if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
  483. print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
  484. }
  485. }
  486. print '</script>';
  487. print '</td>';
  488. print '</tr>'."\n";
  489. }
  490. print "<script>\n";
  491. if (!empty($usemargins) && $user->rights->margins->creer)
  492. {
  493. ?>
  494. /* Some js test when we click on button "Add" */
  495. jQuery(document).ready(function() {
  496. <?php
  497. if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
  498. $("input[name='np_marginRate']:first").blur(function(e) {
  499. return checkFreeLine(e, "np_marginRate");
  500. });
  501. <?php
  502. }
  503. if (!empty($conf->global->DISPLAY_MARK_RATES)) { ?>
  504. $("input[name='np_markRate']:first").blur(function(e) {
  505. return checkFreeLine(e, "np_markRate");
  506. });
  507. <?php
  508. }
  509. ?>
  510. });
  511. /* TODO This does not work for number with thousand separator that is , */
  512. function checkFreeLine(e, npRate)
  513. {
  514. var buying_price = $("input[name='buying_price']:first");
  515. var remise = $("input[name='remise_percent']:first");
  516. var rate = $("input[name='"+npRate+"']:first");
  517. if (rate.val() == '')
  518. return true;
  519. if (! $.isNumeric(rate.val().replace(',','.')))
  520. {
  521. alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
  522. e.stopPropagation();
  523. setTimeout(function () { rate.focus() }, 50);
  524. return false;
  525. }
  526. if (npRate == "np_markRate" && rate.val() >= 100)
  527. {
  528. alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
  529. e.stopPropagation();
  530. setTimeout(function () { rate.focus() }, 50);
  531. return false;
  532. }
  533. var price = 0;
  534. remisejs=price2numjs(remise.val());
  535. if (remisejs != 100) // If a discount not 100 or no discount
  536. {
  537. if (remisejs == '') remisejs=0;
  538. bpjs=price2numjs(buying_price.val());
  539. ratejs=price2numjs(rate.val());
  540. if (npRate == "np_marginRate")
  541. price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
  542. else if (npRate == "np_markRate")
  543. price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
  544. }
  545. $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
  546. return true;
  547. }
  548. <?php
  549. }
  550. ?>
  551. /* JQuery for product free or predefined select */
  552. jQuery(document).ready(function() {
  553. jQuery("#price_ht").keyup(function(event) {
  554. // console.log(event.which); // discard event tag and arrows
  555. if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
  556. jQuery("#price_ttc").val('');
  557. jQuery("#multicurrency_subprice").val('');
  558. }
  559. });
  560. jQuery("#price_ttc").keyup(function(event) {
  561. // console.log(event.which); // discard event tag and arrows
  562. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  563. jQuery("#price_ht").val('');
  564. jQuery("#multicurrency_subprice").val('');
  565. }
  566. });
  567. jQuery("#multicurrency_subprice").keyup(function(event) {
  568. // console.log(event.which); // discard event tag and arrows
  569. if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
  570. jQuery("#price_ht").val('');
  571. jQuery("#price_ttc").val('');
  572. }
  573. });
  574. $("#prod_entry_mode_free").on( "click", function() {
  575. setforfree();
  576. });
  577. $("#select_type").change(function()
  578. {
  579. setforfree();
  580. if (jQuery('#select_type').val() >= 0)
  581. {
  582. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  583. jQuery('#dp_desc').focus();
  584. /* focus if CKEDITOR */
  585. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  586. {
  587. var editor = CKEDITOR.instances['dp_desc'];
  588. if (editor) { editor.focus(); }
  589. }
  590. }
  591. console.log("Hide/show date according to product type");
  592. if (jQuery('#select_type').val() == '0')
  593. {
  594. jQuery('#trlinefordates').hide();
  595. jQuery('.divlinefordates').hide();
  596. }
  597. else
  598. {
  599. jQuery('#trlinefordates').show();
  600. jQuery('.divlinefordates').show();
  601. }
  602. });
  603. $("#prod_entry_mode_predef").on( "click", function() {
  604. console.log("click prod_entry_mode_predef");
  605. setforpredef();
  606. jQuery('#trlinefordates').show();
  607. });
  608. <?php
  609. if (!$freelines) { ?>
  610. $("#prod_entry_mode_predef").click();
  611. <?php
  612. }
  613. ?>
  614. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  615. $("#idprod, #idprodfournprice").change(function()
  616. {
  617. console.log("Call method change() after change on #idprod or #idprodfournprice. this.val = "+$(this).val());
  618. setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
  619. jQuery('#trlinefordates').show();
  620. <?php
  621. if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier))
  622. {
  623. ?>
  624. var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
  625. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
  626. //console.log(pbq);
  627. if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
  628. {
  629. console.log("We are in a price per qty context, we do not call ajax/product, init of fields is done few lines later");
  630. } else {
  631. <?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
  632. 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"); }
  633. <?php } ?>
  634. // Get the HT price for the product and display it
  635. console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
  636. $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
  637. { 'id': $(this).val(), 'socid': <?php print $object->socid; ?> },
  638. function(data) {
  639. console.log("Load unit price end, we got value "+data.price_ht);
  640. jQuery("#price_ht").val(data.price_ht);
  641. },
  642. 'json'
  643. );
  644. }
  645. <?php
  646. }
  647. if (!empty($usemargins) && $user->rights->margins->creer)
  648. {
  649. $langs->load('stocks');
  650. ?>
  651. /* Code for margin */
  652. $("#fournprice_predef").find("option").remove();
  653. $("#fournprice_predef").hide();
  654. $("#buying_price").val("").show();
  655. /* Call post to load content of combo list fournprice_predef */
  656. var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
  657. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
  658. if (data && data.length > 0)
  659. {
  660. var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
  661. var bestpriceid = 0; var bestpricevalue = 0;
  662. var pmppriceid = 0; var pmppricevalue = 0;
  663. var costpriceid = 0; var costpricevalue = 0;
  664. /* setup of margin calculation */
  665. var defaultbuyprice = '<?php
  666. if (isset($conf->global->MARGIN_TYPE))
  667. {
  668. if ($conf->global->MARGIN_TYPE == '1') print 'bestsupplierprice';
  669. if ($conf->global->MARGIN_TYPE == 'pmp') print 'pmp';
  670. if ($conf->global->MARGIN_TYPE == 'costprice') print 'costprice';
  671. } ?>';
  672. console.log("we will set the field for margin. defaultbuyprice="+defaultbuyprice);
  673. var i = 0;
  674. $(data).each(function() {
  675. /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
  676. if (this.id != 'pmpprice' && this.id != 'costprice')
  677. {
  678. i++;
  679. this.price = parseFloat(this.price); // to fix when this.price >0
  680. // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
  681. //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
  682. 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
  683. }
  684. if (this.id == 'pmpprice')
  685. {
  686. // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
  687. console.log("id="+this.id+"-price="+this.price);
  688. if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
  689. {
  690. if (this.price > 0) {
  691. defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
  692. //console.log("pmppricevalue="+pmppricevalue);
  693. }
  694. }
  695. }
  696. if (this.id == 'costprice')
  697. {
  698. // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
  699. console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
  700. if ('costprice' == defaultbuyprice)
  701. {
  702. if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
  703. else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
  704. }
  705. }
  706. options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
  707. });
  708. options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
  709. console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
  710. $("#fournprice_predef").html(options).show();
  711. if (defaultkey != '')
  712. {
  713. $("#fournprice_predef").val(defaultkey);
  714. }
  715. /* At loading, no product are yet selected, so we hide field of buying_price */
  716. $("#buying_price").hide();
  717. /* Define default price at loading */
  718. var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
  719. $("#buying_price").val(defaultprice);
  720. $("#fournprice_predef").change(function() {
  721. console.log("change on fournprice_predef");
  722. /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
  723. var linevalue=$(this).find('option:selected').val();
  724. var pricevalue = $(this).find('option:selected').attr("price");
  725. if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
  726. $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
  727. }
  728. if (linevalue == 'inputprice') {
  729. $('#buying_price').show();
  730. }
  731. if (linevalue == 'pmpprice') {
  732. $("#buying_price").val(pricevalue);
  733. $('#buying_price').hide();
  734. }
  735. });
  736. }
  737. },
  738. 'json');
  739. <?php
  740. }
  741. ?>
  742. /* To process customer price per quantity (CUSTOMER_PRICE_PER_QTY works only if combo product is not an ajax after x key pressed) */
  743. var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
  744. if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
  745. var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
  746. if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
  747. var pbqbase = $('option:selected', this).attr('data-pbqbase');
  748. if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
  749. var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
  750. if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
  751. var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
  752. if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
  753. if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
  754. {
  755. var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
  756. 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);
  757. jQuery("#pbq").val(pbq);
  758. jQuery("#price_ht").val(pbqupht);
  759. if (jQuery("#qty").val() < pbqqty)
  760. {
  761. jQuery("#qty").val(pbqqty);
  762. }
  763. if (jQuery("#remise_percent").val() < pbqpercent)
  764. {
  765. jQuery("#remise_percent").val(pbqpercent);
  766. }
  767. }
  768. else
  769. {
  770. jQuery("#pbq").val('');
  771. }
  772. /* To set focus */
  773. if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
  774. {
  775. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  776. jQuery('#dp_desc').focus();
  777. /* focus if CKEDITOR */
  778. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  779. {
  780. var editor = CKEDITOR.instances['dp_desc'];
  781. if (editor) { editor.focus(); }
  782. }
  783. }
  784. });
  785. <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
  786. setforpredef();
  787. <?php } ?>
  788. });
  789. /* Function to set fields from choice */
  790. function setforfree() {
  791. console.log("Call setforfree. We show most fields");
  792. jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
  793. jQuery("#prod_entry_mode_free").prop('checked',true).change();
  794. jQuery("#prod_entry_mode_predef").prop('checked',false).change();
  795. jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
  796. jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #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();
  797. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
  798. jQuery("#fournprice_predef").hide();
  799. }
  800. function setforpredef() {
  801. console.log("Call setforpredef. We hide some fields and show dates");
  802. jQuery("#select_type").val(-1);
  803. jQuery("#prod_entry_mode_free").prop('checked',false).change();
  804. jQuery("#prod_entry_mode_predef").prop('checked',true).change();
  805. <?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT)) { ?>
  806. jQuery("#price_ht").val('').show();
  807. jQuery("#multicurrency_price_ht").val('').show();
  808. jQuery("#title_up_ht, #title_up_ht_currency").show();
  809. <?php } else { ?>
  810. jQuery("#price_ht").val('').hide();
  811. jQuery("#multicurrency_price_ht").val('').hide();
  812. jQuery("#title_up_ht, #title_up_ht_currency").hide();
  813. <?php } ?>
  814. jQuery("#price_ttc, #fourn_ref, #tva_tx, #title_fourn_ref, #title_vat, #title_up_ttc, #title_up_ttc_currency").hide();
  815. jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
  816. jQuery("#buying_price").show();
  817. jQuery('#trlinefordates, .divlinefordates').show();
  818. }
  819. <?php
  820. print '</script>';
  821. print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";