<?php
include("dbconnect.php");	
session_start();

$filters=@$_GET['cats'];
$datefrom=@$_GET['from'];
$dateto=@$_GET['to'];
$account=@$_GET['account'];
$academicyear=@$_GET['academicyear'];
$query="SELECT * FROM school_info";
$result=@mysqli_query($con,$query);
$resultArr = @mysqli_fetch_array($result);
$school_name =$resultArr['school_name'];
$logo = $resultArr['logo'];
$email = $resultArr['email'];
$address= 'P.O Box '.$resultArr['address'].'-'. $resultArr['code'].' '. $city = $resultArr['city'];
$city = $resultArr['city'];
$phone = $resultArr['phone'];
$type = $resultArr['type'];
$dat=date('d-m-Y');
//$data6='Receipt Cash Book Between '.$frm.' and '.$to.'';
$preinted='Printed Date :'.strtoupper(date("Y-m-d h:i:sa", time()));
$filename =$datefrom.'-'.$dateto.'-cashbook.xls';
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');

if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');

/** Include PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("cleophas Developer school finance")
->setLastModifiedBy("cleophas-Developer")
->setTitle("Office 2007 XLSX Document")
->setSubject("Office 2007 XLSX Document")
->setDescription("Document for Office 2007 XLSX, generated by school finance.")
->setKeywords("cashbook List Excel 2007")
->setCategory("ledgers List");
$rrrssss=0;

$objPHPExcel->createSheet(0);
$objPHPExcel->setActiveSheetIndex($rrrssss)
->setCellValue('A1', $school_name)
->setCellValue('A2', $address)
->setCellValue('A3', $email)
->setCellValue('A4', "CASHBOOK");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A5', 'Date')
->setCellValue('B5', 'From Whom Received')
->setCellValue('C5', 'Rec No')
->setCellValue('D5', 'Cash')
->setCellValue('E5', 'Bank')
->setCellValue('F5', 'Totals');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$rerer=7;
$llletercolumn="F";
$result = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row = mysqli_fetch_array($result)) {
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].'5', $row['votehead']);
	$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
	$llletercolumn=$roooows['nam'];
	$rerer++;
}
$starrrrt=$rerer;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', '');
$dottteddd=$roooows['nam'];
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setWidth(3);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'Date');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'To Whom Paid');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'VR No');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'Cheque');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'cash');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'Bank');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].'5', 'Totals');
$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
$rerer++;
$result = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id ASC");
While($row = mysqli_fetch_array($result)) {
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].'5', $row['votehead']);
	$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
	$llletercolumn=$roooows['nam'];
	$rerer++;
}
$objPHPExcel->getActiveSheet()->mergeCells('A1:'.$llletercolumn.'1');
$objPHPExcel->getActiveSheet()->mergeCells('A2:'.$llletercolumn.'2');
$objPHPExcel->getActiveSheet()->mergeCells('A3:'.$llletercolumn.'3');
$objPHPExcel->getActiveSheet()->mergeCells('A4:'.$llletercolumn.'4');
$objPHPExcel->getActiveSheet() ->getStyle('A1:A4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A5:'.$llletercolumn.'5')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);
$objPHPExcel->getActiveSheet()->getStyle('A1:'.$llletercolumn.'5')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('#CCFFCC');
$border_style= array('borders' => array('right' => array('style' => 
PHPExcel_Style_Border::BORDER_THICK,'color' => array('argb' => '766f6e'),)));
$objPHPExcel->getActiveSheet();
$objPHPExcel->getActiveSheet()->getStyle("A1:D5")->applyFromArray($border_style);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getStyle('A1:'.$llletercolumn.'5')->getFont()->setBold(true);
$nnow=$datefrom;
$noww=$dateto;
$rr=1;
$rr1=1;
while($nnow<=$noww){

$resul = mysqli_query($con,"select *,(select bankname from banks where banks.id=feepayments.bank) as banknam from feepayments where datepaid='$nnow'");
while($rooowss=mysqli_fetch_array($resul)){
	$ban=strtoupper($rooowss['banknam']);
	$recept=$rooowss['receiptno'];
	$cashamt=0;
	$bankamt=0;
	$totallls=$rooowss['amount_paid'];
	if($ban=="CASH"){
		$cashamt=$rooowss['amount_paid'];
	}
	else{
		$bankamt=$rooowss['amount_paid'];
	}
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.(5+$rr), $rooowss['datepaid'])
->setCellValue('B'.(5+$rr), 'Fee Payment')
->setCellValue('C'.(5+$rr), $rooowss['receiptno'])
->setCellValue('D'.(5+$rr), $cashamt)
->setCellValue('E'.(5+$rr), $bankamt)
->setCellValue('F'.(5+$rr), $totallls);	
$rerer=7;
$resulter = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row444 = mysqli_fetch_array($resulter)){
	$viiid=$row444['id'];
	$valamt=0;
	$nowqamt=mysqli_query($con,"select * from studentsfee where `transaction`='$recept' AND transaction_type='2' and votehead='$viiid'");
	if(mysqli_num_rows($nowqamt)>0){
		$rooamt=mysqli_fetch_array($nowqamt);
		$valamt=$rooamt['amount'];
	}
	else{
		$valamt=0;
	}
	
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].($rr+5), $valamt);
	$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
	//$llletercolumn=$roooows['nam'];
	$rerer++;
}	
	
$rr++;	
}
$resultd= mysqli_query($con,"select * from ccustomerslists where trans_id IN (select id  from customerstrans where transtype='6' and `academicyear`='$academicyear' and datepaid='$nnow') and votehead IN (select id from voteheads WHERE account_id='$account' AND academicyear='$academicyear')");
while($rooowss = @mysqli_fetch_array($resultd)){

$transid=$rooowss['trans_id'];

$resultddfd= mysqli_query($con,"select *,(select bankname from banks where banks.id=customerstrans.banks) as banknam,(select fullname from customers where customers.cusno=customerstrans.cusno) as cusnam from customerstrans where id='$transid'");
$eerwee=mysqli_fetch_array($resultddfd);
$ban=strtoupper($eerwee['banknam']);
$cusname=$eerwee['cusnam'];
	$recept='';
	$cashamt=0;
	$bankamt=0;
	$totallls=0;
$rerer=7;
$resulter = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row444 = mysqli_fetch_array($resulter)){
	$viiid=$row444['id'];
	$valamt=0;
	$nowqamt=mysqli_query($con,"select * from ccustomerslists where `trans_id`='$transid' AND votehead='$viiid'");
	if(mysqli_num_rows($nowqamt)>0){
		$rooamt=mysqli_fetch_array($nowqamt);
		$valamt=$rooamt['amount'];
	}
	else{
		$valamt=0;
	}
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].($rr+5), $valamt);
	$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
	//$llletercolumn=$roooows['nam'];
	$totallls=$totallls+$valamt;
	$rerer++;
}	
if($ban=="CASH"){
		$cashamt=$totallls;
	}
	else{
		$bankamt=$totallls;
	}
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.(5+$rr), $eerwee['datepaid'])
->setCellValue('B'.(5+$rr), $cusname)
->setCellValue('C'.(5+$rr), $recept)
->setCellValue('D'.(5+$rr), $cashamt)
->setCellValue('E'.(5+$rr), $bankamt)
->setCellValue('F'.(5+$rr), $totallls);
	
$rr++;	
}

//$resultR = mysqli_query($con,"SELECT * FROM suppliersinvoice WHERE trans_id='4' AND `academicyear`='$academicyear' and datepaid='$nnow'");
$resultR= mysqli_query($con,"select * from ssupplierslists where vourchorno IN (select vourcherno  from suppliersinvoice where trans_id='4' and `academicyear`='$academicyear' and datepaid='$nnow') and votehead IN (select id from voteheads WHERE account_id='$account' AND academicyear='$academicyear')");
while($rowd = @mysqli_fetch_array($resultR)){
	
$vrno=$rowd['vourchorno'];
$recept=$vrno;
$resultddfd= mysqli_query($con,"select *,(select bankname from banks where banks.id=suppliersinvoice.banks) as banknam,(select suppliername from suppliers where suppliers.supplier_no=suppliersinvoice.supplier) as supnam from suppliersinvoice where vourcherno='$vrno'");
$eerwee=mysqli_fetch_array($resultddfd);
$ban=strtoupper($eerwee['banknam']);
$SUPPNAME=$eerwee['supnam'];
	$cashamt=0;
	$bankamt=0;
	$totallls=0;
$rer44=15;
$re = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($ro = mysqli_fetch_array($re)){
	$rer44++;
}
$resulter = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row444 = mysqli_fetch_array($resulter)){
	$viiid=$row444['id'];
	$valamt=0;
	$nowqamt=mysqli_query($con,"select * from ssupplierslists where `vourchorno`='$vrno' AND votehead='$viiid'");
	if(mysqli_num_rows($nowqamt)>0){
		$rooamt=mysqli_fetch_array($nowqamt);
		$valamt=$rooamt['amount'];
	}
	else{
		$valamt=0;
	}
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].($rr1+5), $valamt);
	$objPHPExcel->getActiveSheet()->getColumnDimension($roooows['nam'])->setAutoSize(true);
	//$llletercolumn=$roooows['nam'];
	$totallls=$totallls+$valamt;
	$rer44++;
}	
if($ban=="CASH"){
	$cashamt=$totallls;
}
else{
	$bankamt=$totallls;
}
$rer44s=8;
$re = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($ro = mysqli_fetch_array($re)){
	$rer44s++;
}
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $eerwee['datepaid']);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $SUPPNAME);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $recept);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $eerwee['code']);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $cashamt);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $bankamt);
$rer44s++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44s'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rr1+5), $totallls);	
	
$rr1++;	
}



$date2=strtotime($nnow);
		$day=date("d",$date2);$paymonaa=date("m",$date2);$yyyearrr=date("Y",$date2);
		if($paymonaa=="01"||$paymonaa=="03"||$paymonaa=="05" || $paymonaa=="07" || $paymonaa=="08" || $paymonaa=="10" || $paymonaa=="12"){
		if($day==31){
			if($paymonaa=="12"){
			$dayy="01";$paymonaa1="01";$yyyearrr1=$yyyearrr+1;
			$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;
			}
			else{
			$dayy="01";$paymonaa1=$paymonaa+1;
			if($paymonaa1>9){$paymonaa1=$paymonaa1;}else{$paymonaa1='0'.$paymonaa1;}
			$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;
			}
		}
		else{
			$dayy=$day+1;
			if($dayy>9){$dayy=$dayy;}else{$dayy='0'.$dayy;}
			$paymonaa1=$paymonaa;$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;	
		}
		}
		elseif($paymonaa=="02"){
			if($yyyearrr%4==0){
				if($day==29){
				$dayy="01";	$paymonaa1=$paymonaa+1;
				if($paymonaa1>9){$paymonaa1=$paymonaa1;}else{$paymonaa1='0'.$paymonaa1;}
				$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;	
				}
				else{
				$dayy=$day+1;
				if($dayy>9){$dayy=$dayy;}else{$dayy='0'.$dayy;}
				$paymonaa1=$paymonaa;$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;
				}
			}
			else{
				if($day==28){
				$dayy="01";$paymonaa1=$paymonaa+1;
				if($paymonaa1>9){$paymonaa1=$paymonaa1;}else{$paymonaa1='0'.$paymonaa1;}
				$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;	
				}
				else{
				$dayy=$day+1;
				if($dayy>9){$dayy=$dayy;}else{$dayy='0'.$dayy;}
				$paymonaa1=$paymonaa;$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;
				}
			}
		}
		else{
			if($day==30){
			$dayy="01";	$paymonaa1=$paymonaa+1;
			if($paymonaa1>9){$paymonaa1=$paymonaa1;}else{$paymonaa1='0'.$paymonaa1;}
			$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;
		}
		else{
			$dayy=$day+1;
			if($dayy>9){$dayy=$dayy;}else{$dayy='0'.$dayy;}
			$paymonaa1=$paymonaa;$yyyearrr1=$yyyearrr;$nnow=$yyyearrr1.'-'.$paymonaa1.'-'.$dayy;	
		}
		}
}
$rer44f=14;
$res = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($rot = mysqli_fetch_array($res)){
	$rer44f++;
}
$res = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($rot = mysqli_fetch_array($res)){
	$rer44f++;
}
$nowquey=mysqli_query($con,"select * from alphabets where id='$rer44f'");
$roooows=mysqli_fetch_array($nowquey);
$lastalpha=$roooows['nam'];
$rrf=0;
if($rr>=$rr1){
$rrf=$rr;	
}
else{
	$rrf=$rr1;
}
if($rrf>0){
	$FFROM1="D";
	$TTTO1='';
	$FFROM2="";
	$TTTO2='';
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.(5+$rrf), '')
->setCellValue('B'.(5+$rrf), '')
->setCellValue('C'.(5+$rrf), '')
->setCellValue('D'.(5+$rrf), "=SUM(D6:D".(4+$rrf).")")
->setCellValue('E'.(5+$rrf), "=SUM(E6:E".(4+$rrf).")")
->setCellValue('F'.(5+$rrf), "=SUM(F6:F".(4+$rrf).")");
$rerer=7;
$resulter = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row444 = mysqli_fetch_array($resulter)){
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].($rrf+5), "=SUM(".$roooows['nam']."6:".$roooows['nam'].(4+$rrf).")");
	$TTTO1=$roooows['nam'];
	$rerer++;
}
$rerer++;
$rerer++;
$rerer++;
$rerer++;
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rrf+5), "=SUM(".$roooows['nam']."6:".$roooows['nam'].(4+$rrf).")");
$FFROM2=$roooows['nam'];
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rrf+5), "=SUM(".$roooows['nam']."6:".$roooows['nam'].(4+$rrf).")");
$rerer++;
$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
$roooows=mysqli_fetch_array($nowquey);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($roooows['nam'].($rrf+5), "=SUM(".$roooows['nam']."6:".$roooows['nam'].(4+$rrf).")");
$rerer++;
$resulter = mysqli_query($con,"select * from voteheads WHERE account_id='$account' AND academicyear='$academicyear' ORDER by id");
While($row444 = mysqli_fetch_array($resulter)){
	$nowquey=mysqli_query($con,"select * from alphabets where id='$rerer'");
	$roooows=mysqli_fetch_array($nowquey);
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue($roooows['nam'].($rrf+5), "=SUM(".$roooows['nam']."6:".$roooows['nam'].(4+$rrf).")");
	$TTTO2=$roooows['nam'];
	$rerer++;
}
$objPHPExcel->getActiveSheet()->getStyle('D6:'.$TTTO1.($rrf+5))
->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
$objPHPExcel->getActiveSheet()->getStyle($FFROM2.'6:'.$TTTO2.($rrf+5))
->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
}
$objPHPExcel->getActiveSheet()->getStyle('A'.($rrf+5).':'.$lastalpha.($rrf+5))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('#CFFFCC');
$objPHPExcel->getActiveSheet()->getStyle('A1:'.$lastalpha.($rrf+5))->getBorders()->applyFromArray(
array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array(
'rgb' => '#000000'
)
)
)
);

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
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, 'Excel5');
$objWriter->save('php://output');
exit;
?>