<?php require "_header.php"; ?>
<div id="main-report" align="center">
	<center>
		<h4>Support Inquery Report</h4>
	</center>
	<?php

	$customer_idhedden = Escape($_REQUEST["customer_idhedden"]);
	$startdate = Escape($_REQUEST["startdate"]);
	$enddate = Escape($_REQUEST["enddate"]);


	if ($customer_idhedden == "") {
		?>
		<script language="javascript" type="text/javascript">
			location.href = 'report-suppot-inquery.php';
		</script>
		<?php
	} elseif ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {

		$query = "Select ls.*,le.*
		  FROM
			lms_supportinquiry ls,
			lms_employeemaster  le
		  WHERE 
			le.employee_id=ls.createdby ";

		if ($customer_idhedden != "") {
			$query .= "AND ls.customer_id='" . $customer_idhedden . "'";
		}
		if ($startdate != "From") {
			$startdate = DateConversion($startdate, "Y-m-d", "d/m/Y");
			$query .= " AND ls.supportinquiry_date 	 >= '$startdate' ";
		}

		if ($enddate != "To") {
			$enddate = DateConversion($enddate, "Y-m-d", "d/m/Y");
			$query .= " AND ls.supportinquiry_date 	 <= '$enddate' ";
		}

		//		echo	$query; exit;		 
	
		ob_start();
		$sno = 1;
		$out = dbQuery($query);
		if (dbRows($out) > 0) {
			?>
			<h1>
				<b>Customer Name:</b><?php print $_REQUEST['cust_name']; ?><br />
				<?php
				if ($_POST['startdate'] != "From") {
					?>
					<b>Date:</b><?php print $_POST['startdate']; ?> -
				<?php }
				if ($_POST['enddate'] != "To") { ?>
					<?php print $_POST['enddate']; ?>
				<?php } ?>

			</h1>
			<table class="report" id="report-table-lanscap" style="font-size:9px">
				<tr>
					<td align="center" width="3%"><b>Sr No</b></td>
					<td align="center" width="10%"><b>Inquery Taken By</b></td>
					<td align="center" width="5%"><b>Inquery Date</b></td>
					<td align="center" width="5%"><b>Inquery Time</b></td>
					<td align="center" width="20%"><b>Problem</b></td>

				</tr>
				<?php
				$date = new Date();
				while ($row = dbArray($out)) {
					// print_r($row);
					?>
					<tr>
						<td align="center" width="3%"><?php print $sno; ?></td>
						<td align="center" width="10%"><?php print $row['employee_name']; ?></td>
						<td align="center" width="5%"><?php print $date->format("d/M/Y", $row['supportinquiry_date']); ?></td>
						<td align="center" width="5%"><?php print $row['supportinquiry_time']; ?></td>
						<td align="left" width="20%"><?php print $row['supportinquiry_problem']; ?></td>
						<?php $sno++;
				} ?>
			</table>
			<?php
			$HtmlCode = ob_get_contents();
			ob_end_flush();

			$HtmlUrl = "report-support-inquery" . $_SESSION["cUserId"] . ".html";
			$HtmlPath = "report/" . $HtmlUrl;
			createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode);
			?>
			<br />
			<form name="frm" id="frm" action="" method="post">
				<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl; ?>" />
				<input type="button" name="btnPdf" id="btnPdf" value="PRINT" onclick="SetPageAction('PRINT');" />
				<input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onclick="SetPageAction('PDF');" />
				<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onclick="SetPageAction('HTML');" />
				<input type="button" name="btnWord" id="btnWord" value="Create WORD" onclick="SetPageAction('WORD');" />
				<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onclick="SetPageAction('Excel');" />
			</form>
			<script language="javascript" type="text/javascript">
				function SetPageAction(varAction) {
					if (varAction == "PRINT") {
						document.frm.action = "print/create-print.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					if (varAction == "PDF") {
						document.frm.action = "convertpdf/create-pdf.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "HTML") {
						document.frm.action = "<?php echo $HtmlPath; ?>";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "WORD") {
						document.frm.action = "convertword/create-word.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if (varAction == "Excel") {
						document.frm.action = "convertword/create-excel.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
				}
			</script>
			<?php
		} else {
			echo "<b>No Data Found</b>";
		}

	} else {
		echo "Session Expired";
	}
	?>