<?php require "_header.php"; ?>
<div id="main-report" align="center">
	<center>
		<h4>Customer Support Report Datewise <br />From :
			<?php echo DateConversion($_REQUEST['bill_startdate'], "d-m-Y", "d/m/Y"); ?> TO :
			<?php echo DateConversion($_REQUEST['bill_enddate'], "d-m-Y", "d/m/Y"); ?></h4>
	</center>
	<?php


	if ($_REQUEST['bill_startdate'] == "") {
		?>
		<script language="javascript" type="text/javascript">
			location.href = 'report-cust-support-result.php';
		</script>
		<?php
	} elseif ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
		$header_row_string = "Customer Support Report Datewise  ";
		$total = 0;
		ob_start();

		$query = " SELECT 
				lc.*,lu.user_name,lcm.customer_orgname
				FROM `lms_cust` lc
				INNER JOIN lms_customer lcm
				INNER JOIN lms_usermaster lu
				WHERE 
				lc.customer_id = lcm.customer_id and 
				lc.user_id = lu.user_id and 
				lc.company_id = '" . $_SESSION['cCompany_id'] . "'";

		$bill_startdate = Escape($_REQUEST["bill_startdate"]);
		$bill_enddate = Escape($_REQUEST["bill_enddate"]);
		$hiddendist_code = Escape($_REQUEST["hiddendist_code"]);
		$customer_idhedden = Escape($_REQUEST["customer_idhedden"]);
		$user_id = Escape($_REQUEST["user_idhedden"]);

		// echo $user_id; exit;
	

		if ($bill_startdate != "From") {
			$bill_startdate = DateConversion($bill_startdate, "Y-m-d", "d/m/Y");
			$query .= " AND lc.date1 >= '$bill_startdate' ";
		}
		if ($bill_enddate != "To") {
			$bill_enddate = DateConversion($bill_enddate, "Y-m-d", "d/m/Y");
			$query .= " AND lc.date1 <= '$bill_enddate' ";
		}
		if ($hiddendist_code != "" && $hiddendist_code != "All") {
			$query .= " AND lcm.district_id = '" . $hiddendist_code . "' ";
		}
		if ($customer_idhedden != "") {
			$query .= " AND lc.customer_id = '" . $customer_idhedden . "' ";
		}
		if ($user_id != "") {
			$query .= " AND lc.user_id = '" . $user_id . "' ";
		}

		$query .= " ORDER BY lc.date1";

		/*echo $query;
		   exit;*/
		$res = dbQuery($query);
		if (dbRows($res) > 0) { ?>
			<table width="100%" class="report">
				<tr style="background-color:#CCC">
					<th width="3%" style="text-align:center">Sr.</th>
					<th width="7%" style="text-align:center">Date</th>
					<th width="18%" style="text-align:center">Customer Name</th>
					<th width="7%" style="text-align:center">Status</th>
					<th width="7%" style="text-align:center">Start Date</th>
					<th width="7%" style="text-align:center">Start Time</th>
					<th width="7%" style="text-align:center">End Date</th>
					<th width="7%" style="text-align:center">End Time</th>
					<th width="10%" style="text-align:center">Problem Detail</th>
					<th width="10%" style="text-align:center">Completed Work</th>
					<th width="10%" style="text-align:center">Pending work</th>
					<th width="10%" style="text-align:center">Pending Reason</th>
					<th width="6%" style="text-align:center">User Name</th>
					<th width="5%" style="text-align:center">AssignTo</th>


				</tr>
				<?php
				$sr = 1;
				while ($row1 = dbArray($res)) {
					?>
					<tr style="color:#000">
						<td style="text-align:center"> <?php echo $sr++; ?> </td>
						<td style="text-align:center"><?php echo date("d-m-Y", strtotime($row1['date1'])); ?></td>
						<td style="text-align:left"><?php echo $row1["customer_orgname"]; ?></td>
						<?php if ($row1["status"] == 'Pending') { ?>
							<td style="text-align:center; font-size:14px;color:#F00;"><?php echo $row1["status"]; ?></td>
						<?php } else if ($row1["status"] == 'on work') { ?>
								<td style="text-align:center; font-size:14px;color:BLUE;"><?php echo $row1["status"]; ?></td>
						<?php } else { ?>
								<td style="text-align:center; font-size:14px;color:GREEN;"><?php echo $row1["status"]; ?></td>
						<?php } ?>
						<td style="text-align:center"><?php echo date("d-m-Y", strtotime($row1['support_sdate'])); ?></td>
						<td style="text-align:left"><?php echo $row1["support_timefrom"]; ?></td>
						<td style="text-align:center">
							<?php echo isset($row1['support_edate']) ? date("d-m-Y", strtotime($row1['support_edate'])) : "-"; ?></td>
						<td style="text-align:left"><?php echo $row1["support_timeto"]; ?></td>
						<td style="text-align:left"><?php echo isset($row1["problem_det"]) ? $row1["problem_det"] : "-"; ?></td>
						<td style="text-align:left"><?php echo isset($row1["completed_det"]) ? $row1["completed_det"] : "-"; ?></td>
						<td style="text-align:left"><?php echo isset($row1["pending_work"]) ? $row1["pending_work"] : "-"; ?></td>
						<td style="text-align:left"><?php echo isset($row1["pending_reason"]) ? $row1["pending_reason"] : "-"; ?></td>
						<td style="text-align:center;"><?php echo $row1["user_name"]; ?></td>
						<?php $asign_qry = "SELECT `user_name` as asign_user_name FROM `lms_usermaster` WHERE `user_id` = '" . $row1["assign_user_id"] . "'";
						$asign_res = dbQuery($asign_qry);
						$result_asign = dbArray($asign_res); ?>
						<td style="text-align:center;">
							<?php echo isset($result_asign["asign_user_name"]) ? $result_asign["asign_user_name"] : "-"; ?></td>
					</tr>
				<?php } ?>
			</table>
			<?php

			$HtmlCode = ob_get_contents();
			ob_end_flush();

			$HtmlUrl = "report-cust-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>
			<br />
			<br />
			<?php
		} else {
			echo "<b>No Data Found </b>";
		}
	} else {
		echo "Session Expired";
	}
	?>
</div>
<?php
require "_footer.php"; ?>