var vehicle_form = false; function fetchVehicleInfo(vehicle_id, customer_record_id) { $('#loader').show(); $('#vehicle-information').show(); readCustomerInformationMain(customer_record_id); // readVehicleProfileMain(vehicle_id); setVehicleTab(); } function back() { window.history.back(); } function setVehicleTab() { hideTabActionButton(); removeTabActive(); var selected_tab = ''; if(isEmpty($.cookie("vehicle_selected_tab"))) { //set default tab $.cookie("vehicle_selected_tab",'custom-tabs-three-home-tab') selected_tab = $.cookie("vehicle_selected_tab"); }else{ selected_tab = $.cookie("vehicle_selected_tab"); } //show tab and content $('#'+selected_tab).addClass('active') $('#'+selected_tab+'-content').addClass('active').addClass('show') switch (selected_tab) { case 'custom-tabs-three-home-tab': $('#vehicle-info-button').show(); break; case 'custom-tabs-three-gallery-tab': $('#vehicle-info-button').show(); readVehicleImage(vehicle_record_id); break; case 'custom-tabs-sales-tab': $('#vehicle-info-button').show(); readBrandsOfferedMain(vehicle_record_id); readVehicleSaleDetailsMain(vehicle_record_id); break; case 'custom-tabs-service-tab': refreshServiceDates(); break; } } function readVehicleImage(vehicle_id) { $.ajax({ url: "api/vehicle/vehiclev2.php", type: "POST", dataType: 'json', data: { apiKey: '1164288154587287', vehicle_id: vehicle_id }, beforeSend: function() {}, success: function(result) { // result.total $('#customer-sales-image-data').html(''); $('#customer-sales-image-data').append(result.vehicle_image); } }); } function refreshServiceDates() { var $table = $('#vehicle-service-dates-table') $table.bootstrapTable('destroy').bootstrapTable(); $(function() { $table.bootstrapTable('refresh', { url: 'app/table/service.php' }); }) } function readVehicleProfileMain(vehicle_id) { $.ajax({ url: "api/vehicle/vehiclev2.php", method: "POST", dataType: 'json', data: { apiKey: '5169873963910872', vehicle_id: vehicle_id }, beforeSend: function() { }, success: function(result) { var json = JSON.stringify(result); data = JSON.parse(json)[0]; var count_delay = 0; // alert(data['mod-dd-model-name']); // alert(data['mod-dd-color-name']) $.each(data, function(i, n) { var excemptedFields = ["main_corporation_name", "main_first_name", "main_middle_name", "main_last_name", "information_modified_by", "information_date_modified" ]; if (excemptedFields.indexOf(i) < 0) { //excempted list $("#" + i).css('color', '') if (isEmpty(n)) { $("#" + i).text('(Not Provided)'); $("#" + i).val('(Not Provided)'); $("#" + i).css('color', 'red') } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') } } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') } }); if(isEmpty(data['information_modified_by'])){ $("#information_modified_by_span").hide(); }else{ $("#information_modified_by_span").show(); } if(isEmpty(data['information_date_modified'])){ $("#information_date_modified_span").hide(); }else{ $("#information_date_modified_span").show(); } $('#loader').hide(); // $("#profileDisplay").attr("src", "dist/img/brand/" + data['profileDisplay']); // $("#profileDisplay_pop").attr("href", "dist/img/brand/" + data['profileDisplay']); }, error: function(xhr, status, error) { $('#loader').hide(); back(); sweetAlertSimple('error', 'Oops...', 'Error has occurred, Try again...'); // toastr.remove(); // toastr.error('Error has occurred, Try again...'); } }); } function readCustomerInformationMain(customer_record_id) { // alert(customer_record_id) new_customer_record_id = isEmpty(customer_record_id) ? '-1' : customer_record_id; $.ajax({ url: "api/vehicle/vehiclev2.php", method: "POST", dataType: 'json', data: { apiKey: '8361020315855100', customer_id: new_customer_record_id }, beforeSend: function() {}, success: function(result) { var json = JSON.stringify(result); // console.log(json); data = JSON.parse(json)[0]; $.each(data, function(i, n) { var excemptedFields = ["main_corporation_name", "main_first_name", "main_middle_name", "main_last_name", "information_modified_by", "information_date_modified" ]; if (excemptedFields.indexOf(i) < 0) { //excempted list $("#" + i).css('color', '') $("#sales_" + i).css('color', '') if (isEmpty(n)) { $("#" + i).text('(Not Provided)'); $("#" + i).val('(Not Provided)'); $("#" + i).css('color', 'red') $("#sales_" + i).text('(Not Provided)'); $("#sales_" + i).val('(Not Provided)'); $("#sales_" + i).css('color', 'red') } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') $("#sales_" + i).text(n); $("#sales_" + i).val(n); $("#sales_" + i).trigger('change') $("#sales_" + i).css('color', '007bff') } } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') $("#sales_" + i).text(n); $("#sales_" + i).val(n); $("#sales_" + i).trigger('change') } }); var image_name = 'default.png'; if (!isEmpty(data['photo'])) { image_name = data['photo']; } $("#profileDisplay").attr("src", "dist/img/customer/" + image_name); $("#profileDisplay_pop").attr("href", "dist/img/customer/" + image_name); $(".contact-click").attr("href", "tel:" + $('#main_customer_mobile').text()) $(".landline-click").attr("href", "tel:" + $('#main_customer_landline').text()) $(".contact2-click").attr("href", "tel:" + $('#main_customer_mobile_2').text()) $(".business-click").attr("href", "tel:" + $('#main_customer_business_mobile').text()) $(".residential-click").attr("href", "tel:" + $('#main_customer_home_mobile').text()) $(".viber-click").attr("href", "viber://chat?number=" + $('#main_viber').text()) $(".facebook-click").attr("href", "http://www.facebook.com/" + $('#main_facebook').text()) $(".instagram-click").attr("href", "http://instagram.com/_u/" + $('#main_instagram').text()) $(".whatsapp-click").attr("href", "https://wa.me/" + $('#main_whatsapp').text()) $(".telegram-click").attr("href", "https://t.me/" + $('#main_telegram').text()) $(".website-click").attr("href", "http://" + $('#main_website_link').text()) $(".email1-click").attr("href", "mailto:" + $('#main_email').text()) $(".email2-click").attr("href", "mailto:" + $('#main_customer_email_2').text()) $(".main_name_click").attr("href", "customer_view.php?q=" + new_customer_record_id) $(".main_name_click").click(function() { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); }); // $(".main_name_click").attr("href", "customer_view.php?q=" + new_customer_record_id) }, error: function(xhr, status, error) { $('#loader').hide(); back(); sweetAlertSimple('error', 'Oops...', 'Error has occurred, Try again...'); // toastr.remove(); // toastr.error('Error has occurred, Try again...'); } }); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case 'success': toastr.success(text); break; case 'info': toastr.info(text); break; case 'warning': toastr.warning(text); break; case 'error': toastr.error(text); break; } } function getASANameByASAID(objectId, asa_id) { $.ajax({ url: 'https://www.autohub.ph/connect/LOAD_SALES_PERSON.php', type: "POST", dataType: 'json', data: { uid: asa_id, apiKey: '3892635489643867' }, beforeSend: function() {}, success: function(result) { // alert(result.u_fname) var name = result['rows'][0].u_fname + ' ' + result['rows'][0].u_lname; // alert(name) var newOption = new Option(name, asa_id, true, true); $("#" + objectId).append(newOption).trigger('change'); } }); } function queryServiceDates(params) { return { search: '', offset: params.offset, limit: params.limit, vehicle_id: vehicle_record_id //other filters hehe }; } function isEmpty(string) { var flag = false; if (string == '') { flag = true; } else if (string == null) { flag = true; } else if (typeof string === 'undefined') { flag = true; } else { try{ if (string.trim() == '') { flag = true; } }catch(err){ return true; } } return flag; } function removeImage(id) { // alert(id); Swal.fire({ icon: 'warning', html: 'Do you want to remove this image?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Confirm`, denyButtonText: `Don't Confirm`, }).then((result) => { if (result.isConfirmed) { // toastr.remove(); $.ajax({ url: "api/vehicle/vehiclev2.php", method: "POST", data: { apiKey: '9434631886897744', id: id }, cache: false, beforeSend: function() { sweetAlertSimple('info', 'Oops...', 'Removing image...'); }, success: function(data) { // fetchVehicleInfo(vehicle_record_id, customer_record_id) readVehicleImage(vehicle_record_id); sweetAlertSimple('success', 'Oops...', 'Image remove successfully.'); } }) } else if (result.isDenied) { // Swal.fire('', 'Changes are not saved', 'info') } }) } function readVehicleSaleDetailsMain(vehicle_id) { $.ajax({ url: "api/sales/salesv2.php", method: "POST", dataType: 'json', data: { apiKey: '9718832291017422', vehicle_id: vehicle_id }, beforeSend: function() { }, success: function(result) { var json = JSON.stringify(result); // alert(JSON.parse(json).length) if (JSON.parse(json).length < 1) { $('#vehicle-sales-information').hide(); $('#sales-information-footer').hide(); $('#information-sale-brand-div').hide(); $('#information-sale-model-div').hide(); $('#information-sale-conduction-sticker-div').hide(); $('#information-sale-model-variant-div').hide(); $('#no-vehicle-sales-information').show(); $('#action-sales').val('Add Sales'); has_sales_record = false; return; } $('#vehicle-sales-information').show(); $('#sales-information-footer').hide(); $('#information-sale-brand-div').hide(); $('#information-sale-conduction-sticker-div').hide(); $('#information-sale-model-div').hide(); $('#information-sale-model-variant-div').hide(); $('#no-vehicle-sales-information').hide(); $('#action-sales').val('Update Sales'); has_sales_record = true; data = JSON.parse(json)[0]; var count_delay = 0; // alert(data['mod-dd-model-name']); // alert(data['mod-dd-color-name']) $.each(data, function(i, n) { // alert('') var excemptedFields = ["main_corporation_name", "main_first_name", "main_middle_name", "main_last_name", "information_modified_by", "information_date_modified" ]; if (excemptedFields.indexOf(i) < 0) { //excempted list $("#" + i).css('color', '') if (isEmpty(n)) { $("#" + i).text('(Not Provided)'); $("#" + i).val('(Not Provided)'); $("#" + i).css('color', 'red') } else { if (i == 'information-sale-price' || i == 'information-sale-cost' || i == 'information-sale-discount') { var currency_format = addCommas(n); $("#" + i).text(currency_format); $("#" + i).val(currency_format); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') } } } else { if (i == 'information-sale-price' || i == 'information-sale-cost' || i == 'information-sale-discount') { var currency_format = addCommas(n); $("#" + i).text(currency_format); $("#" + i).val(currency_format); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') } } }); // $("#sales_profileDisplay").attr("src", data['sales_profileDisplay']); // $("#sales_profileDisplay_pop").attr("href", data['sales_profileDisplay']); // $("#profileDisplay").attr("src", data['sales_profileDisplay']); // $("#profileDisplay_pop").attr("href", data['sales_profileDisplay']); } }); } function addCommas(numberString) { numberString += ''; var x = numberString.split('.'), x1 = x[0], x2 = x.length > 1 ? '.' + x[1] : '', rgxp = /(\d+)(\d{3})/; while (rgxp.test(x1)) { x1 = x1.replace(rgxp, '$1' + ',' + '$2'); } return x1 + x2; } function readBrandsOfferedMain(vehicle_id) { $.ajax({ url: "api/sales/salesv2.php", method: "POST", dataType: 'json', data: { apiKey: '5339702066391571', vehicle_id: vehicle_id }, beforeSend: function() { }, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; $('#information_vehicle_offered_list').empty() $("#information_vehicle_offered_list").append( '