File: /www/wwwroot/healthyton.com/wp-content/plugins/astro-accounting/admin/js/astro-accounting-admin.js
let $ = jQuery;
$(function(){
var ajaxurl = astro_object.ajaxurl;
$('.data-table').DataTable();
/* Rates */
$('body').on('click','.btn-delete-rate',function () {
var id = $(this).data('id');
var postdata = "action=admin_ajax_request¶m=delete_rate&id="+id;
var conf = confirm("Do you want to delete?");
if(conf){
$.post(ajaxurl,postdata,function(response){
data = $.parseJSON(response);
if(data.status == 1){
Swal.fire({
icon: 'info',
title: 'Success',
text: response.message
});
setTimeout(function(){
location.reload();
},1000);
}else{
alert(data.message);
}
});
}
return false;
});
$('#frm-create-rate').validate({
submitHandler:function(){
var postdata = "action=admin_ajax_request¶m=create_rate&";
postdata = postdata + $('#frm-create-rate').serialize();
$('.submit-btn').attr('disabled',true).html('Submitting ...');
$.post(ajaxurl,postdata,function(response){
response = $.parseJSON(response);
if(response.status == 1){
Swal.fire({
title: 'Success',
icon: 'info',
text: response.message
});
setTimeout(function(){
location.href = '/wp-admin/admin.php?page=astro-accounting-rates' ;
},1000);
}else{
Swal.fire({
icon: 'error',
title: 'Oops...',
text: response.message
})
$('.submit-btn').attr('disabled',false).html('Submit');
}
});
}
});
$('body').on('click','.btn-add-rate', function(){
newTr =
"<tr>"+
"<td><input type='number' name='words[]'></td>"+
"<td><input type='number' name='amount[]'></td>"+
"<td><a href='#' class='btn btn-danger btn-sm btn-remove-rate'>Remove</<a></td>"+
"</tr>";
$('table#tbl-rates tbody').append(newTr);
return false;
});
$('body').on('click','.btn-remove-rate', function(){
$(this).closest('tr').remove();
return false;
});
/* Rates */
/* Payments */
$('body').on('click','.btn-delete-payment',function () {
var id = $(this).data('id');
var postdata = "action=admin_ajax_request¶m=delete_payment&id="+id;
var conf = confirm("Do you want to delete?");
if(conf){
$.post(ajaxurl,postdata,function(response){
data = $.parseJSON(response);
if(data.status == 1){
Swal.fire({
icon: 'info',
title: 'Success',
text: response.message
});
setTimeout(function(){
location.reload();
},1000);
}else{
alert(data.message);
}
});
}
return false;
});
$('#frm-create-payment').validate({
submitHandler:function(){
var postdata = "action=admin_ajax_request¶m=create_payment&";
postdata = postdata + $('#frm-create-payment').serialize();
$('.submit-btn').attr('disabled',true).html('Submitting ...');
$.post(ajaxurl,postdata,function(response){
response = $.parseJSON(response);
if(response.status == 1){
Swal.fire({
title: 'Success',
icon: 'info',
html: response.message +
"<br>" +
'<button type="button" role="button" tabindex="0" class="swalPaymentLists customSwalBtn">' + 'Go to Payments' + '</button>' +
'<button type="button" role="button" tabindex="0" class="swalAddNew customSwalBtn">' + 'Add New' + '</button>',
showCancelButton: false,
showConfirmButton: false
});
// setTimeout(function(){
// location.reload();
// },1000);
}else{
Swal.fire({
icon: 'error',
title: 'Oops...',
text: response.message
})
$('.submit-btn').attr('disabled',false).html('Submit');
}
});
}
});
$('body').on('click', '.swalAddNew', function(){
location.reload();
});
$('body').on('click', '.swalPaymentLists', function(){
location.href = '/wp-admin/admin.php?page=astro-accounting-list-payments' ;
});
/* Payments */
});