<?php

global $wpdb;
global $current_user;
// Use global
get_currentuserinfo();
// Make sure global is set, if not set it.
$company_id = $current_user->company_id;
$company_name = $current_user->company_name;
//In case of generating application from quotation then show payment tab for showing quotation amount in application tabs
$show_payment_tab = isset($_REQUEST['show_payment_tab']) && !empty($_REQUEST['show_payment_tab']) ? $_REQUEST['show_payment_tab'] : 0;
$new_application_id = 0;
if (isset($_GET['appid'])) {
    $appid = base64_decode($_GET['appid']);
    $CrmOperationsobj = new CrmOperations();
    $resultsfromcrm = $CrmOperationsobj->getCrmEntityDetails('new_application', array('type' => 'and', 'conditions' => array(array('attribute' => 'new_applicationid', 'operator' => 'eq', 'value' => $appid))), 'list');
    //echo "<pre>";print_r($resultsfromcrm);die;
}
if (!isset($appid) && isset($_GET['id'])) {
    $appid = base64_decode($_GET['id']);
}
$status = '';
if (isset($_GET['id']) || isset($_GET['crmid'])) {
    if (user_can($current_user, "staff") || user_can($current_user, "assessor")) {
        $sql = 'select * from ' . $wpdb->prefix . 'application_data where id=' . base64_decode($_GET['id']) . " AND status!='Draft'";
    } else {
        if (user_can($current_user, "contact")) {
            $sql = 'select * from ' . $wpdb->prefix . 'application_data left join ' . $wpdb->prefix . 'application_user_roles on ' . $wpdb->prefix . 'application_user_roles.application_id=' . $wpdb->prefix . 'application_data.id where ' . $wpdb->prefix . 'application_data.id=' . base64_decode($_GET['id']);
        } else {
            $sql = 'select * from ' . $wpdb->prefix . 'application_data where id=' . base64_decode($_GET['id']) . " AND user_id=" . get_current_user_id();
        }
function get_invoice_from_crm()
{
    $CrmOperationsobj = new CrmOperations();
    $resultsfromcrm = $CrmOperationsobj->getCrmEntityDetails('invoice', array('type' => 'and', 'conditions' => array(array('attribute' => 'new_applicationid', 'operator' => 'eq', 'value' => $_POST['app_id']))), 'list');
    // echo "<pre>";print_r($resultsfromcrm);
    $resulttotal = $resultsfromcrm->TotalRecordCount;
    foreach ($resultsfromcrm->Entities as $result) {
    }
    echo $result->name . "~" . $result->totalamount->FormattedValue;
}
<?php

global $wpdb, $per_page, $resulttotal;
global $current_user;
// Use global
get_currentuserinfo();
// Make sure global is set, if not set it.
//include(WP_PLUGIN_DIR.'crm-connector/CrmOperations.php');
$CrmOperationsobj = new CrmOperations();
$resultsfromcrm = $CrmOperationsobj->getCrmEntityDetails('new_application', array('type' => 'and', 'conditions' => array(array('entityname' => 'new_certificate', 'operator' => 'null', 'attribute' => "new_certificateid", 'value' => ''))), 'list', '', $page, $per_page, false);
//echo "<pre>";print_r($resultsfromcrm);
$resulttotal = $resultsfromcrm->TotalRecordCount;
$roles = get_user_meta(get_current_user_id(), "wp_capabilities");
$company_admin = is_user_company_admin();
if (user_can($current_user, "customer") && $company_admin == 1) {
    $sql = "select `id`, `name`, `doc_id` from " . $wpdb->prefix . "applications ";
    $new_accreditation = $wpdb->get_results($sql);
    ?>
<script>
$(document).ready(function() {
    $('#apply_for_new_accreditation_table').DataTable( {
        "searching": false,
		"processing": true,
		"sDom": '<"head-controls"l<"app-filter">f>t<"foot-controls"ip>',
		"bPaginate":false,
		"aoColumnDefs": [
          { 'bSortable': false, 'aTargets': [ 1,2 ] }
       ]
    } );
	jQuery(".colorbox-inline-70").colorbox({
			 overlayClose: false, 
            <th>Status</th>


            <th>Amount Due</th>
            <th>Pay</th>

        </tr>
    </thead>

    <tbody>

        <?php 
if (isset($_GET['crmid'])) {
    $crmid = base64_decode($_GET['crmid']);
    $CrmOperationsobj = new CrmOperations();
    $resultsfromcrm = $CrmOperationsobj->getCrmEntityDetails('invoice', array('type' => 'and', 'conditions' => array(array('attribute' => 'customerid', 'operator' => 'eq', 'value' => $crmid))), 'list', '', $page, $per_page);
    // echo "<pre>";print_r($resultsfromcrm);
    $resulttotal = $resultsfromcrm->TotalRecordCount;
    foreach ($resultsfromcrm->Entities as $result) {
        ?>
                <tr>
                    <td><?php 
        echo isset($result->new_applicationid->Id) ? $result->new_applicationid->Id : "";
        ?>
</td>
                    <td><?php 
        echo isset($result->statuscode->FormattedValue) ? $result->statuscode->FormattedValue : "";
        ?>
</td>
                    <td><?php 
        echo isset($result->totalamount->FormattedValue) ? $result->totalamount->FormattedValue : "";