<?php
    //@ini_set('display_errors','On'); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
    if(!defined('ABSPATH')) exit; // Exit if accessed directly
    global $wpdb;
    if (function_exists( 'mysqli_connect' ) && $wpdb->use_mysqli) {
    } else if (function_exists( 'mysqli_connect' ) && !$wpdb->use_mysqli) {
        ?><div class="nomysqli" style="color:#721c24;background-color:#f8d7da;"><p><strong><?php
            esc_html_e("Bad news. Mysqli is NOT used in your WordPress. So this plugin can NOT be used for your website.");
        ?></strong></p></div><?php
        exit;
    } else if (!function_exists( 'mysqli_connect' ) && !$wpdb->use_mysqli) {
        ?><div class="nomysqli" style="color:#721c24;background-color:#f8d7da;"><p><strong><?php
            esc_html_e("Bad news. Mysqli does NOT exist in your WordPress. So this plugin can NOT be used for your website.");
        ?></strong></p></div><?php
        exit;
    }
    global $dragon_expense_dbResult;
    global $user_ID;
    $dragon_expense_dbResult = null;
    $timezone='';
    $current_user = wp_get_current_user();
    if($current_user === null || $current_user->data->ID === null || intval($current_user->data->ID) <= 0) {
        echo "Invalid User.";exit;
    }
    $userdetails = expenseszyx987_getOneUser(intval($current_user->data->ID));

    if($user_ID && in_array( 'administrator', (array) $current_user->roles ) && (!empty($_POST['expenseszyx987_hidden'])) && $_POST['expenseszyx987_hidden'] === 'Y') {
        $dragon_expense_dbResult = '';

        if($_POST['Submit'] === 'Create Type Category') {
            expenseszyx987_addTypecategory();
        }elseif($_POST['Submit'] === 'Create Type') {
            expenseszyx987_addType();
        } elseif($_POST['Submit'] === 'Create Role') {
            expenseszyx987_addRole();
        } elseif($_POST['Submit'] === 'Create Department') {
            expenseszyx987_addDepartment();
        } elseif($_POST['Submit'] === 'Create Customer Type') {
            expenseszyx987_addCustomertype();
        } elseif($_POST['Submit'] === 'Create Customer') {
            expenseszyx987_addCustomer();
        } elseif($_POST['Submit'] === 'Create Recurring Payment Frequency') {
            expenseszyx987_addRecurringpaymentfrequency();
        } elseif($_POST['Submit'] === 'Create Currency') {
            expenseszyx987_addCurrency();
        } elseif($_POST['Submit'] === 'Create Tax') {
            expenseszyx987_addTax();
        } elseif($_POST['Submit'] === 'Create User') {
            expenseszyx987_addUser();
        } elseif($_POST['Submit'] === 'ENABLE automatically backup database') {
            expenseszyx987_enableAutoBackupDatabaseEveryday();
        } elseif($_POST['Submit'] === 'DISABLE automatically backup database') {
            expenseszyx987_disableAutoBackupDatabaseEveryday();
        } elseif($_POST['Submit'] === 'Backup database now') {
            expenseszyx987_OneTimeBackupDatabaseNow();
        } elseif($_POST['Submit'] === 'Recreate all the stored procedures') {
            expenseszyx987_dropAllStoredprocedures();
        }
    }

    $allexpenses = expenseszyx987_getAllExpenses();
    $activeexpenses = expenseszyx987_getAllExpenses(true);
    $allexpensetypes = expenseszyx987_getAllExpenseTypes();
    $activeexpensetypes = expenseszyx987_getAllExpenseTypes(true);
    $alltypecategories = expenseszyx987_getAllTypecategories();
    $activetypecategories = expenseszyx987_getAllTypecategories(true);
    $alltypes = expenseszyx987_getAllTypes();
    $activetypes = expenseszyx987_getAllTypes(true);
    $allWPusers = expenseszyx987_getAllWPUsers();
    $activeWPusers = expenseszyx987_getAllWPUsers(true);
    $allusers = expenseszyx987_getAllUsers();
    $activeusers = expenseszyx987_getAllUsers(true);
    $allroles = expenseszyx987_getAllRoles();
    $activeroles = expenseszyx987_getAllRoles(true);
    $alldepartments = expenseszyx987_getAllDepartments();
    $activedepartments = expenseszyx987_getAllDepartments(true);
    $activecustomers = expenseszyx987_getAllCustomers(true);
    $allcustomers = expenseszyx987_getAllCustomers();
    $activecustomertypes = expenseszyx987_getAllCustomertypes(true);
    $allcustomertypes = expenseszyx987_getAllCustomertypes();

    $log_Arr = expenseszyx987_getAllLogtypesProcessnamesUserids();
    $log_types = $log_Arr["type"];
    $log_processnames = $log_Arr["processname"];
    $log_userids = $log_Arr["userid"];

    if($dragon_expense_dbResult !== null) {
    ?><div class="updated" style="<?php echo ($dragon_expense_dbResult === '' || strtolower($dragon_expense_dbResult) === 'success. ' || strtolower($dragon_expense_dbResult) === 'success.' || strtolower($dragon_expense_dbResult) === 'success') ? 'color:#155724;background-color:#d4edda;' : 'color:#721c24;background-color:#f8d7da;'; ?>"><p><strong><?php echo ($dragon_expense_dbResult === '' ? esc_html_e('Saved.') : esc_html(sanitize_text_field($dragon_expense_dbResult))); ?></strong></p></div>
    <?php
    }

    $name = '';
    $start = '';
    $end = '';
    $description = '';
    $groupname = '';
    $color = '';
    $name2 = '';
    $start2 = '';
    $end2 = '';
    $description2 = '';

    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
    wp_enqueue_script("jquery-ui-tabs");
    wp_enqueue_script('jquery-ui-datepicker');
    wp_enqueue_script('jquery-ui-dialog');
    wp_enqueue_style('wp-jquery-ui-dialog');
    wp_enqueue_script('jquery-ui-datepicker2', includes_url() . 'js/jquery/ui/datepicker.min.js');
    wp_enqueue_script('custom-script', plugins_url('js/jquery.datetimepicker.full.min.js', __FILE__ ));
    wp_enqueue_style('custom-style', plugins_url('css/jquery.datetimepicker.min.css', __FILE__ )); 
    wp_enqueue_script('custom-script-bootstrap', plugins_url('bootstrap/js/bootstrap.min.js', __FILE__ ));
    wp_enqueue_style('custom-style-bootstrap', plugins_url('bootstrap/css/bootstrap.min.css', __FILE__ ));
    wp_enqueue_script('custom-script-d3', plugins_url('js/d3.v7.min.js', __FILE__ ));

    wp_enqueue_style('custom-style-jqueryui', plugins_url('css/jquery-ui.css', __FILE__ ));
    wp_enqueue_style('custom-style-expenses', plugins_url('css/expenses.css', __FILE__ ));
?><noscript>Your browser does not support JavaScript! Please enable Javascript in your browser and refresh the page!</noscript>
<script>
var expenseszyx987_addproductlocationarray = [], expenseszyx987_editproductlocationarray = [], expenseszyx987_addshippingpolicylocationarray = [], expenseszyx987_addtaxlocationarray = [];
var mediummodalElementContainer = "<div id='mymediummodal' style='display:none;' title=''></div>";
var largemodalElementContainer = "<div id='mylargemodal' data-bs-backdrop='static' data-bs-keyboard='false' class='modal fade' style='z-index: 99999 !important;background-color:white;min-width:100% !important;width:100% !important;height:100% !important;overflow:auto;padding:0px !important;' title='' role='dialog'></div>";
var EXPENSE_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_expense = 1, pg_onload_admin_expense = 1;
var EXPENSEDETAILS_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_expensedetails = 1, pg_onload_admin_expensedetails = 1;
var TYPECATEGORY_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_typecategory = 1, pg_onload_admin_typecategory = 1;
var TYPE_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_type = 1, pg_onload_admin_type = 1;
var ROLE_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_role = 1, pg_onload_admin_role = 1;
var DEPARTMENT_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_department = 1, pg_onload_admin_department = 1;
var USER_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_user = 1, pg_onload_admin_user = 1;
var USERTYPE_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_usertype = 1, pg_onload_admin_usertype = 1;
var LOG_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_log = 1, pg_onload_admin_log = 1;
var TAX_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_tax = 1, pg_onload_admin_tax = 1;
var CURRENCY_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_currency = 1, pg_onload_admin_currency = 1;
var CUSTOMERTYPE_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_customertype = 1, pg_onload_admin_customertype = 1;
var CUSTOMER_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_customer = 1, pg_onload_admin_customer = 1;
var RECURRINGPAYMENTFREQUENCY_ITEMS_PER_PAGE_PRESET_VALUE = '10';
var totalpagenumber_onload_admin_recurringpaymentfrequency = 1, pg_onload_admin_recurringpaymentfrequency = 1;

function expenseszyx987_validString(mystring) {
    if(typeof mystring === 'undefined' || mystring === null) {
        return '';
    }
    return mystring;
}

function expenseszyx987_isEnterSpaceEvent(event) {
    if(event.type === 'keydown') {
        var code = event.charCode || event.keyCode;
        if(code === 32 || code === 13) {
            event.preventDefault();
            return true;
        }
    }
    return false;
}

function expenseszyx987_isClickEnterSpaceEvent(event) {
    if(event.type === 'click') {
        return true;
    } else if(event.type === 'keydown') {
        var code = event.charCode || event.keyCode;
        if(code === 32 || code === 13) {
            event.preventDefault();
            return true;
        }
    }
    return false;
}

//a - amount per page; o - order (asc, desc); pg - page number; st - sortby; n - search expenseor name; r - search expense reason;status - expense status
//f - from date; t - to date;
function expenseszyx987_createPagination(totalpagenumber, topagenumber, itemname) {
    if(totalpagenumber !== parseInt(totalpagenumber, 10) || topagenumber !== parseInt(topagenumber, 10)) {jQuery('div.master_pwrapper > div.master_mypagination').html('');return;}
    var temp = '<ul class="pagination">',i;
    if(topagenumber > totalpagenumber) {topagenumber = 1;totalpagenumber=1;}
    if(totalpagenumber < 7) {
        if(topagenumber===1) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="previous page, button is disabled" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        } else {
            temp += '<li class="page-item prev"><a class="page-link" tabindex="0" aria-label="previous page" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        }
        for(i=1;i<=totalpagenumber;i++) {
            temp += '<li' + (topagenumber===i ? ' class="page-item active" ' : ' class="page-item" ') + '><a class="page-link" role="button" tabindex="0" >' + i + '</a></li>';
        }
        if(topagenumber===totalpagenumber) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="next page, button is disabled" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        } else {
            temp += '<li class="page-item next"><a class="page-link" tabindex="0" aria-label="next page" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        }
    } else if(topagenumber < 4) {
        if(topagenumber===1) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="previous page, button is disabled" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        } else {
            temp += '<li class="page-item prev"><a class="page-link" tabindex="0" aria-label="previous page" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        }
        for(i=1;i<=5;i++) {
            temp += '<li' + (topagenumber===i ? ' class="page-item active" ' : ' class="page-item" ') + '><a class="page-link" role="button" tabindex="0" >' + i + '</a></li>';
        }
        temp += ((totalpagenumber - topagenumber) > 3) ? '<li class="page-item noborder"><a class="page-link" >...</a></li>' : '';
        if(topagenumber===totalpagenumber) {
            temp += '<li class="page-item active" ><a class="page-link" role="button" tabindex="0" >' + totalpagenumber + '</a></li><li class="page-item disabled"><a class="page-link" aria-label="next page, button is disabled" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        } else {
            temp += '<li class="page-item"><a class="page-link" role="button" tabindex="0" >' + totalpagenumber + '</a></li><li class="page-item next"><a class="page-link" tabindex="0" aria-label="next page" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        }
    } else if(topagenumber < (totalpagenumber - 2)) {
        if(topagenumber===1) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="previous page, button is disabled" role="img" ><span aria-hidden="true">&laquo;</span></a></li><li class="page-item active" ><a class="page-link" role="button" tabindex="0" >1</a></li>';
        } else {
            temp += '<li class="page-item prev"><a class="page-link" tabindex="0" aria-label="previous page" role="img" ><span aria-hidden="true">&laquo;</span></a></li><li class="page-item"><a class="page-link" role="button" tabindex="0" >1</a></li>';
        }
        temp += (topagenumber > 4) ? '<li class="page-item noborder"><a class="page-link" >...</a></li>' : '';
        for(i=(topagenumber-2);i<=((topagenumber+2)>(totalpagenumber-1) ? (totalpagenumber-1) : (topagenumber+2));i++) {
            temp += '<li' + (topagenumber===i ? ' class="page-item active" ' : ' class="page-item" ') + '><a class="page-link" role="button" tabindex="0" >' + i + '</a></li>';
        }
        temp += ((totalpagenumber - topagenumber) > 3) ? '<li class="page-item noborder"><a class="page-link" >...</a></li>' : '';
        if(topagenumber===totalpagenumber) {
            temp += '<li class="page-item active"><a class="page-link" role="button" tabindex="0" >' + totalpagenumber + '</a></li><li class="page-item disabled"><a class="page-link" aria-label="next page, button is disabled" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        } else {
            temp += '<li class="page-item"><a class="page-link" role="button" tabindex="0" >' + totalpagenumber + '</a></li><li class="page-item next"><a class="page-link" tabindex="0" aria-label="next page" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        }
    } else if(topagenumber >= (totalpagenumber - 2)) {
        if(topagenumber===1) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="previous page, button is disabled" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        } else {
            temp += '<li class="page-item prev"><a class="page-link" tabindex="0" aria-label="previous page" role="img" ><span aria-hidden="true">&laquo;</span></a></li>';
        }
        temp += '<li' + (topagenumber===1 ? ' class="page-item active" ' : ' class="page-item" ') + '><a class="page-link" role="button" tabindex="0" >1</a></li>';
        temp += ((topagenumber - 1) > 3) ? '<li class="page-item noborder"><a class="page-link" >...</a></li>' : '';
        for(i=(totalpagenumber-4);i<=totalpagenumber;i++) {
            temp += '<li' + (topagenumber===i ? ' class="page-item active" ' : ' class="page-item" ') + '><a class="page-link" role="button" tabindex="0" >' + i + '</a></li>';
        }
        if(topagenumber===totalpagenumber) {
            temp += '<li class="page-item disabled"><a class="page-link" aria-label="next page, button is disabled" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        } else {
            temp += '<li class="page-item next"><a class="page-link" tabindex="0" aria-label="next page" role="img" ><span aria-hidden="true">&raquo;</span></a></li>';
        }
    }
    temp += '</ul>';
    if(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_' + itemname).length > 0) {
        jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_' + itemname).html(temp);
    }
}

function expenseszyx987_showResultOnAjaxReloadedPage(pagenumber, itemname) {
    if(itemname === 'expense') {
        expenseszyx987_getExpensesList(pagenumber);
    } else if(itemname === 'typecategory') {
        expenseszyx987_getTypecategoriesList(pagenumber);
    } else if(itemname === 'type') {
        expenseszyx987_getTypesList(pagenumber);
    } else if(itemname === 'role') {
        expenseszyx987_getRolesList(pagenumber);
    } else if(itemname === 'customertype') {
        expenseszyx987_getCustomertypesList(pagenumber);
    } else if(itemname === 'customer') {
        expenseszyx987_getCustomersList(pagenumber);
    } else if(itemname === 'department') {
        expenseszyx987_getDepartmentsList(pagenumber);
    } else if(itemname === 'user') {
        expenseszyx987_getUsersList(pagenumber);
    } else if(itemname === 'currency') {
        expenseszyx987_getCurrenciesList(pagenumber);
    } else if(itemname === 'tax') {
        expenseszyx987_getTaxesList(pagenumber);
    }
}

function expenseszyx987_updateApprovedValue(element) {
    if(jQuery(element).val() !== '-1') {
        jQuery('select#expenses_expense_approved').val('1');
    }
}

function expenseszyx987_getExpensesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getexpenses:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getExpenses')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getExpenses"};
    dataObj.userid = (jQuery('select#expenses_expense_userid').length === 0 || jQuery('select#expenses_expense_userid').val() === '') ? -1 : parseInt(jQuery('select#expenses_expense_userid').val());
    dataObj.expensetypeid = (jQuery('select#expenses_expense_type').length === 0 || jQuery('select#expenses_expense_type').val() === '') ? -1 : parseInt(jQuery('select#expenses_expense_type').val());
    dataObj.searchreferencenumber = jQuery('input#expenses_expense_referencenumber').val();
    dataObj.searchexpensenotes = jQuery('input#expenses_expense_reason').val();
    dataObj.fromdate = jQuery('input#expenses_expense_fromdate').val();
    dataObj.todate = jQuery('input#expenses_expense_todate').val();
    if(dataObj.fromdate > dataObj.todate) {
        return alert("Error. From date is later than to date.");
    }
    dataObj.searchminexpenseamount = (jQuery('input#expenses_expense_min_amount').length === 0 || jQuery('input#expenses_expense_min_amount').val() === '') ?  -1 : parseFloat(jQuery('input#expenses_expense_min_amount').val());
    dataObj.searchmaxexpenseamount = (jQuery('input#expenses_expense_max_amount').length === 0 || jQuery('input#expenses_expense_max_amount').val() === '') ?  -1 : parseFloat(jQuery('input#expenses_expense_max_amount').val());
    dataObj.searchexpensecustomerid = (jQuery('select#expenses_expense_customer').length === 0 || jQuery('select#expenses_expense_customer').val() === '') ? -1 : parseInt(jQuery('select#expenses_expense_customer').val());
    dataObj.searchexpenseisrecurring = jQuery('select#expenses_expense_isrecurring').val();
    dataObj.mystatus = jQuery('select#expenses_expense_status').val();
    dataObj.amountperpage = jQuery('select#expenses_expense_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_expense_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'userid|asc') {
        dataObj.sortby = 'userid';
        dataObj.order = 'asc';
    } else if(sortby === 'userid|desc') {
        dataObj.sortby = 'userid';
        dataObj.order = 'desc';
    } else if(sortby === 'date|asc') {
        dataObj.sortby = 'expensedate';
        dataObj.order = 'asc';
    } else if(sortby === 'date|desc') {
        dataObj.sortby = 'expensedate';
        dataObj.order = 'desc';
    } else if(sortby === 'expensetype|asc') {
        dataObj.sortby = 'expensetypeid';
        dataObj.order = 'asc';
    } else if(sortby === 'expensetype|desc') {
        dataObj.sortby = 'expensetypeid';
        dataObj.order = 'desc';
    } else {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    }

    jQuery('tbody#expenses_expense').html('');
    jQuery('span#totalexpensequantity').text('');
    jQuery('img#admin_expenselist_loader').show();
    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["expense"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            tempRows += '<tr><td>' + expenseszyx987_validString(objArr[i].id) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expensetypename) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expensecurrencyname) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expenseamount) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expensedate) + '</td>';
            tempRows += '<td><span tabindex="0" style="word-break: normal !important;">' + expenseszyx987_validString(objArr[i].taxrate) + '</span></td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].expenseamountincludetax) === 1 ? '<span tabindex="0" style="color:green;">YES</span></td>' : '<span tabindex="0" style="color:red;">NO</span></td>');
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expensereferencenumber) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].expensenotes) + '</td>';
            tempRows += '<td>' + (parseInt(expenseszyx987_validString(objArr[i].isrecurring)) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].recurringpaymentstartdate) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].recurringpaymentenddate) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].recurringpaymentfrequencyname) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].recurringpaymentdayid === null ? '' : parseInt(objArr[i].recurringpaymentdayid + 1)) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].customername) + '</td>';
            tempRows += '<td>' + (parseInt(expenseszyx987_validString(objArr[i].status)) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">Inactive</span>');
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].username) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].username2) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].userid) + '</td>';
            tempRows += '</tr>';
        }
        jQuery('tbody#expenses_expense').html(tempRows);
        jQuery('input.datepicker').datepicker({changeMonth:true,changeYear:true,yearRange:"1900:c+10",dateFormat:"yy-mm-dd"});
        var totalExpenseQuantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalexpensequantity').text(totalExpenseQuantity);

        totalExpenseQuantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_expense_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(EXPENSE_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_expense = Math.ceil(totalExpenseQuantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_expense, pagenumber , 'expense');
        }
        jQuery('img#admin_expenselist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Expense request failed: " + textStatus );
    });
}

function expenseszyx987_resetExpensesSearchParameters() {
    jQuery('select#expenses_expense_userid').val('-1');
    jQuery('select#expenses_expense_type').val('-1');
    jQuery('input#expenses_expense_fromdate').val('');
    jQuery('input#expenses_expense_todate').val('');
    jQuery('input#expenses_expense_referencenumber').val('');
    jQuery('input#expenses_expense_notes').val('');
    jQuery('select#expenses_expense_status').val('-1');
    jQuery('select#expenses_expense_itemsperpage').val('-1');
    jQuery('select#expenses_expense_sortby').val('-1');
    jQuery('input#expenses_expense_min_amount').val('');
    jQuery('input#expenses_expense_max_amount').val('');
    jQuery('select#expenses_expense_customer').val('-1');
    jQuery('select#expenses_expense_isrecurring').val('-1');
}

function expenseszyx987_getTypecategoriesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_gettypecategories:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getTypecategories')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getTypecategories"};
    dataObj.searchwords = jQuery('input#expenses_typecategory_name').val();
    dataObj.typecategorystatus = jQuery('select#expenses_typecategory_status').val();
    dataObj.amountperpage = jQuery('select#expenses_typecategory_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_typecategory_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_typecategory').html('');
    jQuery('span#totaltypecategoryquantity').text('');
    jQuery('img#admin_typecategorylist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["typecategory"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editTypecategory(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_typecategory_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_typecategory_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveTypecategory(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_typecategory_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_typecategory_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_typecategory_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_typecategory_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_typecategory_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_typecategory_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_typecategory_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_typecategory_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_typecategory_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_typecategory_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_typecategory').html(tempRows);
        var totaltypecategoryquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totaltypecategoryquantity').text(totaltypecategoryquantity);
        totaltypecategoryquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_typecategory_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(TYPECATEGORY_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_typecategory = Math.ceil(totaltypecategoryquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_typecategory, pagenumber , 'typecategory');
        }
        jQuery('img#admin_typecategorylist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request type category list failed: " + textStatus );
    });
}

function expenseszyx987_resetTypecategoriesSearchParameters() {
    jQuery('input#expenses_typecategory_name').val('');
    jQuery('select#expenses_typecategory_status').val('-1');
    jQuery('select#expenses_typecategory_itemsperpage').val('-1');
    jQuery('select#expenses_typecategory_sortby').val('-1');
}

function expenseszyx987_editTypecategory(typecategoryid, containerid) {
    if(jQuery('.' + containerid + typecategoryid).length > 0) {
        jQuery('.' + containerid + typecategoryid).toggle();
    }
}

function expenseszyx987_saveTypecategory(typecategoryid, selectid) {
    var typecategoryname = '';
    if(jQuery('input#' + selectid + 'name_' + typecategoryid).length > 0) {
        typecategoryname = jQuery('input#' + selectid + 'name_' + typecategoryid).val();
    }
    var typecategorydescription = '';
    if(jQuery('input#' + selectid + 'description_' + typecategoryid).length > 0) {
        typecategorydescription = jQuery('input#' + selectid + 'description_' + typecategoryid).val();
    }
    var typecategorystatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + typecategoryid).length > 0) {
        typecategorystatus = jQuery('select#' + selectid + 'status_' + typecategoryid).val();
    }
    if(typecategoryname === '' && typecategorydescription === '' && (typecategorystatus !== '0' && typecategorystatus !== '1')) {
        return alert("Please enter a value.");
    }
    if(typecategoryname === '' || (typecategorystatus !== '0' && typecategorystatus !== '1')) {
        return alert("Name and status are required.");
    }
    var typecategorystatusvalue = parseInt(typecategorystatus);
    var dataObj = {expenseszyx987_hidden_security_savetypecategory:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveTypecategory')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveTypecategory",id: typecategoryid};
    dataObj.name = typecategoryname;
    dataObj.description = typecategorydescription;
    dataObj.status = typecategorystatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getTypecategoriesList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Type category update failed: " + textStatus );
    });
}

function expenseszyx987_getTypesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_gettypes:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getTypes')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getTypes"};
    dataObj.searchwords = jQuery('input#expenses_type_name').val();
    dataObj.typestatus = jQuery('select#expenses_type_status').val();
    dataObj.amountperpage = jQuery('select#expenses_type_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_type_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_type').html('');
    jQuery('span#totaltypequantity').text('');
    jQuery('img#admin_typelist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["type"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editType(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_type_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_type_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveType(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_type_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_type_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_type_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_type_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_type_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_type_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_type_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';

            tempRows += '<td>' + expenseszyx987_validString(objArr[i].typecategoryname);
            tempRows += '<div style="display:none;" class="expenses_type_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_type_typecategoryid_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_type_typecategoryid_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Please choose one...</option>';
            <?php foreach ($activetypecategories as $typecategory) { ?>
            <?php $typecategory_status_temp = $typecategory->status === '1' ? '' : 'color:grey;'; ?>
            tempRows += "<option " + (expenseszyx987_validString(objArr[i].typecategoryid) === <?php echo $typecategory->id === null ? 0 : intval($typecategory->id); ?> ? 'selected' : '') + " value='<?php echo intval($typecategory->id); ?>' style='<?php echo esc_html($typecategory_status_temp); ?>'><?php echo esc_html($typecategory->name); ?></option>";
            <?php } ?>
            tempRows += '</select></div>';
            tempRows += '</td>';

            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_type_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_type_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_type_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_type').html(tempRows);
        var totaltypequantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totaltypequantity').text(totaltypequantity);
        totaltypequantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_type_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(TYPE_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totaltypequantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_type, pagenumber , 'type');
        }
        jQuery('img#admin_typelist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request type list failed: " + textStatus );
    });
}

function expenseszyx987_resetTypesSearchParameters() {
    jQuery('input#expenses_type_name').val('');
    jQuery('select#expenses_type_status').val('-1');
    jQuery('select#expenses_type_itemsperpage').val('-1');
    jQuery('select#expenses_type_sortby').val('-1');
}

function expenseszyx987_editType(typeid, containerid) {
    if(jQuery('.' + containerid + typeid).length > 0) {
        jQuery('.' + containerid + typeid).toggle();
    }
}

function expenseszyx987_saveType(typeid, selectid) {
    var typename = '';
    if(jQuery('input#' + selectid + 'name_' + typeid).length > 0) {
        typename = jQuery('input#' + selectid + 'name_' + typeid).val();
    }
    var typedescription = '';
    if(jQuery('input#' + selectid + 'description_' + typeid).length > 0) {
        typedescription = jQuery('input#' + selectid + 'description_' + typeid).val();
    }
    var typecategoryid = '-1';
    if(jQuery('select#' + selectid + 'typecategoryid_' + typeid).length > 0) {
        typecategoryid = jQuery('select#' + selectid + 'typecategoryid_' + typeid).val();
    }
    var typestatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + typeid).length > 0) {
        typestatus = jQuery('select#' + selectid + 'status_' + typeid).val();
    }
    if(typename === '' && typedescription === '' && typecategoryid === '-1' && (typestatus !== '0' && typestatus !== '1')) {
        return alert("Please enter a value.");
    }
    if(typename === '' || (typestatus !== '0' && typestatus !== '1') || typecategoryid === '-1') {
        return alert("Name, type category, and status are required.");
    }
    var typestatusvalue = parseInt(typestatus);
    var dataObj = {expenseszyx987_hidden_security_savetype:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveType')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveType",id: typeid};
    dataObj.name = typename;
    dataObj.description = typedescription;
    dataObj.typecategoryid = typecategoryid;
    dataObj.status = typestatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getTypesList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Type update failed: " + textStatus );
    });
}

function expenseszyx987_getRolesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getroles:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getRoles')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getRoles"};
    dataObj.searchwords = jQuery('input#expenses_role_name').val();
    dataObj.rolestatus = jQuery('select#expenses_role_status').val();
    dataObj.amountperpage = jQuery('select#expenses_role_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_role_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_role').html('');
    jQuery('span#totalrolequantity').text('');
    jQuery('img#admin_rolelist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["role"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editRole(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_role_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_role_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveRole(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_role_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_role_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_role_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_role_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_role_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_role_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_role_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_role_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_role_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_role_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_role').html(tempRows);
        var totalrolequantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalrolequantity').text(totalrolequantity);
        totalrolequantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_role_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(ROLE_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totalrolequantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_role, pagenumber , 'role');
        }
        jQuery('img#admin_rolelist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request role list failed: " + textStatus );
    });
}

function expenseszyx987_resetRolesSearchParameters() {
    jQuery('input#expenses_role_name').val('');
    jQuery('select#expenses_role_status').val('-1');
    jQuery('select#expenses_role_itemsperpage').val('-1');
    jQuery('select#expenses_role_sortby').val('-1');
}

function expenseszyx987_editRole(roleid, containerid) {
    if(jQuery('.' + containerid + roleid).length > 0) {
        jQuery('.' + containerid + roleid).toggle();
    }
}

function expenseszyx987_saveRole(roleid, selectid) {
    var rolename = '';
    if(jQuery('input#' + selectid + 'name_' + roleid).length > 0) {
        rolename = jQuery('input#' + selectid + 'name_' + roleid).val();
    }
    var roledescription = '';
    if(jQuery('input#' + selectid + 'description_' + roleid).length > 0) {
        roledescription = jQuery('input#' + selectid + 'description_' + roleid).val();
    }
    var rolestatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + roleid).length > 0) {            
        rolestatus = jQuery('select#' + selectid + 'status_' + roleid).val();
    }
    if(rolename === '' && roledescription === '' && (rolestatus !== '0' && rolestatus !== '1')) {
        return alert("Please enter a value.");
    }
    if(rolename === '' || (rolestatus !== '0' && rolestatus !== '1')) {
        return alert("Name and status are required.");
    }
    var rolestatusvalue = parseInt(rolestatus);
    var dataObj = {expenseszyx987_hidden_security_saverole:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveRole')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveRole",id: roleid};
    dataObj.name = rolename;
    dataObj.description = roledescription;
    dataObj.status = rolestatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getRolesList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Role update failed: " + textStatus );
    });
}

function expenseszyx987_getTaxesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_gettaxes:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getTaxes')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getTaxes"};
    dataObj.searchwords = jQuery('input#expenses_tax_name').val();
    dataObj.taxstatus = jQuery('select#expenses_tax_status').val();
    dataObj.amountperpage = jQuery('select#expenses_tax_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_tax_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';      
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }
    jQuery('tbody#expenses_tax').html('');
    jQuery('span#totaltaxquantity').text('');
    jQuery('img#admin_taxlist_loader').show();
    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["tax"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            temp_button = '<a href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editTax(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_tax_container_\');">Edit</a>';                    
            temp_button += '<a href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_tax_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveTax(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_tax_\');">Save</a>';                    

            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_tax_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_tax_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_tax_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].rate);
            tempRows += '<div style="display:none;" class="expenses_tax_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_tax_rate_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_tax_rate_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].rate).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_tax_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_tax_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_tax_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';            
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_tax_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_tax_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_tax_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>Active</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>Not Active</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_tax').html(tempRows);
        var totaltaxquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totaltaxquantity').text(totaltaxquantity);
        totaltaxquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_tax_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(TAX_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_tax = Math.ceil(totaltaxquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_tax, pagenumber , 'tax');
        }
        jQuery('img#admin_taxlist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request tax list failed: " + textStatus );
    });
}

function expenseszyx987_resetTaxesSearchParameters() {
    jQuery('input#expenses_tax_name').val('');        
    jQuery('select#expenses_tax_status').val('-1');
    jQuery('select#expenses_tax_itemsperpage').val('-1');
    jQuery('select#expenses_tax_sortby').val('-1');
}

function expenseszyx987_editTax(taxid, containerid) {
    if(jQuery('.' + containerid + taxid).length > 0) {
        jQuery('.' + containerid + taxid).toggle();
    }
}

function expenseszyx987_saveTax(taxid, selectid) {
    var taxname = '';
    if(jQuery('input#' + selectid + 'name_' + taxid).length > 0) {
        taxname = jQuery('input#' + selectid + 'name_' + taxid).val();
    }
    var taxrate_string = '';
    if(jQuery('input#' + selectid + 'rate_' + taxid).length > 0) {
        taxrate_string = jQuery('input#' + selectid + 'rate_' + taxid).val();
    }
    taxrate = -1;
    if(taxrate_string !== '') {
        taxrate = parseFloat(taxrate_string);
    }
    var taxdescription = '';
    if(jQuery('input#' + selectid + 'description_' + taxid).length > 0) {
        taxdescription = jQuery('input#' + selectid + 'description_' + taxid).val();
    }
    var taxstatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + taxid).length > 0) {
        taxstatus = jQuery('select#' + selectid + 'status_' + taxid).val();
    }
    if(taxname === '' && taxrate_string === '' && taxdescription === '' && taxstatus === '-1') {
        return alert("Please enter a value.");
    }
    if(taxname === '' || taxrate_string === '-1' || taxstatus === '-1') {
        return alert("Name, rate, and status are required.");
    }
    if(taxrate < 0) {
        return alert("Tax rate should be no less than 0.");
    }
    var taxstatusvalue = parseInt(taxstatus);
    var dataObj = {expenseszyx987_hidden_security_savetax:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveTax')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveTax",id: taxid};
    dataObj.name = taxname;
    dataObj.rate = taxrate;
    dataObj.description = taxdescription;
    dataObj.status = taxstatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        alert(mydata);
        if(mydata === 'Success') {
            expenseszyx987_getTaxesList();
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Tax update failed: " + textStatus );
    });
}

function expenseszyx987_getCurrenciesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getcurrencies:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getCurrencies')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getCurrencies"};
    dataObj.searchwords = jQuery('input#expenses_currency_name').val();
    dataObj.currencystatus = jQuery('select#expenses_currency_status').val();
    dataObj.amountperpage = jQuery('select#expenses_currency_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_currency_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';      
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }
    jQuery('tbody#expenses_currency').html('');
    jQuery('span#totalcurrencyquantity').text('');
    jQuery('img#admin_currencylist_loader').show();
    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["currency"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            temp_button = '<a href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editCurrency(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_currency_container_\');">Edit</a>';
            temp_button += '<a href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveCurrency(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_currency_\');">Save</a>';

            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_currency_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_currency_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].sign);
            tempRows += '<div style="display:none;" class="expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_currency_sign_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_currency_sign_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].sign).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].isocurrencycode);
            tempRows += '<div style="display:none;" class="expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_currency_isocurrencycode_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_currency_isocurrencycode_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].isocurrencycode).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_currency_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_currency_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';            
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_currency_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_currency_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_currency_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>Active</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>Not Active</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_currency').html(tempRows);
        var totalcurrencyquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalcurrencyquantity').text(totalcurrencyquantity);
        totalcurrencyquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_currency_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(CURRENCY_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_currency = Math.ceil(totalcurrencyquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_currency, pagenumber , 'currency');
        }
        jQuery('img#admin_currencylist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request currency list failed: " + textStatus );
    });
}

function expenseszyx987_resetCurrenciesSearchParameters() {
    jQuery('input#expenses_currency_name').val('');
    jQuery('select#expenses_currency_status').val('-1');
    jQuery('select#expenses_currency_itemsperpage').val('-1');
    jQuery('select#expenses_currency_sortby').val('-1');
}

function expenseszyx987_editCurrency(currencyid, containerid) {
    if(jQuery('.' + containerid + currencyid).length > 0) {
        jQuery('.' + containerid + currencyid).toggle();
    }
}

function expenseszyx987_saveCurrency(currencyid, selectid) {
    var currencyname = '';
    if(jQuery('input#' + selectid + 'name_' + currencyid).length > 0) {
        currencyname = jQuery('input#' + selectid + 'name_' + currencyid).val();
    }
    var currencysign = '';
    if(jQuery('input#' + selectid + 'sign_' + currencyid).length > 0) {
        currencysign = jQuery('input#' + selectid + 'sign_' + currencyid).val();
    }
    var isocurrencycode = '';
    if(jQuery('input#' + selectid + 'sign_' + currencyid).length > 0) {
        isocurrencycode = jQuery('input#' + selectid + 'isocurrencycode_' + currencyid).val();
    }
    var currencydescription = '';
    if(jQuery('input#' + selectid + 'description_' + currencyid).length > 0) {
        currencydescription = jQuery('input#' + selectid + 'description_' + currencyid).val();
    }
    var currencystatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + currencyid).length > 0) {
        currencystatus = jQuery('select#' + selectid + 'status_' + currencyid).val();
    }
    if(currencyname === '' && isocurrencycode === '-1' && currencysign === '-1' && currencydescription === '' && currencystatus === '-1') {
        return alert("Please enter a value.");
    }
    if(currencyname === '' || isocurrencycode === '-1' || currencysign === '-1' || currencystatus === '-1') {
        return alert("Name, sign, isocurrencycode, and status are required.");
    }
    var currencystatusvalue = parseInt(currencystatus);
    var dataObj = {expenseszyx987_hidden_security_savecurrency:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveCurrency')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveCurrency",id: currencyid};
    dataObj.name = currencyname;
    dataObj.sign = currencysign;
    dataObj.isocurrencycode = isocurrencycode;
    dataObj.description = currencydescription;
    dataObj.status = currencystatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        alert(mydata);
        if(mydata === 'Success') {
            expenseszyx987_getCurrenciesList();
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Currency update failed: " + textStatus );
    });
}

function expenseszyx987_getCustomertypesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getcustomertypes:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getCustomertypes')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getCustomertypes"};
    dataObj.searchwords = jQuery('input#expenses_customertype_name').val();
    dataObj.customertypestatus = jQuery('select#expenses_customertype_status').val();
    dataObj.amountperpage = jQuery('select#expenses_customertype_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_customertype_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_customertype').html('');
    jQuery('span#totalcustomertypequantity').text('');
    jQuery('img#admin_customertypelist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["customertype"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editCustomertype(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_customertype_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_customertype_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveCustomertype(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_customertype_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_customertype_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_customertype_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customertype_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_customertype_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_customertype_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customertype_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_customertype_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_customertype_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customertype_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_customertype').html(tempRows);
        var totalcustomertypequantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalcustomertypequantity').text(totalcustomertypequantity);
        totalcustomertypequantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_customertype_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(CUSTOMERTYPE_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totalcustomertypequantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_customertype, pagenumber , 'customertype');
        }
        jQuery('img#admin_customertypelist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request customer type list failed: " + textStatus );
    });
}

function expenseszyx987_resetCustomertypesSearchParameters() {
    jQuery('input#expenses_customertype_name').val('');
    jQuery('select#expenses_customertype_status').val('-1');
    jQuery('select#expenses_customertype_itemsperpage').val('-1');
    jQuery('select#expenses_customertype_sortby').val('-1');
}

function expenseszyx987_editCustomertype(customertypeid, containerid) {
    if(jQuery('.' + containerid + customertypeid).length > 0) {
        jQuery('.' + containerid + customertypeid).toggle();
    }
}

function expenseszyx987_saveCustomertype(customertypeid, selectid) {
    var customertypename = '';
    if(jQuery('input#' + selectid + 'name_' + customertypeid).length > 0) {
        customertypename = jQuery('input#' + selectid + 'name_' + customertypeid).val();
    }
    var customertypedescription = '';
    if(jQuery('input#' + selectid + 'description_' + customertypeid).length > 0) {
        customertypedescription = jQuery('input#' + selectid + 'description_' + customertypeid).val();
    }
    var customertypestatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + customertypeid).length > 0) {
        customertypestatus = jQuery('select#' + selectid + 'status_' + customertypeid).val();
    }
    if(customertypename === '' && customertypedescription === '' && customertypestatus === '-1') {
        return alert("Please enter a value.");
    }
    if(customertypename === '' || customertypestatus === '-1') {
        return alert("Name and status are required.");
    }
    var customertypestatusvalue = parseInt(customertypestatus);
    var dataObj = {expenseszyx987_hidden_security_savecustomertype:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveCustomertype')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveCustomertype",id: customertypeid};
    dataObj.name = customertypename;
    dataObj.description = customertypedescription;
    dataObj.status = customertypestatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getCustomertypesList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Customer type update failed: " + textStatus );
    });
}

function expenseszyx987_getCustomersList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getcustomers:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getCustomers')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getCustomers"};
    dataObj.searchwords = jQuery('input#expenses_customer_name').val();
    dataObj.customertypeid = jQuery('select#expenses_customer_customertype').val();
    dataObj.customerstatus = jQuery('select#expenses_customer_status').val();
    dataObj.amountperpage = jQuery('select#expenses_customer_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_customer_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_customer').html('');
    jQuery('span#totalcustomerquantity').text('');
    jQuery('img#admin_customerlist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["customer"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editCustomer(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_customer_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_customer_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveCustomer(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_customer_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_customer_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_customer_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customer_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_customer_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_customer_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customer_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';

            tempRows += '<td>' + expenseszyx987_validString(objArr[i].customertypename);
            tempRows += '<div style="display:none;" class="expenses_customer_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_customer_customertypeid_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customer_customertypeid_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Please choose one...</option>';
            <?php foreach ($activecustomertypes as $activecustomertype) { ?>
            <?php $customertype_status_temp = $activecustomertype->status === '1' ? '' : 'color:grey;'; ?>
            tempRows += "<option " + (expenseszyx987_validString(objArr[i].customertypeid) === <?php echo $activecustomertype->id === null ? 0 : intval($activecustomertype->id); ?> ? 'selected' : '') + " value='<?php echo intval($activecustomertype->id); ?>' style='<?php echo esc_html($customertype_status_temp); ?>'><?php echo esc_html($activecustomertype->name); ?></option>";
            <?php } ?>
            tempRows += '</select></div>';
            tempRows += '</td>';

            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_customer_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_customer_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_customer_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_customer').html(tempRows);
        var totalcustomerquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalcustomerquantity').text(totalcustomerquantity);
        totalcustomerquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_customer_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(CUSTOMER_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totalcustomerquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_customer, pagenumber , 'customer');
        }
        jQuery('img#admin_customerlist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request customer list failed: " + textStatus );
    });
}

function expenseszyx987_resetCustomersSearchParameters() {
    jQuery('input#expenses_customer_name').val('');
    jQuery('select#expenses_customer_status').val('-1');
    jQuery('select#expenses_customer_customertype').val('-1');
    jQuery('select#expenses_customer_itemsperpage').val('-1');
    jQuery('select#expenses_customer_sortby').val('-1');
}

function expenseszyx987_editCustomer(customerid, containerid) {
    if(jQuery('.' + containerid + customerid).length > 0) {
        jQuery('.' + containerid + customerid).toggle();
    }
}

function expenseszyx987_saveCustomer(customerid, selectid) {
    var customername = '';
    if(jQuery('input#' + selectid + 'name_' + customerid).length > 0) {
        customername = jQuery('input#' + selectid + 'name_' + customerid).val();
    }
    var customerdescription = '';
    if(jQuery('input#' + selectid + 'description_' + customerid).length > 0) {
        customerdescription = jQuery('input#' + selectid + 'description_' + customerid).val();
    }
    var customerstatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + customerid).length > 0) {
        customerstatus = jQuery('select#' + selectid + 'status_' + customerid).val();
    }
    var customertypeid = '-1';
    if(jQuery('select#' + selectid + 'customertypeid_' + customerid).length > 0) {
        customertypeid = jQuery('select#' + selectid + 'customertypeid_' + customerid).val();
    }
    if(customername === '' && customerdescription === '' && customerstatus === '-1') {
        return alert("Please enter a value.");
    }
    if(customername === '' || customerstatus === '-1') {
        return alert("Name and status are required.");
    }
    var customerstatusvalue = parseInt(customerstatus);
    var dataObj = {expenseszyx987_hidden_security_savecustomer:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveCustomer')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveCustomer",id: customerid};
    dataObj.name = customername;
    dataObj.description = customerdescription;
    dataObj.status = customerstatusvalue;
    dataObj.customertypeid = customertypeid;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getCustomersList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Customer update failed: " + textStatus );
    });
}

function expenseszyx987_getRecurringpaymentfrequenciesList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getrecurringpaymentfrequencies:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getRecurringpaymentfrequencies')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getRecurringpaymentfrequencies"};
    dataObj.searchwords = jQuery('input#expenses_recurringpaymentfrequency_name').val();
    dataObj.recurringpaymentfrequencystatus = jQuery('select#expenses_recurringpaymentfrequency_status').val();
    dataObj.amountperpage = jQuery('select#expenses_recurringpaymentfrequency_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_recurringpaymentfrequency_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_recurringpaymentfrequency').html('');
    jQuery('span#totalrecurringpaymentfrequencyquantity').text('');
    jQuery('img#admin_recurringpaymentfrequencylist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["recurringpaymentfrequency"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editRecurringpaymentfrequency(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_recurringpaymentfrequency_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_recurringpaymentfrequency_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveRecurringpaymentfrequency(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_recurringpaymentfrequency_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_recurringpaymentfrequency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_recurringpaymentfrequency_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_recurringpaymentfrequency_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_recurringpaymentfrequency_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_recurringpaymentfrequency_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_recurringpaymentfrequency_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_recurringpaymentfrequency_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_recurringpaymentfrequency_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_recurringpaymentfrequency_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_recurringpaymentfrequency').html(tempRows);
        var totalrecurringpaymentfrequencyquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalrecurringpaymentfrequencyquantity').text(totalrecurringpaymentfrequencyquantity);
        totalrecurringpaymentfrequencyquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_recurringpaymentfrequency_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(RECURRINGPAYMENTFREQUENCY_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totalrecurringpaymentfrequencyquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_recurringpaymentfrequency, pagenumber , 'recurringpaymentfrequency');
        }
        jQuery('img#admin_recurringpaymentfrequencylist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request recurringpaymentfrequency list failed: " + textStatus );
    });
}

function expenseszyx987_resetRecurringpaymentfrequenciesSearchParameters() {
    jQuery('input#expenses_recurringpaymentfrequency_name').val('');
    jQuery('select#expenses_recurringpaymentfrequency_status').val('-1');
    jQuery('select#expenses_recurringpaymentfrequency_itemsperpage').val('-1');
    jQuery('select#expenses_recurringpaymentfrequency_sortby').val('-1');
}

function expenseszyx987_editRecurringpaymentfrequency(recurringpaymentfrequencyid, containerid) {
    if(jQuery('.' + containerid + recurringpaymentfrequencyid).length > 0) {
        jQuery('.' + containerid + recurringpaymentfrequencyid).toggle();
    }
}

function expenseszyx987_saveRecurringpaymentfrequency(recurringpaymentfrequencyid, selectid) {
    var recurringpaymentfrequencyname = '';
    if(jQuery('input#' + selectid + 'name_' + recurringpaymentfrequencyid).length > 0) {
        recurringpaymentfrequencyname = jQuery('input#' + selectid + 'name_' + recurringpaymentfrequencyid).val();
    }
    var recurringpaymentfrequencydescription = '';
    if(jQuery('input#' + selectid + 'description_' + recurringpaymentfrequencyid).length > 0) {
        recurringpaymentfrequencydescription = jQuery('input#' + selectid + 'description_' + recurringpaymentfrequencyid).val();
    }
    var recurringpaymentfrequencystatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + recurringpaymentfrequencyid).length > 0) {
        recurringpaymentfrequencystatus = jQuery('select#' + selectid + 'status_' + recurringpaymentfrequencyid).val();
    }
    if(recurringpaymentfrequencyname === '' && recurringpaymentfrequencydescription === '' && recurringpaymentfrequencystatus === '-1') {
        return alert("Please enter a value.");
    }
    if(recurringpaymentfrequencyname === '' || recurringpaymentfrequencystatus === '-1') {
        return alert("Name and status are required.");
    }
    var recurringpaymentfrequencystatusvalue = parseInt(recurringpaymentfrequencystatus);
    var dataObj = {expenseszyx987_hidden_security_saverecurringpaymentfrequency:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveRecurringpaymentfrequency')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveRecurringpaymentfrequency",id: recurringpaymentfrequencyid};
    dataObj.name = recurringpaymentfrequencyname;
    dataObj.description = recurringpaymentfrequencydescription;
    dataObj.status = recurringpaymentfrequencystatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getRecurringpaymentfrequenciesList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Recurringpaymentfrequency update failed: " + textStatus );
    });
}

function expenseszyx987_getDepartmentsList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getdepartments:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getDepartments')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getDepartments"};
    dataObj.searchwords = jQuery('input#expenses_department_name').val();
    dataObj.departmentstatus = jQuery('select#expenses_department_status').val();
    dataObj.amountperpage = jQuery('select#expenses_department_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_department_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'name|asc') {
        dataObj.sortby = 'name';
        dataObj.order = 'asc';
    } else if(sortby === 'name|desc') {
        dataObj.sortby = 'name';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';      
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_department').html('');
    jQuery('span#totaldepartmentquantity').text('');
    jQuery('img#admin_departmentlist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["department"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editDepartment(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_department_container_\');">Edit</a>';
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_department_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveDepartment(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_department_\');">Save</a>';
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].name);
            tempRows += '<div style="display:none;" class="expenses_department_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_department_name_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_department_name_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].name).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td><td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_department_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_department_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_department_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';

            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_department_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_department_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_department_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td></tr>';
        }
        jQuery('tbody#expenses_department').html(tempRows);
        var totaldepartmentquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totaldepartmentquantity').text(totaldepartmentquantity);
        totaldepartmentquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_department_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(DEPARTMENT_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_type = Math.ceil(totaldepartmentquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_department, pagenumber , 'department');
        }
        jQuery('img#admin_departmentlist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request department list failed: " + textStatus );
    });
}

function expenseszyx987_resetDepartmentsSearchParameters() {
    jQuery('input#expenses_department_name').val('');
    jQuery('select#expenses_department_status').val('-1');
    jQuery('select#expenses_department_itemsperpage').val('-1');
    jQuery('select#expenses_department_sortby').val('-1');
}

function expenseszyx987_editDepartment(departmentid, containerid) {
    if(jQuery('.' + containerid + departmentid).length > 0) {
        jQuery('.' + containerid + departmentid).toggle();
    }
}

function expenseszyx987_saveDepartment(departmentid, selectid) {
    var departmentname = '';
    if(jQuery('input#' + selectid + 'name_' + departmentid).length > 0) {
        departmentname = jQuery('input#' + selectid + 'name_' + departmentid).val();
    }
    var departmentdescription = '';
    if(jQuery('input#' + selectid + 'description_' + departmentid).length > 0) {
        departmentdescription = jQuery('input#' + selectid + 'description_' + departmentid).val();
    }
    var departmentstatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + departmentid).length > 0) {
        departmentstatus = jQuery('select#' + selectid + 'status_' + departmentid).val();
    }
    if(departmentname === '' && departmentdescription === '' && departmentstatus === '-1') {
        return alert("Please enter a value.");
    }
    if(departmentname === '' || departmentstatus === '-1') {
        return alert("Name and status are required.");
    }
    var departmentstatusvalue = parseInt(departmentstatus);
    var dataObj = {expenseszyx987_hidden_security_savedepartment:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveDepartment')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveDepartment",id: departmentid};
    dataObj.name = departmentname;
    dataObj.description = departmentdescription;
    dataObj.status = departmentstatusvalue;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getDepartmentsList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Department update failed: " + textStatus );
    });
}

function expenseszyx987_getUsersList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getusers:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getUsers')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getUsers"};
    dataObj.userid = (jQuery('select#expenses_user_userid').length === 0 || jQuery('select#expenses_user_userid').val() === '') ? -1 : parseInt(jQuery('select#expenses_user_userid').val());
    dataObj.userfullname = jQuery('input#expenses_user_userfullname').val();
    dataObj.email = jQuery('input#expenses_user_email').val();
    dataObj.reportto = jQuery('select#expenses_user_reportto').val();
    dataObj.canreadinadminpage = jQuery('select#expenses_user_canreadinadminpage').val();
    dataObj.cancreateinadminpage = jQuery('select#expenses_user_cancreateinadminpage').val();
    dataObj.caneditinadminpage = jQuery('select#expenses_user_caneditinadminpage').val();
    dataObj.canactivateinadminpage = jQuery('select#expenses_user_canactivateinadminpage').val();
    dataObj.candeactivateinadminpage = jQuery('select#expenses_user_candeactivateinadminpage').val();
    dataObj.roleid = jQuery('select#expenses_user_roleid').val();
    dataObj.departmentid = jQuery('select#expenses_user_departmentid').val();
    dataObj.userstatus = jQuery('select#expenses_user_status').val();
    dataObj.amountperpage = jQuery('select#expenses_user_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_user_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'userid|asc') {
        dataObj.sortby = 'userid';
        dataObj.order = 'asc';
    } else if(sortby === 'userid|desc') {
        dataObj.sortby = 'userid';
        dataObj.order = 'desc';
    } else if(sortby === 'userfullname|asc') {
        dataObj.sortby = 'userfullname';
        dataObj.order = 'asc';
    } else if(sortby === 'userfullname|desc') {
        dataObj.sortby = 'userfullname';
        dataObj.order = 'desc';
    } else {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    }

    jQuery('tbody#expenses_user').html('');
    jQuery('span#totaluserquantity').text('');
    jQuery('img#admin_userlist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["user"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button += '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editUser(' + expenseszyx987_validString(objArr[i].id) + ', \'expenses_user_container_\');">Edit</a>';                    
            temp_button += '<a role="button" tabindex="0" aria-label="save" href="javascript:void(0);" style="display:none;" class="btn btn-primary expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_saveUser(' + expenseszyx987_validString(objArr[i].id) + ',' + expenseszyx987_validString(objArr[i].userid) + ', \'expenses_user_\');">Save</a>';                    
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].firstname);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_firstname_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_firstname_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].firstname).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].lastname);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_lastname_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_lastname_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].lastname).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].userid); + '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].canreadinadminpage) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_canreadinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_canreadinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].canreadinadminpage) === 1 ? 'selected' : '') + '>YES</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].canreadinadminpage) === 0 ? 'selected' : '') + '>NO</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].cancreateinadminpage) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_cancreateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_cancreateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].cancreateinadminpage) === 1 ? 'selected' : '') + '>YES</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].cancreateinadminpage) === 0 ? 'selected' : '') + '>NO</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].caneditinadminpage) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_caneditinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_caneditinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].caneditinadminpage) === 1 ? 'selected' : '') + '>YES</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].caneditinadminpage) === 0 ? 'selected' : '') + '>NO</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].canactivateinadminpage) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_canactivateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_canactivateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].canactivateinadminpage) === 1 ? 'selected' : '') + '>YES</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].canactivateinadminpage) === 0 ? 'selected' : '') + '>NO</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].candeactivateinadminpage) === 1 ? '<span style="color:green;">YES</span>' : '<span style="color:red;">NO</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_candeactivateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_candeactivateinadminpage_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].candeactivateinadminpage) === 1 ? 'selected' : '') + '>YES</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].candeactivateinadminpage) === 0 ? 'selected' : '') + '>NO</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].reportto);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_reportto_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_reportto_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Please choose one...</option>';
            <?php foreach ($activeWPusers as $user) { ?>
            tempRows += "<option " + (expenseszyx987_validString(objArr[i].reportto) === <?php echo $user->ID === null ? 0 : intval($user->ID); ?> ? 'selected' : '') + " value='<?php echo intval($user->ID); ?>' ><?php echo esc_html($user->fullname) . ' (' . intval($user->ID) . ')'; ?></option>";
            <?php } ?>
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].rolename);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_roleid_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_roleid_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Please choose one...</option>';
            <?php foreach ($activeroles as $role) { ?>
            <?php $role_status_temp = $role->status === '1' ? '' : 'color:grey;'; ?>
            tempRows += "<option " + (expenseszyx987_validString(objArr[i].roleid) === <?php echo $role->id === null ? 0 : intval($role->id); ?> ? 'selected' : '') + " value='<?php echo intval($role->id); ?>' style='<?php echo esc_html($role_status_temp); ?>'><?php echo esc_html($role->name); ?></option>";
            <?php } ?>
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].departmentname);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_departmentid_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_departmentid_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Please choose one...</option>';
            <?php foreach ($activedepartments as $department) { ?>
            <?php $department_status_temp = $department->status === '1' ? '' : 'color:grey;'; ?>
            tempRows += "<option " + (expenseszyx987_validString(objArr[i].departmentid) === <?php echo $department->id === null ? 0 : intval($department->id); ?> ? 'selected' : '') + " value='<?php echo intval($department->id); ?>' style='<?php echo esc_html($department_status_temp); ?>'><?php echo esc_html($department->name); ?></option>";
            <?php } ?>
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>');
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<select name="expenses_user_status_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_status_' + expenseszyx987_validString(objArr[i].id) + '" >';
            tempRows += '<option value="-1">Choose one...</option>';
            tempRows += '<option value="1"' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'selected' : '') + '>ACTIVE</option>';
            tempRows += '<option value="0"' + (expenseszyx987_validString(objArr[i].status) === 0 ? 'selected' : '') + '>NOT ACTIVE</option>';
            tempRows += '</select></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].email);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_email_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_email_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].email).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].phone);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_phone_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_phone_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].phone).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].address);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_address_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_address_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].address).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].address2);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_address2_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_address2_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].address2).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].city);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_city_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_city_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].city).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].province);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_province_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_province_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].province).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].country);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_country_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_country_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].country).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].zip);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_zip_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_zip_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].zip).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].description);
            tempRows += '<div style="display:none;" class="expenses_user_container_' + expenseszyx987_validString(objArr[i].id) + '" ><input type="text" name="expenses_user_description_' + expenseszyx987_validString(objArr[i].id) + '" id="expenses_user_description_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '\\&#34;') + '" /></div>';
            tempRows += '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td></tr>';
        }
        jQuery('tbody#expenses_user').html(tempRows);
        var totalUserQuantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totaluserquantity').text(totalUserQuantity);
        totalUserQuantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_user_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(USER_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_user = Math.ceil(totalUserQuantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_user, pagenumber , 'user');
        }
        jQuery('img#admin_userlist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Get user list request failed: " + textStatus );
    });
}

function expenseszyx987_resetUsersSearchParameters() {
    jQuery('select#expenses_user_userid').val('-1');
    jQuery('input#expenses_user_userfullname').val('');
    jQuery('input#expenses_user_email').val('');
    jQuery('select#expenses_user_reportto').val('-1');
    jQuery('select#expenses_user_canreadinadminpage').val('-1');
    jQuery('select#expenses_user_cancreateinadminpage').val('-1');
    jQuery('select#expenses_user_caneditinadminpage').val('-1');
    jQuery('select#expenses_user_canactivateinadminpage').val('-1');
    jQuery('select#expenses_user_candeactivateinadminpage').val('-1');
    jQuery('select#expenses_user_roleid').val('-1');
    jQuery('select#expenses_user_departmentid').val('-1');
    jQuery('select#expenses_user_status').val('-1');
    jQuery('select#expenses_user_itemsperpage').val('-1');
    jQuery('select#expenses_user_sortby').val('-1');
}

function expenseszyx987_editUser(userid, containerid) {
    if(jQuery('.' + containerid + userid).length > 0) {
        jQuery('.' + containerid + userid).toggle();
    }
}

function expenseszyx987_saveUser(id, userid, selectid) {
    var userfirstname = '';
    if(jQuery('input#' + selectid + 'firstname_' + id).length > 0) {
        userfirstname = jQuery('input#' + selectid + 'firstname_' + id).val();
    }
    var userlastname = '';
    if(jQuery('input#' + selectid + 'lastname_' + id).length > 0) {
        userlastname = jQuery('input#' + selectid + 'lastname_' + id).val();
    }
    var usercanreadinadminpage = '-1';
    if(jQuery('select#' + selectid + 'canreadinadminpage_' + id).length > 0) {
        usercanreadinadminpage = jQuery('select#' + selectid + 'canreadinadminpage_' + id).val();
    }
    var usercancreateinadminpage = '-1';
    if(jQuery('select#' + selectid + 'cancreateinadminpage_' + id).length > 0) {
        usercancreateinadminpage = jQuery('select#' + selectid + 'cancreateinadminpage_' + id).val();
    }
    var usercaneditinadminpage = '-1';
    if(jQuery('select#' + selectid + 'caneditinadminpage_' + id).length > 0) {
        usercaneditinadminpage = jQuery('select#' + selectid + 'caneditinadminpage_' + id).val();
    }
    var usercanactivateinadminpage = '-1';
    if(jQuery('select#' + selectid + 'canactivateinadminpage_' + id).length > 0) {
        usercanactivateinadminpage = jQuery('select#' + selectid + 'canactivateinadminpage_' + id).val();
    }
    var usercandeactivateinadminpage = '-1';
    if(jQuery('select#' + selectid + 'candeactivateinadminpage_' + id).length > 0) {
        usercandeactivateinadminpage = jQuery('select#' + selectid + 'candeactivateinadminpage_' + id).val();
    }
    var userreportto = '-1';
    if(jQuery('select#' + selectid + 'reportto_' + id).length > 0) {
        userreportto = jQuery('select#' + selectid + 'reportto_' + id).val();
    }
    var userrole = '-1';
    if(jQuery('select#' + selectid + 'roleid_' + id).length > 0) {
        userrole = jQuery('select#' + selectid + 'roleid_' + id).val();
    }
    var userdepartment = '-1';
    if(jQuery('select#' + selectid + 'departmentid_' + id).length > 0) {
        userdepartment = jQuery('select#' + selectid + 'departmentid_' + id).val();
    }
    var userstatus = '-1';
    if(jQuery('select#' + selectid + 'status_' + id).length > 0) {
        userstatus = jQuery('select#' + selectid + 'status_' + id).val();
    }
    var useremail = '';
    if(jQuery('input#' + selectid + 'email_' + id).length > 0) {
        useremail = jQuery('input#' + selectid + 'email_' + id).val();
    }
    var userphone = '';
    if(jQuery('input#' + selectid + 'phone_' + id).length > 0) {
        userphone = jQuery('input#' + selectid + 'phone_' + id).val();
    }
    var useraddress = '';
    if(jQuery('input#' + selectid + 'address_' + id).length > 0) {
        useraddress = jQuery('input#' + selectid + 'address_' + id).val();
    }
    var useraddress2 = '';
    if(jQuery('input#' + selectid + 'address2_' + id).length > 0) {
        useraddress2 = jQuery('input#' + selectid + 'address2_' + id).val();
    }
    var usercity = '';
    if(jQuery('input#' + selectid + 'city_' + id).length > 0) {
        usercity = jQuery('input#' + selectid + 'city_' + id).val();
    }
    var userprovince = '';
    if(jQuery('input#' + selectid + 'province_' + id).length > 0) {
        userprovince = jQuery('input#' + selectid + 'province_' + id).val();
    }
    var usercountry = '';
    if(jQuery('input#' + selectid + 'country_' + id).length > 0) {
        usercountry = jQuery('input#' + selectid + 'country_' + id).val();
    }
    var userzip = '';
    if(jQuery('input#' + selectid + 'zip_' + id).length > 0) {
        userzip = jQuery('input#' + selectid + 'zip_' + id).val();
    }
    var userdescription = '';
    if(jQuery('input#' + selectid + 'description_' + id).length > 0) {
        userdescription = jQuery.trim(jQuery('input#' + selectid + 'description_' + id).val());
    }
    if(userfirstname === '' && userlastname === '' && id <= 0 && userid <= 0 && userreportto === '-1') {
        return alert("First name, last name, user id and report to user id are required.");
    }
    if(userfirstname === '' || userlastname === '' || id <= 0 || userid <= 0 || userreportto === '-1') {
        return alert("First name, last name, user id and report to user id are required.");
    }
    var dataObj = {expenseszyx987_hidden_security_saveuser:"<?php echo esc_html(wp_create_nonce('expenseszyx987_saveUser')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_saveUser",id: id};
    dataObj.firstname = userfirstname;
    dataObj.lastname = userlastname;
    dataObj.id = id;
    dataObj.userid = userid;
    dataObj.reportto = userreportto;
    dataObj.canreadinadminpage = usercanreadinadminpage;
    dataObj.cancreateinadminpage = usercancreateinadminpage;
    dataObj.caneditinadminpage = usercaneditinadminpage;
    dataObj.canactivateinadminpage = usercanactivateinadminpage;
    dataObj.candeactivateinadminpage = usercandeactivateinadminpage;
    dataObj.roleid = userrole;
    dataObj.departmentid = userdepartment;
    dataObj.email = useremail;
    dataObj.phone = userphone;
    dataObj.address = useraddress;
    dataObj.address2 = useraddress2;
    dataObj.city = usercity;
    dataObj.province = userprovince;
    dataObj.country = usercountry;
    dataObj.zip = userzip;
    dataObj.description = userdescription;
    dataObj.status = userstatus;
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getUsersList();
        } else {
            alert(mydata);
        }
    }).fail(function( jqXHR, textStatus ) {
        //alert( "User update failed: " + textStatus );
    });
}

function expenseszyx987_updateusertypes_getTypesForUser() {
    var userid = parseInt(jQuery('select#expenseszyx987_updateusertypesuser').val());
    jQuery('p#expenseszyx987_updateusertypescheckboxes').hide();
    jQuery('p#expenseszyx987_updateusertypescheckboxes').html('');
    if(userid <= 0) { return alert('Please choose a user.');}
    jQuery('input#expenseszyx987_updateusertypessubmit').hide();
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: {expenseszyx987_hidden_security_gettypesforuser:"<?php echo esc_html(wp_create_nonce('expenseszyx987_gettypesforuser')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_gettypesforuser", id:userid}
    }).done(function (mydata) {
        jQuery('p#expenseszyx987_updateusertypescheckboxes').show();
        jQuery('input#expenseszyx987_updateusertypessubmit').show();
        if(mydata.length > 0) {
            var temp = '';
            for (var i = 0; i < mydata.length; i++) {
                temp += '<input type="checkbox" id="expenseszyx987_updateusertypes_type_' + mydata[i]["id"] + '" name="expenseszyx987_updateusertypes_type[]" value="' + mydata[i]["id"] + '" ' + (mydata[i]["userid"] === userid ? 'checked' : '') + '><span style="">' + mydata[i]["name"] + '(' + mydata[i]["id"] + ')' + '</span>&nbsp;&nbsp;&nbsp;&nbsp;';
            }
            jQuery('p#expenseszyx987_updateusertypescheckboxes').html(temp);
        }
    });
}    

function expenseszyx987_getLogsList(pagenumber) {
    var dataObj = {expenseszyx987_hidden_security_getlogs:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getLogs')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getLogs"};
    dataObj.searchwords = jQuery('input#expenses_log_description').val();
    dataObj.searchtype = jQuery.trim(jQuery('select#expenses_log_type').val());
    dataObj.processname = jQuery.trim(jQuery('select#expenses_log_processname').val());    
    dataObj.userid = jQuery('select#expenses_log_userid').val();
    dataObj.logstatus = jQuery('select#expenses_log_status').val();
    dataObj.amountperpage = jQuery('select#expenses_log_itemsperpage').val();
    if(typeof pagenumber === 'undefined') {pagenumber = 1;}
    dataObj.pagenumber = pagenumber;

    var sortby = jQuery('select#expenses_log_sortby').val();
    if(sortby === 'id|asc') {
        dataObj.sortby = 'id';
        dataObj.order = 'asc';
    } else if(sortby === 'id|desc') {
        dataObj.sortby = 'id';
        dataObj.order = 'desc';
    } else if(sortby === 'type|asc') {
        dataObj.sortby = 'type';
        dataObj.order = 'asc';
    } else if(sortby === 'type|desc') {
        dataObj.sortby = 'type';
        dataObj.order = 'desc';
    } else if(sortby === 'createtimeutc|asc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'asc';
    } else if(sortby === 'createtimeutc|desc') {
        dataObj.sortby = 'createtimeutc';
        dataObj.order = 'desc';
    }

    jQuery('tbody#expenses_log').html('');
    jQuery('span#totallogquantity').text('');
    jQuery('img#admin_loglist_loader').show();

    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: dataObj
    }).done(function (mydata) {
        var objArr = mydata["log"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            tempRows += '<tr><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + expenseszyx987_validString(objArr[i].type) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].processname) + '</td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].userid) + '</td>';
            tempRows += '<td><span class="logspan" >' + expenseszyx987_validString(objArr[i].description) + '</span><input class="logedittextbox" style="display:none;" name="log_' + expenseszyx987_validString(objArr[i].id) + '" id="log_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].description).replace(/"/g, '&#34;') + '" /><input class="logedittextbox" style="display:none;" type="button" value="Update" name="logeditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="logeditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitLogValue(\'log_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ');" /></td>';
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? '<span style="color:green;">ACTIVE</span>' : '<span style="color:red;">INACTIVE</span>') + '</td></tr>';
        }
        jQuery('tbody#expenses_log').html(tempRows);
        var totallogquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totallogquantity').text(totallogquantity);
        totallogquantity = parseInt(mydata["total"]);
        var amountperpage = parseInt(jQuery('select#expenses_log_itemsperpage').val());
        if(amountperpage === -1) {amountperpage = parseInt(LOG_ITEMS_PER_PAGE_PRESET_VALUE);}
        if(amountperpage > 0) {
            totalpagenumber_onload_admin_log = Math.ceil(totallogquantity / amountperpage);
            expenseszyx987_createPagination(totalpagenumber_onload_admin_log, pagenumber , 'log');
        }
        jQuery('img#admin_loglist_loader').hide();
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request log list failed: " + textStatus );
    });
}

function expenseszyx987_resetLogsSearchParameters() {
    jQuery('select#expenses_log_type').val('-1');
    jQuery('select#expenses_log_processname').val('-1');
    jQuery('select#expenses_log_userid').val('-1');
    jQuery('input#expenses_log_description').val('');
    jQuery('select#expenses_log_status').val('-1');
    jQuery('select#expenses_log_itemsperpage').val('-1');
    jQuery('select#expenses_log_sortby').val('-1');
    
}

function expenseszyx987_getConstantsList() {
    jQuery('tbody#expenses_constant').html('');
    jQuery('span#totalconstantquantity').text('');
    jQuery('img#admin_constantlist_loader').show();
    jQuery.ajax({
        type: "POST",
        async: true,
        url: ajaxurl,
        data: {expenseszyx987_hidden_security_getconstants:"<?php echo esc_html(wp_create_nonce('expenseszyx987_getConstants')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_getConstants"}
    }).done(function (mydata) {
        var objArr = mydata["constant"];
        var tempRows = '';
        for (var i = 0; i < objArr.length; i++) {
            var temp_name = expenseszyx987_validString(objArr[i].name);
            if(temp_name === 'COMPANY_TIMEZONE_HOURS') {
                temp_name += '&nbsp;(manually change it for daylight savings time)';
            }
            var temp_button = '';
            <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
            temp_button = '<a role="button" tabindex="0" aria-label="edit" href="javascript:void(0);" class="btn btn-primary" onclick="expenseszyx987_editConstant(this, ' + expenseszyx987_validString(objArr[i].id) + ');">Edit</a>';
            if(temp_name === 'DBBACKUP_DETAILS' || temp_name === 'PAYMENT_METHOD') {
                temp_button = '';
            }
            <?php } ?>
            tempRows += '<tr><td>'+ temp_button + '</td><td>' + expenseszyx987_validString(objArr[i].id) + '</td><td>' + temp_name + '</td>';
            if(temp_name === 'COMPANY_TIMEZONE') {
                /*tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value) + '</span>';
                tempRows += '<select class="constantedittextbox" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" >';
                
                //tempRows += '<option value="-1">Please choose one...</option>';
                tempRows += '<option value="Etc/GMT+12|-12:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Etc/GMT+12' ? 'selected' : '') + '>(GMT-12:00) International Date Line West</option>';
                tempRows += '<option value="Pacific/Midway|-11:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Midway' ? 'selected' : '') + '>(GMT-11:00) Midway Island, Samoa</option>';
                tempRows += '<option value="Pacific/Honolulu|-10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Honolulu' ? 'selected' : '') + '>(GMT-10:00) Hawaii</option>';
                tempRows += '<option value="America/Anchorage|-09:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Anchorage' ? 'selected' : '') + '>(GMT-09:00) Alaska</option>';
                tempRows += '<option value="America/Los_Angeles|-08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Los_Angeles' ? 'selected' : '') + '>(GMT-08:00) Pacific Time (US & Canada)</option>';
                tempRows += '<option value="America/Tijuana|-08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Tijuana' ? 'selected' : '') + '>(GMT-08:00) Tijuana, Baja California</option>';
                tempRows += '<option value="America/Phoenix|-07:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Phoenix' ? 'selected' : '') + '>(GMT-07:00) Arizona</option>';
                tempRows += '<option value="America/Chihuahua|-07:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Chihuahua' ? 'selected' : '') + '>(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>';
                tempRows += '<option value="America/Denver|-07:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Denver' ? 'selected' : '') + '>(GMT-07:00) Mountain Time (US & Canada)</option>';
                tempRows += '<option value="America/Managua|-06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Managua' ? 'selected' : '') + '>(GMT-06:00) Central America</option>';
                tempRows += '<option value="America/Chicago|-06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Chicago' ? 'selected' : '') + '>(GMT-06:00) Central Time (US & Canada)</option>';
                tempRows += '<option value="America/Mexico_City|-06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Mexico_City' ? 'selected' : '') + '>(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>';
                tempRows += '<option value="America/Regina|-06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Regina' ? 'selected' : '') + '>(GMT-06:00) Saskatchewan</option>';
                tempRows += '<option value="America/Bogota|-05:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Bogota' ? 'selected' : '') + '>(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>';
                tempRows += '<option value="America/New_York|-05:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/New_York' ? 'selected' : '') + '>(GMT-05:00) Eastern Time (US & Canada)</option>';
                tempRows += '<option value="America/Indiana/Indianapolis|-05:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Indiana/Indianapolis' ? 'selected' : '') + '>(GMT-05:00) Indiana (East)</option>';
                tempRows += '<option value="America/Halifax|-04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Halifax' ? 'selected' : '') + '>(GMT-04:00) Atlantic Time (Canada)</option>';
                tempRows += '<option value="America/Caracas|-04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Caracas' ? 'selected' : '') + '>(GMT-04:00) Caracas, La Paz</option>';
                tempRows += '<option value="America/Manaus|-04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Manaus' ? 'selected' : '') + '>(GMT-04:00) Manaus</option>';
                tempRows += '<option value="America/Santiago|-04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Santiago' ? 'selected' : '') + '>(GMT-04:00) Santiago</option>';
                tempRows += '<option value="America/St_Johns|-03:30" ' + (expenseszyx987_validString(objArr[i].value) === 'America/St_Johns' ? 'selected' : '') + '>(GMT-03:30) Newfoundland</option>';
                tempRows += '<option value="America/Sao_Paulo|-03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Sao_Paulo' ? 'selected' : '') + '>(GMT-03:00) Brasilia</option>';
                tempRows += '<option value="America/Argentina/Buenos_Aires|-03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Argentina/Buenos_Aires' ? 'selected' : '') + '>(GMT-03:00) Buenos Aires, Georgetown</option>';
                tempRows += '<option value="America/Godthab|-03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Godthab' ? 'selected' : '') + '>(GMT-03:00) Greenland</option>';
                tempRows += '<option value="America/Montevideo|-03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Montevideo' ? 'selected' : '') + '>(GMT-03:00) Montevideo</option>';
                tempRows += '<option value="America/Noronha|-02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'America/Noronha' ? 'selected' : '') + '>(GMT-02:00) Mid-Atlantic</option>';
                tempRows += '<option value="Atlantic/Cape_Verde|-01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Atlantic/Cape_Verde' ? 'selected' : '') + '>(GMT-01:00) Cape Verde Is.</option>';
                tempRows += '<option value="Atlantic/Azores|-01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Atlantic/Azores' ? 'selected' : '') + '>(GMT-01:00) Azores</option>';
                tempRows += '<option value="Africa/Casablanca|+00:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Casablanca' ? 'selected' : '') + '>(GMT+00:00) Casablanca, Monrovia, Reykjavik</option>';
                tempRows += '<option value="Etc/Greenwich|+00:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Etc/Greenwich' ? 'selected' : '') + '>(GMT+00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</option>';
                tempRows += '<option value="Europe/Amsterdam|+01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Amsterdam' ? 'selected' : '') + '>(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>';
                tempRows += '<option value="Europe/Belgrade|+01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Belgrade' ? 'selected' : '') + '>(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>';
                tempRows += '<option value="Europe/Brussels|+01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Brussels' ? 'selected' : '') + '>(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>';
                tempRows += '<option value="Europe/Sarajevo|+01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Sarajevo' ? 'selected' : '') + '>(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb</option>';
                tempRows += '<option value="Africa/Lagos|+01:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Lagos' ? 'selected' : '') + '>(GMT+01:00) West Central Africa</option>';
                tempRows += '<option value="Asia/Amman|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Amman' ? 'selected' : '') + '>(GMT+02:00) Amman</option>';
                tempRows += '<option value="Europe/Athens|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Athens' ? 'selected' : '') + '>(GMT+02:00) Athens, Bucharest, Istanbul</option>';
                tempRows += '<option value="Asia/Beirut|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Beirut' ? 'selected' : '') + '>(GMT+02:00) Beirut</option>';
                tempRows += '<option value="Africa/Cairo|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Cairo' ? 'selected' : '') + '>(GMT+02:00) Cairo</option>';
                tempRows += '<option value="Africa/Harare|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Harare' ? 'selected' : '') + '>(GMT+02:00) Harare, Pretoria</option>';
                tempRows += '<option value="Europe/Helsinki|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Helsinki' ? 'selected' : '') + '>(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius</option>';
                tempRows += '<option value="Asia/Jerusalem|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Jerusalem' ? 'selected' : '') + '>(GMT+02:00) Jerusalem</option>';
                tempRows += '<option value="Europe/Minsk|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Minsk' ? 'selected' : '') + '>(GMT+02:00) Minsk</option>';
                tempRows += '<option value="Africa/Windhoek|+02:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Windhoek' ? 'selected' : '') + '>(GMT+02:00) Windhoek</option>';
                tempRows += '<option value="Asia/Kuwait|+03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Kuwait' ? 'selected' : '') + '>(GMT+03:00) Kuwait, Riyadh, Baghdad</option>';
                tempRows += '<option value="Europe/Moscow|+03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Europe/Moscow' ? 'selected' : '') + '>(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>';
                tempRows += '<option value="Africa/Nairobi|+03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Africa/Nairobi' ? 'selected' : '') + '>(GMT+03:00) Nairobi</option>';
                tempRows += '<option value="Asia/Tbilisi|+03:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Tbilisi' ? 'selected' : '') + '>(GMT+03:00) Tbilisi</option>';
                tempRows += '<option value="Asia/Tehran|+03:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Tehran' ? 'selected' : '') + '>(GMT+03:30) Tehran</option>';
                tempRows += '<option value="Asia/Muscat|+04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Muscat' ? 'selected' : '') + '>(GMT+04:00) Abu Dhabi, Muscat</option>';
                tempRows += '<option value="Asia/Baku|+04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Baku' ? 'selected' : '') + '>(GMT+04:00) Baku</option>';
                tempRows += '<option value="Asia/Yerevan|+04:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Yerevan' ? 'selected' : '') + '>(GMT+04:00) Yerevan</option>';
                tempRows += '<option value="Asia/Kabul|+04:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Kabul' ? 'selected' : '') + '>(GMT+04:30) Kabul</option>';
                tempRows += '<option value="Asia/Yekaterinburg|+05:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Yekaterinburg' ? 'selected' : '') + '>(GMT+05:00) Yekaterinburg</option>';
                tempRows += '<option value="Asia/Karachi|+05:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Karachi' ? 'selected' : '') + '>(GMT+05:00) Islamabad, Karachi, Tashkent</option>';
                tempRows += '<option value="Asia/Calcutta|+05:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Calcutta' ? 'selected' : '') + '>(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi, Sri Jayawardenapura</option>';
                tempRows += '<option value="Asia/Katmandu|+05:45" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Katmandu' ? 'selected' : '') + '>(GMT+05:45) Kathmandu</option>';
                tempRows += '<option value="Asia/Almaty|+06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Almaty' ? 'selected' : '') + '>(GMT+06:00) Almaty, Novosibirsk</option>';
                tempRows += '<option value="Asia/Dhaka|+06:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Dhaka' ? 'selected' : '') + '>(GMT+06:00) Astana, Dhaka</option>';
                tempRows += '<option value="Asia/Rangoon|+06:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Rangoon' ? 'selected' : '') + '>(GMT+06:30) Yangon (Rangoon)</option>';
                tempRows += '<option value="Asia/Bangkok|+07:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Bangkok' ? 'selected' : '') + '>(GMT+07:00) Bangkok, Hanoi, Jakarta</option>';
                tempRows += '<option value="Asia/Krasnoyarsk|+07:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Krasnoyarsk' ? 'selected' : '') + '>(GMT+07:00) Krasnoyarsk</option>';
                tempRows += '<option value="Asia/Hong_Kong|+08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Hong_Kong' ? 'selected' : '') + '>(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>';
                tempRows += '<option value="Asia/Kuala_Lumpur|+08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Kuala_Lumpur' ? 'selected' : '') + '>(GMT+08:00) Kuala Lumpur, Singapore</option>';
                tempRows += '<option value="Asia/Irkutsk|+08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Irkutsk' ? 'selected' : '') + '>(GMT+08:00) Irkutsk, Ulaan Bataar</option>';
                tempRows += '<option value="Australia/Perth|+08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Perth' ? 'selected' : '') + '>(GMT+08:00) Perth</option>';
                tempRows += '<option value="Asia/Taipei|+08:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Taipei' ? 'selected' : '') + '>(GMT+08:00) Taipei</option>';
                tempRows += '<option value="Asia/Tokyo|+09:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Tokyo' ? 'selected' : '') + '>(GMT+09:00) Osaka, Sapporo, Tokyo</option>';
                tempRows += '<option value="Asia/Seoul|+09:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Seoul' ? 'selected' : '') + '>(GMT+09:00) Seoul</option>';
                tempRows += '<option value="Asia/Yakutsk|+09:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Yakutsk' ? 'selected' : '') + '>(GMT+09:00) Yakutsk</option>';
                tempRows += '<option value="Australia/Adelaide|+09:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Adelaide' ? 'selected' : '') + '>(GMT+09:30) Adelaide</option>';
                tempRows += '<option value="Australia/Darwin|+09:30" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Darwin' ? 'selected' : '') + '>(GMT+09:30) Darwin</option>';
                tempRows += '<option value="Australia/Brisbane|+10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Brisbane' ? 'selected' : '') + '>(GMT+10:00) Brisbane</option>';
                tempRows += '<option value="Australia/Canberra|+10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Canberra' ? 'selected' : '') + '>(GMT+10:00) Canberra, Melbourne, Sydney</option>';
                tempRows += '<option value="Australia/Hobart|+10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Australia/Hobart' ? 'selected' : '') + '>(GMT+10:00) Hobart</option>';
                tempRows += '<option value="Pacific/Guam|+10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Guam' ? 'selected' : '') + '>(GMT+10:00) Guam, Port Moresby</option>';
                tempRows += '<option value="Asia/Vladivostok|+10:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Vladivostok' ? 'selected' : '') + '>(GMT+10:00) Vladivostok</option>';
                tempRows += '<option value="Asia/Magadan|+11:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Asia/Magadan' ? 'selected' : '') + '>(GMT+11:00) Magadan, Solomon Is., New Caledonia</option>';
                tempRows += '<option value="Pacific/Auckland|+12:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Auckland' ? 'selected' : '') + '>(GMT+12:00) Auckland, Wellington</option>';
                tempRows += '<option value="Pacific/Fiji|+12:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Fiji' ? 'selected' : '') + '>(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>';
                tempRows += '<option value="Pacific/Tongatapu|+13:00" ' + (expenseszyx987_validString(objArr[i].value) === 'Pacific/Tongatapu' ? 'selected' : '') + '>(GMT+13:00) Nuku\'alofa</option>';
                tempRows += '</select>';

                tempRows += '<input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ',\'COMPANY_TIMEZONE\');" /></td>';
                jQuery('span#expenses_form_3_5_1_backup_timezone').text(expenseszyx987_validString(objArr[i].value));*/
            } else if(temp_name === 'DBBACKUP_FREQUENCY') {
                tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value) + '</span>';
                tempRows += '<select class="constantedittextbox" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" >';
                tempRows += '<option value="daily" ' + (expenseszyx987_validString(objArr[i].value) === 'daily' ? 'selected' : '') + '>daily</option>';
                tempRows += '<option value="weekly" ' + (expenseszyx987_validString(objArr[i].value) === 'weekly' ? 'selected' : '') + '>weekly (Since WordPress 5.4)</option>';
                tempRows += '<option value="twicedaily" ' + (expenseszyx987_validString(objArr[i].value) === 'twicedaily' ? 'selected' : '') + '>twicedaily</option>';
                tempRows += '<option value="hourly" ' + (expenseszyx987_validString(objArr[i].value) === 'hourly' ? 'selected' : '') + '>hourly</option>';
                tempRows += '</select>';

                tempRows += '<input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ');" /></td>';

            } else if(temp_name === 'DBBACKUP_LOCALTIME') {
                tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value) + '</span>';
                tempRows += '<input class="constantedittextbox expenseszyx987_datetimepicker" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].value) + '"/>';
                tempRows += '<input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ');" /></td>';
            } else if(temp_name === 'DBBACKUP_DETAILS') {
                if(expenseszyx987_validString(objArr[i].value) === '') {
                    tempRows += '<td><span class="constantspan" >VALUE IS NOT SET</span>';
                } else {
                    tempRows += '<td><span class="constantspan" >HAS VALUE, CONFIDENTIAL</span>';
                }
                tempRows += '</td>';
            } else if(temp_name === 'USE_BOOTSTRAP_JS') {
                tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value === '1' ? 'yes' : 'no') + '</span>';
                tempRows += '<select class="constantedittextbox" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" >';
                
                //tempRows += '<option value="-1">Please choose one...</option>';
                tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].value) === '1' ? 'selected' : '') + '>Yes</option>';
                tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].value) === '0' ? 'selected' : '') + '>No</option>';
                tempRows += '</select>';

                tempRows += '<input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ',\'USE_BOOTSTRAP_JS\');" /></td>';
            } else if(temp_name === 'USE_BOOTSTRAP_CSS') {
                tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value === '1' ? 'yes' : 'no') + '</span>';
                tempRows += '<select class="constantedittextbox" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" >';
                
                //tempRows += '<option value="-1">Please choose one...</option>';
                tempRows += '<option value="1" ' + (expenseszyx987_validString(objArr[i].value) === '1' ? 'selected' : '') + '>Yes</option>';
                tempRows += '<option value="0" ' + (expenseszyx987_validString(objArr[i].value) === '0' ? 'selected' : '') + '>No</option>';
                tempRows += '</select>';

                tempRows += '<input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ',\'USE_BOOTSTRAP_CSS\');" /></td>';
            } else {
                tempRows += '<td><span class="constantspan" >' + expenseszyx987_validString(objArr[i].value) + '</span><input class="constantedittextbox" style="display:none;" name="constant_' + expenseszyx987_validString(objArr[i].id) + '" id="constant_' + expenseszyx987_validString(objArr[i].id) + '" value="' + expenseszyx987_validString(objArr[i].value) + '" /><input class="constantedittextbox" style="display:none;" type="button" value="Update" name="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" id="constanteditsubmitbutton_' + expenseszyx987_validString(objArr[i].id) + '" onclick="expenseszyx987_submitConstantValue(\'constant_' + expenseszyx987_validString(objArr[i].id) + '\', ' + expenseszyx987_validString(objArr[i].id) + ');" /></td>';
            }
            tempRows += '<td>' + expenseszyx987_validString(objArr[i].createtimeutc) + '</td><td>' + (expenseszyx987_validString(objArr[i].status) === 1 ? 'ACTIVE' : 'INACTIVE') + '</td></tr>';
        }
        jQuery('tbody#expenses_constant').html(tempRows);
        var totalconstantquantity = mydata["total"] == null ? '0' : mydata["total"];
        jQuery('span#totalconstantquantity').text(totalconstantquantity);
        jQuery('img#admin_constantlist_loader').hide();
        jQuery(".expenseszyx987_datetimepicker").datetimepicker({ scrollMonth: false, scrollInput: false, format:'Y-m-d H:i:s' });
        jQuery(".expenseszyx987_datetimepicker2").datetimepicker({ scrollMonth: false, scrollInput: false, datepicker:false, format:'H:i:s' });
    }).fail(function( jqXHR, textStatus ) {
        //alert( "Request constant list failed: " + textStatus );
    });
}

jQuery(document).ready(function(){
    jQuery("select.presetto_1").val('-1');
    jQuery('div#expenses_tabs').tabs();
    jQuery('div#expenses_tabs_1 select').val('14days');
    jQuery("body").append(mediummodalElementContainer);
    jQuery('div#mymediummodal').html('');
    jQuery("body").append(largemodalElementContainer);
    jQuery('div#mylargemodal').html('');
    document.getElementById('mymediummodal').title = '';
    document.getElementById('mylargemodal').title = '';
    jQuery(".datepicker").val('');
    jQuery(".datepicker").datepicker({ changeMonth:true,changeYear:true,yearRange:"1900:c+10",dateFormat:'yy-mm-dd' });
    jQuery(".expenseszyx987_datetimepicker").datetimepicker({ scrollMonth: false, scrollInput: false, format:'Y-m-d H:i:s' });
    jQuery(".expenseszyx987_datetimepicker2").datetimepicker({ scrollMonth: false, scrollInput: false, datepicker:false, format:'H:i:s' });
    jQuery("input:text").val('');

    jQuery(window).resize(function() {ng
        jQuery("div#mylargemodal").parent().css("width", jQuery(window).width()).css("height", jQuery(window).height()).css("top", 0);
        jQuery("div#mylargemodal").css("width", jQuery(window).width());
    });

    expenseszyx987_getExpensesList();
    expenseszyx987_getRolesList();
    expenseszyx987_getConstantsList();
    expenseszyx987_getTypecategoriesList();
    expenseszyx987_getTypesList();
    expenseszyx987_getTaxesList();
    expenseszyx987_getCurrenciesList();
    expenseszyx987_getDepartmentsList();
    expenseszyx987_getUsersList();
    expenseszyx987_getCustomertypesList();
    expenseszyx987_getCustomersList();
    expenseszyx987_getRecurringpaymentfrequenciesList();
    expenseszyx987_getLogsList();

    if(jQuery('div.master_pwrapper').length > 0) {
        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_expense > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).children().first().text())) ? 0 : parseInt(jQuery(this).children().first().text());
                var currentpage;
                if(jQuery(this).hasClass('prev')){
                    currentpage = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expense > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expense > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expense > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expense > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_expense, (currentpage+1));
                }
                var sortby = jQuery("select#expenses_expense_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'expense');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_expensedetails > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage;
                if(jQuery(this).hasClass('prev')){
                    currentpage = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expensedetails > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expensedetails > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expensedetails > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_expensedetails > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_expensedetails, (currentpage+1));
                }
                var sortby = jQuery("select#expenses_expensedetails_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'expensedetails');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_typecategory > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_typecategory > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_typecategory > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_typecategory > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_typecategory > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_typecategory, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_typecategory_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'typecategory');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_type > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_type > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_type > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_type > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_type > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_type, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_type_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'type');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_role > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_role > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_role > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_role > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_role > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_role, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_role_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'role');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_user > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_user > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_user > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_user > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_user > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_user, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_user_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'user');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_department > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_department > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_department > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_department > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_department > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_department, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_department_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'department');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_usertype > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_usertype > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_usertype > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_usertype > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_usertype > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_usertype, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_usertype_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'usertype');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_currency > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_currency > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_currency > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_currency > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_currency > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_currency, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_currency_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'currency');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_tax > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_tax > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_tax > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_tax > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_tax > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_tax, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_tax_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'tax');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_customertype > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customertype > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customertype > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customertype > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customertype > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_customertype, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_customertype_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'customertype');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_customer > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customer > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customer > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customer > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_customer > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_customer, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_customer_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'customer');
            }
        });

        jQuery('div.master_pwrapper').on( 'click keydown', 'div.master_mypagination.master_mypagination_admin_recurringpaymentfrequency > ul.pagination > li:not(.noborder):not(.disabled)', function (event) {
            if(expenseszyx987_isClickEnterSpaceEvent(event) === true) {
                var topagenumber = isNaN(parseInt(jQuery(this).text())) ? 0 : parseInt(jQuery(this).text());
                var currentpage2;
                if(jQuery(this).hasClass('prev')){
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_recurringpaymentfrequency > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_recurringpaymentfrequency > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.max(1, (currentpage2-1));
                } else if (jQuery(this).hasClass('next')){ 
                    currentpage2 = isNaN(parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_recurringpaymentfrequency > ul.pagination > li.active > a').first().text())) ? 0 : parseInt(jQuery('div.master_pwrapper > div.master_mypagination.master_mypagination_admin_recurringpaymentfrequency > ul.pagination > li.active > a').first().text());
                    topagenumber = Math.min(totalpagenumber_onload_admin_recurringpaymentfrequency, (currentpage2+1));
                }
                var sortby = jQuery("select#expenses_recurringpaymentfrequency_sortby").val();
                expenseszyx987_showResultOnAjaxReloadedPage(topagenumber, 'recurringpaymentfrequency');
            }
        });
    }
}); //end of jQuery(document).ready

function expenseszyx987_containElement(mystring, myelement) {
    var res = mystring === null ? []: mystring.split(",");
    for (var i = 0; i < res.length; i++) {
        if (res[i] === myelement) {
            return true;
        }
    }
    return false;
}

function expenseszyx987_validateInput(callback) {
    return true;
}

function expenseszyx987_confirmDeleteEvent() {
    if(confirm("Are you sure you want to delete this event?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_confirmDisable(dropdownlistid, disableitemname) {
    if(jQuery('#' + dropdownlistid).val() === '0') {
        alert('Please choose a ' + disableitemname + '.');
        return false;
    }
    if(confirm("Are you sure you want to disable this " + disableitemname + "?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_confirmUpload(dropdownlistid) {
    if(jQuery('#' + dropdownlistid).val() === '0') {
        alert('Please choose an excel file.');
        return false;
    }
    if(confirm("Are you sure you want to upload this excel file?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_confirmDrop(dropitemname, includeRelatedTables) {
    var temp = '';
    if(typeof includeRelatedTables !== 'undefined') {
        if(includeRelatedTables === true) {
            temp = ' and related tables';
        }
    } else {
        temp = ' and related tables';
    }
    if(dropitemname !== 'all') {
        if(confirm("Are you sure you want to drop the " + dropitemname + " table" + temp + "?") == true) {
            return true;
        }
    } else {
        if(confirm("Are you sure you want to drop all the tables?") == true) {
            return true;
        }
    }
    return false;
}

function expenseszyx987_confirmDropSP(dropitemname) {
    if(dropitemname !== 'all') {
        if(confirm("Are you sure you want to recreate the " + dropitemname + "?") == true) {
            return true;
        }
    } else {
        if(confirm("Are you sure you want to recreate all the stored procedures?") == true) {
            return true;
        }
    }
    return false;
}

function expenseszyx987_confirmEnableAutoBackupDatabaseEveryday() {
    if(confirm("Are you sure you want to enable automatically backup database?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_confirmDisableAutoBackupDatabaseEveryday() {
    if(confirm("Are you sure you want to disable automatically backup database?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_confirmEnableOnetimeImmediateBackupDatabase() {
    if(confirm("Are you sure you want to backup database now for one time?") == true) {
        return true;
    }
    return false;
}

function expenseszyx987_editConstant(element, constantid) {
    jQuery(element).parent().parent().find('span.constantspan').toggle();
    jQuery(element).parent().parent().find('.constantedittextbox').toggle();
}

function expenseszyx987_submitConstantValue(textboxid, constantid, constantname) {
    if(textboxid === '' || jQuery('#' + textboxid).length === 0) {return "Text box does not exist";}
    var myvalue = jQuery('#' + textboxid).val();
    var myname = ((typeof constantname === 'undefined') ? '' : (constantname === null ? '' : constantname));
    var mypluginurl = "<?php $protocol = is_ssl() ? 'https://' : 'http://'; $urlparts = wp_parse_url(home_url()); $protocol = esc_html($urlparts['scheme']) . '://'; $domain = esc_html($urlparts['host']); $myurl = strtok($protocol . $domain . esc_html($_SERVER['REQUEST_URI']), '?'); if(substr($myurl, -1) === '/') {$myurl = substr($myurl, 0, -1);} echo esc_html($myurl); ?>";
    jQuery.ajax({
        type: "POST",
        url: ajaxurl,
        data: {expenseszyx987_hidden_security_editconstantvalue:"<?php echo esc_html(wp_create_nonce('expenseszyx987_editConstantvalue')); ?>",expenseszyx987_hidden:"Y",action:"expenseszyx987_editConstantvalue", id: constantid, name: myname, value: myvalue, pluginurl: mypluginurl}
    }).done(function (mydata) {
        if(mydata === 'Success') {
            expenseszyx987_getConstantsList();
        } else {
            var myresult = mydata === "" ? 'fail' : mydata;
            alert(myresult);
        }
    }).fail(function( jqXHR, textStatus ) {
        alert( "Request failed: " + textStatus );
    });
}

function expenseszyx987_cloneusertypesuserto_filter(element) {
    if(jQuery(element).length > 0 && jQuery('p#expenseszyx987_cloneusertypesuserto_list > span').length > 0) {
        if(jQuery(element).val() !== '') {
            jQuery('p#expenseszyx987_cloneusertypesuserto_list > span').each(function(index){
                if(jQuery(this).text().toLowerCase().indexOf(jQuery(element).val().toLowerCase()) >= 0) {
                    jQuery(this).show();
                    jQuery(this).prev('input').show();
                } else {
                    jQuery(this).hide();
                    jQuery(this).prev('input').hide();
                }
            });
        } else {
            jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').show();
            jQuery('p#expenseszyx987_cloneusertypesuserto_list > span').show();
        }
    }
}

function expenseszyx987_cloneusertypesuserto_checkall() {
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').prop('checked', true);
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').attr('checked', true);
}

function expenseszyx987_cloneusertypesuserto_reset() {
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').prop('checked', false);
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').attr('checked', false);
}

function expenseszyx987_cloneusertypesuserto_onlyshowchecked() {
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').each(function(index){
        if(jQuery(this).is(":checked")) {
            jQuery(this).show();
            jQuery(this).next('span').show();
        } else {
            jQuery(this).hide();
            jQuery(this).next('span').hide();
        }
    });
}

function expenseszyx987_cloneusertypesuserto_showall() {
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > input').show();
    jQuery('p#expenseszyx987_cloneusertypesuserto_list > span').show();
}

function expenseszyx987_validateDateInput(dateString) {
    var re = /^\d{4}-\d{2}-\d{2}$/;
    var re2 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
    var re3 = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
    return (dateString==="") || re.test(dateString) || re2.test(dateString) || re3.test(dateString);
}
</script>
<div class="wrap">
<?php 
    // Search for an existing page with the specified page slug.
    $slug = 'expenses';
    $valid_pages_found = $wpdb->get_results( $wpdb->prepare( "SELECT guid FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s;", $slug ) );
    if ( count($valid_pages_found) > 1 ) {
        echo '<h2 style="text-decoration: none;font-weight: bold;">' . __( 'Expenses Book', 'expenses_trdom' ) . "</h2>";
        echo "<p style='color:red !important;'>" . __( "More than one expenses page were created:", "expenses_trdom" ) . "</p>";
        $pagecounter = 1;
        foreach( $valid_pages_found as $page ) {
            echo '<p><a target="_blank" style="text-decoration: none;" href=' . $page->guid . ">" . __( 'Page ' . $pagecounter . ': ' . $page->guid, 'expenses_trdom' ) . "</a></p>";
            $pagecounter ++;
        }
    } else if ( count($valid_pages_found) == 1 ) {
        foreach( $valid_pages_found as $page ) {
            echo '<h2><a target="_blank" style="text-decoration: none;font-weight: bold;" href=' . $page->guid . ">" . __( 'Expenses Book', 'expenses_trdom' ) . "</a></h2>";
        }
    } else {
        echo '<h2 style="text-decoration: none;font-weight: bold;">' . __( 'Expenses Book', 'expenses_trdom' ) . "</h2>";
    }
?>
<p>This plugin helps you to record your expenses including recurring expenses. After plugin activation, go to the "Settings" menu to find the plugin admin page. By default, when you activate this plugin, it will automatically create an expenses landing page for you. For some themes, if it does not automatically create an expenses landing page for you, add this plugin root folder template-expenses.php file to your template folder. For example, if you are using theme twentytwenty, then add the template-expenses.php file to this folder: wordpress\wp-content\themes\twentytwenty\templates. Then you can create a new page (not a new post) using this template. When you use the template method to create a new expense page, do not set the page title to "expenses".  If you set the page title to "expenses", it could conflict with the page automatically created when you activate this plugin. Please click "Documents" tab to learn more from the documentation file.</p>
<?php if(intval($userdetails[0]["canreadinadminpage"]) !== 1) { ?>
    <p style="color:red;">You are not authorized to read this page. Please contact web admin.</p>
<?php exit;} ?>
<div id="expenses_tabs">
    <ul>
        <li><a href="#expenses_tabs_2"><?php echo "<h3>" . esc_html__( 'Tables 1', 'expenses_trdom' ) . "</h3>"; ?></a></li>
        <li><a href="#expenses_tabs_3"><?php echo "<h3>" . esc_html__( 'Tables 2', 'expenses_trdom' ) . "</h3>"; ?></a></li>
        <li><a href="#expenses_tabs_4"><?php echo "<h3>" . esc_html__( 'Tables 3', 'expenses_trdom' ) . "</h3>"; ?></a></li>
        <li><a href="#expenses_tabs_5"><?php echo "<h3>" . esc_html__( 'Actions', 'expenses_trdom' ) . "</h3>"; ?></a></li>
        <li><a href="#expenses_tabs_6"><?php echo "<h3>" . esc_html__( 'Re-create stored procedures', 'expenses_trdom' ) . "</h3>" ?></a></li>
        <li><a href="#expenses_tabs_7"><?php echo "<h3>" . esc_html__( 'Documents', 'expenses_trdom' ) . "</h3>" ?></a></li>
    </ul>
<div id="expenses_tabs_2">
<?php echo "<h3>" . esc_html__( '1. Expenses:', 'expenses_trdom' ) . "</h3>"; ?>
    <div id="expenses_order_container">
        <p>Search User: <select id="expenses_expense_userid" name="expenses_expense_userid" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <?php foreach ($allusers as $user) { ?>
           <option value="<?php echo intval($user->userid); ?>" style="<?php echo $user->status === '1' ? '' : 'color:grey;'; ?>"><?php echo esc_html($user->firstname) . ' ' . esc_html($user->lastname) . " (" . intval($user->userid) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p>Search Expense Type:
            <select id="expenses_expense_type" name="expenses_expense_type"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <?php
                if(!empty($activeexpensetypes)){
                    foreach ($activeexpensetypes as $type){
                        echo "<option value='" . intval($type->id) . "'>" . esc_html($type->name) . ' (' . esc_html($type->typecategoryname) . ")</option>";
                    }
                }
                ?>
            </select>
        </p>
        
        <p>Search From Date: <input type="text" id="expenses_expense_fromdate" name="expenses_expense_fromdate" class="datepicker" value="" size="50" /></p>    
        <p>Search To Date: <input type="text" id="expenses_expense_todate" name="expenses_expense_todate" class="datepicker" value="" size="50" /></p>    

        <p>Search Expense Min Amount: <input type="text" id="expenses_expense_min_amount" name="expenses_expense_min_amount" class="" value="" size="50" /></p>
        <p>Search Expense Max Amount: <input type="text" id="expenses_expense_max_amount" name="expenses_expense_max_amount" class="" value="" size="50" /></p>

        <p>Search Expense Customer:
            <select aria-label="Search Expense Customer" id="expenses_expense_customer" name="expenses_expense_customer"  autocomplete="off" class="presetto_1">
                <option value="-1" >Please choose one...</option>
                <?php
                    if(!empty($allcustomers)){
                        foreach ($allcustomers as $customer){
                            echo "<option value='" . intval($customer->id) . "'>" . esc_html($customer->name) . "</option>";
                        }
                    }
                ?>
            </select>
        </p>

        <p><span tabindex="0">Search Expense Is Recurring: </span>
            <select aria-label="Search Expense Is Recurring" id="expenses_expense_isrecurring" name="expenses_expense_isrecurring" autocomplete="off">
                <option value="-1" >Please choose one...</option>
                <option value="1" >YES</option>
                <option value="0" >NO</option>
            </select>
        </p>

        <p>Search Expense Reference Number: <input type="text" id="expenses_expense_referencenumber" name="expenses_expense_referencenumber" class="" value="" size="50" /></p>
        <p>Search Expense Notes: <input type="text" id="expenses_expense_notes" name="expenses_expense_notes" class="" value="" size="50" /></p>


        <p>Search Expense Status:
            <select id="expenses_expense_status" name="expenses_expense_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_expense_search" name="expenses_expense_search" class="" value="Search" onclick="expenseszyx987_getExpensesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_expense_searchreset" name="expenses_expense_searchreset" class="" value="Reset" onclick="expenseszyx987_resetExpensesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page: 
            <select id="expenses_expense_itemsperpage" name="expenses_expense_itemsperpage" onchange="expenseszyx987_getExpensesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_expense_sortby" name="expenses_expense_sortby" onchange="expenseszyx987_getExpensesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >Expense ID low-high</option>
                <option value="id|desc" >Expense ID high-low</option>
                <option value="userid|asc" >User id low-high</option>
                <option value="userid|desc" >User id high-low</option>
                <option value="date|asc" >Expense date old-new</option>
                <option value="date|desc" >Expense date new-old</option>
                <option value="expensetype|asc" >Expense type id low-high</option>
                <option value="expensetype|desc" >Expense type id high-low</option>
            </select>
        </p>

        Total expenses: <span id="totalexpensequantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_expenselist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_expense" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th tabindex="0">ID</th>
                    <th tabindex="0">Type</th>
                    <th tabindex="0">Currency</th>
                    <th tabindex="0">Amount</th>
                    <th tabindex="0">Date</th>
                    <th tabindex="0">Tax Rate</th>
                    <th tabindex="0">Amount Include Tax?</th>
                    <th tabindex="0">Reference #</th>
                    <th tabindex="0">Notes</th>
                    <th tabindex="0">Is Recurring</th> 
                    <th tabindex="0">Recurring Start Date</th>
                    <th tabindex="0">Recurring End Date</th>
                    <th tabindex="0">Recurring Payment Frequency</th>
                    <th tabindex="0">Recurring Payment Day</th>
                    <th tabindex="0">Customer Name</th>
                    <th tabindex="0">Status</th>
                    <th tabindex="0">User Name</th>
                    <th tabindex="0">User Name 2</th>
                    <th tabindex="0">User Id</th>
                </tr>
            </thead>
            <tbody id="expenses_expense">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_expense" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '2. Type Category:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" .  esc_html__( '2.1 Create a new type category', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form2_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addTypecategory")); ?>">
        <p><?php esc_html_e("Type Category Name *: " ); ?><input type="text" name="expenseszyx987_addtypecategoryname" value="" size="100"><?php esc_html_e(" e.g. Entertainment" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addtypecategorydescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Type Category', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new type category. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '2.2 Type Category list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_typecategory_container">
        <p>Search Name: <input type="text" id="expenses_typecategory_name" name="expenses_typecategory_name" class="" value="" size="50" /></p>
        <p>Search Type Category Status: 
            <select id="expenses_typecategory_status" name="expenses_typecategory_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_typecategory_search" name="expenses_typecategory_search" class="" value="Search" onclick="expenseszyx987_getTypecategoriesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_typecategory_searchreset" name="expenses_typecategory_searchreset" class="" value="Reset" onclick="expenseszyx987_resetTypecategoriesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_typecategory_itemsperpage" name="expenses_typecategory_itemsperpage" onchange="expenseszyx987_getTypecategoriesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_typecategory_sortby" name="expenses_typecategory_sortby" onchange="expenseszyx987_getTypecategoriesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total type categories: <span id="totaltypecategoryquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_typecategorylist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_typecategory" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_typecategory">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_typecategory" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '3. Type:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" .  esc_html__( '3.1 Create a new type', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form3_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addType")); ?>">
        <p><?php esc_html_e("Type category *: "); ?>
        <select id="expenseszyx987_addtypetypecategory"  name="expenseszyx987_addtypetypecategory" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($activetypecategories as $typecategory) { ?>
           <option value="<?php echo intval($typecategory->id); ?>" ><?php echo esc_html($typecategory->name); ?></option>
           <?php } ?>
         </select></p>

        <p><?php esc_html_e("Type Name *: " ); ?><input type="text" name="expenseszyx987_addtypename" value="" size="100"></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addtypedescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Type', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new type. Please contact web admin.</p>
    <?php } ?>
    <hr />

    <?php echo "<h3>" .  esc_html__( '3.2 Type list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_type_container">
        <p>Search Name: <input type="text" id="expenses_type_name" name="expenses_type_name" class="" value="" size="50" /></p>
        <p>Search Type Status:
            <select id="expenses_type_status" name="expenses_type_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
        <input type="button" id="expenses_type_search" name="expenses_type_search" class="" value="Search" onclick="expenseszyx987_getTypesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" id="expenses_type_searchreset" name="expenses_type_searchreset" class="" value="Reset" onclick="expenseszyx987_resetTypesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_type_itemsperpage" name="expenses_type_itemsperpage" onchange="expenseszyx987_getTypesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_type_sortby" name="expenses_type_sortby" onchange="expenseszyx987_getTypesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total types: <span id="totaltypequantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_typelist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_type" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Type Category Name</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_type">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_type" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '4. Tax:', 'expenses_trdom' ) . "</h3>"; ?>

    <?php echo "<h3>" .  esc_html__( '4.1 Create a new tax', 'expenses_trdom' ) . "</h3>" ?>
    <form name="expenses_form94_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addTax")); ?>">
        <p><?php esc_html_e("Tax Name *: " ); ?><input type="text" name="expenseszyx987_addtaxname" value="" size="100"><?php esc_html_e(" e.g. HST" ); ?></p>
        <p><?php esc_html_e("Tax Rate *: " ); ?><input type="text" name="expenseszyx987_addtaxrate" value="" size="100"><?php esc_html_e(" e.g. 0.13" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addtaxdescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Tax', 'expenses_trdom' ) ?>" />
        </p>
    </form><hr />
    <?php echo "<h3>" .  esc_html__( '4.2 Tax list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_tax_container">
        <p>Search Name: <input type="text" id="expenses_tax_name" name="expenses_tax_name" class="" value="" size="50" /></p>
        <p>Search Tax Status: 
            <select id="expenses_tax_status" name="expenses_tax_status">
                <option value="-1">Please choose one...</option>
                <option value="0" >Not active</option>
                   <option value="1" >Active</option>
            </select>
        </p>    
        <p>
        <input type="button" id="expenses_tax_search" name="expenses_tax_search" class="" value="Search" onclick="expenseszyx987_getTaxesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" id="expenses_tax_searchreset" name="expenses_tax_searchreset" class="" value="Reset" onclick="expenseszyx987_resetTaxesSearchParameters();" style="background-color:grey;"/>
        </p>
        <p>Items per Page: 
            <select id="expenses_tax_itemsperpage" name="expenses_tax_itemsperpage" onchange="expenseszyx987_getTaxesList();" class="">
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_tax_sortby" name="expenses_tax_sortby" onchange="expenseszyx987_getTaxesList();" class="">
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total taxes: <span id="totaltaxquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_taxlist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_tax" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
              <tr>
                <th></th>
                <th>ID</th>
                <th>Name</th>
                <th>Rate</th>
                <th>Description</th>
                <th>Created Date(UTC)</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody id="expenses_tax">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_tax" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '5. Currency:', 'expenses_trdom' ) . "</h3>"; ?>

    <?php echo "<h3>" .  esc_html__( '5.1 Create a new currency', 'expenses_trdom' ) . "</h3>" ?>
    <form name="expenses_form9_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addCurrency")); ?>">
        <p><?php esc_html_e("Currency Name *: " ); ?><input type="text" name="expenseszyx987_addcurrencyname" value="" size="100"><?php esc_html_e(" e.g. USD" ); ?></p>
        <p><?php esc_html_e("Currency Sign *: " ); ?><input type="text" name="expenseszyx987_addcurrencysign" value="" size="100"><?php esc_html_e(" e.g. $" ); ?></p>
        <p><?php esc_html_e("ISO Currency Code *: " ); ?><input type="text" name="expenseszyx987_addcurrencyisocurrencycode" value="" size="100" maxlength="3"><?php esc_html_e(" e.g. USD" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addcurrencydescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Currency', 'expenses_trdom' ) ?>" />
        </p>
    </form><hr />
    <?php echo "<h3>" .  esc_html__( '5.2 Currency list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_currency_container">
        <p>Search Name: <input type="text" id="expenses_currency_name" name="expenses_currency_name" class="" value="" size="50" /></p>
        <p>Search Currency Status: 
            <select id="expenses_currency_status" name="expenses_currency_status">
                <option value="-1">Please choose one...</option>
                <option value="0" >Not active</option>
                   <option value="1" >Active</option>
            </select>
        </p>
        <p>
        <input type="button" id="expenses_currency_search" name="expenses_currency_search" class="" value="Search" onclick="expenseszyx987_getCurrenciesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" id="expenses_currency_searchreset" name="expenses_currency_searchreset" class="" value="Reset" onclick="expenseszyx987_resetCurrenciesSearchParameters();" style="background-color:grey;"/>
        </p>
        <p>Items per Page: 
            <select id="expenses_currency_itemsperpage" name="expenses_currency_itemsperpage" onchange="expenseszyx987_getCurrenciesList();" class="">
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_currency_sortby" name="expenses_currency_sortby" onchange="expenseszyx987_getCurrenciesList();" class="">
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total currencies: <span id="totalcurrencyquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_currencylist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_currency" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
              <tr>
                <th></th>
                <th>ID</th>
                <th>Name</th>
                <th>Sign</th>
                <th>ISO Currency Code</th>
                <th>Description</th>
                <th>Created Date(UTC)</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody id="expenses_currency">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_currency" style="display: inline-block;"></div>
        </div>
    </div><hr/>
</div>
<div id="expenses_tabs_3">
    <?php echo "<h3>" . esc_html__( '6. Role:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" .  esc_html__( '6.1 Create a new role', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form24_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addRole")); ?>">

        <p><?php esc_html_e("Role Name *: " ); ?><input type="text" name="expenseszyx987_addrolename" value="" size="100"><?php esc_html_e(" e.g. manager" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addroledescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Role', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new role. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '6.2 Role list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_role_container">
        <p>Search Name: <input type="text" id="expenses_role_name" name="expenses_role_name" class="" value="" size="50" /></p>
        <p>Search Role Status:
            <select id="expenses_role_status" name="expenses_role_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_role_search" name="expenses_role_search" class="" value="Search" onclick="expenseszyx987_getRolesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_role_searchreset" name="expenses_role_searchreset" class="" value="Reset" onclick="expenseszyx987_resetRolesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_role_itemsperpage" name="expenses_role_itemsperpage" onchange="expenseszyx987_getRolesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_role_sortby" name="expenses_role_sortby" onchange="expenseszyx987_getRolesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total roles: <span id="totalrolequantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_rolelist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_role" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_role">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_role" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '7. Department:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" . esc_html__( '7.1 Create a new department', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form35_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addDepartment")); ?>">

        <p><?php esc_html_e("Department Name *: " ); ?><input type="text" name="expenseszyx987_adddepartmentname" value="" size="100"><?php esc_html_e(" e.g. Sales" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_adddepartmentdescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Department', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new department. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '7.2 Department list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_department_container">
        <p>Search Name: <input type="text" id="expenses_department_name" name="expenses_department_name" class="" value="" size="50" /></p>
        <p>Search Department Status:
            <select id="expenses_department_status" name="expenses_department_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_department_search" name="expenses_department_search" class="" value="Search" onclick="expenseszyx987_getDepartmentsList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_department_searchreset" name="expenses_department_searchreset" class="" value="Reset" onclick="expenseszyx987_resetDepartmentsSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_department_itemsperpage" name="expenses_department_itemsperpage" onchange="expenseszyx987_getDepartmentsList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_department_sortby" name="expenses_department_sortby" onchange="expenseszyx987_getDepartmentsList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total departments: <span id="totaldepartmentquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_departmentlist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_department" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_department">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_department" style="display: inline-block;"></div>
        </div>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '8. User:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" . esc_html__( '8.1 Create a new user', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form36_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addUser")); ?>">

        <p><?php esc_html_e("First name *: " ); ?><input type="text" name="expenseszyx987_adduserfirstname" value="" size="50"><?php esc_html_e(" e.g. John" ); ?></p>
        <p><?php esc_html_e("Last name *: " ); ?><input type="text" name="expenseszyx987_adduserlastname" value="" size="50"><?php esc_html_e(" e.g. Jackson" ); ?></p>
        <p><?php esc_html_e("WordPress user ID *: " ); ?>
        <select name="expenseszyx987_adduserid"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeWPusers as $user) { ?>
           <option value="<?php echo intval($user->ID); ?>" style=""><?php echo esc_html($user->fullname) . " (" . intval($user->ID) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("Report to WordPress user ID *: " ); ?>
        <select name="expenseszyx987_adduserreportto"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeWPusers as $user) { ?>
           <option value="<?php echo intval($user->ID); ?>" style=""><?php echo esc_html($user->fullname) . " (" . intval($user->ID) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("User can read data in admin page (default is NO): " ); ?>
        <select name="expenseszyx987_addusercanreadinadminpage"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>

        <p><?php esc_html_e("User can create data in admin page (default is NO): " ); ?>
        <select name="expenseszyx987_addusercancreateinadminpage"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can edit data in admin page (default is NO): " ); ?>
        <select name="expenseszyx987_addusercaneditinadminpage"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can activate data in admin page (default is NO): " ); ?>
        <select name="expenseszyx987_addusercanactivateinadminpage"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can deactivate data in admin page (default is NO): " ); ?>
        <select name="expenseszyx987_addusercandeactivateinadminpage"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>

        <p><?php esc_html_e("Role : " ); ?>
        <select name="expenseszyx987_adduserrole"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeroles as $role) { ?>
           <option value="<?php echo intval($role->id); ?>" style="<?php echo $role->status === '1' ? '' : 'color:grey;'; ?>"><?php echo esc_html($role->name) . " (" . intval($role->id) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("Department : " ); ?>
        <select name="expenseszyx987_adduserdepartment"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activedepartments as $department) { ?>
           <option value="<?php echo intval($department->id); ?>" style="<?php echo $department->status === '1' ? '' : 'color:grey;'; ?>"><?php echo esc_html($department->name) . " (" . intval($department->id) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("Status (default is active): " ); ?>
        <select name="expenseszyx987_adduserstatus"  class="presetto_1"  >
           <option value="-1">Please choose one...</option>
           <option value="1">ACTIVE</option>
           <option value="0">NOT ACTIVE</option>
        </select></p>

        <p><?php esc_html_e("Email : " ); ?><input type="text" name="expenseszyx987_adduseremail" value="" size="50"><?php esc_html_e(" e.g. abc@gmail.com" ); ?></p>
        <p><?php esc_html_e("Phone : " ); ?><input type="text" name="expenseszyx987_adduserphone" value="" size="50"><?php esc_html_e(" e.g. 123-456-7890" ); ?></p>
        <p><?php esc_html_e("Address : " ); ?><input type="text" name="expenseszyx987_adduseraddress" value="" size="50"><?php esc_html_e(" e.g. 123 main road" ); ?></p>
        <p><?php esc_html_e("Address 2 : " ); ?><input type="text" name="expenseszyx987_adduseraddress2" value="" size="50"><?php esc_html_e(" e.g. suite 201" ); ?></p>
        <p><?php esc_html_e("City : " ); ?><input type="text" name="expenseszyx987_addusercity" value="" size="50"><?php esc_html_e(" e.g. London" ); ?></p>
        <p><?php esc_html_e("Province/State : " ); ?><input type="text" name="expenseszyx987_adduserprovince" value="" size="50"><?php esc_html_e(" e.g. Iowa" ); ?></p>
        <p><?php esc_html_e("Country : " ); ?><input type="text" name="expenseszyx987_addusercountry" value="" size="50"><?php esc_html_e(" e.g. Canada" ); ?></p>
        <p><?php esc_html_e("ZIP : " ); ?><input type="text" name="expenseszyx987_adduserzip" value="" size="50"><?php esc_html_e(" e.g. 03897" ); ?></p>        
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_adduserdescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create User', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new user. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '8.2 User list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_order_container">
        <p>Search User ID:
        <select id="expenses_user_userid" name="expenses_user_userid" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeWPusers as $user) { ?>
           <option value="<?php echo intval($user->ID); ?>" style=""><?php echo esc_html($user->fullname) . " (" . intval($user->ID) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p>Search User Full Name: <input type="text" id="expenses_user_userfullname" name="expenses_user_userfullname" class="" value="" size="50" /></p>

        <p>Search User Email: <input type="text" id="expenses_user_email" name="expenses_user_email" class="" value="" size="50" /></p>    

        <p><?php esc_html_e("Report to user ID *: " ); ?>
        <select id="expenses_user_reportto" name="expenses_user_reportto" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeWPusers as $user) { ?>
           <option value="<?php echo intval($user->ID); ?>" style=""><?php echo esc_html($user->fullname) . " (" . intval($user->ID) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("User can read data in admin page : " ); ?>
        <select id="expenses_user_canreadinadminpage" name="expenses_user_canreadinadminpage" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>

        <p><?php esc_html_e("User can create data in admin page : " ); ?>
        <select id="expenses_user_cancreateinadminpage" name="expenses_user_cancreateinadminpage" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can edit data in admin page : " ); ?>
        <select id="expenses_user_caneditinadminpage" name="expenses_user_caneditinadminpage" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can activate data in admin page : " ); ?>
        <select id="expenses_user_canactivateinadminpage" name="expenses_user_canactivateinadminpage" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>
        <p><?php esc_html_e("User can deactivate data in admin page : " ); ?>
        <select id="expenses_user_candeactivateinadminpage" name="expenses_user_candeactivateinadminpage" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <option value="1">YES</option>
           <option value="0">NO</option>
        </select></p>

        <p><?php esc_html_e("Role : " ); ?>
        <select id="expenses_user_roleid" name="expenses_user_roleid" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activeroles as $role) { ?>
           <option value="<?php echo intval($role->id); ?>" style="<?php echo $role->status === '1' ? '' : 'color:grey;'; ?>"><?php echo esc_html($role->name) . " (" . intval($role->id) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p><?php esc_html_e("Department : " ); ?>
        <select id="expenses_user_departmentid" name="expenses_user_departmentid" class="presetto_1" >
           <option value="-1">Please choose one...</option>
           <?php foreach ($activedepartments as $department) { ?>
           <option value="<?php echo intval($department->id); ?>" style="<?php echo $department->status === '1' ? '' : 'color:grey;'; ?>"><?php echo esc_html($department->name) . " (" . intval($department->id) . ")"; ?></option>
           <?php } ?>
        </select></p>

        <p>Search User Status: 
            <select id="expenses_user_status" name="expenses_user_status" class="presetto_1">
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_user_search" name="expenses_user_search" class="" value="Search" onclick="expenseszyx987_getUsersList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_user_searchreset" name="expenses_user_searchreset" class="" value="Reset" onclick="expenseszyx987_resetUsersSearchParameters();" style="background-color:grey;"/>
        </p>

        <p style="color:red;">This is not WordPress' wp_users table. This table name is wp_expenseszyx987_users. All the users in this table can access the plugin's landing page. But only users with WordPress administrator role can access the dashboard settings page for this Office Expenses Logbook plugin.</p>

        <p>Items per Page: 
            <select id="expenses_user_itemsperpage" name="expenses_user_itemsperpage" onchange="expenseszyx987_getUsersList();" class="presetto_1">
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_user_sortby" name="expenses_user_sortby" onchange="expenseszyx987_getUsersList();" class="presetto_1">
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="userid|asc" >User ID low-high</option>
                <option value="userid|desc" >User ID high-low</option>
                <option value="userfullname|asc" >User Full Name a-z</option>
                <option value="userfullname|desc" >User Full Name z-a</option>
            </select>
        </p>

        Total users: <span id="totaluserquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_userlist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_user" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>User ID</th>
                    <th>can read in adminpage</th>
                    <th>can create in adminpage</th>
                    <th>can edit in adminpage</th>
                    <th>can activate in adminpage</th>
                    <th>can deactivate in adminpage</th>
                    <th>Report to user ID</th>
                    <th>Role</th>
                    <th>Department</th>
                    <th>Status</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Address</th>
                    <th>Address2</th>
                    <th>City</th>
                    <th>Province</th>
                    <th>Country</th>
                    <th>ZIP</th>
                    <th>Description</th>
                    <th>Created(UTC)</th>
                </tr>
            </thead>
            <tbody id="expenses_user">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_user" style="display: inline-block;"></div>
        </div>

    </div><hr/>
</div>
<div id="expenses_tabs_4">
    <?php echo "<h3>" . esc_html__( '9. Constant:', 'expenses_trdom' ) . "</h3>"; ?>
    <div id="expenses_constant_container">
        <p style="color:red;font-weight:bold;">For this plugin to get your company's current local date, you must set the timezone value correctly. You can edit the timezone at Dashboard -> Settings -> General -> Timezone -> check if the value has been set correctly.</p>
        Total constants: <span id="totalconstantquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_constantlist_loader" alt="loading" style="display:none;" />
        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Value</th>
                    <th>Created(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_constant">
            </tbody>
        </table>
    </div><hr/>

    <?php echo "<h3>" . esc_html__( '10. Customer Type:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" . esc_html__( '10.1 Create a new customer type', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form11_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addCustomertype")); ?>">

        <p><?php esc_html_e("Customer Type Name *: " ); ?><input type="text" name="expenseszyx987_addcustomertypename" value="" size="100"><?php esc_html_e(" e.g. Finance" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addcustomertypedescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Customer Type', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new customer type. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '10.2 Customer type list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_customertype_container">
        <p>Search Name: <input type="text" id="expenses_customertype_name" name="expenses_customertype_name" class="" value="" size="50" /></p>
        <p>Search Customer Type Status:
            <select id="expenses_customertype_status" name="expenses_customertype_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_customertype_search" name="expenses_customertype_search" class="" value="Search" onclick="expenseszyx987_getCustomertypesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_customertype_searchreset" name="expenses_customertype_searchreset" class="" value="Reset" onclick="expenseszyx987_resetCustomertypesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_customertype_itemsperpage" name="expenses_customertype_itemsperpage" onchange="expenseszyx987_getCustomertypesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_customertype_sortby" name="expenses_customertype_sortby" onchange="expenseszyx987_getCustomertypesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total customer types: <span id="totalcustomertypequantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_customertypelist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_customertype" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_customertype">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_customertype" style="display: inline-block;"></div>
        </div>
    </div><hr/>    
    
    <?php echo "<h3>" . esc_html__( '11. Customer:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" . esc_html__( '11.1 Create a new customer', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form12_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addCustomer")); ?>">

        <p><?php esc_html_e("Customer Name *: " ); ?><input type="text" name="expenseszyx987_addcustomername" value="" size="100"><?php esc_html_e(" e.g. KFC" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addcustomerdescription" rows="4" cols="100"></textarea><br/></p>
        <p>Customer Type:
        <select id="expenseszyx987_addcustomercustomertype" name="expenseszyx987_addcustomercustomertype" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($allcustomertypes as $customertype) { ?>
           <option value="<?php echo intval($customertype->id); ?>" ><?php echo esc_html($customertype->name); ?></option>
           <?php } ?>
         </select></p>
        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Customer', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new customer. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '11.2 Customer list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_customer_container">
        <p>Search Name: <input type="text" id="expenses_customer_name" name="expenses_customer_name" class="" value="" size="50" /></p>

        <p>Search Customer Type:
        <select id="expenses_customer_customertype" name="expenses_customer_customertype" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($allcustomertypes as $customertype) { ?>
           <option value="<?php echo $customertype->id; ?>" ><?php echo esc_html($customertype->name); ?></option>
           <?php } ?>
         </select></p>
         
        <p>Search Customer Status:
            <select id="expenses_customer_status" name="expenses_customer_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_customer_search" name="expenses_customer_search" class="" value="Search" onclick="expenseszyx987_getCustomersList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_customer_searchreset" name="expenses_customer_searchreset" class="" value="Reset" onclick="expenseszyx987_resetCustomersSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_customer_itemsperpage" name="expenses_customer_itemsperpage" onchange="expenseszyx987_getCustomersList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_customer_sortby" name="expenses_customer_sortby" onchange="expenseszyx987_getCustomersList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total customers: <span id="totalcustomerquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_customerlist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_customer" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Customer Type</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_customer">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_customer" style="display: inline-block;"></div>
        </div>
    </div><hr/>    

    <?php echo "<h3>" . esc_html__( '12. Recurring payment frequency:', 'expenses_trdom' ) . "</h3>"; ?>
    <?php echo "<h3>" . esc_html__( '12.1 Create a new recurring payment frequency', 'expenses_trdom' ) . "</h3>" ?>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form13_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_addRecurringpaymentfrequency")); ?>">

        <p><?php esc_html_e("Recurring Payment Frequency Name *: " ); ?><input type="text" name="expenseszyx987_addrecurringpaymentfrequencyname" value="" size="100"><?php esc_html_e(" e.g. Yearly" ); ?></p>
        <p><?php esc_html_e("Description: " ); ?><br/><textarea name="expenseszyx987_addrecurringpaymentfrequencydescription" rows="4" cols="100"></textarea><br/></p>

        <p class="submit">
            <input type="submit" name="Submit" onclick="return expenseszyx987_validateInput();" value="<?php esc_html_e('Create Recurring Payment Frequency', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to create a new recurring payment frequency. Please contact web admin.</p>
    <?php } ?>
        <hr />
    <?php echo "<h3>" .  esc_html__( '12.2 Recurring payment frequency list', 'expenses_trdom' ) . "</h3>" ?>
    <div id="expenses_recurringpaymentfrequency_container">
        <p>Search Name: <input type="text" id="expenses_recurringpaymentfrequency_name" name="expenses_recurringpaymentfrequency_name" class="" value="" size="50" /></p>
        <p>Search Recurring Payment Frequency Status:
            <select id="expenses_recurringpaymentfrequency_status" name="expenses_recurringpaymentfrequency_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="1" >ACTIVE</option>
                <option value="0" >NOT ACTIVE</option>
            </select>
        </p>

        <p>
            <input type="button" id="expenses_recurringpaymentfrequency_search" name="expenses_recurringpaymentfrequency_search" class="" value="Search" onclick="expenseszyx987_getRecurringpaymentfrequenciesList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="expenses_recurringpaymentfrequency_searchreset" name="expenses_recurringpaymentfrequency_searchreset" class="" value="Reset" onclick="expenseszyx987_resetRecurringpaymentfrequenciesSearchParameters();" style="background-color:grey;"/>
        </p>

        <p>Items per Page:
            <select id="expenses_recurringpaymentfrequency_itemsperpage" name="expenses_recurringpaymentfrequency_itemsperpage" onchange="expenseszyx987_getRecurringpaymentfrequenciesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_recurringpaymentfrequency_sortby" name="expenses_recurringpaymentfrequency_sortby" onchange="expenseszyx987_getRecurringpaymentfrequenciesList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="name|asc" >Name a-z</option>
                <option value="name|desc" >Name z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total recurring payment frequencies: <span id="totalrecurringpaymentfrequencyquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_recurringpaymentfrequencylist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_recurringpaymentfrequency" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_recurringpaymentfrequency">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_recurringpaymentfrequency" style="display: inline-block;"></div>
        </div>
    </div><hr/>    

    <?php echo "<h3>" . esc_html__( '13. Log:', 'expenses_trdom' ) . "</h3>"; ?>
    <div id="expenses_log_container">
        <p>Search Type:
        <select id="expenses_log_type" name="expenses_log_type" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($log_types as $log_type) { ?>
           <option value="<?php echo esc_html($log_type->type); ?>" ><?php echo esc_html($log_type->type); ?></option>
           <?php } ?>
         </select></p>

        <p>Search Process Name:
        <select id="expenses_log_processname" name="expenses_log_processname" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($log_processnames as $log_processname) { ?>
           <option value="<?php echo esc_html($log_processname->processname); ?>" ><?php echo esc_html($log_processname->processname); ?></option>
           <?php } ?>
         </select></p>

        <p>Search User ID:
        <select id="expenses_log_userid" name="expenses_log_userid" class="presetto_1">
           <option value="-1">Please choose one...</option>
           <?php foreach ($log_userids as $log_userid) { ?>
           <option value="<?php echo ($log_userid === null || empty($log_userid->userid)) ? 0 : intval($log_userid->userid); ?>" ><?php echo ($log_userid === null || empty($log_userid->userid)) ? 0 : intval($log_userid->userid); ?></option>
           <?php } ?>
         </select></p>

        <p>Search Description: <input type="text" id="expenses_log_description" name="expenses_log_description" class="" value="" size="50" /></p>
        <p>Search Status:
            <select id="expenses_log_status" name="expenses_log_status" class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="0" >NOT ACTIVE</option>
                   <option value="1" >ACTIVE</option>
            </select>
        </p>
        <p>
        <input type="button" id="expenses_log_search" name="expenses_log_search" class="" value="Search" onclick="expenseszyx987_getLogsList();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" id="expenses_log_searchreset" name="expenses_log_searchreset" class="" value="Reset" onclick="expenseszyx987_resetLogsSearchParameters();" style="background-color:grey;"/>
        </p>
        <p>Items per Page:
            <select id="expenses_log_itemsperpage" name="expenses_log_itemsperpage" onchange="expenseszyx987_getLogsList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="10" >10</option>
                <option value="20" >20</option>
                <option value="40" >40</option>
                <option value="60" >60</option>
                <option value="80" >80</option>
                <option value="100" >100</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            Sort By:
            <select id="expenses_log_sortby" name="expenses_log_sortby" onchange="expenseszyx987_getLogsList();"  class="presetto_1" >
                <option value="-1">Please choose one...</option>
                <option value="id|asc" >ID low-high</option>
                <option value="id|desc" >ID high-low</option>
                <option value="type|asc" >Type a-z</option>
                <option value="type|desc" >Type z-a</option>
                <option value="createtimeutc|asc" >Created Date old-new</option>
                <option value="createtimeutc|desc" >Created Date new-old</option>
            </select>
        </p>

        Total logs: <span id="totallogquantity"></span><img src="<?php echo esc_html(plugin_dir_url( __FILE__ ));  ?>images/loading.gif" id="admin_loglist_loader" alt="loading" style="display:none;" />

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_log" style="display: inline-block;"></div>
        </div>

        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Type</th>
                    <th>Process Name</th>
                    <th>User ID</th>
                    <th>Description</th>
                    <th>Created Date(UTC)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody id="expenses_log">
            </tbody>
        </table>

        <div class="row master_pwrapper">
            <div class="col-xs-12 master_mypagination master_mypagination_admin_log" style="display: inline-block;"></div>
        </div>
    </div><br/>
</div>
<div id="expenses_tabs_5">
        <?php echo "<h3>" .  esc_html__( '1. Enable automatically backup MySQL database', 'expenses_trdom' ) . "</h3>" ?>
        <p>Currently the auto backup is <?php echo wp_next_scheduled('expenseszyx987_cron_dbbackup_hook') ? '<span style="color:green;">enabled</span>' : '<span style="color:red;">NOT enabled</span>'; ?>.<p>
        <p style="color:brown;">It only backups tables, not views and stored procedures. If the auto backup is enabled and you want to update it, disable the auto backup first, then enable it again with the new parameters.</p>
        <p style="color:brown;">You can find DBBACKUP_LOCALTIME, DBBACKUP_FREQUENCY values from constant table. DBBACKUP_DETAILS value is confidential and encoded in database.</p>
    <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
    <form name="expenses_form_3_5_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_enableAutoBackupDatabaseEveryday")); ?>">    
        <p>Create a new MySQL database username and password to connect to your database and backup the whole database(Your existing MySQL database username and password must have the ability to create a new user):</p>
        <p>Database hostname: <input type="text" id="expenses_dbbackup_hostname" name="expenses_dbbackup_hostname" class="" value="" size="50" />(e.g. localhost)</p>
        <p>Database username: <input type="text" id="expenses_dbbackup_username" name="expenses_dbbackup_username" class="" value="" size="50" /></p>
        <p>Database password: <input type="password" id="expenses_dbbackup_password" name="expenses_dbbackup_password" class="" value="" size="50" /></p>
        <p>Database name: <input type="text" id="expenses_dbbackup_dbname" name="expenses_dbbackup_dbname" class="" value="" size="50" />(Leave it blank if you want to backup all the databases. If several databases, separate them with one space)</p>
        <p>mysqldump file location: <input type="text" id="expenses_dbbackup_mysqldumppath" name="expenses_dbbackup_mysqldumppath" class="" value="" size="50" />(e.g. C:/Program Files/MySQL/MySQL Server 5.7/bin/)</p>
        <p>Database backup file save location: <input type="text" id="expenses_dbbackup_backupfilelocation" name="expenses_dbbackup_backupfilelocation" class="" value="" size="50" />(Do not save this file in your wordpress source code folders. It should be a secure location that hackers can not access. And it should have at least 1GB free space. e.g. G:/dbbackup/)</p>
        <p>Backup Frequency:
        <select id="expenses_dbbackup_frequency" class="presetto_1" name="expenses_dbbackup_frequency" >
            <option value="-1">Please choose one...</option>
            <option value="daily">daily</option>
               <option value="weekly">weekly (Since WordPress 5.4)</option>
            <option value="twicedaily">twicedaily</option>
            <option value="hourly">hourly</option>
         </select>
        <p style="color:brown;">Your current timezone (it's set in the dashboard, settings) is: <span id="expenses_form_3_5_1_backup_timezone" style="color:red;"><?php echo esc_html(get_option('timezone_string')); ?></span>. If it's not correct, please update in the dashboard, settings.</p>
        <p>First Time Backup Local (not UTC) Date Time: <input type="text" id="expenses_dbbackup_time" name="expenses_dbbackup_time" class="expenseszyx987_datetimepicker" value="" size="50" />(e.g. 2021-06-02 04:00:00)</p>

        <p class="submit">
            <input type="submit" name="Submit" class="" onclick="return expenseszyx987_confirmEnableAutoBackupDatabaseEveryday();" value="<?php esc_html_e('ENABLE automatically backup database', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to enable backup database. Please contact web admin.</p>
    <?php } ?>
        <p>If the database backup file is not automatically created, please contact the plugin provider for help. See the documentation for the backup files location. If you need to restore your MySQL database, you need to manually restore the database using some command like "mysql -u <user> -p < db_backup.dump"</p>
        <hr />

        <?php echo "<h3>" .  esc_html__( '2. Disable automatically backup MySQL database', 'expenses_trdom' ) . "</h3>" ?>
        <p>Currently the auto backup is <?php echo wp_next_scheduled('expenseszyx987_cron_dbbackup_hook') ? '<span style="color:green;">enabled</span>' : '<span style="color:red;">NOT enabled</span>'; ?>.<p>
    <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
    <form name="expenses_form_3_6_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_disableAutoBackupDatabaseEveryday")); ?>">    

        <p class="submit">
            <input type="submit" name="Submit" class="delete-danger" onclick="return expenseszyx987_confirmDisableAutoBackupDatabaseEveryday();" value="<?php esc_html_e('DISABLE automatically backup database', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to disable backup database. Please contact web admin.</p>
    <?php } ?>

            <?php echo "<h3>" .  esc_html__( '3. One time immediate backup MySQL database', 'expenses_trdom' ) . "</h3>" ?>
        <p>Currently the auto backup is <?php echo wp_next_scheduled('expenseszyx987_cron_dbbackup_hook') ? '<span style="color:green;">enabled</span>' : '<span style="color:red;">NOT enabled</span>'; ?>.<p>
        <p style="color:brown;">It only backups tables, not views and stored procedures. Sometimes, the automatically backup does not work. Then you can click this button to one time immediately backup database which was entered in section 3 "Enable automatically backup MySQL database". You must go to section 3 to enter and save data first for this feature.</p>
    <?php  if(intval($userdetails[0]["caneditinadminpage"]) === 1) {  ?>
    <form name="expenses_form_3_5_1" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_backupDatabaseNow")); ?>">
        <p class="submit">
            <input type="submit" name="Submit" class="" onclick="return expenseszyx987_confirmEnableOnetimeImmediateBackupDatabase();" value="<?php esc_html_e('Backup database now', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to enable backup database. Please contact web admin.</p>
    <?php } ?>
        <hr />
</div>
<div id="expenses_tabs_6">
    <p>Attention: The old stored procedures will be dropped. Then the new stored procedures will be created.</p>
    <?php  if(intval($userdetails[0]["cancreateinadminpage"]) === 1) {  ?>
    <form name="expenses_form_3_7_14" method="post" action="<?php echo esc_html(str_replace( '%7E', '~', esc_html($_SERVER['REQUEST_URI']))); ?>" enctype="multipart/form-data">
        <input type="hidden" name="expenseszyx987_hidden" value="Y">
        <input type="hidden" name="expenseszyx987_hidden_security" value="<?php echo esc_html(wp_create_nonce("expenseszyx987_dropAllStoredprocedures")); ?>">
        <p class="submit">
            <input type="submit" name="Submit" class="delete-danger" onclick="return expenseszyx987_confirmDropSP('all', false);" value="<?php esc_html_e('Recreate all the stored procedures', 'expenses_trdom' ) ?>" />
        </p>
    </form>
    <?php } else { ?>
            <p style="color:red;">You are not authorized to drop tables. Please contact web admin.</p>
    <?php } ?>
</div>
<div id="expenses_tabs_7">
<h3>Here are the manual for this plugin:</h3><br/>
<a style="color:blue;" href="<?php echo plugins_url('documentation_expenses.pdf', __FILE__ ); ?>" >Manual pdf</a><br/><br/>
</div>
</div>
</div>