changes_v2
changes_v2
val();
var final_status = 0;
var sms_status = 0;
init = function () {
$('#gotoLetterTemplate').hide();
$('#gotoLetterTemplate').attr('href', baseUrl + 'clients/letterTemplates')
}();
function toggle_status(checkAll) {
if (checkAll.checked) {
$(".select").each(function () {
$(this).prop("checked", true);
});
} else {
$(".select").each(function () {
$(this).prop("checked", false);
});
}
}
function validateForm() {
var chks = document.getElementsByName('id[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
hasChecked = true;
break;
}
}
if (!hasChecked) {
show_hide_toastr_message('errorMessage', 'Please select atleast one contact
row to continue !');
return false;
} else {
return true;
}
}
function validateImportForm() {
$('.clientImport').find('i').removeClass('fa-save').addClass('fa-spin fa-
spinner');
if ($('#client_visibility').val() == 1 && $('#assign_business').val() == 0) {
swal({
title: '',
text: "'Client Visibility' in your account is turned on however you
have not selected 'Assign Business' from the data fields. Are you sure you wish to
proceed without assigning clients to a business?",
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: "Proceed",
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
$('#import-client-to-db-form').append('<input type="hidden"
name="import" value="1" />');
$('#import-client-to-db-form').submit();
} else {
$('.clientImport').find('i').removeClass('fa-spin fa-
spinner').addClass('fa-save');
return false;
}
});
} else {
$('#import-client-to-db-form').append('<input type="hidden" name="import"
value="1" />');
$('#import-client-to-db-form').submit();
}
}
function checkBoxChange() {
$(".select").each(function () {
if ($(this).prop("checked") == true) {
$(this).closest("tr").addClass('selected');
} else {
$('.importSelectAll').prop("checked", false);
if ($(this).closest("tr").hasClass('selected')) {
$(this).closest("tr").removeClass('selected');
}
}
});
}
function mergeClients() {
var client_id = $('#client_id').val();
var checked = false;
var clientsNo = $('.delete_checkbox_id:checked').length;
if (clientsNo >= 2) {
$('#deleteCheckedForm').append('<input type="hidden" name="merge_client"
value=1 />');
$('#deleteCheckedForm').submit();
} else {
swal({
title: '',
text: languageConversion('mergeClients'),
type: "warning",
showCancelButton: false,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('ok'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
return false;
});
}
}
function archiveClients(msg) {
var countChecked = $('.delete_checkbox_id:checked').length;
swal({
title: languageConversion('deleteConfirmTitle'),
text: msg,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('archive'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
if (parseInt(countChecked) > 0) {
$('#deleteCheckedForm').append('<input type="hidden"
name="archive_clients" value=1 />');
$('#deleteCheckedForm').submit();
} else {
show_hide_toastr_message('infoMessage',
languageConversion('checkRowMsg'));
}
}
});
}
function addTag2(val) {
var str = 'tags=' + $('#tags_2').val() + '&page=' + $('#page').val();
var msgtype = '';
$tagPage = $('#tagPage').val();
if ($tagPage == 'messaging/new_message/') {
var booking_remainder_type = $('#booking_remainder_type').val();
var msg_type = 'email';
if (booking_remainder_type)
msg_type = 'sms';
if ($('#type').val()) {
msgtype = '&type=' + $('#type').val();
}
}
if ($tagPage = "clients") {
setClientUrl('tags', $('#tags_2').val())
} else {
window.location.href = $('#baseUrl').val() + $('#tagPage').val() + '?tags='
+ $('#tags_2').val() + msgtype;
}
return;
}
function setClientUrl(param, setValue) {
var urlString = location.search.substring(1);
var urlParams = new URLSearchParams(urlString);
var hasParam = urlParams.has(param);
if (hasParam && setValue) {
urlParams.set(param, setValue);
} else if (hasParam && !setValue) {
urlParams.delete(param);
} else {
urlParams.append(param, setValue);
}
if (param == "type" && setValue == "deleted") {
window.location.href = baseUrl + 'clients?type=deleted';
} else {
var query_string = urlParams.toString();
if (query_string) {
window.location.href = baseUrl + 'clients?' + query_string;
} else {
window.location.href = baseUrl + 'clients';
}
}
}
function addTag() {
var client_id = $('#client_id').val();
var str = 'tags=' + $('#tags_3').val() + '&client_id=' + client_id;
$.ajax({
type: "POST",
url: $('#baseUrl').val() + 'clients/add_client_tags',
data: str,
success: function (data) {
$('#tags_3').importTags(data);
$('.tagsinput input').focus();
}
});
}
function addClientTag(element) {
var clientArray = element.split('_');
function addNewClientTag() {
var tag_val = $('#tags_newc').val();
$("#newclient_tags").val(tag_val);
}
function client_search() {
var searchText = $('.cliens-search-wrap input#autosuggest').val();
setClientUrl('search_client_text', searchText);
}
function categoryFieldSortable() {
$(".categoryFieldSortable").sortable({
stop: function (event, ui) {
var categoryId = $(ui.item).attr('data-id');
var order_count = 1;
$('#category_' + categoryId + ' .formElement').each(function () {
$(this).find("input[name='noteFieldOrder[]']").val(order_count)
order_count++;
});
}
});
}
$(document).ready(function () {
$('.client-edit-mode').show();
if ($('.userCategoryBlocks').hasClass('ui-sortable-disabled')) {
$(".userCategoryBlocks").sortable("enable");
}
$(".userCategoryBlocks").sortable({
items: ".portable",
scroll: true,
scrollSensitivity: 100,
connectWith: ".userCategoryBlocks",
placeholder: 'category_block_placeholder',
stop: function (event, ui) {
var order_count = 0;
$('.portable').each(function () {
var categoryId = $(this).attr('data-categoryID');
$.post($('#baseUrl').val() + 'clients/order_category/', {
'categoryId': categoryId,
'order_count': order_count,
'from': $('#from').val()
}, function (data) { });
order_count++;
});
},
cancel: ".disabled"
});
if ($('.categoryFieldNSortable').hasClass('ui-sortable-disabled')) {
$(".categoryFieldNSortable").sortable("enable");
}
$(".categoryFieldNSortable").sortable({
items: ".catFields",
connectWith: ".categoryFieldNSortable",
stop: function (event, ui) {
var categoryId = $(ui.item).attr('data-id');
console.log('categoryId' + categoryId);
var order = 1;
$('#category_' + categoryId).find('.catFields').each(function
() {
var field_tag = $(this).attr('data-catval')
console.log('fieldtag' + field_tag);
$.post($('#baseUrl').val() +
'clients/order_category_fields/', {
'categoryId': categoryId,
'order_count': order,
'field_tag': field_tag,
'from': $('#from').val()
});
order++;
});
}
});
}
});
//fix for control is jumping to top/bottom in safari when selecting an item
from dropdown
$('#clientAddForm select').on('select2:close', function (e) {
$(this).parent().find('select').focus();
});
$('.insert_field_val_tnmce').click(function (e) {
e.preventDefault();
if ($('.clientFieldTextArea').length) {
$('.clientFieldTextArea').each(function () {
if (!$(this).val().trim()) {
$(this).parent().find('.note-placeholder').show();
}
});
}
//copy form url
$('body').on('click', '.copyFormUrl', function (e) {
var formId = $(this).attr('data-formid');
var $temp = $("<input>");
var $this = $(this);
$("body").append($temp);
$temp.val($('#formUrl_' + formId).html()).select();
document.execCommand("copy");
$temp.remove();
$this.attr('data-original-title', 'Copied!');
$this.find('i').removeClass('fa-copy').addClass('fa-check');
$this.removeClass('copyFormUrl');
setTimeout(function () {
$this.find('i').removeClass('fa-check').addClass('fa-copy');
$this.addClass('copyFormUrl');
$this.attr('data-original-title', 'Copy Form Url');
}, 3000
);
});
//assign client to form
$('#assignForm').on('click', function (e) {
var clientId = $('#client_id').val();
var clientFormId = $('#clientFormId').val();
var formOwnerId = $('#clientFormId option:selected').attr('data-
formownerid');
if (clientFormId) {
$('.loader').show();
$.ajax({
type: "POST",
url: baseUrl + 'client_intake_form/assignClientForm',
data: {
clientId: clientId,
clientFormId: clientFormId,
formOwnerId: formOwnerId
},
success: function (data) {
$('#clientIntakeForms').trigger('click');
}
});
} else {
swal("", 'Please select form to continue', "error");
}
});
//datepicker for client field if its type is datepicker
$('.datepickerField').each(function () {
$(".datepickerField").datepicker({
show: true,
format: 'dd/mm/yy',
language: 'en',
changeMonth: true,
changeYear: true,
autoclose: true,
orientation: "bottom auto",
yearRange: '1900:' + (new Date().getFullYear() + 25),
});
});
categoryFieldSortable();
$(".categoryFieldSortable").disableSelection();
$('.tags_3').tagsInput({
autocomplete_url: $('#baseUrl').val() + 'clients/tagdata/' + $
('#noSystemTag').val(),
autocomplete: { selectFirst: true, width: '100px', autoFill: true },
'height': 'auto',
'onAddTag': function () {
addClientTag($(this).attr('id'));
},
'onRemoveTag': function () {
addClientTag($(this).attr('id'));
}
});
/* client details page updates */
$("#client_tabs").on('change', function () {
$("#client_sales_btn").addClass('d-none');
$('.subnav-container').hide();
$("#export_apnt_btn").addClass('d-none');
$('.client').hide();
$('.' + $(this).val() + 'Box').show();
$('.ae-select-content').html($(this).find('a').html());
if ($(this).val() == 'ClientDetails') {
}
if ($(this).val() == 'ClientNotes') {
}
if ($(this).val() == 'ClientSales') {
$('.loader').show();
$.post($('#baseUrl').val() + 'business/ajaxClientSales', {
client_id: client_id
}, function (data) {
if ($('#printInvoice').val() == 'yes') {
pdf_path = 'pdf/download_pdf/' + client_id + '/' + $
('#paymentID').val();
var path = baseUrl + pdf_path;
window.parent.location = path;
}
$('.ClientSalesBox').html(data);
$("#client_sales_btn").removeClass('d-none');
});
$('.loader').delay(100).fadeOut(1000);
}
if ($(this).val() == 'ClientAppointments') {
$(this).addClass('activePac');
$('.loader').show();
$.post($('#baseUrl').val() + 'booking/ajaxClientAppointment/1/' +
client_id, {
client_id: client_id
}, function (data) {
$('.ClientAppointmentsBox').removeClass('formBox').html(data);
$("#export_apnt_btn").removeClass('d-none');
});
$('.loader').delay(100).fadeOut(1000);
}
});
$('.uploadedList select').change(function () {
if ($('#client_visibility').val() == 1) {
$('#assign_business').val(0);
$('.uploadedList select').each(function () {
thisVal = $(this).val();
if (thisVal == 'assign_business') {
$('#assign_business').val(1);
}
});
}
});
$('select#note_type').select2({
width: 'auto'
});
// client list
$('.exportClient').click(function () {
totalClients = $('#totalClients').val();
if (totalClients > 500) {
$("#exportExcelPopup").trigger('click');
} else {
window.location.href = baseUrl + 'clients/export_client_new?type=' + $
('#clientType').val() + 'tags=' + $('#clientTags').val();
}
});
// end client list
$('#clientDetailsSave').click(function () {
if (!$("#clientAddForm").valid()) {
return;
}
$('#clientDetailsSave').find('i').removeClass('fa-save').addClass('fa-
spinner fa-spin');
$('body').css('pointer-events', 'none');
var allTextareas = null;
$('.clientFieldTextArea').each(function(){
var thisId = $(this).attr('id');
var thisName = $(this).attr('name');
var thisValue = tinymce.get(thisId) ?
tinymce.get(thisId).getContent() : '';
if (thisValue) {
tinymce.get(thisId).save();
}
allTextareas += '&' + thisName + '=' + thisValue;
});
$.post($('#clientAddForm').prop('action'), $('#clientAddForm').serialize()
+allTextareas, function (data) {
$('#clientDetailsSave').find('i').removeClass('fa-spinner fa-
spin').addClass('fa-save');
$('body').css('pointer-events', 'initial');
if (data && data.data) {
if (data.data.err_msg) {
toastr.error(data.data.err_msg,
languageConversion('been_problem'), window.overrides);
location.reload();
} else if (data.data.suc_msg) {
toastr.success(data.data.suc_msg,
languageConversion('success'), window.overrides);
location.reload();
}
if (data.data.redirect_url) {
window.location.href = data.data.redirect_url;
location.reload();
}
}
});
});
/* User Add */
$('.addClients').click(function () {
$.post(baseUrl + 'clients/checkPlanAdduser',
function (data) {
if (data == 1) {
$("#clientAdd").trigger('click');
} else {
parent.document.location.href = baseUrl + 'clients/add';
}
});
});
/*search Client*/
$('.cliens-search-wrap .btn').click(function () {
client_search();
});
});
// Country vs state
country_id = $('#country_id').val();
if (country_id) {
$id = country_id;
$.post(baseUrl + "my_profile/ajax_state/", {
country_id: $id,
state_id: $('#ajax_state_id').val(),
actualCountryId: $('#actualCountryId').val()
}, function (data) {
$("#ajax_state").html(data);
if ($('#state_id option').length > 0) {
$('#state_id').select2({ width: '95%' });
}
});
}
$("#country_id").change(function () {
if (!$('#mobile').val()) {
let mobile_code = $(this).find(':selected').data('mobile_code');
if (mobile_code) {
var mobile_no = $("#mobile").val();
window.iti.setNumber("+" + mobile_code);
$("#mobile").val(mobile_no);
} else {
var mobile_code_data = $("#mobile_code").data("mobile_code");
if (mobile_code_data) {
window.iti.setCountry(mobile_code_data);
} else {
$.get('https://ipinfo.io', function () {
}, "jsonp").always(function (resp) {
var countryCode = (resp && resp.country) ? resp.country :
"";
window.iti.setCountry(countryCode);
});
}
}
}
$id = parseInt($(this).val());
if ($id) {
$.post(baseUrl + "my_profile/ajax_state/", {
country_id: $id,
state_id: $('#ajax_state_id').val(),
actualCountryId: $('#actualCountryId').val()
}, function (data) {
$("#ajax_state").html(data);
if ($('#state_id option').length > 0) {
$('#state_id').select2({ width: '95%' });
}
});
}
});
});
function getClientIntakeForms() {
var clientId = $('#client_id').val();
var bookingId = $('#formBookingId').val();
$('.loader').show();
$.ajax({
type: "POST",
url: baseUrl + 'client_intake_form/ajaxClientIntakeForms/1/',
data: {
clientId: clientId,
bookingId: bookingId
},
success: function (data) {
$('.loader').hide();
$('.ClientAppointmentsBox').addClass('formBox').html(data).show();
if ($("#sms_msg_status").length && ($("#sms_msg_status").val() ==
1)) {
setInterval(updateSmsStatus, 2000);
}
}
});
}
$('#addContactTab li').click(function () {
$('#addContactTab li').removeClass('active');
$(this).addClass('active');
if ($(this).attr('id') == 'billingInvoices') {
$('.clientInvoiceFilter').removeClass('d-none').addClass('d-block');
$('.invoiceExport').removeClass('d-none');
getBillingInvoicesFilter();
}
if ($(this).attr('id') == 'billingDetails') {
$('.invoiceExport').addClass('d-none');
$('.billingInvoiceBox').hide();
$('.ClientDetailsBox').show();
}
});
$('.billingInvoiceFilter').on('change', function () {
getBillingInvoicesFilter();
});
$('.billingInvoiceFilterWrap .btn').click(function (e) {
e.preventDefault();
billingInvoiceSearch();
});
function getBillingInvoicesFilter(value = null) {
if (value) {
$('#billingInvoiceFilterWrap
input.billingInvoiceautosuggest').val(value);
}
var query_string = '?type=' + $('#billingInvoiceType').val() +
'&search_product_text=' + $('.billingInvoiceautosuggest').val() +
'&invoiceFilterType=' + $('#invoiceFilterType').val() + '&sale_business_id=' + $
('#sale_business_id').val() + '&sale_venu_id=' + $('#sale_venu_id').val() +
'&date_range=' + $('#billing_invoice_date_range').val();
var billingContactId = $('.billingContactId').val();
var baseUrl = $('#baseUrl').val();
$('.loader').show();
$.post(baseUrl + 'clients/invoices' + query_string, {
billingContactId: billingContactId,
fromBillingContact: 'true',
paging_data: 1
}, function (data) {
$('.loader').hide();
$('.billingInvoiceBox').html(data).show();
$('.ClientDetailsBox').hide();
renderDateRangePicker('billingInvoiceRange');
})
var url = $("#billingInvoiceExport").attr("href");
url += '&type=' + $('#billingInvoiceType').val() + '&search_product_text='
+ $('.billingInvoiceautosuggest').val() + '&invoiceFilterType=' + $
('#invoiceFilterType').val() + '&sale_business_id=' + $('#sale_business_id').val()
+ '&sale_venu_id=' + $('#sale_venu_id').val() + '&date_range=' + $
('#billing_invoice_date_range').val();
$("#billingInvoiceExport").attr("href", url)
}
$('#billingInvoiceFilterWrap
input.billingInvoiceautosuggest').keypress(function (e) {
if (e.which == 13) {
getBillingInvoicesFilter();
}
});
$('#billingInvoiceFilterWrap .btn').click(function () {
getBillingInvoicesFilter();
});
$(".billingInvoiceautosuggest").autocomplete({
source: function (request, response) {
var searchText = $(".billingInvoiceautosuggest").val();
var ajaxUrl = $('#billingInvoiceAutosuggestUrl').val();
var clientId = $('#client_id').val();
var invoiceFilterType = $('#invoiceFilterType').val();
$.ajax({
url: ajaxUrl,
data: {
searchtext: searchText.replace(/^0+/, ''),
invoiceFilterType: invoiceFilterType,
clientId: clientId
},
dataType: "json",
type: "post",
success: function (data) {
response($.map(data, function (obj) {
return {
label: obj.label,
value: obj.displayText,
};
}));
}
});
},
select: function (event, ui) {
event.preventDefault();
getBillingInvoicesFilter(ui.item.value);
},
});
//Function to get client messages
function getClientSentMessages() {
var clientId = $('#client_id').val();
var deliveryStatus = ($('#deliveryStatusDropdown').length && $
('#deliveryStatusDropdown').val()) ? $('#deliveryStatusDropdown').val() : '';
var messageType = ($('#messageTypeDropdown').length && $
('#messageTypeDropdown').val()) ? $('#messageTypeDropdown').val() : '';
var date_range = ($('#message_date_range').length && $
('#message_date_range').val()) ? $('#message_date_range').val() : '';
var messageStatus = ($('#messageStatusDropdown').length && $
('#messageStatusDropdown').val()) ? $('#messageStatusDropdown').val() : '';
$('.loader').show();
$.ajax({
type: "POST",
url: baseUrl + 'clients/ajaxClientSentMessages/1/',
data: {
clientId: clientId,
deliveryStatus: deliveryStatus,
messageType: messageType,
date_range: date_range,
messageStatus: messageStatus,
},
success: function (data) {
$('.loader').hide();
$
('.ClientAppointmentsBox').removeClass('formBox').html(data).show();
if ($("#sms_msg_status").length && ($("#sms_msg_status").val() ==
1)) {
sms_status = setInterval(updateSmsStatus, 2000);
}
renderDateRangePicker('messageRange');
}
});
}
/* Client Details */
$('#activeInactive').change(function () {
$.post($('#baseUrl').val() + "clients/activeInactive/?activate=" + $
(this).val(), function (data) {
if (data) {
var msg = client_name + data;
if (data == 'Archived')
msg = msg + "\n" + languageConversion('clientReinstate')
alert(msg);
}
});
});
$('#tags_3').tagsInput({
autocomplete_url: $('#baseUrl').val() + 'clients/tagdata/' + $
('#noSystemTag').val() + '?client_id=' + $('#client_id').val(),
autocomplete: {
selectFirst: true,
width: '100px',
autoFill: true
},
'onAddTag': function () {
addTag();
},
'onRemoveTag': function () {
addTag();
}
});
$('#tags_newc').tagsInput({
autocomplete_url: $('#baseUrl').val() + 'clients/tagdata/' + $
('#noSystemTag').val(),
autocomplete: {
selectFirst: true,
width: '100px',
autoFill: true
},
'onAddTag': function () {
addNewClientTag();
},
'onRemoveTag': function () {
addNewClientTag();
}
});
/* End Client Details */
/* Note section */
if (!$("#date_range").val()) {
$("#getstartType").val("All");
}
$('#reportrange').daterangepicker({
startDate: getFromToDate(),
endDate: getFromToDate('to'),
showDropdowns: true,
showWeekNumbers: true,
timePicker: false,
timePickerIncrement: 1,
timePicker12Hour: true,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract('days', 1), moment().subtract('days',
1)],
'Tomorrow': [moment().add('days', 1), moment().add('days', 1)],
'Last 7 Days': [moment().subtract('days', 6), moment()],
'Last 30 Days': [moment().subtract('days', 29), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract('month', 1).startOf('month'),
moment().subtract('month', 1).endOf('month')],
'All': [moment().subtract('days', $('#allDays').val()), moment()]
},
opens: 'right',
buttonClasses: ['btn btn-default'],
applyClass: 'btn-small btn-primary',
cancelClass: 'btn-small',
format: 'DD/MM/YYYY',
separator: ' to ',
locale: {
applyLabel: 'Submit',
fromLabel: 'From',
toLabel: 'To',
customRangeLabel: 'Custom Range',
daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
firstDay: 1
}
},
function (start, end) {
var startDate = start.format('MMMM D, YYYY');
var endDate = end.format('MMMM D, YYYY');
var allStart = moment().subtract('days', $
('#allDays').val()).format('MMMM D, YYYY');
var allEnd = moment().format('MMMM D, YYYY');
var dateValue = '';
if (startDate == allStart && endDate == allEnd) {
dateValue = 'All';
} else {
dateValue = startDate + ' - ' + endDate;
}
$('#reportrange span').html(dateValue);
$("#date_range").val(dateValue);
if ($("#clientsPage").val("invoices")) {
$("#clientSearchForm").submit();
} else {
loadClientNotes();
}
if ($("#note_page").val()) {
loadClientNotes();
}
});
if ($("#date_range").val()) {
$('#reportrange span').html($("#date_range").val());
} else {
$('#reportrange span').html('All');
$("#date_range").val('All');
}
if ($("#appointment_date_range").val()) {
$('#appointmentRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#appointmentRange span').html('All');
$("#appointment_date_range").val('all');
}
if ($("#invoice_date_range").val()) {
$('#invoiceRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#invoiceRange span').html('All');
$("#invoice_date_range").val('all');
}
if ($("#payment_date_range").val()) {
$('#paymentRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#paymentRange span').html('All');
$("#payment_date_range").val('all');
}
if ($("#sales_date_range").val()) {
$('#salesRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#salesRange span').html('All');
$("#sales_date_range").val('all');
}
if ($("#message_date_range").val()) {
$('#messageRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#messageRange span').html('All');
$("#message_date_range").val('all');
}
if ($("#billing_invoice_date_range").val()) {
$('#billingInvoiceRange span').html($("#date_range").val());
} else {
//Set the initial state of the picker label
$('#billingInvoiceRange span').html('All');
$("#billing_invoice_date_range").val('all');
}
//client Appointmet download
$("#export_apnt_btn").on('click', function (e) {
e.preventDefault();
var url = $("#export_apnt_btn").attr("href");
window.location.href = url;
});
//dropzone
$(".note-uploader").dropzone({
paramName: 'file',
url: $('#baseUrl').val() + 'clients/upload_item/' + client_id + '/1',
clickable: true,
enqueueForUpload: false,
maxFilesize: 20,
addRemoveLinks: false,
dictDefaultMessage: '',
init: function () {
this.on("sending", function (file, xhr, formData) {
formData.append("note_type", $("#note_type").val());
});
},
accept: function (file, done) {
var re = /(?:\.([^.]+))?$/;
var ext = re.exec(file.name)[1];
ext = ext.toUpperCase();
if (ext == "JPEG" || ext == "BMP" || ext == "GIF" || ext == "JPG" ||
ext == "PNG" || ext == "JPE" ||
ext == "DOC" || ext == "DOCX" || ext == "PPT" || ext == "PPS" ||
ext == "PPTX" || ext == "XLS" ||
ext == "XLSX" || ext == "TXT" || ext == "MSG" || ext == "CSV" ||
ext == "PDF" || ext == "XML") {
done();
} else {
$(".dz-preview").remove();
$(".dz-processing").remove();
done("Disallowed File Format.");
alert("Disallowed File Format.");
return false;
}
},
success: function (data, responseText) {
$('#note-attachment-error').hide();
if (responseText != undefined && responseText != '' && responseText !=
'failure' && responseText != 'upload failed') {
$("#img_error").html("").hide();
$(".dz-preview").remove();
$("#img_error").html("").hide();
var note_type = $("#note_type").val();
$('#' + note_type + '_listAttachment').append(responseText);
} else if (responseText == 'failure') {
$(".dz-preview").remove();
alert('Invalid File Format');
} else if (responseText == 'upload failed') {
$(".dz-preview").remove();
$(".dz-processing").remove();
alert('Unable to upload the file.');
}
}
});
$('#uploding').click(function () {
$('#uploader').trigger('click');
});
$('#listAttachment').on('click', '.deleteAttachment', function () {
clnt_id = client_id;
var att_id = $(this).attr('id').split('_')[1];
$this = $(this);
swal({
title: languageConversion('deleteAttachment'),
text: languageConversion('deleteConfirmation'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.post($('#baseUrl').val() + 'clients/ajax_removenotes/', {
id: att_id,
client_id: clnt_id
}, function (data) {
$this.parent().remove();
});
}
});
});
$('#AddNoteAttachment').click(function () {
var note_type = $('#note_type').val();
if (!note_type || (note_type == 'text' || note_type == 'payment')) {
var clientNote = $('#client_note').val();
var draft_id = $('#draft_id').val();
var attachmentId = $('input.attachmentId').serialize();
if (!clientNote) {
show_hide_toastr_message('errorMessage',
languageConversion('addNote'));
} else {
$('.buttonDisable').attr('disabled', true);
$.post($('#baseUrl').val() + "clients/add_noteSubmit/", {
note: clientNote,
client_id: client_id,
draft_id: draft_id,
'attachmentId': attachmentId
}, function (data) {
$('.notes-shadow:first').before(data);
$('.notes-shadow:first').slideDown(500);
$('#draft_id').val('');
$('#ClientNote').val('');
$('#client_note').val('');
$('#listAttachment').html('');
$('.note-editable').html('');
$('.categoryTextArea').val('');
$('.noNoteFound').hide();
$('.buttonDisable').attr('disabled', false);
});
}
} else {
//validation and custom note submission
$('.buttonDisable').attr('disabled', true);
$.ajax({
type: 'POST',
url: $('#baseUrl').val() + "clients/categoryNoteSubmit/",
data: $('#add-note').find('input,select,textarea').serialize(),
success: function (data) {
$('.notes-shadow:first').before(data);
$('.notes-shadow:first').slideDown(500);
$('#draft_id').val('');
$('#ClientNote').val('');
$('#note').val('');
$('.categoryTextArea').val('');
$('#listAttachment').html('');
$('.note-editable').html('');
$('.noNoteFound').hide();
$('.buttonDisable').attr('disabled', false);
}
});
}
});
$('.letterList tr').click(function () {
var tempId = $(this).find('h2').attr('data-temId');
linkUrl = $('#clickableUrl').val();
window.location.href = linkUrl + '?temp_id=' + tempId;
});
$('#letter_template').change(function () {
var temp_id = $('#letter_template').val();
$.ajax({
type: "POST",
url: baseUrl + 'clients/getLetterTemplate',
data: {
tempId: temp_id
},
success: function (data) {
try {
// Process the response data and update the relevant element
$('#letterTemp').html(data);
// Remove the existing TinyMCE instance
tinymce.remove('#letter_message');
// Reinitialize TinyMCE on the updated textarea element
tinymce.init({
selector: '#letter_message',
branding: false,
menubar: false,
paste_as_text: true,
plugins: 'advlist autolink lists link image charmap preview
anchor table searchreplace autolink directionality visualblocks visualchars media
codesample charmap pagebreak nonbreaking anchor insertdatetime advlist wordcount
charmap emoticons autosave',
toolbar: 'undo redo print spellcheckdialog formatpainter |
blocks fontfamily fontsize| formatselect | bold italic underline forecolor
backcolor| table | link | alignleft aligncenter alignright alignjustify | outdent
indent | removeformat',
height: '500px',
setup: function (editor) {
editor.on('keyup', function () {
$("#letter-message-error").hide();
});
}
});
$("#filetype").select2({
width: '95%'
});
} catch (error) {
console.error(error); // Log any errors that occur during
processing
}
},
error: function (xhr, status, error) {
console.log(error); // Log the error for debugging purposes
}
});
});
$('.cancelLetterTemplate ').click(function () {
linkUrl = $('#clickableUrl').val();
window.location.href = linkUrl;
});
$('.letterSubmit').click(function (e) {
var content = tinymce.get("letter_message") ?
tinymce.get("letter_message").getContent() : '';
if (!content.trim()) {
swal("", 'Please add letter content', "error");
e.preventDefault();
} else {
$("#addTemplate").validate();
}
});
$("body").on('click', '.letterMergeVariable', function () {
$(this).parent().find(".custom-popover").toggle('fast');
});
$(document).on("click", "table.variables_table a.insert_field_val", function
(e) {
let el = e.target;
if (el.tagName !== "A") {
el = $(el).closest('a')[0];
}
e.preventDefault();
// $("#letter_message").summernote('insertText', "{"+$
(el).data('field_val')+"} ");
});
$('#note_template').change(function () {
$("#note-template-error").hide();
$('.loader').show();
$('body').css('pointer-events', 'none');
$.post(baseUrl + "clients/getNoteCategory/", {
category_id: $(this).val(),
note_id: $('#note_id').val(),
client_id: $('#client_id').val()
}, function (data) {
if (data) {
$('#NoteFormCategory').show().html(data);
if ($('#NoteFormCategory').find('.noteSelectBox')) {
$('.noteSelectBox').select2();
}
$('.datepickerField').each(function () {
var format = $(this).next('.dateFormatHidden').val();
$(this).datepicker({
show: true,
dateFormat: 'dd/mm/yy',
language: 'en',
changeMonth: true,
changeYear: true,
autoclose: true,
orientation: "bottom auto",
yearRange: '1900:' + (new Date().getFullYear() + 25),
}).on('changeDate', function (e) {
$(this).datepicker('hide');
});
});
if ($(".signature").length) {
var $sigdiv = $(".signature").jSignature();
}
}
$('body').css('pointer-events', 'initial');
$('.loader').hide();
});
});
/*
categoryTextArea
* */
$("body").on("change", ".noteSelectBox, .noteOnChangeInputs, .episode_type",
function (e) {
console.log('am out');
$('.noteSelectBox, .noteOnChangeInputs , .episode_type').each(function () {
if ($(this).val()) {
console.log('am here');
$('#template_note_changed').val(1);
}
});
});
$("body").on("keyup", "#NoteFormCategory .note-editable,
#NoteFormCategory .noteInputs", function (e) {
$('#template_note_changed').val(1);
});
editNote = $('#editNote').val();
editLetter = $('#editLetter').val();
if (editNote == 1 || editLetter == 1) {
window.addEventListener('load',
function () {
$('#ClientNotesNew').trigger('click');
$('#read_notes').trigger('click');
}, false);
}
clientAppts = $('#clientAppts').val();
if (clientAppts) {
window.addEventListener('load',
function () {
$('#ClientAppointments').trigger('click');
}, false);
}
clientSales = $('#clientSales').val();
if (clientSales) {
window.addEventListener('load',
function () {
$('.clientSales').trigger('click');
}, false);
}
ClientInvoices = $('#clientInvoice').val();
if (ClientInvoices) {
window.addEventListener('load',
function () {
$('#ClientInvoices').trigger('click');
}, false);
}
clientMsg = $('#fromClientDetailsMsg').val();
if (clientMsg) {
window.addEventListener('load',
function () {
$('#clientSentMessages').trigger('click');
}, false);
}
// Delete Notes
$('.DeleteNotes').on('click', function () {
var noteId = $(this).attr('id').split('_')[1];
swal({
title: languageConversion('swalDeleteNoteTitle'),
text: languageConversion('swalDeleteNoteText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.post($('#baseUrl').val() + "clients/delete_note/" + $
('#client_id').val() + '/' + noteId, {
note: noteId
}, function (data) {
readNoteRedirect();
});
} else {
return 0;
}
});
});
/* End Note Section */
/* Client tag page */
$('#tags_1').tagsInput({
width: 'auto',
height: '200px'
});
/* Client List */
$(function () {
$('#tags_2').tagsInput({
autocomplete_url: $('#baseUrl').val() + 'clients/tagdata/' + $
('#noSystemTag').val(),
autocomplete: {
selectFirst: true,
width: '100px',
autoFill: true
},
'defaultText': 'Filter by tag',
'onAddTag': function () {
addTag2();
},
'onRemoveTag': function () {
addTag2();
}
});
});
/* Field Management */
$(".sortableBlock").sortable({
stop: function (event, ui) {
var order_count = 0;
$('.catBlock').each(function () {
var id = $(this).attr('id');
var categoryId = id.split('_')[1];
$.post($('#baseUrl').val() + 'clients/order_category/', {
'categoryId': categoryId,
'order_count': order_count,
'from': $('#from').val()
}, function (data) { });
order_count++;
});
},
cancel: ".disabled"
});
$("#sortable").disableSelection();
$('a.disable').click(function (event) {
event.stopPropagation();
});
$('.catContent').hide();
function removeFields(node) {
$(node).remove();
}
$this.parent().parent().parent().parent().slideUp('slow').hide();
});
}
});
});
$('.addCatBtn').click(function () {
var $_this = $(this);
$.post($('#baseUrl').val() + 'clients/add_field_category/', {
category_title: $('#categoryTitle').val(),
'from': $('#from').val()
}, function (data) {
if (data != 'error') {
$('.sortableBlock').prepend(data);
var curCatId = $('#sortable').find('.catBlock').first().attr('id');
$('#' + curCatId).find('.AddFields').trigger('click');
categoryFieldSortable();
$('#categoryTitle').val('');
show_hide_toastr_message('successMessage',
languageConversion('categoryCreateSuccessMsg'));
} else {
swal({
title: languageConversion('error'),
text: languageConversion('categoryTitleValidationMsg'),
type: "warning",
showCancelButton: false,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('ok'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
return false;
}
});
}
});
});
if (!fieldName) {
error = true;
errorTitle = languageConversion('categoryFieldValidationMsg');
}
if (error || !fieldName) {
$('#cat_' + categoryId).addClass('error');
swal({
title: '',
text: errorTitle,
type: "warning",
showCancelButton: false,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('ok'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
return false;
}
});
$('#cat_' + categoryId + ' a').removeClass('disable');
$('#cat_' + categoryId + ' button').removeAttr('disabled');
return false;
}
$('#cat_' + categoryId).removeClass('error');
_this = $(this);
$.ajax({
url: $('#baseUrl').val() + 'clients/addFields',
type: "post",
data: values + "&from=" + $('#from').val(),
success: function () {
show_hide_toastr_message('successMessage',
languageConversion('customFieldCreateSuccessMsg'));
setTimeout(function () {
window.location.reload();
}, 2000);
},
error: function () { }
});
});
});
$('#deleteClient').click(function () {
swal({
html: true,
title: $('#deleteTittle').val(),
text: $('#deletemsg').val(),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('deleteConfirmButtonText'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
if (isConfirm) {
window.location.href = $('#deleteurl').val();
} else {
return 0;
}
}
});
});
$(".note_user").on('change', function () {
var user_id = $(this).val();
loadUserAvatar(user_id);
});
if ($("#note_edit").val() == 1) {
loadUserAvatar($("#user_id").val());
}
$('.notedatepicker').datetimepicker({
show: true,
format: 'dd/MM/yyyy',
language: 'en',
pickTime: true,
showButtonPanel: true,
autoclose: true
});
$(".notedatepicker").on('click', function () {
var id = $(this).attr('id');
$('#' + id).datetimepicker('show');
});
$(".new-notes-tab-content .nav-link").on("click", function () {
// Check if the clicked tab is the "Letter" tab
if ($(this).attr("id") === "letter-note") {
$('#savesend').removeClass('d-none');
} else {
$('#savesend').addClass('d-none');
}
});
$('.client_tabs').on('click', function () {
$("#editNote").val(0);
var id = $(this).attr('id');
var isReadNotesTabClicked = $('#read_notes_li').hasClass('active');
if (isReadNotesTabClicked) {
$('.blue-bg').hide();
}
if (id == 'ClientNotesNew') {
$('.edit_single_episode').hide();
$(".notes-client-name").show();
$("#sub-chlidnav").hide();
$("#template_tags").val('');
$('#tags_5').val('');
$(".delete_note").hide();
$(".save_note").show();
$(".right-side-tabs").hide();
if ($("#client_id").val()) {
loadEpisodes($("#client_id").val());
loadUserAvatar($("#user_id").val());
}
} else {
if (id == 'ClientDetails') {
$('.blue-bg').show();
}
$(".notes-client-name").hide();
$("#sub-chlidnav").show();
}
});
$('.notes-add-new').on('click', function () {
$.post($('#baseUrl').val() + 'clients/addEpisode', {
}, function (data) {
$("#addEpisode").modal('show');
$("#addEpisode").html(data);
});
});
$('.discharge-btn').on('click', function () {
$.post($('#baseUrl').val() + 'clients/addDischarge?discharge_id=' + $
("#discharge_id").val(), {
}, function (data) {
$("#addDischarge").modal('show');
$("#addDischarge").html(data);
});
});
$('#read_notes_li').click(function () {
$(".notesNavLink").first().trigger('click');
});
$('#add_new_note').click(function () {
clickedEventTriggered = false;
$('#text_note_changed').val(0);
});
$.ajax({
type: 'POST',
url: $('#baseUrl').val() + "clients/categoryNoteSubmit/",
data: $('#save_template').serialize() + '&client_id=' + client_id +
'&save_type=' + save_type + '&discharge=' + discharge_id + '&draft_id=' + draft_id
+ '&consent=' + consent_check,
success: function (data) {
$('.buttonDisable').attr('disabled', false);
if (notesNavLinkClick) {
if ($("#template_draft_id").val() <= 0 || $
("#template_draft_id").val() === '') {
var noteObj = JSON.parse(data);
$("#template_draft_id").val(noteObj.note_id)
}
}
if (!notesNavLinkClick) {
show_hide_toastr_message('successMessage',
languageConversion('notesSavedSuccessfully'));
readNoteRedirect();
}
}
});
$('.buttonDisable').attr('disabled', true);
var bodyChartLength = $('#bodychart_listBodyChart .attach-file').length
if (!bodyChartLength) {
$('#body-chart-error').show();
$('.buttonDisable').attr('disabled', false);
return false;
}
$.ajax({
type: 'POST',
url: $('#baseUrl').val() + "clients/saveBodyChartNote/",
data: $('#save_bodychart').serialize() + '&client_id=' + client_id
+ '&save_type=' + save_type + '&discharge=' + discharge_id + '&draft_id=' +
draft_id,
success: function (data) {
$('#body_chart_note_draft_id').val(data);
if (!notesNavLinkClick) {
show_hide_toastr_message('successMessage',
languageConversion('notesSavedSuccessfully'));
readNoteRedirect();
}
$('.buttonDisable').attr('disabled', false);
}
});
}
});
$('.allNoteTags').tagsInput({
'onAddTag': function () {
addNoteTag($(this).attr('id'));
},
'onRemoveTag': function () {
addNoteTag($(this).attr('id'));
}
})
$(".main-notes-tab").on('click', function () {
if ($(this).children('a').attr('href') == '#read-notes') {
$('#current_note_view').val('read_notes_view');
$('.blue-bg').hide();
$(".right-side-tabs").show();
$(".read-subs").addClass('fade');
$(".read-nav-tabs").removeClass('active');
$("#all-nav-tab").addClass('active');
$("#read_note_type").val('all');
$(".export_note").hide();
$('.notesAllSelect').hide();
$('.selectAllNotes').prop("checked", false);
$(".noteAlert").addClass('readNoteAlert');
loadClientNotes();
} else {
$('#current_note_view').val('new_notes_view');
var displayDate = $("#today_date").val();
$('.displayDate').html(displayDate);
$('.default-datepicker-input').val(displayDate);
$('.notedatepicker').datetimepicker('setDate', displayDate);
$('.blue-bg').show();
$('.edit_single_episode').hide();
$(".delete_note").hide();
$(".export_note").hide();
$(".save_note").show();
$(".right-side-tabs").hide();
$('.notesAllSelect').hide();
$('.selectAllNotes').prop("checked", false);
$(".noteAlert").removeClass('readNoteAlert');
}
});
// Filter click
$(".open-filter").on('click', function () {
var effect = 'slide';
var options = {
direction: 'left'
};
var duration = 1;
$('.filter-widget').toggle(effect, options, duration, function () {
$('.new-filter-wrap').toggleClass('slider-open');
$(this).toggleClass('opened');
$('.filter-widget').css('visibility', 'visible');
if ($('.new-filter-wrap').hasClass('slider-open')) {
$('.open-filter').find('i').removeClass('fa-angle-right');
$('.open-filter').find('i').addClass('fa-angle-left');
setCookie('noteFilterOpened', 'yes', 1);
} else {
setCookie('noteFilterOpened', 'no', 1);
$('.open-filter').find('i').removeClass('fa-angle-left');
$('.open-filter').find('i').addClass('fa-angle-right');
}
});
});
$(".read-nav-tabs").on('click', function () {
$(".read-subs").addClass('fade');
var selection = $(this).children('a').attr('href').replace('#', '');
$("#read_note_type").val(selection);
$('.blue-bg').hide();
loadClientNotes();
$("#navtab-ul").removeClass('in');
$("#navtab-ul").addClass('collapse');
});
function showHideDelet() {
let lockedFalg = false;
$("#read_notes_div input.delete_notes_id:checkbox:checked").each(function
(e) {
if ($(this).data('note_final_status') === 1) {
lockedFalg = true;
return false;
}
});
if (lockedFalg) {
$('.delete_note').hide();
} else {
$('.delete_note').show();
}
}
$('.user-checkbox').on('click', function () {
totalCheckbox = $('.user-checkbox').length;
checkedLength = $('.user-checkbox:checked').length;
if (totalCheckbox > checkedLength) {
$('input#user-checkobx-chekall').removeAttr('checked');
} else if (totalCheckbox == checkedLength) {
$('input#user-checkobx-chekall').prop('checked', 'checked');
}
if (checkedLength == 0) {
$('input.first-checkbox').prop('checked', 'checked');
}
loadClientNotes();
});
$('#user-checkobx-chekall').click(function () {
if ($(this).is(':checked')) {
$('input.user-checkbox').prop('checked', 'checked');
} else {
$('#user-checkobx-chekall').removeAttr('checked');
$('input.first-checkbox').prop('checked', 'checked');
}
loadClientNotes();
});
function deleteNotesAndEpisodes() {
$("#deleteNotesForm > input.note-id").remove();
$("#deleteNotesForm > input.episode-id").remove();
$("#read_notes_div input.delete_notes_id:checkbox:checked").each(function
(e) {
if ($(this).prop('checked')) {
$("<input type='hidden' class='note-id' name='note_id[]' value='" +
$(this).data("note_id") + "'/>").appendTo("#deleteNotesForm");
}
});
$("#read_notes_div
input.episode_edit_delete:checkbox:checked").each(function (e) {
if ($(this).prop('checked')) {
$("<input type='hidden' class='episode-id' name='episode_id[]'
value='" + $(this).data("episode_id") + "'/>").appendTo("#deleteNotesForm");
}
});
$.ajax({
type: "POST",
data: $("#deleteNotesForm").serialize(),
cache: false,
url: $("#deleteNotesForm").attr("action"),
success: function (data) {
loadClientNotes();
}
});
}
$(".delete_note").on('click', function (e) {
let notes = $("#read_notes_div
input.delete_notes_id:checkbox:checked").length;
let episodes = $("#read_notes_div
input.episode_edit_delete:checkbox:checked").length;
let letters = $("#read_notes_div
input.deleteLetterId:checkbox:checked").length;
var letterId = $("#read_notes_div
input.deleteLetterId:checkbox:checked").map(function () {
return this.value;
}).get();
if (letters > 0) {
swal({
title: languageConversion('swalDeleteLetterTitle'),
text: languageConversion('swalDeleteLetterText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.ajax({
type: "POST",
dataType: "json",
url: baseUrl + 'clients/deleteLetters',
data: {
letterId: letterId
},
success: function (data) {
show_hide_toastr_message('successMessage',
languageConversion('swalDeleteLetterNotification'));
readNoteRedirect(1);
}
})
} else {
return 0;
}
});
}
if (notes > 0 && episodes > 0) {
swal({
title: languageConversion('swalDeleteNoteEpisodeTitle'),
text: languageConversion('swalDeleteNoteEpisodeText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
deleteNotesAndEpisodes();
} else {
return 0;
}
});
} else if (episodes > 0) {
swal({
title: languageConversion('swalDeleteEpisode'),
text: languageConversion(episodes > 1 ? 'swalDeleteEpisodesText' :
'swalDeleteEpisodeText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
deleteNotesAndEpisodes();
} else {
return 0;
}
});
} else if (notes > 0) {
swal({
title: languageConversion('swalDeleteNoteTitle'),
text: languageConversion(notes > 1 ? 'swalDeleteNotesText' :
'swalDeleteNoteText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
deleteNotesAndEpisodes();
} else {
return 0;
}
});
}
});
$("#search_notes").on('keyup', function () {
if (($("#search_notes").val() != '' && $("#search_notes").val().length > 3)
|| !$("#search_notes").val()) {
loadClientNotes();
}
});
$(".cancel_edit").on('click', function () {
readNoteRedirect();
});
setInterval(function() {
saveNoteDraft(clickedEventTriggered, true);
}, 5000);
setInterval(saveTemplateDraft, 5000);
$.validator.addMethod(
"australianDate",
function (value, element) {
// put your own logic here, this is just a (crappy) example
if (value) {
return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/);
} else {
return true;
}
},
languageConversion('dateFormatError')
);
$('#clientAddForm,#form1').validate({
rules: {
myDate: {
australianDate: true
},
'businessId[]': {
required: true,
minlength: 1
}
},
messages: {
'businessId[]': {
required: "You must assign at least 1 business"
}
},
ignore: "checkbox:hidden",
errorPlacement: function (error, element) {
if (element.attr("name") == "teamMemberId[]") {
error.appendTo('.teamMembersCheck');
} else if (element.attr("name") == "businessId[]") {
error.appendTo('.businessCheck');
} else {
error.insertAfter(element);
}
}
});
$(".australianDate").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1900:' + new Date().getFullYear().toString(),
maxDate: '-1d',
defaultDate: '01/01/2000'
});
if (dataAction == 'deselect') {
prop = false;
action = 'select';
text = 'Select All';
}
$('.clientSelectAll').attr('data-action', action);
$('.clientSelectAll span').html(text);
$('#client-list .delete_checkbox_id:visible').each(function () {
$(this).prop("checked", prop);
if (prop) {
$(this).parents('tr').addClass('checked');
$('.client-list').addClass('selected');
manageClientIdsStorage($(this).val(), 'add');
localStorage.setItem('selectAll', 1);
} else {
$(this).parents('tr').removeClass('checked');
manageClientIdsStorage($(this).val(), 'remove');
localStorage.setItem('selectAll', '');
}
});
var clientsNo = $('.delete_checkbox_id:checked').length;
if (clientsNo >= 2 && dataAction != 'deselect') {
$("#btnMerge").removeClass("d-none");
} else {
$("#btnMerge").addClass("d-none");
}
});
if (localStorage.getItem('selectAll')) {
$('.client-list .option-wrap.blue-bg').show();
$('.clientSelectAll').trigger('click');
} else {
localStorage.setItem('businessAssociateClientIds', '');
}
$('#treatment_consent').on('change', function () {
if ($(this).is(":checked")) {
$("#NoteForm .note-editable").prepend('Consent to Treatment');
} else {
var k = $("#NoteForm .note-editable").html();
var h = k.replace('Consent to Treatment', "");
$("#NoteForm .note-editable").html(h);
}
});
$('#clientLinkSaves').click(function () {
$(".clientSearchRelation").css('visibility', 'visible');
});
$("#autosuggestClientRelation").autocomplete({
source: function (request, response) {
var searchText = $("#autosuggestClientRelation").val();
var ajaxUrl = $('#autosuggestUrl').val();
var client_id = $('#client_id').val();
$.ajax({
url: ajaxUrl,
data: {
searchtext: searchText.replace(/^0+/, ''),
relation: 1,
client_id: client_id,
},
dataType: "json",
type: "post",
success: function (data) {
response($.map(data, function (obj) {
return {
label: obj.label,
value: obj.id,
dob: obj.dob,
};
}));
}
});
},
select: function (event, ui) {
var searchId = ui.item.value;
event.preventDefault();
ClientSearchRelation(searchId);
},
});
$(".removeRelatedClient").on("click", function () {
var relationClientId = $(this).attr("data-client_code");
var clientId = $('#client_id').val();
$(this).closest(".relatedClient").remove();
$.ajax({
type: "POST",
url: $('#baseUrl').val() + 'clients/deleteLinkedClients',
dataType: "JSON",
data: {
relationClientId: relationClientId,
clientId: clientId,
},
success: function (data) {
return true;
}
});
});
$("#discard_draft").on('click', function () {
var draftId = '';
if ($("#note_type").val() == 'template' || $("#note_type").val() ==
'category') {
draftId = $("#template_draft_id").val();
} else if ($("#note_type").val() == 'text') {
draftId = $("#draft_id").val();
}
if (draftId != '') {
$.post($('#baseUrl').val() + "clients/delete_note/" + $
('#client_id').val() + '/' + draftId, {}, function (data) {
if (data) {
$("#discard_draft").hide();
$('#treatment_consent').prop('checked', false);
$(".autosave_text").html('');
$(".autosave_text").hide();
$('#draft_id').val('');
$('#template_draft_id').val('');
$("#template_note_changed").val(0);
$("#text_note_changed").val(0);
$('.episode_type').val(null).trigger("change");
$('#note_template').val(null).trigger("change");
loadUserAvatar($("#user_id").val());
tinymce.get("note").setContent('');
$('.note-attachment').html('');
$('.note-editable').html('');
$('#NoteFormCategory').html('');
$("#note_template").val(0).trigger("change");
$("#template_tags").val('');
$('#tags_5').val('');
$('.tag').remove();
$('.buttonDisable').attr('disabled', false);
}
});
}
});
$('.invoiceFilter').on('change', function () {
getClientInvoicesFilter();
});
$('.paymentFilter').on('change', function () {
getClientPaymentsFilter();
});
$('.appointmentFilter').on('change', function () {
getClientappointmentFilter();
});
if ($("#teamMemberAll").prop('checked')) {
});
let flag = true;
$("#team_members_row input.teamMemberIds").each(function (e) {
let checked = $(this).prop('checked');
flag = flag && checked;
});
$("#teamMemberAll").prop('checked', flag);
function renderDateRangePicker(id) {
var dateRangeOpen = datePickerRangeOpens();
$('#' + id).daterangepicker({
startDate: moment().subtract('days', $('#allDays').val()),
endDate: moment(),
showDropdowns: true,
showWeekNumbers: true,
timePicker: false,
timePickerIncrement: 1,
timePicker12Hour: true,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract('days', 1),
moment().subtract('days', 1)],
'Tomorrow': [moment().add('days', 1), moment().add('days', 1)],
'Last 7 Days': [moment().subtract('days', 6), moment()],
'Last 30 Days': [moment().subtract('days', 29), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract('month', 1).startOf('month'),
moment().subtract('month', 1).endOf('month')],
'All': [moment().subtract('days', $('#allDays').val()), moment()]
},
opens: dateRangeOpen,
buttonClasses: ['btn btn-default'],
applyClass: 'btn-small btn-primary',
cancelClass: 'btn-small',
format: 'MM/DD/YYYY',
separator: ' to ',
locale: {
applyLabel: 'Submit',
fromLabel: 'From',
toLabel: 'To',
customRangeLabel: 'Custom Range',
daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
monthNames: ['January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December'],
firstDay: 1
}
},
function (start, end) {
var startDate = start.format('MMMM D, YYYY');
var endDate = end.format('MMMM D, YYYY');
var allStart = moment().subtract('days', $
('#allDays').val()).format('MMMM D, YYYY');
var allEnd = moment().format('MMMM D, YYYY');
var dateValue = '';
if (startDate == allStart && endDate == allEnd) {
dateValue = 'All';
} else {
dateValue = startDate + ' - ' + endDate;
}
$('#' + id + ' span').html(dateValue);
if (id == 'invoiceRange') {
$("#invoice_date_range").val(dateValue);
getClientInvoicesFilter();
} else if (id == 'paymentRange') {
$("#payment_date_range").val(dateValue);
getClientPaymentsFilter();
} else if (id == 'salesRange') {
$("#sales_date_range").val(dateValue);
getClientSalesFilter();
} else if (id == 'appointmentRange') {
$("#appointment_date_range").val(dateValue);
getClientappointmentFilter();
} else if (id == 'messageRange') {
$("#message_date_range").val(dateValue);
getClientSentMessages();
} else if (id == 'billingInvoiceRange') {
$("#billing_invoice_date_range").val(dateValue);
getBillingInvoicesFilter();
}
});
}
$("#teamMemberAll").on('click', function (e) {
if ($("#teamMemberAll").prop('checked')) {
$("#team_members_row input.teamMemberIds").prop('checked', true);
}
});
$("#team_members_row input.teamMemberIds").on('click', function (e) {
$flag = true;
$("#team_members_row input.teamMemberIds").each(function (e) {
$flag = $flag && $(this).prop('checked');
});
$("#teamMemberAll").prop('checked', $flag);
});
$("#invoice_type").on('change', function (e) {
e.preventDefault();
$("#type").val($(e.target).val());
$("#clientSearchForm").submit();
});
$("#invoiceFilterType").on('change', function (e) {
e.preventDefault();
$("#autosuggest").val('');
});
$("#contact_submenu").on('change', function (e) {
window.location = $(this).find(':selected').data('url');
});
// delete invoice
$('body').on('click', '.delete-invoice', function () {
var thisElement = $(this);
var thisIdArray = $(this).attr('id').split('-');
var client_id = thisIdArray[1];
var payment_id = thisIdArray[2];
swal({
title: languageConversion('deleteConfirmTitle'),
text: languageConversion('invoiceDeleteConfirmMsg'),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('deleteConfirmButtonText'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.post(baseUrl + 'delete-invoice', {
payment_id: payment_id,
client_id: client_id,
my_token_name: $("input[name*='my_token_name']").val()
}, function (data) {
if (data == 'success') {
if ($('#type').val() == 'sales') {
location.reload();
}
thisElement.closest('tr').slideUp('slow');
} else {
swal("", languageConversion('cannotDeleteInvoice'),
"error");
}
});
}
});
});
//billing contact -> invoice page, set search placeholder text based on filter
type when changing filter type
$('#invoiceFilterType').on('change', function (e) {
setSearchPlaceholder();
});
setSearchPlaceholder();
function setSearchPlaceholder() {
let filterType = $('#invoiceFilterType').val();
let placeholderText = null;
if (filterType == 'client') {
placeholderText = 'Client First or Last Name';
} else if (filterType == 'mobile') {
placeholderText = 'Client Mobile Number';
} else if (filterType == 'invoice') {
placeholderText = 'Invoice Number';
} else if (filterType == 'contact') {
placeholderText = 'Billing Contact Name';
}
if (placeholderText) {
$('#autosuggest').attr('placeholder', placeholderText);
}
}
function manageClientIdsStorage(clientId, action) {
var businessAssociateClientIds =
localStorage.getItem('businessAssociateClientIds');
if (businessAssociateClientIds) {
var arrayClientIds = businessAssociateClientIds.split(',');
var inAarry = $.inArray(clientId, arrayClientIds);
if (inAarry > -1) {
if (action == 'remove') {
arrayClientIds.splice(inAarry, 1);
localStorage.setItem('selectAll', '');
}
} else {
if (action == 'add') {
arrayClientIds.push(clientId)
}
}
businessAssociateClientIds = arrayClientIds.join(',');
localStorage.setItem('businessAssociateClientIds',
businessAssociateClientIds);
} else if (action == 'add') {
localStorage.setItem('businessAssociateClientIds', clientId);
}
}
if (clientTab == 'notes') {
$('#ClientNotesNew').click()
}
});
}
function removeNotes() {
var note_id = $("input.delete_notes_id:checked").val();
swal({
title: languageConversion('swalDeleteNoteTitle'),
text: languageConversion('swalDeleteNoteText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.post($('#baseUrl').val() + "clients/delete_note/" + $
('#client_id').val() + '/' + note_id, {
note: note_id
}, function (data) {
if (data) {
$(".blue-bg").hide();
loadClientNotes();
}
});
} else {
return 0;
}
});
}
function removeEpisode() {
var episode = $("input.episode_edit_delete:checked").val();
var note_count = $("#view_episode_" + episode).parent().find('span').html();
if (note_count == 0) {
swal({
title: languageConversion('swalDeleteEpisode'),
text: languageConversion('swalDeleteEpisodeText'),
type: "info",
showCancelButton: true,
confirmButtonColor: "#3ada25",
confirmButtonText: languageConversion('yes'),
cancelButtonText: languageConversion('cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm == true) {
$.post($('#baseUrl').val() + "clients/delete_episode/", {
episode_id: episode
}, function (data) {
if (data) {
$(".blue-bg").hide();
loadClientNotes();
}
});
} else {
return 0;
}
});
} else {
swal("", languageConversion('swalEpisodeDeleteError'), "error");
return false;
}
}
var intervalId;
$("#open_non_modal_dialog").on("click", function () {
$("#client_modal").show();
var iframeDoc = $('#contentIframe')[0].contentWindow.document;
if ($(iframeDoc).find('#read_notes_li').length > 0) {
openReadNotes();
}
intervalId = setInterval(checkButtonInsideIframe, 100);
});
$("#close_non_modal_dialog").on("click", function () {
$("#client_modal").hide();
clearInterval(intervalId);
});
$("#expand_non_modal_dialog").on("click", function () {
if ($("#client_modal").outerWidth() == $(window).innerWidth() && $
("#client_modal").outerHeight() == $(window).innerHeight()-90) {
// If already maximized, restore to initial size
$('#expand_non_modal_dialog').find('i.fa-compress-alt').removeClass('fa-
compress-alt').addClass('fa-expand-alt');
var left = $("#client_modal").outerWidth()-($
("#client_modal").outerWidth()*70/100 + 80);
var top = $("#client_modal").outerHeight()-($
("#client_modal").outerHeight()*70/100 + 20);
$("#client_modal").animate({
left: left,
top: top,
width: '70%',
height: '70%',
});
} else {
// Otherwise, maximize
var height = $(window).innerHeight()-90;
$('#expand_non_modal_dialog').find('i.fa-expand-alt').removeClass('fa-
expand-alt').addClass('fa-compress-alt');
$("#client_modal").animate({
left: '0',
top: '90',
width: '100%',
height: height,
});
}
});
$('#contentIframe').on('load', function() {
var iframeDoc = $('#contentIframe')[0].contentWindow.document;
$(iframeDoc).find('#ClientNotesNew').click();
$(iframeDoc).find('#open_non_modal_dialog').hide();
});
function checkButtonInsideIframe() {
var iframeContent = $('#contentIframe')[0].contentWindow.document;
var buttonInsideIframe = $(iframeContent).find("#open_non_modal_dialog");
if (buttonInsideIframe.length) {
$(iframeContent).find('#open_non_modal_dialog').hide();
}
}
function openReadNotes(){
var iframeDoc = $('#contentIframe')[0].contentWindow.document;
$(iframeDoc).find('#read_notes_li').click();
$(iframeDoc).find('.main-notes-tab').click();
$(iframeDoc).find('#read_notes').addClass('active');
$(iframeDoc).find('.main-notes-tab').addClass('active');
$(iframeDoc).find('.main-notes-tab').removeClass('active');
$(iframeDoc).find('.read-notes-tab').addClass('active');
$(iframeDoc).find('.blue-bg').hide();
$(iframeDoc).find("#new-notes-tab").removeClass('active');
$(iframeDoc).find("#new-notes-tab").addClass('fade');
$(iframeDoc).find("#read-notes").removeClass('fade');
$(iframeDoc).find("#read-notes").addClass('active');
$(iframeDoc).find(".right-side-tabs").show();
$(iframeDoc).find(".read-subs").addClass('fade');
$(iframeDoc).find(".read-nav-tabs").removeClass('active');
$(iframeDoc).find("#all-nav-tab").addClass('active');
$(iframeDoc).find("#read_note_type").val('all');
$(iframeDoc).find("#discard_draft").hide();
}
dragElement(document.getElementById("client_modal"));
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if ($('#' + elmnt.id + "header").length) {
//if present, the header is where you move the DIV from:
$('#' + elmnt.id + "header").on('mousedown', dragMouseDown);
} else {
//otherwise, move the DIV from anywhere inside the DIV
$(elmnt).on('mousedown', dragMouseDown);
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
$(document).on('mouseup', closeDragElement);
// call a function whenever the cursor moves:
$(document).on('mousemove', elementDrag);
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
$(elmnt).css('top', (elmnt.offsetTop - pos2) + "px");
$(elmnt).css('left', (elmnt.offsetLeft - pos1) + "px");
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
$(document).off('mouseup', closeDragElement);
$(document).off('mousemove', elementDrag);
}
}
function readNoteRedirect(letter = null) {
if (($("#edit_note").length && $("#edit_note").val() == 1) || $
("#emailConfirm").val() || $('#edit_letter').val()) {
window.location.href = $("#notesEdit").val();
} else {
$('#treatment_consent').prop('checked', false);
$(".autosave_text").html('');
$(".autosave_text").hide();
$('#draft_id').val('');
$('#template_draft_id').val('');
$("#template_note_changed").val(0);
$("#text_note_changed").val(0);
$('.episode_type').val(null).trigger("change");
$('#note_template').val(null).trigger("change");
loadUserAvatar($("#user_id").val());
$('#note').val('');
$('.note-attachment').html('');
$('.note-editable').html('');
$('#NoteFormCategory').html('');
$("#note_template").val(0).trigger("change");
$("#template_tags").val('');
$('#tags_5').val('');
$('.tag').remove();
$('.buttonDisable').attr('disabled', false);
$('.main-notes-tab').removeClass('active');
$('.read-notes-tab').addClass('active');
$('.blue-bg').hide();
$("#new-notes-tab").removeClass('active');
$("#new-notes-tab").addClass('fade');
$("#read-notes").removeClass('fade');
$("#read-notes").addClass('active');
$(".right-side-tabs").show();
$(".read-subs").addClass('fade');
$(".read-nav-tabs").removeClass('active');
$("#all-nav-tab").addClass('active');
$("#read_note_type").val('all');
$("#discard_draft").hide();
loadClientNotes(0, letter);
}
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function getCheckedUserIds() {
var userIds = [];
$.each($("input.user-checkbox:checked"), function () {
userIds.push($(this).attr('id').split('-')[1]);
});
return userIds.join(',');
}
function getCheckedEpisodeIds() {
var episodeIds = [];
$.each($("input.episode-checkbox:checked"), function () {
episodeIds.push($(this).attr('id').split('-')[1]);
});
return episodeIds.join(',');
}
function getEpisodesToExport() {
var episodeIds = [];
$.each($("input.episode_edit_delete:checked"), function () {
episodeIds.push($(this).val());
});
return episodeIds.join(',');
}
function getNotesToExport() {
var noteIds = [];
$.each($("input.delete_notes_id:checked"), function () {
noteIds.push($(this).val());
});
return noteIds.join(',');
}
function loadUserAvatar(user_id) {
$.post($('#baseUrl').val() + 'booking/getUserApppointmentColor/', {
user_id: user_id,
dataType: "json",
}, function (data) {
data = $.parseJSON(data);
if (data.picture) {
$('.note-avatar').removeClass('no-border');
$('.note-avatar').css('background-image', "url(" + data.picture + ")");
$('.note-avatar').show();
$('.no-avatar').hide();
} else if (data.initials) {
$('.note-avatar').hide();
$('.no-avatar').show();
$('.no-avatar').html(data.initials);
} else {
$('.no-avatar').hide();
$('.note-avatar').addClass('no-border');
$('.note-avatar').css('background-image', 'none');
}
});
if (user_id) {
$(".note_user").val(user_id);
}
setTimeout(function () {
$(".note_user").select2({ width: 150 });
});
}
function saveNoteDraft(clickedEvent, showTostr) {
if ($('#text_note_changed').val() == 1) {
if ($('#note_type').val() == 'text' || $('#note_type').val() == 'payment'
|| $('#note_type').val() == 'credits' || $('#note_type').val() == 'appointment') {
$('.buttonDisable').attr('disabled', true);
if ($("#note").length > 0) {
var note = tinymce.get("note") ? tinymce.get("note").getContent() :
'';
if (note) {
tinymce.get('note').save();
}
}
if ($("#note_edit").length > 0 && $("#note_edit").val() == 1) {
var note = tinymce.get('edit_client_note') ?
tinymce.get('edit_client_note').getContent() : '';
if (note) {
tinymce.get('edit_client_note').save();
}
}
if ($("<div/>").html(note).text() == '') {
if (!clickedEvent ) {
$("#note-text-error").show();
}
$('.buttonDisable').attr('disabled', false);
return false;
}
var consent_check = 0;
if ($('#treatment_consent').is(":checked")) {
consent_check = 1;
}
var attachmentId = $('#text-
notes').find('input.attachmentId').serialize();
$.ajax({
type: 'POST',
dataType: 'json',
url: $('#baseUrl').val() + "clients/save_draft_note/",
data: {
client_id: $("#client_id").val(),
note: note.replace('Consent to Treatment', ""),
note_date: $("input[name=text_note_date]").val(),
note_added: $("select[name=text_note_user]").val(),
episode: $("select[name=note_episode]").val(),
draft_id: $('#draft_id').val(),
attachmentId: attachmentId,
consent: consent_check,
note_tags: $("#note_tags").val()
},
success: function (response) {
if (response.data.error) {
$("#note-size-error").show();
} else {
$("#note-size-error").hide();
$('#draft_id').val(response.data.note_id);
$('#text_note_changed').val(0);
$('.buttonDisable').attr('disabled', false);
if (showTostr) {
showToster('Your draft was saved at ' +
response.data.note_time, 'Draft Saved');
}
$("#discard_draft").show();
}
}
}, 'json');
}
}
}
};
function saveTemplateDraft() {
if ($('#template_note_changed').val() == 1) {
if ($("#note_type").val() == 'template' || $("#note_type").val() ==
'category') {
$('.buttonDisable').attr('disabled', true);
var discharge_id = $("#discharge_id").val();
var consent_check = 0;
if ($('#template_treatment_consent').is(":checked")) {
consent_check = 1;
}
$('.signature').each(function (e) {
if ($(this).is(':visible')) {
var sigData = $(this).jSignature('getData');
var baseValue = sigData.split(",");
$
(this).parent().parent().parent().find('.signatureData').val(baseValue[1]);
}
});
$.ajax({
type: 'POST',
dataType: 'json',
url: $('#baseUrl').val() + "clients/categoryNoteSubmit/",
data: $('#save_template').serialize() + '&client_id=' + $
("#client_id").val() + '&save_type=draft&discharge=' + discharge_id + '&draft_id='
+ $("#template_draft_id").val() + '&consent=' + consent_check,
success: function (data) {
$('#template_draft_id').val(data.note_id);
$('#template_note_changed').val(0);
$('.buttonDisable').attr('disabled', false);
showToster('Your draft was saved at ' + data.note_time, 'Draft
Saved');
$("#discard_draft").show();
}
});
}
}
}
function autoSize(ele) {
ele.style.height = 'auto';
var newHeight = (ele.scrollHeight > 32 ? ele.scrollHeight : 32);
ele.style.height = newHeight.toString() + 'px';
}
function addTemplateTag() {
var tag_val = $('#tags_5').val();
$("#template_tags").val(tag_val);
}
function addNoteTag(element) {
var note_type = element.split('_')[1];
var tag_val = $('#' + element).val();
$("#" + note_type + "_tags").val(tag_val);
}
function updateNoteSection() {
var date_range = $('#date_range').val();
var client_id = $('#client_id').val();
$('.loader').show();
$.post($('#baseUrl').val() + "clients/ajaxNoteListing/" + client_id + "?
date_range=" + date_range, function (data) {
if (data) {
$('#noteListing').html(data);
}
$('.loader').delay(100).fadeOut(1000);
});
}
} else {
$(".episode_type").html(k);
$(".episode_type").select2({ width: 'auto' });
}
}
}, 'json')
}
}
function loadEpisodeFilter() {
$.post($('#baseUrl').val() + 'clients/getEpisodeFilter', {
client_id: $('#client_id').val()
}, function (data) {
$('#episode_filter').html(data);
});
}
function ClientSearchRelation(searchId) {
var clientSearch = $('#autosuggestClientRelation').val();
var client_id = $("#client_id").val();
var user_id = $("#user_id").val();
var parent_user_id = $("#parent_user_id").val();
var relation_id = searchId;
var added_by = $("#user_id").val();
var baseUrl = $('#baseUrl').val();
$('.selectedClient').each(function () {
var $this = $(this).val();
if ($this == relation_id) {
swal({
title: "error",
text: 'Client is already selected',
type: "error",
showCancelButton: false,
confirmButtonColor: "#3ada25",
confirmButtonText: "Ok",
closeOnConfirm: true,
closeOnCancel: true
});
$(this).closest(".relatedClient").remove();
}
});
$.ajax({
type: "POST",
dataType: 'json',
url: baseUrl + 'clients/addClientLink',
data: {
client_id: client_id,
user_id: user_id,
parent_user_id: parent_user_id,
relation_id: relation_id,
added_by: added_by,
clientSearch: clientSearch,
},
success: function (data) {
if (data == false) {
swal({
title: "error",
text: 'Already linked client.',
type: "error",
showCancelButton: false,
confirmButtonColor: "#3ada25",
confirmButtonText: "Ok",
closeOnConfirm: true,
closeOnCancel: true
});
} else {
var relationId = data.clientId;
var clientName = data.clientName;
var dob = data.dob;
if (!dob || dob == '00/00/0000') {
dob = '';
} else {
dob = '(' + dob + ')';
}
$('#SelectedClientList').append('<div class="relatedClient d-flex
justify-content-between mb-3"><input type="hidden" class="selectedClient"
name="relationId[]" value="' + relationId + '">' +
'<div class="d-flex"><a href="' + data.clientLink + '"
id="link" style="cursor: pointer;" target="_blank" data-client_code="' + relationId
+ '">' + clientName +
'<span>' + ' ' + dob + '</span> <span
id="clientRelationText_' + relationId + '"></span></a></div>' +
'<div><a data-toggle="tooltip" data-placement="top" title="Add
Client Relationship" href="javascript:void(0);" class="mr-4 clientRelationship"
id="ClientRelation" data-client_code="' + relationId + '"><i class="fal fa-
link"></i></a>' + '</span>' +
'<span>' + '<a data-toggle="tooltip" data-placement="top"
title="Remove" href="javascript:void(0);" class="removeRelatedClient"
id="removeRelatedClient" data-client_code="' + relationId + '"><i class="fal fa-
times"></i></a>' + '</span></div></div>');
$("[data-toggle=tooltip]").tooltip();
}
}
});
$("#autosuggestClientRelation").val('');
}
$("#invoiceautosuggest").autocomplete({
source: function (request, response) {
var searchText = $("#invoiceautosuggest").val();
var ajaxUrl = $('#invoiceAutosuggestUrl').val();
var clientId = $('#client_id').val();
$.ajax({
url: ajaxUrl,
data: {
searchtext: searchText.replace(/^0+/, ''),
searchType: 'invoice',
invoiceFilterType: 'invoice',
clientId: clientId
},
dataType: "json",
type: "post",
success: function (data) {
response($.map(data, function (obj) {
return {
label: obj.label,
value: obj.id,
};
}));
}
});
},
select: function (event, ui) {
event.preventDefault();
searchInvoiceById(ui.item.value);
},
});
function searchInvoiceById(value) {
if (value) {
$('.invoice-search-wrap input#invoiceautosuggest').val(value);
var query_string = '?type=' + $('#invoiceType').val() +
'&search_product_text=' + value + '&invoiceFilterType=invoice' +
'&sale_business_id=' + $('#sale_business_id').val() + '&sale_venu_id=' + $
('#sale_venu_id').val() + '&date_range=' + $('#invoice_date_range').val();
var clientId = $('#client_id').val();
var baseUrl = $('#baseUrl').val();
$('.loader').show();
$.post(baseUrl + 'invoices' + query_string, {
clientId: clientId,
// clientDetailsInvoice: 'true',
paging_data: 1
}, function (data) {
$('.loader').hide();
$('.ClientInvoiceBox').html(data).show();
});
}
}
$("#paymentautosuggest").autocomplete({
source: function (request, response) {
var searchText = $("#paymentautosuggest").val();
var ajaxUrl = $('#paymentAutosuggestUrl').val();
var clientId = $('#client_id').val();
$.ajax({
url: ajaxUrl,
data: {
searchtext: searchText.replace(/^0+/, ''),
searchType: 'invoice',
invoiceFilterType: 'invoice',
clientId: clientId
},
dataType: "json",
type: "post",
success: function (data) {
response($.map(data, function (obj) {
return {
label: obj.label,
value: obj.id,
};
}));
}
});
},
select: function (event, ui) {
event.preventDefault();
searchPaymentByInvoiceId(ui.item.value);
},
});
function searchPaymentByInvoiceId(value) {
if (value) {
$('.payment-search-wrap input#paymentautosuggest').val(value);
var query_string = '?business_id=' + $('#payment_business_id').val() +
'&venu_id=' + $('#payment_venu_id').val() + '&search_product_text=' + value +
'&paymentFilterType=invoice' + '&user_id=' + $('#team_member').val() +
'&filter_category=' + $('#filter_product_category').val() + '&date_range=' + $
('#payment_date_range').val();
var clientId = $('#client_id').val();
var baseUrl = $('#baseUrl').val();
$('.loader').show();
$.post(baseUrl + 'payments' + query_string, {
clientId: clientId,
paging_data: 1
}, function (data) {
$('.loader').hide();
$('.ClientPaymentBox').html(data).show();
});
}
}
function datePickerRangeOpens() {
var tabCount = $("#sub-chlidnav ul").find("li:visible").length;
var datePickerOpens = 'right';
if (tabCount > 4) {
var datePickerOpens = 'left';
}
return datePickerOpens;
}
$(function () {
var userId = $("#userId").val();
if (localStorage.getItem("filterStatus-" + userId) === 'open') {
$('.filter-nav').addClass('active');
$("#filter-container").show();
} else {
$('.filter-nav').removeClass('active');
$("#filter-container").hide();
}
filterShow = $('#filter-container').data('filter');
if ((getParam().char || getParam().tags || filterShow) &&
localStorage.getItem("filterStatus-" + userId) === 'close' && $
('#clientsPage').val() == 'clients') {
$('.filter-nav').addClass('clientFilterAppiled');
$('.filter-nav').attr('data-original-title',
languageConversion('clientFilterAppiled'));
}
});