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

	if ($_REQUEST['hiddendist_code'] == "") {
		?>
		<script language="javascript" type="text/javascript">
			location.href = 'report-customer-distwise.php';
		</script>
		<?php
	} else if ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
		$header_row_string = "Customer Information Report ";

		$total = 0;

		ob_start();
		$where = "";
		$custName = "SELECT * from lms_customer,lms_designation desg where desg.designation_id = customer_cpdesignation1 AND  company_id='" . $_SESSION['cCompany_id'] . "'";

		$hiddendist_code = Escape($_REQUEST["hiddendist_code"]);
		if ($hiddendist_code != "" && $hiddendist_code != "All") {
			$custName .= " and district_id='" . $hiddendist_code . "'";
		}

		$custName .= " order by customer_id";
		/*echo $custName;
		   exit;*/
		//$invoicid=$invoicid.$where;
		//$invoicid = $invoicid." order by lci.customerinvoice_no";
	
		$custRes = dbQuery($custName);

		if (dbRows($custRes) > 0) { ?>
				<table width="100%" class="report">

					<tr style="background-color:#CCC">
						<th width="5%" style="text-align:center">Sr No.</th>
						<th width="4%" style="text-align:center">Cust Id.</th>
						<th width="30%" style="text-align:center">Customer Name</th>
						<th width="25%" style="text-align:center">Address</th>
						<th width="10%" style="text-align:center">Contact No</th>
						<th width="10%" style="text-align:center">Contact Person</th>
						<th width="5%" style="text-align:center">Designation</th>
						<th width="15%" style="text-align:center">Email Id</th>

					</tr>

				<?php
				$sr = 1;
				while ($row1 = dbArray($custRes)) {
					?>

						<tr>
							<td style="text-align:center"> <?php echo $sr; ?> </td>
							<td style="text-align:center"> <?php echo $row1["customer_id"]; ?> </td>
							<td style="text-align:left"> <?php echo $row1["customer_orgname"]; ?> </td>
							<td style="text-align:left"><?php echo $row1["customer_address"]; ?></td>
							<td style="text-align:center"><?php
							if ($row1['customer_phone1'] != "" && $row1['customer_phone2'] != "") {
								echo $row1["customer_phone1"] . '<br/>' . $row1["customer_phone2"];
							} elseif ($row1['customer_phone1'] != "" && $row1['customer_phone2'] == "")
								echo $row1["customer_phone1"];
							elseif ($row1['customer_phone2'] != "" && $row1['customer_phone1'] == "")
								echo $row1["customer_phone2"];
							else
								echo '-';
							?></td>
							<td style="text-align:center"><?php echo $row1['customer_cpname1'] . "<br/>" . $row1['customer_cpmobile1'] ?>
							</td>
							<td style="text-align:center"><?php echo $row1['designation_name']; ?></td>

							<td width="20%" style="text-align:left"><?php echo $row1["customer_email"]; ?></td>
						</tr>

						<?php
						$sr++;
				}

				?>
				</table>
				<?php

				$HtmlCode = ob_get_contents();
				ob_end_flush();

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