PK#6ãZü'~ûž+ž+report_sales_ltms.jsnu„[µü¤$(document).ready(function(){ let data_set_sales = []; // Global data set let totalDataCount = 0; // Total number of records to fetch // Function to disable buttons function disableButtons() { $('#generate-btn-sales').prop('disabled', true); $('#btn-close-modal-sales').prop('disabled', true); $('#export-sales-excel').prop('disabled', true); $('#export-sales-pdf').prop('disabled', true); } // Function to enable buttons function enableButtons() { $('#generate-btn-sales').prop('disabled', false); $('#btn-close-modal-sales').prop('disabled', false); $('#export-sales-excel').prop('disabled', false); $('#export-sales-pdf').prop('disabled', false); } // Function to fetch data in batches async function fetchData(offset) { try { const response = await $.ajax({ url: "api/ltms_report/ltms_sales_report.php", type: "post", dataType: "json", data: { apiKey: "11113487258290", cid : $("#company_sales_report").val(), did : $("#dealer_sales_report").val(), date_from_sales: $("#date_from_ltms_sales").val(), date_to_sales: $("#date_to_ltms_sales").val(), ltms_status_sales: $("#ltms-filter-sales").val(), offset: offset, limit: 50 // Limit for each request } }); if (offset === 0) { totalDataCount = response.total_data; } data_set_sales = data_set_sales.concat(response.results); const progressPercentage = Math.min((data_set_sales.length / totalDataCount) * 100, 100); $('#data-fetch-progress-sales').css('width', progressPercentage + '%').attr('aria-valuenow', progressPercentage).text(Math.round(progressPercentage) + '%'); if (response.results.length === 50) { await fetchData(offset + 50); } else { enableButtons(); } } catch (error) { console.error("Error fetching data:", error); enableButtons(); } } $("#generate-btn-sales").on('click', function() { data_set_sales = []; disableButtons(); fetchData(0); }); document.getElementById('export-sales-pdf').addEventListener('click', function () { if (data_set_sales.length === 0) { alert("No data available to export."); return; } // var { jsPDF } = window.jspdf; window.jsPDF = window.jspdf.jsPDF; var doc = new jsPDF({ orientation: 'portrait', format: 'a4' }); doc.setFontSize(10); const title = "Sales LTMS "; const titleWidth = doc.getStringUnitWidth(title) * doc.internal.getFontSize() / doc.internal.scaleFactor; const xTitle = (doc.internal.pageSize.getWidth() - titleWidth) / 2; doc.text(title, xTitle, 15); // Add numbering column header const headers = [ "No.", "Dealer", "Name", "Type", "CS Number", "Date Released", "Mobile", "W/ LTMS", ]; let yPos = 25; const xHeader = 10; const columnWidths = [10,25, 34, 20, 27, 30,26,18]; // Adjust column widths // Set fill color for the header background doc.setFillColor(9, 151, 0); // RGB for blue // Draw the headers with background and borders doc.setFont("helvetica", "bold"); // Loop through the headers to draw the background first and then the text doc.rect(xHeader, yPos - 4, doc.internal.pageSize.getWidth() - (xHeader*2), 10, 'FD'); headers.forEach((header, index) => { let xPos = xHeader + columnWidths.slice(0, index).reduce((a, b) => a + b, 0); // Calculate x position based on previous column widths // Draw the background rectangle for each column with its own width // 'FD' means fill and draw (border) // Set text color to white for the header text doc.setTextColor(255, 255, 255); // Add header text (centered vertically within the cell) doc.text(header, xPos + 2, yPos + 2); }); // Reset text color to black for the content rows doc.setTextColor(0, 0, 0); yPos += 10; let counter = 1; doc.setFontSize(8); // Render table rows data_set_sales.forEach((item) => { let dealerName = item.dealer_name || ""; let splitdealerName = doc.splitTextToSize(dealerName, columnWidths[1] - 7); let customerName = item.first_name + ' ' + item.middle_name + ' ' + item.last_name || ""; let corporationName = item.corporation_name || ""; let splitCorporationName = doc.splitTextToSize(corporationName, columnWidths[2] - 7); let splitCustomerName = doc.splitTextToSize(customerName, columnWidths[2] - 7); // Adjust to fit width let csNumber = item.cs_number || ""; let splitCsNumber = doc.splitTextToSize(csNumber, columnWidths[4] - 7); // let salesDate = formatDate(item.activity_date) || ""; // let splitActivityDate = doc.splitTextToSize(salesDate, columnWidths[4] - 5); // Determine which name to use based on type let displayedName = item.type == 1 ? splitCustomerName : splitCorporationName; let maxRowHeight = Math.max(displayedName.length, splitCsNumber.length) * 7; // Draw cell borders let currentX = 10; // Starting X position for columns // Column 1: Row numbering doc.rect(currentX, yPos - 4, columnWidths[0], maxRowHeight); // Draw border doc.text(counter.toString(), currentX + 2, yPos); // Add some padding for text currentX += columnWidths[0]; doc.setFontSize(8); doc.rect(currentX, yPos - 4, columnWidths[1], maxRowHeight); // Draw border doc.text(splitdealerName, currentX + 2, yPos); currentX += columnWidths[1]; // Column 2: Customer or Corporation Name doc.rect(currentX, yPos - 4, columnWidths[2], maxRowHeight); // Draw border doc.text(displayedName, currentX + 2, yPos); currentX += columnWidths[2]; // Column 3: Type doc.rect(currentX, yPos - 4, columnWidths[3], maxRowHeight); // Draw border doc.text(item.type == 1 ? "Individual" : "Corporation", currentX + 2, yPos); currentX += columnWidths[3]; // Column 4: CS Number doc.rect(currentX, yPos - 4, columnWidths[4], maxRowHeight); // Draw border doc.text(splitCsNumber, currentX + 2, yPos); currentX += columnWidths[4]; // Column 5: Date Released doc.setFontSize(8); doc.rect(currentX, yPos - 4, columnWidths[5], maxRowHeight); // Draw border doc.text(formatDate(item.activity_date) || "", currentX + 2, yPos); currentX += columnWidths[5]; // doc.setFontSize(11); // Column 6: Mobile doc.rect(currentX, yPos - 4, columnWidths[6], maxRowHeight); // Draw border doc.text(item.mobile_phone_1, currentX + 2, yPos); currentX += columnWidths[6]; doc.rect(currentX, yPos - 4, columnWidths[7], maxRowHeight); // Draw border doc.text(item.has_tag_ltms == 1 ? "Uploaded" : "No LTMS", currentX + 2, yPos); // Adjust yPos based on the tallest column yPos += maxRowHeight; // Add new page if necessary if (yPos > 270) { doc.addPage(); yPos = 10; } // Increment counter counter++; }); // Add total row at the end yPos += 10; doc.setFont("helvetica", "bold"); doc.text("Total", 10, yPos); doc.text(counter - 1 + " entries", 10 + columnWidths[0] + columnWidths[1], yPos); // Display the total count of rows // Add page numbering to each page const totalPages = doc.internal.getNumberOfPages(); for (let i = 1; i <= totalPages; i++) { doc.setPage(i); doc.text(`Page ${i} of ${totalPages}`, 180, 290); } // Save the PDF doc.save('LTMS_Sales_Report.pdf'); }); document.getElementById('export-sales-excel').addEventListener('click', function () { // Check if data_set has data if (data_set_sales.length === 0) { alert("No data available to export."); return; } // Convert data_set to a format suitable for Excel const formattedData = data_set_sales.map(item => ({ 'COMPANY' : item.company_name, 'DEALER' : item.company_code +' - '+item.dealer_name, 'NAME': (item.type ==1 ? item.first_name + ' ' + item.middle_name + ' ' + item.last_name : item.corporation_name), 'MOBILE' : item.mobile_phone_1, 'TYPE' : (item.type ==1 ? "Individual" : "Corporation"), 'CS NUMBER': item.cs_number, // Ensure the property names are correct 'DATE RELEASED': formatDate(item.activity_date), 'LTMS STATUS' : (item.has_tag_ltms ==1 ? "Uploaded" : "No LTMS") })); // Log the formatted data to verify the structure before export console.log(formattedData); // Create a new workbook const wb = XLSX.utils.book_new(); // Convert the formatted data to a worksheet const ws = XLSX.utils.json_to_sheet(formattedData); // Append the worksheet to the workbook XLSX.utils.book_append_sheet(wb, ws, 'Customer Data'); // Export as Excel file XLSX.writeFile(wb, 'sales_customer_data.xlsx'); }); function formatDate(date) { const parsedDate = new Date(date); if (isNaN(parsedDate)) { return ""; } const formattedDate = parsedDate.toLocaleString('en-US', { year: 'numeric', month: 'long', // Full month name (e.g., "October") day: 'numeric', // hour: 'numeric', // minute: 'numeric', // second: 'numeric', // hour12: true // Enables AM/PM }); return formattedDate; } });PK#6ãZ$á ¤ ¤ltms_view09-25-24.jsnu„[µü¤ var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year :filter_year, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_count); $('#new_customer_count').text(result.pending); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active ); $('#inactive_customer_count').text(result.total_is_inactive ); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_ltms_upload_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_ltms_upload_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month: filter_month, filter_year : filter_year, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { // alert("click outside"); event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: `
` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('
').attr({'class':'mod-div'}); let inputGroup = $('
').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('
').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('
').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('
').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('
').attr({'class':'form-group mb-0'}); let inputGroup2 = $('
').attr({'class':'input-group'}); let label = $('').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); // const modalHtml = ` // // `; // $('body').append(modalHtml); // jQuery event listener for image link clicks PK#6ãZ«)ùöÍ>Í>ltms11-18-24.jsnu„[µü¤ var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var sales_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function initListSales() { var $table = $('#sales-table'); $table.bootstrapTable('destroy'); $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''; // Custom search placeholder for sales } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() // getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_customer_ltms_list.php' }); }) showList(); } // customerCountSummary(); } function refreshTableSales() { var $table = $('#sales-table'); if (getCookie("sales_toggle") != null && $.cookie("sales_toggle") == 1) { initGridSales(); showGridSales(); } else { initListSales(); $table.bootstrapTable('refresh', { url: 'app/table/bt_sales_ltms_list.php' }); showListSales(); } } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); // getCustomerGrid(n, 9); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showGridSales() { $("#sales-grid-data-paging").show(); $("#sales-table").hide(); $("#sales-grid").show(); $("#sales-grid-card").show(); $('#sales-grid-data-paging').show(); // $("button[name='grid_toggle_on']").show(); // $(".fixed-table-pagination").hide(); // $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function showListSales() { $("#sales-grid").hide(); $("#sales-table").show(); $("#sales-grid").hide(); $("#sales-grid-card").hide(); $('#sales-grid-data-paging').hide(); $(".fixed-table-pagination").show(); } function queryParams(params) { var filter_cs_number = $("#cs_status").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var filter_sc = ($("#filter-sc").val() == '') ? '0' : $("#filter-sc").val(); var filter_dealer = ($("#filter-dealer").val() == '') ? '0' : $("#filter-dealer").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { // ref_header : ref_header, search: params.search, offset: params.offset, limit: 15,//params.limit, sort: params.sort, order: params.order, cs_number: filter_cs_number, // company: company, // type: type, // gender: gender, // filter_age: filter_age, // filter_data: filter_data, // filter_month: filter_month, // filter_year: filter_year, // filter_sc : filter_sc, // filter_dealer : filter_dealer, // customer_actions: customer_actions, // my_records : my_records }; } function queryParamsSales(params) { var fromDate = $('#from-date').val(); var toDate = $('#to-date').val(); var ltmsStatus = $('#ltms-filter').val(); var did = $("#dealer_sales").val(); var cid = $("#company_sales").val(); return { // ref_header : ref_header, search: params.search, offset: params.offset, limit: 15,// params.limit, sort: params.sort, order: params.order, cid : cid, did : did, start_date :fromDate, end_date : toDate, ltms_status: ltmsStatus }; } function addFilterListenerSales(){ $('#company_sales').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#dealer_sales').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#to-date').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#ltms-filter').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); } function addFilterListener(){ $('#cs_status').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { initGrid() } else { initList(); initListSales(); } refreshTableCustomer(); refreshTableSales(); addFilterListenerSales(); addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#filter-sc').select2({ placeholder: "Employee", allowClear: true }) $('#filter-dealer').select2({ placeholder: "Dealer", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); // $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // // alert(value) // if (value == 'email_1' || value == 'mobile_phone_1') { // return; // } // customerInfo($el.id); // }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: `
` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#filter-month').off('change.mychange'); $('#filter-year').off('change.mychange'); $('#filter-sc').off('change.mychange'); $('#filter-dealer').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#filter-month').val('').trigger('change') $('#filter-year').val('').trigger('change') $('#filter-sc').val('').trigger('change') $('#filter-dealer').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) }); const goBack = () => { window.history.back(); } PK#6ãZ«)ùöÍ>Í>ltms.jsnu„[µü¤ var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var sales_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function initListSales() { var $table = $('#sales-table'); $table.bootstrapTable('destroy'); $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''; // Custom search placeholder for sales } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() // getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_customer_ltms_list.php' }); }) showList(); } // customerCountSummary(); } function refreshTableSales() { var $table = $('#sales-table'); if (getCookie("sales_toggle") != null && $.cookie("sales_toggle") == 1) { initGridSales(); showGridSales(); } else { initListSales(); $table.bootstrapTable('refresh', { url: 'app/table/bt_sales_ltms_list.php' }); showListSales(); } } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); // getCustomerGrid(n, 9); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showGridSales() { $("#sales-grid-data-paging").show(); $("#sales-table").hide(); $("#sales-grid").show(); $("#sales-grid-card").show(); $('#sales-grid-data-paging').show(); // $("button[name='grid_toggle_on']").show(); // $(".fixed-table-pagination").hide(); // $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function showListSales() { $("#sales-grid").hide(); $("#sales-table").show(); $("#sales-grid").hide(); $("#sales-grid-card").hide(); $('#sales-grid-data-paging').hide(); $(".fixed-table-pagination").show(); } function queryParams(params) { var filter_cs_number = $("#cs_status").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var filter_sc = ($("#filter-sc").val() == '') ? '0' : $("#filter-sc").val(); var filter_dealer = ($("#filter-dealer").val() == '') ? '0' : $("#filter-dealer").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { // ref_header : ref_header, search: params.search, offset: params.offset, limit: 15,//params.limit, sort: params.sort, order: params.order, cs_number: filter_cs_number, // company: company, // type: type, // gender: gender, // filter_age: filter_age, // filter_data: filter_data, // filter_month: filter_month, // filter_year: filter_year, // filter_sc : filter_sc, // filter_dealer : filter_dealer, // customer_actions: customer_actions, // my_records : my_records }; } function queryParamsSales(params) { var fromDate = $('#from-date').val(); var toDate = $('#to-date').val(); var ltmsStatus = $('#ltms-filter').val(); var did = $("#dealer_sales").val(); var cid = $("#company_sales").val(); return { // ref_header : ref_header, search: params.search, offset: params.offset, limit: 15,// params.limit, sort: params.sort, order: params.order, cid : cid, did : did, start_date :fromDate, end_date : toDate, ltms_status: ltmsStatus }; } function addFilterListenerSales(){ $('#company_sales').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#dealer_sales').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#to-date').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); $('#ltms-filter').off('change.mychange').on('change.mychange', function() { refreshTableSales(); }); } function addFilterListener(){ $('#cs_status').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { initGrid() } else { initList(); initListSales(); } refreshTableCustomer(); refreshTableSales(); addFilterListenerSales(); addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#filter-sc').select2({ placeholder: "Employee", allowClear: true }) $('#filter-dealer').select2({ placeholder: "Dealer", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); // $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // // alert(value) // if (value == 'email_1' || value == 'mobile_phone_1') { // return; // } // customerInfo($el.id); // }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: `
` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#filter-month').off('change.mychange'); $('#filter-year').off('change.mychange'); $('#filter-sc').off('change.mychange'); $('#filter-dealer').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#filter-month').val('').trigger('change') $('#filter-year').val('').trigger('change') $('#filter-sc').val('').trigger('change') $('#filter-dealer').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) }); const goBack = () => { window.history.back(); } PK#6ãZü'~ûž+ž+report_sales_ltms.jsnu„[µü¤PK#6ãZ$á ¤ ¤â+ltms_view09-25-24.jsnu„[µü¤PK#6ãZ«)ùöÍ>Í>1Ðltms11-18-24.jsnu„[µü¤PK#6ãZ«)ùöÍ>Í>=ltms.jsnu„[µü¤PK>AN