PK ZZ signup.jsnu [ var init_signup = function() {
init_toastr();
return $.ajax({
url: "resources/views/signup.php",
data: {},
type: "POST",
beforeSend: function() {
show_hide_preloader(true);
},
success: function(data) {
document.title = 'Sign up';
side_menu_loaded = false;
$('#header_content').html('');
$('#main_content').html(data);
$("#dealer").select2({
// tags:true,
// multiple: true,
placeholder: "Select dealer",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/dealer.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'dealer_list',
api: true,
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
$("#position").select2({
// tags:true,
// multiple: true,
placeholder: "Select position",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/position.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'position_list',
api: true,
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
$('#id_no').on('keyup',function() {
str = $(this).val().trim()
str = str.replace(/\s/g, '')
$(this).val(str)
});
$('#login_account').on('click', function() {
init_signin();
});
$('#btn_signup').on('click', function() {
if (check_if_empty_field($('#dealer'), 'Dealer is required.')) {
return;
}
if (check_if_empty_field($('#id_no'), 'ID number is required.')) {
return;
}
if (check_if_empty_field($('#firstname'), 'Firstname is required.')) {
return;
}
if (check_if_empty_field($('#lastname'), 'Lastname is required.')) {
return;
}
if (check_if_empty_field($('#email'), 'Email address is required.')) {
return;
}
if (!isValidEmailAddress($('#email').val().trim())) {
$('#email').focus();
toastr.remove();
toastr.error('Invalid email address.');
return;
}
if (check_if_empty_field($('#mobile'), 'Mobile is required.')) {
return;
}
if ($('#mobile').val().trim().length < 10) {
$('#mobile').focus();
toastr.remove();
toastr.error('Invalid mobile format.');
return;
}
if (check_if_empty_field($('#password'), 'Password is required.')) {
return;
}
if ($('#password').val().trim().length < 6) {
$('#password').focus();
toastr.remove();
toastr.error('Password must be 6 characters and above.');
return;
}
var $element = $("[json-signup]");
var json_data = generate_json('json-signup', $element);
return $.ajax({
url: "app/models/user.php",
data: {
model: 'signup',
api: true,
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info("Signing up.");
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
init_signin();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
};PK ZZ= common.jsnu [
function defaultFunctions() {
initToolTip()
}
function initToolTip() {
$('.tooltip-me').bstooltip();
$('.tooltip-me').on('click', function() {
$(this).bstooltip('hide')
})
}
function show_hide_preloader(show) {
if (show) {
$(".preloader").css("height", "");
$(".animation__wobble").css("display", "");
} else {
$(".preloader").css("height", "0px");
$(".animation__wobble").css("display", "none");
}
}
function get_user_login_info() {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'user_login_info'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result` )
},
error: function(result) {
// console.log(result)
toastr.remove();
// toastr.error("Error has occurred. Try again.");
toastr.error(result.responseText);
init_signin();
}
});
}
function get_user_notification_info() {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'user_notification_info'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function delay(callback, ms) {
var timer = 0;
return function() {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function() {
callback.apply(context, args);
}, ms || 0);
};
}
function get_user_notifications() {}
function get_user_messages() {}
function add_content_close_listener(elmnt_id) {
var count = 0;
$("#" + elmnt_id + " button[data-card-widget]").each(function() {
if (this.getAttribute("data-card-widget") == "remove") {
$(this).on('click', function() {
$("#" + elmnt_id + " > .card").each(function() {
if ($(this).css('display').toLowerCase() != 'none') {
count++;
}
});
if (count == 1) {
$("#" + elmnt_id).css("display", "none");
if (elmnt_id == 'center_content') {
$("#right_content,#left_content").toggleClass('col-md-3')
.toggleClass('col-md');
side_menu_loaded = false;
}
}
count = 0;
});
}
});
}
function generate_json(attribute, $element) {
var
/* Create an object. */
obj = {},
/* Create a variable that references the current object (default → obj). */
ref = obj;
/* Iterate over every input. */
$element.each(function() {
/* Cache the id of the input. */
var id = this.id;
/* Check whether the nodetype attribute is set to 'parent'. */
if (this.getAttribute(attribute) == "parent") {
/* Set a new object to the property and set ref to refer to it. */
ref = obj[id] = {};
} else {
/* Set the value of the input to the referred object. */
if (this.getAttribute(attribute) == "true") {
if (isEmpty($(this).val())) {
ref[id] = '';
} else {
ref[id] = $(this).val().trim();
}
}
}
});
/* Stringify the object and return it. */
return JSON.stringify(obj);
}
function isValidEmailAddress(emailAddress) {
var pattern =
/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
return pattern.test(emailAddress);
}
function isEmpty(string) {
var flag = false;
try {
if (string.trim() == '') {
flag = true;
} else if (string == null) {
flag = true;
} else if (typeof string === 'undefined') {
flag = true;
}
} catch (err) {
console.log(err);
flag = true;
}
return flag;
}
function check_if_empty_field($element, msg) {
if (isEmpty($element.val())) {
$element.focus();
toastr.remove();
toastr.error(msg);
return true;
} else {
return false;
}
}
function customSelectOption($el,id,text){
if(!isEmpty(id)){
var newOption = new Option(text, id, true, true);
$el.append(newOption).trigger('change');
}
}
function init_function(type){
switch(type){
case 0:
break;
case 'lead_profile':
init_leadprofile_page();
break;
case 'refresh_lead_table':
refreshLeadfileTable();
break;
}
}
function upper_first_letter(data){
return data.toLowerCase()
.replace(/\b[a-z]/g, function(
letter) {
return letter.toUpperCase();
});
}
function init_destroy_session() {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'signout',
api: 1
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
// toastr.remove();
// toastr.error("Error has occurred. Try again.")
}
});
}
function addSearchTransition($searchEl,$searchElDiv){
//groupfile member tab
$searchEl.focusin(function() {
$searchElDiv.removeClass(
'default-search-size');
$searchElDiv.addClass(
'expand-search-size');
});
$searchEl.focusout(function() {
if (isEmpty($(this).val())) {
$searchElDiv.removeClass(
'expand-search-size');
$searchElDiv.addClass(
'default-search-size');
}
});
}
function resetGroupOwners(){
selected_group = [];
selected_group_owner = [];
selected_group_owner.push({
owner_id: 0,
owner_name: 'My',
});
}
function accessManagement(code){
if(!global_menu_access.includes(code)){
return false;
}
switch(parseInt(code)){
case 1 : //settings
$('#nav_config').show();
$('#nav_config_divider').show();
break;
case 2: //mastefile
$('#master_add_company').show();
$('.masterfile_action_remove').show();
break;
case 3: //user groups
$('#nav_groups').show();
$('#nav_groups_divider').show();
break;
}
}
PK ZZѣC C groupfile.jsnu [ //START ROLES FILE//////////////////////////////////////////////////////////////////////////
function init_groupfile_page() {
init_header();
if (side_menu_loaded) {
init_groupfile();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_groupfile();
});
}
}
var init_groupfile = function() {
if(!global_menu_access.includes(3)){
return false;
}
return $.ajax({
url: "resources/views/groupfile.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'My Groups';
$('#center_content').html(data);
add_content_close_listener('center_content');
defaultFunctions();
if(selected_group_owner.length > 1){
$('#groupfile_back').on('click', function() {
selected_group_owner.pop();
// init_masterfile_page();
init_group_member_page();
});
}else{
$('#groupfile_back').hide();
}
$('#group_owner_name').text(selected_group_owner.slice(-1)[0].owner_name);
addSearchTransition($('#groupfile-search'),$('#groupfile-search-div'));
$('#groupfile-search').on('keyup',delay(function(e) {
refreshGroupfileTableSilent();
}, 500));
// if(selected_group_owner.length > 1) {
// // $('#nav_groupfile_add_groupfile').html(' ');
// $('#nav_groupfile_add_groupfile').html('Group List');
// }
$(document).on('click', '.groupfile-list-filter', function(e) {
e.stopPropagation();
});
$('#groupfile_add_groupfile').on('click', function() {
$.when(init_group_modal()/*,create_temporary_group()*/).done(function(ajax1Results/*,ajax2Results*/) {
// alert(ajax2Results.id)
// created_group_id = ajax2Results[0].id;
// alert(created_group_id)
$('#group_modal').modal('show');
$('#group_modal').on('hidden.bs.modal', function() {
// remove_temporary_group(created_group_id);
$('#group_modal').remove();
});
addSearchTransition($('#group-member-search'),$('#group-member-search-div'));
//groupfile member tab
//*update
$('#group-member-search').on('keyup',delay(function(e) {
refreshGroupMemberTableSilent();
}, 500));
//end groupfile tab
$('#txt_group_name').focus();
$('#btn_group_save').on('click', function() {
if (check_if_empty_field($('#txt_group_name'),
'Group name is required.')) {
return;
}
var $element = $("[json-group-modal]");
var json_data = generate_json('json-group-modal',
$element);
update_group(0, json_data,'')
// console.log(json_data);
});
refreshGroupMemberTable();
});
});
refreshGroupfileTable();
$('#table_groupfile').on('click-cell.bs.table', function(field, value, row, $el) {
if (value != "action" && value != "update") {
var selected_group_id = $el.id;
var selected_group_name = $el.name;
selected_group.push({
group_id: selected_group_id,
group_name: selected_group_name,
});
// console.log("Groups: ");
// console.log(selected_group);
init_group_member_page();
}
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_group_modal() {
return $.ajax({
url: "resources/views/modals/group_modal.php",
data: {},
type: "POST",
beforeSend: function() {
selected_group_member = []; //remove all previous selected in group
},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function update_group(group_id, json_data,type ) {
return $.ajax({
url: "app/models/group.php",
data: {
model: 'update_group',
id: group_id,
owner_id: selected_group_owner.slice(-1)[0].owner_id,
json_data: json_data,
group_members : JSON.stringify(selected_group_member),
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_group_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving group.");
},
success: function(result) {
if (parseInt(result.status) === 1) {
if(type == 'group_member'){
var json_data_obj = JSON.parse(json_data)
var group_name = json_data_obj.txt_group_name.toUpperCase()
selected_group_owner.slice(-1)[0].owner_name = group_name
$('#selected_group_name').text(group_name);
document.title = group_name;
refreshGroupMemberTableFile();
}else{
refreshGroupfileTable();
}
toastr.remove();
toastr.success(result.message);
// refreshGroupfileDealerfileTable();
$('#group_modal').off('hidden.bs.modal').on('hidden.bs.modal', function() {});
$('#group_modal').modal(
'hide');
$('#group_modal').remove();
} else {
$('#btn_group_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
$('#btn_group_save').prop(
'disabled', false);
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function create_temporary_group() {
return $.ajax({
url: "app/models/group.php",
data: {
model: 'add_temporary_group'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
return result;
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function remove_temporary_group(group_id) {
return $.ajax({
url: "app/models/group.php",
data: {
model: 'remove_temporary_group',
id: group_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function refreshGroupfileTable() {
initGroupfileList();
var $table = $('#table_groupfile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function refreshGroupfileTableSilent() {
var $table = $('#table_groupfile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function initGroupfileList() {
var $table = $('#table_groupfile');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {
if(selected_group_owner.length > 1) {
// $('.btn_groupfile_update').hide();
// $('.btn_groupfile_remove').hide();
// alert('')
}
},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function groupfileQueryParams(params) {
return {
search: $('#groupfile-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
added_by: selected_group_owner.slice(-1)[0].owner_id,
model: 'group_table',
};
}
function updateGroupfileFormatter(value, row, index) {
if(selected_group_owner.length > 1) {
// return '';
}
return '';
}
function removeGroupfileFormatter(value, row, index) {
if(selected_group_owner.length > 1) {
// return '';
}
return '';
}
window.removeGroupfileEvent = {
'click i': function(e, value, row, index) {
// if (parseInt(row.user_count) > 0) {
// toastr.remove();
// toastr.error('Groupfile is currently active in some users.');
// return;
// }
if(!global_menu_access.includes(3)){
return false;
}
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this group?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "app/models/group.php",
method: "POST",
dataType: 'json',
data: {
model: 'remove_group',
id: row.id
},
beforeSend: function() {
toastr.remove();
toastr.info('Removing...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
refreshGroupfileTable();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (result.isDenied) {} else {}
})
}
};
window.updateGroupfileEvent = {
'click i': function(e, value, row, index) {
updateGroupfileEventFunc(row.id,row.name,'')
}
};
function updateGroupfileEventFunc(group_id,group_name,type){
if(!global_menu_access.includes(3)){
return false;
}
$.when(init_group_modal()).done(function(ajax1Results) {
created_group_id = group_id;
$('#group_modal').modal('show');
$('#group_modal').on('hidden.bs.modal', function() {
$('#group_modal').remove();
});
addSearchTransition($('#group-member-search'),$('#group-member-search-div'));
//*update
$('#group-member-search').on('keyup',delay(function(e) {
refreshGroupMemberTableSilent();
}, 500));
//end groupfile tab
$('#txt_group_name').focus();
$('#txt_group_name').val(group_name);
$('#btn_group_save').on('click', function() {
if (check_if_empty_field($('#txt_group_name'),
'Group name is required.')) {
return;
}
var $element = $("[json-group-modal]");
var json_data = generate_json('json-group-modal',
$element);
update_group(created_group_id, json_data,type)
// console.log(json_data);
});
refreshGroupMemberTable();
});
}
////START group member
function refreshGroupMemberTable() {
initGroupMemberTable();
var $table = $('#table_group_member')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function refreshGroupMemberTableSilent() {
var $table = $('#table_group_member')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function initGroupMemberTable() {
var $table = $('#table_group_member');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
formatNoMatches: function () {
return 'User has no group not found.';
},
onLoadSuccess: function() {},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function groupMemberQueryParams(params) {
return {
search: $('#group-member-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
group_id : created_group_id,
owner_id : selected_group_owner.slice(-1)[0].owner_id,
model: 'group_user_table',
group_members : JSON.stringify(selected_group_member),
};
}
function groupMemberFormatter(value, row, index) {
var html = '';
if (parseInt(row.status) === 1) {
html = '';
}
return html;
}
window.groupMemberEvent = {
'click input': function(e, value, row, index) {
if(selected_group_member.includes(row.id) ){
const index = selected_group_member.indexOf(row.id);
if (index > -1) {
selected_group_member.splice(index, 1);
}
}else{
selected_group_member.push(row.id)
}
// alert(JSON.stringify(selected_group_member));
refreshGroupMemberTableSilent();
//get selected id
// $.ajax({
// url: "app/models/group.php",
// method: "POST",
// dataType: 'json',
// data: {
// model: 'group_member_status',
// user_id: row.id,
// group_id: created_group_id
// },
// beforeSend: function() {
// // toastr.remove();
// // toastr.info('Updating...')
// },
// success: function(result) {
// if (parseInt(result.status) === 1) {
// // toastr.remove();
// // toastr.success(result.message);
// refreshGroupMemberTableSilent();
// } else {
// toastr.remove();
// toastr.error(result.message);
// }
// },
// error: function() {
// toastr.remove();
// toastr.error(
// "Error has occurred. Try again."
// )
// }
// });
}
};
////END ROLE DEALER
//END ROLES FILE////////////////////////////////////////////////////////////////////////////////////PK ZZ O O notification.jsnu [ //START CONFIG FILE/////////////////////////////////////////////////////////////////////////////////////////////////////
function init_notification_page() {
init_header();
if (side_menu_loaded) {
init_notification();
// console.log('asd')
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_notification();
});
}
}
var init_notification = function() {
return $.ajax({
url: "resources/views/notification.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'Notifications';
$('#center_content').html(data);
add_content_close_listener('center_content');
notification_display_limit = notification_display_limit_const;
$.when(user_notification()).done(function(ajax2Results) {
// console.log(ajax2Results['data'])
//reset notification_display_limit
notification_display_limit = notification_display_limit +
notification_display_limit_const;
//init objects
$('#notification_list_div').html('');
$('#notification_view_more').on('click', function() {
$.when(user_notification()).done(function(ajax1Results2) {
var result_notification2 = ajax1Results2['data'];
notification_display_limit =
notification_display_limit +
notification_display_limit_const;
notification_display(result_notification2);
});
});
//ajax when area
var result_notification = ajax2Results['data'];
notification_display(result_notification);
mark_as_read_notification();
show_hide_preloader(false);
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function refresh_notification() {
$.when(get_user_notification_info()).done(function(ajax2Results) {
// console.log();
var notif_count = parseInt(ajax2Results.total);
if(notif_count){
$('#notif_count_badge').text(notif_count);
if(notif_count > 1){
$('#notif_count').text(notif_count+ ' Notifications');
}else{
$('#notif_count').text(notif_count+ ' Notification');
}
$('#notif_div_container').html('')
//display notification per category
$.each(ajax2Results['data'], function(i, n) {
// console.log(n['type'])
$('#notif_div_container').append(`
`+n['count']+ ' ' +n['type']+`
`+n['ago']+ `
`)
});
}else{
$('#notif_count').text('0 Notification');
}
$("[notification-header]").each(function() {
$(this).off('click').on('click', function() {
global_in_notif_section = true;
selected_notification_category = $(this).attr('notification-header');
// console.log(selected_notification_category)
init_notification_page();
});
});
});
}
function mark_as_read_notification(){
return $.ajax({
url: "app/models/user.php",
data: {
model: 'mark_as_read_notification',
type_id: selected_notification_category,
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
// setTimeout(function(){
refresh_notification();
global_in_notif_section = false;
// }, 3000);
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function user_notification() {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'user_notification',
type_id: selected_notification_category,
offset: notification_display_limit - notification_display_limit_const,
limit: notification_display_limit_const
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function notification_display(ajaxResult) {
$.each(ajaxResult, function(i, n) {
var data = ajaxResult[i];
// console.log(data);
var is_read = parseInt(data['is_read']) === 0? 'border-primary' : '' ;
$('#notification_list_div').append(`
`);
});
}PK ZZ5 scripts.phpnu [
PK ZZ# # configuration.jsnu [ //START CONFIG FILE/////////////////////////////////////////////////////////////////////////////////////////////////////
function init_config_page() {
init_header();
if (side_menu_loaded) {
init_config();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_config();
});
}
}
var init_config = function() {
if(!global_menu_access.includes(1)){
return false;
}
return $.ajax({
url: "resources/views/config.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'Configurations';
$('#center_content').html(data);
add_content_close_listener('center_content');
$('#config_user_roles').on('click', function() {
init_rolefile_page();
});
$('#config_sms').on('click', function() {
$.when(init_sms_modal(),get_activated_sms_api()).done(function(ajax1Results,ajax2Results) {
$('#sms_modal').modal('show');
$('#sms_modal').on('hidden.bs.modal', function() {
$('#sms_modal').remove();
});
$('#dd_sms_api').select2({
placeholder: "Select API",
allowClear: true,
minimumResultsForSearch: -1,
// allowClear: true,
ajax: {
url: 'app/models/sms.php?model=api_list',
dataType: 'json'
}
});
$('#btn_sms_save').on('click', function() {
var $element = $("[json-sms-modal]");
var json_data = generate_json('json-sms-modal',
$element);
return $.ajax({
url: "app/models/sms.php",
data: {
model: 'set_activated_api',
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_sms_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving...");
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
$('#sms_modal').modal(
'hide');
$('#sms_modal').remove();
} else {
$('#btn_sms_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
$('#btn_sms_save').prop(
'disabled', false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
});
var api_information = ajax2Results[0];
// console.log(api_information);
// set sms api
customSelectOption($("#dd_sms_api"), api_information['id'], api_information['name']);
});
});
$('#config_system').on('click', function() {
$.when(init_system_settings_modal(),get_system_settings()).done(function(ajax1Results,ajax2Results) {
$('#system_settings_modal').modal('show');
$('#system_settings_modal').on('hidden.bs.modal', function() {
$('#system_settings_modal').remove();
});
var result_system_settings = ajax2Results[0];
$.each(result_system_settings, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
$('#btn_system_settings_save').on('click', function() {
var $element = $("[json-system-settings-modal]");
var json_data = generate_json('json-system-settings-modal',
$element);
return $.ajax({
url: "app/models/system_settings.php",
data: {
model: 'update',
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_sms_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving...");
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
$('#system_settings_modal').modal(
'hide');
$('#system_settings_modal').remove();
} else {
$('#btn_sms_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
$('#btn_sms_save').prop(
'disabled', false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
});
});
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_sms_modal() {
return $.ajax({
url: "resources/views/modals/sms_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_system_settings_modal() {
return $.ajax({
url: "resources/views/modals/system_settings_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function get_system_settings(){
return $.ajax({
url: "app/models/system_settings.php",
data: {
model: 'get_system_settings'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function get_activated_sms_api() {
return $.ajax({
url: "app/models/sms.php",
data: {
model: 'activated_api'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
//END CONFIG FILE/////////////////////////////////////////////////////////////////////////////////////////////////////PK ZZz group_member.jsnu [ //START ROLES FILE//////////////////////////////////////////////////////////////////////////
function init_group_member_page() {
init_header();
if (side_menu_loaded) {
init_group_member();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_group_member();
});
}
}
var init_group_member = function() {
if(!global_menu_access.includes(3)){
return false;
}
return $.ajax({
url: "resources/views/group_member.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
var selected__group = selected_group.slice(-1)[0];
document.title = selected__group.group_name;
$('#center_content').html(data);
add_content_close_listener('center_content');
defaultFunctions();
$('#selected_group_name').text(selected__group.group_name);
$('#group_member_back').on('click', function() {
//remove last element in var selected_group
selected_group.pop();
init_groupfile_page();
});
// if(selected_group.length > 1) {
// $('#nav_group_member_add_group_member').html('Member List');
// }
addSearchTransition($('#group-member-file-search'),$('#group-member-file-search-div'));
//*update
$('#group-member-file-search').on('keyup',delay(function(e) {
refreshGroupMemberTableFileSilent();
}, 500));
$(document).on('click', '.groupfile-list-filter', function(e) {
e.stopPropagation();
});
$('#group_member_add_group_member').on('click', function() {
updateGroupfileEventFunc(selected__group.group_id,selected__group.group_name,'group_member');
});
refreshGroupMemberTableFile();
$('#table_group_member_file').on('click-cell.bs.table', function(field, value, row, $el) {
// console.log($el);return;
// var selected_group_id = $el.id;
var selected_group_owner_id = $el.id;
var selected_group_owner_name = $el.name;
// var selected_group_name = $el.name;
if (value == "groups" ) {
selected_group_owner.push({
owner_id: selected_group_owner_id,
owner_name: selected_group_owner_name,
});
init_groupfile_page();
}else if (value == "leads" ) {
selected_group_owner.push({
owner_id: selected_group_owner_id,
owner_name: selected_group_owner_name,
});
init_leadfile_page();
}
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function refreshGroupMemberTableFile() {
initGroupMemberList();
var $table = $('#table_group_member_file')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function refreshGroupMemberTableFileSilent() {
var $table = $('#table_group_member_file');
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/group.php'
});
})
}
function initGroupMemberList() {
var $table = $('#table_group_member_file');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {
if(selected_group.length > 1) {
// $('.btn_group_member_file_remove').hide();
// alert('231')
}
},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function groupMemberFileQueryParams(params) {
return {
search: $('#group-member-file-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
group_id : selected_group.slice(-1)[0].group_id,
model: 'group_member_table',
};
}
function removeGroupMemberFormatter(value, row, index) {
// if(selected_group.length > 1) {
// return '';
// }
return '';
}
function memberGroupsFormatter(value, row, index) {
return 'Groups';
}
function memberLeadsFormatter(value, row, index) {
return 'Leads';
}
window.removeGroupMemberEvent = {
'click i': function(e, value, row, index) {
if(!global_menu_access.includes(3)){
return false;
}
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this member?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "app/models/group.php",
method: "POST",
dataType: 'json',
data: {
model: 'group_member_status',
user_id: row.id,
group_id : selected_group.slice(-1)[0].group_id
},
beforeSend: function() {
toastr.remove();
toastr.info('Removing...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
refreshGroupMemberTableFileSilent();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (result.isDenied) {} else {}
})
}
};
PK ZZƍDq Dq lead_list.jsnu [ //START LEADS FILE//////////////////////////////////////////////////////////////////////////
function init_leadfile_page() {
init_header();
if (side_menu_loaded) {
init_leadfile();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_leadfile();
});
}
}
var init_leadfile = function() {
return $.ajax({
url: "resources/views/leads.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'Leads';
$('#center_content').html(data);
add_content_close_listener('center_content');
defaultFunctions();
$('#lead_back').on('click', function() {
if(selected_group_owner.length > 1){
selected_group_owner.pop();
init_group_member_page();
}else{
init_masterfile_page();
}
});
if(selected_group_owner.length > 1) {
$('#leads_owner_name').text( selected_group_owner.slice(-1)[0].owner_name+' Leads');
}else{
$('#leads_owner_name').text('Leads Summary');
}
$('#lead-search').focusin(function() {
$('#lead-search-div').removeClass('default-search-size');
$('#lead-search-div').addClass('expand-search-size');
});
$('#lead-search').focusout(function() {
if (isEmpty($(this).val())) {
$('#lead-search-div').removeClass('expand-search-size');
$('#lead-search-div').addClass('default-search-size');
}
});
$('#lead-search').on('keyup',delay(function(e) {
refreshLeadfileTableSilent();
}, 500));
$(document).on('click', '.lead-list-filter', function(e) {
e.stopPropagation();
});
$(".lead-list-filter li").each(function() {
$(this).on('click', function() {
$(this).toggleClass("active");
var active_items = $('.lead-list-filter').find('li.active').map(
function() {
var item = {};
// item.id = this.value;
item.status = $(this).text();
return item;
});
var active_items_arr = [];
$.each(active_items, function(i, n) {
active_items_arr.push(n.status)
});
if (active_items_arr.length > 1) {
$("#selected_filter").text('Multiple Filter');
} else if (active_items_arr.length == 1) {
$("#selected_filter").text($('.lead-list-filter').find(
'li.active').text());
} else {
$("#selected_filter").text('');
}
lead_selected_filters = JSON.stringify(active_items_arr);
refreshLeadfileTable();
});
});
$('#lead_add_lead').on('click', function() {
display_lead_modal('refresh_lead_table','add');
});
refreshLeadfileTable();
$('#table_leadfile').on('click-cell.bs.table', function(field, value, row, $el) {
selected_lead = $el.id;
selected_lead_inquiry = $el.inquiry_id;
if (value != "action") {
init_leadprofile_page();
}
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_lead_modal() {
return $.ajax({
url: "resources/views/modals/lead_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function leadActionFormatter(value, row, index) {
return `
`;
}
function leadNameFormatter(value, row, index) {
// return value;
var inactive_label = (parseInt(row.inactive_lead) === 0) ? `` : ` Inactive`;
return ``+value+inactive_label+``;
}
function refreshLeadfileTable() {
initLeadfileList();
var $table = $('#table_leadfile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/lead.php'
});
})
}
function refreshLeadfileTableSilent() {
var $table = $('#table_leadfile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/lead.php'
});
})
}
function initLeadfileList() {
var $table = $('#table_leadfile');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function leadfileQueryParams(params) {
return {
model: 'lead_table',
search: $('#lead-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
filters: lead_selected_filters,
company: selected_company,
owner_id: selected_group_owner.slice(-1)[0].owner_id
};
}
function display_lead_modal(init__function,type){
$.when(init_lead_modal(),get_user_dealers()).done(function(ajax1Results,user_dealers_result) {
$('#lead_modal').modal('show');
$('#lead_modal').on('hidden.bs.modal', function() {
$('#lead_modal').remove();
});
defaultFunctions();
$("[lead-alert]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
$('#type_person').on('click',function() {
if ($('#type_person').is(':checked')) {
$('.company-field').hide();
$('.person-field').show();
$('#type_person').val('1');
$('#type_company').val('0');
}
});
$('#type_company').on('click',function() {
if ($('#type_company').is(':checked')) {
$('.person-field').hide();
$('.company-field').show();
$('#type_person').val('0');
$('#type_company').val('1');
}
});
$('#dd_lead_gender').select2({
placeholder: "Select gender",
allowClear: true,
minimumResultsForSearch: -1,
// allowClear: true,
ajax: {
url: 'app/models/general.php?model=gender_list',
dataType: 'json'
}
});
$("#dd_lead_brand").select2({
// tags:true,
placeholder: "Select brand",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/brand.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'brand_list',
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
// $('#dd_lead_brand').on('select2:select', function(e) {
$('#dd_lead_brand').on('change', function(e) {
var brand_name = $('#dd_lead_brand').val();
$("#dd_lead_model").val('');
$("#dd_lead_model").select2('destroy').select2({
// tags:true,
placeholder: "Select model",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/model.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'model_list',
brand_name: brand_name,
search: data
.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
});
$('#dd_lead_model').select2({
placeholder: "Select brand first",
minimumResultsForSearch: -1
});
$("#dd_lead_color").select2({
tags: true,
placeholder: "Select color",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/color.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'color_list',
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
//display this if multiple dealer
// console.log(JSON.parse(user_dealers_result))
$("#dd_lead_dealer").select2({
// tags:true,
// multiple: true,
placeholder: "Select dealer",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/dealer.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'dealer_list_by_ids',
// company_id: selected_company,
// api: true,
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
if(user_dealers_result[0].length > 1){
$("#dd_lead_dealer_div").show();
}
$('#role-search').on('keyup',delay(function(e) {
refreshRolefileTableSilent();
}, 500));
// Advanced 1
var xhr = null;
$('#txt_lead_company').autoComplete({
resolver: 'custom',
noResultsText: '',
events: {
search: function(qry, callback) {
// let's do a custom ajax call
if (xhr != null) {
//kill the request
xhr.abort()
}
xhr = $.ajax(
'app/models/lead.php', {
data: {
'search': qry,
'model': 'lead_company_list'
}
}
).done(function(res) {
results = JSON.parse(res)
callback(results.data)
});
}
}
});
$('#txt_lead_company').on('autocomplete.select', function(evt,
item) {
$("#txt_lead_company_id").val(item.id);
});
$("#txt_lead_company").on("keyup change", function(e) {
$("#txt_lead_company_id").val('');
})
// $('#txt_lead_fname').focus();
$('#txt_lead_fname').trigger('focus');
$('#btn_lead_save').on('click', function() {
if ($('#type_company').is(':checked')) {
if (check_if_empty_field($('#txt_lead_company'),
'Company name is required.')) {
return;
}
if (isEmpty($('#txt_lead_mobile').val()
.trim()) &&
isEmpty($('#txt_lead_landline').val()
.trim())
) {
$('#txt_lead_mobile').focus();
toastr.remove();
toastr.error('Mobile or Landline is required.');
return;
}
if (!isEmpty($('#txt_lead_mobile').val()
.trim())) {
if ($('#txt_lead_mobile').val()
.trim().length < 10 || !$(
'#txt_lead_mobile').val()
.trim().startsWith('9')) {
$('#txt_lead_mobile').focus();
toastr.remove();
toastr.error('Invalid mobile.');
return;
}
}
if (!isEmpty($('#txt_lead_landline').val()
.trim())) {
if ($('#txt_lead_landline').val()
.trim().length < 4) {
$('#txt_lead_landline').focus();
toastr.remove();
toastr.error('Invalid landline.');
return;
}
}
}
if ($('#type_person').is(':checked')) {
if (check_if_empty_field($('#txt_lead_fname'),
'Firstname is required.')) {
return;
}
if (check_if_empty_field($('#txt_lead_lname'),
'Lastname is required.')) {
return;
}
if (check_if_empty_field($('#dd_lead_gender'),
'Gender required.')) {
return;
}
if (check_if_empty_field($('#txt_lead_mobile'),
'Mobile is required.')) {
return;
}
if (!isEmpty($('#txt_lead_mobile').val()
.trim())) {
if ($('#txt_lead_mobile').val()
.trim().length < 10 || !$(
'#txt_lead_mobile').val()
.trim().startsWith('9')) {
$('#txt_lead_mobile').focus();
toastr.remove();
toastr.error('Invalid mobile.');
return;
}
}
if (!isEmpty($('#txt_lead_landline').val()
.trim())) {
if ($('#txt_lead_landline').val()
.trim().length < 4) {
$('#txt_lead_landline').focus();
toastr.remove();
toastr.error('Invalid landline.');
return;
}
}
}
if (check_if_empty_field($('#txt_lead_email'),
'Email is required.')) {
return;
}
if (!isValidEmailAddress($('#txt_lead_email').val()
.trim())) {
$('#txt_lead_email').focus();
toastr.remove();
toastr.error('Invalid email address.');
return;
}
if (check_if_empty_field($('#dd_lead_brand'),
'Select brand.')) {
return;
}
if (check_if_empty_field($('#dd_lead_model'),
'Select model.')) {
return;
}
var $element = $("[json-lead-modal]");
var json_data = generate_json('json-lead-modal',
$element);
// console.log(json_data);
// return;
return $.ajax({
url: "app/models/lead.php",
data: {
model: type,
json_data: json_data,
lead_id: selected_lead,
inquire_id: selected_lead_inquiry,
owner_id: selected_group_owner.slice(-1)[0].owner_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving lead.");
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
// refreshLeadfileTable();
init_function(init__function)
$('#lead_modal').modal(
'hide');
$('#lead_modal').remove();
} else {
$('#btn_lead_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
$('#btn_lead_save').prop(
'disabled', false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
});
if(type == 'update'){
//get data
$.when(lead_read_profile_form()).done(function(lead_information) {
// console.log(lead_information);
$.each(lead_information, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
//set customer type
$('#type_category').hide();
if(parseInt(lead_information['lead_type']) === 1){
$('.company-field').hide();
$('.person-field').show();
$('#type_person').val('1');
$('#type_company').val('0');
$('#type_person').attr('checked',true);
}else if(parseInt(lead_information['lead_type']) === 2){
$('.person-field').hide();
$('.company-field').show();
$('#type_person').val('0');
$('#type_company').val('1');
$('#type_company').attr('checked',true);
}
// set dealer
customSelectOption($("#dd_lead_dealer"), lead_information['dealer_id'], lead_information['dealer_code']);
// set brand
customSelectOption($("#dd_lead_brand"), lead_information['brand_name'], lead_information['brand_name']);
// set model
customSelectOption($("#dd_lead_model"), lead_information['model_name'], lead_information['model_name']);
// set color
customSelectOption($("#dd_lead_color"), lead_information['color_name'], lead_information['color_name']);
// set gender
customSelectOption($("#dd_lead_gender"), lead_information['gender_id'], lead_information['gender']);
//set alert
var json_alert_id = JSON.parse(lead_information['json_alert_id']);
$.each(json_alert_id, function(i, n) {
$.each(n, function(j, m) {
if(parseInt(m) === 1){
$("#" + j).attr('checked',true);
}
$("#" + j).text(m);
$("#" + j).val(m);
$("#" + j).trigger('change')
});
});
});
}
});
}
function lead_read_profile_form(){
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'lead_read_profile_form',
// lead_id: selected_lead,
inquire_id: selected_lead_inquiry
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function get_user_dealers(){
return $.ajax({
url: "app/models/user.php",
data: {
model: 'get_user_dealers'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
//END LEADS FILE////////////////////////////////////////////////////////////////////////////////////PK ZZdlS< S< lead_profile.jsnu [
//START LEADS PROFILE FILE////////////////////////////////////////////////////////////////////////////////////
function init_leadprofile_page() {
init_header();
if (side_menu_loaded) {
init_leadprofile();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_leadprofile();
});
}
}
var init_leadprofile = function() {
return $.ajax({
url: "resources/views/lead_profile.php",
data: {},
type: "POST",
beforeSend: function() {
show_hide_preloader(true);
},
success: function(data) {
document.title = 'Lead Information';
$('#center_content').html(data);
add_content_close_listener('center_content');
defaultFunctions();
// $('#lead_activities_div').html('');
lead_activities_display_limit = lead_activities_display_limit_const;
$('#lead_profile_back').on('click', function() {
init_leadfile_page();
});
$.when(lead_profile(), lead_activities()).done(function(ajax1Results, ajax2Results) {
//reset lead_activities_display_limit
lead_activities_display_limit = lead_activities_display_limit +
lead_activities_display_limit_const;
//init objects
$('#lead_activities_div').html('');
$('#lead_activity_view_more').on('click', function() {
$.when(lead_activities()).done(function(ajax1Results2) {
var result_lead_activities2 = ajax1Results2['data'];
lead_activities_display_limit =
lead_activities_display_limit +
lead_activities_display_limit_const;
lead_activities_display(result_lead_activities2);
});
});
//ajax when area
var result_lead_activities = ajax2Results[0]['data'];
var result_lead_profile = ajax1Results[0];
//put profiule data to UI
$.each(result_lead_profile, function(i, n) {
if (i.startsWith('profile_href_')) {
$("#" + i).attr("href", n);
} else {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
}
});
// alert(result_lead_profile['inactive_lead'])
//set if active or inactive
if(parseInt(result_lead_profile['inactive_lead']) === 1){
$("#profile_inactive_label").show();
}
//set progress bar
for (var i = 1; i <= parseInt(result_lead_profile[
'profile_progress_type_level']); i++) {
$("#lead_progress_" + i).toggleClass('text-secondary').toggleClass(
'text-primary');
}
//display latest activities
$.each(result_lead_activities, function(i, n) {
var data = result_lead_activities[i];
$('#latest_activity_type').text(data['type'] + ':');
$('#latest_activity_owner').text(data['owner']);
$('#latest_activity_description').html(data['description']);
return false;
});
//set html classes & attributes
progress_type_class_obj = (JSON.parse(result_lead_profile.html_class));
var progress_type_class_final = progress_type_class_obj.text.join(' ');
$('#profile_progress_type').addClass(progress_type_class_final);
//display all lead activities
lead_activities_display(result_lead_activities);
// action buttons
//LEAD ADD PROGRESS
$('#lead_profile_add_progress').on('click', function() {
display_progress_modal('lead_profile','')
});
// LEAD ADD NOTE
$('#lead_profile_add_notes').on('click', function() {
display_note_modal('lead_profile','')
});
// LEAD ADD CALL
$('#lead_profile_add_call').on('click', function() {
display_call_modal('lead_profile','')
});
// TAG INACTIVE LEAD
$('#lead_profile_action_inactive').on('click', function() {
display_inactive_modal('lead_profile','')
});
$('#lead_profile_view').on('click', function() {
display_lead_modal('lead_profile','update');
});
$('#lead_profile_send_sms').on('click', function() {
display_sms_lead_modal('lead_profile','')
});
$('#lead_profile_send_email').on('click', function() {
display_mail_lead_modal('lead_profile','')
});
show_hide_preloader(false);
});
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function lead_profile() {
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'lead_profile_v2',
lead_id: selected_lead
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function lead_activities() {
console.log("offset: " + (lead_activities_display_limit - lead_activities_display_limit_const))
console.log("limit: " + (lead_activities_display_limit_const))
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'lead_activities',
inquire_id: selected_lead_inquiry,
offset: lead_activities_display_limit - lead_activities_display_limit_const,
limit: lead_activities_display_limit_const
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function lead_activities_display(ajaxResult) {
$.each(ajaxResult, function(i, n) {
var data = ajaxResult[i];
// console.log(data);
var activity_action = '';
if(data['activity_type'] == 'progress' && data['description'] == 'NEW LEAD'){
activity_action = '';
}else{
activity_action = `View
Remove
`;
}
$('#lead_activities_div').append(``);
});
}
function view_lead_activity(id,type){
switch(type){
case 'inactive':
display_inactive_modal('lead_profile',id);
break;
case 'email':
display_mail_lead_modal('lead_profile',id);
break;
case 'sms':
display_sms_lead_modal('lead_profile',id);
break;
case 'call':
display_call_modal('lead_profile',id);
break;
case 'note':
display_note_modal('lead_profile',id)
break;
case 'progress':
display_progress_modal('lead_profile',id)
break;
}
}
function remove_lead_activity(id,type){
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this activity?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "app/models/lead.php",
method: "POST",
dataType: 'json',
data: {
model: 'remove_activity',
type : type,
activity_id: id,
inquire_id: selected_lead_inquiry
},
beforeSend: function() {
toastr.remove();
toastr.info('Removing...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
init_function('lead_profile');
} else {
toastr.remove();
toastr.error(result.message);
}
}
});
} else if (result.isDenied) {} else {}
})
// switch(type){
// case 'inactive':
// display_inactive_modal('lead_profile',id);
// break;
// case 'email':
// display_mail_lead_modal('lead_profile',id);
// break;
// case 'sms':
// display_sms_lead_modal('lead_profile',id);
// break;
// case 'call':
// display_call_modal('lead_profile',id);
// break;
// case 'note':
// display_note_modal('lead_profile',id)
// break;
// case 'progress':
// display_progress_modal('lead_profile',id)
// break;
// }
}
function init_note_modal() {
return $.ajax({
url: "resources/views/modals/note_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_call_modal() {
return $.ajax({
url: "resources/views/modals/call_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_inactive_modal() {
return $.ajax({
url: "resources/views/modals/inactive_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_progress_modal() {
return $.ajax({
url: "resources/views/modals/progress_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function display_progress_modal(type,activity_id) {
$.when(init_progress_modal(),progress_list_json(),get_progress_data(activity_id)).done(function(init_progress_modal_result,progress_list_json_result,progress_data_result) {
$('#progress_modal').modal('show');
$('#progress_modal').on('hidden.bs.modal', function() {
$('#progress_modal').remove();
});
$('#progress_type_div').html('');
$('#btn_lead_progress_save').on('click', function() {
var selected_progress_type = $(
'input[name=lead_update_progress]:checked'
).val();
var lead_progress_description = $(
'#txt_lead_progress_description')
.val();
if (isEmpty(selected_progress_type) ||
parseInt(selected_progress_type) ===
1 /*prevent selecting default status*/
) {
toastr.remove();
toastr.error(
'Please select a progress type');
return false;
}
$.when(add_lead_progress(selected_progress_type,lead_progress_description,activity_id)).done(function(ajax1Results4) {
init_function(type);
});
});
// $.when(progress_list_json()).done(function(
// ajax1Results3) {
var results = JSON.parse(progress_list_json_result[0]);
$.each(results, function(i, n) {
var title_class = isEmpty(n[0][
'type_class'
]) ?
'{"badge":["badge-primary"],"text":["text-primary"]}' :
n[0][
'type_class'
];
title_class_obj = (JSON.parse(
title_class));
var title_class_final =
title_class_obj.badge.join(
' ');
$('#progress_type_div').append(`
`);
$.each(results[i], function(j,
m) {
// alert(results[i][j]['id']+' ' +results[i][j]['name']);
$('#progress_type_' +
i).append(`
`);
});
});
//disable newly added lead status or default status
$('#progress_type_1').prop(
'disabled', true);
// });
if(!isEmpty(activity_id)){
var progress_data = progress_data_result[0][0];
$.each(progress_data, function(i, n) {
// alert(i+ ' ' +n)
if(i == 'progress_type'){
// alert('#progress_type_'+n)
$('#progress_type_'+n).prop('checked', true);
}else{
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
}
});
}
});
}
function get_progress_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_progress_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function add_lead_progress(selected_progress_type, lead_progress_description,activity_id) {
var activity_type = isEmpty(activity_id) ? 'add_lead_progress' : 'update_lead_progress' ;
return $.ajax({
url: "app/models/lead.php",
data: {
model: activity_type,
progress_type: selected_progress_type,
description: lead_progress_description,
inquire_id: selected_lead_inquiry,
activity_id:activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_progress_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving...");
},
success: function(result) {
if (parseInt(result.status) ===
1) {
toastr.remove();
toastr.success(result
.message);
$('#progress_modal').modal(
'hide');
$('#progress_modal')
.remove();
} else {
$('#btn_lead_progress_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_progress_save').prop(
'disabled', false);
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function display_note_modal(type,activity_id){
$.when(init_note_modal(),get_note_data(activity_id)).done(function(ajax1Results4,note_data_result) {
$('#note_modal').modal('show');
$('#note_modal').on('hidden.bs.modal', function() {
$('#note_modal').remove();
});
$('#txt_reminder_time_div').datetimepicker({
format: 'LT'
})
$('#txt_reminder_date_div').datetimepicker({
format: 'MM/DD/YYYY',
minDate:moment()
});
$("[lead-note-copy]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
$('#btn_lead_note_save').on('click', function() {
if (check_if_empty_field($(
'#txt_lead_note_description'),
'Note is required.')) {
return false;
}
if (!isEmpty($('#txt_reminder_date').val()
.trim()) && isEmpty($(
'#txt_reminder_time').val()
.trim())) {
$('#txt_reminder_time').focus();
toastr.remove();
toastr.error('Please enter time.')
return false;
}
if (isEmpty($('#txt_reminder_date').val()
.trim()) && !isEmpty($(
'#txt_reminder_time').val()
.trim())) {
$('#txt_reminder_date').focus();
toastr.remove();
toastr.error('Please enter date.')
return false;
}
var $element = $("[json-lead-note-modal]");
var json_data = generate_json(
'json-lead-note-modal',
$element);
// alert(json_data);
$.when(add_lead_note(json_data,activity_id)).done(function(ajax1Results5) {
init_function(type);
});
});
//
if(!isEmpty(activity_id)){
$("[lead-note-copy]").each(function() {
$(this).prop('disabled',true);
});
var note_data = note_data_result[0][0];
$.each(note_data, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
var selected_copy = JSON.parse(note_data.note_copy_json);
$.each(selected_copy, function(i, n) {
$.each(n, function(j, m) {
if(parseInt(m) === 1){
$('#'+j).prop('checked', true);
$('#'+j).val('1');
}
});
});
}
});
}
function get_note_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_note_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function add_lead_note(json_data,activity_id){
var activity_type = isEmpty(activity_id) ? 'add_lead_note' : 'update_lead_note' ;
return $.ajax({
url: "app/models/lead.php",
data: {
model: activity_type,
json_data: json_data,
inquire_id: selected_lead_inquiry,
activity_id : activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_note_save')
.prop(
'disabled', true
);
toastr.remove();
toastr.info(
"Adding...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// init_leadprofile_page();
$('#note_modal')
.modal(
'hide');
$('#note_modal')
.remove();
} else {
$('#btn_lead_note_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_note_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function display_call_modal(type,activity_id){
$.when(init_call_modal(),lead_profile(),get_call_data(activity_id)).done(function(ajax1Results1,ajax1Results2,call_data_result) {
$('#call_modal').modal('show');
$('#call_modal').on('hidden.bs.modal', function() {
$('#call_modal').remove();
});
// alert(ajaxResults3)
var result_lead_profile = ajax1Results2[0];
//store lead contactss
const lead_contacts = {
mobile: result_lead_profile['profile_mobile'],
viber: result_lead_profile['profile_viber'],
landline: result_lead_profile['profile_landline'],
email: result_lead_profile['profile_email'],
};
$('#txt_follow_up_time_div').datetimepicker({
format: 'LT'
})
$('#txt_follow_up_date_div').datetimepicker({
format: 'MM/DD/YYYY',
minDate:moment()
});
$.each(lead_contacts, function(i, n) {
if (!isEmpty(n) && i != 'email') {
var call_via_type = upper_first_letter(i);
$('#lead_call_via_div').append(`
`);
}
});
$("[lead-call-via]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
$('#btn_lead_call_save').on('click', function() {
if (check_if_empty_field($(
'#txt_lead_call_description'),
'Description is required.')) {
return false;
}
if (!isEmpty($('#txt_follow_up_date').val()
.trim()) && isEmpty($(
'#txt_follow_up_time').val()
.trim())) {
$('#txt_follow_up_time').focus();
toastr.remove();
toastr.error('Please enter time.')
return false;
}
if (isEmpty($('#txt_follow_up_date').val()
.trim()) && !isEmpty($(
'#txt_follow_up_time').val()
.trim())) {
$('#txt_follow_up_date').focus();
toastr.remove();
toastr.error('Please enter date.')
return false;
}
var $element = $("[json-lead-call-modal]");
var json_data = generate_json(
'json-lead-call-modal',
$element);
// alert(json_data);
$.when(add_lead_call(json_data,activity_id)).done(function(ajax1Results6) {
init_function(type);
});
});
if(!isEmpty(activity_id)){
var call_data = call_data_result[0][0];
$.each(call_data, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
var selected_via_call = JSON.parse(call_data.call_via_json);
$.each(selected_via_call, function(i, n) {
$.each(n, function(j, m) {
if(parseInt(m) === 1){
$('#'+j).prop('checked', true);
$('#'+j).val('1');
}
});
});
}
});
}
function get_call_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_call_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function add_lead_call(json_data,activity_id){
var activity_type = isEmpty(activity_id) ? 'add_lead_call' : 'update_lead_call' ;
return $.ajax({
url: "app/models/lead.php",
data: {
model: activity_type,
json_data: json_data,
inquire_id: selected_lead_inquiry,
activity_id:activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_call_save')
.prop(
'disabled', true
);
toastr.remove();
toastr.info(
"Saving...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// init_leadprofile_page();
$('#call_modal')
.modal(
'hide');
$('#call_modal')
.remove();
} else {
$('#btn_lead_call_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_call_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function formatState (state) {
// console.log(state);return false;
if (!state.id) {
return state.text;
}
var $state = $(
' ' + state.text + ''+ ' ' + ' ' + state.type + ''
);
return $state;
}
function display_mail_lead_modal(type,activity_id){
$.when(init_mail_lead_modal(),get_mail_data(activity_id)).done(function(ajax1Results1,ajax2Results) {
$('#mail_lead_modal').on('shown.bs.modal', function() {
})
$('#mail_lead_modal').on('hidden.bs.modal', function() {
$('#mail_lead_modal').remove();
});
$('#mail_lead_modal').modal('show');
init_mail_template_list();
$('#txt_lead_mail_lead_description').summernote({
placeholder: 'Compose a message',
tabsize: 2,
height: 200,
dialogsInBody: true,
tooltip: false,
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['insert', ['picture', 'video','link']],
['view', ['fullscreen']]
]
});
$('#btn_lead_mail_lead_save').on('click', function() {
//alert conformation
if (check_if_empty_field($(
'#txt_lead_mail_lead_subject'
),
'Subject is required.')) {
return false;
}
if (
$('#txt_lead_mail_lead_description').summernote('code') == '
' ||
$('#txt_lead_mail_lead_description').summernote('code') == '') {
$('#txt_lead_mail_lead_description').summernote('focus');
toastr.remove();
toastr.error('Message is required.')
return false;
}
if ($('#txt_lead_mail_lead_description').val().trim().length <= 5) {
$('#txt_lead_mail_lead_description').trigger('focus')
toastr.remove();
toastr.error('Your message is too short.')
return false;
}
var $element = $(
"[json-mail-lead-modal]");
var json_data = generate_json(
'json-mail-lead-modal',
$element);
$.when(add_lead_mail(json_data,activity_id)).done(function(ajax1Results5) {
init_function(type);
});
});
$("[lead-mail-parameter]").each(function() {
$(this).on('click', function() {
set_mail_message($(this).text());
});
});
$('#remove_mail_lead_save_template').on('click', function() {
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this template?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
var mail_template_id = $('#dd_mail_lead_template').val();
$.ajax({
url: "app/models/lead.php",
data: {
model: 'remove_mail_template',
mail_template_id : mail_template_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info(
"Removing...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// $('#dd_mail_lead_template').select2('destroy');
// $('#dd_mail_lead_template').off('change');
// init_mail_template_list();
$('#dd_mail_lead_template').val('').trigger('change');
} else {
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (result.isDenied) {} else {}
})
});
$("[lead-mail-chk]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
$('#mail_lead_save_template').on('change', function() {
if (this.checked) {
Swal.fire({
text: "Template name",
input: 'text',
showCancelButton: true,
preConfirm: (value) => {
if (!value) {
Swal.showValidationMessage(
'Template name is required'
)
}else{
$(this).val(value);
}
}
}).then(function(result){
if(result.value){
}else if(result.isDismissed){
$('#mail_lead_save_template').prop('checked', false);
}
});
} else {
$(this).val("");
}
});
$('#clear_mail_lead_description').on('click', function() {
$('#txt_lead_mail_lead_description').summernote('reset');
$('#txt_lead_mail_lead_description').summernote('focus');
$('#dd_mail_lead_template').val('').trigger('change');
});
//get activity description if any
// return false;
if(!isEmpty(activity_id)){
var mail_data = ajax2Results[0][0]
//hide elements
$('#txt_lead_mail_lead_description').summernote('destroy');
$('#txt_lead_mail_lead_subject').attr('readonly', true);
$('#txt_lead_mail_lead_subject').css('background-color', 'white');
$('#mail-template-section').hide();
$('#mail-parameter-section').hide();
$('#mail-save-template-section').hide();
$('#mail-bcc-section').hide();
$('#mail-clear-section').hide();
$('#btn_lead_mail_lead_save').off('click');
$('#btn_lead_mail_lead_save').hide();
$('#btn_lead_mail_lead_cancel').html('Close');
$('#txt_lead_mail_lead_description').summernote({
placeholder: 'Compose a message',
tabsize: 2,
height: 350,
dialogsInBody: true,
tooltip: false,
toolbar: []
});
$('#txt_lead_mail_lead_description').summernote('disable');
$('.note-editor.note-airframe .note-editing-area .note-editable[contenteditable=false], .note-editor.note-frame .note-editing-area .note-editable[contenteditable=false]').css('background-color', 'white');
$.each(mail_data, function(i, n) {
if(i == 'txt_lead_mail_lead_description'){
$('#txt_lead_mail_lead_description').summernote('code', n);
}else{
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
}
});
}
});
}
function get_mail_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_mail_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function set_mail_message(text){
$('#txt_lead_mail_lead_description').summernote('saveRange');
// // Editor loses selected range (e.g after blur)
$('#txt_lead_mail_lead_description').summernote('restoreRange');
$('#txt_lead_mail_lead_description').summernote('focus');
$('#txt_lead_mail_lead_description').summernote('insertText', text);
}
function init_mail_template_list(){
$('#dd_mail_lead_template').select2({
placeholder: "Select Template",
allowClear: true,
minimumResultsForSearch: -1,
templateResult: formatState,
// allowClear: true,
ajax: {
url: 'app/models/lead.php?model=my_mail_template_list',
dataType: 'json'
}
});
$('#dd_mail_lead_template').on('change', function(e) {
var mail_template_id = $('#dd_mail_lead_template').val();
if(isEmpty(mail_template_id)){
$('#remove_mail_lead_save_template').hide();
return false;
}else{
$('#remove_mail_lead_save_template').show();
}
$.ajax({
url: "app/models/lead.php",
data: {
model: 'get_mail_template',
mail_template_id : mail_template_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info(
"Fetching...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// set text to field
$('#txt_lead_mail_lead_subject').val(result.subject);
// set_mail_message(result.content)
$('#txt_lead_mail_lead_description').summernote('code', result.content);
} else {
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
});
}
function init_mail_lead_modal() {
return $.ajax({
url: "resources/views/modals/mail_lead_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function add_lead_mail(json_data){
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'add_lead_mail',
json_data: json_data,
inquire_id: selected_lead_inquiry
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_mail_lead_save')
.prop(
'disabled', true
);
toastr.remove();
toastr.info(
"Processing...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// init_leadprofile_page();
$('#mail_lead_modal')
.modal(
'hide');
$('#mail_lead_modal')
.remove();
} else {
$('#btn_lead_mail_lead_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_mail_lead_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function display_sms_lead_modal(type,activity_id){
$.when(init_sms_lead_modal(),get_sms_data(activity_id)).done(function(ajax1Results1,sms_data_result) {
$('#sms_lead_modal').modal('show');
$('#sms_lead_modal').on('hidden.bs.modal', function() {
$('#sms_lead_modal').remove();
});
init_sms_template_list();
$('#btn_lead_sms_lead_save').on('click', function() {
//alert conformation
if (check_if_empty_field($(
'#txt_lead_sms_lead_description'
),
'Message is required.')) {
return false;
}
if ($('#txt_lead_sms_lead_description').val().trim().length <= 5) {
$('#txt_lead_sms_lead_description').trigger('focus')
toastr.remove();
toastr.error('Your message is too short.')
return false;
}
var $element = $(
"[json-sms-lead-modal]");
var json_data = generate_json(
'json-sms-lead-modal',
$element);
$.when(add_lead_sms(json_data)).done(function(ajax1Results5) {
init_function(type);
});
});
$("[lead-sms-parameter]").each(function() {
$(this).on('click', function() {
// $('#txt_lead_sms_lead_description').val($('#txt_lead_sms_lead_description').val()+$(this).text());
$('#txt_lead_sms_lead_description').insertAtCaret($(this).text());
$('#txt_lead_sms_lead_description').trigger('focus');
});
});
$('#remove_sms_lead_save_template').on('click', function() {
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this template?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
var sms_template_id = $('#dd_sms_lead_template').val();
$.ajax({
url: "app/models/lead.php",
data: {
model: 'remove_sms_template',
sms_template_id : sms_template_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info(
"Removing...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// $('#dd_sms_lead_template').select2('destroy');
// $('#dd_sms_lead_template').off('change');
// init_sms_template_list();
$('#dd_sms_lead_template').val('').trigger('change');
} else {
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (result.isDenied) {} else {}
})
});
$('#sms_lead_save_template').on('change', function() {
if (this.checked) {
Swal.fire({
text: "Template name",
input: 'text',
showCancelButton: true,
preConfirm: (value) => {
if (!value) {
Swal.showValidationMessage(
'Template name is required'
)
}else{
$(this).val(value);
}
}
}).then(function(result){
if(result.value){
}else if(result.isDismissed){
$('#sms_lead_save_template').prop('checked', false);
}
});
} else {
$(this).val("");
}
});
$('#clear_sms_lead_description').on('click', function() {
$('#txt_lead_sms_lead_description').val('');
$('#dd_sms_lead_template').val('').trigger('change');
});
if(!isEmpty(activity_id)){
var mail_data = sms_data_result[0][0];
$('#clear_sms_lead_description').hide();
$('#sms-template-section').hide();
$('#sms-save-template-section').hide();
$('#sms-parameter-section').hide();
$('#txt_lead_sms_lead_description').attr('readonly', true);
$('#txt_lead_sms_lead_description').css('background-color', 'white');
$('#btn_lead_sms_lead_save').off('click');
$('#btn_lead_sms_lead_save').hide();
$('#btn_lead_sms_lead_cancel').html('Close');
$.each(mail_data, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
}
});
}
function get_sms_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_sms_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function init_sms_lead_modal() {
return $.ajax({
url: "resources/views/modals/sms_lead_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function add_lead_sms(json_data){
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'add_lead_sms',
json_data: json_data,
inquire_id: selected_lead_inquiry
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_sms_lead_save')
.prop(
'disabled', true
);
toastr.remove();
toastr.info(
"Processing...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// init_leadprofile_page();
$('#sms_lead_modal')
.modal(
'hide');
$('#sms_lead_modal')
.remove();
} else {
$('#btn_lead_sms_lead_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_sms_lead_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function init_sms_template_list(){
$('#dd_sms_lead_template').select2({
placeholder: "Select Template",
allowClear: true,
minimumResultsForSearch: -1,
templateResult: formatState,
// allowClear: true,
ajax: {
url: 'app/models/lead.php?model=my_sms_template_list',
dataType: 'json'
}
});
$('#dd_sms_lead_template').on('change', function(e) {
var sms_template_id = $('#dd_sms_lead_template').val();
if(isEmpty(sms_template_id)){
$('#remove_sms_lead_save_template').hide();
return false;
}else{
$('#remove_sms_lead_save_template').show();
}
$.ajax({
url: "app/models/lead.php",
data: {
model: 'get_sms_template',
sms_template_id : sms_template_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info(
"Fetching...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// set text to field
$('#txt_lead_sms_lead_description').val(result.content);
} else {
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
});
}
function display_inactive_modal(type,activity_id){
$.when(init_inactive_modal(),get_inactive_data(activity_id)).done(function(ajax1Results1,inactive_data_result) {
$('#inactive_modal').modal('show');
$('#inactive_modal').on('hidden.bs.modal', function() {
$('#inactive_modal').remove();
});
$('#txt_revisit_date_div').datetimepicker({
format: 'MM/DD/YYYY',
minDate:moment()
});
$('#btn_lead_inactive_save').on('click', function() {
//alert conformation
if (check_if_empty_field($(
'#txt_lead_inactive_description'
),
'Reason is required.')) {
return false;
}
var $element = $(
"[json-lead-inactive-modal]");
var json_data = generate_json(
'json-lead-inactive-modal',
$element);
$.when(add_lead_inactive(json_data,activity_id)).done(function(ajax1Results5) {
if(parseInt(ajax1Results5.status) === 1){
init_function(type);
}
});
});
//get activity description if any
if(!isEmpty(activity_id)){
var inactive_data = inactive_data_result[0][0]
$.each(inactive_data, function(i, n) {
$("#" + i).text(n);
$("#" + i).val(n);
$("#" + i).trigger('change')
});
}
});
}
function get_inactive_data(activity_id){
if(isEmpty(activity_id)){
return false;
}
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'get_inactive_data',
activity_id: activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function add_lead_inactive(json_data,activity_id){
var activity_type = isEmpty(activity_id) ? 'add_lead_inactive' : 'update_lead_inactive' ;
return $.ajax({
url: "app/models/lead.php",
data: {
model: activity_type,
json_data: json_data,
inquire_id: selected_lead_inquiry,
activity_id : activity_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_lead_inactive_save')
.prop(
'disabled', true
);
toastr.remove();
toastr.info(
"Saving...");
},
success: function(result) {
if (parseInt(result
.status) ===
1) {
toastr.remove();
toastr.success(
result
.message);
// init_leadprofile_page();
$('#inactive_modal')
.modal(
'hide');
$('#inactive_modal')
.remove();
} else {
$('#btn_lead_inactive_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_lead_inactive_save')
.prop(
'disabled',
false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
function progress_list_json() {
return $.ajax({
url: "app/models/lead.php",
data: {
model: 'lead_progress_list'
},
type: "POST",
beforeSend: function() {},
success: function(data) {
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
//END LEADS PROFILE FILE////////////////////////////////////////////////////////////////////////////////////PK ZZT3j3 3
masterfile.jsnu [
//MASTER FILE/////////////////////////////////////////////////////////////////////////////////////////////////////
function init_masterfile_page() {
init_header();
if (side_menu_loaded) {
init_masterfile();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_masterfile();
});
}
}
var init_masterfile = function() {
return $.ajax({
url: "resources/views/masterfile.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'Masterfile';
$('#center_content').html(data);
add_content_close_listener('center_content');
$('#master_add_company').on('click', function() {
if(!global_menu_access.includes(2)){
return false;
}
$.when(init_company_modal()).done(function(ajax1Results) {
$('#company_modal').modal('show');
$('#company_modal').on('hidden.bs.modal', function() {
$('#company_modal').remove();
});
var selected_tab = 1;
$('#txt_company_code').focus();
$('#company-modal-company-tab').on('click', function() {
selected_tab = 1;
});
$('#company-modal-dealer-tab').on('click', function() {
selected_tab = 2;
});
$("#dd_dealer_company").select2({
// tags:true,
// multiple: true,
placeholder: "Select company",
allowClear: true,
escapeMarkup: function(markup) {
return markup;
},
ajax: {
url: 'app/models/company.php',
dataType: 'json',
delay: 250,
data: function(data) {
return {
model: 'company_list',
api: true,
search: data.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
$('#btn_company_save').on('click', function() {
if (parseInt(selected_tab) === 1) {
if (check_if_empty_field($('#txt_company_code'),
'Code is required.')) {
return;
}
if (check_if_empty_field($('#txt_company_name'),
'Name is required.')) {
return;
}
var $element = $("[json-company-modal]");
var json_data = generate_json('json-company-modal',
$element);
return $.ajax({
url: "app/models/company.php",
data: {
model: 'add',
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_company_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Adding...");
},
success: function(result) {
if (parseInt(result.status) ===
1) {
toastr.remove();
toastr.success(result
.message);
refreshMasterfileTable();
$('#company_modal').modal(
'hide');
$('#company_modal')
.remove();
} else {
$('#btn_company_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_company_save').prop(
'disabled', false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (parseInt(selected_tab) === 2) {
if (check_if_empty_field($('#dd_dealer_company'),
'Dealer company is required.')) {
return;
}
if (check_if_empty_field($('#txt_dealer_code'),
'Code is required.')) {
return;
}
if (check_if_empty_field($('#txt_dealer_name'),
'Name is required.')) {
return;
}
var $element = $("[json-dealer-modal]");
var json_data = generate_json('json-dealer-modal',
$element);
return $.ajax({
url: "app/models/dealer.php",
data: {
model: 'add',
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_company_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Adding...");
},
success: function(result) {
if (parseInt(result.status) ===
1) {
toastr.remove();
toastr.success(result
.message);
$('#company_modal').modal(
'hide');
$('#company_modal')
.remove();
} else {
$('#btn_company_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result
.message);
}
},
error: function() {
$('#btn_company_save').prop(
'disabled', false);
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
});
});
});
refreshMasterfileTable();
$('#table_masterfile').on('click-cell.bs.table', function(field, row, value, $el) {
if (row != "remove") {
selected_company = $el.id;
init_leadfile_page();
// init_groupfile_page();
}
});
accessManagement(2);
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_company_modal() {
return $.ajax({
url: "resources/views/modals/company_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function initMasterfileList() {
var $table = $('#table_masterfile');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {
$('.masterfile_action_remove').hide();
accessManagement(2)
// if(!global_menu_access.includes(2)){
// $('.masterfile_action_remove').hide();
// }else{
// $('.masterfile_action_remove').show();
// }
},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function refreshMasterfileTable() {
initMasterfileList();
var $table = $('#table_masterfile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/company.php'
});
})
}
function masterFileQueryParams(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
model: 'company_table',
};
}
function removeCompanyFormatter(value, row, index) {
return '';
}
window.removeCompanyEvent = {
'click i': function(e, value, row, index) {
if(!global_menu_access.includes(2)){
return false;
}
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this company?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "app/models/company.php",
method: "POST",
dataType: 'json',
data: {
model: 'remove',
id: row.id
},
beforeSend: function() {
toastr.remove();
toastr.info('Removing...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
refreshMasterfileTable();
} else {
toastr.remove();
toastr.error(result.message);
}
}
});
} else if (result.isDenied) {} else {}
})
}
};
//MASTER FILE/////////////////////////////////////////////////////////////////////////////////////////////////////PK ZZ$- signin.jsnu [ var init_signin = function() {
init_toastr();
return $.ajax({
url: "resources/views/signin.php",
data: {},
type: "POST",
beforeSend: function() {
show_hide_preloader(true);
},
// success: function(data) {
// },
success: function(data) {
document.title = 'Sign in';
side_menu_loaded = false;
init_destroy_session();
$('#header_content').html('');
$('#main_content').html(data);
// var conn = new WebSocket('ws://localhost:8080');
// conn.onopen = function(e) {
// console.log("Connection established!");
// };
// conn.onmessage = function(e) {
// console.log(e.data);
// var data = JSON.parse(e.data);
// alert(data.msg)
// };
// $('#forgot_password').on('click', function(){
// var data = {
// userId : 1,
// msg : $('#username').val()
// };
// conn.send(JSON.stringify(data));
// });
$('#create_account').on('click', function() {
init_signup();
});
$('#username').on('keyup',function(e) {
if (e.which == 13) {
// if ($('#username').is(":focus") || $('#password').is(":focus")) {
$('#btn_signin').trigger('click');
return;
// }
}
str = $(this).val().trim()
str = str.replace(/\s/g, '')
$(this).val(str)
});
$('#password').on('keyup',function(e) {
if (e.which == 13) {
$('#btn_signin').trigger('click');
return;
}
});
// $(document).on('keypress', function(e) {
// console.log(e.which);
// if (e.which == 13) {
// if ($('#username').is(":focus") || $('#password').is(":focus")) {
// $('#btn_signin').trigger('click');
// }
// }
// });
$('#btn_signin').on('click', function() {
if (check_if_empty_field($('#username'),
'ID number or email address is required.')) {
return;
}
if (check_if_empty_field($('#password'), 'Password is required.')) {
return;
}
var $element = $("[json-signin]");
var json_data = generate_json('json-signin', $element);
return $.ajax({
url: "app/models/user.php",
data: {
model: 'signin',
api: true,
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
toastr.remove();
toastr.info("Signing in.");
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
init_default_page();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
};PK ZZɅ* * default_options.jsnu [ //START CHANGE DEFAULTS///////////////////////////////
function init_toastr() {
toastr.options = {
"closeButton": true,
"debug": false,
"progressBar": true,
"positionClass": "toast-top-right",
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "3000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
}
$.fn.extend({
insertAtCaret: function(myValue) {
this.each(function() {
if (document.selection) {
this.focus();
var sel = document.selection.createRange();
sel.text = myValue;
this.focus();
} else if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos) +
myValue + this.value.substring(endPos,this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
} else {
this.value += myValue;
this.focus();
}
});
return this;
}
});PK ZZAC@ @ role.jsnu [ //START ROLES FILE//////////////////////////////////////////////////////////////////////////
function init_rolefile_page() {
init_header();
if (side_menu_loaded) {
init_rolefile();
} else {
$.when(init_side_content()).done(function(ajax1Results) {
init_rolefile();
});
}
}
var init_rolefile = function() {
return $.ajax({
url: "resources/views/roles.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
document.title = 'Roles';
$('#center_content').html(data);
add_content_close_listener('center_content');
$('#role_back').on('click', function() {
init_config_page();
});
$('#role-search').focusin(function() {
$('#role-search-div').removeClass('default-search-size');
$('#role-search-div').addClass('expand-search-size');
});
$('#role-search').focusout(function() {
if (isEmpty($(this).val())) {
$('#role-search-div').removeClass('expand-search-size');
$('#role-search-div').addClass('default-search-size');
}
});
$('#role-search').on('keyup',delay(function(e) {
refreshRolefileTableSilent();
}, 500));
$(document).on('click', '.role-list-filter', function(e) {
e.stopPropagation();
});
$('#role_add_role').on('click', function() {
$.when(init_role_modal(), create_temporary_role()).done(function(ajax1Results,
ajax2Results) {
// alert(ajax2Results.id)
created_role_id = ajax2Results[0].id;
$('#role_modal').modal('show');
$('#role_modal').on('hidden.bs.modal', function() {
remove_temporary_role(created_role_id);
$('#role_modal').remove();
});
$("[role-access]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
//role dealer tab
$('#role-dealer-search').focusin(function() {
$('#role-dealer-search-div').removeClass(
'default-search-size');
$('#role-dealer-search-div').addClass(
'expand-search-size');
});
$('#role-dealer-search').focusout(function() {
if (isEmpty($(this).val())) {
$('#role-dealer-search-div').removeClass(
'expand-search-size');
$('#role-dealer-search-div').addClass(
'default-search-size');
}
});
$('#role-dealer-search').on('keyup',delay(function(e) {
refreshRoleDealerfileTableSilent();
}, 500));
//end role tab
$('#txt_role_name').focus();
$('#btn_role_save').on('click', function() {
if (check_if_empty_field($('#txt_role_name'),
'Role name is required.')) {
return;
}
var $element = $("[json-role-modal]");
var json_data = generate_json('json-role-modal',
$element);
update_role(created_role_id, json_data)
// console.log(json_data);
});
refreshRoleDealerfileTable();
});
});
refreshRolefileTable();
$('#table_rolefile').on('click-cell.bs.table', function(field, value, row, $el) {
if (value != "action") {
//update role
$.when(init_role_modal()).done(function(ajax1Results) {
init_role_modal_elements($el.id,$el.name,$el.menu_access);
});
}
});
show_hide_preloader(false);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function init_role_modal_elements(role_id,role_name,role_access){
created_role_id = role_id;
$('#role_modal').modal('show');
$('#role_modal').on('hidden.bs.modal', function() {
$('#role_modal').remove();
});
$("[role-access]").each(function() {
$(this).on('change', function() {
if (this.checked) {
$(this).val("1");
} else {
$(this).val("0");
}
});
});
//role dealer tab
$('#role-dealer-search').focusin(function() {
$('#role-dealer-search-div').removeClass(
'default-search-size');
$('#role-dealer-search-div').addClass(
'expand-search-size');
});
$('#role-dealer-search').focusout(function() {
if (isEmpty($(this).val())) {
$('#role-dealer-search-div').removeClass(
'expand-search-size');
$('#role-dealer-search-div').addClass(
'default-search-size');
}
});
$('#role-dealer-search').on('keyup',delay(function(e) {
refreshRoleDealerfileTableSilent();
}, 500));
//end role tab
$('#txt_role_name').focus();
$('#txt_role_name').val(role_name);
$('#btn_role_save').on('click', function() {
if (check_if_empty_field($('#txt_role_name'),
'Role name is required.')) {
return;
}
var $element = $("[json-role-modal]");
var json_data = generate_json('json-role-modal',
$element);
update_role(created_role_id, json_data)
// console.log(json_data);
});
//set check to menu access
const menuobj = JSON.parse(role_access);
// console.log(menuobj)
$.each(menuobj, function(i, n) {
var $current_el = $('#ra_'+n);
$current_el.val("1");
$current_el.attr('checked',true);
});
refreshRoleDealerfileTable();
}
function init_role_modal() {
return $.ajax({
url: "resources/views/modals/role_modal.php",
data: {},
type: "POST",
beforeSend: function() {},
success: function(data) {
$('#center_content').append(data);
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function update_role(role_id, json_data) {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'update_role',
id: role_id,
json_data: json_data
},
type: "POST",
dataType: 'json',
beforeSend: function() {
$('#btn_role_save').prop(
'disabled', true);
toastr.remove();
toastr.info("Saving role.");
},
success: function(result) {
if (parseInt(result.status) === 1) {
refreshRolefileTable();
toastr.remove();
toastr.success(result.message);
// refreshRoleDealerfileTable();
$('#role_modal').off('hidden.bs.modal').on('hidden.bs.modal', function() {});
$('#role_modal').modal(
'hide');
$('#role_modal').remove();
} else {
$('#btn_role_save').prop(
'disabled', false);
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
$('#btn_role_save').prop(
'disabled', false);
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function create_temporary_role() {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'add_temporary_role'
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
// console.log(result)
return result;
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function remove_temporary_role(role_id) {
return $.ajax({
url: "app/models/user.php",
data: {
model: 'remove_temporary_role',
id: role_id
},
type: "POST",
dataType: 'json',
beforeSend: function() {},
success: function(result) {
},
error: function() {
toastr.remove();
toastr.error("Error has occurred. Try again.")
}
});
}
function refreshRolefileTable() {
initRolefileList();
var $table = $('#table_rolefile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/user.php'
});
})
}
function refreshRolefileTableSilent() {
var $table = $('#table_rolefile')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/user.php'
});
})
}
function initRolefileList() {
var $table = $('#table_rolefile');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function rolefileQueryParams(params) {
return {
search: $('#role-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
model: 'role_list',
};
}
function removeRoleFormatter(value, row, index) {
return '';
}
window.removeRoleEvent = {
'click i': function(e, value, row, index) {
if (parseInt(row.user_count) > 0) {
toastr.remove();
toastr.error('Role is currently active in some users.');
return;
}
Swal.fire({
icon: 'warning',
html: 'Are you sure you want to remove this role?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Yes`,
cancelButtonText: `No`,
denyButtonText: `Don't Confirm`,
showClass: {
backdrop: 'swal2-noanimation', // disable backdrop animation
popup: '', // disable popup animation
icon: '' // disable icon animation
},
hideClass: {
popup: '', // disable popup fade-out animation
},
customClass: 'swal-height'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "app/models/user.php",
method: "POST",
dataType: 'json',
data: {
model: 'remove_role',
id: row.id
},
beforeSend: function() {
toastr.remove();
toastr.info('Removing...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
toastr.remove();
toastr.success(result.message);
refreshRolefileTable();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
} else if (result.isDenied) {} else {}
})
}
};
////START ROLE DEALER
function refreshRoleDealerfileTable() {
initRoleDealerfileList();
var $table = $('#table_role_dealer_file')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/user.php'
});
})
}
function refreshRoleDealerfileTableSilent() {
var $table = $('#table_role_dealer_file')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/models/user.php'
});
})
}
function initRoleDealerfileList() {
var $table = $('#table_role_dealer_file');
$table.bootstrapTable('destroy').bootstrapTable({
sidePagination: 'server',
formatSearch: function() {
return 'Search...'
},
onLoadSuccess: function() {},
exportOptions: {
fileName: function() {
return 'titile'
}
}
});
}
function roleDealerfileQueryParams(params) {
return {
search: $('#role-dealer-search').val(),
offset: params.offset,
limit: params.limit,
sort: params.sort,
order: params.order,
role_id: created_role_id,
model: 'role_dealer_list',
};
}
function roleDealerFormatter(value, row, index) {
var html = '';
if (parseInt(row.status) === 1) {
html = '';
}
return html;
}
window.roleDealerEvent = {
'click input': function(e, value, row, index) {
//get selected id
$.ajax({
url: "app/models/user.php",
method: "POST",
dataType: 'json',
data: {
model: 'role_change_status',
dealer_id: row.d_id,
role_id: created_role_id
},
beforeSend: function() {
// toastr.remove();
// toastr.info('Updating...')
},
success: function(result) {
if (parseInt(result.status) === 1) {
// toastr.remove();
// toastr.success(result.message);
refreshRoleDealerfileTableSilent();
} else {
toastr.remove();
toastr.error(result.message);
}
},
error: function() {
toastr.remove();
toastr.error(
"Error has occurred. Try again."
)
}
});
}
};
////END ROLE DEALER
//END ROLES FILE////////////////////////////////////////////////////////////////////////////////////PK IZ؝/t\ \ ' sms_service/script_auto_sms_service.phpnu [
PK IZ5D' industry/industry.jsnu [ // GLOBAL VARIABLES
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;
$(function(){
start = moment().startOf('month');
end = moment().endOf('month');
// $('#tip-categorized-vehicle').attr('data-original-title', "Grouped by plate / cs number
");
// $('#tip-individual-insurance').attr('data-original-title', "Total count of individual insurance
");
$('#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 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 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
}PK IZE?X ?X finance_pdc/finance_pdc_list.jsnu [ // GLOBAL VARIABLES
var pdc_id = "";
var pdc_plate_cs_number1 = "";
var company = 0;
var dealer = 0;
var company_id = 0;
var dealer_id = 0;
var start = null;
var end = null;
var reset = 1;
var filter_date = 0;
var filter_box = 0;
// Add variables
var pdc_add_client_name = "";
var pdc_add_client_mobile = "";
var pdc_add_client_other_contact = "";
var pdc_add_client_email = "";
var pdc_add_plate_cs_number = "";
var pdc_add_dealer = "";
var pdc_add_brand = 0;
var pdc_add_model = "";
var pdc_add_variant = "";
var pdc_add_check_number = "";
var pdc_add_check_amount = "";
var pdc_add_check_date = "";
var pdc_add_policy_number = "";
var pdc_add_insurance_company = "";
var pdc_add_bank = "";
var pdc_add_branch = "";
$(function(){
initTableFinancePDC();
refreshFinancePDCTable();
addListenerCompanyFilter();
start = moment().startOf('month');
end = moment().endOf('month');
$('#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')]
}
});
let isMobile = window.matchMedia("only screen and (max-width: 760px)").matches;
$(".daterangepicker").on('click', function() {
setDateRangePickerWidth(isMobile);
});
$("#filter-date").on('click', function() {
setDateRangePickerWidth(isMobile);
});
$('#company-filter').select2({
placeholder: "Company",
allowClear: true
})
$('#dealer').select2({
placeholder: "Dealer",
allowClear: false
})
$('#pdc-add-dealer').select2({
placeholder: "Dealer",
allowClear: true
})
$('#pdc-add-brand').select2({
placeholder: "Brand",
allowClear: true
})
$('#pdc-add-model').select2({
placeholder: "Model",
allowClear: true
})
$('#pdc-add-variant').select2({
placeholder: "Variant",
allowClear: true
})
$('#pdc-add-insurance-company').select2({
placeholder: "Insurance Company",
allowClear: true
})
$('#pdc-add-bank').select2({
placeholder: "Bank",
allowClear: true
})
$('#check-date').datetimepicker({
format: 'L'
});
$('[data-mask]').inputmask();
$('#filter-date').on('apply.daterangepicker', function(ev, picker) {
$('#filter-date span').html(picker.startDate.format('MMMM D, YYYY') + ' - ' + picker.endDate
.format(
'MMMM D, YYYY'));
cb(picker.startDate, picker.endDate);
filter_date = 1;
});
$('#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 initTableFinancePDC() {
var $table = $('#finance-pdc-table')
$table.bootstrapTable('destroy').bootstrapTable({
})
}
function refreshFinancePDCTable() {
var $table = $('#finance-pdc-table')
$(function() {
$table.bootstrapTable('refresh', { // 1
url: 'app/table/finance_pdc_table.php'
});
})
}
function queryParamsFinancePDCTable(params) {
start = $('#filter-date').data('daterangepicker').startDate;
end = $('#filter-date').data('daterangepicker').endDate;
company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val();
dealer = $("#dealer").val();
if(filter_date == 1){
start_date = start.format('YYYY-MM-DD');
end_date = end.format('YYYY-MM-DD');
}
else {
start_date = "";
end_date = "";
}
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 1, // app/table/finance_pdc_table > finance pdc list
company: company,
dealer: dealer,
filter_box: filter_box
};
}
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("\"\"");
$('#dealer').append("\"" + result + "\"");
}
});
}
function setDateRangePickerWidth(isMobile) {
if ($(".daterangepicker").hasClass('show-calendar') && !isMobile) {
$('.daterangepicker').css('width', '630px');
}
else {
$('.daterangepicker').css('width', 'auto');
}
reset = 0;
}
function passDate(startDate, endDate) {
refreshFinancePDCTable();
// detailsCount();
}
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 fillModelDropdown(brand){
$.ajax({
url:"/app/finance_pdc/dd_get_model.php",
type:"POST",
async: false,
data: {
brand_id: brand,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#pdc-add-model').html('');
$('#pdc-add-model').append("\"\"");
$('#pdc-add-model').append("\"" + result + "\"");
}
});
}
function fillVariantDropdown(model){
$.ajax({
url:"/app/finance_pdc/dd_get_variant.php",
type:"POST",
data: {
model_id: model,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#pdc-add-variant').html('');
$('#pdc-add-variant').append("\"\"");
$('#pdc-add-variant').append("\"" + result + "\"");
}
});
}
function isEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(email)) {
return false;
}
else {
return true;
}
}
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 addPDCModalTabSelectedTab(type){
$('#pdc-modal-tab .nav-link').removeClass('active');
$('#pdc-add-modal-tab-content .tab-pane').removeClass('show');
$('#pdc-add-modal-tab-content .tab-pane').removeClass('active');
switch (type) {
case 1:
$('#pdc-add-modal-tab-information').addClass('active');
$('#pdc-add-modal-information').addClass('active');
$('#pdc-add-modal-information').addClass('show');
break;
case 2:
$('#pdc-add-modal-tab-insurance').addClass('active');
$('#pdc-add-modal-insurance').addClass('active');
$('#pdc-add-modal-insurance').addClass('show');
break;
}
}
function clearAddModal(){
$('#pdc-add-client-fullname').val("");
$('#pdc-add-client-mobile').val("");
$('#pdc-add-client-email').val("");
$('#pdc-add-plate-cs-number').val("");
$('#pdc-add-dealer').val(null).trigger('change');
$('#pdc-add-brand').val(null).trigger('change');
$('#pdc-add-model').val(null).trigger('change');
$('#pdc-add-variant').val(null).trigger('change');
$('#pdc-add-check-number').val("");
$('#pdc-add-check-amount').val("");
$('#check-date').val("");
$('#pdc-add-policy-number').val("");
$('#pdc-add-insurance-company').val(null).trigger('change');
$('#pdc-add-bank').val(null).trigger('change');
$('#pdc-add-branch').val("");
}
$('#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);
});
$('#pdc-add-brand').on('change', function(){
var selected_brand = $('#pdc-add-brand').val();
fillModelDropdown(selected_brand);
})
$('#pdc-add-model').on('change', function(){
var selected_model = $('#pdc-add-model').val();
fillVariantDropdown(selected_model);
})
$('#button-new-pdc-details').on('click', function(){
$('#modal-financepdc-add-pdc').modal('show');
addPDCModalTabSelectedTab(1);
})
$('#pdc-close-modal').on('click', function(){
clearAddModal();
})
$('#button-add-pdc-details').on('click', function(){
pdc_add_client_name = $('#pdc-add-client-fullname').val();
pdc_add_client_mobile = "+63" + $('#pdc-add-client-mobile').val();
pdc_add_client_other_contact = $('#pdc-add-client-other-contact').val();
pdc_add_client_email = $('#pdc-add-client-email').val();
pdc_add_plate_cs_number = $('#pdc-add-plate-cs-number').val();
pdc_add_dealer = $('#pdc-add-dealer').val(); if(pdc_add_dealer === null || pdc_add_dealer == "" || typeof pdc_add_dealer === "undefined"){ pdc_add_dealer = 0; }
pdc_add_brand = $('#pdc-add-brand').val(); if(pdc_add_brand === null || pdc_add_brand == "" || typeof pdc_add_brand === "undefined"){ pdc_add_brand = 0; }
pdc_add_model = $('#pdc-add-model').val(); if(pdc_add_model === null || pdc_add_model == "" || typeof pdc_add_model === "undefined"){ pdc_add_model = 0; }
pdc_add_variant = $('#pdc-add-variant').val(); if(pdc_add_variant === null || pdc_add_variant == "" || typeof pdc_add_variant === "undefined"){ pdc_add_variant = 0; }
pdc_add_check_number = $('#pdc-add-check-number').val();
pdc_add_check_amount = $('#pdc-add-check-amount').val();
pdc_add_check_date = $('#check-date').val();
pdc_add_policy_number = $('#pdc-add-policy-number').val();
pdc_add_insurance_company = $('#pdc-add-insurance-company').val(); if(pdc_add_insurance_company === null || pdc_add_insurance_company == "" || typeof pdc_add_insurance_company === "undefined"){ pdc_add_insurance_company = 0; }
pdc_add_bank = $('#pdc-add-bank').val(); if(pdc_add_bank === null || pdc_add_bank == "" || typeof pdc_add_bank === "undefined"){ pdc_add_bank = 0; }
pdc_add_branch = $('#pdc-add-branch').val();
// alert(pdc_add_client_mobile); return;
// required fields
if(pdc_add_client_name == ""){
toastr.remove();
toastr.error("Client name field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-fullname').trigger('focus');
$('#pdc-add-client-fullname').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-fullname').css("border", "");
$("#pdc-add-client-fullname").trigger('blur');
}, 3000);
return;
}
if(pdc_add_client_mobile == ""){
toastr.remove();
toastr.error("Client mobile field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-mobile').trigger('focus');
$('#pdc-add-client-mobile').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-mobile').css("border", "");
$("#pdc-add-client-mobile").trigger('blur');
}, 3000);
return;
}
if(pdc_add_client_email == ""){
toastr.remove();
toastr.error("Client email field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-email').trigger('focus');
$('#pdc-add-client-email').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-fullname').css("border", "");
$("#pdc-add-client-fullname").trigger('blur');
}, 3000);
return;
}
if(pdc_add_plate_cs_number == ""){
toastr.remove();
toastr.error("Plate/CS Number field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#pdc-add-plate-cs-number').trigger('focus');
$('#pdc-add-plate-cs-number').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-plate-cs-number').css("border", "");
$("#pdc-add-plate-cs-number").trigger('blur');
}, 3000);
return;
}
if(pdc_add_dealer == 0){
toastr.remove();
toastr.error("Please specify dealer", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#div-dealer').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-dealer').css("border", "");
$("#div-dealer").trigger('blur');
}, 3000);
return;
}
if(pdc_add_brand == 0){
toastr.remove();
toastr.error("Please specify brand", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#div-brand').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-brand').css("border", "");
$("#div-brand").trigger('blur');
}, 3000);
return;
}
if(pdc_add_model == 0){
toastr.remove();
toastr.error("Please specify model", "Incomplete data");
addPDCModalTabSelectedTab(1);
$('#div-model').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-model').css("border", "");
$("#div-model").trigger('blur');
}, 3000);
return;
}
if(pdc_add_check_number == ""){
toastr.remove();
toastr.error("Check number field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#pdc-add-check-number').trigger('focus');
$('#pdc-add-check-number').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-check-number').css("border", "");
$("#pdc-add-check-number").trigger('blur');
}, 3000);
return;
}
if(pdc_add_check_amount == ""){
toastr.remove();
toastr.error("Check amount field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#pdc-add-check-amount').trigger('focus');
$('#pdc-add-check-amount').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-check-amount').css("border", "");
$("#pdc-add-check-amount").trigger('blur');
}, 3000);
return;
}
if(pdc_add_check_date == ""){
toastr.remove();
toastr.error("Check date field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#pdc-add-check-date').trigger('focus');
$('#pdc-add-check-date').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-check-date').css("border", "");
$("#pdc-add-check-date").trigger('blur');
}, 3000);
return;
}
if(pdc_add_policy_number == ""){
toastr.remove();
toastr.error("Policy number field cannot be empty", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#pdc-edit-policy-number').trigger('focus');
$('#pdc-edit-policy-number').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-policy-number').css("border", "");
$("#pdc-edit-policy-number").trigger('blur');
}, 3000);
return;
}
if(pdc_add_insurance_company == 0){
toastr.remove();
toastr.error("Please specify insurance company", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#div-insurance-company').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-insurance-company').css("border", "");
$("#div-insurance-company").trigger('blur');
}, 3000);
return;
}
if(pdc_add_bank == 0){
toastr.remove();
toastr.error("Please specify bank", "Incomplete data");
addPDCModalTabSelectedTab(2);
$('#div-bank').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-bank').css("border", "");
$("#div-bank").trigger('blur');
}, 3000);
return;
}
// VALIDATIONS
// mobile
if(pdc_add_client_mobile.length != 13 || pdc_add_client_mobile.substring(0, 4) != "+639"){
toastr.remove();
toastr.warning("It seems that client mobile is invalid", "Warning");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-mobile').trigger('focus');
$('#pdc-add-client-mobile').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-mobile').css("border", "");
$("#pdc-add-client-mobile").trigger('blur');
}, 3000);
return;
}
// email
if(isEmail(pdc_add_client_email) == false){
toastr.remove();
toastr.warning("It seems that client email is invalid", "Warning");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-email').trigger('focus');
$('#pdc-add-client-email').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-email').css("border", "");
$("#pdc-add-client-email").trigger('blur');
}, 3000);
return;
}
$.ajax({
url: "/app/finance_pdc/pdc_crud.php",
method: "POST",
dataType: 'json',
data: {
new_client_fullname: pdc_add_client_name,
new_client_mobile: pdc_add_client_mobile,
new_client_other_contact: pdc_add_client_other_contact,
new_client_email: pdc_add_client_email,
new_plate_cs_number: pdc_add_plate_cs_number,
new_dealer: pdc_add_dealer,
new_brand: pdc_add_brand,
new_model: pdc_add_model,
new_variant: pdc_add_variant,
new_check_number: pdc_add_check_number,
new_check_amount: pdc_add_check_amount,
new_check_date: pdc_add_check_date,
new_policy_number: pdc_add_policy_number,
new_insurance_company: pdc_add_insurance_company,
new_bank: pdc_add_bank,
new_branch: pdc_add_branch,
type: 1 // add details
},
beforeSend: function(){
},
success: function(result) {
if(result.status == 0){ // add success
toastr.remove();
toastr.success("Successfully added");
clearAddModal();
$('#modal-financepdc-add-pdc').modal('hide');
refreshFinancePDCTable();
return;
}
else if(result.status == 1){ // update failed
toastr.remove();
toastr.error("Something went wrong, please try again", "Update failed");
return;
}
else if(result.status == 2){ // no company found
toastr.remove();
toastr.error("It seems that the dealer selected is not designated to any company", "Dealer error / Company not found");
return;
}
else if(result.status == 3){ // duplicate found
toastr.remove();
toastr.error("You may be entering a record that is already existing", "Duplicate found");
return;
}
else if(result.status == 4){ // invalid mobile
toastr.remove();
toastr.warning("It seems that client mobile is invalid", "Invalid mobile");
addPDCModalTabSelectedTab(1);
$('#pdc-add-client-mobile').trigger('focus');
$('#pdc-add-client-mobile').css('border-color', 'red');
setTimeout(function(){
$('#pdc-add-client-mobile').css("border", "");
$("#pdc-add-client-mobile").trigger('blur');
}, 3000);
return;
}
}
});
})
$('#finance-pdc-table').on('click-cell.bs.table', function(field, value, row, $el) {
pdc_plate_cs_number = $el.plate_cs_number1;
window.location.href = "/financepdc/" + pdc_plate_cs_number;
});PK IZsL3p p finance_pdc/pdc_information.jsnu [
var record_id = "";
var edit_id = "";
// Update variables
var pdc_edit_client_name = "";
var pdc_edit_client_mobile = "";
var pdc_edit_client_other_contact = "";
var pdc_edit_client_email = "";
var pdc_edit_plate_cs_number = "";
var pdc_edit_dealer = "";
var pdc_edit_brand = "";
var pdc_edit_model = "";
var pdc_edit_variant = "";
var pdc_edit_check_number = "";
var pdc_edit_check_amount = "";
var pdc_edit_check_date = "";
var pdc_edit_policy_number = "";
var pdc_edit_insurance_company = "";
var pdc_edit_bank = "";
var pdc_edit_branch = "";
$(function(){
initTablePDCInformation();
initTableRemainingDays();
refreshPDCInformationTable();
loadPDCInformation();
editPDCModalTabSelectedTab(1);
// INITIALIZATION
$('#pdc-edit-dealer').select2({
placeholder: "Dealer",
allowClear: true
})
$('#pdc-edit-brand').select2({
placeholder: "Brand",
allowClear: true
})
$('#pdc-edit-model').select2({
placeholder: "Model",
allowClear: true
})
$('#pdc-edit-variant').select2({
placeholder: "Variant",
allowClear: true
})
$('#pdc-edit-insurance-company').select2({
placeholder: "Insurance Company",
allowClear: true
})
$('#pdc-edit-bank').select2({
placeholder: "Bank",
allowClear: true
})
$('#check-date').datetimepicker({
format: 'L'
});
$('[data-mask]').inputmask();
})
function initTablePDCInformation() {
var $table = $('#pdc-information-table')
$table.bootstrapTable('destroy').bootstrapTable({
// onLoadSuccess: function(data){
// $('#pdc-info-plate-cs').val(data.rows[0].plate_cs_number);
// $('#pdc-info-brand').val(data.rows[0].brand);
// $('#pdc-info-company-dealer').val(data.rows[0].company_dealer);
// }
})
}
function initTableRemainingDays() {
var $table = $('#pdc-remaining-days')
$table.bootstrapTable('destroy').bootstrapTable({
})
}
function initTablePDCActivityLog() {
var $table = $('#pdc-activity-log-table')
$table.bootstrapTable('destroy').bootstrapTable({
})
}
function refreshPDCInformationTable() { // 2
var $table = $('#pdc-information-table')
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_pdc_table.php'
});
})
}
function refreshPDCRemainingDays() { // 3
var $table = $('#pdc-remaining-days');
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_pdc_table.php'
});
})
}
function refreshPDCActivityLogTable() { // 4 activity log table
initTablePDCActivityLog();
$('#modal-act-log-title').text("Activity Log (" + pdc_plate_cs_number + ")");
var $table = $('#pdc-activity-log-table');
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_pdc_table.php'
});
})
}
function queryParamsPDCInformationTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 2, // app/table/finance_pdc_table > pdc information insurance table list
pdc_plate_cs_number: pdc_plate_cs_number
};
}
function queryParamsPDCRemainingDaysTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 3, // app/table/finance_pdc_table > finance information insurance table list
record_id: record_id
};
}
function queryParamsPDCActivityLogTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 4, // app/table/finance_table > finance activity log table list
plate_cs_number1: pdc_plate_cs_number
};
}
function back(){
window.history.back();
}
function editPDCModalTabSelectedTab(type){
$('#pdc-modal-tab .nav-link').removeClass('active');
$('#pdc-edit-modal-tab-content .tab-pane').removeClass('show');
$('#pdc-edit-modal-tab-content .tab-pane').removeClass('active');
switch (type) {
case 1:
$('#pdc-edit-modal-tab-information').addClass('active');
$('#pdc-edit-modal-information').addClass('active');
$('#pdc-edit-modal-information').addClass('show');
break;
case 2:
$('#pdc-edit-modal-tab-insurance').addClass('active');
$('#pdc-edit-modal-insurance').addClass('active');
$('#pdc-edit-modal-insurance').addClass('show');
break;
}
}
function editPDCInfo(value, row, index){
if(can_edit_record == 0){
if(can_delete_record == 0){
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
else {
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
}
else {
if(can_delete_record == 0){
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
else {
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
}
}
function loadPDCInformation(){
$.ajax({
url: "/app/finance_pdc/pdc_information.php",
method: "POST",
dataType: 'json',
data: {
pdc_plate_cs_number1: pdc_plate_cs_number,
type: 1 // (function)
},
beforeSend: function() {
},
success: function(result) {
$('#pdc-info-plate-cs').val(result.plate_cs_number);
$('#pdc-info-brand').val(result.brand);
$('#pdc-info-company-dealer').val(result.company + "/" + result.dealer);
$('#span-date-uploaded').text(result.date_uploaded);
$('#span-uploaded-by').text(result.uploaded_by);
$('#span-modified-by').text(result.modified_by);
}
});
}
function editInformation(row_id){
if(can_edit_record == 0){
toastr.remove();
toastr.error("Sorry, you have no access in updating record", "No access");
return;
}
else {
edit_id = row_id;
editPDCModalTabSelectedTab(1);
$.ajax({
url: "/app/finance_pdc/pdc_crud.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
type: 2 // read details
},
beforeSend: function(){
},
success: function(result) { // alert(result.client_mobile);
$('#pdc-edit-client-fullname').val(result.client_name);
$('#pdc-edit-client-mobile').val(parseInt(result.client_mobile));
$('#pdc-edit-client-other-contact').val(result.client_other_contact);
$('#pdc-edit-client-email').val(result.client_email);
$('#pdc-edit-plate-cs-number').val(result.plate_cs_number);
$('#pdc-edit-dealer').val(result.dealer_id).trigger('change');
$('#pdc-edit-brand').val(result.brand_id).trigger('change');
$('#pdc-edit-model').off('change.mychange');
$('#pdc-edit-model').val(result.model_id).trigger('change');
$('#pdc-edit-model').on('change');
$('#pdc-edit-variant').off('change.mychange');
$('#pdc-edit-variant').val(result.variant_id).trigger('change');
$('#pdc-edit-variant').on('change');
$('#check-date').val(result.check_date);
$('#pdc-edit-policy-number').val(result.policy_number);
$('#pdc-edit-bank').val(result.bank_id).trigger('change');
$('#pdc-edit-branch').val(result.branch);
$('#pdc-edit-insurance-company').val(result.insurance_company_id).trigger('change');
$('#pdc-edit-check-amount').val(result.check_amount);
$('#pdc-edit-check-number').val(result.check_number);
}
});
}
}
function deleteInformation(row_id){
if(can_delete_record == 0){
toastr.remove();
toastr.error('Sorry, you have no access in deleting record', 'No access');
}
else {
swalDeletePDCRecord(row_id);
}
}
function swalDeletePDCRecord(record_id){
Swal.fire({
icon: 'question',
html: 'Are you sure you want to remove this record?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Confirm`,
denyButtonText: `Don't Confirm`,
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "/app/finance_pdc/pdc_crud.php",
method: "POST",
dataType: 'json',
data: {
type: 4, // delete
record_id: record_id
},
beforeSend: function() {
// sweetAlertSimple('info', 'Oops...', 'Removing PDC record...');
},
success: function(result) {
if(parseInt(result.status) === 0) { // deletion success
if(result.record_count > 0){
window.location.href = "/financepdc/" + pdc_plate_cs_number;
}
else {
window.location.href = "/financepdc";
}
toastr.remove();
toastr.success('Record successfully deleted', 'Success');
}
else {
toastr.remove();
toastr.error('Oops.. an error has occurred in deleting', 'Deletion failed');
}
},
error: function() {
toastr.remove();
toastr.error('Oops.. an error has occurred in deleting', 'Deletion failed');
}
});
}
else if (result.isDenied) {
// Swal.fire('', 'Changes are not saved', 'info')
}
})
}
function loadPDCDetails(record_id){
$.ajax({
url: "/app/finance_pdc/pdc_information.php",
method: "POST",
dataType: 'json',
data: {
record_id: record_id,
type: 2 // inner table
},
beforeSend: function() {
},
success: function(result) { // alert(result.check_amount); return;
if(result.client_name == ""){ $('#span-client-fullname').css('color', 'red'); $('#span-client-fullname').text("(Not provided)");} else { $('#span-client-fullname').css('color', 'black'); $('#span-client-fullname').text(result.client_name); }
if(result.client_mobile == ""){ $('#span-client-mobile').css('color', 'red'); $('#span-client-mobile').text("(Not provided)");} else { $('#span-client-mobile').css('color', 'black'); $('#span-client-mobile').text(result.client_mobile); }
if(result.client_email == ""){ $('#span-client-email').css('color', 'red'); $('#span-client-email').text("(Not provided)");} else { $('#span-client-email').css('color', 'black'); $('#span-client-email').text(result.client_email); }
if(result.bank_branch == ""){ $('#span-bank-branch-name').css('color', 'red'); $('#span-bank-branch-name').text("(Not provided)");} else { $('#span-bank-branch-name').css('color', 'black'); $('#span-bank-branch-name').text(result.bank_branch); }
if(result.check_amount == ""){ $('#span-check-amount').css('color', 'red'); $('#span-check-amount').text("(Not provided)");} else { $('#span-check-amount').css('color', 'black'); $('#span-check-amount').text(result.check_amount); }
if(result.model == "-"){ $('#span-model').css('color', 'red'); $('#span-model').text("(Not provided)");} else { $('#span-model').css('color', 'black'); $('#span-model').text(result.model); }
if(result.variant == "-"){ $('#span-variant').css('color', 'red'); $('#span-variant').text("(Not provided)");} else { $('#span-variant').css('color', 'black'); $('#span-variant').text(result.variant); }
$('#span-date-uploaded').text(result.date_added);
$('#span-uploaded-by').text(result.added_by);
$('#span-modified-by').text(result.modified_by);
refreshPDCRemainingDays();
}
});
}
function isEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(email)) {
return false;
}
else {
return true;
}
}
function fillModelDropdown(brand){
$.ajax({
url:"/app/finance_pdc/dd_get_model.php",
type:"POST",
async: false,
data: {
brand_id: brand,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#pdc-edit-model').html('');
$('#pdc-edit-model').append("\"\"");
$('#pdc-edit-model').append("\"" + result + "\"");
}
});
}
function fillVariantDropdown(model){
$.ajax({
url:"/app/finance_pdc/dd_get_variant.php",
type:"POST",
async: false,
data: {
model_id: model,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#pdc-edit-variant').html('');
$('#pdc-edit-variant').append("\"\"");
$('#pdc-edit-variant').append("\"" + result + "\"");
}
});
}
$('#pdc-edit-brand').on('change', function(){
var selected_brand = $('#pdc-edit-brand').val();
fillModelDropdown(selected_brand);
});
$('#pdc-edit-model').on('change', function(){
var selected_model = $('#pdc-edit-model').val();
fillVariantDropdown(selected_model);
});
$('#pdc-information-table').on('click-cell.bs.table', function(field, value, row, $el) {
record_id = $el.record_id;
loadPDCDetails(record_id);
});
$('#button-edit-pdc-details').on('click', function(){
if(can_edit_record == 0){
toastr.remove();
toastr.error("You do not have access in updating record", "No access");
return;
}
pdc_edit_client_name = $('#pdc-edit-client-fullname').val();
pdc_edit_client_mobile = "+63" + $('#pdc-edit-client-mobile').val();
pdc_edit_client_other_contact = $('#pdc-edit-client-other-contact').val();
pdc_edit_client_email = $('#pdc-edit-client-email').val();
pdc_edit_plate_cs_number = $('#pdc-edit-plate-cs-number').val();
pdc_edit_dealer = $('#pdc-edit-dealer').val(); if(pdc_edit_dealer === null || pdc_edit_dealer == "" || typeof pdc_edit_dealer === "undefined"){ pdc_edit_dealer = 0; }
pdc_edit_brand = $('#pdc-edit-brand').val(); if(pdc_edit_brand === null || pdc_edit_brand == "" || typeof pdc_edit_brand === "undefined"){ pdc_edit_brand = 0; }
pdc_edit_model = $('#pdc-edit-model').val(); if(pdc_edit_model === null || pdc_edit_model == "" || typeof pdc_edit_model === "undefined"){ pdc_edit_model = 0; }
pdc_edit_variant = $('#pdc-edit-variant').val(); if(pdc_edit_variant === null || pdc_edit_variant == "" || typeof pdc_edit_variant === "undefined"){ pdc_edit_variant = 0; }
pdc_edit_check_number = $('#pdc-edit-check-number').val();
pdc_edit_check_amount = $('#pdc-edit-check-amount').val();
pdc_edit_check_date = $('#check-date').val();
pdc_edit_policy_number = $('#pdc-edit-policy-number').val();
pdc_edit_insurance_company = $('#pdc-edit-insurance-company').val(); if(pdc_edit_insurance_company === null || pdc_edit_insurance_company == "" || typeof pdc_edit_insurance_company === "undefined"){ pdc_edit_insurance_company = 0; }
pdc_edit_bank = $('#pdc-edit-bank').val(); if(pdc_edit_bank === null || pdc_edit_bank == "" || typeof pdc_edit_bank === "undefined"){ pdc_edit_bank = 0; }
pdc_edit_branch = $('#pdc-edit-branch').val();
// required fields
if(pdc_edit_client_name == ""){
toastr.remove();
toastr.error("Client name field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-client-fullname').trigger('focus');
$('#pdc-edit-client-fullname').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-client-fullname').css("border", "");
$("#pdc-edit-client-fullname").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_client_mobile == ""){
toastr.remove();
toastr.error("Client mobile field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-client-mobile').trigger('focus');
$('#pdc-edit-client-mobile').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-client-mobile').css("border", "");
$("#pdc-edit-client-mobile").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_client_email == ""){
toastr.remove();
toastr.error("Client email field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-client-email').trigger('focus');
$('#pdc-edit-client-email').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-client-fullname').css("border", "");
$("#pdc-edit-client-fullname").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_plate_cs_number == ""){
toastr.remove();
toastr.error("Plate/CS Number field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-plate-cs-number').trigger('focus');
$('#pdc-edit-plate-cs-number').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-plate-cs-number').css("border", "");
$("#pdc-edit-plate-cs-number").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_dealer == 0){
toastr.remove();
toastr.error("Please specify dealer", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#div-dealer').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-dealer').css("border", "");
$("#div-dealer").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_brand == 0){
toastr.remove();
toastr.error("Please specify brand", "Incomplete data");
editPDCModalTabSelectedTab(1);
$('#div-brand').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-brand').css("border", "");
$("#div-brand").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_check_number == ""){
toastr.remove();
toastr.error("Check number field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(2);
$('#pdc-edit-check-number').trigger('focus');
$('#pdc-edit-check-number').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-check-number').css("border", "");
$("#pdc-edit-check-number").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_check_amount == ""){
toastr.remove();
toastr.error("Check amount field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(2);
$('#pdc-edit-check-amount').trigger('focus');
$('#pdc-edit-check-amount').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-check-amount').css("border", "");
$("#pdc-edit-check-amount").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_check_date == ""){
toastr.remove();
toastr.error("Check date field cannot be empty", "Incomplete data");
editPDCModalTabSelectedTab(2);
$('#pdc-edit-check-date').trigger('focus');
$('#pdc-edit-check-date').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-check-date').css("border", "");
$("#pdc-edit-check-date").trigger('blur');
}, 3000);
return;
}
// if(pdc_edit_policy_number == ""){
// toastr.remove();
// toastr.error("Policy number field cannot be empty", "Incomplete data");
// editPDCModalTabSelectedTab(2);
// $('#pdc-edit-policy-number').trigger('focus');
// $('#pdc-edit-policy-number').css('border-color', 'red');
// setTimeout(function(){
// $('#pdc-edit-policy-number').css("border", "");
// $("#pdc-edit-policy-number").trigger('blur');
// }, 3000);
// return;
// }
if(pdc_edit_insurance_company == 0){
toastr.remove();
toastr.error("Please specify insurance company", "Incomplete data");
editPDCModalTabSelectedTab(2);
$('#div-insurance-company').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-insurance-company').css("border", "");
$("#div-insurance-company").trigger('blur');
}, 3000);
return;
}
if(pdc_edit_bank == 0){
toastr.remove();
toastr.error("Please specify bank", "Incomplete data");
editPDCModalTabSelectedTab(2);
$('#div-bank').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-bank').css("border", "");
$("#div-bank").trigger('blur');
}, 3000);
return;
}
// alert(pdc_edit_client_mobile); return;
// VALIDATIONS
// mobile
if(pdc_edit_client_mobile.length != 13 || pdc_edit_client_mobile.substring(0, 4) != "+639"){
toastr.remove();
toastr.warning("It seems that client mobile is invalid", "Warning");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-client-mobile').trigger('focus');
$('#pdc-edit-client-mobile').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-client-mobile').css("border", "");
$("#pdc-edit-client-mobile").trigger('blur');
}, 3000);
return;
}
// email
if(isEmail(pdc_edit_client_email) == false){
toastr.remove();
toastr.warning("It seems that client email is invalid", "Warning");
editPDCModalTabSelectedTab(1);
$('#pdc-edit-client-email').trigger('focus');
$('#pdc-edit-client-email').css('border-color', 'red');
setTimeout(function(){
$('#pdc-edit-client-email').css("border", "");
$("#pdc-edit-client-email").trigger('blur');
}, 3000);
return;
}
$.ajax({
url: "/app/finance_pdc/pdc_crud.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
update_client_fullname: pdc_edit_client_name,
update_client_mobile: pdc_edit_client_mobile,
update_client_other_contact: pdc_edit_client_other_contact,
update_client_email: pdc_edit_client_email,
update_plate_cs_number: pdc_edit_plate_cs_number,
update_dealer: pdc_edit_dealer,
update_brand: pdc_edit_brand,
update_model: pdc_edit_model,
update_variant: pdc_edit_variant,
update_check_number: pdc_edit_check_number,
update_check_amount: pdc_edit_check_amount,
update_check_date: pdc_edit_check_date,
update_policy_number: pdc_edit_policy_number,
update_insurance_company: pdc_edit_insurance_company,
update_bank: pdc_edit_bank,
update_branch: pdc_edit_branch,
type: 3 // update details
},
beforeSend: function(){
},
success: function(result) {
if(result.status == 0){ // update success
toastr.remove();
toastr.success("Successfully updated");
$('#modal-pdc-edit-info').modal('hide');
pdc_plate_cs_number1 = result.plate_cs_number1;
refreshPDCInformationTable();
window.history.pushState({
"html": Response.html,
"pageTitle": Response.pageTitle
},
"",
"/financepdc/" + pdc_plate_cs_number1
);
loadPDCInformation();
loadPDCDetails(result.record_id);
return;
}
else if(result.status == 1){ // update failed
toastr.remove();
toastr.error("Something went wrong, please try again", "Update failed");
return;
}
else if(result.status == 2){ // no company found
toastr.remove();
toastr.error("It seems that the dealer selected is not designated to any company", "Dealer error / Company not found");
return;
}
else if(result.status == 3){ // duplicate found
toastr.remove();
toastr.error("You may be entering a record that is already existing", "Duplicate found");
return;
}
// else if(result.status == 4){ // invalid mobile
// toastr.remove();
// toastr.warning("It seems that both client mobile is invalid", "Invalid mobile");
// editPDCModalTabSelectedTab(1);
// $('#pdc-edit-client-mobile').trigger('focus');
// $('#pdc-edit-client-mobile').css('border-color', 'red');
// setTimeout(function(){
// $('#pdc-edit-client-mobile').css("border", "");
// $("#pdc-edit-client-mobile").trigger('blur');
// }, 3000);
// return;
// }
}
});
})PK IZky˯} }
functions.phpnu [ PK IZFw p p car_club.phpnu [ PK IZaJ aJ finance/financedashboard.jsnu [ // GLOBALS
var graph_companies = null;
var lineChart = null;
var box = 0;
var granted = granted_company_ids;
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;
$(function(){
initToolTip();
detailsCount();
showGraphCompany();
showLineGraph();
initTableFinanceDashboard();
start = moment().startOf('month');
end = moment().endOf('month');
$('#tip-new').attr('data-original-title', "Newly added this year, first time
");
$('#tip-company-count').attr('data-original-title', "Overall count
");
$('#tip-versus-years').attr('data-original-title', "Individual insurance count
");
$('#tip-with-vehicle').attr('data-original-title', "Insurance that have vehicle record
");
$('#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);
});
$('#company-filter').select2({
placeholder: "Company",
allowClear: true
})
$('#dealer').select2({
placeholder: "Dealer",
allowClear: false
})
$('[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();
});
$('#date-range').text("No Filter");
})
function initToolTip(){
var bootstrapTooltip = $.fn.tooltip.noConflict();
$.fn.bstooltip = bootstrapTooltip;
$('#tip-new').bstooltip();
$('#tip-company-count').bstooltip();
$('#tip-versus-years').bstooltip();
$('#tip-with-vehicle').bstooltip();
}
function initTableFinanceDashboard() {
var $table = $('#finance-table-dashboard')
$table.bootstrapTable('destroy').bootstrapTable({
})
}
function refreshFinanceDashboardTable() { // 5
var $table = $('#finance-dashboard-table')
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_table.php'
});
})
}
function queryParamsFinanceDashboardTable(params) {
// $('#company-filter').text(company == '0' ? 'All' : $("#company-filter option:selected").text());
return {
search: params.search,
offset: params.offset,
limit: params.limit,
company: company,
dealer: dealer,
type: 5,
box: box
};
}
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function fillDealer(){
var comp = $('#company-filter').val();
dealer = 0;
hideTable();
$.ajax({
url:"app/misc/get_dealer3.php",
type:"POST",
data: {
company: comp,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#dealer').html('');
// $('#dealer').append("\"\"");
$('#dealer').append("\"" + result + "\"");
}
});
}
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 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();
if(company === null || company == "" || typeof company === "undefined"){ company = 0; }
fillDealer();
hideTable();
reset = 0;
$('#span-company').text($('#company-filter').select2('data')[0].text);
$('#span-dealer').text("");
cb(start, end);
});
}
function setDateRangePickerWidth(isMobile) {
if ($(".daterangepicker").hasClass('show-calendar') && !isMobile) {
$('.daterangepicker').css('width', '630px');
}
else {
$('.daterangepicker').css('width', 'auto');
}
reset = 0;
}
function passDate(startDate, endDate) {
detailsCount();
showGraphCompany();
showLineGraph();
}
function cb(start, end) {
var startDate = start.format('YYYY-MM-DD');
passDate(start, end); //pass empty dates
}
function buttonsFunction() {
return {
grid_toggle_off: {
'icon': 'far fa-times',
'event': 'hideTable',
'attributes': {
'id': 'hide-table',
'title': 'Close / Hide table',
'class': 'error'
}
}
// ,
// excel_export: {
// 'icon': 'fa-file-excel',
// 'event': 'exportXlsx',
// 'attributes': {
// 'id': 'download-excel-bg',
// 'title': 'Download XLSX (Excel)',
// 'data-test': 'test123'
// }
// }
}
}
function hideTable(){
$('#fni-dashboard-div').fadeOut();
}
function showGraphCompany(){
$.ajax({
url: "/app/finance/dashboard/company_count.php",
method: "POST",
dataType: 'json',
data: {
// startDate: startDate,
// endDate: endDate,
company: company,
dealer: dealer
},
beforeSend: function() {
$('#loading_company_count').show();
},
success: function(data) {
var tooltip = "";
var id = [];
var name = [];
var marks = [];
var total = 0;
for(var i in data) {
name.push(data[i].code);
marks.push(data[i].total);
id.push(data[i].id);
total = total + parseInt(data[i].total);
tooltip = tooltip + data[i].code + ' - ' +addCommas(data[i].total) + '
';
}
$('#bar-chart-company-title').attr('data-original-title', tooltip);
var chartdata = {
labels: name,
ids: id,
datasets: [{
label: 'Total: ' + addCommas(total),
backgroundColor: '#17a2b8',
borderColor: '#46d5f1',
hoverBackgroundColor: '#00c0ef',
hoverBorderColor: '#666666',
data: marks
}]
};
var barOptions = {
responsive: true,
maintainAspectRatio: false,
// onClick: graphClickEventCompany,
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var value = data.datasets[0].data[tooltipItem.index];
return addCommas(value)
}
} // end callbacks:
}, //end tooltips
scales: {
yAxes: [{
ticks: {
precision: 0,
beginAtZero: true,
callback: function(label, index, labels) {
if (parseInt(label) >= 1000000) {
return label / 1000000 + 'M';
} else if (parseInt(label) >= 1000) {
return label / 1000 + 'K';
} else {
return label;
}
}
},
}],
xAxes: [{
ticks: {
autoSkip: false,
maxRotation: 90,
minRotation: 90
}
}]
}
}
var graphTarget = $("#bar-chart-company");
if(graph_companies != null) {
graph_companies.destroy();
}
graph_companies = new Chart(graphTarget, {
type: 'bar',
data: chartdata,
options: barOptions
});
$('.company_countings_loading').hide();
}
})
}
function showLineGraph(){
$.ajax({
url: "/app/finance/dashboard/versus_years.php",
method: "POST",
dataType: 'json',
data: {
// startDate: startDate,
// endDate: endDate,
company: company,
dealer: dealer
},
beforeSend: function() {
$('#loading_versus_years').show();
},
success: function(data) {
var current_year = data.current_year;
var current = data.current;
var previous = data.previous;
var previous_2 = data.previous_2;
var lineChartData = {
labels : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
datasets: [
{
label : current_year,
backgroundColor : 'rgba(45,85,255,1)',
borderColor : 'rgba(45,85,255,1)',
pointRadius : true,
pointColor : '#3b8bba',
pointStrokeColor : 'rgba(60,141,188,1)',
pointHighlightFill : '#fff',
pointHighlightStroke: 'rgba(60,141,188,1)',
data : current
},
{
label : current_year-1,
backgroundColor : 'rgba(0, 181, 204, 1)',
borderColor : 'rgba(0, 181, 204, 1)',
pointRadius : true,
pointColor : 'rgba(210, 214, 222, 1)',
pointStrokeColor : '#c1c7d1',
pointHighlightFill : '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data : previous
},
{
label : current_year-2,
backgroundColor : 'rgba(210, 214, 222, 1)',
borderColor : 'rgba(210, 214, 222, 1)',
pointRadius : true,
pointColor : '',
pointStrokeColor : 'rgba(60,141,188,1)',
pointHighlightFill : '#fff',
pointHighlightStroke: 'rgba(60,141,188,1)',
data : previous_2
},
]
}
var lineChartCanvas = $('#line-chart').get(0).getContext('2d');
lineChartData.datasets[0].fill = false;
lineChartData.datasets[1].fill = false;
lineChartData.datasets[2].fill = false;
var lineChartOptions = {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
precision: 0,
beginAtZero: true,
callback: function(label, index, labels) {
if (parseInt(label) >= 1000000) {
return label / 1000000 + 'M';
}
else if (parseInt(label) >= 1000) {
return label / 1000 + 'K';
}
else {
return label;
}
}
},
}],
xAxes: [{
ticks: {
autoSkip: false,
maxRotation: 90,
minRotation: 90
}
}]
},
title: {
fontSize: 15,
display: true,
text: 'Versus previous years',
padding: 3
},
}
lineChart = new Chart(lineChartCanvas, {
type: 'line',
data: lineChartData,
options: lineChartOptions
})
$('#loading_versus_years').hide();
}
})
}
function detailsCount(){
$.ajax({
url:"/app/finance/dashboard/details_count.php",
type:"POST",
dataType:"json",
data: {
company: company,
dealer: dealer,
type: 1 // details box count
},
beforeSend: function(){
},
success: function(result){
$('#span-categorized-vehicle').text(result.categorized);
// $('#span-individual-insurance').text(result.individual_insurance);
$('#span-inactive').text(result.inactive);
$('#span-newly-added').text(result.newly_added);
$('#span-vehicle-record').text(result.vehicle_record);
}
});
}
$('#dealer').on('change', function(){
dealer = $('#dealer').val();
var start = $('#filter-date').data('daterangepicker').startDate;
var end = $('#filter-date').data('daterangepicker').endDate;
reset = 0;
$('#span-dealer').text($('#dealer').find(':selected').text());
cb(start, end);
})
// COUNT BOXES
$('#box-categorized-by-vehicle').on('click', function() {
box = 1; // categorized by vehicle
$('#fni-dashboard-div').attr('hidden', false);
$('#fni-dashboard-div').fadeIn();
refreshFinanceDashboardTable();
})
$('#box-inactive').on('click', function() { // alert("On going"); return;
box = 2; // inactive
$('#fni-dashboard-div').attr('hidden', false);
$('#fni-dashboard-div').fadeIn();
refreshFinanceDashboardTable();
})
$('#box-new').on('click', function() { // alert("Maintenance"); return;
box = 3; // new
$('#fni-dashboard-div').attr('hidden', false);
$('#fni-dashboard-div').fadeIn();
refreshFinanceDashboardTable();
})
$('#box-with-vehicle').on('click', function() { // alert("On going"); return;
box = 4; // with vehicle
$('#fni-dashboard-div').attr('hidden', false);
$('#fni-dashboard-div').fadeIn();
refreshFinanceDashboardTable();
})
$('#finance-dashboard-table').on('click-cell.bs.table', function(field, value, row, $el) {
var finance_id = $el.id;
var plate_cs_number = $el.plate_cs_number;
window.location.href = "/financelist/" + plate_cs_number;
});
$('#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('');
hideTable();
company = 0;
dealer = 0;
$('#span-company').text("");
$('#span-dealer').text("");
addListenerCompanyFilter(); //enable again the company filter event
start = moment().startOf('month');
end = moment().endOf('month');
reset = 1;
filter_date = 0;
resetDateRangePicker(start, end);
});PK IZVa a finance/finance.jsnu [ // 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', "Grouped by plate / cs number
");
$('#tip-individual-insurance').attr('data-original-title', "Total count of individual insurance
");
$('#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("\"\"");
$('#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("\"\"");
$('#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("\"\"");
$('#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')
}
})
}PK IZ ͉ ͉ finance/finance_information.jsnu [ //GLOBAL VARIABLES
var fin_id = 0;
// Update variables
var fni_edit_plate_cs_number = "";
var fni_edit_brand = "";
var fni_edit_model = "";
var fni_edit_variant = "";
var fni_edit_dealer = "";
var fni_edit_customer_fullname = "";
var fni_edit_customer_mobile = "";
var fni_edit_customer_other_contact = "";
var fni_edit_customer_email = "";
var fni_edit_customer_address = "";
var fni_edit_policy_issue_date = "";
var fni_edit_policy_start_date = "";
var fni_edit_policy_end_date = "";
var fni_edit_policy_number = "";
var fni_edit_bank = "";
var fni_edit_insurance_provider = "";
var fni_edit_insurance_type = "";
var fni_edit_sales_consultant = "";
var fni_edit_paid_amount = "";
var fni_edit_lock_in_year = "";
var fni_edit_terms = "";
var fni_edit_locked_in = 1;
// others: for dropdown
var selected_brand = "";
var selected_model = "";
$(function(){
refreshFinanceInformationTable();
loadFinanceInformation();
initTableFinanceInformation();
initTableRemainingDays();
editFNIModalTabSelectedTab(1);
$('#finance-information-table').on('click', '.clickable-row', function(event) { // wala lang ito, 'di pa gumagana
if($(this).hasClass('active')){
$(this).removeClass('active');
}
else {
$(this).addClass('active').siblings().removeClass('active');
}
});
$('#fni-edit-brand').select2({
placeholder: "Brand",
allowClear: true
});
$('#fni-edit-model').select2({
placeholder: "Model",
allowClear: true
});
$('#fni-edit-variant').select2({
placeholder: "Variant",
allowClear: true
});
$('#fni-edit-dealer').select2({
placeholder: "Dealer",
allowClear: true
})
$('#fni-edit-insurance-provider').select2({
placeholder: "Insurance Provider",
allowClear: true
})
$('#fni-edit-insurance-type').select2({
placeholder: "Insurance Type",
allowClear: true
})
$('#issue-date').datetimepicker({
format: 'L'
});
$('#start-date').datetimepicker({
format: 'L'
});
$('#end-date').datetimepicker({
format: 'L'
});
//Date picker
$('#mod-birth-date').datetimepicker({
format: 'L'
});
$('[data-mask]').inputmask();
});
function initTableFinanceInformation() {
var $table = $('#finance-information-table')
$table.bootstrapTable('destroy').bootstrapTable({
})
}
function initTableRemainingDays() {
var $table = $('#finance-remaining-days')
$table.bootstrapTable('destroy').bootstrapTable({
onLoadSuccess: function(data) {
// alert(data.rows.length);
}
})
}
function initTableFinanceActivityLog() {
var $table = $('#finance-activity-log-table')
$table.bootstrapTable('destroy').bootstrapTable({
});
}
function refreshFinanceInformationTable() { // 2 finance information table
var $table = $('#finance-information-table')
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_table.php'
});
})
}
function refreshFinanceRemainingDays() { // 3 remaining days table
var $table = $('#finance-remaining-days')
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_table.php'
});
})
}
function refreshFNIActivityLogTable() { // 6 activity log table
initTableFinanceActivityLog();
$('#modal-act-log-title').text("Activity Log (" + plate_cs_number + ")");
var $table = $('#finance-activity-log-table');
$(function() {
$table.bootstrapTable('refresh', {
url: '/app/table/finance_table.php'
});
})
}
function queryParamsFinanceInformationTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 2, // app/table/finance_table > finance information insurance table list
plate_cs_number: plate_cs_number
};
}
function queryParamsFinanceRemainingDaysTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 3, // app/table/finance_table > finance information insurance table list
fin_id: fin_id,
plate_cs_number: plate_cs_number,
policy_number: policy_number
};
}
function queryParamsFinanceActivityLogTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 6, // app/table/finance_table > finance activity log table list
plate_cs_number1: plate_cs_number
};
}
function back(){
$('#span-customer-fullname').text("");
$('#span-mobile-number').text("");
$('#span-email').text("");
$('#span-sales-consultant').text("");
$('#span-address').text("");
$('#span-bank-name').text("");
$('#span-locked-in-status').text("");
$('#span-locked-in-years').text("");
$('#span-terms').text("");
window.history.back();
}
function loadFinanceInformation(){
$.ajax({
url: "/app/finance/finance_information.php",
method: "POST",
dataType: 'json',
data: {
plate_cs_number: plate_cs_number,
type: 1 // (function)
},
beforeSend: function() {
},
success: function(result) {
// $('#span-plate-cs').text(result.plate_cs_number);
$('#fni-info-plate-cs').val(result.plate_cs_number);
// if(result.brand == "(None)"){$('#span-brand').text("(Not provided)"); $('#span-brand').css('color', 'red'); } else { $('#span-brand').css('color', 'black'); $('#span-brand').text(result.brand); }
$('#fni-info-brand').val(result.brand);
$('#fni-info-company-dealer').val(result.company + "/" + result.dealer);
// $('#span-company-dealer').text(result.company + "/" + result.dealer);
// $('#span-date-uploaded').text(result.date_uploaded);
// $('#span-uploaded-by').text(result.uploaded_by);
// $('#span-modified-by').text(result.modified_by);
}
});
}
function loadFinanceDetails(fin_id, policy_number, policy_issue_date){
$.ajax({
url: "/app/finance/finance_information.php",
method: "POST",
dataType: 'json',
data: {
policy_number: policy_number,
policy_issue_date: policy_issue_date,
type: 2 // inner table
},
beforeSend: function() {
},
success: function(result) { // alert($.trim(result.modified_by)); return;
if(result.customer_fullname == ""){ $('#span-customer-fullname').css('color', 'red'); $('#span-customer-fullname').text("(Not provided)");} else { $('#span-customer-fullname').css('color', 'black'); $('#span-customer-fullname').text(result.customer_fullname); }
if(result.mobile_number == ""){ $('#span-mobile-number').css('color', 'red'); $('#span-mobile-number').text("(Not provided)");} else { $('#span-mobile-number').css('color', 'black'); $('#span-mobile-number').text(result.mobile_number); }
if(result.email == ""){ $('#span-email').css('color', 'red'); $('#span-email').text("(Not provided)");} else { $('#span-email').css('color', 'black'); $('#span-email').text(result.email); }
if(result.sales_consultant == ""){ $('#span-sales-consultant').css('color', 'red'); $('#span-sales-consultant').text("(Not provided)");} else { $('#span-sales-consultant').css('color', 'black'); $('#span-sales-consultant').text(result.sales_consultant); }
if(result.customer_address == ""){ $('#span-address').css('color', 'red'); $('#span-address').text("(Not provided)");} else { $('#span-address').css('color', 'black'); $('#span-address').text(result.customer_address); }
if(result.bank_name == ""){ $('#span-bank-name').css('color', 'red'); $('#span-bank-name').text("(Not provided)");} else { $('#span-bank-name').css('color', 'black'); $('#span-bank-name').text(result.bank_name); }
$('#span-locked-in-status').text(result.locked_in);
if(result.locked_in_years == ""){ $('#span-locked-in-years').css('color', 'red'); $('#span-locked-in-years').text("(Not provided)");} else { $('#span-locked-in-years').css('color', 'black'); $('#span-locked-in-years').text(result.locked_in_years); }
$('#span-terms').text(result.terms);
// if(result.brand == "-"){ $('#span-brand').css('color', 'red'); $('#span-brand').text("(Not provided)");} else { $('#span-brand').css('color', 'black'); $('#span-brand').text(result.brand); }
if(result.model == "-"){ $('#span-car-model').css('color', 'red'); $('#span-car-model').text("(Not provided)");} else { $('#span-car-model').css('color', 'black'); $('#span-car-model').text(result.model); }
if(result.variant == "-"){ $('#span-variant').css('color', 'red'); $('#span-variant').text("(Not provided)");} else { $('#span-variant').css('color', 'black'); $('#span-variant').text(result.variant); }
$('#span-date-uploaded').text(result.date_uploaded + " " + result.add_source);
$('#span-uploaded-by').text(result.uploaded_by);
if($.trim(result.modified_by) == "Unknown"){
$('#span-modified-by').text("");
}
else {
$('#span-modified-by').text(result.modified_by + " (" + result.date_modified + ")");
}
$('#finance-plate-cs-information').attr('hidden', false);
}
});
refreshFinanceRemainingDays();
}
function editFNIInfo(value, row, index){
if(can_edit_record == 0){
if(can_delete_record == 0){
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
else {
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
}
else {
if(can_delete_record == 0){
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
else {
return '' +
'
' +
'' +
'
' +
'
' +
'' +
'
' +
'
'
;
}
}
}
function editInformation(row_id){
if(can_edit_record == 0){
toastr.remove();
toastr.error("Sorry, you have no access in updating record", "No access");
return;
}
else {
edit_id = row_id;
editFNIModalTabSelectedTab(1);
$.ajax({
url: "/app/finance/finance_crud.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
type: 2 // read details
},
beforeSend: function(){
},
success: function(result) { // alert(result.customer_mobile_number); return;
$('#fni-edit-plate-cs-number').val(result.plate_cs_number);
$('#fni-edit-brand').val(result.brand_id).trigger('change');
// var promises = fillModelDropdown(result.brand_id);
// $.when.apply($, promises).then(function(){
// fillVariantDropdown(result.model_id);
// });
// $.when(a(result.brand_id)).done(function(){
// b(result.model_id);
// });
$('#fni-edit-model').off('change.mychange');
$('#fni-edit-model').val(result.model_id).trigger('change');
$('#fni-edit-model').on('change');
$('#fni-edit-variant').off('change.mychange');
$('#fni-edit-variant').val(result.variant_id).trigger('change');
$('#fni-edit-variant').on('change');
$('#fni-edit-dealer').val(result.dealer_id).trigger('change');
$('#fni-edit-customer-fullname').val(result.customer_fullname);
$('#fni-edit-customer-mobile').val(parseInt(result.customer_mobile_number));
$('#fni-edit-customer-other-contact').val(result.customer_other_contact);
$('#fni-edit-customer-email').val(result.customer_email);
$('#fni-edit-customer-address').val(result.customer_address);
$('#issue-date').val(result.policy_issue_date);
$('#start-date').val(result.policy_start_date);
$('#end-date').val(result.policy_end_date);
$('#fni-edit-policy-number').val(result.policy_number);
$('#fni-edit-bank').val(result.bank_name);
$('#fni-edit-insurance-provider').val(result.insurance_provider).trigger('change');
$('#fni-edit-insurance-type').val(result.insurance_business_type).trigger('change');
$('#fni-edit-sales-consultant').val(result.sales_consultant);
$('#fni-edit-paid-amount').val(result.paid_amount);
$('#fni-edit-lock-in-year').val(result.locked_in_years);
$('#fni-edit-terms').val(result.terms);
// check box locked in
if(result.locked_in == 0){
$('#check-lock-in').prop('checked', false);
fni_edit_locked_in = 0;
}
else {
$('#check-lock-in').prop('checked', true);
fni_edit_locked_in = 1;
}
}
});
}
}
function a(value){
$('#fni-edit-model').off('change.mychange');
$('#fni-edit-model').val(value).trigger('change');
$('#fni-edit-model').on('change');
}
function b(value){
$('#fni-edit-variant').off('change.mychange');
$('#fni-edit-variant').val(value).trigger('change');
$('#fni-edit-variant').on('change');
}
function editFNIModalTabSelectedTab(type){
$('#fni-modal-tab .nav-link').removeClass('active');
$('#fni-edit-modal-tab-content .tab-pane').removeClass('show');
$('#fni-edit-modal-tab-content .tab-pane').removeClass('active');
switch (type) {
case 1:
$('#fni-edit-modal-tab-information').addClass('active');
$('#fni-edit-modal-information').addClass('active');
$('#fni-edit-modal-information').addClass('show');
break;
case 2:
$('#fni-edit-modal-tab-insurance').addClass('active');
$('#fni-edit-modal-insurance').addClass('active');
$('#fni-edit-modal-insurance').addClass('show');
break;
}
}
function isEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(email)) {
return false;
}
else {
return true;
}
}
function fillModelDropdown(){
$.ajax({
url:"/app/finance/dd_get_model.php",
type:"POST",
async: false,
data: {
brand_id: selected_brand,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#fni-edit-model').html('');
$('#fni-edit-model').append("\"\"");
$('#fni-edit-model').append("\"" + result + "\"");
}
});
}
function fillVariantDropdown(){
$.ajax({
url:"/app/finance/dd_get_variant.php",
type:"POST",
async: false,
data: {
model_id: selected_model,
type: 1
},
beforeSend: function(){
},
success: function(result){
$('#fni-edit-variant').html('');
$('#fni-edit-variant').append("\"\"");
$('#fni-edit-variant').append("\"" + result + "\"");
}
});
}
function deleteInformation(row_id){
if(can_delete_record == 0){
toastr.remove();
toastr.error('Sorry, you have no access in deleting record', 'No access');
}
else {
swalDeleteFNIRecord(row_id);
}
}
function swalDeleteFNIRecord(record_id){
Swal.fire({
icon: 'question',
html: 'Are you sure you want to remove this record?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Confirm`,
denyButtonText: `Don't Confirm`,
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "/app/finance/finance_crud.php",
method: "POST",
dataType: 'json',
data: {
type: 4, // delete
record_id: record_id
},
beforeSend: function() {
// sweetAlertSimple('info', 'Oops...', 'Removing FNI record...');
},
success: function(result) {
if(parseInt(result.status) === 0) { // deletion success
if(result.record_count > 0){
window.location.href = "/financelist/" + plate_cs_number;
}
else {
window.location.href = "/financelist";
}
toastr.remove();
toastr.success('Record successfully deleted', 'Success');
}
else {
toastr.remove();
toastr.error('Oops.. an error has occurred in deleting', 'Deletion failed');
}
},
error: function() {
toastr.remove();
toastr.error('Oops.. an error has occurred in deleting', 'Deletion failed');
}
});
}
else if (result.isDenied) {
// Swal.fire('', 'Changes are not saved', 'info')
}
})
}
$('#finance-information-table').on('click-cell.bs.table', function(field, value, row, $el) {
fin_id = $el.finance_id;
policy_number = $el.policy_number;
policy_issue_date = $el.policy_issue_date;
loadFinanceDetails(fin_id, policy_number, policy_issue_date);
loadFinanceInformation();
});
$('#fni-edit-brand').on('change', function(){
selected_brand = $('#fni-edit-brand').val();
$('#fni-edit-variant').html('');
// fillModelDropdown(selected_brand);
$.when(fillModelDropdown()).done(function(){
fillVariantDropdown();
});
// var promises = fillModelDropdown(selected_brand);
// $.when.apply($, promises).then(function(){
// fillVariantDropdown(selected_model);
// });
});
$('#fni-edit-model').on('change', function(){
selected_model = $('#fni-edit-model').val();
fillVariantDropdown(selected_model);
});
$('#fni-edit-brand').on('select2: unselecting', function(event){
fni_edit_brand = 0;
})
$('#check-lock-in').on('click', function(){
if(fni_edit_locked_in == 0){ fni_edit_locked_in = 1; } else { fni_edit_locked_in = 0; }
});
$('#button-edit-fni-details').on('click', function(){ // alert("Working"); return;
if(can_edit_record == 0){
toastr.remove();
toastr.error("You do not have access in updating record", "No access");
return;
}
fni_edit_plate_cs_number = $('#fni-edit-plate-cs-number').val();
fni_edit_dealer = $('#fni-edit-dealer').val();
fni_edit_brand = $('#fni-edit-brand').val(); if(fni_edit_brand === null || fni_edit_brand == "" || typeof fni_edit_brand === "undefined"){ fni_edit_brand = 0; }
fni_edit_model = $('#fni-edit-model').val(); if(fni_edit_model === null || fni_edit_model == "" || typeof fni_edit_model === "undefined"){ fni_edit_model = 0; }
fni_edit_variant = $('#fni-edit-variant').val(); if(fni_edit_variant === null || fni_edit_variant == "" || typeof fni_edit_variant === "undefined"){ fni_edit_variant = 0; }
fni_edit_customer_fullname = $('#fni-edit-customer-fullname').val();
fni_edit_customer_mobile = "+63" + $('#fni-edit-customer-mobile').val();
fni_edit_customer_other_contact = $('#fni-edit-customer-other-contact').val();
fni_edit_customer_email = $('#fni-edit-customer-email').val();
fni_edit_customer_address = $('#fni-edit-customer-address').val();
fni_edit_policy_issue_date = $('#issue-date').val();
fni_edit_policy_start_date = $('#start-date').val();
fni_edit_policy_end_date = $('#end-date').val();
fni_edit_policy_number = $('#fni-edit-policy-number').val();
fni_edit_bank = $('#fni-edit-bank').val();
fni_edit_sales_consultant = $('#fni-edit-sales-consultant').val();
fni_edit_paid_amount = $('#fni-edit-paid-amount').val();
fni_edit_lock_in_year = $('#fni-edit-lock-in-year').val();
fni_edit_terms = $('#fni-edit-terms').val();
// dropdowns
fni_edit_brand = $('#fni-edit-brand').val();
if(fni_edit_brand === null || fni_edit_brand == "" || typeof fni_edit_brand === "undefined"){ fni_edit_brand = 0; }
fni_edit_insurance_provider = $('#fni-edit-insurance-provider').val();
if(fni_edit_insurance_provider === null || fni_edit_insurance_provider == "" || typeof fni_edit_insurance_provider === "undefined"){ fni_edit_insurance_provider = 0; }
fni_edit_insurance_type = $('#fni-edit-insurance-type').val();
if(fni_edit_insurance_type === null || fni_edit_insurance_type == "" || typeof fni_edit_insurance_type === "undefined"){ fni_edit_insurance_type = 0; }
// required fields
if(fni_edit_plate_cs_number == ""){ // plate/cs number
toastr.remove();
toastr.error("Plate/CS Number field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#fni-edit-plate-cs-number').trigger('focus');
$('#fni-edit-plate-cs-number').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-plate-cs-number').css("border", "");
$("#fni-edit-plate-cs-number").trigger('blur');
}, 3000);
return;
}
if(fni_edit_brand == 0){ // brand
toastr.remove();
toastr.error("Please specify brand", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#div-brand').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-brand').css("border", "");
$("#div-brand").trigger('blur');
}, 3000);
return;
}
// if(fni_edit_model == 0){ // model
// toastr.remove();
// toastr.error("Please specify model", "Incomplete!");
// editFNIModalTabSelectedTab(1);
// $('#div-model').css('border', '1px solid #dc3545');
// setTimeout(function(){
// $('#div-model').css("border", "");
// $("#div-model").trigger('blur');
// }, 3000);
// return;
// }
if(fni_edit_dealer == 0){ // dealer
toastr.remove();
toastr.error("Please specify dealer", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#div-dealer').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-dealer').css("border", "");
$("#div-dealer").trigger('blur');
}, 3000);
return;
}
if(fni_edit_customer_fullname == ""){ // customer fullname
toastr.remove();
toastr.error("Customer fullname field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-fullname').trigger('focus');
$('#fni-edit-customer-fullname').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-fullname').css("border", "");
$("#fni-edit-customer-fullname").trigger('blur');
}, 3000);
return;
}
if(edit_mobile_required == 1){
if(fni_edit_customer_mobile == "+63"){ // customer mobile
toastr.remove();
toastr.error("Customer mobile is required", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-mobile').trigger('focus');
$('#fni-edit-customer-mobile').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-mobile').css("border", "");
$("#fni-edit-customer-mobile").trigger('blur');
}, 3000);
return;
}
else {
if(fni_edit_customer_mobile.length != 13 || fni_edit_customer_mobile.substring(0, 4) != "+639"){
toastr.remove();
toastr.warning("It seems that customer mobile is invalid", "Warning!");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-mobile').trigger('focus');
$('#fni-edit-customer-mobile').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-mobile').css("border", "");
$("#fni-edit-customer-mobile").trigger('blur');
}, 3000);
return;
}
}
}
else {
if(fni_edit_customer_mobile != ""){
if(fni_edit_customer_mobile.length != 13 || fni_edit_customer_mobile.substring(0, 4) != "+639"){
toastr.remove();
toastr.warning("It seems that customer mobile is invalid", "Invalid mobile");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-mobile').trigger('focus');
$('#fni-edit-customer-mobile').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-mobile').css("border", "");
$("#fni-edit-customer-mobile").trigger('blur');
}, 3000);
return;
}
}
}
if(edit_email_required == 1){
if(fni_edit_customer_email == ""){ // customer email
toastr.remove();
toastr.error("Customer email is required", "Incomplete!");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-email').trigger('focus');
$('#fni-edit-customer-email').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-email').css("border", "");
$("#fni-edit-customer-email").trigger('blur');
}, 3000);
return;
}
else {
if(isEmail(fni_edit_customer_email) == false){
toastr.remove();
toastr.warning("It seems that customer email is invalid", "Invalid email");
editFNIModalTabSelectedTab(1);
$('#fni-edit-customer-email').trigger('focus');
$('#fni-edit-customer-email').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-customer-email').css("border", "");
$("#fni-edit-customer-email").trigger('blur');
}, 3000);
return;
}
}
}
if(fni_edit_policy_issue_date == ""){ // policy issue date
toastr.remove();
toastr.error("Policy Issue Date field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#issue-date').trigger('focus');
$('#issue-date').css('border-color', 'red');
setTimeout(function(){
$('#issue-date').css("border", "");
$("#issue-date").trigger('blur');
}, 3000);
return;
}
if(fni_edit_policy_start_date == ""){ // policy start date
toastr.remove();
toastr.error("Policy Start Date field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#start-date').trigger('focus');
$('#start-date').css('border-color', 'red');
setTimeout(function(){
$('#start-date').css("border", "");
$("#start-date").trigger('blur');
}, 3000);
return;
}
if(fni_edit_policy_end_date == ""){ // policy end date
toastr.remove();
toastr.error("Policy End Date field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#end-date').trigger('focus');
$('#end-date').css('border-color', 'red');
setTimeout(function(){
$('#end-date').css("border", "");
$("#end-date").trigger('blur');
}, 3000);
return;
}
if(edit_policy_required == 1){
if(fni_edit_policy_number == ""){ // policy number
toastr.remove();
toastr.error("Policy Number field cannot be empty", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#fni-edit-policy-number').trigger('focus');
$('#fni-edit-policy-number').css('border-color', 'red');
setTimeout(function(){
$('#fni-edit-policy-number').css("border", "");
$("#fni-edit-policy-number").trigger('blur');
}, 3000);
return;
}
}
if(fni_edit_insurance_provider == 0){ // insurance company/provider
toastr.remove();
toastr.error("Please specify Insurance Company/Provider", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#div-insurance-provider').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-insurance-provider').css("border", "");
$("#div-insurance-provider").trigger('blur');
}, 3000);
return;
}
if(fni_edit_insurance_type == 0){ // insurance company/provider
toastr.remove();
toastr.error("Please specify Insurance Type", "Incomplete!");
editFNIModalTabSelectedTab(2);
$('#div-insurance-type').css('border', '1px solid #dc3545');
setTimeout(function(){
$('#div-insurance-type').css("border", "");
$("#div-insurance-type").trigger('blur');
}, 3000);
return;
}
// alert("No invalid");
// return;
$.ajax({
url: "/app/finance/finance_crud.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
update_plate_cs_number: fni_edit_plate_cs_number,
update_brand: fni_edit_brand,
update_model: fni_edit_model,
update_variant: fni_edit_variant,
update_dealer: fni_edit_dealer,
update_customer_fullname: fni_edit_customer_fullname,
update_customer_mobile: fni_edit_customer_mobile,
update_customer_other_contact: fni_edit_customer_other_contact,
update_customer_email: fni_edit_customer_email,
update_customer_address: fni_edit_customer_address,
update_policy_issue_date: fni_edit_policy_issue_date,
update_policy_start_date: fni_edit_policy_start_date,
update_policy_end_date: fni_edit_policy_end_date,
update_policy_number: fni_edit_policy_number,
update_bank: fni_edit_bank,
update_insurance_provider: fni_edit_insurance_provider,
update_insurance_type: fni_edit_insurance_type,
update_sales_consultant: fni_edit_sales_consultant,
update_paid_amount: fni_edit_paid_amount,
update_lock_in_year: fni_edit_lock_in_year,
update_terms: fni_edit_terms,
update_lock_in: fni_edit_locked_in,
type: 3 // update details
},
beforeSend: function(){
},
success: function(result) {
if(result.status == 0){ // update success
toastr.remove();
toastr.success("Successfully updated");
$('#modal-finance-edit-info').modal('hide');
refreshFinanceInformationTable();
loadFinanceDetails(fin_id, fni_edit_policy_number, fni_edit_policy_issue_date);
return;
}
else if(result.status == 1){ // update failed
toastr.remove();
toastr.error("Something went wrong, please try again", "Update failed");
return;
}
else if(result.status == 2){ // duplicate found
toastr.remove();
toastr.error("It seems that the dealer selected is not designated to any company", "Dealer error / Company not found");
return;
}
else if(result.status == 3){ // duplicate found
toastr.remove();
toastr.error("Updated details matched a record", "Duplicate found");
return;
}
}
});
});PK ZZ signup.jsnu [ PK ZZ= common.jsnu [ PK ZZѣC C _6 groupfile.jsnu [ PK ZZ O O >z notification.jsnu [ PK ZZ5 ̖ scripts.phpnu [ PK ZZ# # configuration.jsnu [ PK ZZz group_member.jsnu [ PK ZZƍDq Dq lead_list.jsnu [ PK ZZdlS< S< ]h lead_profile.jsnu [ PK ZZT3j3 3
masterfile.jsnu [ PK ZZ$- signin.jsnu [ PK ZZɅ* * default_options.jsnu [ PK ZZAC@ @ role.jsnu [ PK IZ؝/t\ \ ' \/ sms_service/script_auto_sms_service.phpnu [ PK IZ5D' S industry/industry.jsnu [ PK IZE?X ?X finance_pdc/finance_pdc_list.jsnu [ PK IZsL3p p B finance_pdc/pdc_information.jsnu [ PK IZky˯} }
j functions.phpnu [ PK IZFw p p R} car_club.phpnu [ PK IZaJ aJ finance/financedashboard.jsnu [ PK IZVa a R finance/finance.jsnu [ PK IZ ͉ ͉ finance/finance_information.jsnu [ PK >