objectline_create.tpl.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.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 Marcos García <marcosgdf@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * Need to have following variables defined:
  24. * $object (invoice, order, ...)
  25. * $conf
  26. * $langs
  27. * $dateSelector
  28. * $forceall (0 by default, 1 for supplier invoices/orders)
  29. * $senderissupplier (0 by default, 1 for supplier invoices/orders)
  30. * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
  31. */
  32. $usemargins=0;
  33. if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande')))
  34. {
  35. $usemargins=1;
  36. }
  37. global $forceall, $senderissupplier, $inputalsopricewithtax;
  38. if (empty($dateSelector)) $dateSelector=0;
  39. if (empty($forceall)) $forceall=0;
  40. if (empty($senderissupplier)) $senderissupplier=0;
  41. if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
  42. // Define colspan for button Add
  43. $colspan = 3; // Col total ht + col edit + col delete
  44. if (in_array($object->element,array('propal', 'supplier_proposal','facture','facturerec','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
  45. //print $object->element;
  46. ?>
  47. <!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->
  48. <tr class="liste_titre liste_titre_add nodrag nodrop">
  49. <td class="linecoldescription" <?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
  50. <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span><?php // echo $langs->trans("FreeZone"); ?>
  51. </td>
  52. <?php if ($object->element == 'supplier_proposal') { ?>
  53. <td class="linecolrefsupplier" align="right"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierProposalRefFourn'); ?></span></td>
  54. <?php } ?>
  55. <td class="linecolvat" align="right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
  56. <td class="linecoluht" align="right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
  57. <?php if (!empty($conf->multicurrency->enabled)) { $colspan++;?>
  58. <td class="linecoluht_currency" align="right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
  59. <?php } ?>
  60. <?php if (! empty($inputalsopricewithtax)) { ?>
  61. <td class="linecoluttc" align="right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
  62. <?php } ?>
  63. <td class="linecolqty" align="right"><?php echo $langs->trans('Qty'); ?></td>
  64. <?php
  65. if($conf->global->PRODUCT_USE_UNITS)
  66. {
  67. print '<td class="linecoluseunit" align="left">';
  68. print '<span id="title_units">';
  69. print $langs->trans('Unit');
  70. print '</span></td>';
  71. }
  72. ?>
  73. <td class="linecoldiscount" align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
  74. <?php
  75. if ($this->situation_cycle_ref) {
  76. print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
  77. }
  78. if (! empty($usemargins))
  79. {
  80. ?>
  81. <td align="right" class="margininfos linecolmargin1">
  82. <?php
  83. if ($conf->global->MARGIN_TYPE == "1")
  84. echo $langs->trans('BuyingPrice');
  85. else
  86. echo $langs->trans('CostPrice');
  87. ?>
  88. </td>
  89. <?php
  90. if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
  91. if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
  92. }
  93. ?>
  94. <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
  95. </tr>
  96. <tr <?php echo $bcnd[$var]; ?>>
  97. <?php
  98. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  99. $coldisplay=2; }
  100. else {
  101. $coldisplay=0; }
  102. ?>
  103. <td class="nobottom linecoldescription"<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
  104. <?php
  105. $forceall=1; // We always force all type for free lines (module product or service means we use predefined product or service)
  106. if ($object->element == 'contrat')
  107. {
  108. 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
  109. else $forceall=0;
  110. }
  111. // Free line
  112. echo '<span class="prod_entry_mode_free">';
  113. // Show radio free line
  114. if ($forceall >= 0 && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
  115. {
  116. echo '<label for="prod_entry_mode_free">';
  117. echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
  118. //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (empty($conf->product->enabled) || empty($conf->service->enabled)))?' checked':'') );
  119. echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : '');
  120. echo '> ';
  121. // Show type selector
  122. echo $langs->trans("FreeLineOfType");
  123. echo '</label>';
  124. echo ' ';
  125. }
  126. else
  127. {
  128. echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
  129. // Show type selector
  130. if ($forceall >= 0)
  131. {
  132. if (empty($conf->product->enabled) || empty($conf->service->enabled)) echo $langs->trans("Type");
  133. else echo $langs->trans("FreeLineOfType");
  134. echo ' ';
  135. }
  136. }
  137. echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,1,$forceall);
  138. echo '</span>';
  139. // Predefined product/service
  140. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
  141. {
  142. if ($forceall >= 0) echo '<br>';
  143. echo '<span class="prod_entry_mode_predef">';
  144. echo '<label for="prod_entry_mode_predef">';
  145. 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':'').'> ';
  146. if (empty($senderissupplier))
  147. {
  148. if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToSell');
  149. else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToSell');
  150. else echo $langs->trans('PredefinedProductsAndServicesToSell');
  151. }
  152. else
  153. {
  154. if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToPurchase');
  155. else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToPurchase');
  156. else echo $langs->trans('PredefinedProductsAndServicesToPurchase');
  157. }
  158. echo '</label>';
  159. echo ' ';
  160. $filtertype='';
  161. if (! empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $filtertype='1';
  162. if (empty($senderissupplier))
  163. {
  164. $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(),$buyer->id);
  165. }
  166. else
  167. {
  168. $ajaxoptions=array(
  169. 'update' => array('qty'=>'qty','remise_percent' => 'discount','idprod' => 'idprod'), // html id tags that will be edited with which ajax json response key
  170. 'option_disabled' => 'addPredefinedProductButton', // html id to disable once select is done
  171. 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'error'
  172. );
  173. $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1);
  174. }
  175. echo '</span>';
  176. }
  177. if (is_object($hookmanager) && empty($senderissupplier))
  178. {
  179. $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int'));
  180. $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action);
  181. if (!empty($hookmanager->resPrint)) {
  182. print $hookmanager->resPrint;
  183. }
  184. }
  185. if (is_object($hookmanager) && ! empty($senderissupplier))
  186. {
  187. $parameters=array('htmlname'=>'addproduct');
  188. $reshook=$hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action);
  189. if (!empty($hookmanager->resPrint)) {
  190. print $hookmanager->resPrint;
  191. }
  192. }
  193. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) echo '<br>';
  194. // Editor wysiwyg
  195. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  196. $nbrows=ROWS_2;
  197. $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
  198. if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
  199. $toolbarname='dolibarr_details';
  200. if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes';
  201. $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,$toolbarname,'',false,true,$enabled,$nbrows,'98%');
  202. $doleditor->Create();
  203. ?>
  204. </td>
  205. <?php if ($object->element == 'supplier_proposal') { ?>
  206. <td class="nobottom linecolresupplier" align="right"><input id="fourn_ref" name="fourn_ref" class="flat" value="" size="12"></td>
  207. <?php } ?>
  208. <td class="nobottom linecolvat" align="right"><?php
  209. if ($seller->tva_assuj == "0") echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
  210. else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer, 0, 0, '', false, 1);
  211. ?>
  212. </td>
  213. <td class="nobottom linecoluht" align="right">
  214. <input type="text" size="5" name="price_ht" id="price_ht" class="flat" value="<?php echo (isset($_POST["price_ht"])?$_POST["price_ht"]:''); ?>">
  215. </td>
  216. <?php if (!empty($conf->multicurrency->enabled)) { $colspan++;?>
  217. <td class="nobottom linecoluht_currency" align="right">
  218. <input type="text" size="5" name="multicurrency_price_ht" id="multicurrency_price_ht" class="flat" value="<?php echo (isset($_POST["multicurrency_price_ht"])?$_POST["multicurrency_price_ht"]:''); ?>">
  219. </td>
  220. <?php } ?>
  221. <?php if (! empty($inputalsopricewithtax)) { ?>
  222. <td class="nobottom linecoluttc" align="right">
  223. <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat" value="<?php echo (isset($_POST["price_ttc"])?$_POST["price_ttc"]:''); ?>">
  224. </td>
  225. <?php } ?>
  226. <td class="nobottom linecolqty" align="right"><input type="text" size="2" name="qty" id="qty" class="flat" value="<?php echo (isset($_POST["qty"])?$_POST["qty"]:1); ?>">
  227. </td>
  228. <?php
  229. if($conf->global->PRODUCT_USE_UNITS)
  230. {
  231. print '<td class="nobottom linecoluseunit" align="left">';
  232. print $form->selectUnits($line->fk_unit, "units");
  233. print '</td>';
  234. }
  235. ?>
  236. <td class="nobottom nowrap linecoldiscount" align="right"><input type="text" size="1" name="remise_percent" id="remise_percent" class="flat" value="<?php echo (isset($_POST["remise_percent"])?$_POST["remise_percent"]:$buyer->remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
  237. <?php
  238. if ($this->situation_cycle_ref) {
  239. $coldisplay++;
  240. print '<td class="nobottom nowrap" align="right"><input type="text" size="1" value="0" name="progress">%</td>';
  241. }
  242. if (! empty($usemargins))
  243. {
  244. ?>
  245. <td align="right" class="nobottom margininfos linecolmargin">
  246. <!-- For predef product -->
  247. <?php if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { ?>
  248. <select id="fournprice_predef" name="fournprice_predef" class="flat" data-role="none" style="display: none;"></select>
  249. <?php } ?>
  250. <!-- For free product -->
  251. <input type="text" size="5" id="buying_price" name="buying_price" class="flat" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
  252. </td>
  253. <?php
  254. $coldisplay++;
  255. if ($user->rights->margins->creer)
  256. {
  257. if (! empty($conf->global->DISPLAY_MARGIN_RATES))
  258. {
  259. echo '<td align="right" class="nobottom nowrap margininfos"><input type="text" size="2" id="np_marginRate" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'"><span class="np_marginRate hideonsmartphone">%</span></td>';
  260. $coldisplay++;
  261. }
  262. if (! empty($conf->global->DISPLAY_MARK_RATES))
  263. {
  264. echo '<td align="right" class="nobottom nowrap margininfos"><input type="text" size="2" id="np_markRate" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'"><span class="np_markRate hideonsmartphone">%</span></td>';
  265. $coldisplay++;
  266. }
  267. }
  268. else
  269. {
  270. if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $coldisplay++;
  271. if (! empty($conf->global->DISPLAY_MARK_RATES)) $coldisplay++;
  272. }
  273. }
  274. ?>
  275. <td class="nobottom linecoledit" align="center" valign="middle" colspan="<?php echo $colspan; ?>">
  276. <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
  277. </td>
  278. <?php
  279. // Lines for extrafield
  280. if (!empty($extrafieldsline))
  281. {
  282. if ($this->table_element_line=='commandedet') {
  283. $newline = new OrderLine($this->db);
  284. }
  285. elseif ($this->table_element_line=='propaldet') {
  286. $newline = new PropaleLigne($this->db);
  287. }
  288. elseif ($this->table_element_line=='supplier_proposaldet') {
  289. $newline = new SupplierProposalLine($this->db);
  290. }
  291. elseif ($this->table_element_line=='facturedet') {
  292. $newline = new FactureLigne($this->db);
  293. }
  294. elseif ($this->table_element_line=='contratdet') {
  295. $newline = new ContratLigne($this->db);
  296. }
  297. elseif ($this->table_element_line=='commande_fournisseurdet') {
  298. $newline = new CommandeFournisseurLigne($this->db);
  299. }
  300. elseif ($this->table_element_line=='facture_fourn_det') {
  301. $newline = new SupplierInvoiceLine($this->db);
  302. }
  303. if (is_object($newline)) {
  304. print $newline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8));
  305. }
  306. }
  307. ?>
  308. </tr>
  309. <?php
  310. if ((! empty($conf->service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required
  311. {
  312. $colspan = 6;
  313. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  314. $colspan++;
  315. }
  316. if ($this->situation_cycle_ref) {
  317. $colspan++;
  318. }
  319. // We add 1 if col total ttc
  320. if (!empty($inputalsopricewithtax)) {
  321. $colspan++;
  322. }
  323. if ($conf->global->PRODUCT_USE_UNITS) {
  324. $colspan++;
  325. }
  326. if (count($object->lines)) {
  327. //There will be an edit and a delete button
  328. $colspan += 2;
  329. // With this, there is a column move button ONLY if lines > 1
  330. if (in_array($object->element, array(
  331. 'propal',
  332. 'supplier_proposal',
  333. 'facture',
  334. 'facturerec',
  335. 'invoice',
  336. 'commande',
  337. 'order',
  338. 'order_supplier',
  339. 'invoice_supplier'
  340. ))) {
  341. $colspan++;
  342. }
  343. }
  344. if (!empty($conf->multicurrency->enabled)) $colspan+=2;
  345. if (! empty($usemargins))
  346. {
  347. $colspan++; // For the buying price
  348. if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
  349. if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
  350. }
  351. ?>
  352. <tr id="trlinefordates" <?php echo $bcnd[$var]; ?>>
  353. <td colspan="<?php echo $colspan; ?>">
  354. <?php
  355. $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  356. $date_end=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  357. if (! empty($object->element) && $object->element == 'contrat')
  358. {
  359. print $langs->trans("DateStartPlanned").' ';
  360. $form->select_date($date_start,"date_start",$usehm,$usehm,1,"addproduct");
  361. print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
  362. $form->select_date($date_end,"date_end",$usehm,$usehm,1,"addproduct");
  363. }
  364. else
  365. {
  366. echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
  367. echo $form->select_date($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,1);
  368. echo ' '.$langs->trans('to').' ';
  369. echo $form->select_date($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,1);
  370. };
  371. print '<script type="text/javascript">';
  372. if (!$date_start) {
  373. if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
  374. print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
  375. }
  376. if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
  377. print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
  378. }
  379. }
  380. if (!$date_end) {
  381. if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
  382. print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
  383. }
  384. if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
  385. print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
  386. }
  387. }
  388. print '</script>'
  389. ?>
  390. </td>
  391. </tr>
  392. <?php
  393. }
  394. ?>
  395. <script type="text/javascript">
  396. <?php
  397. if (! empty($usemargins) && $user->rights->margins->creer)
  398. {
  399. ?>
  400. /* Some js test when we click on button "Add" */
  401. jQuery(document).ready(function() {
  402. <?php
  403. if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
  404. $("input[name='np_marginRate']:first").blur(function(e) {
  405. return checkFreeLine(e, "np_marginRate");
  406. });
  407. <?php
  408. }
  409. if (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
  410. $("input[name='np_markRate']:first").blur(function(e) {
  411. return checkFreeLine(e, "np_markRate");
  412. });
  413. <?php
  414. }
  415. ?>
  416. });
  417. /* TODO This does not work for number with thousand separator that is , */
  418. function checkFreeLine(e, npRate)
  419. {
  420. var buying_price = $("input[name='buying_price']:first");
  421. var remise = $("input[name='remise_percent']:first");
  422. var rate = $("input[name='"+npRate+"']:first");
  423. if (rate.val() == '')
  424. return true;
  425. if (! $.isNumeric(rate.val().replace(',','.')))
  426. {
  427. alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
  428. e.stopPropagation();
  429. setTimeout(function () { rate.focus() }, 50);
  430. return false;
  431. }
  432. if (npRate == "np_markRate" && rate.val() >= 100)
  433. {
  434. alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
  435. e.stopPropagation();
  436. setTimeout(function () { rate.focus() }, 50);
  437. return false;
  438. }
  439. var price = 0;
  440. remisejs=price2numjs(remise.val());
  441. if (remisejs != 100) // If a discount not 100 or no discount
  442. {
  443. if (remisejs == '') remisejs=0;
  444. bpjs=price2numjs(buying_price.val());
  445. ratejs=price2numjs(rate.val());
  446. if (npRate == "np_marginRate")
  447. price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
  448. else if (npRate == "np_markRate")
  449. price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
  450. }
  451. $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
  452. return true;
  453. }
  454. <?php
  455. }
  456. ?>
  457. /* JQuery for product free or predefined select */
  458. jQuery(document).ready(function() {
  459. $("#prod_entry_mode_free").on( "click", function() {
  460. setforfree();
  461. });
  462. $("#select_type").change(function()
  463. {
  464. setforfree();
  465. if (jQuery('#select_type').val() >= 0)
  466. {
  467. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  468. jQuery('#dp_desc').focus();
  469. /* focus if CKEDITOR */
  470. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  471. {
  472. var editor = CKEDITOR.instances['dp_desc'];
  473. if (editor) { editor.focus(); }
  474. }
  475. }
  476. if (jQuery('#select_type').val() == '0') jQuery('#trlinefordates').hide();
  477. else jQuery('#trlinefordates').show();
  478. });
  479. $("#prod_entry_mode_predef").on( "click", function() {
  480. console.log("click prod_entry_mode_predef");
  481. setforpredef();
  482. jQuery('#trlinefordates').show();
  483. });
  484. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  485. $("#idprod, #idprodfournprice").change(function()
  486. {
  487. console.log("#idprod, #idprodfournprice change triggered");
  488. setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
  489. jQuery('#trlinefordates').show();
  490. <?php
  491. if (! empty($usemargins) && $user->rights->margins->creer)
  492. {
  493. $langs->load('stocks');
  494. ?>
  495. /* Code for margin */
  496. $("#fournprice_predef").find("option").remove();
  497. $("#fournprice_predef").hide();
  498. $("#buying_price").val("").show();
  499. /* Call post to load content of combo list fournprice_predef */
  500. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val() }, function(data) {
  501. if (data && data.length > 0)
  502. {
  503. var options = '';
  504. var defaultkey = '';
  505. var defaultprice = '';
  506. var bestpricefound = 0;
  507. var bestpriceid = 0; var bestpricevalue = 0;
  508. var pmppriceid = 0; var pmppricevalue = 0;
  509. var costpriceid = 0; var costpricevalue = 0;
  510. /* setup of margin calculation */
  511. var defaultbuyprice = '<?php
  512. if (isset($conf->global->MARGIN_TYPE))
  513. {
  514. if ($conf->global->MARGIN_TYPE == '1') print 'bestsupplierprice';
  515. if ($conf->global->MARGIN_TYPE == 'pmp') print 'pmp';
  516. if ($conf->global->MARGIN_TYPE == 'costprice') print 'costprice';
  517. } ?>';
  518. console.log("we will set the field for margin. defaultbuyprice="+defaultbuyprice);
  519. var i = 0;
  520. $(data).each(function() {
  521. if (this.id != 'pmpprice' && this.id != 'costprice')
  522. {
  523. i++;
  524. this.price = parseFloat(this.price); // to fix when this.price >0
  525. // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
  526. //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
  527. 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
  528. }
  529. if (this.id == 'pmpprice')
  530. {
  531. // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
  532. //console.log("id="+this.id+"-price="+this.price);
  533. if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
  534. {
  535. if (this.price > 0) {
  536. defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
  537. //console.log("pmppricevalue="+pmppricevalue);
  538. }
  539. }
  540. }
  541. if (this.id == 'costprice')
  542. {
  543. // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
  544. //console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
  545. if ('costprice' == defaultbuyprice)
  546. {
  547. if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
  548. else if (pmppricevalue > 0) { defaultkey = pmppriceid; defaultprice = pmppricevalue; }
  549. }
  550. }
  551. options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
  552. });
  553. options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
  554. console.log("finally selected defaultkey="+defaultkey+" defaultprice="+defaultprice);
  555. $("#fournprice_predef").html(options).show();
  556. if (defaultkey != '')
  557. {
  558. $("#fournprice_predef").val(defaultkey);
  559. }
  560. /* At loading, no product are yet selected, so we hide field of buying_price */
  561. $("#buying_price").hide();
  562. /* Define default price at loading */
  563. var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
  564. $("#buying_price").val(defaultprice);
  565. $("#fournprice_predef").change(function() {
  566. console.log("change on fournprice_predef");
  567. /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
  568. var linevalue=$(this).find('option:selected').val();
  569. var pricevalue = $(this).find('option:selected').attr("price");
  570. if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
  571. $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
  572. }
  573. if (linevalue == 'inputprice') {
  574. $('#buying_price').show();
  575. }
  576. if (linevalue == 'pmpprice') {
  577. $("#buying_price").val(pricevalue);
  578. $('#buying_price').hide();
  579. }
  580. });
  581. }
  582. },
  583. 'json');
  584. <?php
  585. }
  586. ?>
  587. /* To set focus */
  588. if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
  589. {
  590. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  591. jQuery('#dp_desc').focus();
  592. /* focus if CKEDITOR */
  593. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  594. {
  595. var editor = CKEDITOR.instances['dp_desc'];
  596. if (editor) { editor.focus(); }
  597. }
  598. }
  599. });
  600. <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef ?>
  601. setforpredef();
  602. <?php } ?>
  603. });
  604. /* Function to set fields from choice */
  605. function setforfree() {
  606. console.log("Call setforfree. We show most fields");
  607. jQuery("#search_idprod").val('');
  608. jQuery("#idprod").val('');
  609. jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
  610. jQuery("#search_idprodfournprice").val('');
  611. jQuery("#prod_entry_mode_free").prop('checked',true);
  612. jQuery("#prod_entry_mode_predef").prop('checked',false);
  613. jQuery("#price_ht").show();
  614. jQuery("#price_ttc").show(); // May no exists
  615. jQuery("#tva_tx").show();
  616. jQuery("#buying_price").val('').show();
  617. jQuery("#fournprice_predef").hide();
  618. jQuery("#title_vat").show();
  619. jQuery("#title_up_ht").show();
  620. jQuery("#title_up_ttc").show();
  621. jQuery("#np_marginRate").show(); // May no exists
  622. jQuery("#np_markRate").show(); // May no exists
  623. jQuery(".np_marginRate").show(); // May no exists
  624. jQuery(".np_markRate").show(); // May no exists
  625. jQuery("#units, #title_units").show();
  626. }
  627. function setforpredef() {
  628. console.log("Call setforpredef. We hide some fields");
  629. jQuery("#select_type").val(-1);
  630. jQuery("#prod_entry_mode_free").prop('checked',false);
  631. jQuery("#prod_entry_mode_predef").prop('checked',true);
  632. jQuery("#price_ht").hide();
  633. jQuery("#price_ttc").hide(); // May no exists
  634. jQuery("#tva_tx").hide();
  635. jQuery("#buying_price").show();
  636. //jQuery("#fournprice_predef").show(); // management somewhere else
  637. jQuery("#title_vat").hide();
  638. jQuery("#title_up_ht").hide();
  639. jQuery("#title_up_ttc").hide();
  640. jQuery("#np_marginRate").hide(); // May no exists
  641. jQuery("#np_markRate").hide(); // May no exists
  642. jQuery(".np_marginRate").hide(); // May no exists
  643. jQuery(".np_markRate").hide(); // May no exists
  644. jQuery("#units, #title_units").hide();
  645. }
  646. </script>
  647. <!-- END PHP TEMPLATE objectline_create.tpl.php -->