<?php
session_start();
require_once('lib/db_functions.php');  
$output = '';

if( isset($_GET['status']) ){
  $status = $obj->data_filter($_GET['status']); 
  if(!preg_match('/^[0-1]{1}$/', $status)){}
  else
  {
      if(isset($_SESSION["company_detail_id"]))
          { 
               $company_detail_id=$_SESSION["company_detail_id"];
       $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>";
                             // print_r($company_arr);
                          $type_of_concern_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_excel_type='2' 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_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_excel_type='2' AND gbca_company_shareholding_status='1'"); 

    
                  
     $sub_id=$_SESSION["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"];
              $substantially_interested=$substantially_interested[0]["company_detail_substantially_interested"];
              
              $time=time();              
                  
                  
                    // print_r('applicable');
                 $sub_id=$_SESSION["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"];
              
               $substantially_interested=$detail[0]["company_detail_substantially_interested"];
               
              $time=time();
                // $res='';
                     $res .='<!DOCTYPE html><html><head><style>table{width:100%;}th, td{padding:10px;}th{background: rgba(20,133,204,0.2);}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"><img src="https://gbcacompliance.oneroof.tech/new/assets/img/logo.png" style="height: 70px;" alt="logo"></td><td style="border:none"><h3 style="color:#483D8B;"><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/>';
               
               if(is_array($company_arr) || $substantially_interested == 'No' )
                {
                 $res .='<h4>Sec 2(22)(e) is Applicable to you. Please refer to the following Party-wise Checklist for your ready reference.</h4>';
                }
                else
                {
                   $res .='<h4>Sec 2(22)(e) is not Applicable to you. You can give loans to any person.</h4>';
  
                }
               
               
               
                 $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 record found.</td></tr>';  
                  }
                 
                 $res .='</table><br/><p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advance</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="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>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 record found.</td></tr>';   
                    
                  }
    
                  
                  
                  $res .='</table><br/>'; 
     
      // $paper = 'A4';
        // $orientation = 'orientation';

        $filename =$company_name.'_'.$time.'.xls';
         
          }  
          else
          {
          $company_detail_id=$_COOKIE["company_detail_id"];
       $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>";
                             // print_r($company_arr);
                          $type_of_concern_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_excel_type='2' 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_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_excel_type='2' AND gbca_company_shareholding_status='1'"); 

    
                  
               $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"];
              $substantially_interested=$detail[0]["company_detail_substantially_interested"];
              
              $time=time();              
                  
                  
                    // 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"];
              $substantially_interested=$detail[0]["company_detail_substantially_interested"];
              
              $time=time();
                // $res='';
                     $res .='<!DOCTYPE html><html><head><style>table{width:100%;}th, td{padding:10px;}th{background: rgba(20,133,204,0.2);}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"><img src="https://gbcacompliance.oneroof.tech/new/assets/img/logo.png" style="height: 70px;" alt="logo"></td><td style="border:none"><h3 style="color:#483D8B;"><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/>';
               
               
               if(is_array($company_arr) || $substantially_interested == 'No' )
                {
                 $res .='<h4>Sec 2(22)(e) is Applicable to you. Please refer to the following Party-wise Checklist for your ready reference.</h4>';
                }
                else
                {
                   $res .='<h4>Sec 2(22)(e) is not Applicable to you. You can give loans to any person.</h4>';
  
                }
                
                      if(is_array($company_arr))
                {
                 $res .='<h4>Sec 185 is Applicable to you. Please refer to the following Party-wise Checklist for your ready reference. Non-compliance of such provisions will have penal consequences on both, the lender and the borrower.</h4>';
                }
                else
                {
                  $res .='<h4>Sec 185 is not Applicable to you. You can give loans to any person, however please take due care of Sec 2(22)(e) of the Income Tax Act, 1961.</h4>';
  
                }
               
               
                 $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 record found.</td></tr>';  
                  }
                 
                 $res .='</table><br/><p>B. List of Concerns, being companies, to whom you cannot extend any Loan or Advance</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="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>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 record found.</td></tr>';   
                    
                  }
    
                  
                  
                  $res .='</table><br/>'; 
     
      // $paper = 'A4';
        // $orientation = 'orientation';

        $filename =$company_name.'_'.$time.'.xls';
         
}
                
  }
  
  
} 
else{}  

header("Content-Disposition: attachment; filename=$filename");
  header("Content-Type: application/vnd.ms-excel");

// header('Content-Type: application/xls');
// header('Content-Disposition: attachment; filename='.$filename.'.xls');  
// header("Pragma: no-cache");  
// header("Expires: 0");

// header("Content-Type: application/pdf");
// header("Cache-Control: max-age=0");
// header("Accept-Ranges: none");
// header("Content-Disposition: attachment; filename=\"google_com.pdf\"");   

echo $res; 

function show_contact2($val){
  return ($val == '')?'NA':$val;
}
 
function show_emergency_contact($val){
  return ($val == '')?'NA':$val;
} 

function show_father_name($val){
  return ($val == '')?'NA':$val;
} 

function show_father_phone($val){
  return ($val == '')?'NA':$val;
}  

function show_mother_name($val){
  return ($val == '')?'Na':$val;
} 

function show_mother_phone($val){
  return ($val == '')?'NA':$val;
} 

function show_spouse_name($val){
  return ($val == '')?'NA':$val;
}

function show_spouse_phone($val){
  return ($val == '')?'':$val;
} 

function show_communication_addr($val){
  return ($val == '')?'':$val;
} 

function show_x_doc($val){
  return ($val == '')?'No':'Yes';
} 

function show_xii_doc($val){
  return ($val == '')?'No':'Yes';
} 

function show_transfer_doc($val){
  return ($val == '')?'No':'Yes';
} 

function show_proof($val){
  return ($val == '')?'No':'Yes';
} 

function show_photo($val){
  return ($val == '')?'No':'Yes';
} 

function show_sign($val){
  return ($val == '')?'No':'Yes';
}
?>