0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.144.101.193


Current Path : /var/www/html/univadmin/Reports/
Upload File :
Current File : /var/www/html/univadmin/Reports/feeReportHeadwise.php

<?php

$main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('GMT+5:30');
// PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
$pdf_writer_class = $main_src . '/PHPExcel/Classes/PHPExcel.php';
require_once($pdf_writer_class);

function getheaders($objPHPExcel, $fileName)
{
    //To Fit To Page while printing
    $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="' . $fileName . '.xls"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');

    // If you're serving to IE over SSL, then the following may be needed
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header('Pragma: public'); // HTTP/1.0
    ob_clean();
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
}


function headwiseFeeReport($aobj_context)
{
    $objPHPExcel = new PHPExcel();
    $fileName = 'HeadwiseFeeReport';
    $objPHPExcel->getProperties()->setCreator("Uniclare")
    ->setLastModifiedBy("Me")->setTitle("My Excel Sheet")
    ->setSubject("My Excel Sheet")->setDescription("Excel Sheet")
    ->setKeywords("Excel Sheet")->setCategory("Me");

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    
    // Add column headers and make them bold
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('argb' => '000000'),
            ),
        ),
    );

    $univcode = $aobj_context->mobj_data["univcode"];  
    $rformat = $aobj_context->mobj_data["Screentype"];     
    $fcollfrm = $aobj_context->mobj_data["cntr_from"];  
    $fcollto = $aobj_context->mobj_data["cntr_end"];  
    $fdegfrm = $aobj_context->mobj_data["degree_from"];  
    $fdegto = $aobj_context->mobj_data["degree_to"];  
    $exmrange = $aobj_context->mobj_data["examno_from"];  
    $deggrp = $aobj_context->mobj_data["Degree"];  
    $rtype = $aobj_context->mobj_data["ReportType"];   
    $rftype = $aobj_context->mobj_data["rftype"];   
    $count = "";

    $alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 
    'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC',
    'AD', 'AF', 'AE', 'AF', 'AG', 'AH'
  ];
  $j=4;
  $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
  $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setSize(12);
  $objPHPExcel->getActiveSheet()->freezePane('A2');
  $objPHPExcel->getActiveSheet()
      ->setCellValue('A1', 'Sl. No.')
      ->setCellValue('B1', 'College Code')
      ->setCellValue('C1', 'College Name')
      ->setCellValue('D1', 'Degree Code')
  ;
  $query = "select distinct ffeecode from appstudfee";
  $result = $aobj_context->pobj_db->GetAll($query);

  foreach($result as $k=>$value){
    $objPHPExcel->getActiveSheet()
    ->setCellValue($alpha[$j].'1', $value['ffeecode'])->getColumnDimension($alpha[$j])->setwidth(20);
    $count .= "sum(if(sf.ffeecode = '{$value['ffeecode']}',sf.famount,0)) as sum{$k},";
    $j++;
  }

    $objPHPExcel->getActiveSheet()->getStyle('A1:'.$alpha[$j-1].'1')->applyFromArray($styleArray);
    // $objPHPExcel->getActiveSheet()->getColumnDimension('G1')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(45);
    $objPHPExcel->getActiveSheet()->getStyle('A1:'.$alpha[$j-1].'1')->getAlignment()->setWrapText(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1:'.$alpha[$j-1].'1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->getStyle('A1:'.$alpha[$j-1].'1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
   
    $count=rtrim($count,", ");

    $query = "select concat(c.fcollname,', Const.,',c.ftown) as fcollname,
    c.fcollcode,sf.fdegree,sf.ffeecode,
    {$count}
    from appstudfee sf
    inner join college c on c.fcollcode=sf.fcollcode 
    inner join degree d on d.fdegree=sf.fdegree and d.fexamno=sf.fexamno and sf.fcollcode=c.fcollcode
    inner join appcandsum cs on sf.fdegree=cs.fdegree and sf.fcollcode=cs.fcollcode
    and cs.fexamno = sf.fexamno and sf.appno=cs.appno and sf.fregno=cs.fregno
    where sf.fdegree between '{$fdegfrm}' and '{$fdegto}' and
    sf.fcollcode between '{$fcollfrm}' and '{$fcollto}' and
    cs.fpaymentstatus='success' and d.fdeggrp='{$deggrp}'and ifnull(cs.ftotalfee,'')<>''
    group by sf.fcollcode,sf.fdegree
    order by sf.fcollcode,sf.fdegree,sf.ffeecode";
    $result1 = $aobj_context->pobj_db->GetAll($query);  
    foreach ($result1 as $key => $value) {
      $slNo = $key + 2;
      $j=4;
      $objPHPExcel->getActiveSheet()->setCellValue('A' . $slNo, $slNo - 1)->getColumnDimension('A')->setwidth(5);
      $objPHPExcel->getActiveSheet()->setCellValue('B' . $slNo, $value['fcollcode'])->getColumnDimension('B')->setwidth(8.43);
      $objPHPExcel->getActiveSheet()->setCellValue('C' . $slNo, $value['fcollname'])->getColumnDimension('C')->setwidth(50);
      $objPHPExcel->getActiveSheet()->setCellValue('D' . $slNo, $value['fdegree'])->getColumnDimension('D')->setwidth(8.43);

      foreach($result as $k=>$v){
        $objPHPExcel->getActiveSheet()->setCellValue($alpha[$j].$slNo, moneyFormatIndia((int)$value['sum'.$k]))
        ->getColumnDimension($alpha[$j])->setwidth(40);
        $objPHPExcel->getActiveSheet()->getStyle($alpha[$j]. $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle($alpha[$j] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $j++;
      }

      // $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setwidth(12);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':'.$alpha[$j-1] . $slNo)->applyFromArray($styleArray);
      
      //->setWrapText(true);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':'.$alpha[$j-1] . $slNo)->getAlignment()->setWrapText(true);

      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':B' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':B' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->getStyle('D' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('D' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':'.$alpha[$j-1] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':'.$alpha[$j-1] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-1]. $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-1] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-2]. $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-2] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-3]. $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
    //   $objPHPExcel->getActiveSheet()->getStyle($alpha[$j-3] . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    }
    $objPHPExcel->getActiveSheet()->setTitle($fileName);
    $objPHPExcel->getActiveSheet()->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
    
    $get_coll_name = "select FUNIVNAME as 'FUNIVNAME',FUNIVCODE,
    FUNIVADD1 as 'state', pdf_logo_path,
    ifnull(FEXAMAPPREQ,'F') as FEXAMAPPREQ From control";

    $lobj_get_coll_name = $aobj_context->pobj_db->GetRow($get_coll_name);

    // $deggrp = $aobj_context->mobj_data["dgp"];
    // $query = "select distinct concat(fexamdate,' ',' Examination') as fexamdate 
    // from deggrp where fdeggrp = '{$deggrp}'";
    // $results = $aobj_context->pobj_db->GetRow($query);

    $aobj_context->FUNIVNAME = $lobj_get_coll_name['FUNIVNAME'];
    $aobj_context->s_state = $lobj_get_coll_name['state'];
    $aobj_context->pdf_logo_path = $lobj_get_coll_name['pdf_logo_path'];
    $aobj_context->FUNIVCODE = $lobj_get_coll_name['FUNIVCODE'];    
    // die();

    // $objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($aobj_context->main_src.'img/'.$aobj_context->FUNIVCODE.'_logo.jpg', PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H&"-,Bold"&16' . $aobj_context->FUNIVNAME . "\n" . '&12' . $rtype);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H'.$deggrp);

    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&RPage &P of &N');

    getheaders($objPHPExcel, $fileName);
}


function moneyFormatIndia($num)
{
    $explrestunits = "";
    if (strlen($num) > 3) {
        $lastthree = substr($num, strlen($num) - 3, strlen($num));
        $restunits = substr($num, 0, strlen($num) - 3); // extracts the last three digits
        $restunits = (strlen($restunits) % 2 == 1) ? "0" . $restunits : $restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
        $expunit = str_split($restunits, 2);
        for ($i = 0; $i < sizeof($expunit); $i++) {
            // creates each of the 2's group and adds a comma to the end
            if ($i == 0) {
                $explrestunits .= (int)$expunit[$i] . ","; // if is first value , convert into integer
            } else {
                $explrestunits .= $expunit[$i] . ",";
            }
        }
        $thecash = $explrestunits . $lastthree;
    } else {
        $thecash = $num;
    }
    return $thecash; // writes the final format where $currency is the currency symbol.
}
?>