<?php session_start();

	include_once ("../../functions/init.php"); 
	include_once ($thisUrl."adm1n/functions/access.php");
	include_once ($thisUrl."adm1n/functions/koneksi.php");
	include_once ($thisUrl."functions/indonesian_date.php");
	include_once ($thisUrl."adm1n/functions/getUrl.php");
	include_once ($thisUrl."adm1n/functions/php_functions.php");
	include_once ($thisUrl."adm1n/functions/request_data.php");

	$laporan  = (isset($_POST["laporan"]) ? $_POST["laporan"] : null);
	$fileName = str_replace(".php", ".xlsx", date("mdY_hms_").$laporan);

	require_once("vendor/autoload.php"); 
	use PhpOffice\PhpSpreadsheet\Spreadsheet;
	use PhpOffice\PhpSpreadsheet\IOFactory;
	
	$spreadsheet = new Spreadsheet();
	
	//Specify the properties for this document
	$spreadsheet->getProperties()
		->setTitle('Trade Expo Indonesia')
		->setSubject('TEI2019')
		->setDescription('Laporan Kontak Dagang')
		->setCreator('Trade Expo Indonesia')
		->setLastModifiedBy('Trade Expo Indonesia');
	
	//Adding data to the excel sheet
	$spreadsheet->setActiveSheetIndex(0)
		->setCellValue('A1', 'Tjhun')
		->setCellValue('A2', 'Khu')
		->setCellValue('A3', 'Rules')
		->setCellValue('A4', 'by')
		->setCellValue('A5', 'example');
	
	$spreadsheet->getActiveSheet()
		->setCellValue('B1', "Ini")
		->setCellValue('B2', "Adalah")
		->setCellValue('B3', "Contoh")
		->setCellValue('B4', "Laporan")
		->setCellValue('B5', "Excell terbaru")
		->setCellValue('B6', "on")
		->setCellValue('B7', "TEI 2019");
	
	
	$spreadsheet->getActiveSheet()
		->setCellValue('C1', 1052)
		->setCellValue('C2', 0.5)
		->setCellValue('C3', 5215)
		->setCellValue('C4', 4741)
		->setCellValue('C5', 5255);
	
	$spreadsheet->getActiveSheet()
		->setCellValue('C6', '=SUM(C1:C5)');
	$spreadsheet->getActiveSheet()
		->getStyle("C6")->getFont()
		->setBold(true);
	
	if (!file_exists("c:/kd22019")) {
		mkdir("c:/kd22019");
	}
	
	$writer =  IOFactory::createWriter($spreadsheet, "Xlsx"); //Xls is also possible
	$writer -> save('generated/'.$fileName);
	
	
	$action 	= (isset($_POST["action"]) ? $_POST["action"] : null);
	$date_start = (isset($_POST["data_start"]) ? $_POST["data_start"] : null);
	$date_end 	= (isset($_POST["data_end"]) ? $_POST["data_end"] : null);
	$remark 	= (isset($_POST["remark"]) ? $_POST["remark"] : null);
	$pic 		= (isset($_POST["pic"]) ? $_POST["pic"] : null);
	
	$jenis_transaksi = (isset($_POST["jenis_transaksi"]) ? $_POST["jenis_transaksi"] : null);
	if ($jenis_transaksi) {
		$_transaksi = $jenis_transaksi;
		$jenis_transaksi = explode (',',$jenis_transaksi);
	}
	
	echo '
	<form name="theForm" id="theForm" class="form" action="'.$thisPage.'adm1n/pages/laporan-transaksi/" method="post">
		<input type="hidden" name="action" id="action" value="'.$action.'" />
		<input type="hidden" name="laporan" id="laporan" value="'.$laporan.'" />
		<input type="hidden" name="data_start" id="date_start" value="'.$date_start.'" />
		<input type="hidden" name="data_end" id="date_end" value="'.$date_end.'" />
		<input type="hidden" name="remark" id="remark" value="'.$remark.'" />
		<input type="hidden" name="remark" id="remark" value="'.$pic.'" />
		<input type="hidden" name="_transaksi" id="_transaksi" value="'.$_transaksi.'" />
	</form>
	
	<script>
		alert("Finish Printing ..");
		document.theForm.submit();
	</script>';
	
	//exit;
?>