PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/tpl/objectline_add.tpl.php

https://bitbucket.org/speedealing/speedealing
PHP | 527 lines | 446 code | 37 blank | 44 comment | 137 complexity | 96879566bcb9d72adf564cff722ac7c4 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. *
  20. * Need to have following variables defined:
  21. * $conf
  22. * $langs
  23. * $dateSelector
  24. * $this (invoice, order, ...)
  25. * $line defined
  26. */
  27. ?>
  28. <!-- BEGIN PHP TEMPLATE objectline_add.tpl.php -->
  29. <tr class="liste_titre nodrag nodrop">
  30. <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>><div id="add"></div><?php echo $langs->trans('AddNewLine'); ?></td>
  31. <td align="right" width="50"><?php echo $langs->trans('VAT'); ?></td>
  32. <td align="right" width="80"><?php echo $langs->trans('PriceUHT'); ?></td>
  33. <td align="right" width="80"><?php echo $langs->trans('PriceUTTC'); ?></td>
  34. <td align="right" width="50"><?php echo $langs->trans('Qty'); ?></td>
  35. <td align="right" width="50"><?php echo $langs->trans('ReductionShort'); ?></td>
  36. <?php
  37. $colspan = 4;
  38. $colspan2 = 12;
  39. if (! empty($conf->margin->enabled)) {
  40. ?>
  41. <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
  42. <?php
  43. if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
  44. $colspan++;
  45. $colspan2++;
  46. }
  47. if (! empty($conf->global->DISPLAY_MARK_RATES)) {
  48. $colspan++;
  49. $colspan2++;
  50. }
  51. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  52. $colspan2++;
  53. }
  54. }
  55. ?>
  56. <td colspan="<?php echo $colspan; ?>">&nbsp;</td>
  57. </tr>
  58. <form name="addproduct" id="addproduct" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id; ?>#add" method="POST">
  59. <input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>" />
  60. <input type="hidden" name="action" value="addline" />
  61. <input type="hidden" name="usenewaddlineform" value="1" />
  62. <input type="hidden" name="id" value="<?php echo $this->id; ?>" />
  63. <?php if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { ?>
  64. <tr class="liste_titre nodrag nodrop">
  65. <td colspan="<?php echo $colspan2; ?>">
  66. <?php
  67. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
  68. {
  69. // show/hide, update elements after select
  70. $ajaxoptions=array(
  71. 'update' => array(
  72. 'select_type' => 'type',
  73. 'product_ref' => 'value',
  74. 'product_label' => 'label2',
  75. 'price_base_type' => 'pricebasetype',
  76. 'price_ht' => 'price_ht',
  77. 'origin_price_ht_cache' => 'price_ht',
  78. 'origin_tva_tx_cache' => 'tva_tx',
  79. 'origin_price_ttc_cache' => 'price_ttc'
  80. ),
  81. 'update_textarea' => array(
  82. 'product_desc' => 'desc'
  83. ),
  84. 'show' => array(
  85. 'price_base_type_area'
  86. ),
  87. 'disabled' => array(
  88. 'select_type'
  89. )
  90. );
  91. $form->select_produits('', 'idprod', '', $conf->product->limit_size, $buyer->price_level, 1, 2, '', 3, $ajaxoptions);
  92. }
  93. ?>
  94. <span id="add_product_area" class="hideobject"> | <input type="checkbox" id="add_product_checkbox" name="add_product" value="1" />
  95. <span id="add_product_text" class="hideobject">
  96. <?php echo $form->textwithtooltip($langs->trans('AddThisProductCard'), $langs->trans('HelpAddThisProductCard'),1,0,'','',3); ?>
  97. </span>
  98. <span id="add_service_text" class="hideobject">
  99. <?php echo $form->textwithtooltip($langs->trans('AddThisServiceCard'), $langs->trans('HelpAddThisServiceCard'),1,0,'','',3); ?>
  100. </span>
  101. </span>
  102. </td>
  103. </tr>
  104. <?php } ?>
  105. <tr <?php echo $bcnd[$var]; ?>>
  106. <td colspan="<?php echo $colspan2; ?>">
  107. <?php echo $form->select_type_of_lines((GETPOST('type')?GETPOST('type'):-1), 'type', 1); ?>
  108. <span id="product_ref_area" class="hideobject">
  109. &nbsp;<label for="product_ref"><?php echo $langs->trans("Ref"); ?></label>
  110. <input id="product_ref" name="product_ref" size="20" value="<?php echo GETPOST('product_ref'); ?>">
  111. </span>
  112. <span id="product_label_area">
  113. &nbsp;<label for="product_label"><?php echo $langs->trans("Label"); ?></label>
  114. <input id="product_label" name="product_label" size="40" value="<?php echo GETPOST('product_label'); ?>">
  115. </span>
  116. <span id="price_base_type_area" class="hideobject">
  117. <input type="hidden" id="price_base_type" name="price_base_type" value="" /> | <?php echo $langs->trans('PriceBase'); ?>:
  118. <span id="view_price_base_type"></span>
  119. </span>
  120. <?php
  121. if (is_object($hookmanager))
  122. {
  123. $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line'));
  124. $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action);
  125. }
  126. ?>
  127. </td>
  128. <tr <?php echo $bcnd[$var]; ?>>
  129. <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
  130. <?php
  131. // Editor wysiwyg
  132. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  133. $nbrows=ROWS_2;
  134. if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
  135. $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
  136. $doleditor=new DolEditor('product_desc', GETPOST('product_desc'), '', 150, 'dolibarr_details', '', false, true, $enable, $nbrows, 70);
  137. $doleditor->Create();
  138. ?>
  139. </td>
  140. <td align="right">
  141. <?php echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer); ?>
  142. <input type="hidden" id="origin_tva_tx_cache" name="origin_tva_tx_cache" value="" />
  143. </td>
  144. <td align="right">
  145. <input type="text" size="8" id="price_ht" name="price_ht" value="<?php echo (GETPOST('price_ht')?GETPOST('price_ht'):''); ?>">
  146. <input type="hidden" id="origin_price_ht_cache" name="origin_price_ht_cache" value="" />
  147. </td>
  148. <td align="right">
  149. <input type="text" size="8" id="price_ttc" name="price_ttc" value="<?php echo (GETPOST('price_ttc')?GETPOST('price_ttc'):''); ?>">
  150. <input type="hidden" id="origin_price_ttc_cache" name="origin_price_ttc_cache" value="" />
  151. </td>
  152. <td align="right"><input type="text" size="3" id="qty" name="qty" value="<?php echo (GETPOST('qty')?GETPOST('qty'):1); ?>"></td>
  153. <td align="right" nowrap="nowrap"><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" name="remise_percent">%</td>
  154. <?php
  155. $colspan = 4;
  156. if (! empty($conf->margin->enabled)) {
  157. ?>
  158. <td align="right">
  159. <select id="fournprice" name="fournprice" style="display: none;"></select>
  160. <input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (GETPOST('buying_price')?GETPOST('buying_price'):''); ?>">
  161. </td>
  162. <?php
  163. if (! empty($conf->global->DISPLAY_MARGIN_RATES))
  164. $colspan++;
  165. if (! empty($conf->global->DISPLAY_MARK_RATES))
  166. $colspan++;
  167. }
  168. ?>
  169. <td align="center" valign="middle" colspan="<?php echo $colspan; ?>"><input type="submit" class="button" id="addlinebutton" name="addline" value="<?php echo $langs->trans('Add'); ?>"></td>
  170. </tr>
  171. <?php if (! empty($conf->service->enabled) && ! empty($dateSelector)) {
  172. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  173. $colspan = 12;
  174. else
  175. $colspan = 11;
  176. if (! empty($conf->margin->enabled)) {
  177. if (! empty($conf->global->DISPLAY_MARGIN_RATES))
  178. $colspan++;
  179. if (! empty($conf->global->DISPLAY_MARK_RATES))
  180. $colspan++;
  181. }
  182. ?>
  183. <tr id="service_duration_area" <?php echo $bcnd[$var]; ?>>
  184. <td colspan="<?php echo $colspan; ?>">
  185. <?php
  186. $hourmin=(isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:'');
  187. echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
  188. echo $form->select_date('','date_start',$hourmin,$hourmin,1,"addproduct");
  189. echo ' '.$langs->trans('to').' ';
  190. echo $form->select_date('','date_end',$hourmin,$hourmin,1,"addproduct");
  191. ?>
  192. </td>
  193. </tr>
  194. <?php } ?>
  195. </form>
  196. <script type="text/javascript">
  197. $(document).ready(function() {
  198. // Add line button disabled by default
  199. $('#addlinebutton').attr('disabled','disabled');
  200. // Service duration hide by default
  201. $('#service_duration_area').hide();
  202. $('#idprod').change(function() {
  203. if ($(this).val() > 0) {
  204. // Update vat rate combobox
  205. getVATRates('getSellerVATRates', 'tva_tx', $(this).val());
  206. // For compatibility with combobox
  207. <?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
  208. $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php', {
  209. 'action': 'fetch',
  210. 'id': $(this).val(),
  211. 'price_level': <?php echo empty($buyer->price_level)?1:$buyer->price_level; ?>},
  212. function(data) {
  213. if (typeof data != 'undefined') {
  214. $('#product_ref').val(data.ref);
  215. $('#product_label').val(data.label);
  216. $('#price_base_type').val(data.pricebasetype).trigger('change');
  217. $('#price_ht').val(data.price_ht).trigger('change');
  218. $('#origin_price_ht_cache').val(data.price_ht);
  219. //$('#origin_price_ttc_cache').val(data.price_ttc);
  220. $('#origin_tva_tx_cache').val(data.tva_tx);
  221. $('#select_type').val(data.type).attr('disabled','disabled').trigger('change');
  222. $('#price_base_type_area').show();
  223. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances['product_desc'] != "undefined") {
  224. CKEDITOR.instances['product_desc'].setData(data.desc).focus();
  225. } else {
  226. $("#product_desc").html(data.desc).focus();
  227. }
  228. }
  229. }, 'json');
  230. <?php } ?>
  231. } else {
  232. $('#price_ttc').val('');
  233. // Restore vat rate combobox
  234. getVATRates('getSellerVATRates', 'tva_tx');
  235. // For compatibility with combobox
  236. <?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
  237. $('#select_type').val('').removeAttr('disabled').trigger('change');
  238. $('#product_ref').val('');
  239. $('#product_label').val('');
  240. $('#price_ht').val('').trigger('change');
  241. $('#origin_price_ht_cache').val('');
  242. //$('#origin_price_ttc_cache').val('');
  243. $('#origin_tva_tx_cache').val('');
  244. $('#price_base_type').val('');
  245. $('#price_base_type_area').hide();
  246. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances['product_desc'] != "undefined") {
  247. CKEDITOR.instances['product_desc'].setData('');
  248. } else {
  249. $("#product_desc").html('');
  250. }
  251. <?php } ?>
  252. }
  253. });
  254. $('#select_type').change(function() {
  255. var type = $(this).val();
  256. if (type >= 0) {
  257. if (type == 0) {
  258. $('#add_product_text').show();
  259. $('#add_service_text').hide();
  260. $('#service_duration_area').hide();
  261. $('#date_start').val('').trigger('change');
  262. $('#date_end').val('').trigger('change');
  263. } else if (type == 1) {
  264. $('#add_product_text').hide();
  265. $('#add_service_text').show();
  266. $('#service_duration_area').show();
  267. }
  268. //$('#add_product_area').show(); // TODO for add product card
  269. var addline=false;
  270. if ($('#price_ht').val().length > 0) {
  271. if ($('#idprod').val() == 0) {
  272. if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
  273. var content = CKEDITOR.instances['product_desc'].getData();
  274. } else {
  275. var content = $('#product_desc').val();
  276. }
  277. if (content.length > 0) {
  278. addline=true;
  279. }
  280. } else {
  281. addline=true;
  282. }
  283. }
  284. if (addline) {
  285. $('#addlinebutton').removeAttr('disabled');
  286. } else {
  287. $('#addlinebutton').attr('disabled','disabled');
  288. }
  289. } else {
  290. //$('#add_product_area').hide(); // TODO for add product card
  291. $('#add_product_checkbox').removeAttr('checked').trigger('change');
  292. $('#addlinebutton').attr('disabled','disabled');
  293. $('#service_duration_area').hide();
  294. $('#date_start').val('').trigger('change');
  295. $('#date_end').val('').trigger('change');
  296. }
  297. });
  298. // TODO for add product card
  299. $('#add_product_checkbox').change(function() {
  300. if ($(this).attr('checked')) {
  301. $('#product_ref_area').show();
  302. $('#product_ref').focus();
  303. $('#product_label').removeAttr('disabled');
  304. $('#search_idprod').attr('disabled','disabled');
  305. $('#update_label_area').hide();
  306. $('#update_label_checkbox').removeAttr('checked');
  307. } else {
  308. if ($("#idprod").val() > 0) {
  309. $('#update_label_area').show();
  310. $('#product_label').attr('disabled', 'disabled');
  311. }
  312. $('#product_ref_area').hide();
  313. $('#search_idprod').removeAttr('disabled');
  314. }
  315. });
  316. $('#price_ht').focusin(function() {
  317. $('#price_base_type').val('HT').trigger('change');
  318. });
  319. $('#price_ttc').focusin(function() {
  320. $('#price_base_type').val('TTC').trigger('change');
  321. });
  322. $('#price_base_type').change(function() {
  323. $('#view_price_base_type').html($(this).val());
  324. });
  325. $('#price_ht').bind('change keyup input', function() {
  326. if (($('#idprod').val() == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val() > 0) {
  327. update_price('price_ht', 'price_ttc');
  328. }
  329. });
  330. $('#price_ttc').bind('change keyup input', function() {
  331. if ($('#price_base_type').val() == 'TTC') {
  332. update_price('price_ttc', 'price_ht');
  333. }
  334. });
  335. if ($('#idprod').val() == 0 && $('#tva_tx').val() == 0) {
  336. $('#price_ttc').attr('disabled','disabled');
  337. }
  338. $('#tva_tx').change(function() {
  339. if ($(this).val() == 0) {
  340. if ($('#idprod').val() == 0) {
  341. $('#price_ttc').attr('disabled','disabled');
  342. }
  343. $('#price_ttc').val('');
  344. } else {
  345. // Enable excl.VAT field
  346. $('#price_ttc').removeAttr('disabled');
  347. // Update prices fields
  348. if ($('#price_base_type').val() == 'HT') {
  349. update_price('price_ht', 'price_ttc');
  350. } else if ($('#price_base_type').val() == 'TTC') {
  351. update_price('price_ttc', 'price_ht');
  352. }
  353. }
  354. });
  355. function update_price(input, output) {
  356. $.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
  357. 'amount': $('#' + input).val(),
  358. 'output': output,
  359. 'tva_tx': $('#tva_tx').val()
  360. },
  361. function(data) {
  362. var addline=false;
  363. if (typeof data[output] != 'undefined') {
  364. // Hide price_ttc if no vat
  365. //if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) {
  366. $('#' + output).val(data[output]);
  367. //}
  368. if ($('#idprod').val() == 0 && $('#select_type').val() >= 0) {
  369. if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
  370. var content = CKEDITOR.instances['product_desc'].getData();
  371. } else {
  372. var content = $('#product_desc').val();
  373. }
  374. if (content.length > 0) {
  375. addline=true;
  376. }
  377. } else {
  378. addline=true;
  379. }
  380. } else {
  381. $('#' + input).val('');
  382. $('#' + output).val('');
  383. }
  384. if (addline) {
  385. $('#addlinebutton').removeAttr('disabled');
  386. } else {
  387. $('#addlinebutton').attr('disabled','disabled');
  388. }
  389. }, 'json');
  390. }
  391. function getVATRates(action, htmlname, idprod) {
  392. var productid = (idprod?idprod:0);
  393. $.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/vatrates.php', {
  394. 'action': action,
  395. 'id': <?php echo $buyer->id; ?>,
  396. 'productid': productid,
  397. 'htmlname': htmlname },
  398. function(data) {
  399. if (typeof data != 'undefined' && data.error == null) {
  400. $("#" + htmlname).html(data.value).trigger('change');
  401. }
  402. }, 'json');
  403. }
  404. // Check if decription is not empty for free line
  405. <?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  406. CKEDITOR.on('instanceReady', function() {
  407. CKEDITOR.instances['product_desc'].on('key', function() {
  408. var addline=false;
  409. if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
  410. var content = CKEDITOR.instances['product_desc'].getData();
  411. if (content.length > 0) {
  412. addline=true;
  413. }
  414. } else if ($('#idprod').val() > 0 && $('#price_ht').val().length > 0) {
  415. addline=true;
  416. }
  417. if (addline) {
  418. $('#addlinebutton').removeAttr('disabled');
  419. } else {
  420. $('#addlinebutton').attr('disabled','disabled');
  421. }
  422. });
  423. });
  424. <?php } else { ?>
  425. $('#product_desc').onDelayedKeyup({
  426. 'handler': function() {
  427. var addline=false;
  428. if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
  429. var content = $('#product_desc').val();
  430. if (content.length > 0) {
  431. addline=true;
  432. }
  433. } else if ($('#idprod').val() > 0 && $('#price_ht').val().length > 0) {
  434. addline=true;
  435. }
  436. if (addline) {
  437. $('#addlinebutton').removeAttr('disabled');
  438. } else {
  439. $('#addlinebutton').attr('disabled','disabled');
  440. }
  441. }
  442. });
  443. <?php } ?>
  444. });
  445. </script>
  446. <?php if (! empty($conf->margin->enabled)) { ?>
  447. <script type="text/javascript">
  448. $("#idprod").change(function() {
  449. $("#fournprice").empty();
  450. $("#buying_price").show();
  451. if ($(this).val() > 0)
  452. {
  453. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) {
  454. if (data && data.length > 0) {
  455. var options = '';
  456. var i = 0;
  457. $(data).each(function() {
  458. i++;
  459. options += '<option value="'+this.id+'" title="'+this.title+'" price="'+this.price+'"';
  460. if (i == 1) {
  461. options += ' selected';
  462. $("#buying_price").val(this.price);
  463. }
  464. options += '>'+this.label+'</option>';
  465. });
  466. options += '<option value=null><?php echo $langs->trans("InputPrice"); ?></option>';
  467. $("#fournprice").html(options);
  468. $("#buying_price").hide();
  469. $("#fournprice").show();
  470. $("#fournprice").change(function() {
  471. var selval = $(this).find('option:selected').attr("price");
  472. if (selval)
  473. $("#buying_price").val(selval).hide();
  474. else
  475. $('#buying_price').show();
  476. });
  477. } else {
  478. $("#fournprice").hide();
  479. $('#buying_price').val('');
  480. }
  481. },
  482. 'json');
  483. } else {
  484. $("#fournprice").hide();
  485. $('#buying_price').val('');
  486. }
  487. });
  488. </script>
  489. <?php } ?>
  490. <!-- END PHP TEMPLATE objectline_add.tpl.php -->