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 : 18.191.67.90
Current Path : /var/www/html/oums/src/ |
| Current File : /var/www/html/oums/src/expense_report_statement_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 = "";
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");
$mysql = "SET SESSION group_concat_max_len = 1000000;";
$myres = mysqli_query($mycon, $mysql);
//expense summary start here
$myqry = "";
if ($type_id != "ADMIN" || $type_id != "CHIEF") {
$myqry = " ex.femplcode like '$_POST[empl_code]' ";
} else {
$myqry = " ex.femplcode like '$empl_id' ";
}
echo $mysqlx = "select ex.femplcode,femplname,concat('`',em.facntnumb) as facntnumb,em.fifsccode,
date_format('$_POST[expn_mnth]-01','%Y-%m') as fexpnmnth,
date_format('$_POST[expn_mnth]-01','%M %Y') as fdispmnth,
sum(case when facnttype='PAYMENT' and fexpndate<'$_POST[expn_mnth]-01' then ifnull(fexpnamnt,0) else 0 end) -
sum(case when facnttype='RECEIPT' and fexpndate<'$_POST[expn_mnth]-01' then ifnull(fexpnamnt,0) else 0 end) as fopenbaln,
sum(case when facnttype='PAYMENT' and date_format(fexpndate,'%Y-%m') = '$_POST[expn_mnth]' then ifnull(fexpnamnt,0) else 0 end) as fmnthpayt,
sum(case when facnttype='RECEIPT' and date_format(fexpndate,'%Y-%m') = '$_POST[expn_mnth]' then ifnull(fexpnamnt,0) else 0 end) as fmnthrecp,
sum(case when facnttype='PAYMENT' then ifnull(fexpnamnt,0) else 0 end) as ftotlpayt,
sum(case when facnttype='RECEIPT' then ifnull(fexpnamnt,0) else 0 end) as ftotlrecp,
sum(case when facnttype='PAYMENT' then ifnull(fexpnamnt,0) else 0 end) -
sum(case when facnttype='RECEIPT' then ifnull(fexpnamnt,0) else 0 end) as ftotlbaln,
ifnull(fadvnamnt,0) as fadvnamnt
from expenses ex
inner join masempl em on ex.femplcode = em.femplcode
left join (select sum(ifnull(fadvnamnt,0)) as fadvnamnt,femplcode,fadvndate from expenses_advance
where date_format(fadvndate,'%Y-%m')=date_format(date_add('$_POST[expn_mnth]-01',interval 1 month),'%Y-%m') group by femplcode) ea
on ex.femplcode = ea.femplcode and date_format(fadvndate,'%Y-%m')=date_format(date_add('$_POST[expn_mnth]-01',interval 1 month),'%Y-%m')
where " . $myqry . " and ex.fexpndate<date_format(date_add('$_POST[expn_mnth]-01',interval 1 month),'%Y-%m')
group by ex.femplcode having ftotlbaln + fadvnamnt<>0
order by femplname;";
$myresx = mysqli_query($mycon, $mysqlx);
$i = 1;
$empl_code = "";
$ShtNo = 0;
while ($myrowx = mysqli_fetch_object($myresx)) {
if ($empl_code == "") {
$expn_mnth = $myrowx->fexpnmnth;
$disp_mnth = $myrowx->fdispmnth;
$objPHPExcel->setActiveSheetIndexByName('Worksheet');
$objPHPExcel->getActiveSheet()->setTitle('Expense Summary');
$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()->getPageMargins()->setTop(1.0);
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.5);
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(1.0);
$objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
$objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
$objPHPExcel->getActiveSheet()->setShowGridlines(true);
// $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HMonthly Expense Statment');
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . '&CPage &P of &N');
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(16);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(18);
$objPHPExcel->getActiveSheet()->mergeCells('A1:J1');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A1', 'Expenses Summary - ' . $disp_mnth);
$objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getAlignment()->setHorizontal('center')->setVertical('center');
$i = 2;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 'Sl. No.')
->setCellValue('B' . $i, 'Employee Name')
->setCellValue('C' . $i, 'Open Balance')
->setCellValue('D' . $i, 'Expenses Incurred')
->setCellValue('E' . $i, 'Amount Received')
->setCellValue('F' . $i, 'Closing Balance')
->setCellValue('G' . $i, 'Future Expenses')
->setCellValue('H' . $i, 'Advance Required')
->setCellValue('I' . $i, 'Account No')
->setCellValue('J' . $i, 'IFSC');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A1:J2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A1:J2')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->freezePane('A3');
$i = 3;
}
$empl_code = $myrowx->femplcode;
$empl_name = $myrowx->femplname;
$acnt_numb = $myrowx->facntnumb;
$ifsc_code = $myrowx->fifsccode;
$totl_recp = $myrowx->fmnthrecp;
$totl_payt = $myrowx->fmnthpayt;
$advn_amnt = $myrowx->fadvnamnt;
$open_baln = $myrowx->fopenbaln;
$totl_baln = $myrowx->ftotlbaln;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, $i - 2)
->setCellValue('B' . $i, $empl_code . ' - ' . $empl_name)
->setCellValue('C' . $i, $open_baln)
->setCellValue('D' . $i, $totl_payt)
->setCellValue('E' . $i, $totl_recp)
->setCellValue('F' . $i, $totl_baln)
->setCellValue('G' . $i, $advn_amnt)
->setCellValue('H' . $i, '=ceiling(if(F' . $i . '+G' . $i . '>0,F' . $i . '+G' . $i . ',0),2000)')
->setCellValue('I' . $i, $acnt_numb)
->setCellValue('J' . $i, $ifsc_code);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
// $objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
// $objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
// $objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
// $objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
// $objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
// $objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
// $objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
// $objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
// $objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
// $objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':J' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
$i++;
}
//end of summary sheet
//start of individual expense report
$i = 1;
$empl_code = "";
$ShtNo = 0;
$myqry = "";
if ($type_id == "ADMIN") {
$myqry = " ";
} else {
$myqry = " and ex.femplcode = '$empl_id' ";
}
$mysql = "select
date_format(fexpndate,'%Y-%m') as fexpnmnth,
date_format(fexpndate,'%M %Y') as fdispmnth,
date_format(ex.fupdttime,'%d/%m/%Y') as fsystdate,
date_format(ex.fexpndate,'%d/%m/%Y') as fexpndate,
ex.femplcode,femplname,ex.fclntcode,cl.fclntshrt,ex.facnttype,hd.fheadtype,ex.fheaddesc,ex.fexpnamnt,ex.fexpnremk
from expenses ex
left join masempl em on ex.femplcode = em.femplcode
left join masclient cl on ex.fclntcode = cl.fclntcode
left join mashead hd on ex.fheaddesc = hd.fheaddesc and ex.facnttype = hd.facnttype
where date_format(fexpndate,'%Y-%m') = '$_POST[expn_mnth]'
" . $myqry . "
order by femplname,fexpndate,ex.fclntcode,fheaddesc;";
$myres = mysqli_query($mycon, $mysql);
while ($myrow = mysqli_fetch_object($myres)) {
if ($empl_code != $myrow->femplcode) {
if ($empl_code != '') {
$expn_last_row = $i - 1;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, '')
->setCellValue('B' . $i, '')
->setCellValue('C' . $i, '')
->setCellValue('D' . $i, '')
->setCellValue('E' . $i, '')
->setCellValue('F' . $i, 'TOTAL')
->setCellValue('G' . $i, '')
->setCellValue('H' . $i, '= SUM(H5: H' . $expn_last_row . ')')
->setCellValue('I' . $i, '= SUM(I5: I' . $expn_last_row . ')')
->setCellValue('J' . $i, '');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':C' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$i++;
$i++;
$mysql4 = "select ex.femplcode,femplname,
date_format(ex.fupdttime,'%d/%m/%Y') as fsystdate,
date_format(ex.fadvndate,'%d/%m/%Y') as fadvndate,
fadvndesc,ifnull(fadvnamnt,0) as fadvnamnt,ex.fclntcode,cl.fclntshrt
from expenses_advance ex
inner join masempl em on ex.femplcode = em.femplcode
left join masclient cl on ex.fclntcode = cl.fclntcode
where ex.femplcode='$empl_code' and date_format(fadvndate,'%Y-%m')=date_format(DATE_ADD('$_POST[expn_mnth]-01',interval 1 month),'%Y-%m');";
$myres4 = mysqli_query($mycon, $mysql4);
while ($myrow4 = mysqli_fetch_object($myres4)) {
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, $i - 5)
->setCellValue('B' . $i, $myrow4->fsystdate)
->setCellValue('C' . $i, $myrow4->fadvndate)
->setCellValue('D' . $i, $myrow4->fclntcode . ' - ' . $myrow4->fclntshrt)
->setCellValue('E' . $i, 'ADVANCE')
->setCellValue('F' . $i, $myrow4->fadvndesc)
->setCellValue('G' . $i, '-')
->setCellValue('H' . $i, '-')
->setCellValue('I' . $i, '-')
->setCellValue('J' . $i, $myrow4->fadvnamnt + 0);
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':C' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$i++;
}
$advn_frst_row = $expn_last_row + 3;
$advn_last_row = $i - 1;
if (($advn_last_row - $advn_frst_row) > 0) {
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, '')
->setCellValue('B' . $i, '')
->setCellValue('C' . $i, '')
->setCellValue('D' . $i, '')
->setCellValue('E' . $i, '')
->setCellValue('F' . $i, 'TOTAL')
->setCellValue('G' . $i, '')
->setCellValue('H' . $i, '-')
->setCellValue('I' . $i, '-')
->setCellValue('J' . $i, '= SUM(J' . $advn_frst_row . ': J' . $advn_last_row . ')');
}
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':C' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
}
$expn_mnth = $myrow->fexpnmnth;
$disp_mnth = $myrow->fdispmnth;
$empl_code = $myrow->femplcode;
$empl_name = $myrow->femplname;
//Create sheet for expense display
$ShtNo++;
$objPHPExcel->createSheet($ShtNo);
$objPHPExcel->setActiveSheetIndex($ShtNo);
$objPHPExcel->getActiveSheet()->setTitle($empl_code . '-' . $empl_name);
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 3);
$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(10);
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop(1.0);
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.5);
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(1.0);
$objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
$objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
$objPHPExcel->getActiveSheet()->setShowGridlines(true);
// $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HMonthly Expense Statment');
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . '&CPage &P of &N');
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(35);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
$objPHPExcel->getActiveSheet()->mergeCells('A1:J1');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A1', 'Expense Statement for the period ' . $disp_mnth);
$objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->mergeCells('A2:B2');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A2', 'Incharge Name');
$objPHPExcel->getActiveSheet()->mergeCells('C2:F2');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('C2', '[' . $empl_code . '] ' . $empl_name);
$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->mergeCells('G2:H2');
$objPHPExcel->getActiveSheet()->mergeCells('I2:J2');
//advance amount calculations
$advn_amnt = 0;
$mysql1 = "select ex.femplcode,sum(ifnull(fadvnamnt,0)) as fadvnamnt
from expenses_advance ex
inner join masempl em on ex.femplcode = em.femplcode
where ex.femplcode ='$empl_code' and date_format(fadvndate,'%Y-%m')=date_format(DATE_ADD('$_POST[expn_mnth]-01',interval 1 month),'%Y-%m')";
$myres1 = mysqli_query($mycon, $mysql1);
while ($myrow1 = mysqli_fetch_assoc($myres1)) {
$advn_amnt = $myrow1['fadvnamnt'] + 0;
}
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('G2', 'Required for Next Month');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('I2', $advn_amnt);
$objPHPExcel->getActiveSheet()->getStyle('G2:I2')->getAlignment()->setHorizontal('center')->setVertical('center');
$i = 3;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 'Sl. No.')
->setCellValue('B' . $i, 'Date')
->setCellValue('C' . $i, 'Expense Date')
->setCellValue('D' . $i, 'Client Code')
->setCellValue('E' . $i, 'Expense Head')
->setCellValue('F' . $i, 'Expense Desc')
->setCellValue('G' . $i, 'Remarks')
->setCellValue('H' . $i, 'Expense')
->setCellValue('I' . $i, 'Received')
->setCellValue('J' . $i, 'Balance');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A1:J3')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A3:J3')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->freezePane('A4');
//previous balance calculations
$prev_recp = 0;
$prev_payt = 0;
$blnc_amnt = 0;
$mysql2 = "select
sum(case when facnttype='payment' and date_format(fexpndate,'%Y-%m')=date_format(DATE_ADD('$_POST[expn_mnth]-01',interval -1 month),'%Y-%m') then fexpnamnt end) as fcurrpayt,
sum(case when facnttype='receipt' and date_format(fexpndate,'%Y-%m')=date_format(DATE_ADD('$_POST[expn_mnth]-01',interval -1 month),'%Y-%m') then fexpnamnt end) as fcurrrecp,
sum(case when facnttype='payment' and fexpndate < str_to_date('$expn_mnth','%Y-%m-%d') then fexpnamnt end) as fprevpayt,
sum(case when facnttype='receipt' and fexpndate < str_to_date('$expn_mnth','%Y-%m-%d') then fexpnamnt end) as fprevrecp,
sum(case when facnttype='payment' and fexpndate < str_to_date('$expn_mnth','%Y-%m-%d') then fexpnamnt end) -
sum(case when facnttype='receipt' and fexpndate < str_to_date('$expn_mnth','%Y-%m-%d') then fexpnamnt end) as fprevblnc
from expenses ex
inner join masempl em on ex.femplcode = em.femplcode
where ex.femplcode like '$empl_code';";
$myres2 = mysqli_query($mycon, $mysql2);
while ($myrow2 = mysqli_fetch_assoc($myres2)) {
$curr_recp = $myrow2['fcurrrecp'] + 0;
$curr_payt = $myrow2['fcurrpayt'] + 0;
$prev_recp = $myrow2['fprevrecp'] + 0;
$prev_payt = $myrow2['fprevpayt'] + 0;
$blnc_amnt = $myrow2['fprevblnc'] + 0;
}
$i = 4;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 1)
->setCellValue('B' . $i, "-")
->setCellValue('C' . $i, "-")
->setCellValue('D' . $i, "-")
->setCellValue('E' . $i, "-")
->setCellValue('F' . $i, "Opening Balance")
->setCellValue('G' . $i, "")
->setCellValue('H' . $i, $curr_payt)
->setCellValue('I' . $i, $curr_recp)
->setCellValue('J' . $i, $blnc_amnt);
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':C' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$i++;
}
//Display expense for each employee
$empl_code = $myrow->femplcode;
$recp_amnt = 0;
$payt_amnt = 0;
$recp_amnt = $myrow->facnttype == 'RECEIPT' ? $myrow->fexpnamnt : 0;
$payt_amnt = $myrow->facnttype == 'PAYMENT' ? $myrow->fexpnamnt : 0;
$blnc_amnt = $blnc_amnt - $recp_amnt + $payt_amnt;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, $i - 3)
->setCellValue('B' . $i, $myrow->fsystdate)
->setCellValue('C' . $i, $myrow->fexpndate)
->setCellValue('D' . $i, $myrow->fclntcode . ' - ' . $myrow->fclntshrt)
->setCellValue('E' . $i, $myrow->fheadtype)
->setCellValue('F' . $i, $myrow->fheaddesc)
->setCellValue('G' . $i, $myrow->fexpnremk)
->setCellValue('H' . $i, $payt_amnt + 0)
->setCellValue('I' . $i, $recp_amnt + 0)
->setCellValue('J' . $i, $blnc_amnt + 0);
$objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':A' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('B' . $i . ':B' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('C' . $i . ':C' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('I' . $i . ':I' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getAlignment()->setHorizontal('right')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('J' . $i . ':J' . $i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
$i++;
}
$objPHPExcel->setActiveSheetIndex('0');
$file_name = "expense_statement_monthly_" . $expn_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;
}
}
function get_advance_details()
{
}
function get_expense_details()
{
}
|