//GLOBALS WITTHOUT PHP
var customer_record_type = "1";
var vehicle_form = false;
//FUNCTIONS
function initVehicleSection() {
if (!vehicle_form) {
vehicle_form = true;
$.ajax({
url: 'include/components/customer/modal/vehicle_form.php',
type: 'post',
beforeSend: function() {
$('#customer-vehicle-button').attr('disabled', true);
},
success: function(data) {
$('#vehicle_form').html(data);
$.ajax({
url: 'dist/js/vehicle/vehicle_form.js',
type: 'post',
success: function(data) {
$('#customer-vehicle-button').attr('disabled', false);
initVehicle();
},
error: function() {
$('#vehicle_form').text('An error occurred');
}
});
},
error: function() {
$('#vehicle_form').text('An error occurred');
}
});
} else {
$('#modal-vehicle').modal('show');
initOwnerSelect2();
}
}
function refreshTableLogs() {
var $table = $('#logs-table')
$table.bootstrapTable('destroy').bootstrapTable();
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/table/customer_log.php'
});
})
}
function queryParamsLogs(params) {
console.log(params)
return {
search: params.search,
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
customer_id: customer_record_id
};
}
function queryParamsSales(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
customer_id: customer_record_id
};
}
function queryParamsService(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
customer_id: customer_record_id
};
}
function queryParamsCorporationCustomer(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
customer_id: customer_record_id,
customer_corporation: true
};
}
function readCustomerSalesImage() {
$.ajax({
url: "api/customer/customerv2.php",
type: "POST",
dataType: 'json',
data: {
apiKey: '7472626829226859',
customer_id: customer_record_id
},
beforeSend: function() {
$('#loader').show();
},
success: function(result) {
// result.total
$('#customer-sales-image-data').html('');
$('#customer-sales-image-data').append(result.sales_image);
$('#loader').hide();
}
});
}
function readCustomerChildren(isModal) {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '8307826786414874',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
if (isModal) {
if (obj.length > 0) {
// $('#unit_association').click();
}
} else {
$('#information_family_list').empty()
$("#information_family_list").append(
'
Children/s List'
);
if (obj.length > 0) {
$('#information_family_div').show();
$('#family-page-footer').hide();
} else {
$('#information_family_div').hide();
$('#family-page-footer').show();
}
}
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
if (isModal) {
var item = addCustomerChildren();
let $elementFirstname = $('#' + item[0]);
let $elementLastname = $('#' + item[1]);
let $elementBirthday = $('#' + item[2]);
let $elementMobile = $('#' + item[3]);
$elementFirstname.val(value.first_name);
$elementLastname.val(value.last_name);
$elementBirthday.val(value.date_of_birth);
$elementMobile.val(value.mobile_phone);
} else {
var new_mobile = (value.mobile_phone != '') ? '+63' + value
.mobile_phone : '';
$("#information_family_list").append(`
Name:
` +
value.first_name + ' ' + value.last_name +
`
Birthday: ` +
value.date_of_birth +
`
`);
}
}, count_delay * 250);
count_delay++;
});
}
});
}
function readCustomerAffiliations(isModal) {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '5660696728127200',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
if (isModal) {
if (obj.length > 0) {
// $('#unit_association').click();
}
} else {
$('#information_affiliations_list').empty()
$("#information_affiliations_list").append(
// 'Village or Condo Homeowners Association'
);
if (obj.length > 0) {
$('#information_affiliations_div').show();
$('#affiliations-page-footer').hide();
} else {
$('#information_affiliations_div').hide();
$('#affiliations-page-footer').show();
}
}
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
if (isModal) {
var item = addAffiliationsItem();
let $elementCategory = $('#' + item[0]);
$elementCategory.val(value
.affiliation_category).trigger('change');
let $elementContent = $('#' + item[1]);
var newContent = new Option(value.affiliation_content, value
.affiliation_content, true, true)
$elementContent.append(newContent).trigger('change');
} else {
$("#information_affiliations_list").append(`
Category:
` +
value.affiliation_category_name +
`
Name: ` +
value.affiliation_content +
`
`);
}
}, count_delay * 250);
count_delay++;
});
}
});
}
function fetchCustomerInfo(customer_record_id) {
$("#profileDisplay").attr("src", "dist/img/customer/default.png");
$(".customer-data-side").text('');
$(".basic-info-name").text('');
$(".basic-info-email").text('');
$(".basic-info-mobile").text('');
$(".basic-info-type").text('');
$('#loader').show();
$('#h3-card-title').text("Customer Profile");
$('#customer-about-me').show();
$('#customer-details').show();
$('#information-customer').show();
$('#customer-vehicle').show();
$('#customer-service').show();
$('#customer-sales').show();
$('#customer-corporation-individual').show();
readCustomerInformationMain();
readCustomerInterestMain();
readCustomerContactPersonMain();
readCustomerChildren(false);
readCustomerAffiliations(false);
setCustomerTab();
}
function setCustomerTab(){
hideCustomerTabActionButton();
removeTabActive();
var selected_tab = '';
if(isEmpty($.cookie("customer_selected_tab"))) {
//set default tab
$.cookie("customer_selected_tab",'custom-tabs-three-home-tab')
selected_tab = $.cookie("customer_selected_tab");
}else{
selected_tab = $.cookie("customer_selected_tab");
}
//show tab and content
$('#'+selected_tab).addClass('active')
$('#'+selected_tab+'-content').addClass('active').addClass('show')
//additional condition here
switch (selected_tab) {
case 'custom-tabs-three-home-tab':
$('#customer-info-button').show();
break;
case 'custom-tabs-three-hobbies-tab':
$('#customer-info-button').show();
break;
case 'custom-tabs-three-family-tab':
$('#customer-info-button').show();
break;
case 'custom-tabs-vehicle-tab':
$('#customer-vehicle-button').show();
var offset_n = 0;
if (!isEmpty($.cookie("vehicle_list_offset"))) {
offset_n = parseInt($.cookie("vehicle_list_offset"));
}
console.log('111')
getVehiclesGrid(offset_n, 9);
break;
case 'custom-tabs-service-tab':
refreshTableService();
break;
case 'custom-tabs-sales-tab':
refreshTableSales();
break;
case 'custom-tabs-three-individuals-tab':
refreshTableCorporationIndividual();
break;
case 'custom-tabs-three-gallery-tab':
readCustomerSalesImage();
break;
case 'custom-tabs-customer-logs-tab':
refreshTableLogs();
break;
case 'custom-tabs-customer-activities-tab':
refreshTableActivities();
break;
case 'custom-tabs-insurance-tab':
initTableFinance();
getVehicles();
break;
}
}
// start --------------------- appended code -> khel (insurance tab)
var arr_found = new Array();
function initTableFinance() {
var $table = $('#finance-table')
$table.bootstrapTable('destroy').bootstrapTable({
// onLoadSuccess: function(data) {
// // detailsCount(start_date, end_date);
// }
});
}
function refreshFinanceTable() { // alert(JSON.stringify(arr_found)); return;
var $table = $('#finance-table')
$(function() {
$table.bootstrapTable('refresh', { // 7
url: 'app/table/finance_table.php'
});
})
}
function queryParamsFinanceTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
plate_cs_number: arr_found,
type: 7
};
}
function getVehicles() {
$.ajax({
url: "api/customer/customer_insurance.php",
method: "POST",
dataType: 'json',
data: {
type: 1,
customer_id: customer_record_id
},
beforeSend: function() {
},
success: function(result) { // alert(JSON.stringify(result)); return;
getFniOfVehicle(result);
}
});
}
function getFniOfVehicle(itemsArr){
$.ajax({
url: "api/customer/customer_fni.php",
method: "POST",
dataType: 'json',
data: {
arr: itemsArr,
type: 1
},
success: function(result){
if(result.length === 0){
arr_found = 0;
}
else {
arr_found = result;
}
refreshFinanceTable();
}
});
}
function addToTable(arr){
$.ajax({
url: "api/customer/customer_fni.php",
method: "POST",
// dataType: 'json',
data: {
type: 2,
arr: arr
},
success: function(result){
$('#table_data').prepend(result);
}
});
}
// end --------------------- appended code -> khel (insurance tab)
function checkFieldsMain(customer_type) {
if (parseInt(customer_type) === 1) {
$('#information_dob_span').text('Date of birth');
$('#information_gender_div').show();
$('#information_religion_div').show();
$('#information_nationality_div').show();
$('#information_business_company_name_div').show();
$('#information_position_div').show();
$('#information_marital_status_div').show();
$('#information_spouse_div').show();
$('#div-mod-no-of-children_div').show();
// $('#information_interest_hobbies_div').show();
$('#information_profession_div').show();
$('#customer-family-tab').show();
$('#customer-corporation_individuals-tab').hide();
}
else if (parseInt(customer_type) === 2) {
$('#information_dob_span').text('Date established');
$('#information_gender_div').hide();
$('#information_religion_div').hide();
$('#information_nationality_div').hide();
$('#information_business_company_name_div').hide();
$('#information_position_div').hide();
$('#information_marital_status_div').hide();
$('#information_spouse_div').hide();
$('#div-mod-no-of-children_div').hide();
// $('#information_interest_hobbies_div').hide();
$('#information_profession_div').hide();
$('#customer-family-tab').hide();
$('#customer-corporation_individuals-tab').show();
}
}
function readCustomerInformationMain() {
// return false;
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '8361020315855100',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var json = JSON.stringify(result);
data = JSON.parse(json)[0];
if(isEmpty(data['customer_record_id'])){
window.location.href ='customer.php';
return;
}
$.each(data, function(i, n) {
console.log('i :'+i+ ' n : '+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(){
// }
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();
}
customer_record_type = data['customer_type_id'];
checkFieldsMain(customer_record_type);
$(".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())
$(".email-click").attr("href", "mailto:" + $('#main_email').text())
$(".email2-click").attr("href", "mailto:" + $('#main_customer_email_2').text())
$("#profileDisplay").attr("src", "dist/img/customer/" + data['photo']);
$("#profileDisplay_pop").attr("href", "dist/img/customer/" + data['photo']);
$('#loader').hide();
},
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 readCustomerInterestMain() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '6579442853321353',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
$('#information_interest_hobbies_list').empty()
$("#information_interest_hobbies_list").append(
'Interest/Hobbies'
);
if (obj.length > 0) {
$('#information_interest_hobbies_div').show();
} else {
$('#information_interest_hobbies_div').hide();
}
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
$("#information_interest_hobbies_list").append(`
` + value.interest_content + `
` + value.interest_category_name + `
`);
}, count_delay * 250);
count_delay++;
});
}
});
}
function readCustomerContactPersonMain() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '4788616921820004',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
$('#information_contact_person_list').empty()
$("#information_contact_person_list").append(
'Contact Person'
);
if (obj.length > 0) {
$('#information_contact_person_div').show();
} else {
$('#information_contact_person_div').hide();
}
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
$("#information_contact_person_list").append(`
`);
}, count_delay * 250);
count_delay++;
});
}
});
}
function hideCustomerTabActionButton() {
$('#customer-info-button').hide();
$('#customer-gallery-button').hide();
$('#customer-vehicle-button').hide();
}
function removeTabActive() {
$('.customer-tab').removeClass('active')
$('.customer-tab-content').removeClass('active').removeClass('show')
}
function gotoOffset(n) {
$.cookie("vehicle_list_offset", n);
console.log('222')
getVehiclesGrid(n, 9);
}
function getVehiclesGrid(offset, limit) {
$.ajax({
url: "app/table/vehiclev2.php",
type: "POST",
dataType: 'json',
data: {
customer_id: customer_record_id,
grid: 1,
offset: offset,
limit: limit
},
beforeSend: function() {
$('#loader-vehicle').show();
},
success: function(result) {
// result.total
$('#customer-owned-vehicle').html('');
$('#customer-owned-vehicle').append(result.vehicle_list);
$('#customer-owned-vehicle-paging').html('');
if (result.total <= 0) {
$('#customer-owned-vehicle-paging').append(result.vehicle_list_paging);
}
if (result.grid_offset > 6) {
$('#customer-owned-vehicle-paging').append(result.vehicle_list_paging);
}
$('#loader-vehicle').hide();
}
});
}
function customerVehicleInfo(grid_vehicle_id) {
$.cookie("vehicle_selected_tab",'custom-tabs-three-home-tab')
window.location.href = "vehicle_view.php?q=" + grid_vehicle_id;
}
function refreshTableService() {
var $table = $('#service-table')
$table.bootstrapTable('destroy').bootstrapTable();
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/table/service.php'
});
})
}
function refreshTableCorporationIndividual() {
var $table = $('#corporation-individual')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/table/bt_customer_list.php'
});
})
}
function refreshTableSales() {
var $table = $('#sales-table')
$table.bootstrapTable('destroy').bootstrapTable();
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/table/sales.php'
});
})
}
function back() {
window.history.back();
}
function customerModal() {
$('#proceed-button').text("Save changes");
$('#proceed-button').attr('disabled', true);
$('.customer-modal-overlay').show();
if (parseInt(customer_record_type) === 1) {
$('#modal-title').text("Edit Customer Information (Individual)");
checkFieldsModal(true);
} else if (parseInt(customer_record_type) === 2) {
$('#modal-title').text("Edit Customer Information (Corporation)");
checkFieldsModal(false);
}
resetCustomerModal();
//fetch data and put to fields
readCustomerProfile();
}
function readCustomerProfile() {
readCustomerInformation();
readCustomerProfileDataSource();
readCustomerContactPerson();
readCustomerChildren(true);
readCustomerProfileInterest();
readCustomerAffiliations(true);
}
function readCustomerInformation() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '3463916057587803',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
$('.customer-modal-overlay').hide();
$('#proceed-button').attr('disabled', false);
var json = JSON.stringify(result);
data = JSON.parse(json)[0];
$.each(data, function(i, n) {
console.log('i :'+i+' n:'+n);
if (i == 'mod-nature-of-business' && n != 0) {
var newOption = new Option(data['mod-nature-of-business-name'], data[
'mod-nature-of-business-name'], true,
true);
$("#" + i).append(newOption).trigger('change');
} else if (i == 'mod-preferred-moc' && n != 0) {
var newOption = new Option(data['mod-preferred-moc-name'], data['mod-preferred-moc-name'], true,
true);
$("#" + i).append(newOption).trigger('change');
} else if (i == 'mod-dd-profession' && n != 0) {
var newOption = new Option(data['mod-dd-profession-name'], data[
'mod-dd-profession-name'], true,
true);
$("#" + i).append(newOption).trigger('change');
} else if (i == 'mod-business-company' && n != 0) {
var newOption = new Option(data['mod-business-company-name'], data[
'mod-business-company'], true,
true);
$("#" + i).append(newOption).trigger('change');
} else if (i == 'aha-status' ) {
if(parseInt(data['aha-status'])){
$('#aha-status').prop('checked', true).trigger('change')
$('#aha-status').val('1');
}
} else {
// MODIFY
if(i =='mod-other-mobile-number1' && n.length>0){
$("#countInputMobile").val(1);
var count =$("#countInputMobile").val();
appendOtherContact(count);
}
if(i =='mod-other-mobile-number2' && n.length>0){
$("#countInputMobile").val(2);
var count =$("#countInputMobile").val();
appendOtherContact(count);
}
if(i =='mod-other-email1' && n.length > 0){
console.log('email1');
appendOtherEmail(1);
}
if(i =='mod-other-email2' && n!=null && n.length > 0){
console.log('email2');
appendOtherEmail(2);
}
// END MODIFY
$("#" + i).val(n);
$("#" + i).trigger('change')
}
});
}
});
}
// MODIFY
function appendOtherContact(count)
{
let inputMobLengh = $('.mod-div input[name="mob[]"]').length;
console.log('count :'+inputMobLengh);
if(inputMobLengh <2){
var inputCount = $("#countInputMobile").val();
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', 'id':'mod-other-mobile-number','type':'number','maxlength':'10','json-modal':'true','oninput':'"this.value=this.value.slice(0,this.maxLength)"'});
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){
$(this).closest('.mod-div').remove();
$('#mod-contact-div input[name="mob[]"]').each(function(index){
$(this).attr('id',"mod-other-mobile-number"+(index+1));
});
inputMobLengh = inputMobLengh-1;
if(inputMobLengh<1){
$("#btn-add-mobile").show();
}
else{
$("#btn-add-mobile").hide();
}
}); //end delete
$(inputGroup).append(inputBtl,inputjson,deleteSPan);
$(divGrid).append(label,inputGroup);
$("#mod-contact-div").append(divGrid);
$('#mod-contact-div input[name="mob[]"]').each(function(index){
$(this).attr('id',"mod-other-mobile-number"+(index+1));
});
if(inputMobLengh<1){
$("#btn-add-mobile").show();
}
else{
$("#btn-add-mobile").hide();
}
}//end if
}
function appendOtherEmail(count){
if($('#email-add input[name="mob-email[]"]').length <=1){
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'+count,'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'}).click(function(e){
$(this).closest('.div-email').remove();
$('#email-add input[name="mob-email[]"]').each(function(index){
$(this).attr('id',"mod-other-email"+(index+1));
});
if(($('#email-add input[name="mob-email[]"]').length)>=3){
$("#btn-add-email").hide();
}
else
{
$("#btn-add-email").show();
}
}); //end delete
$(inputGroup2).append(inputjson,deleteSPan);
$(inputGroup).append(label,inputGroup2);
$(divGrid).append(inputGroup);
$('#email-add').append(divGrid);
$('#email-add input[name="mob-email[]"]').each(function(index){
$(this).attr('id',"mod-other-email"+(index+1));
});
if(($('#email-add input[name="mob-email[]"]').length)>=2){
$("#btn-add-email").hide();
}
else
{
$("#btn-add-email").show();
}
}//end if
}
// END MODIFY
function readCustomerProfileDataSource() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '3099751888433363',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
var dataSourceItem = addDataSourceItem();
let $dataSourceCustomerNo = $('#' + dataSourceItem[0]);
$dataSourceCustomerNo.val(value.customer_dms_id);
let $dataSourceDMS = $('#' + dataSourceItem[1]);
$dataSourceDMS.val(value.dms_id).trigger('change');
let $dataSourceCompany = $('#' + dataSourceItem[2]);
var newCompanyContent = new Option(value.company_name, value
.company_id, true, true)
$dataSourceCompany.append(newCompanyContent).trigger('change');
let $dataSourceDealer = $('#' + dataSourceItem[3]);
var newDealerContent = new Option(value.dealer_name, value
.dealer_id, true, true)
$dataSourceDealer.append(newDealerContent).trigger('change');
}, count_delay * 250);
count_delay++;
});
}
});
}
function readCustomerContactPerson() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '4788616921820004',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
var item = addCustomerContactPerson();
let $elementFullname = $('#' + item[0]);
let $elementEmail = $('#' + item[1]);
let $elementMobile = $('#' + item[2]);
$elementFullname.val(value.full_name);
$elementEmail.val(value.email);
$elementMobile.val(value.mobile_phone);
}, count_delay * 250);
count_delay++;
});
}
});
}
function readCustomerProfileInterest() {
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '6579442853321353',
customer_id: customer_record_id
},
beforeSend: function() {},
success: function(result) {
var obj = jQuery.parseJSON(JSON.stringify(result));
var index = 0;
if (obj.length > 0) {
// $('#intereset_hobbies_div').click();
}
var count_delay = 0;
$.each(obj, function(key, value) {
setTimeout(function() {
var interestItem = addInterestItem();
let $elementInterestCategory = $('#' + interestItem[0]);
// let val = $elementInterestCategory.find("option:contains('" + value
// .interest_category + "')").val()
$elementInterestCategory.val(value
.interest_category).trigger('change');
let $elementInterestContent = $('#' + interestItem[1]);
var newInterestContent = new Option(value.interest_content, value
.interest_content, true, true)
$elementInterestContent.append(newInterestContent).trigger(
'change');
}, count_delay * 250);
count_delay++;
});
}
});
}
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')
}
})
}
//END FUNCTIONS
$(function() {
fetchCustomerInfo(customer_record_id);
$('#corporation-individual').on('click-cell.bs.table', function(field, value, row, $el) {
if (value == 'email_1' || value == 'mobile_phone_1') {
return;
}
// $.cookie("tab_open_view", 1);
$.cookie("customer_selected_tab", 'custom-tabs-three-home-tab');
window.location.href = "customer_view.php?q=" + $el.id;
});
$('.customer-tab').on('click',function(event){
console.log(this.id);
$.cookie("customer_selected_tab", this.id);
setCustomerTab();
});
$('#service-table').on('click-cell.bs.table', function(field, value, row, $el) {
// window.location.hash = 'data_information';
//Do the Ajax request for getting customer full profile information
var id = $el.id;
var customer_id = $el.customer_id;
var ro_number = $el.ro_number;
$('#loader').show();
$.cookie("service_customer_id", customer_id);
$.cookie("service_service_id", id);
$.cookie("service_ro_number", ro_number);
var url = location_url+"service.php#service_data";
window.location.href = url;
});
$('#sales-table').on('click-cell.bs.table', function(field, value, row, $el) {
//Do the Ajax request for getting customer full profile information
var id = $el.id;
var customer_id = $el.customer_id;
var vehicle_id = $el.vehicle_id;
$('#loader').show();
$.cookie("sale_customer_id", customer_id);
$.cookie("sale_sale_id", id);
$.cookie("sale_vehicle_id", vehicle_id);
var url = location_url+"sales.php#sales_data";
window.location.href = url;
});
$(document).on('click', '[data-toggle="lightbox"]', function(event) {
event.preventDefault();
$(this).ekkoLightbox({
alwaysShowClose: false,
loadingMessage: "Loading…",
});
});
$('#customer-vehicle-button').click(function() {
initVehicleSection();
})
$('#proceed-button').on("click", function() {
// console.log(getCustomerAllModalData());return;
// validate all data
if (parseInt(customer_record_type) === 1) {
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));
if(parseInt(cust_age) < 17 ){
addCustomerModalTabSelectedTab(1);
$('#mod-birthdate').focus();
sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.')
return;
}
}
} else if (parseInt(customer_record_type) === 2) {
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 (parseInt(customer_record_type) === 1) {
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;
}
//MODIFY//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
{
$("#mod-other-mobile-number1").prop('required',false);
}
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(''+$('#mod-other-mobile-number2').length);
$('#mod-other-mobile-number2').attr("required", "false");
$('#mod-other-mobile-number2').removeAttr('required');
}
//END MODIFY
} else if (parseInt(customer_record_type) === 2) {
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())) {
// if (!isEmail($('#mod-email').val())) {
// addCustomerModalTabSelectedTab(2);
// $('#mod-email').focus();
// sweetAlertSimple('error', 'Oops...', 'Invalid email address');
// 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;
// }
// }
//MODIFY
if (!isEmpty($('#mod-email').val())) {
if (!isEmail($('#mod-email').val())) {
addCustomerModalTabSelectedTab(2);
$('#mod-email').focus();
sweetAlertSimple('error', 'Oops...', 'Invalid email address');
return;
}
}
else
{
$('#mod-email').focus();
sweetAlertSimple('error', 'Oops...', 'Email address required');
return;
}
if($('#mod-other-email1').length > 0 && $('#mod-other-email1').val() != '')
{
if (!isEmpty($('#mod-other-email1').val())) {
if (!isEmail($('#mod-other-email1').val())) {
addCustomerModalTabSelectedTab(2);
$('#mod-other-email1').focus();
sweetAlertSimple('error', 'Oops...', 'Invalid other email address');
return;
}
}
if($('#mod-other-email1').val() == $('#mod-email').val())
{
sweetAlertSimple('error', 'Oops...', 'Duplicate email address.');
return;
}
}else if($('#mod-other-email1').length ===1 && $('#mod-other-email1').val()===''){
// console.log('accept validation');return;
$("#mod-other-email1").prop('required',true);
sweetAlertSimple('error', 'Oops...', 'Field required.');
$('#mod-other-email1').focus();
return;
}else
{
$("#mod-other-email1").prop('required',false);
// sweetAlertSimple('error', 'Oops...', 'Field required.');
// $('#mod-other-email2').focus();
// return;
}
if($('#mod-other-email2').length > 0 && $('#mod-other-email2').val() != '')
{
if (!isEmpty($('#mod-other-email2').val())) {
if (!isEmail($('#mod-other-email2').val())) {
addCustomerModalTabSelectedTab(2);
$('#mod-other-email2').focus();
sweetAlertSimple('error', 'Oops...', 'Invalid other email address');
return;
}
}
if($('#mod-other-email2').val() == $('#mod-email').val())
{
sweetAlertSimple('error', 'Oops...', 'Duplicate email address.');
return;
}
if($('#mod-other-email1').val() == $('#mod-other-email2').val())
{
sweetAlertSimple('error', 'Oops...', 'Duplicate email address.');
return;
}
}
else if($('#mod-other-email2').length ===1 && $('#mod-other-email2').val()===''){
// console.log('accept validation');return;
$("#mod-other-email2").prop('required',true);
sweetAlertSimple('error', 'Oops...', 'Field required.');
$('#mod-other-email1').focus();
return;
}
else
{
$("#mod-other-email2").prop('required',false);
// sweetAlertSimple('error', 'Oops...', 'Field required.');
// $('#mod-other-email2').focus();
// return;
}
//END MODIFY
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-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;
}
$.ajax({
url: "api/customer/customerv2.php",
method: "POST",
dataType: 'json',
data: {
apiKey: '8906433219679554',
customer_id: customer_record_id,
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);
fetchCustomerInfo(customer_record_id); //error city dropdown after call
$('#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();
$('#proceed-button').attr('disabled', false);
$('.customer-modal-overlay').hide();
force_update = 0;
force_update_reason = '';
},
error: handleError
});
});
$('#customer_delete_action').click(function() {
removeCustomer(customer_record_id)
})
$('#aha-status').on('change',function(){
if($(this).is(':checked')){
$(this).val('1');
}else{
$(this).val('0');
}
});
//MODIFY
//add mobile number dynamically
$("#btn-add-mobile").on('click', function(){
// var count = $("#countInputMobile").val();
// count++;
let inputMobLengh = $('.mod-div input[name="mob[]"]').length;
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));
});
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-addinput[name="mob-email[]"]').each(function(index){
$(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
});
//END MODIFY
});