function process_ajax_get_tasks_per_project()
{
    $has_admin = array();
    //@TODO ADD NONCE CHECK
    $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
    $project_id = isset($_POST['project_id']) ? $_POST['project_id'] : 0;
    if ($post_id <= 0 && $project_id <= 0) {
        return;
    }
    $asscoiativeTasks = array();
    if ($project_id == 0) {
        $project_id = get_post_meta($post_id, 'project', true);
        $project_id = maybe_get_pod_id($project_id);
    }
    $args = array('post_type' => 'mg_task', 'meta_key' => 'project', 'meta_value' => $project_id, 'post_status' => array('complete', 'in-progress', 'not-started', 'publish', 'published'), 'posts_per_page' => -1);
    $the_query = new WP_Query($args);
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $asscoiativeTasks[] = get_the_ID();
    }
    $data = array('tasks' => $asscoiativeTasks);
    $output = json_encode($data);
    exit($output);
}
function invoice_or_estimate_update($est_to_add, $est_to_remove, $inv_to_add, $inv_to_remove, $changed_fields, $id)
{
    if (isset($changed_fields['add_line_item_to_estimate'])) {
        if ($changed_fields['add_line_item_to_estimate'] === '' || isset($_SESSION['prev_est']) && check_for_value($_SESSION['prev_est']) === true) {
            if (isset($_SESSION['prev_est']) && check_for_value($_SESSION['prev_est']) === true) {
                $current_estimates = maybe_get_pod_id($_SESSION['prev_est']);
                if ($est_to_remove === false) {
                    if (check_for_value($changed_fields['add_line_item_to_estimate']) === false) {
                        $est_to_remove = false;
                    } else {
                        if (!is_array($current_estimates)) {
                            $current_estimates = explode(",", $current_estimates);
                        }
                        if (!is_array($changed_fields['add_line_item_to_estimate'])) {
                            $changed_fields['add_line_item_to_estimate'] = explode(",", $changed_fields['add_line_item_to_estimate']);
                        }
                        $est_to_remove = array_diff($current_estimates, $changed_fields['add_line_item_to_estimate']);
                    }
                }
            }
        }
        if (is_array($changed_fields['add_line_item_to_estimate']) && check_for_value($changed_fields['add_line_item_to_estimate']) === true && (!isset($est_to_add) || isset($est_to_add) && check_for_value($est_to_add) === false)) {
            $est_to_add = $changed_fields['add_line_item_to_estimate'];
        }
    }
    if (isset($changed_fields['add_line_item_to_invoice'])) {
        if ($changed_fields['add_line_item_to_invoice'] === '' || isset($_SESSION['prev_inv']) && check_for_value($_SESSION['prev_inv']) === true) {
            if (isset($_SESSION['prev_inv']) && check_for_value($_SESSION['prev_inv']) === true) {
                $current_invoices = maybe_get_pod_id($_SESSION['prev_inv']);
                if ($inv_to_remove === false) {
                    if (check_for_value($changed_fields['add_line_item_to_invoice']) === false) {
                        $inv_to_remove = false;
                    } else {
                        if (!is_array($current_invoices)) {
                            $current_invoices = explode(",", $current_invoices);
                        }
                        if (!is_array($changed_fields['add_line_item_to_invoice'])) {
                            $changed_fields['add_line_item_to_invoice'] = explode(",", $changed_fields['add_line_item_to_invoice']);
                        }
                        $inv_to_remove = array_diff($current_invoices, $changed_fields['add_line_item_to_invoice']);
                    }
                }
            }
        }
        if (is_array($changed_fields['add_line_item_to_invoice']) && check_for_value($changed_fields['add_line_item_to_invoice']) === true && (!isset($inv_to_add) || isset($inv_to_add) && check_for_value($inv_to_add) === false)) {
            $inv_to_add = $changed_fields['add_line_item_to_invoice'];
        }
    }
    $invoice_changes = array();
    $estimate_changes = array();
    if ($inv_to_add !== false) {
        $invoice_add = array('invoices_to_add' => $inv_to_add);
        $invoice_changes = array_merge($invoice_changes, $invoice_add);
    }
    if ($inv_to_remove !== false) {
        $inv_remove = array('invoices_to_remove' => $inv_to_remove);
        $invoice_changes = array_merge($invoice_changes, $inv_remove);
    }
    if ($est_to_add !== false) {
        $est_add = array('estimates_to_add' => $est_to_add);
        $estimate_changes = array_merge($estimate_changes, $est_add);
    }
    if ($est_to_remove !== false) {
        $est_remove = array('estimates_to_remove' => $est_to_remove);
        $estimate_changes = array_merge($estimate_changes, $est_remove);
    }
    if (isset($changed_fields['percent_adjustment']) || isset($changed_fields['rate']) || isset($changed_fields['quantity']) || isset($changed_fields['estimated_time'])) {
        if (isset($inv_to_add) && $inv_to_add !== false && !empty($inv_to_add) && !is_null($inv_to_add) && (isset($inv_to_add[0]) && $inv_to_add[0] !== false && !empty($inv_to_add[0]) && !is_null($inv_to_add[0])) || isset($_SESSION["update_inv"]) && $_SESSION["update_inv"] !== false && !empty($_SESSION["update_inv"]) && !is_null($_SESSION["update_inv"]) && (isset($_SESSION["update_inv"][0]) && $_SESSION["update_inv"][0] !== false && !empty($_SESSION["update_inv"][0]) && !is_null($_SESSION["update_inv"][0])) || isset($_SESSION["prev_inv"]) && $_SESSION["prev_inv"] !== false && !empty($_SESSION["prev_inv"]) && !is_null($_SESSION["prev_inv"]) && (isset($_SESSION["prev_inv"][0]) && $_SESSION["prev_inv"][0] !== false && !empty($_SESSION["prev_inv"][0]) && !is_null($_SESSION["prev_inv"][0]))) {
            if (isset($_SESSION["update_inv"]) && $_SESSION["update_inv"] !== false && !empty($_SESSION["update_inv"]) && !is_null($_SESSION["update_inv"]) && (isset($_SESSION["update_inv"][0]) && $_SESSION["update_inv"][0] !== false && !empty($_SESSION["update_inv"][0]) && !is_null($_SESSION["update_inv"][0]))) {
                $inv_to_add = maybe_get_pod_id($_SESSION["update_inv"]);
            } elseif (isset($_SESSION["prev_inv"]) && $_SESSION["prev_inv"] !== false && !empty($_SESSION["prev_inv"]) && !is_null($_SESSION["prev_inv"]) && (isset($_SESSION["prev_inv"][0]) && $_SESSION["prev_inv"][0] !== false && !empty($_SESSION["prev_inv"][0]) && !is_null($_SESSION["prev_inv"][0]))) {
                $inv_to_add = maybe_get_pod_id($_SESSION["prev_inv"]);
            }
            $inv_update = array('invoices_to_update' => $inv_to_add);
            $invoice_changes = array_merge($invoice_changes, $inv_update);
        }
    }
    if (isset($changed_fields['percent_adjustment']) || isset($changed_fields['rate']) || isset($changed_fields['quantity']) || isset($changed_fields['estimated_time'])) {
        if (isset($est_to_add) && $est_to_add !== false && !empty($est_to_add) && !is_null($est_to_add) && (isset($est_to_add[0]) && $est_to_add[0] !== false && !empty($est_to_add[0]) && !is_null($est_to_add[0])) || isset($_SESSION["update_est"]) && $_SESSION["update_est"] !== false && !empty($_SESSION["update_est"]) && !is_null($_SESSION["update_est"]) && (isset($_SESSION["update_est"][0]) && $_SESSION["update_est"][0] !== false && !empty($_SESSION["update_est"][0]) && !is_null($_SESSION["update_est"][0])) || isset($_SESSION["prev_est"]) && $_SESSION["prev_est"] !== false && !empty($_SESSION["prev_est"]) && !is_null($_SESSION["prev_est"]) && (isset($_SESSION["prev_est"][0]) && $_SESSION["prev_est"][0] !== false && !empty($_SESSION["prev_est"][0]) && !is_null($_SESSION["prev_est"][0]))) {
            if (isset($_SESSION["update_est"]) && $_SESSION["update_est"] !== false && !empty($_SESSION["update_est"]) && !is_null($_SESSION["update_est"]) && (isset($_SESSION["update_est"][0]) && $_SESSION["update_est"][0] !== false && !empty($_SESSION["update_est"][0]) && !is_null($_SESSION["update_est"][0]))) {
                $est_to_add = maybe_get_pod_id($_SESSION["update_est"]);
            } elseif (isset($_SESSION["prev_est"]) && $_SESSION["prev_est"] !== false && !empty($_SESSION["prev_est"]) && !is_null($_SESSION["prev_est"]) && (isset($_SESSION["prev_est"][0]) && $_SESSION["prev_est"][0] !== false && !empty($_SESSION["prev_est"][0]) && !is_null($_SESSION["prev_est"][0]))) {
                $est_to_add = maybe_get_pod_id($_SESSION["prev_est"]);
            }
            $est_update = array('estimates_to_update' => $est_to_add);
            $estimate_changes = array_merge($estimate_changes, $est_update);
        }
    }
    $output = ['estimates' => $estimate_changes, 'invoices' => $invoice_changes];
    return $output;
}