		<?php  

		require_once("../lib/db_functions.php");
        // require_once("../pdf_genrator/dompdf/autoload.inc.php");
        // namespace Dompdf;
           require_once 'dompdf/autoload.inc.php';
          use Dompdf\Dompdf;
           $dompdf = new Dompdf();
        // require_once 'adminpanel/dompdf/autoload.inc.php';

		$response = array();  
	      $type=$_POST['type'];
	     $company_name=$obj->data_filter($_POST['new_company']);
        $step = $obj->data_filter($_POST['step1']);
         $prev = $obj->data_filter($_POST['prev']);
      
        $company_edit_id = $obj->data_filter($_POST['company_edit_id']);
        
		$type_company     = $obj->data_filter($_POST['company-select']);
		$other            = $obj->data_filter($_POST['other']); 
		$financ_year      = $obj->data_filter($_POST['financ_year']);
		$cut_off             = $obj->data_filter(date("Y-m-d",strtotime($_POST['datepicker'])));
		
		$lending          = $obj->data_filter($_POST['lending']);
		$prevailing       = $obj->data_filter($_POST['prevailing']);
		$borrow_date         = $obj->data_filter(date("Y-m-d",strtotime($_POST['cut'])));
        
		$banks            = $obj->data_filter($_POST['banks']); 
		$nbfc             = $obj->data_filter($_POST['nbfc']);
		$foreign          = $obj->data_filter($_POST['foreign']);
		$indian_comp      = $obj->data_filter($_POST['indian_comp']);
		$llp              = $obj->data_filter($_POST['llp']); 
		$financ_inst      = $obj->data_filter($_POST['financ_inst']);
		$total            = $obj->data_filter($_POST['total']);
  
		$equity           = $obj->data_filter($_POST['equity']);
		$capital          = $obj->data_filter($_POST['capital']);
		$total_cap        = $obj->data_filter($_POST['total_cap']); 
		$twice_cap        = $obj->data_filter($_POST['twice_cap']);
		$repayment        = $obj->data_filter($_POST['repayment']);
		$shareholders     = $obj->data_filter($_POST['share-holding']);
		$specify_sharehold= $obj->data_filter($_POST['specify']);

		$hold_comp          = $obj->data_filter($_POST['hold_comp']);
		$subs_comp          = $obj->data_filter($_POST['subs_comp']);
		$wholl_own          = $obj->data_filter($_POST['wholl_own']);
		$form_dir           = $obj->data_filter($_POST['form_dir']);
		$whole_time         = $obj->data_filter($_POST['whole_time']); 
		$direc_comp         = $obj->data_filter($_POST['direc_comp']);  
		$relat_direct       = $obj->data_filter($_POST['relat_direct']); 
		$part_dirc          = $obj->data_filter($_POST['part_dirc']); 
		$dirc_part          = $obj->data_filter($_POST['dirc_part']);
		$rel_dirc           = $obj->data_filter($_POST['rel_dirc']); 
		$priv_comp          = $obj->data_filter($_POST['priv_comp']);  
		$direc_mem          = $obj->data_filter($_POST['direc_mem']);
		$direc_hold_comp    = $obj->data_filter($_POST['direc_hold_comp']);
		$llp_comp           = $obj->data_filter($_POST['llp_comp']); 
		$llp_comp_lead      = $obj->data_filter($_POST['llp_comp_lead']);
		
		$given_loan         = $obj->data_filter($_POST['given_loan']);
	
        $given_relation     = $obj->data_filter($_POST['given_relation']);
		$loan               = $obj->data_filter($_POST['loan']); 
		$loan_relation      = $obj->data_filter($_POST['loan_relation']); 
		$guarantee_loan     = $obj->data_filter($_POST['guarantee_loan']); 
		$guarantee_relation = $obj->data_filter($_POST['guarantee_relation']); 
		$security_loan      = $obj->data_filter($_POST['security_loan']);
		$security_relation  = $obj->data_filter($_POST['security_relation']);
	    
	 if($type =='section')
	 {
	if($company_edit_id != "")
	{
	   setcookie($cookie_name, $cookie_value, time() - (60 * 60), "/");
	   
	    $_SESSION["company_edit_id"] = $company_edit_id;
	   
	  if($step==1)
	  {
	     $status='0';
	     $section_arr = $obj_dba_func->set_185('',$company_edit_id,$type_company,$lending,$prevailing,$financ_year,$cut_off,$other,$status);
	  
        if($section_arr['n'] == 1)
		{
			$response['n']   = 2;
			$response['msg'] = "step1 success"; 
	   }
	   else
	   {
	     
			$response['n']   = 0;
			$response['msg'] = "step1 error";   
	   }
	  }
	  else if($step==2)
	  {
	      $status='0';
	    $update_adm = $obj_dba_func->set_borrowing('',$company_edit_id,$banks,$nbfc,$financ_inst,$indian_comp,$llp,$foreign,$total,$equity,$capital,$total_cap,$twice_cap,$repayment,$shareholders,$specify_sharehold,$status);
         
	 	   if($update_adm['n'] == 1)
		{    
	
           $response['n']   = 2;
			$response['msg'] = "step2 success"; 
		}
		else
		{
           $response['n']   = 0;
		   $response['msg'] = "step2 error";  
		}
	  }
	  else if($step==3)
	  {
	     
	       $delete = $obj_dba_func->delete_record('',$company_edit_id);
	      
	       if($delete['n'] == 1)
	       {
	           
	        if(isset($hold_comp) && !empty($hold_comp))
			{  	
			    
				$hold_comp_array=explode(',',$hold_comp);
		
				$i=0;
				foreach($hold_comp_array as $hold)
				{
		          
				      $sub_company_type_id=1;
			          $share = $obj_dba_func->set_sharing('',$company_edit_id,$sub_company_type_id,$hold,'holding company','3'); 
                
					$i++;
				}
			
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] = $share['msg'];
					$response['data'] = $share['data'];  
					$response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}
			}
			if(isset($subs_comp) && !empty($subs_comp))
			{
			     $sub_company_type_id=2;
			    $subs_comp_array=explode(',',$subs_comp);
				// $company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'2',$wholl_own);
             
				$i=0;
				foreach($subs_comp_array as $subs)
				{
				// 	// echo $hold.'<br>';
					$share= $obj_dba_func->set_sharing('',$company_edit_id,$sub_company_type_id,$subs,'Subsidiary Companies','3'); 

					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
                    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}
             
			}
			if(isset($wholl_own) && !empty($wholl_own))
			{	
	            $sub_company_type_id=3;
				$wholl_own_array=explode(',',$wholl_own);
				// $company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'3',$whole_time ); 
				$i=0;
				foreach($wholl_own_array as $wholl)
				{
				// 	// echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,$sub_company_type_id,$wholl,'Wholly Owned Subidiary Companies','3'); 

					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
			       $response['fourth'] = $share['fourth'];  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($form_dir)  && !empty($form_dir))
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$form_dir_array=explode(',',$form_dir);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'4',$relat_direct); 
				$i=0;
				foreach($form_dir_array as $form)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'4',$form,'Managing Director','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($whole_time) && !empty($whole_time))
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$whole_time_array=explode(',',$whole_time);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'5',$dirc_part); 
				$i=0;
				foreach($whole_time_array as $whole)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'5', $whole,'Whole time directors','3'); 
					$i++;
				}  
           
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_comp) && !empty($direc_comp) )
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$direc_comp_array=explode(',',$direc_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'6',$priv_comp); 
				$i=0;
				foreach($direc_comp_array as $direc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'6', $direc,'Director of an Company','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($relat_direct) && !empty($relat_direct))
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$relat_direct_array=explode(',',$relat_direct);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'7',$subs_comp); 
				$i=0;
				foreach($relat_direct_array as $relat)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'7', $relat,'Relative of directors','3'); 
					$i++;
				}  
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($part_dirc) && !empty($part_dirc))
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$part_dirc_array=explode(',',$part_dirc);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'8',$form_dir ); 
				$i=0;
				foreach($part_dirc_array as $part)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'8', $part,'Partner of directors in any firm (incl. LLP)','3'); 
					$i++;
				}
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
			        $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($dirc_part) && !empty($dirc_part))
			{			
				// $company_detail_id=$_COOKIE["company_detail_id"];
				$dirc_part_array=explode(',',$dirc_part);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'9',$direc_comp); 
				$i=0;
				foreach($dirc_part_array as $dirc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'9', $dirc,'Firm (incl. LLP) in which director is a partner','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($rel_dirc ) && !empty($rel_dirc ))
			{			
			//	$company_detail_id=$_COOKIE["company_detail_id"];
				$rel_dirc_array=explode(',',$rel_dirc );
			//$share = $obj_dba_func->set_sharing($company_detail_id,'10',$part_dirc); 
				$i=0;
				foreach($rel_dirc_array as $rel)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'10',$rel,'Firm (incl. LLP) in which relative of director is a partner','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($priv_comp) && !empty(	$priv_comp))
			{			
			//	$company_detail_id=$_COOKIE["company_detail_id"];
				$priv_comp_array=explode(',',$priv_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'11',$direc_hold_comp); 

				$i=0;
				foreach($priv_comp_array as $priv)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'11',$priv,'Private Companies in which director is a director','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			       $response['data'] = $share['data'];
			       $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_mem ) && !empty($direc_mem) )
			{			
				//$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_mem_array=explode(',',$direc_mem);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'12',$direc_mem ); 

				$i=0;
				foreach($direc_mem_array as $direc_m)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'12',$direc_m,'Private Companies in which director is a Member','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_hold_comp) && !empty($direc_hold_comp))
			{			
				//$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_hold_comp_array=explode(',',$direc_hold_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'13',$rel_dirc); 
				$i=0;
				foreach($direc_hold_comp_array as $direc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'13',$direc,'Director of holding company','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp) && !empty($llp_comp))
			{			
				//$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_array=explode(',',$llp_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'14',$llp_comp); 
				$i=0;
				foreach($llp_comp_array as $llp)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'14',$llp,'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp_lead) && !empty($llp_comp_lead))
			{		

			//	$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_lead_array=explode(',',$llp_comp_lead);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'15',$llp_comp_lead); 
				$i=0;
				foreach( $llp_comp_lead_array as $llp_com)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing('',$company_edit_id,'15',$llp_com,'any directors of lending company','3'); 
					$i++;
				} 
			
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
                    $response['fourth'] = $share['fourth']; 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			} 
			
	       }
	       else
	       {
	          $response['n']   = 0;
			$response['msg'] = "delete error";   
	       }
          
	      
	  }
	  else if($step==4)
	  {
	      
	      
	       $delete = $obj_dba_func->delete_record1($company_edit_id);
	     
	       if($delete['n'] == 1)
	       {
	        if(isset($given_loan) && !empty($given_loan))
			{		
               
				//$company_detail_id=$_COOKIE["company_detail_id"];
				$given_loan_array=explode(',',$given_loan);
				//print_r($given_loan_array);
			    $given_relation_array=explode(',',$given_relation);
			    
				$i=0;
				foreach( $given_loan_array as $key => $given_loan)
				{
					$give_loan_index = $key;

					foreach($given_relation_array as $index => $given_relation)
					{
                     $given_relation_index = $index;
                     if($give_loan_index == $given_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction('',$company_edit_id,'16',$given_loan,$given_relation,'4'); 
                       
                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   =2;
					$response['msg'] =  $trans['msg'];
                    $response['success'] =3;
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
				if(isset($loan) && !empty($loan))
			{		

				//$company_detail_id=$_COOKIE["company_detail_id"];
				$loan_array=explode(',',$loan);
				//print_r($given_loan_array);
			     $loan_relation_array=explode(',',$loan_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach( $loan_array as $key => $loan)
				{
					$loan_index = $key;

					foreach( $loan_relation_array as $index => $loan_relation)
					{
                    $loan_relation_index = $index;
                     if($loan_index == $loan_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction('',$company_edit_id,'17',$loan,$loan_relation,'4'); 
                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];
                    $response['success'] =3;
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
             	if(isset($guarantee_loan) && !empty($guarantee_loan ))
			{		

				//$company_detail_id=$_COOKIE["company_detail_id"];
				$guarantee_loan_array=explode(',',$guarantee_loan);
				//print_r($given_loan_array);
			    $guarantee_relation_array=explode(',',$guarantee_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach($guarantee_loan_array as $key => $guarantee_loan)
				{
					 $guarantee_loan_index = $key;

					foreach($guarantee_relation_array as $index => $guarantee_relation)
					{
                     $guarantee_relation_index = $index;
                     if($guarantee_loan_index == $guarantee_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction('',$company_edit_id,'18',$guarantee_loan,$guarantee_relation,'4'); 
                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];
                    $response['success'] =3;
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
             	if(isset($security_loan ) && !empty($security_loan ))
			{		

				//$company_detail_id=$_COOKIE["company_detail_id"];
				$security_loan_array=explode(',',$security_loan );
				//print_r($given_loan_array);
			    $security_relation_array=explode(',',$security_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach($security_loan_array as $key => $security_loan)
				{
					$security_loan_index = $key;

					foreach($security_relation_array as $index => $security_relation)
					{
                    $security_relation_index = $index;
                     if($security_loan_index == $security_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction('',$company_edit_id,'19',$security_loan,$security_relation,'4'); 
                        
                     	
                     }
					$i++;
				   }

				   
			   }

				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}
               
			}
			else
			{ 
			    
			   	$trans = $obj_dba_func->set_transaction('',$company_edit_id,'','','','4'); 
			    
			    if( $trans['n']== 1)
				{ 
				    
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
			}
	       }
	     
	  }
	 
			 if($trans["success"]==3)
              {
                  
                                        $company_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_edit_id AND (sub_company_type_id=6 OR sub_company_type_id=7 OR sub_company_type_id=8 OR sub_company_type_id=10 OR sub_company_type_id=13)");
                              // echo "<pre>";print_r($company_arr);echo "</pre>";
                             // print_r($company_arr);
                          $loan_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'ELSE 'Security Provided to' END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_edit_id AND sub_company_type_id=2");

                            $wholly_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'ELSE 'Security Provided to' END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_edit_id AND sub_company_type_id=3");

    $parties_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name , CASE  WHEN sub_company_type_id = 4 THEN '1. It should be a part of the conditions of service extended by the company to all its employees; or
2. It should be pursuant to any scheme approved by the members by a special resolution;
' WHEN sub_company_type_id = 5 THEN '1. It should be a part of the conditions of service extended by the company to all its employees; or
2. It should be pursuant to any scheme approved by the members by a special resolution;
'WHEN sub_company_type_id = 11 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 12 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 14 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 15 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'

END as conditi","gbca_sub_company_mapping","company_detail_id=$company_edit_id AND (sub_company_type_id=4 OR sub_company_type_id=5 OR sub_company_type_id=11 OR sub_company_type_id=12 OR sub_company_type_id=14 OR sub_company_type_id=15)");

                             
    $given_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_edit_id AND (sub_company_type_id=16 OR sub_company_type_id=17 OR sub_company_type_id=18 OR sub_company_type_id=19 )");
                  
               
            
               $detail=$obj->select( "*","gbca_company_detail_master as gbca RIGHT JOIN gbca_company_master as mas ON gbca.company_detail_name=mas.company_id RIGHT JOIN gbca_section_master as sec ON gbca.section_id=sec.section_id ","company_detail_id= $company_edit_id ");
           
              $section=$detail[0]["section_name"];
              $company=trim($detail[0]["company_name"]);
              $preparation=date("d F Y");
              $maker=$detail[0]["company_detail_maker_name"];
              $checker=$detail[0]["company_detail_checker_name"];
              $today_date=date('d M Y');
              $date=$detail[0]["company_detail_preparation_date"];
           
              $time=time();
                // $res='';
                     $res .='<!DOCTYPE html><html><head> <style>table{width: 100%;}th, td{padding: 10px;}th{background: rgb(37,71 ,150); color: #fff;}table, th, td{border: 1px solid black; border-collapse: collapse; text-align: left;}</style></head><body> <table style="border:none"> <tr style="border:none"> <td style="border:none; text-align: center;"><img src="https://gbcacompliance.oneroof.tech/new/assets/img/logo.png" style="height: 70px;" alt="logo"></td></tr><tr style="border:none"> <td style="border:none"> <h3 style="color:#483D8B; text-align: center;"><u>Report Card for Eligibility Test of Section 185 of the Companies Act, 2013</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company.'</td><td style="border:none"><b>Preparation Date: </b>'.$date.'</td></tr><tr style="border:none"> <td style="border:none"><b>Made By: </b>'. $maker.'</td><td style="border:none"><b>Checked By: </b>'. $checker.'</td></tr></table><br/>';
               
               
                 $res .=' <p>A. List of Parties to whom the company cannot advance any Loan or Provide any Security and Give any guarantee in respect of loan taken by such party</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 42%;">Parties</th> <th style="width: 42%;">Nature of relation</th> </tr>';
                 
                  if(is_array($company_arr))
                  {
                      $i = 1;
                  foreach($company_arr as $company1)
                  {
                 
                 $res .='<tr><td>'.$i.'</td><td>'.$company1["sub_company_type_name"].'</td><td>'.$company1["sub_company_name"].'</td></tr>';
                 
                   $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No record found.</td></tr>';  
                  }
                 
                 $res .='</table><br/><p>B. List of Parties to whom the company cannot advance any Loan but can Provide any Security or Give any guarantee in respect of loan taken by such party</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 42%;">Parties</th> <th style="width: 42%;">Nature of relation</th> </tr>';
                 
                  if(is_array($loan_arr))
                  {
                      $i = 1;
                  foreach($loan_arr as $loan)
                  {
                 
                     $res .='<tr><td>'.$i.'</td><td>'.$loan["sub_company_type_name"].'</td><td>'.$loan["sub_company_name"].'</td></tr>';
                     
                      $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No record found.</td></tr>';   
                  }
                     
                    $res .='</table><br/> <p>C. List of Parties to whom the company can advance Loan or Provide any Security or Give any guarantee in respect of loan taken by such party without any conditions</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Remark</th> </tr>';
                    
                     if(is_array($wholly_arr))
                  {
                      $i = 1;
                  foreach($wholly_arr as $wholly)
                  {
                  
                    
                        $res .='<tr><td>'.$i.'</td><td>'.$wholly["sub_company_type_name"].'</td><td>'.$wholly["sub_company_name"].'</td><td></td></tr>';
                  }
                  }else
                  {
                     $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
    
                  $res .='</table><br/> <p>D. List of Parties to whom the company can advance Loan or Provide any Security or Give any guarantee in respect of loan taken by such party provided certain conditions are met. <br>(If such conditions are not met, the transaction shall be treated as non-compliant)</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Condition</th> </tr>';
                  
                  if(is_array($parties_arr))
                  {
                      $i = 1;
                  foreach($parties_arr as $parties)
                  {
                   $res .='<tr><td>'.$i.'</td><td>'.$parties["sub_company_type_name"].'</td><td>'.$parties["sub_company_name"].'</td><td>'. $parties['conditi'].'</td></tr>';
                      
                    $i++;
                  }
                  }
                  else
                  {
                      
                        $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
                  
                      $res .='</table><br/> <p>E. List of Parties with whom the company has already undertaken specified transactions which require due attention of the management as the same may either be not in compliance with the provisions or may require to fulfill one or the other condition to comply with the provisions of Sec 185 of the Companies Act, 2013 <br>(unless the borrower is Wholly Owned Subsidiary).</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Transaction Type</th> </tr>';
                  
                  if(is_array($given_arr))
                  {
                   $i = 1;
                  foreach($company_arr as $company1)
                  {
                 
                 $res .='<tr><td>'.$i.'</td><td>'.$company1["sub_company_type_name"].'</td><td>'.$company1["sub_company_name"].'</td></tr>';
                 
                   $i++;
                  }   
                      
                      $i = 1;
                  foreach($given_arr as $given)
                  {
                   $res .='<tr><td>'.$i.'</td><td>'.$given["sub_company_type_name"].'</td><td>'.$given["sub_company_transaction_relation"].'</td><td>'.$given["sub_company_name"].'</td></tr>';
               
                    $i++;
                  }
                  }
                  else
                  {
                      
                        $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
                  
                  $res .='</table></body></html><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
                 $company= str_replace(" ","_",$company);
				$filename =$company.'_'.$time.'.pdf';
				$dompdf->set_paper($paper,$orientation);
				$dompdf->load_html($res);
				$dompdf->render();
				$output = $dompdf->output();
				$file_to_save = '../pdffiles/'.$filename;
				file_put_contents($file_to_save, $output);
				$file = $file_to_save;
				$file_size = filesize($file);
				$handle = fopen($file, "r");
				$content = fread($handle, $file_size);
				fclose($handle);
                
               	$destination_url = '../pdffiles/';
                	
                $documents = $obj_dba_func->store_pdf('',$company_edit_id,$filename); 

                	$response['n']   = 1;
					$response['msg'] = "applicable";
                

              }


	
  }
  
	else
	{
	 
	  	if(isset($_COOKIE["company_detail_id"]))
	{
	   if($step==1)
	   {
	       unset($_SESSION["company_edit_id"]);
	     $company_detail_id=$_COOKIE["company_detail_id"];
            $status='0';
		$section_arr = $obj_dba_func->set_185($company_detail_id,'',$type_company,$lending,$prevailing,$financ_year,$cut_off,$other,$status);
     	
     
        if($section_arr['n'] == 1)
		{
			$response['n']   = 2;
			$response['msg'] = $section_arr['msg'];
			$response['data'] = $section_arr['date'];
		}
		else
		{
		 	$response['n']   = 0;
			$response['msg'] = $section_arr['msg'];   
		}
	   }
	   else if($step==2)
	   {
	         $company_detail_id=$_COOKIE["company_detail_id"];
	         
	          $status='0';
	      $update_adm = $obj_dba_func->set_borrowing($company_detail_id,'',$banks,$nbfc,$financ_inst,$indian_comp,$llp,$foreign,$total,$equity,$capital,$total_cap,$twice_cap,$repayment,$shareholders,$specify_sharehold,$status);
           
      
         
	 	   if($update_adm['n'] == 1)
		  {
		     
           $response['n']   = 2;
			$response['msg'] =  $update_adm['msg'];
             
		  }
		  else
		  {
		    $response['n']   = 0;
			$response['msg'] =  $update_adm['msg']; 
		  }
	   }
	   else if($step==3)
	   {
	      // $delete = $obj_dba_func->delete_record($company_detail_id);
	       $company_detail_id=$_COOKIE["company_detail_id"];
	       
	       $previous_records=$obj->select( "*","gbca_sub_company_mapping","company_detail_id=$company_detail_id");
          
          if(is_array($previous_records))
          {
              
             $delete = $obj_dba_func->delete_record($company_detail_id,'');
             
             if($delete['n'] == 1)
             {
                 
              if(isset($hold_comp) && !empty($hold_comp))
			  {  	
			   
				$hold_comp_array=explode(',',$hold_comp);
				
				$company_detail_id=$_COOKIE["company_detail_id"];

				//$share = $obj_dba_func->set_sharing($company_detail_id,'1',$hold_comp); 
				$i=0;
				foreach($hold_comp_array as $hold)
				{
			      
					$share = $obj_dba_func->set_sharing($company_detail_id,'','1',$hold,'holding company','3'); 
                 
					$i++;
				}
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] = $share['msg'];
					$response['data'] = $share['data'];  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}
			}
			  if(isset($subs_comp) && !empty($subs_comp))
			  {
				$subs_comp_array=explode(',',$subs_comp);
				$company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'2',$wholl_own);
             
				$i=0;
				foreach($subs_comp_array as $subs)
				{
				// 	// echo $hold.'<br>';
					$share= $obj_dba_func->set_sharing($company_detail_id,'','2',$subs,'Subsidiary Companies','3'); 

					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			  if(isset($wholl_own) && !empty($wholl_own))
			  {	
		//print_r('in whole');	
				$wholl_own_array=explode(',',$wholl_own);
				$company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'3',$whole_time ); 
				$i=0;
				foreach($wholl_own_array as $wholl)
				{
				// 	// echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','3',$wholl,'Wholly Owned Subidiary Companies','3'); 

					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			  if(isset($form_dir)  && !empty($form_dir))
		      {			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$form_dir_array=explode(',',$form_dir);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'4',$relat_direct); 
				$i=0;
				foreach($form_dir_array as $form)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','4',$form,'Managing Director','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			  if(isset($whole_time) && !empty($whole_time))
			  {			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$whole_time_array=explode(',',$whole_time);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'5',$dirc_part); 
				$i=0;
				foreach($whole_time_array as $whole)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','5', $whole,'Whole time directors','3'); 
					$i++;
				}  

				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			  if(isset($direc_comp) && !empty($direc_comp) )
			  {			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_comp_array=explode(',',$direc_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'6',$priv_comp); 
				$i=0;
				foreach($direc_comp_array as $direc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','6', $direc,'Director of an Company','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			  if(isset($relat_direct) && !empty($relat_direct))
			  {			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$relat_direct_array=explode(',',$relat_direct);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'7',$subs_comp); 
				$i=0;
				foreach($relat_direct_array as $relat)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','7',$relat,'Relative of directors','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
		      if(isset($part_dirc ) && !empty($part_dirc ))
			  {			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$part_dirc_array=explode(',',$part_dirc );
			//$share = $obj_dba_func->set_sharing($company_detail_id,'8',$form_dir ); 
				$i=0;
				foreach($part_dirc_array as $part)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','8', $part,'Partner of directors in any firm (incl. LLP)','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($dirc_part ) && !empty($dirc_part ))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$dirc_part_array=explode(',',$dirc_part );
			//$share = $obj_dba_func->set_sharing($company_detail_id,'9',$direc_comp); 
				$i=0;
				foreach($dirc_part_array as $dirc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','9', $dirc,'Firm (incl. LLP) in which director is a partner','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($rel_dirc) && !empty($rel_dirc))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$rel_dirc_array=explode(',',$rel_dirc);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'10',$part_dirc); 
				$i=0;
				foreach($rel_dirc_array as $rel)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','10',$rel,'Firm (incl. LLP) in which relative of director is a partner','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($priv_comp) && !empty($priv_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$priv_comp_array=explode(',',$priv_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'11',$direc_hold_comp); 

				$i=0;
				foreach($priv_comp_array as $priv)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','11',$priv,'Private Companies in which director is a director','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			       $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_mem ) && !empty($direc_mem) )
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_mem_array=explode(',',$direc_mem);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'12',$direc_mem ); 

				$i=0;
				foreach($direc_mem_array as $direc_m)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','12',$direc_m,'Private Companies in which director is a Member','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_hold_comp) && !empty($direc_hold_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_hold_comp_array=explode(',',	$direc_hold_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'13',$rel_dirc); 
				$i=0;
				foreach($direc_hold_comp_array as $direc_hold)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','13',$direc_hold,'Director of holding company','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp) && !empty($llp_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_array=explode(',',$llp_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'14',$llp_comp); 
				$i=0;
				foreach($llp_comp_array as $llp)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','14',$llp,'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp_lead) && !empty($llp_comp_lead))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_lead_array=explode(',',$llp_comp_lead);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'15',$llp_comp_lead); 
				$i=0;
				foreach( $llp_comp_lead_array as $llp_com)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','15',$llp_com,'any directors of lending company','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}      
             }
             
          }
          else
          {
     
	        if(isset($hold_comp) && !empty($hold_comp))
			{  	
			   
				$hold_comp_array=explode(',',$hold_comp);
				
				$company_detail_id=$_COOKIE["company_detail_id"];

				//$share = $obj_dba_func->set_sharing($company_detail_id,'1',$hold_comp); 
				$holding=array();
				
				$i=0;
				foreach($hold_comp_array as $hold)
				{
			        
					$share = $obj_dba_func->set_sharing($company_detail_id,'','1',$hold,'holding company','3'); 
                    
                   
					$i++;
				}
				if( $share['n']== 1)
				{ 
				  
					$response['n']   = 2;
					$response['msg'] = $share['msg'];
					$response['data'] = $share['data'];  
				
					
				
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}
			}
			if(isset($subs_comp) && !empty($subs_comp))
			{
				$subs_comp_array=explode(',',$subs_comp);
				$company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'2',$wholl_own);
             
				$i=0;
				foreach($subs_comp_array as $subs)
				{
				// 	// echo $hold.'<br>';
					$share= $obj_dba_func->set_sharing($company_detail_id,'','2',$subs,'Subsidiary Companies','3'); 

					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
                 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($wholl_own) && !empty($wholl_own))
			{	
		//print_r('in whole');	
				$wholl_own_array=explode(',',$wholl_own);
				$company_detail_id=$_COOKIE["company_detail_id"];

			//$share = $obj_dba_func->set_sharing($company_detail_id,'3',$whole_time ); 
				$i=0;
				foreach($wholl_own_array as $wholl)
				{
				// 	// echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','3',$wholl,'Wholly Owned Subidiary Companies','3'); 

					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
			      
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($form_dir)  && !empty($form_dir))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$form_dir_array=explode(',',$form_dir);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'4',$relat_direct); 
				$i=0;
				foreach($form_dir_array as $form)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','4',$form,'Managing Director','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($whole_time) && !empty($whole_time))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$whole_time_array=explode(',',$whole_time);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'5',$dirc_part); 
				$i=0;
				foreach($whole_time_array as $whole)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','5', $whole,'Whole time directors','3'); 
					$i++;
				}  

				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_comp) && !empty($direc_comp) )
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_comp_array=explode(',',$direc_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'6',$priv_comp); 
				$i=0;
				foreach($direc_comp_array as $direc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','6', $direc,'Director of an Company','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				   
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($relat_direct) && !empty($relat_direct))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$relat_direct_array=explode(',',$relat_direct);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'7',$subs_comp); 
				$i=0;
				foreach($relat_direct_array as $relat)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','7',$relat,'Relative of directors','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				   	
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($part_dirc ) && !empty($part_dirc ))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$part_dirc_array=explode(',',$part_dirc );
			//$share = $obj_dba_func->set_sharing($company_detail_id,'8',$form_dir ); 
				$i=0;
				foreach($part_dirc_array as $part)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','8', $part,'Partner of directors in any firm (incl. LLP)','3'); 
					$i++;
				}  
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			        $response['data'] = $share['data'];
			       
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($dirc_part ) && !empty($dirc_part ))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$dirc_part_array=explode(',',$dirc_part );
			//$share = $obj_dba_func->set_sharing($company_detail_id,'9',$direc_comp); 
				$i=0;
				foreach($dirc_part_array as $dirc)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','9', $dirc,'Firm (incl. LLP) in which director is a partner','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($rel_dirc) && !empty($rel_dirc))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$rel_dirc_array=explode(',',$rel_dirc);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'10',$part_dirc); 
				$i=0;
				foreach($rel_dirc_array as $rel)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','10',$rel,'Firm (incl. LLP) in which relative of director is a partner','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($priv_comp) && !empty($priv_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$priv_comp_array=explode(',',$priv_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'11',$direc_hold_comp); 

				$i=0;
				foreach($priv_comp_array as $priv)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','11',$priv,'Private Companies in which director is a director','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
			       $response['data'] = $share['data'];
			      
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_mem ) && !empty($direc_mem) )
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_mem_array=explode(',',$direc_mem);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'12',$direc_mem ); 

				$i=0;
				foreach($direc_mem_array as $direc_m)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','12',$direc_m,'Private Companies in which director is a Member','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($direc_hold_comp) && !empty($direc_hold_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$direc_hold_comp_array=explode(',',	$direc_hold_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'13',$rel_dirc); 
				$i=0;
				foreach($direc_hold_comp_array as $direc_hold)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','13',$direc_hold,'Director of holding company','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
					
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp) && !empty($llp_comp))
			{			
				$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_array=explode(',',$llp_comp);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'14',$llp_comp); 
				$i=0;
				foreach($llp_comp_array as $llp)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','14',$llp,'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
				    $response['data'] = $share['data'];
				
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}
			if(isset($llp_comp_lead) && !empty($llp_comp_lead))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$llp_comp_lead_array=explode(',',$llp_comp_lead);
			//$share = $obj_dba_func->set_sharing($company_detail_id,'15',$llp_comp_lead); 
				$i=0;
				foreach( $llp_comp_lead_array as $llp_com)
				{
				 // echo $hold.'<br>';
					$share = $obj_dba_func->set_sharing($company_detail_id,'','15',$llp_com,'any directors of lending company','3'); 
					$i++;
				} 
				if( $share['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $share['msg'];
                    $response['data'] = $share['data'];
                  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $share['msg'];
				}

			}   
          }
	   }
	   else if($step==4)
	   {
	       
	      if(isset($given_loan) && !empty($given_loan))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$given_loan_array=explode(',',$given_loan);
				//print_r($given_loan_array);
			    $given_relation_array=explode(',',$given_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach( $given_loan_array as $key => $given_loan)
				{
					$give_loan_index = $key;

					foreach($given_relation_array as $index => $given_relation)
					{
                     $given_relation_index = $index;
                     if($give_loan_index == $given_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction($company_detail_id,'','16',$given_loan,$given_relation,'4'); 

                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   =2;
					$response['msg'] =  $trans['msg'];

				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
			if(isset($loan) && !empty($loan))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$loan_array=explode(',',$loan);
				//print_r($given_loan_array);
			     $loan_relation_array=explode(',',$loan_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach( $loan_array as $key => $loan)
				{
					$loan_index = $key;

					foreach( $loan_relation_array as $index => $loan_relation)
					{
                    $loan_relation_index = $index;
                     if($loan_index == $loan_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction($company_detail_id,'','17',$loan,$loan_relation,'4'); 
                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
             if(isset($guarantee_loan) && !empty($guarantee_loan ))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$guarantee_loan_array=explode(',',$guarantee_loan);
				//print_r($given_loan_array);
			    $guarantee_relation_array=explode(',',$guarantee_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach($guarantee_loan_array as $key => $guarantee_loan)
				{
					 $guarantee_loan_index = $key;

					foreach($guarantee_relation_array as $index => $guarantee_relation)
					{
                     $guarantee_relation_index = $index;
                     if($guarantee_loan_index == $guarantee_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction($company_detail_id,'','18',$guarantee_loan,$guarantee_relation,'4'); 
                     }
					$i++;
				   }
				   
			   }
				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}

			}
             if(isset($security_loan ) && !empty($security_loan ))
			{		

				$company_detail_id=$_COOKIE["company_detail_id"];
				$security_loan_array=explode(',',$security_loan );
				//print_r($given_loan_array);
			    $security_relation_array=explode(',',$security_relation);
			    //print_r($given_relation_array);
				$i=0;
				foreach($security_loan_array as $key => $security_loan)
				{
					$security_loan_index = $key;

					foreach($security_relation_array as $index => $security_relation)
					{
                    $security_relation_index = $index;
                     if($security_loan_index == $security_relation_index)
                     {
                     	$trans = $obj_dba_func->set_transaction($company_detail_id,'','19',$security_loan,$security_relation,'4'); 
                        
                     	
                     }
					$i++;
				   }

				   
			   }

				if( $trans['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $trans['msg'];
				}
               
			}  
			else
			{ 
			    $company_detail_id=$_COOKIE["company_detail_id"];
			   	$trans = $obj_dba_func->set_transaction($company_detail_id,'','','','',''); 
			    
			    if( $trans['n']== 1)
				{ 
				    
					$response['n']   = 2;
					$response['msg'] =  $trans['msg'];

				}
			}
	   }
		
	      if($trans["success"]==3)
              {
                  
                  
                  
                                        $company_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_detail_id AND (sub_company_type_id=6 OR sub_company_type_id=7 OR sub_company_type_id=8 OR sub_company_type_id=10 OR sub_company_type_id=13)");
                              // echo "<pre>";print_r($company_arr);echo "</pre>";
                             // print_r($company_arr);
                          $loan_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'ELSE 'Security Provided to' END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_detail_id AND sub_company_type_id=2");

                            $wholly_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'ELSE 'Security Provided to' END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_detail_id AND sub_company_type_id=3");

    $parties_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name , CASE  WHEN sub_company_type_id = 4 THEN '1. It should be a part of the conditions of service extended by the company to all its employees; or
2. It should be pursuant to any scheme approved by the members by a special resolution;
' WHEN sub_company_type_id = 5 THEN '1. It should be a part of the conditions of service extended by the company to all its employees; or
2. It should be pursuant to any scheme approved by the members by a special resolution;
'WHEN sub_company_type_id = 11 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 12 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 14 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'
WHEN sub_company_type_id = 15 THEN 'Passing of special resolution + Explanatory statement to the notice disclosing the full particulars of the loans given, or guarantee given or security provided + the purpose for which the loan or guarantee or security is proposed to be utilised by the recipient of the loan or guarantee or security + the loans are utilised by the borrowing company for its principal business activities.'

END as conditi","gbca_sub_company_mapping","company_detail_id=$company_detail_id AND (sub_company_type_id=4 OR sub_company_type_id=5 OR sub_company_type_id=11 OR sub_company_type_id=12 OR sub_company_type_id=14 OR sub_company_type_id=15)");

                             
    $given_arr = $obj->select("*,CASE
    WHEN sub_company_type_id = 1 THEN 'Holding Companies'
    WHEN sub_company_type_id = 2 THEN 'Subsidiary Companies'
    WHEN sub_company_type_id = 3 THEN 'Wholly Owned Subidiary Companies'
    WHEN sub_company_type_id = 4 THEN 'Managing Director'
    WHEN sub_company_type_id = 5 THEN 'Whole time directors'
    WHEN sub_company_type_id = 6 THEN 'Director of an Company'
    WHEN sub_company_type_id = 7 THEN 'Relative of directors'
    WHEN sub_company_type_id = 8 THEN 'Partner of directors in any firm (incl. LLP)'
     WHEN sub_company_type_id = 9 THEN 'Firm (incl. LLP) in which director is a partner'
    WHEN sub_company_type_id = 10 THEN 'Firm (incl. LLP) in which relative of director is a partner'
    WHEN sub_company_type_id = 11 THEN 'Private Companies in which director is a director'
    WHEN sub_company_type_id = 12 THEN 'Private Companies in which director is a Member'
    WHEN sub_company_type_id = 13 THEN 'Director of holding company'
    WHEN sub_company_type_id = 14 THEN 'Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%'
    WHEN sub_company_type_id = 15 THEN 'any directors of lending company'
    WHEN sub_company_type_id = 16 THEN 'Given Loan to'
    WHEN sub_company_type_id = 17 THEN 'Loan Represented as Book debt'
    WHEN sub_company_type_id = 18 THEN 'Guarantee Given in respect of Loan taken by'
    ELSE 'Security Provided to'
END as sub_company_name","gbca_sub_company_mapping","company_detail_id=$company_detail_id AND (sub_company_type_id=16 OR sub_company_type_id=17 OR sub_company_type_id=18 OR sub_company_type_id=19)");
                  
                 
                    // print_r('applicable');
                 $sub_id=$_COOKIE["company_detail_id"];
               $detail=$obj->select( "*","gbca_company_detail_master as gbca RIGHT JOIN gbca_company_master as mas ON gbca.company_detail_name=mas.company_id RIGHT JOIN gbca_section_master as sec ON gbca.section_id=sec.section_id ","company_detail_id= $sub_id ");
            
              $section=$detail[0]["section_name"];
              $company=trim($detail[0]["company_name"]);
               
              $preparation=date("d F Y");
              $maker=$detail[0]["company_detail_maker_name"];
              $checker=$detail[0]["company_detail_checker_name"];
              $today_date=date('d M Y');
              $date=$detail[0]["company_detail_preparation_date"];
           
              $time=time();
                // $res='';
                     $res .='<!DOCTYPE html><html><head> <style>table{width: 100%;}th, td{padding: 10px;}th{background: rgb(37,71, 150); color: #fff;}table, th, td{border: 1px solid black; border-collapse: collapse; text-align: left;}</style></head><body> <table style="border:none"> <tr style="border:none"> <td style="border:none; text-align: center;"><img src="https://gbcacompliance.oneroof.tech/new/assets/img/logo.png" style="height: 70px;" alt="logo"></td></tr><tr style="border:none"> <td style="border:none"> <h3 style="color:#483D8B; text-align: center;"><u>Report Card for Eligibility Test of Section 185 of the Companies Act, 2013</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company.'</td><td style="border:none"><b>Preparation Date: </b>'.$date.'</td></tr><tr style="border:none"> <td style="border:none"><b>Made By: </b>'. $maker.'</td><td style="border:none"><b>Checked By: </b>'. $checker.'</td></tr></table><br/>';
               
               
                 $res .='<p>A. List of Parties to whom the company cannot advance any Loan or Provide any Security and Give any guarantee in respect of loan taken by such party</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 42%;">Parties</th> <th style="width: 42%;">Nature of relation</th> </tr>';
                 
                  if(is_array($company_arr))
                  {
                      $i = 1;
                  foreach($company_arr as $company1)
                  {
                 
                 $res .='<tr><td>'.$i.'</td><td>'.$company1["sub_company_type_name"].'</td><td>'.$company1["sub_company_name"].'</td></tr>';
                 
                   $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No record found.</td></tr>';  
                  }
                 
                 $res .='</table><br/><p>B. List of Parties to whom the company cannot advance any Loan but can Provide any Security or Give any guarantee in respect of loan taken by such party</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 42%;">Parties</th> <th style="width: 42%;">Nature of relation</th> </tr>';
                 
                  if(is_array($loan_arr))
                  {
                      $i = 1;
                  foreach($loan_arr as $loan)
                  {
                 
                     $res .='<tr><td>'.$i.'</td><td>'.$loan["sub_company_type_name"].'</td><td>'.$loan["sub_company_name"].'</td></tr>';
                     
                      $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No record found.</td></tr>';   
                  }
                     
                    $res .='</table><br/><p>C. List of Parties to whom the company can advance Loan or Provide any Security or Give any guarantee in respect of loan taken by such party without any conditions</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Remark</th> </tr>';
                    
                     if(is_array($wholly_arr))
                  {
                      $i = 1;
                  foreach($wholly_arr as $wholly)
                  {
                  
                    
                        $res .='<tr><td>'.$i.'</td><td>'.$wholly["sub_company_type_name"].'</td><td>'.$wholly["sub_company_name"].'</td><td></td></tr>';
                  }
                  }else
                  {
                     $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
    
                  $res .='</table><br/> <p>D. List of Parties to whom the company can advance Loan or Provide any Security or Give any guarantee in respect of loan taken by such party provided certain conditions are met. <br>(If such conditions are not met, the transaction shall be treated as non-compliant)</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Condition</th> </tr>';
                  
                  if(is_array($parties_arr))
                  {
                      $i = 1;
                  foreach($parties_arr as $parties)
                  {
                   $res .='<tr><td>'.$i.'</td><td>'.$parties["sub_company_type_name"].'</td><td>'.$parties["sub_company_name"].'</td><td>'. $parties['conditi'].'</td></tr>';
               
                    $i++;
                  }
                  }else
                  {
                      
                        $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
                  
                      $res .='</table><br/> <p>E. List of Parties with whom the company has already undertaken specified transactions which require due attention of the management as the same may either be not in compliance with the provisions or may require to fulfill one or the other condition to comply with the provisions of Sec 185 of the Companies Act, 2013 <br>(unless the borrower is Wholly Owned Subsidiary).</p><table> <tr> <th style="width: 7%;">Sr. No.</th> <th style="width: 39%;">Parties</th> <th style="width: 39%;">Nature of relation</th> <th style="width: 15%;">Transaction Type</th> </tr>';
                  
                  if(is_array($given_arr))
                  {
                      $i = 1;
                  foreach($given_arr as $given)
                  {
                   $res .='<tr><td>'.$i.'</td><td>'.$given["sub_company_type_name"].'</td><td>'.$given["sub_company_transaction_relation"].'</td><td>'.$given["sub_company_name"].'</td></tr>';
               
                    $i++;
                  }
                  }else
                  {
                      
                        $res .='<tr><td  colspan="4" style="text-align:center">No record found.</td></tr>';    
                  }
                  
                  $res .='</table></body></html><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
				
                $company= str_replace(" ","_",$company);
                
				$filename =$company.'_'.$time.'.pdf';
			    
				$dompdf->set_paper($paper,$orientation);
				$dompdf->load_html($res);
				$dompdf->render();
				$output = $dompdf->output();
				$file_to_save = '../pdffiles/'.$filename;
			
				file_put_contents($file_to_save, $output);
				$file = $file_to_save;
				$file_size = filesize($file);
				$handle = fopen($file, "r");
				$content = fread($handle, $file_size);
				fclose($handle);
                
               	$destination_url = '../pdffiles/';
                 	
                $documents = $obj_dba_func->store_pdf($company_detail_id,'',$filename); 

                	$response['n']   = 1;
					$response['msg'] = "applicable";
                

              }

}
		 
	else
	{
		
			$response['n']   = 0;
			$response['msg'] ="COOKIES NOT SET";
		
	}  
	}
	
	 }
	else if($type =='add')
	{
	   $is_company = $obj->select("*","gbca_company_master","company_name = '$company_name' AND company_status = '1'");
	
	  if($is_company != 0 || is_array($is_company))
	  {
	      $response['n'] = 2;
		$response['msg']= "Company already exists";
	  }
	  else
	  {
	    
	  $status='1';
	  $new = $obj_dba_func->set_new_company($company_name,$status);

	  if($new['n'] == 1)
		{
			$response['n']   = 1;
			$response['msg'] = "company added successfully"; 
			
	   }
	   else
	   {
	     
			$response['n']   = 0;
			$response['msg'] = "company error";   
	   }
	}
	}
	else
	{
	    	$response['n']   = 0;
			$response['msg'] = "type error"; 
	}
		//setcookie("company_detail_id", "", time()-3600);

  

	echo json_encode($response);
	?>