<?php 
include('../accesscheck2.php');
require_once('../Connections/courier.php'); 
require_once '../functions/functions.php';
$action = $_POST['act'];
$branch = $_POST['id'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$div1 = $_POST['div1'];
$lens_type = $_POST['lens_type'];
$lens_type_addition = $_POST['lens_type_addition'];
$eye_type = $_POST['eye_type'];

if ($action == "rr" || $action == "rr1") {?>
	<?php 
	if ($action == "rr1") {
		$date_rangeSpecific = "SELECT count(*)AS mediaCount,media_option FROM `process_claim_no` WHERE (date_added>='$start_date' and date_added <='$end_date')  GROUP BY media_option";
		$executeSpecific = mysql_query($date_rangeSpecific);
		$totalRows_rsodestSpecific = mysql_num_rows($executeSpecific);
	}else{
		$date_rangeSpecific = "SELECT count(*)AS mediaCount,media_option FROM `process_claim_no` WHERE (date_added>='$start_date' and date_added <='$end_date') AND branch_id = '$branch'  GROUP BY media_option";
		$executeSpecific = mysql_query($date_rangeSpecific);
		$totalRows_rsodestSpecific = mysql_num_rows($executeSpecific);	
	}

	?>
	<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
		<thead>
			<?php if ($action == "rr1") { ?>
				<tr>
					<tr>
						<th>SN</th>
						<th>MEDIA REPORT FOR ALL</th>
						<th>QTY</th>
					</tr>
				</tr> 
			<?php }else{ ?>
				<tr>
					<th>SN</th>
					<th>MEDIA REPORT FOR <?php echo strtoupper(branchName($branch, $courier)) ?></th>
					<th>QTY</th>
				</tr>
			<?php } ?>
			
			
		</thead>
		<tbody>

			<?php if($totalRows_rsodestSpecific>0){ 
				$i=1;
				while ($row_rsodestSpecific = mysql_fetch_assoc($executeSpecific)){  ?>
					<tr>
						<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>
						<td valign="top" style="cursor: pointer;"><?php if ($row_rsodestSpecific['media_option'] == '' || is_null($row_rsodestSpecific['media_option'])) {
							echo strtoupper('NONE');
						}else{
							echo strtoupper($row_rsodestSpecific['media_option']);
						}  ?></td>

						<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodestSpecific['mediaCount']); 
						$total_amountMedia1 += $row_rsodestSpecific['mediaCount'];?></td>


					</tr>
					<?php $i++; } 
				} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
				<tr>
					<td style="font-weight:bolder;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 2;}else{ echo 2;} ?>">OVERALL TOTAL AMOUNT </td>
					<td style="font-weight:bolder;"> <?php echo $total_amountMedia1; ?> </td>
				</tr>
			</tbody>
		</table>


	<?php };



	if ($action == "cor" || $action == "cor1") {

		if ($action == "cor1") {
			$date_rangeCash = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'cash'";
			$rsodestcash = mysql_query($date_rangeCash);
			$totalRows_rsodestcash= mysql_fetch_assoc($rsodestcash);

			$date_rangeCompany = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'company'";
			$rsodestCompany = mysql_query($date_rangeCompany);
			$totalRows_rsodestCompany = mysql_fetch_assoc($rsodestCompany);

			$date_rangeInsurance = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'insurance'";
			$rsodestInsurance = mysql_query($date_rangeInsurance);
			$totalRows_rsodestInsurance = mysql_fetch_assoc($rsodestInsurance);

			$date_rangeMale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'male'";
			$rsodestMale = mysql_query($date_rangeMale);
			$male = mysql_fetch_assoc($rsodestMale);

			$date_rangeFemale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'female'";
			$rsodestFemale = mysql_query($date_rangeFemale);
			$female = mysql_fetch_assoc($rsodestFemale);

			$date_rangeUnknown = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and (b.sex = '' OR b.sex IS NULL)";
			$rsodestUnknown = mysql_query($date_rangeUnknown);
			$Unknown = mysql_fetch_assoc($rsodestUnknown);


			$date_rangeLess10 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 10 and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestLess10 = mysql_query($date_rangeLess10);
			$less10 = mysql_fetch_assoc($rsodestLess10);

			$date_rangeBTN10And18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE (TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 10 and TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 18) and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestBTN10And18 = mysql_query($date_rangeBTN10And18);
			$BTN10And18 = mysql_fetch_assoc($rsodestBTN10And18);

			$date_rangeAbove18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 18 and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestAbove18 = mysql_query($date_rangeAbove18);
			$Above18 = mysql_fetch_assoc($rsodestAbove18);

			$date_rangeNODOB = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE dateofbirth = '0000-00-00' and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestNODOB = mysql_query($date_rangeNODOB);
			$NODOB = mysql_fetch_assoc($rsodestNODOB);




			$date_rangeCashgratis = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'gratis'";
			$rsodestcashgratis = mysql_query($date_rangeCashgratis);
			$totalRows_rsodestcashgratis = mysql_fetch_assoc($rsodestcashgratis);

			$date_rangeCashcreditsales = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'credit sales'";
			$rsodestcashcreditsales = mysql_query($date_rangeCashcreditsales);
			$totalRows_rsodestcashcreditsales = mysql_fetch_assoc($rsodestcashcreditsales);

			$date_rangeCashReview = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Review'";
			$rsodestcashReview = mysql_query($date_rangeCashReview);
			$totalRows_rsodestcashReview= mysql_fetch_assoc($rsodestcashReview);

			$date_rangeCashPromo = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Promo'";
			$rsodestcashPromo = mysql_query($date_rangeCashPromo);
			$totalRows_rsodestcashPromo = mysql_fetch_assoc($rsodestcashPromo);

		}else{
			$date_rangeCash = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date') AND a.branch_id = '$branch' AND mode_of_payment = 'cash'";
			$rsodestcash = mysql_query($date_rangeCash);
			$totalRows_rsodestcash= mysql_fetch_assoc($rsodestcash);

			$date_rangeCompany = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date')AND a.branch_id = '$branch' AND mode_of_payment = 'company'";
			$rsodestCompany = mysql_query($date_rangeCompany);
			$totalRows_rsodestCompany = mysql_fetch_assoc($rsodestCompany);

			$date_rangeInsurance = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date') AND a.branch_id = '$branch' AND mode_of_payment = 'insurance'";
			$rsodestInsurance = mysql_query($date_rangeInsurance);
			$totalRows_rsodestInsurance = mysql_fetch_assoc($rsodestInsurance);

			$date_rangeMale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date') AND a.branch_id = '$branch' and b.sex = 'male'";
			$rsodestMale = mysql_query($date_rangeMale);
			$male = mysql_fetch_assoc($rsodestMale);

			$date_rangeFemale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date')AND a.branch_id = '$branch' and b.sex = 'female'";
			$rsodestFemale = mysql_query($date_rangeFemale);
			$female = mysql_fetch_assoc($rsodestFemale);

			$date_rangeUnknown = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%consultation%' and (a.date_added>='$start_date' and a.date_added <='$end_date') AND a.branch_id = '$branch' and (b.sex = '' OR b.sex IS NULL)";
			$rsodestUnknown = mysql_query($date_rangeUnknown);
			$Unknown = mysql_fetch_assoc($rsodestUnknown);


			$date_rangeLess10 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 10 and a.item like '%consultation%' AND a.branch_id = '$branch' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestLess10 = mysql_query($date_rangeLess10);
			$less10 = mysql_fetch_assoc($rsodestLess10);

			$date_rangeBTN10And18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE (TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 10 and TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 18) and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestBTN10And18 = mysql_query($date_rangeBTN10And18);
			$BTN10And18 = mysql_fetch_assoc($rsodestBTN10And18);

			$date_rangeAbove18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 18 and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestAbove18 = mysql_query($date_rangeAbove18);
			$Above18 = mysql_fetch_assoc($rsodestAbove18);

			$date_rangeNODOB = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE dateofbirth = '0000-00-00' and a.item like '%consultation%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestNODOB = mysql_query($date_rangeNODOB);
			$NODOB = mysql_fetch_assoc($rsodestNODOB);

			$date_rangeCashgratis = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'gratis' AND a.branch_id = '$branch'";
			$rsodestcashgratis = mysql_query($date_rangeCashgratis);
			$totalRows_rsodestcashgratis = mysql_fetch_assoc($rsodestcashgratis);

			$date_rangeCashcreditsales = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date') AND mode_of_payment = 'credit sales' AND a.branch_id = '$branch'";
			$rsodestcashcreditsales = mysql_query($date_rangeCashcreditsales);
			$totalRows_rsodestcashcreditsales = mysql_fetch_assoc($rsodestcashcreditsales);

			$date_rangeCashReview = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date') AND mode_of_payment = 'Review' AND a.branch_id = '$branch'";
			$rsodestcashReview = mysql_query($date_rangeCashReview);
			$totalRows_rsodestcashReview= mysql_fetch_assoc($rsodestcashReview);

			$date_rangeCashPromo = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%consultation%' AND (a.date_added>='$start_date' and a.date_added <='$end_date') AND mode_of_payment = 'Promo' AND a.branch_id = '$branch'";
			$rsodestcashPromo = mysql_query($date_rangeCashPromo);
			$totalRows_rsodestcashPromo = mysql_fetch_assoc($rsodestcashPromo);
		}



		?>
		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
			<thead>
				<?php if ($action == "cor1") { ?>
					<tr>
						<th>SN</th>
						<th>ITEM REPORT FOR ALL</th>
						<th>QTY</th>
					</tr> 
				<?php }else{ ?>
					<tr>
						<th>SN</th>
						<th>ITEM REPORT FOR <?php echo strtoupper(branchName($branch, $courier)) ?></th>
						<th>QTY</th>
					</tr> 
				<?php } ?>
				
			</thead>
			<tbody>
				<tr>
					<td height="23" valign="top" class="count">1</td>
					<td valign="top" style="cursor: pointer;">CASH</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcash['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">2</td>
					<td valign="top" style="cursor: pointer;">COMAPNY</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestCompany['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">3</td>
					<td valign="top" style="cursor: pointer;">INSURANCE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestInsurance['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">4</td>
					<td valign="top" style="cursor: pointer;">GRATIS</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashgratis['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">5</td>
					<td valign="top" style="cursor: pointer;">CREDIT SALES</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashcreditsales['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">6</td>
					<td valign="top" style="cursor: pointer;">PROMO</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashPromo['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">7</td>
					<td valign="top" style="cursor: pointer;">REVIEW</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashReview['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">8</td>
					<td valign="top" style="cursor: pointer;">MALE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $male['itemCount']; ?></td>

				</tr>

				<tr>
					<td height="23" valign="top" class="count">9</td>
					<td valign="top" style="cursor: pointer;">FEMALE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $female['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">10</td>
					<td valign="top" style="cursor: pointer;">UNKNOWN GENDER</td>
					<td valign="top" style="cursor: pointer;"><?php echo $Unknown['itemCount']; ?></td>

				</tr>
				<tr>
					<td height="23" valign="top" class="count">11</td>
					<td valign="top" style="cursor: pointer;">CHILDREN UNDER 10</td>
					<td valign="top" style="cursor: pointer;"><?php echo $less10['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">12</td>
					<td valign="top" style="cursor: pointer;">CHILDREN BTWEEN 10 AND 18</td>
					<td valign="top" style="cursor: pointer;"><?php echo $BTN10And18['itemCount']; ?></td>

				</tr>

				<tr>
					<td height="23" valign="top" class="count">13</td>
					<td valign="top" style="cursor: pointer;">ABOVE 18</td>
					<td valign="top" style="cursor: pointer;"><?php echo $Above18['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">14</td>
					<td valign="top" style="cursor: pointer;">UNKNOWN DATE OF BIRTH</td>
					<td valign="top" style="cursor: pointer;"><?php echo $NODOB['itemCount']; ?></td>
				</tr>
				<tr>
				</tr>
			</tbody>
		</table>
	<?php }


	if ($action == "oph" || $action == "oph1") {

		if ($action == "oph1") {
			$date_rangeCash = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'cash'";
			$rsodestcash = mysql_query($date_rangeCash);
			$totalRows_rsodestcash= mysql_fetch_assoc($rsodestcash);

			$date_rangeCompany = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'company'";
			$rsodestCompany = mysql_query($date_rangeCompany);
			$totalRows_rsodestCompany = mysql_fetch_assoc($rsodestCompany);

			$date_rangeInsurance = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'insurance'";
			$rsodestInsurance = mysql_query($date_rangeInsurance);
			$totalRows_rsodestInsurance = mysql_fetch_assoc($rsodestInsurance);


			$date_rangeMale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'male'";
			$rsodestMale = mysql_query($date_rangeMale);
			$male = mysql_fetch_assoc($rsodestMale);

			$date_rangeFemale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'female'";
			$rsodestFemale = mysql_query($date_rangeFemale);
			$female = mysql_fetch_assoc($rsodestFemale);

			$date_rangeUnknown = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and (b.sex = '' OR b.sex IS NULL)";
			$rsodestUnknown = mysql_query($date_rangeUnknown);
			$Unknown = mysql_fetch_assoc($rsodestUnknown);


			$date_rangeLess10 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 10 and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestLess10 = mysql_query($date_rangeLess10);
			$less10 = mysql_fetch_assoc($rsodestLess10);

			$date_rangeBTN10And18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE (TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 10 and TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 18) and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestBTN10And18 = mysql_query($date_rangeBTN10And18);
			$BTN10And18 = mysql_fetch_assoc($rsodestBTN10And18);

			$date_rangeAbove18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 18 and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestAbove18 = mysql_query($date_rangeAbove18);
			$Above18 = mysql_fetch_assoc($rsodestAbove18);


			$date_rangeNODOB = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE dateofbirth = '0000-00-00' and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
			$rsodestNODOB = mysql_query($date_rangeNODOB);
			$NODOB = mysql_fetch_assoc($rsodestNODOB);



			$date_rangeCashgratis = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'gratis'";
			$rsodestcashgratis = mysql_query($date_rangeCashgratis);
			$totalRows_rsodestcashgratis = mysql_fetch_assoc($rsodestcashgratis);

			$date_rangeCashcreditsales = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'credit sales'";
			$rsodestcashcreditsales = mysql_query($date_rangeCashcreditsales);
			$totalRows_rsodestcashcreditsales = mysql_fetch_assoc($rsodestcashcreditsales);

			$date_rangeCashReview = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Review'";
			$rsodestcashReview = mysql_query($date_rangeCashReview);
			$totalRows_rsodestcashReview= mysql_fetch_assoc($rsodestcashReview);

			$date_rangeCashPromo = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Promo'";
			$rsodestcashPromo = mysql_query($date_rangeCashPromo);
			$totalRows_rsodestcashPromo = mysql_fetch_assoc($rsodestcashPromo);

		}else{

			$date_rangeCash = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'cash' AND a.branch_id = '$branch'";
			$rsodestcash = mysql_query($date_rangeCash);
			$totalRows_rsodestcash= mysql_fetch_assoc($rsodestcash);

			$date_rangeCompany = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'company' AND a.branch_id = '$branch'";
			$rsodestCompany = mysql_query($date_rangeCompany);
			$totalRows_rsodestCompany = mysql_fetch_assoc($rsodestCompany);

			$date_rangeInsurance = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'insurance' AND a.branch_id = '$branch'";
			$rsodestInsurance = mysql_query($date_rangeInsurance);
			$totalRows_rsodestInsurance = mysql_fetch_assoc($rsodestInsurance);


			$date_rangeMale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'male' AND a.branch_id = '$branch'";
			$rsodestMale = mysql_query($date_rangeMale);
			$male = mysql_fetch_assoc($rsodestMale);

			$date_rangeFemale = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and b.sex = 'female' AND a.branch_id = '$branch'";
			$rsodestFemale = mysql_query($date_rangeFemale);
			$female = mysql_fetch_assoc($rsodestFemale);

			$date_rangeUnknown = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount from claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no where item like '%ophthalmic%' and (a.date_added>='$start_date' and a.date_added <='$end_date') and (b.sex = '' OR b.sex IS NULL) AND a.branch_id = '$branch'";
			$rsodestUnknown = mysql_query($date_rangeUnknown);
			$Unknown = mysql_fetch_assoc($rsodestUnknown);


			$date_rangeLess10 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 10 and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestLess10 = mysql_query($date_rangeLess10);
			$less10 = mysql_fetch_assoc($rsodestLess10);

			$date_rangeBTN10And18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE (TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 10 and TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) < 18) and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestBTN10And18 = mysql_query($date_rangeBTN10And18);
			$BTN10And18 = mysql_fetch_assoc($rsodestBTN10And18);

			$date_rangeAbove18 = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE TIMESTAMPDIFF(YEAR, b.dateofbirth, NOW()) >= 18 and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestAbove18 = mysql_query($date_rangeAbove18);
			$Above18 = mysql_fetch_assoc($rsodestAbove18);

			$date_rangeNODOB = "SELECT COUNT(DISTINCT a.process_claim_no) AS itemCount, b.dateofbirth FROM claims_details a INNER JOIN patient_information b ON b.card_number = a.patient_no WHERE dateofbirth = '0000-00-00' and a.item like '%ophthalmic%' and (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND a.branch_id = '$branch'";
			$rsodestNODOB = mysql_query($date_rangeNODOB);
			$NODOB = mysql_fetch_assoc($rsodestNODOB);

			$date_rangeCashgratis = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'gratis' AND a.branch_id = '$branch'";
			$rsodestcashgratis = mysql_query($date_rangeCashgratis);
			$totalRows_rsodestcashgratis = mysql_fetch_assoc($rsodestcashgratis);

			$date_rangeCashcreditsales = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'credit sales' AND a.branch_id = '$branch'";
			$rsodestcashcreditsales = mysql_query($date_rangeCashcreditsales);
			$totalRows_rsodestcashcreditsales = mysql_fetch_assoc($rsodestcashcreditsales);

			$date_rangeCashReview = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Review' AND a.branch_id = '$branch'";
			$rsodestcashReview = mysql_query($date_rangeCashReview);
			$totalRows_rsodestcashReview= mysql_fetch_assoc($rsodestcashReview);

			$date_rangeCashPromo = "SELECT COUNT(DISTINCT a.process_claim_no) as itemCount, branch_id, item, mode_of_payment, sex from claims_details a INNER JOIN patient_information b ON a.patient_no = b.card_number where a.item like '%ophthalmic%' AND (date_added>='$start_date' and date_added <='$end_date') AND mode_of_payment = 'Promo' AND a.branch_id = '$branch'";
			$rsodestcashPromo = mysql_query($date_rangeCashPromo);
			$totalRows_rsodestcashPromo = mysql_fetch_assoc($rsodestcashPromo);
		}

		?>

		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
			<thead>
				<tr>
					<th>SN</th>
					<th>ITEM - <?php echo strtoupper(branchName($branch, $courier)) ?></th>
					<th>QTY</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td height="23" valign="top" class="count">1</td>
					<td valign="top" style="cursor: pointer;">CASH</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcash['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">2</td>
					<td valign="top" style="cursor: pointer;">COMAPNY</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestCompany['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">3</td>
					<td valign="top" style="cursor: pointer;">INSURANCE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestInsurance['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">4</td>
					<td valign="top" style="cursor: pointer;">GRATIS</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashgratis['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">5</td>
					<td valign="top" style="cursor: pointer;">CREDIT SALES</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashcreditsales['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">6</td>
					<td valign="top" style="cursor: pointer;">PROMO</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashPromo['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">7</td>
					<td valign="top" style="cursor: pointer;">REVIEW</td>
					<td valign="top" style="cursor: pointer;"><?php echo $totalRows_rsodestcashReview['itemCount']; ?></td>
				</tr>

				<tr>
					<td height="23" valign="top" class="count">8</td>
					<td valign="top" style="cursor: pointer;">MALE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $male['itemCount']; ?></td>

				</tr>

				<tr>
					<td height="23" valign="top" class="count">9</td>
					<td valign="top" style="cursor: pointer;">FEMALE</td>
					<td valign="top" style="cursor: pointer;"><?php echo $female['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">10</td>
					<td valign="top" style="cursor: pointer;">UNKNOWN GENDER</td>
					<td valign="top" style="cursor: pointer;"><?php echo $Unknown['itemCount']; ?></td>

				</tr>
				<tr>
					<td height="23" valign="top" class="count">11</td>
					<td valign="top" style="cursor: pointer;">CHILDREN UNDER 10</td>
					<td valign="top" style="cursor: pointer;"><?php echo $less10['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">12</td>
					<td valign="top" style="cursor: pointer;">CHILDREN BTWEEN 10 AND 18</td>
					<td valign="top" style="cursor: pointer;"><?php echo $BTN10And18['itemCount']; ?></td>

				</tr>

				<tr>
					<td height="23" valign="top" class="count">13</td>
					<td valign="top" style="cursor: pointer;">ABOVE 18</td>
					<td valign="top" style="cursor: pointer;"><?php echo $Above18['itemCount']; ?></td>
				</tr>
				<tr>
					<td height="23" valign="top" class="count">14</td>
					<td valign="top" style="cursor: pointer;">UNKNOWN DATE OF BIRTH</td>
					<td valign="top" style="cursor: pointer;"><?php echo $NODOB['itemCount']; ?></td>
				</tr>
				<tr>
				</tr>
			</tbody>
		</table>
	<?php }

	if ($action == "pdr" || $action == "pdr1") {

		if ($action == "pdr1") {
			$pending_diagnosticbr = "SELECT *, count(a.id) AS itemCount FROM `process_claim_no` a INNER JOIN patient_information b ON b.card_number = a.patient_no INNER JOIN claims_details c on c.patient_no = a.patient_no WHERE a.consulting_room_status = 'pending_diagnostic' AND (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND c.item_service = 'Laboratory' GROUP BY a.patient_no";
		}else{
			$pending_diagnosticbr = "SELECT *, count(a.id) AS itemCount FROM `process_claim_no` a INNER JOIN patient_information b ON b.card_number = a.patient_no INNER JOIN claims_details c on c.patient_no = a.patient_no WHERE a.consulting_room_status = 'pending_diagnostic' AND (a.date_added >= '$start_date' and a.date_added <= '$end_date') AND c.item_service = 'Laboratory' AND branch_id = '$branch' GROUP BY a.patient_no";
		}
		$pending_diagnosticbr1 = mysql_query($pending_diagnosticbr);
		$pending_diagnosticbr2 = mysql_num_rows($pending_diagnosticbr1);
		?>
		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">

			<thead>
				<?php if ($action == "pdr1") { ?>
					<tr style="background-color: #333; color: white;">
						<th>SN</th>
						<th>NAME</th>
						<th>QTY</th>
					</tr>
				<?php }else{ ?>
					<tr style="background-color: #333; color: white;">
						<th>SN</th>
						<th>NAME - <?php echo strtoupper(branchName($branch, $courier)) ?></th>
						<th>QTY</th>
					</tr>
				<?php } ?>


			</thead>
			<thead>

			</thead>
			<tbody>

				<?php if($pending_diagnosticbr2>0){ 
					$i=1;
					while ($row_rsodest2 = mysql_fetch_assoc($pending_diagnosticbr1)){  ?>
						<tr style="cursor:pointer;" onclick="$('.detailspatient_<?php echo $row_rsodest2['patient_no']; ?>').slideToggle();">
							<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>
							<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest2['surname'].' '.$row_rsodest2['othernames']) ?></td>

							<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest2['itemCount']); 
							$total_amountMedia += $row_rsodest2['itemCount'];?></td>
						</tr>
						<tr class="detailspatient_<?php echo $row_rsodest2['patient_no']; ?>" style="display:none;">
							<td class="detailspatient_<?php echo $row_rsodest2['patient_no']; ?>" colspan="11" style="display:none;">

								<div class="detailspatient_<?php echo $row_rsodest2['patient_no']; ?>" style="display:none;">

									<table class="table table-bordered">
										<thead>
											<tr style="background-color: #333; color: #fff">

												<th style="text-align:center;">ITEM</th>
												<th style="text-align:center;">TYPE</th>
												<th style="text-align:center;">STATUS</th>

											</tr>
										</thead>

										<tbody>
											<?php 
											$fetchDetails  = "SELECT * FROM claims_details a  INNER JOIN process_claim_no b on a.patient_no = b.patient_no  WHERE a.patient_no = '".$row_rsodest2['patient_no']."' AND a.process_claim_no = '".$row_rsodest2['process_claim_no']."' AND b.consulting_room_status = 'pending_diagnostic' AND a.item_service = 'Laboratory'";
											$executeDetail = mysql_query($fetchDetails);
											while ($row = mysql_fetch_assoc($executeDetail)) {

												?>
												<tr>
													<td><?php echo $row['item']; ?></td>
													<td><?php $row['item_service']; ?></td>
													<td><?php if ($row['consulting_room_status'] == "pending_diagnostic") {echo "Pending Diagnostic";} $row['consulting_room_status']; ?></td>
												</tr>
											<?php } ?>
										</tbody>

									</table>

								</div>
							</td>
						</tr>

						<?php $i++; } 
					} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
					<tr>
						<td style="font-weight:bolder;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 2;}else{ echo 2;} ?>">OVERALL TOTAL AMOUNT </td>
						<td style="font-weight:bolder;"> <?php echo $total_amountMedia; ?> </td>
					</tr>


				</tbody>
			</table>
		<?php } ?>

		<?php if ($action == "lrt" || $action == "lrt1") {

			if ($action == "lrt") {
                $branch_id = $branch;
                if ($lens_type && $lens_type_addition) {

                    if ($eye_type == "all"){
                        $lens_typer = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS countr, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date')  GROUP BY a.od_sphere, b.lens_type ORDER BY countr DESC";

                        $lens_typel = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS countl, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.os_sphere, b.lens_type ORDER BY countl DESC";


                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";
                    }else if($eye_type == "right"){
                        $lens_type2 = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.od_sphere, b.lens_type ORDER BY count DESC";

                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";
                    }else if ($eye_type == "left"){
                        $lens_type2 = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count , a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.os_sphere, b.lens_type ORDER BY count DESC";

                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a. INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_type_addition' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";
                    }

                }else if ($lens_type) {

                    if ($eye_type == "all"){
                        $lens_typer = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS countr, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.od_sphere, b.lens_type ORDER BY countr DESC";

                        $lens_typel = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS countl, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no AND c.branch_id = '$branch_id' WHERE b.lens_type LIKE '%$lens_type%' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date')  GROUP BY a.os_sphere, b.lens_type ORDER BY countl DESC";

                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";

                    }else if ($eye_type == "right"){
                        $lens_type2 = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.od_sphere, b.lens_type ORDER BY count DESC";

                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";
                    }else if ($eye_type == "left"){
                        $lens_type2 = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count , a.os_add
,a.od_add FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY a.os_sphere, b.lens_type ORDER BY count DESC";

                        $lens_type_summary = "SELECT a.od_sphere, a.os_sphere,a.od_cylinder, a.os_cylinder, a.lens_type, a.process_claim_no, count(*) AS count, c.branch_id FROM optical_examination a INNER JOIN patient_lens_type b on b.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no INNER JOIN claims_details c ON c.process_claim_no = a.process_claim_no WHERE b.lens_type LIKE '%$lens_type%' AND c.branch_id = '$branch_id' AND (a.date_time_exam >= '$start_date' and a.date_time_exam <= '$end_date') GROUP BY c.branch_id ORDER BY count DESC";
                    }
                }

                $lens_type8 = mysql_query($lens_type2);
                $lens_type_summary1 = mysql_query($lens_type_summary);
                $lens_typeR = mysql_query($lens_typer);
                $lens_typeL = mysql_query($lens_typel);
			}?>
            <?php if ($eye_type == 'all'){ ?>
                    <table>
                        <tr style="text-align: center">
                            <th> <?php echo branchName($branch_id, $courier)?> </th>
                        </tr>
                    </table>
                    <div class="row">
                        <div class="col-lg-6">
                            <table class="table table-bordered">
                                <thead>
                                <tr style="background-color: #333; color: #fff">
                                    <th style="text-align:center;">NO</th>
                                    <th style="text-align:center;">OD SPHERE</th>
                                    <th style="text-align:center;">OD CYLINDER</th>
                                    <th style="text-align:center;">OD ADD</th>
                                    <th style="text-align:center;">LENS TYPE</th>
                                    <th style="text-align:center;">LENS ADDITION</th>
                                    <th style="text-align:center;">FREQUENCY</th>

                                </tr>
                                </thead>

                                <?php
                                $count = 0;
                                while ($row = mysql_fetch_assoc($lens_typeR)) {
                                    $count ++;
                                    ?>
                                    <tr>
                                        <td><?php echo $count; ?></td>
                                        <td><?php echo $row['od_sphere']; ?></td>
                                        <td><?php echo $row['od_cylinder']; ?></td>
                                        <td><?php echo $row['od_add']; ?></td>
                                        <td><?php echo $lens_type; ?></td>
                                        <td><?php if($lens_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></td>
                                        <td><?php echo $row['countr']; ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </div>

                        <div class="col-lg-6">
                            <table class="table table-bordered">
                                <thead>
                                <tr style="background-color: #333; color: #fff">
                                    <th style="text-align:center;">NO</th>
                                    <th style="text-align:center;">OS SPHERE</th>
                                    <th style="text-align:center;">OS CYLINDER</th>
                                    <th style="text-align:center;">OS ADD</th>
                                    <th style="text-align:center;">LENS TYPE</th>
                                    <th style="text-align:center;">LENS ADDITION</th>
                                    <th style="text-align:center;">FREQUENCY</th>
                                </tr>
                                </thead>

                                <?php
                                $count = 0;
                                while ($row = mysql_fetch_assoc($lens_typeL)) {
                                    $count ++;
                                    ?>

                                    <tr>
                                        <td><?php echo $count; ?></td>
                                        <td><?php echo $row['os_sphere']; ?></td>
                                        <td><?php echo $row['os_cylinder']; ?></td>
                                        <td><?php echo $row['os_add']; ?></td>
                                        <td><?php echo $lens_type; ?></td>
                                        <td><?php if($lens_type_addition == ""){ echo "None";}else{ echo strtoupper($lens_type_addition);} ?></td>
                                        <td><?php echo $row['countl']; ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </div>
                    </div>

                <?php } else { ?>
                <table>
                    <tr style="text-align: center">
                        <th> <?php echo branchName($branch_id, $courier)?> </th>
                    </tr>
                </table>
                    <table class="table table-bordered">
                        <thead>
                        <tr style="background-color: #333; color: #fff">
                            <?php if ($eye_type == ''){ ?>
                                <th style="text-align:center;">NO</th>
                                <th style="text-align:center;">OD SPHERE</th>
                                <th style="text-align:center;">OD CYLINDER</th>
                                <th style="text-align:center;">OD ADD</th>
                                <th style="text-align:center;">LENS TYPE</th>
                                <th style="text-align:center;">LENS ADDITION</th>
                                <th style="text-align:center;">FREQUENCY</th>


                                <th style="text-align:center;">OS SPHERE</th>
                                <th style="text-align:center;">OS CYLINDER</th>
                                <th style="text-align:center;">OS ADD</th>
                                <th style="text-align:center;">LENS TYPE</th>
                                <th style="text-align:center;">LENS ADDITION</th>
                                <th style="text-align:center;">FREQUENCY</th>

                            <?php }else if ($eye_type == 'right'){ ?>
                                <th style="text-align:center;">NO</th>
                                <th style="text-align:center;">OD SPHERE</th>
                                <th style="text-align:center;">OD CYLINDER</th>
                                <th style="text-align:center;">OD ADD</th>
                                <th style="text-align:center;">LENS TYPE</th>
                                <th style="text-align:center;">LENS ADDITION</th>
                                <th style="text-align:center;">FREQUENCY</th>
                            <?php }else if ($eye_type == "left"){?>
                                <th style="text-align:center;">NO</th>
                                <th style="text-align:center;">OS SPHERE</th>
                                <th style="text-align:center;">OS CYLINDER</th>
                                <th style="text-align:center;">OS ADD</th>
                                <th style="text-align:center;">LENS TYPE</th>
                                <th style="text-align:center;">LENS ADDITION</th>
                                <th style="text-align:center;">FREQUENCY</th>
                            <?php }?>

                        </tr>
                        </thead>

                        <tbody>
                        <?php

                        $count = 0;
                        while ($row = mysql_fetch_assoc($lens_type8)) {
                            $count ++;
                            ?>
                            <?php if ($eye_type == ''){ ?>
                                <tr>
                                    <td><?php echo $count; ?></td>
                                    <td><?php echo $row['od_sphere']; ?></td>
                                    <td><?php echo $row['od_cylinder']; ?></td>
                                    <td><?php echo $row['od_add']; ?></td>
                                    <td><?php echo $lens_type; ?></td>
                                    <td><?php if($lens_type_addition == ""){ echo "None";}else{ echo strtoupper($lens_type_addition);} ?></td>
                                    <td><?php echo $row['count']; ?></td>


                                    <td><?php echo $row['os_sphere']; ?></td>
                                    <td><?php echo $row['os_cylinder']; ?></td>
                                    <td><?php echo $row['os_add']; ?></td>
                                    <td><?php echo $lens_type; ?></td>
                                    <td><?php if($lens_type_addition == ""){ echo "None";}else{ echo strtoupper($lens_type_addition);} ?></td>
                                    <td><?php echo $row['countl']; ?></td>
                                </tr>

                            <?php }else if ($eye_type == 'right'){ ?>
                                <tr>
                                    <td><?php echo $count; ?></td>
                                    <td><?php echo $row['od_sphere']; ?></td>
                                    <td><?php echo $row['od_cylinder']; ?></td>
                                    <td><?php echo $row['od_add']; ?></td>
                                    <td><?php echo $lens_type; ?></td>
                                    <td><?php if($lens_type_addition == ""){ echo "None";}else{ echo strtoupper($lens_type_addition);} ?></td>
                                    <td><?php echo $row['count']; ?></td>
                                </tr>

                            <?php }else if ($eye_type == "left"){?>
                                <tr>
                                    <td><?php echo $count; ?></td>
                                    <td><?php echo $row['os_sphere']; ?></td>
                                    <td><?php echo $row['os_cylinder']; ?></td>
                                    <td><?php echo $row['os_add']; ?></td>
                                    <td><?php echo $lens_type; ?></td>
                                    <td><?php if($lens_type_addition == ""){ echo "None";}else{ echo strtoupper($lens_type_addition);} ?></td>
                                    <td><?php echo $row['count']; ?></td>
                                </tr>

                            <?php }?>

                        <?php } ?>

                        </tbody>
                    </table>
                <?php } ?>

		<?php } ?>



