<?php require "_header.php";
error_reporting(1); ?>
<div id="main-report" align="center">
	<center>
		<h4>Customer Support Report</h4>
	</center>
	<?php
	$startdate = Escape($_REQUEST["startdate"]);
	$enddate = Escape($_REQUEST["enddate"]);
	$customer_idhedden = Escape($_REQUEST["customer_idhedden"]);
	// $query = "";
	
	if ($customer_idhedden == "") {
		?>
		<script language="javascript" type="text/javascript">
			location.href = 'report-from-customer-suppot.php';
		</script>
		<?php
	} elseif ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {

		$query = "Select lc.*,le.*
		  FROM
			lms_customersupport lc,
			lms_employeemaster  le
		  WHERE 
			le.employee_id=lc.createdby ";

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

			$query .= " AND lc.support_date >= '$startdate' ";
		}

		if ($enddate != "To") {
			$enddate = DateConversion($enddate, "Y-m-d", "d/m/Y");
			$query .= " AND lc.support_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>Support Given By</b></td>
					<td align="center" width="5%"><b>Date</b></td>
					<td align="center" width="5%"><b>Start Time</b></td>
					<td align="center" width="5%"><b>End Time</td>
					<td align="center" width="20%"><b>Work</b></td>
					<td align="center" width="20%"><b>Pendding</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['support_date']); ?></td>
						<td align="center" width="5%"><?php print $row['support_stime']; ?></td>
						<td align="center" width="5%"><?php print $row['support_etime']; ?></td>
						<td align="left" width="20%"><?php print $row['support_work']; ?></td>
						<td align="left" width="20%"><?php print $row['support_pending']; ?></td>



						<?php $sno++;
				} ?>
			</table>
			<?php
			$HtmlCode = ob_get_contents();
			ob_end_flush();

			$HtmlUrl = "report-form-customer-support" . $_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";
	}
	?>