<?php
require("php_con.php");
require("function.php");

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

$excel->setActiveSheetIndex()
->setCellValue("A1","Product Name")
->setCellValue("B1","Supplier")
->setCellValue("C1","Bar./Pro. ID")
->setCellValue("D1","QTY")
->setCellValue("E1","Value");

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

$row_count=2;
$total_amount=0;
if($_GET['product_supplier']=="all"){
$list_qury=mysqli_query($connation,"SELECT pd.*,sd.supplier_name
FROM product_details pd LEFT JOIN supplier_details sd ON pd.product_supplier=sd.supplier_id
ORDER BY sd.supplier_name");
}
else{
$product_supplier=mysqli_real_escape_string($connation,$_GET['product_supplier']);
$list_qury=mysqli_query($connation,"SELECT pd.*,sd.supplier_name
FROM product_details pd LEFT JOIN supplier_details sd ON pd.product_supplier=sd.supplier_id
WHERE sd.supplier_id='$product_supplier'
ORDER BY sd.supplier_name");
}
while($resalt=mysqli_fetch_array($list_qury)){

$value=price_sale($resalt['product_systemid'])*availbel_qty($resalt['product_systemid']);
	
$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['product_name'])
->setCellValue("B".$row_count,$resalt['supplier_name'])
->setCellValue("C".$row_count,$resalt['product_barcode']."/".$resalt['product_productid'])
->setCellValue("D".$row_count,availbel_qty($resalt['product_systemid']))
->setCellValue("E".$row_count,$value);
$row_count++;
}




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

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