Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * App Invoice - Add
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. const invoiceItemPriceList = document.querySelectorAll('.invoice-item-price'),
  7. invoiceItemQtyList = document.querySelectorAll('.invoice-item-qty'),
  8. invoiceDateList = document.querySelectorAll('.date-picker');
  9. // Price
  10. if (invoiceItemPriceList) {
  11. invoiceItemPriceList.forEach(function (invoiceItemPrice) {
  12. if (invoiceItemPrice) {
  13. invoiceItemPrice.addEventListener('input', event => {
  14. invoiceItemPrice.value = formatNumeral(event.target.value, {
  15. delimiter: '',
  16. numeral: true
  17. });
  18. });
  19. }
  20. });
  21. }
  22. // Qty
  23. if (invoiceItemQtyList) {
  24. invoiceItemQtyList.forEach(function (invoiceItemQty) {
  25. if (invoiceItemQty) {
  26. invoiceItemQty.addEventListener('input', event => {
  27. invoiceItemQty.value = formatNumeral(event.target.value, {
  28. delimiter: '',
  29. numeral: true
  30. });
  31. });
  32. }
  33. });
  34. }
  35. // Datepicker
  36. if (invoiceDateList) {
  37. invoiceDateList.forEach(function (invoiceDateEl) {
  38. invoiceDateEl.flatpickr({
  39. monthSelectorType: 'static'
  40. });
  41. });
  42. }
  43. // repeater (jquery)
  44. var applyChangesBtn = $('.btn-apply-changes'),
  45. discount,
  46. tax1,
  47. tax2,
  48. discountInput,
  49. tax1Input,
  50. tax2Input,
  51. sourceItem = $('.source-item'),
  52. adminDetails = {
  53. 'App Design': 'Designed UI kit & app pages.',
  54. 'App Customization': 'Customization & Bug Fixes.',
  55. 'ABC Template': 'Bootstrap 4 admin template.',
  56. 'App Development': 'Native App Development.'
  57. };
  58. // Prevent dropdown from closing on tax change
  59. $(document).on('click', '.tax-select', function (e) {
  60. e.stopPropagation();
  61. });
  62. // On tax change update it's value value
  63. function updateValue(listener, el) {
  64. listener.closest('.repeater-wrapper').find(el).text(listener.val());
  65. }
  66. // Apply item changes btn
  67. if (applyChangesBtn.length) {
  68. $(document).on('click', '.btn-apply-changes', function (e) {
  69. var $this = $(this);
  70. tax1Input = $this.closest('.dropdown-menu').find('#taxInput1');
  71. tax2Input = $this.closest('.dropdown-menu').find('#taxInput2');
  72. discountInput = $this.closest('.dropdown-menu').find('#discountInput');
  73. tax1 = $this.closest('.repeater-wrapper').find('.tax-1');
  74. tax2 = $this.closest('.repeater-wrapper').find('.tax-2');
  75. discount = $('.discount');
  76. if (tax1Input.val() !== null) {
  77. updateValue(tax1Input, tax1);
  78. }
  79. if (tax2Input.val() !== null) {
  80. updateValue(tax2Input, tax2);
  81. }
  82. if (discountInput.val().length) {
  83. $this
  84. .closest('.repeater-wrapper')
  85. .find(discount)
  86. .text(discountInput.val() + '%');
  87. }
  88. });
  89. }
  90. // Repeater init
  91. if (sourceItem.length) {
  92. sourceItem.on('submit', function (e) {
  93. e.preventDefault();
  94. });
  95. sourceItem.repeater({
  96. show: function () {
  97. $(this).slideDown();
  98. // Initialize tooltip on load of each item
  99. const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
  100. tooltipTriggerList.map(function (tooltipTriggerEl) {
  101. return new bootstrap.Tooltip(tooltipTriggerEl);
  102. });
  103. },
  104. hide: function (e) {
  105. $(this).slideUp();
  106. }
  107. });
  108. }
  109. // Item details select onchange
  110. $(document).on('change', '.item-details', function () {
  111. var $this = $(this),
  112. value = adminDetails[$this.val()];
  113. if ($this.next('textarea').length) {
  114. $this.next('textarea').val(value);
  115. } else {
  116. $this.after('<textarea class="form-control" rows="2">' + value + '</textarea>');
  117. }
  118. });
  119. });