<?php require "_header.php";
include "Numbers/Words.php"; ?>
<div id="main-report" align="center">

	<?php
	/*echo "<pre>";
	print_r($_SESSION);
	exit;*/
	if ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
		$startdate = Escape($_REQUEST["startdate"]);
		$enddate = Escape($_REQUEST["enddate"]);
		$csc_data = $_REQUEST["csc_data"];

		$agencyid = $_SESSION["cCompany_id"];
		$cond = "";

		if ($startdate != "From" && $startdate != "To") {

			$startdate = DateConversion($startdate, "Y-m-d", "d/m/Y");
			$enddate = DateConversion($enddate, "Y-m-d", "d/m/Y");
			$cond .= " AND CAST(invoice_date as Date) >= '$startdate' ";
			$cond .= " AND CAST(invoice_date as DATE) <=  '$enddate' ";
		}

		$qry = " SELECT * from csc_customer as cm,lms_customersupport as cs 
			where 1= 1 and cm.customer_id = cs.customer_id";


		$qry .= $cond;
		$qry .= "";

		$rs = dbQuery($qry);
		$count = dbRows($rs);

		$j = 0;


		ob_start();
		$i = 0;
		$sno = 1;
		if ($csc_data != 'on') {
			?>
			<table class="report" width="100%" align="center" border="1">
				<tr>
					<th>Sr No</th>
					<th>BARCODE</th>
					<th>REF</th>
					<th>City</th>
					<th>Pincode</th>
					<th>Name</th>
					<th>ADD1</th>
					<th>ADD2</th>
					<th>ADD3</th>
					<th>ADDREMAIL</th>
					<th>ADDRMOBILE</th>
					<th>SENDERMOBILE</th>
					<th>WEIGHT</th>
					<th>Date</th>
					<th>Product Name</th>
					<th>Quantity</th>



				</tr>
				<?php
				while ($row = dbArray($rs)) {


					?>
					<tr>
						<td><?php echo $sno++; ?>
						<td><?php echo $row['courier_no']; ?></td>
						<td>&nbsp;</td>
						<td><?php echo $row['district']; ?></td>
						<td><?php echo substr($row['address1'], -6); ?></td>
						<td><?php echo $row['estore_name']; ?></td>
						<td><?php echo $row['vendor_name'] . ", " .$row['address1']; ?></td>
						<td><?php echo $row['district']; ?></td>
						<td><?php echo $row['state']; ?></td>
						<td>&nbsp;</td>
						<td><?php echo $row['estore_phoneno']; ?></td>
						<td>9925293900</td>
						<td>&nbsp;</td>
						<td><?php echo date("d-m-Y", strtotime($row['invoice_date']));
						; ?></td>
						<td><?php echo $row['product_name']; ?></td>
						<td><?php echo $row['quantity']; ?></td>
					</tr>

					<?php
				}


				?>
			</table>
			<?php
		} else {
			?>
			<table class="report" width="100%" align="center" border="1">
				<tr>
					<th>Sr No</th>
					<th>ORDER NUMBER</th>
					<th>AWD NUMBER</th>
					<th>COURIER PARTNER</th>
					<th>TRACKING LINK</th>
					<th>CONTACT PERSON NAME</th>
					<th>CONTACT PERSON NUMBER</th>
					<th>DISPATCH DATE</th>
					<th>ORDER STATUS</th>
				</tr>
				<?php
				while ($row = dbArray($rs)) {


					?>
					<tr>
						<td><?php echo $sno++; ?>
						<td><?php echo $row['order_no']; ?></td>
						<td><?php echo $row['courier_no']; ?></td>
						<?php if ($row['courier_company'] == 'Shree Maruti Courier') {
							?>
							<td>Shree Maruti Courier</td>
							<?php
						} else if ($row['courier_company'] == 'Delhivery') {
							?>
								<td>Delhivery</td>
							<?php
						} else if ($row['courier_company'] == 'Nandan Courier') {
							?>
									<td>Nandan Courier</td>
							<?php
						} else {
							?>
									<td>INDIA POST</td>
							<?php
						}
						?>
						<?php if ($row['courier_company'] == 'Shree Maruti Courier') {
							?>
							<td>www.shreemaruticourier.com</td>
							<?php
						} else if ($row['courier_company'] == 'Delhivery') {
							?>
								<td>https://www.delhivery.com</td>
							<?php
						} else if ($row['courier_company'] == 'Nandan Courier') {
							?>
									<td>https://shreenandancourier.com/</td>
							<?php
						} else {
							?>
									<td>https://www.indiapost.gov.in/MBE/Pages/Content/Speed-Post.aspx</td>
							<?php
						}
						?>
						<td><?php echo $row['estore_name']; ?></td>
						<td><?php echo $row['estore_phoneno']; ?></td>
						<td>&nbsp;</td>
						<td>DISPATCHED</td>

					</tr>

					<?php
				}

				?>
			</table>


			<?php
		}
		$HtmlCode = ob_get_contents();
		ob_end_flush();
		$HtmlUrl = "customerbill-report-" . $_SESSION["eAgencyId"] . ".html";
		$HtmlPath = "report/" . $HtmlUrl;
		createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode, true);
		?>
		<br />
		<br /><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">
			//SetPageAction('PRINT');
			function SetPageAction(varAction) {

				if (varAction == "PRINT") {
					document.frm.action = "print/create-print.php";
					document.frm.target = "_blank";
					document.frm.submit();
				}
				else 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 }
	require "_footer.php"; ?>