| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /**
- * App Invoice - Add
- */
-
- 'use strict';
-
- document.addEventListener('DOMContentLoaded', function (e) {
- const invoiceItemPriceList = document.querySelectorAll('.invoice-item-price'),
- invoiceItemQtyList = document.querySelectorAll('.invoice-item-qty'),
- invoiceDateList = document.querySelectorAll('.date-picker');
-
- // Price
- if (invoiceItemPriceList) {
- invoiceItemPriceList.forEach(function (invoiceItemPrice) {
- if (invoiceItemPrice) {
- invoiceItemPrice.addEventListener('input', event => {
- invoiceItemPrice.value = formatNumeral(event.target.value, {
- delimiter: '',
- numeral: true
- });
- });
- }
- });
- }
-
- // Qty
- if (invoiceItemQtyList) {
- invoiceItemQtyList.forEach(function (invoiceItemQty) {
- if (invoiceItemQty) {
- invoiceItemQty.addEventListener('input', event => {
- invoiceItemQty.value = formatNumeral(event.target.value, {
- delimiter: '',
- numeral: true
- });
- });
- }
- });
- }
-
- // Datepicker
- if (invoiceDateList) {
- invoiceDateList.forEach(function (invoiceDateEl) {
- invoiceDateEl.flatpickr({
- monthSelectorType: 'static'
- });
- });
- }
-
- // repeater (jquery)
- var applyChangesBtn = $('.btn-apply-changes'),
- discount,
- tax1,
- tax2,
- discountInput,
- tax1Input,
- tax2Input,
- sourceItem = $('.source-item'),
- adminDetails = {
- 'App Design': 'Designed UI kit & app pages.',
- 'App Customization': 'Customization & Bug Fixes.',
- 'ABC Template': 'Bootstrap 4 admin template.',
- 'App Development': 'Native App Development.'
- };
-
- // Prevent dropdown from closing on tax change
- $(document).on('click', '.tax-select', function (e) {
- e.stopPropagation();
- });
-
- // On tax change update it's value value
- function updateValue(listener, el) {
- listener.closest('.repeater-wrapper').find(el).text(listener.val());
- }
-
- // Apply item changes btn
- if (applyChangesBtn.length) {
- $(document).on('click', '.btn-apply-changes', function (e) {
- var $this = $(this);
- tax1Input = $this.closest('.dropdown-menu').find('#taxInput1');
- tax2Input = $this.closest('.dropdown-menu').find('#taxInput2');
- discountInput = $this.closest('.dropdown-menu').find('#discountInput');
- tax1 = $this.closest('.repeater-wrapper').find('.tax-1');
- tax2 = $this.closest('.repeater-wrapper').find('.tax-2');
- discount = $('.discount');
-
- if (tax1Input.val() !== null) {
- updateValue(tax1Input, tax1);
- }
-
- if (tax2Input.val() !== null) {
- updateValue(tax2Input, tax2);
- }
-
- if (discountInput.val().length) {
- $this
- .closest('.repeater-wrapper')
- .find(discount)
- .text(discountInput.val() + '%');
- }
- });
- }
-
- // Repeater init
- if (sourceItem.length) {
- sourceItem.on('submit', function (e) {
- e.preventDefault();
- });
- sourceItem.repeater({
- show: function () {
- $(this).slideDown();
- // Initialize tooltip on load of each item
- const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
- tooltipTriggerList.map(function (tooltipTriggerEl) {
- return new bootstrap.Tooltip(tooltipTriggerEl);
- });
- },
- hide: function (e) {
- $(this).slideUp();
- }
- });
- }
-
- // Item details select onchange
- $(document).on('change', '.item-details', function () {
- var $this = $(this),
- value = adminDetails[$this.val()];
- if ($this.next('textarea').length) {
- $this.next('textarea').val(value);
- } else {
- $this.after('<textarea class="form-control" rows="2">' + value + '</textarea>');
- }
- });
- });
|