Last active
September 13, 2016 17:45
-
-
Save prakashmalviya/b5c0b25e7fd217cb6b35e9239970b99d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ManageBill = function () { | |
var body = $('body'); | |
var oTable = ''; | |
var initDataTable = function (targeTable, url) { | |
var dturl = url; | |
$.extend($.fn.dataTable.defaults, { | |
dom: 'rt<"bottom"lp>', | |
bAutoWidth: false, | |
bSortable: true, | |
processing: true, | |
serverSide: true, | |
order: [[0, "desc"]], | |
language: { | |
"sEmptyTable": sEmptyTable, | |
"sInfo": sInfo, | |
"sInfoEmpty": sInfoEmpty, | |
"sInfoFiltered": sInfoFiltered, | |
"sInfoPostFix": sInfoPostFix, | |
"sInfoThousands": sInfoThousands, | |
"sLengthMenu": sLengthMenu, | |
"sLoadingRecords": sLoadingRecords, | |
"sProcessing": sProcessing, | |
"sSearch": sSearch, | |
"sZeroRecords": sZeroRecords, | |
"oPaginate": { | |
"sFirst": sFirst, | |
"sPrevious": sPrevious, | |
"sNext": sNext, | |
"sLast": sLast | |
}, | |
"oAria": { | |
"sSortAscending": sSortAscending, | |
"sSortDescending": sSortDescending | |
} | |
}, | |
ajax: { | |
url: dturl, | |
data: function (d) { | |
d.filter_by_id = $('input[name=filter_by_id]').val(); | |
d.filter_by_name = $('input[name=filter_by_name]').val(); | |
} | |
}, | |
}); | |
$.fn.dataTable.ext.errMode = 'throw'; | |
oTable = $('#' + targeTable).dataTable({ | |
"columns": [ | |
{data: 'bill_number', 'searchable': true, "className": 'dt-center'}, | |
{data: 'bill_date', 'searchable': true}, | |
{data: 'patient_lname', 'searchable': true}, | |
{data: 'patient_street', 'searchable': true}, | |
{data: 'patient_city', 'searchable': true}, | |
{data: 'total_amount', 'searchable': true}, | |
{data: 'payment_status', 'searchable': false}, | |
{data: 'action', 'orderable': false, 'searchable': false, 'name': 'id', "className": 'dt-center'} | |
] | |
}); | |
oTable.processFilters(); | |
}; | |
var initInvoiceDataTable = function (targeTable, url) { | |
var dturl = url; | |
$.extend($.fn.dataTable.defaults, { | |
dom: 'rt<"bottom"lp>', | |
bAutoWidth: false, | |
bSortable: true, | |
processing: true, | |
serverSide: true, | |
order: [[0, "desc"]], | |
language: { | |
"sEmptyTable": sEmptyTable, | |
"sInfo": sInfo, | |
"sInfoEmpty": sInfoEmpty, | |
"sInfoFiltered": sInfoFiltered, | |
"sInfoPostFix": sInfoPostFix, | |
"sInfoThousands": sInfoThousands, | |
"sLengthMenu": sLengthMenu, | |
"sLoadingRecords": sLoadingRecords, | |
"sProcessing": sProcessing, | |
"sSearch": sSearch, | |
"sZeroRecords": sZeroRecords, | |
"oPaginate": { | |
"sFirst": sFirst, | |
"sPrevious": sPrevious, | |
"sNext": sNext, | |
"sLast": sLast | |
}, | |
"oAria": { | |
"sSortAscending": sSortAscending, | |
"sSortDescending": sSortDescending | |
} | |
}, | |
ajax: { | |
url: dturl, | |
data: function (d) { | |
d.filter_by_id = $('input[name=filter_by_id]').val(); | |
d.filter_by_name = $('input[name=filter_by_name]').val(); | |
} | |
}, | |
}); | |
$.fn.dataTable.ext.errMode = 'throw'; | |
oTable = $('#' + targeTable).dataTable({ | |
"columns": [ | |
{data: 'bill_number', 'searchable': true, "className": 'dt-center'}, | |
{data: 'created_at', 'searchable': true}, | |
{data: 'client_name', 'searchable': true}, | |
{data: 'total_amount', 'searchable': true}, | |
{data: 'payment_status', 'searchable': false}, | |
{data: 'action', 'orderable': false, 'searchable': false, 'name': 'id', "className": 'dt-center'} | |
] | |
}); | |
oTable.processFilters(); | |
}; | |
var payAction = function () { | |
body.on('click', '.invoice-pay', function () { | |
var $_this = $(this); | |
var bill_id = $_this.attr('data-value'); | |
if (typeof bill_id !== typeof undefined && bill_id != '') { | |
swal({ | |
title: confirm_title, | |
text: pay_confirm, | |
type: "warning", | |
showCancelButton: true, | |
confirmButtonColor: "#5cb85c", | |
confirmButtonText: paid_message, | |
closeOnConfirm: true, | |
cancelButtonText: cancel | |
}, function (isConfirm) { | |
if (isConfirm) { | |
$.ajax({ | |
type: "POST", | |
data: {id: bill_id}, | |
url: base_url + "bill/" + bill_id + "/pay", | |
success: function (data) { | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
oTable.fnDraw(); | |
$('.earning-month').html(data.earning_month); | |
$('.pending-month').html(data.pending_amount); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} else { | |
$_this.prop('selectedIndex', 0); | |
} | |
}); | |
} | |
}); | |
}; | |
var paymentReminderAction = function () { | |
$(document).on("click", ".btn-reminder", function () { | |
var bill_id = $(this).attr('data-value'); | |
var bill_email = $(this).attr('data-email'); | |
$(".modal-body #bill_id").val(bill_id); | |
$(".modal-body #email").val(bill_email); | |
}); | |
body.on('click', '#bill-reminder-action', function () { | |
var bill_id = $(".modal-body #bill_id").val(); | |
var bill_email_form = $('#bill-reminder-form'); | |
bill_email_form.validate({ | |
rules: { | |
'email': { | |
required: { | |
depends: function () { | |
return $('input[name=reminder_option]:checked').val() == '2'; | |
} | |
}, | |
email: true | |
}, | |
}, | |
errorPlacement: function (error, element) { | |
error.insertAfter(element); | |
} | |
}); | |
if (bill_email_form.valid()) { | |
var reminder_option = $(".modal-body .bill-warning:checked").val(); | |
var bill_id = $(".modal-body #bill_id").val(); | |
$.ajax({ | |
method: 'post', | |
data: bill_email_form.serialize(), | |
url: bill_email_form.attr('action'), | |
beforeSend: function () { | |
$('#bill-reminder-action').prop('disabled', true); | |
}, | |
success: function (data) { | |
oTable.fnDraw(); | |
$('#reminder-modal').modal('hide'); | |
bill_email_form[0].reset(); | |
$('#bill-reminder-action').prop('disabled', false); | |
$('.email-option').addClass('hidden'); | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message); | |
// If print open selected then need to open as pdf | |
if (data.reminder_option == 1) { | |
document.location = base_url + "bill/" + bill_id + "/bill-reminder-print"; | |
} | |
} else { | |
showAjaxAlert('alert-danger', data.message); | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
$('.email-option').addClass('hidden'); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} | |
} | |
); | |
}; | |
var paymentWarningAction = function () { | |
$(document).on("click", ".btn-warning", function () { | |
var bill_id = $(this).attr('data-value'); | |
var bill_email = $(this).attr('data-email'); | |
$(".modal-body-warning #bill_id").val(bill_id); | |
$(".modal-body-warning #email").val(bill_email); | |
}); | |
body.on('click', '#bill-warning-action', function () { | |
var bill_email_form = $('#bill-warning-form'); | |
bill_email_form.validate({ | |
rules: { | |
'email': { | |
required: { | |
depends: function () { | |
return $('input[name=reminder_option]:checked').val() == '2'; | |
} | |
}, | |
email: true | |
}, | |
}, | |
errorPlacement: function (error, element) { | |
error.insertAfter(element); | |
} | |
}); | |
if (bill_email_form.valid()) { | |
var reminder_option = $(".modal-body-warning .bill-warning:checked").val(); | |
var bill_id = $(".modal-body-warning #bill_id").val(); | |
$.ajax({ | |
method: 'post', | |
data: bill_email_form.serialize(), | |
url: bill_email_form.attr('action'), | |
beforeSend: function () { | |
$('#bill-warning-action').prop('disabled', true); | |
}, | |
success: function (data) { | |
oTable.fnDraw(); | |
$('#bill-warning-action').prop('disabled', false); | |
bill_email_form[0].reset(); | |
$('#warning-modal').modal('hide'); | |
$('.email-option').addClass('hidden'); | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
if (reminder_option == 1) { | |
document.location = base_url + "bill/" + bill_id + "/bill-warning-print"; | |
} | |
} else { | |
showAjaxAlert('alert-danger', data.message); | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
$('.email-option').addClass('hidden'); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} | |
}); | |
}; | |
var billReminderOption = function () { | |
body.on('click', '.bill-reminder, .bill-warning', function () { | |
var $_this = $(this); | |
if ($_this.val() == 2) { | |
$_this.parents().next('.form-group').removeClass('hidden'); | |
} else { | |
$_this.parents().next('.form-group').addClass('hidden'); | |
} | |
}); | |
}; | |
var deleteAction = function () { | |
body.on('click', '.invoice-delete', function () { | |
var $_this = $(this); | |
var bill_id = $_this.attr('data-value'); | |
if (typeof bill_id !== typeof undefined && bill_id != '') { | |
swal({ | |
title: confirm_title, | |
text: delete_confirm, | |
type: "warning", | |
showCancelButton: true, | |
confirmButtonColor: "#DD6B55", | |
confirmButtonText: delete_message, | |
closeOnConfirm: true, | |
cancelButtonText: cancel | |
}, function (isConfirm) { | |
if (isConfirm) { | |
$.ajax({ | |
type: "DELETE", | |
data: {id: bill_id}, | |
url: base_url + "bill/" + bill_id, | |
success: function (data) { | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
oTable.fnDraw(); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} else { | |
$_this.prop('selectedIndex', 0); | |
} | |
}); | |
} | |
}); | |
}; | |
var invoiceDeleteAction = function () { | |
body.on('click', '.fee-invoice-delete', function () { | |
var $_this = $(this); | |
var bill_id = $_this.attr('data-value'); | |
if (typeof bill_id !== typeof undefined && bill_id != '') { | |
swal({ | |
title: confirm_title, | |
text: delete_confirm, | |
type: "warning", | |
showCancelButton: true, | |
confirmButtonColor: "#DD6B55", | |
confirmButtonText: delete_message, | |
closeOnConfirm: true, | |
cancelButtonText: cancel | |
}, function (isConfirm) { | |
if (isConfirm) { | |
$.ajax({ | |
type: "DELETE", | |
data: {id: bill_id}, | |
url: base_url + "invoice/" + bill_id, | |
success: function (data) { | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
oTable.fnDraw(); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} else { | |
$_this.prop('selectedIndex', 0); | |
} | |
}); | |
} | |
}); | |
}; | |
var validateBillForm = function () { | |
$.validator.setDefaults({ignore: ''}); | |
var $validator = $("#bill-form").validate({ | |
rules: { | |
template_id: {required: true}, | |
patient_fname: {required: true, maxlength: 50}, | |
patient_lname: {required: true, maxlength: 50}, | |
patient_dob: {germanDate: true}, | |
patient_email: {email: true}, | |
patient_street: {required: true, maxlength: 100}, | |
patient_city_code: {required: true, minlength: 4, maxlength: 5, number: true}, | |
patient_city: {required: true, maxlength: 50}, | |
emergency_number: {minlength: 1, maxlength: 7, number: true}, | |
bill_date: {required: true, germanDate: true}, | |
time_start: {required: true}, | |
time_end: {required: true}, | |
diagnosis_id: {number: true}, | |
remote_billing_address_name: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, | |
}, | |
remote_billing_address_email: { | |
email: true, | |
}, | |
remote_billing_address_street: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, | |
}, | |
remote_billing_address_city_code: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, minlength: 4, maxlength: 5, number: true | |
}, | |
remote_billing_address_city: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, | |
} | |
}, | |
errorPlacement: function (error, element) { | |
error.insertAfter(element); | |
} | |
}); | |
customValidation(); | |
}; | |
var $validator = $("#bill-form").validate({ | |
rules: { | |
template_id: {required: true}, | |
patient_fname: {required: true, maxlength: 50}, | |
patient_lname: {required: true, maxlength: 50}, | |
patient_dob: {germanDate: true}, | |
patient_email: {email: true}, | |
patient_street: {required: true, maxlength: 100}, | |
patient_city_code: {required: true, minlength: 4, maxlength: 5, number: true}, | |
patient_city: {required: true, maxlength: 50}, | |
emergency_number: {minlength: 1, maxlength: 7, number: true}, | |
bill_date: {required: true, germanDate: true}, | |
time_start: {required: true}, | |
time_end: {required: true}, | |
diagnosis_id: {number: true}, | |
remote_billing_address_name: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, maxlength: 50, | |
}, | |
remote_billing_address_email: { | |
email: true, | |
}, | |
remote_billing_address_street: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, maxlength: 100, | |
}, | |
remote_billing_address_city_code: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, minlength: 4, maxlength: 5, number: true, | |
}, | |
remote_billing_address_city: { | |
required: { | |
depends: function () { | |
return $('input[name=address2]:checked').val() == '1' || $('input[name=address2]:checked').val() == '2'; | |
} | |
}, maxlength: 50, | |
} | |
}, | |
errorPlacement: function (error, element) { | |
if (element.parent('.input-group').length) { | |
error.insertAfter(element.parent()); // radio/checkbox? | |
} else if (element.hasClass('input-code') || element.hasClass('select2')) { | |
error.insertAfter(element.next('span')); // select2 | |
} else { | |
error.insertAfter(element); // default | |
} | |
} | |
}); | |
var customValidation = function () { | |
$(".code_factor").each(function () { | |
$(this).rules('add', { | |
required: { | |
depends: function () { | |
return $(this).closest('.element_list').find("input:checkbox").is(':checked'); | |
}, | |
}, | |
}); | |
}); | |
$(".amount").each(function () { | |
$(this).rules('add', { | |
required: { | |
depends: function () { | |
return $(this).closest('.element_list').find("input:checkbox").is(':checked'); | |
}, | |
}, | |
}); | |
}); | |
$(".input-code").each(function () { | |
$(this).rules('add', { | |
required: { | |
depends: function () { | |
return $(this).closest('.element_list').find("input:checkbox").is(':checked'); | |
}, | |
}, | |
}); | |
}); | |
}; | |
var initWizard = function () { | |
$('#rootwizard').bootstrapWizard({ | |
onNext: function (tab, navigation, index) { | |
var $valid = $("#bill-form").valid(); | |
if (!$valid) { | |
$validator.focusInvalid(); | |
return false; | |
} | |
if (index == 2) { | |
checkRule(); | |
} | |
}, onTabShow: function (tab, navigation, index) { | |
if (index == 3) { | |
checkRule(); | |
} | |
var $total = navigation.find('li').length; | |
var $current = index + 1; | |
var $percent = ($current / $total) * 100; | |
$('#rootwizard .progress-bar').css({width: $percent + '%'}); | |
// If it's the last tab then hide the last button and show the finish instead | |
if ($current >= $total) { | |
$('#rootwizard').find('.pager .next').hide(); | |
$('#rootwizard').find('.pager .finish').show(); | |
$('#rootwizard').find('.pager .finish').removeClass('disabled'); | |
} else { | |
$('#rootwizard').find('.pager .next').show(); | |
$('#rootwizard').find('.pager .finish').hide(); | |
} | |
}, | |
'onTabClick': function (tab, navigation, index) { | |
return false; | |
var isValid = false; | |
var hadError = false; | |
var index = index + 1; | |
var inputs = $('input, select'); | |
var stepElements = $('#tab' + index).find(inputs); | |
var count = stepElements.length; | |
if (count <= 0) { | |
return true; | |
} | |
$(stepElements).each(function (idx) { | |
isValid = $("#bill-form").validate().element($(this)); | |
if (!isValid) { | |
hadError = true; | |
} | |
}); | |
return !hadError; | |
} | |
}); | |
window.prettyPrint && prettyPrint(); | |
}; | |
var changeTemplate = function () { | |
body.on('change', '#template_id', function (e) { | |
if ($(this).val() != '') { | |
// For some specific template we have to disabled emergency number | |
if ($(this).val() == 2) { | |
$('#emergency_number').attr('disabled', true).parents('.form-group').hide(); | |
} else { | |
$('#emergency_number').attr('disabled', false).parents('.form-group').show(); | |
} | |
e.stopPropagation(); | |
$.ajax({ | |
type: "POST", | |
data: { | |
template_id: $(this).val(), | |
_token: $("[name='_token']").val() | |
}, | |
url: base_url + 'bill/change-template', | |
beforeSend: function () { | |
swal({ | |
title: fetching_set, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
$(".user-sets").html(data.html); | |
$("#user_set_id").html(data.sets); | |
//showReasonBoxForHighFactor(); | |
if (data.address2 == 1) { | |
$("input[name=address2][value='2']").trigger('click'); | |
$('.address2-option').show(); | |
} else { | |
$("input[name=address2][value='0']").trigger('click'); | |
$('.address2-option').hide(); | |
} | |
if (data.diagnosis != '') { | |
$("#diagnosis_id").html(data.diagnosis); | |
$('#diagnosis_id').select2(diagnosisSelect2); | |
} | |
swal.close(); | |
validateBillForm(); | |
}, | |
complete: function () { | |
$(".rule-sets, .suggestion-list, .code-message-list").html(''); | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} | |
}); | |
}; | |
var changeDiagnosis = function () { | |
$("#diagnosis_id").select2({ | |
// your options here | |
}).on('change', function () { | |
$(this).valid(); | |
}); | |
}; | |
var addressOptions = function () { | |
body.on('click', '.address2_chk', function () { | |
var val = $(this).val(); | |
if ($(this).is(':checked')) { | |
if (val == 0) { | |
$('.address2-option').hide(); | |
clearRemoteBillingAddress(); | |
} else { | |
$('.address2-option').show(); | |
} | |
} else { | |
$('.address2-option').hide(); | |
} | |
}); | |
}; | |
var clearRemoteBillingAddress = function () { | |
$('#remote-billing-address-name').val(''); | |
$('#remote-billing-address-email').val(''); | |
$('#remote-billing-address-street').val(''); | |
$('#remote-billing-address-city-code').val(''); | |
$('#remote-billing-address-city').val(''); | |
$(".billing-address").addClass('hidden'); | |
}; | |
var addressSave = function () { | |
body.on('click', '#save-user-address', function () { | |
var form_valid = true; | |
if (!$('input[name="remote_billing_address_name"]').valid()) { | |
form_valid = false; | |
} | |
if (!$('input[name="remote_billing_address_email"]').valid()) { | |
form_valid = false; | |
} | |
if (!$('input[name="remote_billing_address_street"]').valid()) { | |
form_valid = false; | |
} | |
if (!$('input[name="remote_billing_address_city_code"]').valid()) { | |
form_valid = false; | |
} | |
if (!$('input[name="remote_billing_address_city"]').valid()) { | |
form_valid = false; | |
} | |
// Need to save address using ajax request | |
if (form_valid == true) { | |
if ($('#user_address_id').val()) { | |
data = { | |
id: $('#user_address_id').val(), | |
name: $('#remote-billing-address-name').val(), | |
email: $('#remote-billing-address-email').val(), | |
street: $('#remote-billing-address-street').val(), | |
city_code: $('#remote-billing-address-city-code').val(), | |
city: $('#remote-billing-address-city').val(), | |
_token: $("[name='_token']").val() | |
} | |
} else { | |
data = { | |
name: $('#remote-billing-address-name').val(), | |
email: $('#remote-billing-address-email').val(), | |
street: $('#remote-billing-address-street').val(), | |
city_code: $('#remote-billing-address-city-code').val(), | |
city: $('#remote-billing-address-city').val(), | |
_token: $("[name='_token']").val() | |
} | |
} | |
$.ajax({ | |
type: "POST", | |
data: data, | |
url: base_url + 'bill/user/save-address', | |
beforeSend: function () { | |
swal({ | |
title: saving_address, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
swal.close(); | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
var items = '<option value="">Place not saved</option>'; | |
$.each(data.user_address, function (i, address) { | |
var selected_str = ($('#remote-billing-address-name').val() == address.name) ? 'selected="selected"' : ''; | |
items += "<option value='" + address.id + "' " + selected_str + ">" + address.name + "</option>"; | |
}); | |
$('#user_address_id').html(items); | |
$('#user_address_id').select2({ | |
language: 'de', | |
}); | |
$('#remote-billing-address-street,#remote-billing-address-city-code,#remote-billing-address-city').before("<i class='glyphicon glyphicon-ok success'></i>"); | |
$(".billing-address").removeClass('hidden'); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
$('#remote-billing-address-street,#remote-billing-address-city-code,#remote-billing-address-city').addClass('error'); | |
$(".billing-address").addClass('hidden'); | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} | |
}); | |
}; | |
var changeAddress = function () { | |
body.on('change', '#user_address_id', function (e) { | |
e.stopPropagation(); | |
var address_id = $(this).val(); | |
if (address_id != '' && $.isNumeric(address_id)) { | |
$.ajax({ | |
type: "POST", | |
data: { | |
id: address_id, | |
_token: $("[name='_token']").val() | |
}, | |
url: base_url + 'bill/user/change-address', | |
beforeSend: function () { | |
$(".billing-address").addClass('hidden'); | |
swal({ | |
title: fetching_address, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
swal.close(); | |
if (data.success == true) { | |
showAjaxAlert('alert-success', data.message) | |
$('#remote-billing-address-name').val(data.name); | |
$('#remote-billing-address-email').val(data.email); | |
$('#remote-billing-address-street').val(data.street); | |
$('#remote-billing-address-city-code').val(data.city_code); | |
$('#remote-billing-address-city').val(data.city); | |
$(".billing-address").removeClass('hidden'); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} else { | |
clearRemoteBillingAddress(); | |
} | |
}); | |
}; | |
var changeSets = function () { | |
body.on('change', '.all-sets', function (e) { | |
e.stopPropagation(); | |
var $_this = $(this); | |
if ($_this.val() != '') { | |
swal({ | |
title: set_change_warning, | |
type: "info", | |
showCancelButton: true, | |
closeOnConfirm: false, | |
showLoaderOnConfirm: true, | |
cancelButtonText: cancel | |
}, | |
function (isConfirm) { | |
if (isConfirm) { | |
$.ajax({ | |
type: "POST", | |
data: { | |
set_id: $_this.val(), | |
_token: $("[name='_token']").val() | |
}, | |
url: base_url + 'bill/change-set', | |
beforeSend: function () { | |
swal({ | |
title: fetching_set, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
swal.close(); | |
$(".user-sets").html(data.html); | |
validateBillForm(); | |
//showReasonBoxForHighFactor(); | |
$(".more-sets").html(''); | |
localStorage.code_count = 0; | |
calculateAmount(); | |
}, complete: function (data) { | |
checkRule(); | |
CodeExclusion.onLoadCheckAction(); | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
} else { | |
$(this).val($.data(this, 'current')); // added parenthesis (edit) | |
return false; | |
} | |
}); | |
} | |
$.data(this, 'current', $(this).val()); | |
}); | |
}; | |
var showReasonBoxForHighFactor = function () { | |
$('.code_factor').each(function () { | |
var $_this = $(this); | |
var last_option = $("option:last", $_this).val(); | |
// if code factor is high then we have to ask for reason for such high factor | |
// also make the reason field required so user must have to enter reason | |
if (last_option == $_this.val() && $_this.closest('.element_list').find("input:checkbox").is(':checked') && $_this.val() > 1) { | |
$_this.closest('.element_list').find(".reason-text").attr('disabled', false).removeClass('hidden').focus(); | |
$_this.closest('.element_list').find(".reason-text").rules('add', {required: true}); | |
} else{ | |
$_this.closest('.element_list').find(".reason-text").attr('disabled', true).addClass('hidden').focus(); | |
} | |
}); | |
}; | |
var addCode = function () { | |
body.on('click', '#btn-add-code', function (e) { | |
e.preventDefault(); | |
var clone = $('.master-sets-option > .sets-panel-body').clone(); | |
clone.find('label,input,select').each(function () { | |
var $_this = $(this); | |
var label_for = $_this.attr('for'); | |
var name = $_this.attr('name'); | |
var id = $_this.attr('id'); | |
if (typeof name !== typeof undefined && name !== false && name == 'code_id[]') { | |
$_this.addClass('sets_chk'); | |
} | |
if (typeof id !== typeof undefined && id !== false && id == 'code') { | |
$_this.attr('id', (id.replace('code', 'code_' + count_code))); | |
} | |
if (typeof id !== typeof undefined && id !== false && id == 'code_factor') { | |
$_this.addClass('code_factor'); | |
} | |
if (typeof id !== typeof undefined && id !== false && id == 'amount') { | |
$_this.addClass('amount'); | |
} | |
if (typeof id !== typeof undefined && id !== false && id == 'code') { | |
$_this.addClass('input-code'); | |
} | |
}); | |
clone.appendTo('.more-sets'); | |
$('.input-code').select2({ | |
allowClear: true, | |
val: null | |
}).on("change", function (e) { | |
// mostly used event, fired to the original element when the value changes | |
}); | |
count_code++; | |
customValidation(); | |
calculateExtraCode('plush'); | |
changeSelectedSetName(); | |
}); | |
}; | |
var removeCode = function () { | |
body.on('click', '.btn-remove-set-item', function () { | |
$(this).closest('.element_list').remove(); | |
calculateAmount(); | |
calculateExtraCode('minus'); | |
changeSelectedSetName(); | |
checkRule(); | |
CodeExclusion.onLoadCheckAction(); | |
}); | |
}; | |
var calculateAmount = function () { | |
var total = 0; | |
var chk_flag = false; | |
$(".sets_chk").each(function () { | |
var $_this = $(this); | |
if (this.checked) { | |
chk_flag = true; | |
var point = $_this.val(); | |
var code_factor = $(this).closest('.element_list').find(".code_factor").val(); | |
var amount = $(this).closest('.element_list').find(".amount").val(); | |
if ($.isNumeric(point) && $.isNumeric(code_factor) && $.isNumeric(amount)) { | |
total = total + (point * code_factor * amount * price_per_points); | |
} | |
$('.payment').html(total.toFixed(2)); | |
} | |
// If there is no code selected then we have to set empty value, this will be happens during edit operation | |
if (chk_flag == false) { | |
$('.payment').html(0.00); | |
} | |
}); | |
// Default value zero needs to set while add the sets are deleted | |
if ($(".sets_chk").length == 0) { | |
$('.payment').html(0.00); | |
} | |
}; | |
var changeCode = function () { | |
body.on('click', '.sets_chk', function (e) { | |
if (!$(this).hasClass('rule_code')) { | |
showReasonBoxForHighFactor(); | |
checkRule(); | |
} | |
calculateAmount(); | |
}); | |
}; | |
var checkRule = function () { | |
// On code change we have to check for applied rule on it | |
console.log('Rules Checking...'); | |
$(".rule_code").each(function () { | |
$(this).attr('checked', false); | |
}); | |
$.ajax({ | |
type: "POST", | |
data: $('#rootwizard input,select,checkbox').serialize(), | |
url: base_url + 'rules/check', | |
success: function (data) { | |
if (data.success == true) { | |
// Need to applied rule code | |
$(".rule-sets").html(data.html); | |
$(".verified-address").html("<i class='glyphicon glyphicon-ok success'></i>") | |
$(".main-address").removeClass('hidden'); | |
} else { | |
showAjaxAlert('alert-danger', data.message); | |
$('#rootwizard').bootstrapWizard('show', 1); | |
$('#patient_street,#patient_city_code,#patient_city').addClass('error'); | |
$(".main-address").addClass('hidden'); | |
} | |
}, error: function (data) { | |
$(".rule-sets").html(''); | |
}, complete: function (data) { | |
validateBillForm(); | |
calculateAmount(); | |
initTooltip(); | |
CodeExclusion.onLoadCheckAction(); | |
} | |
}); | |
} | |
var selectCode = function () { | |
body.on('change', '.input-code', function () { | |
var $_this = $(this); | |
var value = $_this.val().split('####'); | |
// First of all we have to get possible code factor item based on code id | |
// and need to bind that value on code factor dropdown | |
$.ajax({ | |
type: "POST", | |
data: { | |
code_id: value[0], | |
default_value: value[2] | |
}, | |
url: base_url + 'codes/get-code-factor-group', | |
beforeSend: function () { | |
swal({ | |
title: fetching_default_code_factor, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
swal.close(); | |
if (data.success == true) { | |
$_this.closest('.element_list').find(".code_factor").html(data.code_factor); | |
} else { | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, complete: function () { | |
// Need to change checkbox name | |
$_this.prev().attr('name', 'code_id[' + value[0] + ']'); | |
$_this.prev().attr('data-id', value[0]); | |
$_this.prev().attr('data-code', value[4]); | |
$_this.prev().attr('data-text', value[5]); | |
$_this.prev().val(value[1]); | |
//$_this.prev().prop("checked", true); | |
// need to change code factor name | |
$_this.closest('.element_list').find(".code_factor").attr('name', 'code_factor[' + value[0] + ']'); | |
// Need to change amount name | |
$_this.closest('.element_list').find(".amount").attr('name', 'amount[' + value[0] + ']'); | |
$_this.closest('.element_list').find(".amount").val(value[3]); | |
// Need to change reason text name | |
$_this.closest('.element_list').find(".reason-text").attr('name', 'reason[' + value[0] + ']'); | |
$_this.prev().trigger('click'); | |
showReasonBoxForHighFactor(); | |
// | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
}); | |
}; | |
var changeCodeFactor = function () { | |
body.on('change', '.code_factor', function (e) { | |
e.preventDefault(); | |
var $_this = $(this); | |
var last_option = $("option:last", $_this).val(); | |
// if code factor is high then we have to ask for reason for such high factor | |
// also make the reason field required so user must have to enter reason | |
if (last_option == $_this.val() && $_this.closest('.element_list').find("input:checkbox").is(':checked') && $_this.val() > 1) { | |
$_this.closest('.element_list').find(".reason-text").attr('disabled', false).removeClass('hidden').focus(); | |
$_this.closest('.element_list').find(".reason-text").rules('add', {required: true}); | |
} else { | |
$_this.closest('.element_list').find(".reason-text").attr('disabled', true).addClass('hidden').val(''); | |
} | |
calculateAmount(); | |
}); | |
}; | |
var changeAmount = function () { | |
body.on('change', '.amount', function () { | |
calculateAmount(); | |
}); | |
}; | |
var setSave = function () { | |
body.on('click', '#set-save-action', function () { | |
// First of all we have to checked all codes for save or save as | |
checkAllCodes(); | |
var set_id = $('#user_set_id').val(); | |
if (set_id != '') { | |
if (default_set_list.indexOf(set_id) != -1) { | |
swal({ | |
title: default_set_save_warning, | |
text: default_set_save_message, | |
type: "warning", | |
showCancelButton: true, | |
closeOnConfirm: false, | |
showLoaderOnConfirm: false, | |
cancelButtonText: cancel | |
}, | |
function () { | |
swal({ | |
title: set_save_warning, | |
text: enter_set_name, | |
type: "input", | |
showCancelButton: true, | |
closeOnConfirm: false, | |
animation: "slide-from-top", | |
inputPlaceholder: enter_set_name, | |
cancelButtonText: cancel | |
}, | |
function (inputValue) { | |
if (inputValue === false) return false; | |
if (inputValue === "") { | |
swal.showInputError(set_error_message); | |
return false | |
} else { | |
$('#set-name').val(inputValue); | |
} | |
// Ajax call for save as new set | |
$.ajax({ | |
type: "POST", | |
data: $('#set-data input,select,hidden').serialize(), | |
url: base_url + 'set/save-as-new-set', | |
success: function (data) { | |
if (data.success == true) { | |
swal("Nice!", set_success_message + inputValue, "success"); | |
html = '<option value="' + data.set_detail.id + '" selected="selected">' + data.set_detail.name + '</option>'; | |
$('#user_set_id').append(html); | |
//$('#user_set_id').trigger('change'); | |
reloadNewSet(); | |
} else { | |
swal.close(); | |
showAjaxAlert('alert-danger', data.message); | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
}); | |
}); | |
} else { | |
if (localStorage.code_count == 0) { | |
swal("", set_upto_date, "success"); | |
return false; | |
} else { | |
$(".sets_chk").each(function () { | |
var $_this = $(this); | |
if (!this.checked) { | |
$_this.attr('checked', true); | |
} | |
}); | |
swal({ | |
title: set_save_warning, | |
type: "info", | |
showCancelButton: true, | |
closeOnConfirm: false, | |
showLoaderOnConfirm: true, | |
}, | |
function () { | |
$.ajax({ | |
type: "POST", | |
data: $('#set-data input,select,hidden').serialize(), | |
url: base_url + 'set/update', | |
beforeSend: function () { | |
swal({ | |
title: updating_set, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
if (data.success == true) { | |
swal("", data.message, "success"); | |
//$('#user_set_id').trigger('change'); | |
reloadNewSet(); | |
$('#user_set_id option:selected').text(localStorage.set_value); | |
} else { | |
swal.close(); | |
showAjaxAlert('alert-danger', data.message) | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
}); | |
} | |
} | |
} | |
}); | |
}; | |
var saveAsNewSet = function () { | |
body.on('click', '#save-as-new-set-action', function () { | |
// First of all we have to check all codes for save or save as | |
checkAllCodes(); | |
swal({ | |
title: set_save_warning, | |
text: enter_set_name, | |
type: "input", | |
showCancelButton: true, | |
closeOnConfirm: false, | |
animation: "slide-from-top", | |
inputPlaceholder: enter_set_name, | |
cancelButtonText: cancel | |
}, | |
function (inputValue) { | |
if (inputValue === false) return false; | |
if (inputValue === "") { | |
swal.showInputError(set_error_message); | |
return false | |
} else { | |
$('#set-name').val(inputValue); | |
} | |
// Ajax call for save as new set | |
$.ajax({ | |
type: "POST", | |
data: $('#set-data input,select').serialize(), | |
url: base_url + 'set/save-as-new-set', | |
success: function (data) { | |
if (data.success == true) { | |
swal("Nice!", set_success_message + inputValue, "success"); | |
html = '<option value="' + data.set_detail.id + '" selected="selected">' + data.set_detail.name + '</option>'; | |
$('#user_set_id').append(html); | |
//$('#user_set_id').trigger('change'); | |
reloadNewSet(); | |
} else { | |
swal.close(); | |
showAjaxAlert('alert-danger', data.message); | |
} | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
}); | |
}); | |
}; | |
var checkAllCodes = function () { | |
$(".sets_chk").each(function () { | |
$(this).prop('checked', true); | |
}); | |
}; | |
var reloadNewSet = function () { | |
$.ajax({ | |
type: "POST", | |
data: { | |
set_id: $('#user_set_id option:selected').val(), | |
_token: $("[name='_token']").val() | |
}, | |
url: base_url + 'bill/change-set', | |
beforeSend: function () { | |
swal({ | |
title: fetching_set, | |
text: loading, | |
showConfirmButton: false | |
}); | |
}, | |
success: function (data) { | |
swal.close(); | |
$(".user-sets").html(data.html); | |
validateBillForm(); | |
$(".more-sets").html(''); | |
localStorage.code_count = 0; | |
calculateAmount(); | |
}, complete: function () { | |
checkRule(); | |
CodeExclusion.onLoadCheckAction(); | |
}, error: function (jq_xhr, json, errorThrown) { | |
swal.close(); | |
errors_html = displayFormRequestErrors(jq_xhr); | |
showAjaxAlert('alert-danger', errors_html); | |
} | |
}); | |
}; | |
var saveAction = function () { | |
body.on('click', '#save-bill', function () { | |
if ($('input[name^=code_id]:checked').length <= 0) { | |
sweetAlert("Oops...", code_error, "error"); | |
return false; | |
} | |
if ($("#bill-form").valid() == true) { | |
var form = $("#bill-form"); | |
dataChanged = 0; | |
form.submit(); | |
} else { | |
return false; | |
} | |
}); | |
}; | |
var calculateExtraCode = function (option) { | |
if (localStorage.code_count) { | |
if (option == 'plush') { | |
localStorage.code_count = Number(localStorage.code_count) + 1; | |
} else { | |
localStorage.code_count = Number(localStorage.code_count) - 1; | |
} | |
} else { | |
localStorage.code_count = 1; | |
} | |
}; | |
var changeSelectedSetName = function () { | |
if (localStorage.code_count == 1) { | |
var set_value = $('#user_set_id option:selected').text(); | |
localStorage.set_value = set_value; | |
var unsaved_set_value = set_value + unsaved_text; | |
$('#user_set_id option:selected').text(unsaved_set_value); | |
} else if (localStorage.code_count == 0) { | |
$('#user_set_id option:selected').text(localStorage.set_value); | |
} | |
}; | |
var navigateTab = function () { | |
$('a[data-toggle="tab"]').on('show', function (e) { | |
$("#bill-form").valid(); | |
}); | |
}; | |
var setDefaultReason = function () { | |
body.on('blur', '.reason-text', function () { | |
var $_this = $(this); | |
if ($_this.val() == '') { | |
$_this.val(reason_text); | |
} | |
}); | |
}; | |
var initTooltip = function () { | |
globalInitTooltip(); | |
}; | |
var mainAddressCheckOnGoogle = function () { | |
body.on('click', '.map-main-address', function () { | |
var street = $("input[name=patient_street]").val(); | |
var city = $("input[name=patient_city]").val(); | |
var city_code = $("input[name=patient_city_code]").val(); | |
if (street != "" && city != "" && city_code != "") { | |
window.open(base_url + "address-check/" + street + "/" + city_code + "/" + city, '_blank'); | |
} else { | |
sweetAlert("Oops...", google_check_error, "error"); | |
} | |
}); | |
}; | |
var displayMainAddressGoogleCheckLink = function () { | |
body.on('blur', '#patient_street,#patient_city,patient_city_code', function () { | |
var street = $("input[name=patient_street]").val(); | |
var city = $("input[name=patient_city]").val(); | |
var city_code = $("input[name=patient_city_code]").val(); | |
if (street != "" && city != "" && city_code != "") { | |
$('.main-address').removeClass('hidden'); | |
} else { | |
$('.main-address').addClass('hidden'); | |
} | |
}); | |
}; | |
var businessAddressCheckOnGoogle = function () { | |
body.on('click', '.map-billing-address', function () { | |
var street = $("input[name=remote_billing_address_street]").val(); | |
var city = $("input[name=remote_billing_address_city]").val(); | |
var city_code = $("input[name=remote_billing_address_city_code]").val(); | |
if (street != "" && city != "" && city_code != "") { | |
window.open(base_url + "address-check/" + street + "/" + city_code + "/" + city, '_blank'); | |
} else { | |
sweetAlert("Oops...", google_check_error, "error"); | |
} | |
}); | |
}; | |
var displayBusinessAddressGoogleCheckLink = function () { | |
body.on('blur', '#remote-billing-address-street,#remote-billing-address-city,remote-billing-address-city-code', function () { | |
var street = $("input[name=remote_billing_address_street]").val(); | |
var city = $("input[name=remote_billing_address_city]").val(); | |
var city_code = $("input[name=remote_billing_address_city_code]").val(); | |
if (street != "" && city != "" && city_code != "") { | |
$('.billing-address').removeClass('hidden'); | |
} else { | |
$('.billing-address').addClass('hidden'); | |
} | |
}); | |
}; | |
return { | |
initDataTable: function (targeTable, url) { | |
initDataTable(targeTable, url); | |
deleteAction(); | |
payAction(); | |
paymentReminderAction(); | |
paymentWarningAction(); | |
billReminderOption(); | |
}, | |
initInvoiceDataTable: function (targeTable, url) { | |
initInvoiceDataTable(targeTable, url); | |
invoiceDeleteAction(); | |
}, | |
initBillAction: function () { | |
validateBillForm(); | |
customValidation(); | |
changeSets(); | |
changeTemplate(); | |
changeDiagnosis(); | |
selectCode(); | |
addCode(); | |
removeCode(); | |
initWizard(); | |
saveAction(); | |
changeCode(); | |
changeCodeFactor(); | |
changeAmount(); | |
calculateAmount(); | |
addressOptions(); | |
addressSave(); | |
changeAddress(); | |
navigateTab(); | |
setSave(); | |
saveAsNewSet(); | |
setDefaultReason(); | |
initTooltip(); | |
mainAddressCheckOnGoogle(); | |
displayMainAddressGoogleCheckLink(); | |
businessAddressCheckOnGoogle(); | |
displayBusinessAddressGoogleCheckLink(); | |
} | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment