<?php

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

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

$excel->setActiveSheetIndex()
->setCellValue("A1","Order ID")
->setCellValue("B1","Status")
->setCellValue("C1","Customer")
->setCellValue("D1","Total Discount")
->setCellValue("E1","Total Amount")
->setCellValue("F1","Total Bill")
->setCellValue("G1","Pay Type")
->setCellValue("H1","Delivery Cost")
->setCellValue("I1","Date/Time");

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

$row_count=2;

$qury=mysqli_query($conn,"SELECT o.order_id,o.orid,o.pay_option,o.amount,o.paid_amount,o.due_amount,o.card_no,o.customer,o.delivery_cost,o.user_id,o.create_at,o.status ostatus,t.tempid,t.orderid torderid,t.proid,t.pro_price,t.pro_dis,t.pro_qty,t.user_id tuser_id,p.prid,p.proname,p.qtyp.price,p.sellprice FROM mobileorders o INNER JOIN mobiletemporarycart t ON o.order_id=t.orderid INNER JOIN mobileproducts p ON p.prid=t.proid WHERE o.status='0' group BY o.order_id DESC");
while($resalt=mysqli_fetch_array($qury)){

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['orid'])
->setCellValue("B".$row_count,$resalt['ostatus'])
->setCellValue("C".$row_count,$resalt['customer'])
->setCellValue("D".$row_count,$resalt['amount'])
->setCellValue("E".$row_count,$resalt['paid_amount'])
->setCellValue("F".$row_count,$resalt['due_amount'])
->setCellValue("G".$row_count,$resalt['pay_option'])
->setCellValue("H".$row_count,$resalt['delivery_cost'])
->setCellValue("I".$row_count,$resalt['create_at']);
$row_count++;

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

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

?>