<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; 
use Auth;
use Session;
use steelAuth;
use curlHandler;
use commonFunction;
use DB;
class HometabController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index(Request $request)
    {
     try {
		 
         $param = $request->all();
           $tab = 'prices';

        if(isset($param['tab'])){
            $tab= $param['tab'];
        }
		$homeTabsection = '';
		if(isset($param['section'])){
            $homeTabsection = $param['section'];
        }
        if($tab!='events' && $homeTabsection!='homefilter'){
         if(steelAuth::getID()){
                $checkAccess = steelAuth::checkAccess($tab);
                 if($checkAccess=='false'){
                    return redirect()->route('checkPermission');
                }
              }
        }
		
		$sectionST=array();
	/*	if((isset($param['searchTerm']) && $param['searchTerm']!='') || empty($param)){
            ///$tab= $param['tab'];
			$param['commodity'] = 'all';
			$param['location'] = 'all';
			$param['tab'] = 'prices';
			$param['selectComm'] = 'All';
			$param['selectRegion'] = 'All';
			if( steelAuth::getID()  == 56350 && (isset($param['searchTerm']) && $param['searchTerm']!='')){
				
				$c_phrase_server = "http://0.0.0.0:8947";
				$utterance = trim($param['searchTerm']);
				
				$resultST = json_decode(file_get_contents($c_phrase_server."/api/slot-filler?session=0&question=".urlencode($utterance)), true );
				
				echo "<pre>" , $utterance, print_r($resultST), "</pre>" ;
				$focusTab='';
				$itemCommodity=array();
				$itemRegion=array();
				foreach($resultST['interpretations'] as $res){
					if($focusTab=='')
						$focusTab = $res['focus'];
					foreach($res['slots'] as $slot){
						$sectionST[$res['focus']][$slot['slot']][] = $slot['value'];
						
						if(strpos($slot['slot'], "commodity") !== false){
							if(strpos($slot['value'], "[") !== false)
								$itemCommodity = explode(',',strtr($slot['value'], array('['=>'',']'=>'',"'"=>'')));
							else
								$itemCommodity[] = strtr($slot['value'], array('['=>'',']'=>''));
							//$itemCommodity[] = $slot['value'];
						}
						if(strpos($slot['slot'], "country") !== false){
							//$itemRegion[] = $slot['value'];
							if(strpos($slot['value'], "[") !== false)
								$itemRegion = explode(',',strtr($slot['value'], array('['=>'',']'=>'',"'"=>'')));
							else
								$itemRegion[] = strtr($slot['value'], array('['=>'',']'=>''));
						}
					}
				}
				echo "<pre>" , $utterance, print_r($itemCommodity),print_r($itemRegion),print_r($sectionST), "</pre>" ;
				// 
				if(!empty($itemCommodity)){	
					$rcmID = DB::table('tbl_region_commodity_master')
						->select(DB::raw("GROUP_CONCAT(distinct ID) as `ids`"))	
						->where('itemType', '=', 'commodity')
						->whereIN('itemName', $itemCommodity)
						->first();
					//print_r($rcmID);
					$param['commodity'] = $rcmID['ids'];
					$param['selectComm'] = implode(',',array_unique($itemCommodity));
					
					$param['searchTerm']='';
				}

				if(!empty($itemRegion)){	
					$rcmID = DB::table('tbl_region_commodity_master')
						->select(DB::raw("GROUP_CONCAT(distinct ID) as `ids`"))	
						->where('itemType', '=', 'region')
						->whereIN('itemName', $itemRegion)
						->first();
					//print_r($rcmID);
					$param['location'] = $rcmID['ids'];
					$param['selectRegion'] = implode(',',array_unique($itemRegion));
					
					$param['searchTerm']='';
				}
				//echo "<pre>" , print_r($itemCommodity),print_r($param), "</pre>" ;
			}
        }*/
		
        $activeSidebar = 'Home';
        $title = 'Home';
        $data = array();
        $homeTabTenderListing = $this->homeTabListing($param,'tenders','listing');
        $homeTabInsightsListing = $this->homeTabListing($param,'insights','listing');
        $homeTabReportsListing = $this->homeTabListing($param,'reports','listing');

		
		
        $homeTabPricesListing = $this->homePriceListing($param,'prices','listing');
		//exit;
        $homeTabEventListing = $this->archivedEventListing($param,'events','listing');
        $filterListing = $this->filterListing();
        $currencyListing = $this->currencyListing();
        $tenderTabArray = '';
        $insightTabArray = '';
        $reportTabArray = '';
        $tenderTabArray = $this->CommodityTenderTab($homeTabTenderListing,'');
        $insightTabArray = $this->CommodityInsightsTab($homeTabInsightsListing,'');
        $data['insightData'] = $homeTabInsightsListing;
        $reportTabArray = $this->CommodityReportTab($homeTabReportsListing,'');
        //echo "<pre>";
        //print_r($reportTabArray);exit();
       $commonFunc = new commonFunction();
		$data['toolbox'] = $commonFunc->getCommodityRegion();
		
       $statsdata = array();
       $graphData = array();
         $responce = $this->preLoginGetParameterListForGraph();
           $responce = json_decode($responce, true);
          if($responce){
             $preLoginStatsInputs = $responce['data']['preLoginStatsInputs'];
            $argsForGraph = array(
              'resourceType' => $preLoginStatsInputs['resourceType'],
              'region' => $preLoginStatsInputs['region'],
              'dataType' => $preLoginStatsInputs['dataType'],
              'commodity' => $preLoginStatsInputs['commodity'],
              'columnNameOfRegion' => $preLoginStatsInputs['columnNameOfRegion'],
              'columnNameOfCommodity' => $preLoginStatsInputs['columnNameOfCommodity'],
              'source' => 'home'
             );

             $graphData = $this->getParentGraph($argsForGraph);
             $graphData = json_decode($graphData, true);
            

             if($graphData['status']['status']==1001){ 
                $statsdata['graphData']=  $graphData['data'];
          }else{
                $statsdata['graphData'] = array();
            } 
      }

        if(!empty($statsdata)){
            $data['graphData'] = $statsdata['graphData'];
            $data['graphData']['preLoginStatsInputs'] = $preLoginStatsInputs;
        }else{
            $data['graphData'] = array();
        }
        return view('hometab.prelogin-searchflow', compact('data', 'title', 'activeSidebar','tenderTabArray','insightTabArray','reportTabArray','homeTabPricesListing','homeTabEventListing','tab','filterListing','currencyListing'));
          }
        catch(\Exception $e) {
            return $e->getMessage();
        }
    }

             /**
     * Display a listing for home tab.
     *
     * @return \Illuminate\Http\Response
     */
    public function homePriceListing($param,$url,$action) {
       try {
		   //echo "<pre>";
		   //print_r($param);exit;
           $memid = steelAuth::getID();
           $apiUrl = config('constants.apiUrl') . $url;
           $tab = $param['tab'];

          $fields = array();

          $fields['resourceType'] = 'web';
          $fields['source'] = 'listing';
           if($memid){
                $fields['memid'] = $memid;
            }
			if(isset($param['currencyFilter']) && ($param['currencyFilter']!='Currency_filter')){
               $fields['currencyName']= $param['currencyFilter'];
            }
			
			
            //if($action=='filter' || $tab==$url){
            if(isset($param['searchTerm']) && $param['searchTerm']!=''){
			    $fields['filters']['searchTerms'] = $param['searchTerm'];
		    }elseif(isset($param['commodity']) && !empty($param['commodity']) && ($param['commodity']!='all')){
                $fields['filters']['commodityID'] = array($param['commodity']);
            }
            if(isset($param['location']) && !empty($param['location']) && ($param['location']!='all')){
                $fields['filters']['regionID'] = array($param['location']);
            }
        //}
           $fields['filters']['tabFilter'] = 'listing';
		   
           $data = array();
           $result = curlHandler::post($apiUrl, $fields);
           $result = json_decode($result, true);
		   //echo $apiUrl;
		   //echo "<pre>";
		  // print_r($fields);exit;
		   /* if( $memid == 56350){
				echo "<pre>", $apiUrl, print_r($fields),print_r($result),"</pre>" ; 
			} */
            if (isset($result['status']['code']) && ($result['status']['code'] == 1001)) {
                if (!empty($result['data'])) {
                $data = $result['data'];
				return $data;
				//echo "<pre>";
		   //print_r($data);exit;
                 //return $this->formatPrice($data);
             }else{
                $result['data'] = array();
                $data = $result['data'];
               
                return $data;
             } 
            } else {
                $result['data'] = array();
                $data = $result['data'];
               
                return $data;
            }
        }
        catch(\Exception $e) {
            return $e->getMessage();
        }

    }

       public function preLoginGetParameterListForGraph(){
        try{
          $url = config('constants.apiUrl').'common/referencedataNew?resourceType=web'; 
          $responce = curlHandler::get($url);
          return $responce;
        }
          catch (\Exception $e) {
            return $e->getMessage();
          }
    }
      /*
      Purpose:- Get Parent Graph by its needed parameter
     */
     public function getParentGraph($attr)
     {
       try{
         $url = config('constants.apiUrl').'statistics/graph';
          $responce = curlHandler::post($url,$attr);
          return $responce;
       }catch(\ Exception $e){
        return $e->getMessage();
       }
     }
    /**
     * Display a listing of the Archived Event.
     *
     * @return \Illuminate\Http\Response
     */
    public function archivedEventListing($param,$url,$action) {
        try {
            $memid = steelAuth::getID();
             $apiUrl = config('constants.apiUrl') . 'site/'.$url;
             $tab = $param['tab'];
             if($memid){
            $fields = array('resourceType' => "web", 'section' => 'event','listType' => 'archived','source' => 'listing','memid' => $memid);
            }else{
                $fields = array('resourceType' => "web", 'section' => 'event','listType' => 'archived', 'source' => 'listing');
            }
            //if($action=='filter' || $tab==$url){
            if(isset($param['commodity']) && ($param['commodity']!='all')){
                $fields['filters']['commodityID'] = $param['commodity'];
            }
            if(isset($param['location']) && ($param['location']!='all')){
                $fields['filters']['regionID'] = $param['location'];
            }
           //}
            $reportData = array();
            $data = array();
            $fields = json_encode($fields);
            $result = curlHandler::get($apiUrl,$fields); //for get
            $result = json_decode($result, true);
            if ($result['status']['code'] == 1001) {
                $data = $result['data'];
                return $data;
            } else {
               $result['data'] = array();
                $data = $result['data'];
                return $data;
            }
        }
        catch(\Exception $e) {
            return $e->getMessage();
        }
    }

                 /**
     * Display a listing for home tab.
     *
     * @return \Illuminate\Http\Response
     */
    public function homeTabListing($data,$url,$action) {
       try {
        
         $tab = $data['tab'];
        $fields = array();

        $fields['resourceType'] = 'web';
        //$fields['source'] = 'listing';
           $memid = steelAuth::getID();
           if($memid){
                $fields['memid'] = $memid;
            }
            //if($tab==$url || $action=='filter'){
           if(isset($data['searchTerm']) && $data['searchTerm']!=''){
				$fields['filters']['searchTerms'] = $data['searchTerm'];
		   }elseif(isset($data['commodity']) && !empty($data['commodity']) && ($data['commodity']!='all')){
                $fields['filters']['commodityID'] = array($data['commodity']);
            }
            if(isset($data['location']) && !empty($data['location']) && ($data['location']!='all')){
                $fields['filters']['regionID'] = array($data['location']);
            }
          //}
			if( "insights" ==  $url){
				$fields['source'] = 'listing';
				/*$fields['source'] = 'regionwise';
				if( isset($fields['filters']['regionID']) && count($fields['filters']['regionID']) > 0  ){
					if( isset($fields['filters']['commodityID'])  ){
						$fields['source'] = 'listing';
					} else {
						$fields['source'] = 'regionwise';
					}
				} else {
					if( isset($fields['filters']['commodityID']) && count($fields['filters']['commodityID']) > 0  ){
						$fields['source'] = 'commoditywise';
					} else {
						$fields['source'] = 'listing';
					} 
				}*/
			} else {
				$fields['source'] = 'listing';
			}
         
			/*  if( $memid == 116707 && "insights" ==  $url){
				echo "<pre>" . config('constants.apiUrl') . $url;
				print_r($fields); //die();
			}  */
           $apiUrl = config('constants.apiUrl') . $url;
           $data = array();
           $result = curlHandler::post($apiUrl, $fields);
           $result = json_decode($result, true);
			/* if( $memid == 56350){
				echo "<pre>" .config('constants.apiUrl') . $url;; print_r($fields); print_r($data); 
				print_r($result); 
				echo "2</pre>" ; 
			} */
		   //echo $apiUrl;
		    //echo "<pre>";
		  //print_r($fields);
            if (isset($result['status']['code']) && ($result['status']['code'] == 1001)) {
                $data = $result['data'];
                return $data;
            } else {
                $result['data'] = array();
                $data = $result['data'];
               
                return $data;
            }
        }
        catch(\Exception $e) {
            return $e->getMessage();
        }

    }
	
	        //CommodityTenderTab
   public function formatPrice($attr){
       try {
          //echo "<pre>";
          //print_r($attr);die();
           if(is_array($attr) && count($attr) > 0){
               $filter = array(); 
              foreach ($attr as $key => $value) {
                   //$filter[$value['commodityID'].'|'.$value['regionID']][$value['regionID']][] = $value;
               if($value['sectionHeading']!='' && $value['subSectionHeading']!=''){
                   $filter[$value['sectionHeading'].' | '.$value['subSectionHeading']][$value['subSectionHeading']][] = $value;
                }
              }
              return $filter;
           }
   
       } catch (\Exception $e) {
           return $e->getMessage();
       }
   }

    public function CommodityTenderTab($tenderTabResult,$type){
        /*echo "<pre>";
        print_r($tenderTabResult);exit();*/

        $tenderTabArray = array();
        if(!empty($tenderTabResult)){
            foreach ($tenderTabResult as $key => $value) {
                if($type=='commodity'){
                    $tenderTabArray['commodityWise'][$value['subCommodityName'].'-'.$value['subCommodityID']][$key]= $value;
                }else{
                    $tenderTabArray['commodityWise'][$value['commodityName'].'-'.$value['commodityID']][$key]= $value;
                }
            }
        }

        return $tenderTabArray;
    }

    public function CommodityInsightsTab($insightTabResult,$type){
       /* echo '<pre>';
        print_r($insightTabResult);
        exit;*/
		/* if( steelAuth::getID() == 116707 ){
			echo "inside CommodityInsightsTab";
			print_r($insightTabResult); die();
		} */
        $insightTabArray = array();
        if(!empty($insightTabResult)){
            foreach ($insightTabResult as $key => $value) { 
                $insightTabArray['commodityWise'][$value['commodityName'].'-'.$value['commodityID']] [$key]= $value;
                
            }
        }

        
        return $insightTabArray;
        
    }

    public function CommodityReportTab($reportTabResult,$type){
        $reportTabArray = array();
        if(!empty($reportTabResult)){
            foreach ($reportTabResult as $key => $value) {
                $reportTabArray['commodityWise'][$value['commodityName'].'-'.$value['commodityID']][$key]= $value;
            }
            
        }
		/* echo '<pre>';
        print_r($insightTabResult);
        exit;*/
        return $reportTabArray;
    }

     /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function homeFilterdata(Request $request)
    {
     try {
         //echo "<pre>";
         //print_r($request->all());exit();
        $param = $request->all();
		$currencyListing = $this->currencyListing();
        $tab = $param['tab'];
        $activeSidebar = 'Home';
        $title = 'Home';
        if($tab=='prices'){
            $url = 'prices';
        }else if($tab=='insights'){
            $url = 'insights';
        }else if($tab=='tenders'){
            $url = 'tenders';
        }else if($tab=='reports'){
            $url = 'reports';
        }else if($tab=='events'){
            $url = 'events';
        }else{
            $url = 'statistics';
        }
		
       $data = array();
        if($url=='prices'){
            $homeTabPricesListing = $this->homePriceListing($param,$url,'filter');
            /*echo "<pre>";
            print_r($homeTabPricesListing);exit();*/
            if(!empty($homeTabPricesListing)){
                $data['priceStatus'] = 1;
            }else{
                $data['priceStatus'] = 0;
            }
            $data['tab'] = $tab;
            $data['priceData'] = view('hometab.price-tab', compact('homeTabPricesListing','currencyListing'))->render();
        }else if( $url == 'insights'){
            $homeTabInsightsListing = $this->homeTabListing($param,$url,'filter');
            $insightTabArray = $this->CommodityInsightsTab($homeTabInsightsListing,'');
            if(!empty($insightTabArray)){
                $data['insightStatus'] = 1;
            }else{
                $data['insightStatus'] = 0;
            }
            $data['tab'] = $tab;
            $data['insightData'] = view('hometab.insight-tab', compact('insightTabArray'))->render();
        }else if( $url == 'tenders'){
            $homeTabTenderListing = $this->homeTabListing($param,$url,'filter');
            $tenderTabArray = $this->CommodityTenderTab($homeTabTenderListing,'');
            if(!empty($tenderTabArray)){
                $data['tenderStatus'] = 1;
            }else{
                $data['tenderStatus'] = 0;
            }
            $data['tab'] = $tab;
            $data['tenderData'] = view('hometab.tender-tab', compact('tenderTabArray'))->render();
            //echo "<pre>";
            //print_r($data['tenderData']);die();
        }else if( $url == 'reports'){
            $homeTabReportsListing = $this->homeTabListing($param,$url,'filter');
            $reportTabArray = $this->CommodityReportTab($homeTabReportsListing,'');
            if(!empty($reportTabArray)){
                $data['reportStatus'] = 1;
            }else{
                $data['reportStatus'] = 0;
            }
            $data['tab'] = $tab;
            $data['reportData'] = view('hometab.report-tab', compact('reportTabArray'))->render();
        }else if( $url == 'events'){
            $homeTabEventListing = $this->archivedEventListing($param,$url,'filter');
            //echo "<pre>";
            //print_r($homeTabEventListing);exit();
            if(!empty($homeTabEventListing)){
                $data['eventStatus'] = 1;
            }else{
                $data['eventStatus'] = 0;
            }
            $data['tab'] = $tab;
            $data['eventData'] = view('hometab.events-tab', compact('homeTabEventListing'))->render();
        }else if( $url == 'statistics'){
            
                $data['statisticsStatus'] = 1;
           
            $data['tab'] = $tab;
           
        }
        //echo "<pre>";
        //print_r($homeTabInsightsListing);exit();
        echo json_encode($data);

          }
        catch(\Exception $e) {
            return $e->getMessage();
        }
    }

           /**
     * Display filter listing.
     *
     * @return \Illuminate\Http\Response
     */
      public function filterListing() {
        try {
            $apiUrl = config('constants.apiUrl') . 'common/referencedataNew?resourceType=web';
            $eventData = array();
            $data = array();
            $result = curlHandler::get($apiUrl); //for get
            $result = json_decode($result, true);
            if ($result['status']['code'] == 1001) {
                if (!empty($result['data'])) {
                    $eventData = $result['data'];
                    $data = $eventData['WEB_INDEX'];
                    return $data;
                } else {
                    $data = '';
                    return $data;
                }
            }
        }
        catch(\Exception $e) {
            return $e->getMessage();
        }
    }
	
	   
      public function currencyListing() {
        try {
            $apiUrl = config('constants.apiUrl') . 'common/referencedataNew?resourceType=web';
            $eventData = array();
            $data = array();
            $result = curlHandler::get($apiUrl); //for get
            $result = json_decode($result, true);
            if ($result['status']['code'] == 1001) {
                if (!empty($result['data'])) {
                    $eventData = $result['data'];
                    $data = $eventData['currencyConvertor']['prices'];
                    return $data;
                } else {
                    $data = '';
                    return $data;
                }
            }
        }
        catch(\Exception $e) {
            return $e->getMessage();
        }
    }
	
	public function currencyFilter1(Request $request){
	try {
		$param = $request->all();
		//echo "<pre>";
		//print_r($param);exit;
            $memid = steelAuth::getID();
           $priceApiUrl = config('constants.apiUrl').'prices';
          

          $fields = array();

          $fields['resourceType'] = 'web';
          $fields['source'] = 'listing';
		
		  	if(isset($param['cname']) && ($param['cname']!='Currency_filter')){
               $fields['currencyName']= $param['cname'];
            }
			
		  
           if($memid){
                $fields['memid'] = $memid;
            }
            
            if(isset($param['commodity']) && ($param['commodity']!='all')){
                $fields['filters']['commodityID'] = array($param['commodity']);
            }
            if(isset($param['location']) && ($param['location']!='all')){
                $fields['filters']['regionID'] = array($param['location']);
            }
        
           $fields['filters']['tabFilter'] = 'listing';
           $data = array();
           $result = curlHandler::post($priceApiUrl, $fields);
           $result = json_decode($result, true);
			//echo "<pre>";
			//print_r($fields);die;
			
            $homeTabPricesListing = array();
            $responce = array();
            $commoditiesApiUrl = config('constants.apiUrl').'common/referencedataNew?resourceType=web';
			$commodities = curlHandler::get($commoditiesApiUrl);
			$commodities = json_decode($commodities, true);
			$currurency = array();
			$currurency = $commodities['data']['currencyConvertor']['prices']; 

            if($result['status']['code']==1001){
                //$priceTabArray= $this->formatPriceTab($priceTabResult['data']);
				 $homeTabPricesListing = $this->formatPrice($result['data']);
                //echo "<pre>";
		  // print_r($homeTabPricesListing);die;
               $responce['status']['code'] = 1001;
            	$responce['status']['message'] = 'success';
            	$responce['html'] = view('hometab.priceAjax-tab',['homeTabPricesListing'=> $homeTabPricesListing,'currencyListing' => $currurency])->render();
            }else{
            	$responce['status']['code'] = 2001;
            	$responce['status']['message'] = 'No Record Found!';
            }

             echo json_encode($responce);
             exit();
	} catch (\Exception $e) {
		return $e->getMessage();
	}
		
}


   //loadMoreCommodityRegionData
    public function loadmoreHomeTab(Request $request)
    {
		 //echo "dddddddddd";die;
        try{
            $data = array();
			 $fields = array();
            $params = $request->all();
			//echo "<pre>";
			//print_r($params);exit;
			
            $memid = steelAuth::getID();
            if($params['type']=='reports'){
                $apiUrl = config('constants.apiUrl').'reports'; 
            }else if($params['type']=='tenders'){
                $apiUrl = config('constants.apiUrl').'tenders'; 
            }else if($params['type']=='insights'){
                $apiUrl = config('constants.apiUrl').'insights'; 
            } else if($params['type']=='events'){
                $apiUrl = config('constants.apiUrl') . 'site/events';
               $fields = array('section' => 'event','listType' => 'archived');
            }else{
                $apiUrl = config('constants.apiUrl').'insights'; 
            }
           
            $fields['pageValue']= $params['pageValue'];
            $fields['memid']= $memid;
            $fields['resourceType']= 'web';
			$fields['source'] = 'listing';
			
			if($params['type']=='events'){
				if(isset($params['commodityId']) && ($params['commodityId']!='all')){
                $fields['filters']['commodityID'] = array($params['commodityId']);
            }
				
			}else{
				if(isset($params['itemID'])){
					$fields['filters']['commodityID'] = array($params['itemID']);
				 $data['itemID'] = $params['itemID'];
				}
			}
			
			if(isset($params['commodityId']) && !empty($params['commodityId'])  && ($params['commodityId']!='all')){
                $fields['filters']['commodityID'] = array($params['commodityId']);
            }
            
            if(isset($params['regionId']) && !empty($params['regionId']) && ($params['regionId']!='all')){ 
                $fields['filters']['regionID'] = array($params['regionId']);
            }
			
			if(isset($params['searchTerm']) && $params['searchTerm']!=''){
			    $fields['filters']['searchTerms'] = $params['searchTerm'];
				 $fields['filters']['commodityID'] = array();
				 $fields['filters']['regionID'] = array();
		    }
			
			//echo "<pre>";
			//print_r($fields);exit;
			if($params['type']=='events'){
			 $fields = json_encode($fields);
            $result = curlHandler::get($apiUrl,$fields);
			}else{
            $result = curlHandler::post($apiUrl,$fields);
			}
			
			
            $result = json_decode($result, true);
			/* if(steelAuth::getID() == 56350){		   
				echo "<pre>" . $apiUrl;
						print_r($fields);
						print_r($result);
						echo "</pre>"; 
			} */
            $data['pageValue'] = $params['pageValue']+1;
            $data['type'] = $params['type'];
           
            //$data['commodityOrRegion'] = $params['commodityOrRegion'];
            $type = $params['type'];
            if($result['status']['code']==1001){
                if(count($result['data'])>0){
                    $data['status']   = 1;
                }else{
                    $data['status']   = 2;
                }
                if($params['type']=='reports'){
                    $data['reportData'] = $result['data'];
                    $data['loadMoreReports'] = view('hometab.load-more-reports', compact('data','type'))->render();
                }else if($params['type']=='tenders'){
                    $data['tenderData'] = $result['data'];
                    //$data['loadMoreTenders'] = view('tender.tenders-commonlisting', compact('data','type'))->render();  
                    $data['loadMoreTenders'] = view('hometab.load-more-tenders', compact('data','type'))->render();  
                }else if($params['type']=='events'){
                    $data['eventData'] = $result['data'];
                    $data['loadMoreEvenrt'] = view('hometab.load-more-events-tab', compact('data','type'))->render();  
                }else{
                    $data['insightData'] = $result['data'];
                    //$data['loadMoreInsights'] = view('hometab.load-more-insights', compact('data','type'))->render();
                    $data['loadMoreInsights'] = view('insights.load-more-insights', compact('data','type'))->render();
                }
            }else{
                $data['status']   = 0;
            }
            echo json_encode($data);
        }catch(\Exception $e){
            return $e->getmessage();
        }

    }



}


