<?php  
require_once("../lib/db_functions.php");
// print_r($_POST);
require_once 'dompdf/autoload.inc.php';
          use Dompdf\Dompdf;
           $dompdf = new Dompdf();
    $response = array();  
	$step =  $obj->data_filter($_POST['step']); 
   $company_edit_id = $obj->data_filter($_POST['company_detail_id']);
  $preparation_date =$obj->data_filter(date("Y-m-d"));
  $type_company     = $obj->data_filter($_POST['company-select']);
  	$substantial_interest = $obj->data_filter($_POST['substantial_interest']);

	$other            = $obj->data_filter($_POST['other_company_name']); 
	$financ_year      = $obj->data_filter($_POST['finan-year']);
	$cut_off          = $obj->data_filter(date("Y-m-d",strtotime($_POST['date'])));
	$name_of_shareholder        = $obj->data_filter($_POST['name_of_shareholder']); 
     
	$shareholding_per   = $obj->data_filter($_POST['shareholding_per']);
// 	$entity_of_second_step = $obj->data_filter($_POST['entity1']);
	$name_of_shareholder2  = $obj->data_filter($_POST['name_of_shareholder2']);
	$shareholding_per2     = $obj->data_filter($_POST['shareholding_per2']);
	$list_of_concern         = $obj->data_filter($_POST['list_of_concern']);
	$type_of_concern     = $obj->data_filter($_POST['type_of_concern']);
	$entity_of_third_step = $obj->data_filter($_POST['entity2']);

	
	if($company_edit_id != "")
	{
	    setcookie($cookie_name, $cookie_value, time() - (60 * 60), "/");
	    $_SESSION["company_detail_id"] = $company_edit_id;
	 
	  if($step==1)
	  {
	     
	     $section_arr = $obj_dba_func->set_section_22e('',$company_edit_id,$type_company,$financ_year,$other,$cut_off,$substantial_interest);
	  
        if($section_arr['n'] == 1)
		{
			$response['n']   = 2;
			$response['msg'] = "step1 success"; 
			$response['second_step'] = $section_arr['second_step']; 

	   }
	   else
	   {
	     
			$response['n']   = 0;
			$response['msg'] = "step1 success";   
	   }
	  }
	  else if($step==2)
	  {
	      
	  	// $delete_records = $obj_dba_func->delete_shareholders($company_edit_id,'1'); 
				
				// if($delete_records['n'] == 	1)
				// {
			if(isset($name_of_shareholder) && !empty($name_of_shareholder))
			{	
				
			 // $myJSON=explode(',',$name_of_shareholder);
			 $name_of_shareholder_array=explode(',',$name_of_shareholder);	
			  $shareholding_per_array=explode(',',$shareholding_per);
                // $entity1_array=explode(',',$entity_of_second_step);
                
				$i=0;
				foreach( $name_of_shareholder_array as $key => $name_of_shareholder)
				{
					$name_of_shareholder_index = $key;

					foreach($shareholding_per_array as $index => $shareholding_per)
					{
					    
                     $shareholding_per_index = $index;
                        
                        // foreach($entity1_array as $ind => $entity1 )
                        // {
                        //     $entity1_index = $ind;
                        
                     if($name_of_shareholder_index == $shareholding_per_index)  
                     {
                         
            				            $shares = $obj_dba_func->set_shareholders('',$company_edit_id,$name_of_shareholder,$shareholding_per); 
            				            
            				     
                     }
                     	$i++;
				// }
				
                        
                     }
					
				
				   
			   }  

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

			}
				 
// 			}
// 			else
// 			{
// 				 $response['n']   = 0;
// 			$response['msg'] = "delete error";  
// 			}
		}
         
	 	   
	  else if($step==3)
	  {
	    $delete_records = $obj_dba_func->delete_shareholders($company_edit_id,'2'); 
				
		if($delete_records['n'] == 	1) 
		{
	    if(isset($name_of_shareholder2) && !empty($name_of_shareholder2))
			{	

	       $name_of_shareholder_array=explode(',',$name_of_shareholder2);
				//print_r($given_loan_array);
			    $shareholding_per_array=explode(',',$shareholding_per2);
			    $type_of_concern_array=explode(',',$type_of_concern);
			    $list_of_concern_array=explode(',',$list_of_concern);
			    $entity2_array=explode(',',$entity_of_third_step);
			    //print_r($given_relation_array);
				$i=0;
				foreach( $name_of_shareholder_array as $key => $name_of_shareholder)
				{
					$name_of_shareholder_index = $key;

					foreach($shareholding_per_array as $index => $shareholding_per)
					{
                     $shareholding_per_index = $index;
                     foreach($type_of_concern_array as $keyindex => $type_of_concern)
										{
											$type_of_concern_index = $keyindex;

										foreach($list_of_concern_array as $indexkey => $list_of_concern)
										{
											$list_of_concern_index = $indexkey;
                                        foreach($entity2_array as $entity2_indexkey => $entity2)
										{
											$entity2_index = $entity2_indexkey;
                     if(($name_of_shareholder_index == $shareholding_per_index) && ($name_of_shareholder_index == $type_of_concern_index) && ($name_of_shareholder_index == $list_of_concern_index) && ($name_of_shareholder_index == $entity2_index) )
                     {
                     	$shares2 = $obj_dba_func->set_shareholders2('',$company_edit_id,$name_of_shareholder,$list_of_concern,$type_of_concern,$shareholding_per,$entity2); 

                     }
					$i++;
				  }
			      }
				 }
				}

 
			   }
				if( $shares2['n']== 1)
				{ 
					$response['n']   = 2;
					$response['msg'] = $shares2['msg'];
				
					  
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $shares2['msg'];
				}
			
			}
	   else
			{
		    $response['n']   = 0;
			$response['msg'] = "delete error";  
			}
            
             if($shares2["success"]==3)
              {
                  $report=$obj->select( "*","gbca_company_detail_master","(company_type_name='private-company' Or company_detail_substantially_interested='No') AND  company_detail_id=$company_edit_id");
                    // print_r($report);
                    
              	 $company_arr = $obj->select("*,gbca_company_shareholding_name,gbca_company_shareholding_percentage","gbca_company_shareholding_master","gbca_company_shareholding_company_id='$company_edit_id' AND  gbca_company_shareholding_percentage >=10 AND gbca_company_shareholding_excel_type='1' and gbca_company_shareholding_status='1'");
                                // echo "<pre>";print_r($company_arr);echo "</pre>";exit;
                  //print_r($company_arr);
            //   $type_of_concern_company_arr = $obj->select("*","gbca_company_shareholding_master","gbca_company_shareholding_company_id='$company_edit_id' and gbca_company_shareholding_type_of_concern = 'company' and gbca_company_shareholding_status='1'");

              $type_of_concern_other_than_company_arr = $obj->select("*","gbca_company_shareholding_master","gbca_company_shareholding_company_id='$company_edit_id' and ( (gbca_company_shareholding_type_of_concern != 'company' and  gbca_company_shareholding_type_of_concern != '') or  gbca_company_shareholding_type_of_concern != '' or gbca_company_shareholding_list_of_concern != '' or gbca_company_shareholding_percentage != null  ) and gbca_company_shareholding_status='1' and gbca_company_shareholding_excel_type='2'"); 
 
                if(is_array($report))
                {
                    //print_r('not 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= $company_edit_id");
           
              $section=$detail[0]["section_name"];
              $company_name=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="../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 2(22)e of the Income Tax Act, 1961</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company_name.'</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 Shareholders to whom the company cannot extend any Loan or Advance</p><table> <tr> <th>Sr. No.</th> <th>Name of the Shareholder</th> <th>% Eq. Shareholding</th> </tr>';
                 
                  if(is_array($company_arr))
                  {
                      $i = 1;
                  foreach($company_arr as $company)
                  {
                 
                 $res .='<tr><td>'.$i.'</td><td>'.$company["gbca_company_shareholding_name"].'</td><td>'.$company["gbca_company_shareholding_percentage"].'</td></tr>';
                 
                   $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No Data Inserted.</td></tr>';  
                  }
                 
                 $res .=' </table><br/> <p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advancey</p><table> <tr> <th>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                 
                  if(is_array($type_of_concern_company_arr))
                  {
                      $i = 1;
                  foreach($type_of_concern_company_arr as $type_of_concern_company)
                  {
                 
                     $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_percentage"].'</td></tr>';
                     
                      $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="4" style="text-align:center">No Data Inserted.</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>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>
  ';
                    
                     if(is_array($type_of_concern_other_than_company_arr))
                  {
                      $i = 1;
                  foreach($type_of_concern_other_than_company_arr as $type_of_concern_other_than_company)
                  {
                  
                    
                        $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_percentage"].'</td></tr>';
                        $i++;
                  }
                  }else
                  {
                     $res .='<tr><td  colspan="4" style="text-align:center">No Data Inserted.</td></tr>';    
                  }
    
                 
                  $res .='</table><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
                $company= str_replace(" ","_",$company_name);
				$filename =$company_name.'_'.$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
                {
               		
                // $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= $company_edit_id");
           
              $section=$detail[0]["section_name"];
              $company_name=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="../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 2(22)e of the Income Tax Act, 1961</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company_name.'</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 Shareholders to whom the company cannot extend any Loan or Advance</p><table> <tr> <th>Sr. No.</th> <th>Name of the Shareholder</th> <th>% Eq. Shareholding</th> </tr>';
                 
                //   if(is_array($company_arr))
                //   {
                //       $i = 1;
                //   foreach($company_arr as $company)
                //   {
                 
                //  $res .='<tr><td>'.$i.'</td><td>'.$company["gbca_company_shareholding_name"].'</td><td>'.$company["gbca_company_shareholding_percentage"].'</td></tr>';
                 
                //   $i++;
                //   }
                //   }else
                //   {
                    $res .='<tr><td colspan="3" style="text-align:center">No Data Inserted.</td></tr>';  
                //   }
                 
                 $res .='</table><br/> <p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advancey</p><table> <tr> <th>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                 
                //   if(is_array($type_of_concern_company_arr))
                //   {
                //       $i = 1;
                //   foreach($type_of_concern_company_arr as $type_of_concern_company)
                //   {
                 
                //      $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_percentage"].'</td></tr>';
                     
                //       $i++;
                //   }
                //   }else
                //   {
                    $res .='<tr><td colspan="4" style="text-align:center">No Data Inserted.</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>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                    
                //      if(is_array($type_of_concern_other_than_company_arr))
                //   {
                //       $i = 1;
                //   foreach($type_of_concern_other_than_company_arr as $type_of_concern_other_than_company)
                //   {
                  
                    
                //         $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_percentage"].'</td></tr>';
                //   }
                //   }else
                //   {
                     $res .='<tr><td  colspan="4" style="text-align:center">No Data Inserted.</td></tr>';    
                //   }
    
                 
                  $res .='</table><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
                $company= str_replace(" ","_",$company_name);
				$filename =$company_name.'_'.$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']   = 3;
									$response['msg'] = "not applicable";
                
                }

              }


	
  }
	    }
	
}
else{
	if(isset($_COOKIE["company_detail_id"]))
	{	

		if($step == 1)
		{
		    unset($_SESSION["company_detail_id"]);
	     $company_detail_id=$_COOKIE["company_detail_id"];
		$section_arr = $obj_dba_func->set_section_22e($company_detail_id,'',$type_company,$financ_year,$other,$cut_off,$substantial_interest);   
         if($section_arr['n'] == 1)
	 {
	 	$response['n']   = 2;
	 	$response['msg'] ="step1 success";
	 }
	 else
	 {
	 	$response['n']   = 0;
	 	$response['msg'] ="step1 success";
	 }
	
		}
		else if($step==2)
     {
         $company_detail_id=$_COOKIE["company_detail_id"];
     	$delete_records = $obj_dba_func->delete_shareholders_on_add($company_detail_id,'1'); 
        
        	if($delete_records['n'] == 	1){
               	$company_detail_id=$_COOKIE["company_detail_id"];
				$name_of_shareholder_array=explode(',',$name_of_shareholder);
			    $shareholding_per_array=explode(',',$shareholding_per);
			 //   $entity1_array = explode(',',$entity_of_second_step);
			 //print_r($name_of_shareholder_array);
			    
			   
			   
				$i=0;
				foreach( $name_of_shareholder_array as $key => $name_of_shareholder)
				{
					$name_of_shareholder_index = $key;

					foreach($shareholding_per_array as $index => $shareholding_per)
					{					
                     $shareholding_per_index = $index;
    //                     	foreach($entity1_array as $ind => $entity1)
				// 	{
				// 	    $entity1_index = $ind;
                     if($name_of_shareholder_index == $shareholding_per_index) 
                     {
                     
                     	$shares = $obj_dba_func->set_shareholders($company_detail_id,'',$name_of_shareholder,$shareholding_per); 
                     
 
                     }
                      $i++;
					
				//   }
				  
				   
					}
				   
			   }
				if( $shares['n']== 1)
				{ 
					$response['n']   =  2 ;
					$response['msg'] =  "step2 success";
					$response['third_step'] = $shares['third_step'];
 
				}
				else
				{
					$response['n']   = 0;
					$response['msg'] =  $shares['msg'];
				}
            }
             else
			{
		    $response['n']   = 0;
			$response['msg'] = "delete error";  
			}
        
        
     }
     else if($step==3)
     {
     	$company_detail_id=$_COOKIE["company_detail_id"];
				$name_of_shareholder_array=explode(',',$name_of_shareholder2);
				//print_r($given_loan_array);
			    $shareholding_per_array=explode(',',$shareholding_per2);
			    $type_of_concern_array=explode(',',$type_of_concern);
			    $list_of_concern_array=explode(',',$list_of_concern);
			    $entity2_array=explode(',',$entity_of_third_step);
			    //print_r($given_relation_array);
				$i=0;
				foreach( $name_of_shareholder_array as $key => $name_of_shareholder)
				{
					$name_of_shareholder_index = $key;

					foreach($shareholding_per_array as $index => $shareholding_per)
					{
                     $shareholding_per_index = $index;
                     foreach($type_of_concern_array as $keyindex => $type_of_concern)
										{
											$type_of_concern_index = $keyindex;

										foreach($list_of_concern_array as $indexkey => $list_of_concern)
										{
											$list_of_concern_index = $indexkey;

                        
                        foreach($entity2_array as $entity2_array_indexkey => $entity2)
										{
											$entity2_index = $entity2_array_indexkey;
                            
                     if(($name_of_shareholder_index == $shareholding_per_index) && ($name_of_shareholder_index == $type_of_concern_index) && ($name_of_shareholder_index == $list_of_concern_index) && ($name_of_shareholder_index == $entity2_index)  )
                     {
                     	$shares2 = $obj_dba_func->set_shareholders2($company_detail_id,'',$name_of_shareholder,$list_of_concern,$type_of_concern,$shareholding_per,$entity2); 

                     }
					$i++;
				   }
				}
				 }
				}

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

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

				 if($shares2["success"]== 3)
              {
              	// print_r('in success');
              	 $report=$obj->select( "*","gbca_company_detail_master","(company_type_name='private-company' or company_detail_substantially_interested='No') And  company_detail_id=$company_detail_id");

                    // print_r($report); 
              	 $company_arr = $obj->select("*,gbca_company_shareholding_name,gbca_company_shareholding_percentage","gbca_company_shareholding_master","gbca_company_shareholding_company_id='$company_detail_id' AND  gbca_company_shareholding_percentage >=10 AND gbca_company_shareholding_excel_type='1' and gbca_company_shareholding_status='1'");
                                // echo "<pre>";print_r($company_arr);echo "</pre>";exit;
                              //print_r($company_arr);
                       $type_of_concern_other_than_company_arr = $obj->select("*","gbca_company_shareholding_master","gbca_company_shareholding_company_id='$company_detail_id' and ( (gbca_company_shareholding_type_of_concern != 'company' and  gbca_company_shareholding_type_of_concern != '') or  gbca_company_shareholding_type_of_concern != '' or gbca_company_shareholding_list_of_concern != '' or gbca_company_shareholding_percentage != null  ) and gbca_company_shareholding_status=1 and gbca_company_shareholding_excel_type=2"); 
              	 if(is_array($report))
                {
                          $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_name=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="../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 2(22)e of the Income Tax Act, 1961</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company_name.'</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 Shareholders to whom the company cannot extend any Loan or Advance</p><table> <tr> <th>Sr. No.</th> <th>Name of the Shareholder</th> <th>% Eq. Shareholding</th> </tr>';
                 
                  if(is_array($company_arr))
                  {
                      $i = 1;
                  foreach($company_arr as $company)
                  {
                 
                 $res .='<tr><td>'.$i.'</td><td>'.$company["gbca_company_shareholding_name"].'</td><td>'.$company["gbca_company_shareholding_percentage"].'</td></tr>';
                 
                   $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="3" style="text-align:center">No Data Inserted.</td></tr>';  
                  }
                 
                 $res .='</table><br/> <p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advancey</p><table> <tr> <th>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                 
                  if(is_array($type_of_concern_company_arr))
                  {
                      $i = 1;
                  foreach($type_of_concern_company_arr as $type_of_concern_company)
                  {
                 
                     $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_percentage"].'</td></tr>';
                     
                      $i++;
                  }
                  }else
                  {
                    $res .='<tr><td colspan="4" style="text-align:center">No Data Inserted.</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>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                    
                     if(is_array($type_of_concern_other_than_company_arr))
                  {
                      $i = 1;
                  foreach($type_of_concern_other_than_company_arr as $type_of_concern_other_than_company)
                  {
                  
                    
                        $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_percentage"].'</td></tr>';
                  }
                  }else
                  {
                     $res .='<tr><td  colspan="4" style="text-align:center">No Data Inserted.</td></tr>';    
                  }
    
                 
                  $res .='</table><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
                $company= str_replace(" ","_",$company_name);
				$filename =$company_name.'_'.$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
                {
               		
                 
                    // 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_name=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="../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 2(22)e of the Income Tax Act, 1961</u> </h3> </td></tr></table><br/> <table style="border:none"> <tr style="border:none"> <td style="border:none"><b>Company Name: </b>'. $company_name.'</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 Shareholders to whom the company cannot extend any Loan or Advance</p><table> <tr> <th>Sr. No.</th> <th>Name of the Shareholder</th> <th>% Eq. Shareholding</th> </tr>';
                 
                //   if(is_array($company_arr))
                //   {
                //       $i = 1;
                //   foreach($company_arr as $company)
                //   {
                 
                //  $res .='<tr><td>'.$i.'</td><td>'.$company["gbca_company_shareholding_name"].'</td><td>'.$company["gbca_company_shareholding_percentage"].'</td></tr>';
                 
                //   $i++;
                //   }
                //   }else
                //   {
                    $res .='<tr><td colspan="3" style="text-align:center">No Data Inserted.</td></tr>';  
                //   }
                 
                 $res .='</table><br/> <p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advancey</p><table> <tr> <th>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                 
                //   if(is_array($type_of_concern_company_arr))
                //   {
                //       $i = 1;
                //   foreach($type_of_concern_company_arr as $type_of_concern_company)
                //   {
                 
                //      $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_company["gbca_company_shareholding_percentage"].'</td></tr>';
                     
                //       $i++;
                //   }
                //   }else
                //   {
                    $res .='<tr><td colspan="4" style="text-align:center">No Data Inserted.</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>Sr. No.</th> <th>Name of the Concern</th> <th>Substantial Interest of</th> <th>% Shareholding / % Interest</th> </tr>';
                    
                //      if(is_array($type_of_concern_other_than_company_arr))
                //   {
                //       $i = 1;
                //   foreach($type_of_concern_other_than_company_arr as $type_of_concern_other_than_company)
                //   {
                  
                    
                //         $res .='<tr><td>'.$i.'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_type_of_concern"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_name"].'</td><td>'.$type_of_concern_other_than_company["gbca_company_shareholding_percentage"].'</td></tr>';
                //         $i++;
                //   }
                //   }else
                //   {
                     $res .='<tr><td  colspan="4" style="text-align:center">No Data Inserted.</td></tr>';    
                //   }
    
                 
                  $res .='</table><br/>'; 
		 
		   $paper = 'A4';
				$orientation = 'orientation';
                $company= str_replace(" ","_",$company_name);
				$filename =$company_name.'_'.$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']   = 3;
					$response['msg'] = "not applicable";
                
                }
              }
     //  $response['n']   = 3;
	 	  // $response['msg'] ="step1 success";
     }
   
	} 
	
}

 
echo json_encode($response);

?>