<?php
 $company_detail_id=$_COOKIE["company_detail_id"];
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
  {
    $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=$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();              
                  
                  
                    // 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=$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: 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/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></td><td style="border:none"><b>'.$date.'</b></td></tr><tr style="border:none"> <td style="border:none"><b>'. $maker.'</b></td><td style="border:none"><b>'. $checker.'</b></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 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.'.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); 

                
  }
  
  
} 
else{}  

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';
}
?>