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

	if ($_SESSION['cCompany_id'] != "" && isset($_SESSION['cCompany_id'])) {
		$header_row_string = "Customer Payment Report ";
		$Case_total = 0;
		$Cheque_total = 0;
		$total = 0;

		ob_start();

		$invoicid = "SELECT 	lcir.invoice_no,(select dist_nameeng from lms_distmaster where lms_distmaster.dist_id = lc.district_id)as Dist,lcir.receipt_date,lcir.receipt_no,lcir.amount,lcir.payment_mode,lc.customer_cpmobile1,lc.customer_orgname from lms_custinvoicereceipt lcir,lms_customer lc where lcir.company_id='" . $_SESSION['cCompany_id'] . "' and lcir.customer_id=lc.customer_id";

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

		if ($bill_startdate != "From") {
			$bill_startdate = DateConversion($bill_startdate, "Y-m-d", "d/m/Y");
			$invoicid .= " AND lcir.receipt_date >= '$bill_startdate' ";
		}
		if ($bill_enddate != "To") {
			$bill_enddate = DateConversion($bill_enddate, "Y-m-d", "d/m/Y");
			$invoicid .= " AND lcir.receipt_date <= '$bill_enddate' ";
		}
		if ($customer_idhedden != "") {
			$invoicid .= " AND lcir.customer_id = '" . $customer_idhedden . "' ";
		}
		$invoicid .= " order by receipt_no";
		//echo $invoicid;
		//exit;
		$finalinvoiceid = dbQuery($invoicid);
		if (dbRows($finalinvoiceid) > 0) { ?>
			<table width="100%" class="report">

				<tr style="background-color:#CCC">
					<th width="10%" style="text-align:center">Receipt No.</th>
					<th width="15%" style="text-align:center">Invoice Nos.</th>
					<th width="10%" style="text-align:center">Date</th>
					<th width="20%" style="text-align:center">Customer Name</th>
					<th width="10%" style="text-align:center">District Name</th>
					<th width="10%" style="text-align:center">ContactNo</th>
					<th width="10%" style="text-align:center">Payment Mode</th>
					<th width="15%" style="text-align:center">Paid Amount</th>
				</tr>
				<?php
				while ($row1 = dbArray($finalinvoiceid)) {
					?>

					<tr>


						<td width="10%" style="text-align:center"> <?php echo $row1["receipt_no"]; ?> </td>
						<td width="15%" style="text-align:center"> <?php echo $row1["invoice_no"]; ?> </td>
						<td width="10%" style="text-align:center"><?php echo date("d-m-Y", strtotime($row1['receipt_date'])); ?></td>
						<td width="20%" style="text-align:left"><?php echo $row1["customer_orgname"]; ?></td>
						<td width="10%" style="text-align:left"><?php echo $row1["Dist"]; ?></td>
						<td width="10%" style="text-align:center"><?php
						if ($row1['customer_cpmobile1'] != "")
							echo $row1["customer_cpmobile1"];
						else
							echo '-';
						?></td>
						<td width="10%" style="text-align:center"><?php
						if ($row1['payment_mode'] == "0") {
							$Case_total += $row1["amount"];
							echo 'Cash';
						} else {
							$Cheque_total += $row1["amount"];
							echo 'Cheque';
						}
						?></td>
						<td width="15%" style="text-align:center"><?php echo $row1["amount"]; ?></td>



					</tr>

					<?php
					$total += $row1["amount"];
				}

				?>
				<tr>
					<th colspan="7" style="text-align:right; font-weight:bold; font-size:14px">Total Collection</th>
					<td style="text-align:center; font-weight:bold; font-size:14px; color:#F00;"><?php echo $total; ?></td>
				</tr>
				<?php if ($Cheque_total > 0) { ?>
					<tr>
						<th colspan="7" style="text-align:right; font-weight:bold; font-size:14px">Cheque Total </th>
						<td style="text-align:center; font-weight:bold; font-size:14px; color:#41ACF2;"><?php echo $Cheque_total; ?>
						</td>
					</tr>
				<?php }
				if ($Case_total > 0) { ?>
					<tr>
						<th colspan="7" style="text-align:right; font-weight:bold; font-size:14px">Cash Total</th>
						<td style="text-align:center; font-weight:bold; font-size:14px; color:#41ACF2;"><?php echo $Case_total; ?>
						</td>
					</tr>
				<?php } ?>


			</table>
			<?php

			$HtmlCode = ob_get_contents();
			ob_end_flush();

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