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

		$query = "Select le.employee_id,
	 				le.employee_name,
					lcs.support_id,
					lcs.support_date,
					lcs.support_stime,
					lcs.support_etime,
					lc.customer_orgname
			 FROM
			 	lms_employeemaster le,
				lms_customersupport lcs,
				lms_customer lc 
			WHERE
			le.employee_id=lcs.createdby
			AND lcs.customer_id=lc.customer_id ";

		if ($employeehidden != "") {
			$query .= "AND le.employee_id='" . $employeehidden . "'";
		}
		if ($startdate != "From") {
			$startdate = DateConversion($startdate, "Y-m-d", "d/m/Y");
			$query .= " AND lcs.support_date >= '$startdate' ";
		}

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



		ob_start();
		$objSupportExpencsesMgmt = new SupportExpencsesMgmt();
		$sno = 1;
		$totalCost = 0;
		$out = dbQuery($query);
		if (dbRows($out) > 0) {
			?>
			<h1>
				<b>Employee Name:</b><?php print $_REQUEST['emp_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="2%"><b>Sr No</b></td>
					<td align="center" width="20%"><b>Customer Name</b></td>
					<td align="center" width="9%"><b>Date</b></td>
					<td align="center" width="8%"><b>Start Time</b></td>
					<td align="center" width="8%"><b>End Time</td>
					<?php
					if ($_POST['expenses'] != "All") { ?>

						<td align="center" width="10%"><b><?php echo $_POST['expenses'] ?></b></td>


					<?php } else { ?>

						<td align="center" width="8%"><b>Auto</b></td>
						<td align="center" width="8%"><b>Bus</td>
						<td align="center" width="8%"><b>Food</b></td>
						<td align="center" width="8%"><b>Petrol</td>
						<td align="center" width="8%"><b>Train</b></td>
						<td align="center" width="8%"><b>Stay</b></td>

					<?php } ?>

				</tr>
				<?php
				while ($row = dbArray($out)) {
					$cost = 0;
					$auto = 0;
					$food = 0;
					$petrol = 0;
					$train = 0;
					$stay = 0;


					// print_r($row);
					?>
					<tr>
						<td align="center" width="3%"><?php print $sno; ?></td>
						<td align="center" width="20%"><?php print $row['customer_orgname']; ?></td>
						<td align="center" width="9%"><?php print $row['support_date']; ?></td>
						<td align="center" width="8%"><?php print $row['support_stime']; ?></td>
						<td align="center" width="8%"><?php print $row['support_etime']; ?></td>
						<?php
						if ($_POST['expenses'] != "All") {
							$cost = $objSupportExpencsesMgmt->getcost($row['support_id'], $_POST['expenses']);
							?>
							<td align="center" width="10%"><b><?php echo $cost ?></b></td>

							<?php
							$totalCost += $cost;
						} else {
							$auto = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Auto');
							$bus = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Bus');
							$food = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Food');
							$petrol = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Petrol');
							$train = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Train');
							$stay = $objSupportExpencsesMgmt->getcost($row['support_id'], 'Stay');
							?>


							<td align="center" width="8%"><b><?php echo $auto; ?></b></td>
							<td align="center" width="8%"><b><?php echo $bus; ?></b></td>
							<td align="center" width="8%"><b><?php echo $food; ?></b></td>
							<td align="center" width="8%"><b><?php echo $petrol; ?></b></td>
							<td align="center" width="8%"><b><?php echo $train ?></b></td>
							<td align="center" width="8%"><b><?php echo $stay ?></b></td>
							<?php

							$totalauto += $auto;
							$totalbus += $bus;
							$totalfood += $food;
							$totalpetrol += $petrol;
							$totaltrain += $train;
							$totalstay += $stay;
						} ?>
						<?php $sno++;

				} ?>
				<tr>
					<td colspan="5" align="right"><b>Total Expenses</b></td>
					<?php
					if ($_POST['expenses'] != "All") { ?>
						<td align="center" width="20%"><b><?php echo $totalCost; ?></b></td>
					<?php } else { ?>
						<td align="center" width="8%"><b><?php echo number_format($totalauto, 2); ?></b></td>
						<td align="center" width="8%"><b><?php echo number_format($totalbus, 2); ?></b></td>
						<td align="center" width="8%"><b><?php echo number_format($totalfood, 2); ?></b></td>
						<td align="center" width="8%"><b><?php echo number_format($totalpetrol, 2); ?></b></td>
						<td align="center" width="8%"><b><?php echo number_format($totaltrain, 2); ?></b></td>
						<td align="center" width="8%"><b><?php echo number_format($totalstay, 2); ?></b></td>

					<?php } ?>

				</tr>
			</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";
	}
	?>