<?php

include 'dbconfig.php';
require_once("conn.php");
require_once 'db_connection.php'; 

require("PHPExcel/PHPExcel.php");
$excel= new PHPExcel();

$excel->setActiveSheetIndex()
->setCellValue("A1","Name")
->setCellValue("B1","Email")
->setCellValue("C1","Phone")
->setCellValue("D1","Address")
->setCellValue("E1","Credit")
->setCellValue("F1","Commission");

$excel->getActiveSheet()->getStyle("A1:F1")->getFont()->setBold( true );

$row_count=2;

$qury=mysqli_query($conn,"SELECT * FROM mobilecustomers ORDER BY coid");
while($resalt=mysqli_fetch_array($qury)){


    $cid = $resalt['coid'];
    $qry = mysqli_query($conn, "SELECT SUM(customer_commision) as commision,customer FROM mobileorders WHERE customer='$cid'");
    $rw = mysqli_fetch_array($qry);


	
	

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['cname'])
->setCellValue("B".$row_count,$resalt['cemail'])
->setCellValue("C".$row_count,$resalt['cphone'])
->setCellValue("D".$row_count,$resalt['caddress'])
->setCellValue("E".$row_count,$resalt['ccredit'])
->setCellValue("F".$row_count,$rw['commision']);
$row_count++;

}
	
header('content-Type:Application.openxmlformats-officedocument.spreadsheetml.sheet');
header('content-Disposition:attachment; filename="all_employes_commission_report.xlsx"');
header('cache-Control: max-age=0');

$file=PHPExcel_IOFactory::CreateWriter($excel,'Excel2007');
$file->save('php://output');

?>