<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page
$subscriptions_taxrateObj =  new  subscriptions_taxrate();
if(isset($_REQUEST['act']) && $_REQUEST['act']=='change_status' && isset($_REQUEST['plan_id'])){
    
    
    if(isset($_REQUEST['status']))
    {
        if($_REQUEST['status'] == '0')
        {
            $data['plan_status'] = 'inactive';
        }else
        {
            $data['plan_status'] = 'active';
        }
        $planID = $_REQUEST['plan_id'];

        $updaters=$subscription_plansObj->updateRecords($data,$planID);
        echo RECORD_STATUS;
    }
    return true;
}
/*if(isset($_REQUEST['act']) && $_REQUEST['act']=='delete' && isset($_REQUEST['user_id'])){
    $subscriptions_taxrateObj->deleteFromId($_REQUEST['user_id']);
    $successMsg = base64_encode(RECORD_DELETE);
}*/


if (isset($_REQUEST['act']) && $_REQUEST['act']=='load'){
    $records = $_REQUEST['length'];
    $start=0;
    if(isset($_GET['start']) && $_GET['start']!='0'){
        $page = $_GET['start'];
    }
    $start=($page-1)*$limit;
    $limit = array('start'=>$_GET['start'],'record'=>$records);

    $where = " 1=1 ";

    if(isset($_REQUEST['tax_name']) && $_REQUEST['tax_name'] != '')
    {
       $where .= " AND taxrate_display_name = '".$_REQUEST['tax_name']."'";
    }
    
    if(isset($_REQUEST['tax_id']) && $_REQUEST['tax_id'] != '')
    {
        $where .= " AND taxrate_txr_id = '".$_REQUEST['tax_id']."'";
    }
    
    if(isset($_REQUEST['tax_rate']) && $_REQUEST['tax_rate'] != '')
    {
        $where .= " AND  taxrate_percentage = '".$_REQUEST['tax_rate']."' ";
    }

    if(isset($_REQUEST['tax_mode']) && $_REQUEST['tax_mode'] != '')
    {
        $where .= " AND taxrate_mode = '".$_REQUEST['tax_mode']."'";
    }

    if(isset($_REQUEST['tax_status']) && $_REQUEST['tax_status'] != '')
    {
        $where .= " AND  taxrate_status = '".$_REQUEST['tax_status']."' ";
    }
    

    if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = " taxrate_txr_id LIKE '%".$_REQUEST['search']['value']."%' OR taxrate_type LIKE '%".$_REQUEST['search']['value']."%' OR taxrate_display_name LIKE '%".$_REQUEST['search']['value']."%' OR taxrate_percentage LIKE '%".$_REQUEST['search']['value']."%' OR taxrate_mode LIKE '%".$_REQUEST['search']['value']."%' OR taxrate_region LIKE '%".$_REQUEST['search']['value']."%' OR  taxrate_status LIKE '%".$_REQUEST['search']['value']."%'";
        
    } 
    
    $taxArg    = array('where'=>$where,'limit' => $limit);

    $taxDetails = $subscriptions_taxrateObj->getAllRecords($taxArg);

    $recordsTotal   =   $subscriptions_taxrateObj->getAllCount($planArg);

        
    if ($taxDetails && count($taxDetails)>0){
        foreach ($taxDetails as $key => $taxdata){
            
            $response[] = array('<input type="checkbox" name="check[]" id="check[]" value="'.$taxdata->taxrate_id .'" class="check_class" />',
                    $taxdata->taxrate_id,
                    $taxdata->taxrate_txr_id,
                    $taxdata->taxrate_type,    
                    $taxdata->taxrate_display_name, 
                    $taxdata->taxrate_percentage, 
                    $taxdata->taxrate_mode,
                    $taxdata->taxrate_region,
                    $taxdata->taxrate_status,
             );
        }
        $result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response);
    }else{
        $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
    }
    echo json_encode($result);
    exit;
}

// Include Template 
include_once('../libs/routs.php');
?>