설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app-invoice-edit.js 3.9KB

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