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.137.214.16
Current Path : /var/www/html/oums/src/ |
| Current File : /var/www/html/oums/src/expense_report_statement_excel - Copy.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);
$myqry = "";
if ($type_id != "ADMIN" || $type_id != "CHIEF") {
$myqry = " and ex.fdeptcode like '$_POST[dept_code]' ";
} else {
$myqry = " and ex.femplcode like '$empl_id' ";
}
$mysql = "select
date_format(fexpndate,'%Y-%m') as fexpnmnth,
date_format(fexpndate,'%M %Y') as fdispmnth,
ex.fdeptcode,dp.fdeptname,dp.fdeptshrt,dp.fdepthead,femplname,
date_format(ex.fupdttime,'%d/%m/%Y') as fsystdate,
date_format(ex.fexpndate,'%d/%m/%Y') as fexpndate,
hd.fheadtype,ex.fheaddesc,fexpnamnt,fexpnremk,fclntcode,ex.facnttype
from expenses ex
left join masdept dp on ex.fdeptcode = dp.fdeptcode
left join mashead hd on ex.fheaddesc = hd.fheaddesc and ex.facnttype = hd.facnttype
left join masempl em on dp.fdepthead = em.femplcode
where date_format(fexpndate,'%Y-%m') = '$_POST[expn_mnth]' " . $myqry . "
order by ex.fdeptcode,fexpndate,fheaddesc";
$myres = mysqli_query($mycon, $mysql);
$i = 1;
$dept_code = "";
$ShtNo = 0;
while ($myrow = mysqli_fetch_object($myres)) {
if ($dept_code != $myrow->fdeptcode) {
$expn_mnth = $myrow->fexpnmnth;
$disp_mnth = $myrow->fdispmnth;
$dept_code = $myrow->fdeptcode;
$dept_name = $myrow->fdeptname;
$dept_shrt = $myrow->fdeptshrt;
$dept_head = $myrow->fdepthead;
$head_name = $myrow->femplname;
//Create sheet for expense display
$ShtNo++;
$objPHPExcel->createSheet($ShtNo);
$objPHPExcel->setActiveSheetIndex($ShtNo);
$objPHPExcel->getActiveSheet()->setTitle($dept_code);
$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(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A1', 'Expense Statement for the period ' . $disp_mnth);
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->mergeCells('A2:B2');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A2', 'Client ');
$objPHPExcel->getActiveSheet()->mergeCells('C2:H2');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('C2', '[' . $dept_code . '] ' . $dept_name);
$objPHPExcel->getActiveSheet()->getStyle('A2:H2')->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->mergeCells('A3:B3');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A3', 'Incharge Name');
$objPHPExcel->getActiveSheet()->mergeCells('C3:E3');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('C3', '[' . $dept_head . '] ' . $head_name);
$objPHPExcel->getActiveSheet()->getStyle('A3:E3')->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->mergeCells('F3:G3');
$advn_amnt = 0;
$mysql1 = "select fdeptcode,sum(fadvnamnt) as fadvnamnt from expenses_advance
where fdeptcode ='$dept_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'];
}
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('F3', 'Advance for Next Month');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('H3', $advn_amnt);
$objPHPExcel->getActiveSheet()->getStyle('F3:H3')->getAlignment()->setHorizontal('center')->setVertical('center');
$i = 4;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 'Sl. No.')
->setCellValue('B' . $i, 'Date')
->setCellValue('C' . $i, 'Expense Date')
->setCellValue('D' . $i, 'Expense Head')
->setCellValue('E' . $i, 'Expense Desc')
->setCellValue('F' . $i, 'Received')
->setCellValue('G' . $i, 'Expense')
->setCellValue('H' . $i, 'Balance');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A1:H4')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A4:H4')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->freezePane('A5');
$prev_recp = 0;
$prev_payt = 0;
$blnc_amnt = 0;
$mysql2 = "select
sum(case when facnttype='receipt' then fexpnamnt end) as fprevrecp,
sum(case when facnttype='payment' then fexpnamnt end) as fprevpayt,
sum(case when facnttype='receipt' then fexpnamnt end)-sum(case when facnttype='payment' then fexpnamnt end) as fprevblnc
from expenses where fdeptcode like '$dept_code' and fexpndate < str_to_date('$expn_mnth','%Y-%m-%d')";
$myres2 = mysqli_query($mycon, $mysql2);
while ($myrow2 = mysqli_fetch_assoc($myres2)) {
$prev_recp = $myrow2['fprevrecp'];
$prev_payt = $myrow2['fprevpayt'];
$blnc_amnt = $myrow2['fprevblnc'];
}
$i = 5;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 1)
->setCellValue('B' . $i, "-")
->setCellValue('C' . $i, "-")
->setCellValue('D' . $i, "-")
->setCellValue('E' . $i, "Opening Balance")
->setCellValue('F' . $i, $prev_recp)
->setCellValue('G' . $i, $prev_payt)
->setCellValue('H' . $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('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$i++;
}
//Display expense for each dept.
$dept_code = $myrow->fdeptcode;
$recp_amnt = 0;
$payt_amnt = 0;
$recp_amnt = $myrow->facnttype == 'RECEIPT' ? $myrow->fexpnamnt : 0;
$payt_amnt = $myrow->facnttype == 'PAYMENT' ? $myrow->fexpnamnt : 0;
$blnc_amnt = ($recp_amnt - $payt_amnt) + $blnc_amnt;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, $i - 4)
->setCellValue('B' . $i, $myrow->fsystdate)
->setCellValue('C' . $i, $myrow->fexpndate)
->setCellValue('D' . $i, $myrow->fheadtype)
->setCellValue('E' . $i, $myrow->fheaddesc . " " . $myrow->fexpnremk)
->setCellValue('F' . $i, $recp_amnt)
->setCellValue('G' . $i, $payt_amnt)
->setCellValue('H' . $i, $blnc_amnt);
$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('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
$i++;
}
//start of advance summary sheet
$myqry = "";
if ($type_id != "ADMIN" || $type_id != "CHIEF") {
$myqry = " and ex.fdeptcode like '$_POST[dept_code]' ";
} else {
$myqry = " and ex.femplcode like '$empl_id' ";
}
$mysqlx = "select
date_format(fexpndate,'%Y-%m') as fexpnmnth,
date_format(fexpndate,'%M %Y') as fdispmnth,
ex.fdeptcode,dp.fdeptname,dp.fdeptshrt,dp.fdepthead,femplname,
sum(case when facnttype='RECEIPT' then fexpnamnt else 0 end) as ftotlrecp,
sum(case when facnttype='PAYMENT' then fexpnamnt else 0 end) as ftotlpayt,
tadvnamnt
from expenses ex
inner join masdept dp on ex.fdeptcode = dp.fdeptcode
left join masempl em on dp.fdepthead = em.femplcode
left join (select sum(ifnull(fadvnamnt,0)) as tadvnamnt, fdeptcode,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 fdeptcode) ea on ex.fdeptcode = ea.fdeptcode and date_format(fadvndate,'%Y-%m')=date_format(date_add('" . $_POST['expn_mnth'] . "-01',interval 1 month),'%Y-%m')
where date_format(fexpndate,'%Y-%m') = '$_POST[expn_mnth]' " . $myqry . "
group by dp.fdepthead";
$myresx = mysqli_query($mycon, $mysqlx);
$i = 1;
$dept_head = "";
$ShtNo = 0;
while ($myrowx = mysqli_fetch_object($myresx)) {
if ($dept_head == "") {
$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(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
$objPHPExcel->setActiveSheetIndex($ShtNo)->setCellValue('A1', 'Expense Summary for the period ' . $disp_mnth);
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getAlignment()->setHorizontal('center')->setVertical('center');
$i = 2;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, 'Sl. No.')
->setCellValue('B' . $i, 'Location')
->setCellValue('C' . $i, 'Incharge Name')
->setCellValue('D' . $i, 'Open Balance')
->setCellValue('E' . $i, 'Received')
->setCellValue('F' . $i, 'Expenses')
->setCellValue('G' . $i, 'Close Balance')
->setCellValue('H' . $i, 'Advance');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A1:H2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A1:H2')->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->freezePane('A3');
$i = 3;
}
$dept_code = $myrowx->fdeptcode;
$dept_name = $myrowx->fdeptname;
$dept_shrt = $myrowx->fdeptshrt;
$dept_head = $myrowx->fdepthead;
$head_name = $myrowx->femplname;
$totl_recp = $myrowx->ftotlrecp;
$totl_payt = $myrowx->ftotlpayt;
$advn_amnt = $myrowx->tadvnamnt;
$open_blnc = 0;
$clse_blnc = 0;
$mysql3 = "select ifnull(sum(case when facnttype='receipt' then fexpnamnt end),0) - ifnull(sum(case when facnttype='payment' then fexpnamnt end),0) as fopenblnc
from expenses
where fdeptcode in (select fdeptcode from masdept where fdepthead = '$dept_head') and fexpndate < str_to_date('$_POST[expn_mnth]','%Y-%m-%d')";
$myres3 = mysqli_query($mycon, $mysql3);
while ($myrow3 = mysqli_fetch_assoc($myres3)) {
$open_blnc = $myrow3['fopenblnc'];
}
$clse_blnc = $open_blnc + $totl_recp - $totl_payt;
$objPHPExcel->setActiveSheetIndex($ShtNo)
->setCellValue('A' . $i, $i - 2)
->setCellValue('B' . $i, '[' . $dept_code . ']' . $dept_shrt)
->setCellValue('C' . $i, '[' . $dept_head . ']' . $head_name)
->setCellValue('D' . $i, $open_blnc)
->setCellValue('E' . $i, $totl_recp)
->setCellValue('F' . $i, $totl_payt)
->setCellValue('G' . $i, $clse_blnc)
->setCellValue('H' . $i, $advn_amnt);
$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 . ':C' . $i)->getAlignment()->setHorizontal('left')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('D' . $i . ':D' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('E' . $i . ':E' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('F' . $i . ':F' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('G' . $i . ':G' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getStyle('H' . $i . ':H' . $i)->getAlignment()->setHorizontal('center')->setVertical('center');
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(25);
$i++;
}
//end of advance summary sheet
$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');
$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;
}
}
|