File manager - Edit - /home/autoph/public_html/connectv1/resources/views/common/scripts/finance/finance.js
Back
// GLOBAL VARIABLES var finance_id = 0; var plate_cs_number = ""; var policy_number = ""; var policy_issue_date = ""; var start_date = ""; var end_date = ""; var start = null; var end = null; var company = 0; var dealer = 0; var reset = 1; var filter_date = 0; var filter_box = 0; // ADD FNI RECORD var fni_add_plate_cs_number = ""; var fni_add_brand = ""; var fni_add_model = ""; var fni_add_variant = ""; var fni_add_dealer = ""; var fni_add_customer_fullname = ""; var fni_add_customer_mobile = ""; var fni_add_customer_other_contact = ""; var fni_add_customer_email = ""; var fni_add_customer_address = ""; var fni_add_policy_issue_date = ""; var fni_add_policy_start_date = ""; var fni_add_policy_end_date = ""; var fni_add_policy_number = ""; var fni_add_bank = ""; var fni_add_insurance_provider = ""; var fni_add_insurance_type = ""; var fni_add_sales_consultant = ""; var fni_add_paid_amount = ""; var fni_add_lock_in_year = ""; var fni_add_terms = ""; var fni_add_locked_in = 1; $(function(){ initTableFinance(); refreshFinanceTable(); initToolTip(); detailsCount(); start = moment().startOf('month'); end = moment().endOf('month'); $('#tip-categorized-vehicle').attr('data-original-title', "<div id='tool' class=''>Grouped by plate / cs number</div>"); $('#tip-individual-insurance').attr('data-original-title', "<div id='tool' class=''>Total count of individual insurance</div>"); $('#filter-date').daterangepicker({ autoUpdateInput: false, showDropdowns: true, parentEl: '#dropdown-filter', locale: { cancelLabel: 'Cancel' }, startDate: start, opens: "left", endDate: end, ranges: { 'Today': [moment(), moment()], 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], 'Last 7 Days': [moment().subtract(6, 'days'), moment()], 'Last 30 Days': [moment().subtract(29, 'days'), moment()], 'This Month': [moment().startOf('month'), moment().endOf('month')], 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')], 'This Year': [moment().startOf('year'), moment().endOf('year')], 'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')] } }); // resetDateRangePicker(start, end); let isMobile = window.matchMedia("only screen and (max-width: 760px)").matches; $(".daterangepicker").on('click', function() { setDateRangePickerWidth(isMobile); }); $("#filter-date").on('click', function() { setDateRangePickerWidth(isMobile); }); $('#fni-add-brand').select2({ placeholder: "Brand", allowClear: true }); $('#fni-add-model').select2({ placeholder: "Model", allowClear: true }); $('#fni-add-variant').select2({ placeholder: "Variant", allowClear: true }); $('#fni-add-dealer').select2({ placeholder: "Dealer", allowClear: true }) $('#fni-add-insurance-provider').select2({ placeholder: "Insurance Provider", allowClear: true }) $('#fni-add-insurance-type').select2({ placeholder: "Insurance Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#dealer').select2({ placeholder: "Dealer", allowClear: false }) $('#issue-date').datetimepicker({ format: 'L' }); $('#start-date').datetimepicker({ format: 'L' }); $('#end-date').datetimepicker({ format: 'L' }); $('[data-mask]').inputmask(); addListenerCompanyFilter(); $('#filter-date').on('apply.daterangepicker', function(ev, picker) { $('#filter-date span').html(picker.startDate.format('MMMM D, YYYY') + ' - ' + picker.endDate .format( 'MMMM D, YYYY')); filter_date = 1; cb(picker.startDate, picker.endDate); }); $('#filter-date').on('cancel.daterangepicker', function(ev, picker) { $('#filter-date').data('daterangepicker').hideCalendars(); filter_date = 0; }); $('#btn-no-filter').on('click', function() { $('#company-filter').off('change.mychange'); //off the company filter built in change event $('#company-filter').val('').trigger('change'); $('#dealer').off('change.mychange'); //off the company filter built in change event $('#dealer').val(0).trigger('change'); $('#dealer').html(''); company = 0; dealer = 0; addListenerCompanyFilter(); //enable again the company filter event start = moment().startOf('month'); end = moment().endOf('month'); reset = 1; filter_date = 0; resetDateRangePicker(start, end); }); document.getElementById("dropdown-filter").addEventListener('click', function(event) { event.stopPropagation(); }); setTimeout(function(){ }, 3000); $('#date-range').text("No Filter"); }); function addFNIModalTabSelectedTab(type){ $('#fni-modal-tab .nav-link').removeClass('active'); $('#fni-add-modal-tab-content .tab-pane').removeClass('show'); $('#fni-add-modal-tab-content .tab-pane').removeClass('active'); switch (type) { case 1: $('#fni-add-modal-tab-information').addClass('active'); $('#fni-add-modal-information').addClass('active'); $('#fni-add-modal-information').addClass('show'); break; case 2: $('#fni-add-modal-tab-insurance').addClass('active'); $('#fni-add-modal-insurance').addClass('active'); $('#fni-add-modal-insurance').addClass('show'); break; } } function fillDealer(){ var comp = $('#company-filter').val(); dealer = 0; $.ajax({ url:"app/misc/get_dealer3.php", type:"POST", data: { company: comp, type: 1 }, beforeSend: function(){ }, success: function(result){ $('#dealer').html(''); // $('#dealer').append("\"<option value=''>ALL</option>\""); $('#dealer').append("\"" + result + "\""); } }); } function initTableFinance() { var $table = $('#finance-table') $table.bootstrapTable('destroy').bootstrapTable({ onLoadSuccess: function(data) { detailsCount(start_date, end_date); } }) } function refreshFinanceTable() { var $table = $('#finance-table') $(function() { $table.bootstrapTable('refresh', { // 1 url: 'app/table/finance_table.php' }); }) } function queryParamsFinanceTable(params) { start = $('#filter-date').data('daterangepicker').startDate; end = $('#filter-date').data('daterangepicker').endDate; company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); if(company === null || company == "" || typeof company === "undefined"){ company = 0; } dealer = ($("#dealer").val() == '') ? '0' : $("#dealer").val(); if(dealer === null || dealer == "" || typeof dealer === "undefined"){ dealer = 0; } if(filter_date == 1){ start_date = start.format('YYYY-MM-DD'); end_date = end.format('YYYY-MM-DD'); } else { start_date = ""; end_date = ""; } if(reset == 0){ if(filter_date == 0){ $('#span-date-range').text("No Filter"); } else { $('#span-date-range').text(start.format('MMM D, YYYY') + ' - ' + end.format('MMM D, YYYY')); } } else { $('#span-date-range').text("No Filter"); } $('#span-company').text(company == 0 ? 'ALL' : $("#company-filter option:selected").text()); if(reset == 1){ $('#span-dealer').text("ALL"); } else { $('#span-dealer').text(dealer == 0 ? 'ALL' :$("#dealer option:selected").text()); } return { search: params.search, offset: params.offset, limit: params.limit, type: 1, company: company, dealer: dealer, start_date: start_date, end_date: end_date, filter_box: filter_box }; } function initToolTip(){ var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $('.tooltip-me').bstooltip(); } function setDateRangePickerWidth(isMobile) { if ($(".daterangepicker").hasClass('show-calendar') && !isMobile) { $('.daterangepicker').css('width', '630px'); } else { $('.daterangepicker').css('width', 'auto'); } reset = 0; } function passDate(startDate, endDate) { refreshFinanceTable(); } function cb(start, end) { var startDate = start.format('YYYY-MM-DD'); passDate(start, end); //pass empty dates } function addListenerCompanyFilter() { $('#company-filter').off('change.mychange').on('change.mychange', function() { var start = $('#filter-date').data('daterangepicker').startDate; var end = $('#filter-date').data('daterangepicker').endDate; company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); fillDealer(); reset = 0; cb(start, end); }); } function resetDateRangePicker(start, end) { $("#filter-date").data('daterangepicker').setStartDate(start); $("#filter-date").data('daterangepicker').setEndDate(end); $('#filter-date').data('daterangepicker').hideCalendars(); $('.daterangepicker').css('width', 'auto'); var startDate = start.format('MMMM DD, YYYY'); var endDate = end.format('MMMM DD, YYYY'); if(reset == 0) {$('#date-range').text(startDate + ' - ' + endDate);} else if(reset == 1) {$('#date-range').text("No Filter");} cb(start, end); } function fillModelDropdown(brand){ $.ajax({ url:"/app/finance/dd_get_model.php", type:"POST", data: { brand_id: brand, type: 1 }, beforeSend: function(){ }, success: function(result){ $('#fni-add-model').html(''); $('#fni-add-model').append("\"<option value=''></option>\""); $('#fni-add-model').append("\"" + result + "\""); } }); } function fillVariantDropdown(model){ $.ajax({ url:"/app/finance/dd_get_variant.php", type:"POST", data: { model_id: model, type: 1 }, beforeSend: function(){ }, success: function(result){ $('#fni-add-variant').html(''); $('#fni-add-variant').append("\"<option value=''></option>\""); $('#fni-add-variant').append("\"" + result + "\""); } }); } function detailsCount(sd, ed){ $.ajax({ url:"app/finance/finance_list_boxes.php", type:"POST", dataType:"json", data: { company: company, dealer: dealer, start_date: sd, end_date: ed, type: 1 // details box count }, beforeSend: function(){ }, success: function(result){ $('#span-total').text(result.total_count); $('#span-expiring').text(result.exp_this_month); $('#span-individual-insurance').text(result.individual_insurance); $('#span-added').text(result.added_today); } }); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $('.tooltip-me').bstooltip(); } function removeCustomer(customer_record_id){ Swal.fire({ icon: 'question', html: 'Are you sure you want to remove this customer?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Confirm`, denyButtonText: `Don't Confirm`, }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer/customerv2.php", method: "POST", dataType: 'json', data: { apiKey: '3695340036334748', customer_id: customer_record_id }, beforeSend: function() { sweetAlertSimple('info', 'Oops...', 'Removing customer...') }, success: function(result) { if(parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); var url = location_url+"customer.php"; window.location.href = url; } else { sweetAlertSimple('error', 'Oops...', result.message) } }, error: function() { sweetAlertSimple('error', 'Oops...', 'Error has been occurred, please try again.') } }); } else if (result.isDenied) { // Swal.fire('', 'Changes are not saved', 'info') } }) } function clearElements(){ $('.el-add').val(""); $('.dd-add').val(0).trigger('change'); } $('#dealer').on('change', function(){ dealer = $('#dealer').val(); var start = $('#filter-date').data('daterangepicker').startDate; var end = $('#filter-date').data('daterangepicker').endDate; reset = 0; cb(start, end); }) $('#finance-table').on('click-cell.bs.table', function(field, value, row, $el) { plate_cs_number = $el.plate_cs_number1; window.location.href = "/financelist/" + plate_cs_number; }); $('#company-filter').on('select2: unselecting', function(event){ $('#company-filter').val(""); }) $('#fni-add-brand').on('select2: unselecting', function(event){ fni_add_brand = ""; }) $('#fni-add-dealer').on('select2: unselecting', function(event){ fni_add_dealer = ""; }) $('#fni-add-insurance-provider').on('select2: unselecting', function(event){ fni_add_ins_provider = ""; }) $('#fni-add-insurance-type').on('select2: unselecting', function(event){ fni_add_ins_type = ""; }); $('#fni-add-brand').on('change', function(){ var brand_selected = $('#fni-add-brand').val(); fillModelDropdown(brand_selected); }); $('#fni-add-model').on('change', function(){ var model_selected = $('#fni-add-model').val(); fillVariantDropdown(model_selected); }); $('#box-categorized').on('click', function(){ filter_box = 1; refreshFinanceTable(); }); $('#box-individual-insurance').on('click', function(){ filter_box = 2; refreshFinanceTable(); }); $('#box-expiring').on('click', function(){ filter_box = 3; refreshFinanceTable(); }); $('#box-added').on('click', function(){ filter_box = 4; refreshFinanceTable(); }); $('#button-new-fni-details').on('click', function(){ $('#modal-finance-add-fni').modal('show'); addFNIModalTabSelectedTab(1); }) $('#check-lock-in').on('click', function(){ if(fni_add_locked_in == 0){fni_add_locked_in = 1;} else {fni_add_locked_in = 0;} }); $('#button-add-fni-details').on('click', function(){ fni_add_plate_cs_number = $('#fni-add-plate-cs-number').val(); fni_add_brand = $('#fni-add-brand').val(); fni_add_model = $('#fni-add-model').val(); fni_add_variant = $('#fni-add-variant').val(); fni_add_dealer = $('#fni-add-dealer').val(); fni_add_customer_fullname = $('#fni-add-customer-fullname').val(); fni_add_customer_mobile = "+63" + $('#fni-add-customer-mobile').val(); fni_add_customer_other_contact = $('#fni-add-customer-other-contact').val(); fni_add_customer_email = $('#fni-add-customer-email').val(); fni_add_customer_address = $('#fni-add-customer-address').val(); fni_add_policy_issue_date = $('#issue-date').val(); fni_add_policy_start_date = $('#start-date').val(); fni_add_policy_end_date = $('#end-date').val(); fni_add_policy_number = $('#fni-add-policy-number').val(); fni_add_bank = $('#fni-add-bank').val(); fni_add_insurance_provider = $('#fni-add-insurance-provider').val(); fni_add_insurance_type = $('#fni-add-insurance-type').val(); fni_add_sales_consultant = $('#fni-add-sales-consultant').val(); fni_add_paid_amount = $('#fni-add-paid-amount').val(); fni_add_lock_in_year = $('#fni-add-lock-in-year').val(); fni_add_terms = $('#fni-add-terms').val(); // REQUIREMENTS if(fni_add_plate_cs_number == ""){ toastr.remove(); toastr.error("Plate/CS Number cannot be empty", "Incomplete data"); return; } if(fni_add_brand == ""){ toastr.remove(); toastr.error("Please specify brand", "Incomplete data"); return; } if(fni_add_model == ""){ toastr.remove(); toastr.error("Please specify model", "Incomplete data"); return; } if(fni_add_dealer == ""){ toastr.remove(); toastr.error("Please specify dealer", "Incomplete data"); return; } if(fni_add_customer_fullname == ""){ toastr.remove(); toastr.error("Customer name cannot be empty", "Incomplete data"); return; } if(add_mobile_required == 1){ if(fni_add_customer_mobile == ""){ toastr.remove(); toastr.error("Customer mobile cannot be empty", "Incomplete data"); return; } else { // VALIDATIONS if(fni_add_customer_mobile.length != 13){ toastr.remove(); toastr.error("Customer mobile seems invalid"); return; } if(fni_add_customer_mobile.substring(0, 4) != "+639"){ toastr.remove(); toastr.error("Customer mobile seems invalid"); return; } } } if(add_email_required == 1){ if(fni_add_customer_email == ""){ toastr.remove(); toastr.error("Customer email cannot be empty", "Incomplete data"); return; } } if(fni_add_policy_issue_date == ""){ toastr.remove(); toastr.error("Please specify Policy Issue date", "Incomplete data"); return; } if(fni_add_policy_start_date == ""){ toastr.remove(); toastr.error("Please specify Policy Start date", "Incomplete data"); return; } if(fni_add_policy_end_date == ""){ toastr.remove(); toastr.error("Please specify Policy End date", "Incomplete data"); return; } if(add_policy_required == 1){ if(fni_add_policy_number == ""){ toastr.remove(); toastr.error("Policy Number cannot be empty", "Incomplete data"); return; } } if(fni_add_insurance_provider == ""){ toastr.remove(); toastr.error("Please specify Insurance Provider", "Incomplete data"); return; } if(fni_add_insurance_type == ""){ toastr.remove(); toastr.error("Please specify Insurance Type", "Incomplete data"); return; } // date validation var sd = new Date(fni_add_policy_start_date); var ed = new Date(fni_add_policy_end_date); var time_difference = ed.getTime() - sd.getTime(); var date_diff = time_difference / (1000*60*60*24); if(date_diff < 0){ toastr.remove(); toastr.warning("It seems that start date and end date interchange", "Confusing date: Start date is less than End date"); return; } else if(date_diff < 365){ toastr.remove(); toastr.warning("It seems that the interval between start date and end date is less than a year", "Not one year"); return; } // ADD RECORD $.ajax({ url:"app/finance/finance_crud.php", type:"POST", dataType:"json", data: { new_plate_cs_number: fni_add_plate_cs_number, new_brand: fni_add_brand, new_model: fni_add_model, new_variant: fni_add_variant, new_dealer: fni_add_dealer, new_customer_fullname: fni_add_customer_fullname, new_customer_mobile: fni_add_customer_mobile, new_customer_other_contact: fni_add_customer_other_contact, new_customer_email: fni_add_customer_email, new_customer_address: fni_add_customer_address, new_policy_issue_date: fni_add_policy_issue_date, new_policy_start_date: fni_add_policy_start_date, new_policy_end_date: fni_add_policy_end_date, new_policy_number: fni_add_policy_number, new_bank: fni_add_bank, new_insurance_provider: fni_add_insurance_provider, new_insurance_type: fni_add_insurance_type, new_sales_consultant: fni_add_sales_consultant, new_paid_amount: fni_add_paid_amount, new_lock_in_year: fni_add_lock_in_year, new_terms: fni_add_terms, new_lock_in: fni_add_locked_in, type: 1 // add new record }, beforeSend: function(){ $('#loading-view').attr('hidden', false); $('.el-add').attr('disabled', true); }, success: function(result){ if(result.status == 0){ // success toastr.remove(); toastr.success("Added successfully"); $('#modal-finance-add-fni').modal('hide'); $('#loading-view').attr('hidden', true); $('.el-add').attr('disabled', false); refreshFinanceTable(); detailsCount(); clearElements(); } else if(result.status == 1){ // failed add $('#loading-view').attr('hidden', true); $('.el-add').attr('disabled', false); toastr.remove(); toastr.error("Adding failed, please try again"); } else if(result.status == 2){ // dealer validation error $('#loading-view').attr('hidden', true); $('.el-add').attr('disabled', false); toastr.remove(); toastr.error("Dealer validation error"); } else if(result.status == 3){ // duplicate toastr.remove(); toastr.warning("Duplicate record"); // var duplicate_id = result.duplicate_id; // var duplicate_plate_cs_number = result.duplicate_plate_cs_number; // alertDuplicate(duplicate_id, duplicate_plate_cs_number); $('#loading-view').attr('hidden', true); $('#button-add-fni-details').attr('disabled', false); return; } else if(result.status == 4){ // invalid email $('#loading-view').attr('hidden', true); $('.el-add').attr('disabled', false); toastr.remove(); toastr.error("Invalid email"); return; } } }) }) function alertDuplicate(id, plate_cs_number){ Swal.fire({ icon: 'question', html: 'Are you sure you want to remove this customer?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Confirm`, denyButtonText: `Don't Confirm`, }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer/customerv2.php", method: "POST", dataType: 'json', data: { apiKey: '3695340036334748', customer_id: customer_record_id }, beforeSend: function() { sweetAlertSimple('info', 'Oops...', 'Removing customer...') }, success: function(result) { if(parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); var url = location_url+"customer.php"; window.location.href = url; } else { sweetAlertSimple('error', 'Oops...', result.message) } }, error: function() { sweetAlertSimple('error', 'Oops...', 'Error has been occurred, please try again.') } }); } else if (result.isDenied) { // Swal.fire('', 'Changes are not saved', 'info') } }) }
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings