<?php

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

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

$excel->setActiveSheetIndex()
->setCellValue("A1","Product")
->setCellValue("B1","Opening Qty")
->setCellValue("C1","Sales Qty")
->setCellValue("D1","Balance Qty");

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

$row_count=2;

$qury=mysqli_query($conn,"SELECT *  FROM mobiletemporarycart INNER JOIN mobileproducts ON mobileproducts.prid=mobiletemporarycart.proid GROUP BY mobileproducts.prid");
while($resalt=mysqli_fetch_array($qury)){

$op_qty = $resalt["qty"];
$pro_qty = $resalt["pro_qty"];
$blance_qty = $op_qty - $pro_qty;

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['proname'])
->setCellValue("B".$row_count,$resalt['qty'])
->setCellValue("C".$row_count,$resalt['pro_qty'])
->setCellValue("D".$row_count,$blance_qty);
$row_count++;

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

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

?>