<?php
include("../php_con.php");
include("../function.php");


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

$excel->setActiveSheetIndex()
->setCellValue("A1","pd_id")
->setCellValue("B1","pd_name")
->setCellValue("C1","pd_name_sinhala")
->setCellValue("D1","pd_category")
->setCellValue("E1","pd_unit")
->setCellValue("F1","pd_sku")
->setCellValue("G1","pd_barcode")
->setCellValue("H1","pd_exp_date")
->setCellValue("I1","pd_buy_price")
->setCellValue("J1","pd_market_price")
->setCellValue("K1","pd_sale_price")
->setCellValue("L1","pd_discount")
->setCellValue("M1","pd_wholesale_price")
->setCellValue("N1","pd_re_order_level")
->setCellValue("O1","pd_description")
->setCellValue("P1","pd_supplier")
->setCellValue("Q1","pd_add_date")
->setCellValue("R1","pd_add_time")
->setCellValue("S1","pd_status")
->setCellValue("T1","pd_stock_maintenance")
->setCellValue("U1","stock")
->setCellValue("V1","category");

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

$row_count=2;
$list_qury=mysqli_query($connation,"SELECT *
FROM product_details pd LEFT JOIN catogary_list cl ON pd.product_catagory=cl.catogary_id
ORDER BY pd.product_id ASC");
while($list_resalt=mysqli_fetch_assoc($list_qury)){
	
$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$list_resalt['product_id'])
->setCellValue("B".$row_count,$list_resalt['product_name'])
->setCellValue("C".$row_count,$list_resalt['product_name_sinhala'])
->setCellValue("D".$row_count,$list_resalt['product_catagory'])
->setCellValue("E".$row_count,"1")
->setCellValue("F".$row_count,$list_resalt['product_barcode'])
->setCellValue("G".$row_count,$list_resalt['product_barcode'])
->setCellValue("H".$row_count,"")
->setCellValue("I".$row_count,price_buy($list_resalt['product_systemid']))
->setCellValue("J".$row_count,price_sale($list_resalt['product_systemid']))
->setCellValue("K".$row_count,price_sale($list_resalt['product_systemid']))
->setCellValue("L".$row_count,"0")
->setCellValue("M".$row_count,"0")
->setCellValue("N".$row_count,"0")
->setCellValue("O".$row_count,"")
->setCellValue("P".$row_count,"1")
->setCellValue("Q".$row_count,"")
->setCellValue("R".$row_count,"")
->setCellValue("S".$row_count,"")
->setCellValue("T".$row_count,"1")
->setCellValue("U".$row_count,"0")
->setCellValue("V".$row_count,$list_resalt['catogary_text']);
$row_count++;
		
}

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

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