<?php session_start();
include('../accesscheck2.php');
require_once('../Connections/courier.php'); 
require_once '../functions/functions.php';
mysql_select_db($database_courier, $courier);

if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
		if (PHP_VERSION < 6) {
			$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
		}

		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

		switch ($theType) {
			case "text":
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;    
			case "long":
			case "int":
			$theValue = ($theValue != "") ? intval($theValue) : "NULL";
			break;
			case "double":
			$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
			break;
			case "date":
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;
			case "defined":
			$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
			break;
		}
		return $theValue;
	}
}


$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];
$payment_methods = $_GET['payment_method'];
$payment_statuss = $_GET['payment_status'];

$lens_type = $_GET['lens_type'];
$lens_additions = $_GET['lens_additions'];
$lens_extra_additions = $_GET['lens_extra_additions'];

$sphere = $_GET['sphere'];
$cylinder = $_GET['cylinder'];

list($od_sphere, $os_sphere) = explode("@@", $sphere);
list($od_cylinder, $os_cylinder) = explode("@@", $cylinder);

list($report_type, $report_type_txt) = explode("@@@", $_GET['report_type']);

//echo $report_type; exit();

if (count($payment_statuss) > 0) {
	foreach ($payment_statuss as $payment_status) {
		$payment_sts_qry .= "a.ins_company='$payment_status' OR ";
	}
	$payment_sts_qry = substr($payment_sts_qry, 0, -4);
	$payment_sts_qry = "AND (".$payment_sts_qry.")";
}

if ($report_type == "rr") {
	$date_range = "SELECT count(*) as count, branch_id, media_option FROM patient_information a INNER JOIN process_claim_no b on a.card_number = b.patient_no WHERE (date_added >= '$start_date' and date_added <= '$end_date') GROUP BY b.branch_id";


	$date_range2 = "SELECT count(*)AS mediaCount,media_option FROM `process_claim_no` WHERE (date_added>='$start_date' and date_added <='$end_date')  GROUP BY media_option";

	$execute = mysql_query($date_range);
	$totalRows_rsodestrr = mysql_num_rows($execute);

	$execute1 = mysql_query($date_range2);
	$totalRows_rsodest2 = mysql_num_rows($execute1);


}

if ($report_type == "cor") {
	$date_range = "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') GROUP BY branch_id";
	$execute = mysql_query($date_range);
	$totalRows_rsodestCor = mysql_num_rows($execute);


	$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);

}

if ($report_type == "oph") {
	$date_range = "SELECT COUNT(DISTINCT process_claim_no) as itemCount, branch_id, item from claims_details where item like '%ophthalmic%' and  (date_added>='$start_date' and date_added <='$end_date') GROUP BY branch_id";
	$execute = mysql_query($date_range);
	$totalRows_rsodestOph = mysql_num_rows($execute);

	$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);


}


// if ($report_type == "oph") {
// 	$date_range = "SELECT DISTINCT count(item) as itemCount, branch_id, item from claims_details where item like '%ophthalmic%' and  (date_added>='$start_date' and date_added <='$end_date') GROUP BY branch_id";
// 	$execute = mysql_query($date_range);
// 	$totalRows_rsodestOph = mysql_num_rows($execute);

// 	$date_rangeCash = "SELECT DISTINCT count(item) 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 DISTINCT count(item) 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 DISTINCT count(item) 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(b.sex) 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(b.sex) 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_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);

// }

if ($report_type == "frr") {
	$date_rangeFrameReport = "SELECT item,item_service,sub_item_service_type,item_service_type,date_added,branch_id, sum(qty) AS itemCount FROM claims_details 
	WHERE item_service_type='Optical Frame' and (date_added >= '$start_date' and date_added <= '$end_date') and (branch_id IS NOT NULL OR branch_id <> '')
	GROUP BY branch_id";
	$rsodestFrameReport = mysql_query($date_rangeFrameReport);
	$totalRows_rsodestFrame = mysql_num_rows($rsodestFrameReport);
}

if ($report_type  == "frdr") {
	$date_rangeFrameReport = "SELECT a.service_type, a.item, sum(a.qty) AS itemCount, sum(a.price), price, delivery_location AS branch_id  FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no
	WHERE (supplied_date >= '$start_date' and supplied_date <= '$end_date') AND a.order_status = 'received'
	GROUP BY delivery_location";
	$rsodestFrameReport = mysql_query($date_rangeFrameReport);
	$totalRows_rsodestFrame = mysql_num_rows($rsodestFrameReport);

}

if ($report_type  == "ftr") {
	$date_rangeFrameReport = "SELECT a.service_type, a.item, sum(a.qty) AS itemCount, sum(a.price), price, delivery_location AS branch_id  FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no
	WHERE (supplied_date >= '$start_date' and supplied_date <= '$end_date') AND a.order_status = 'transfered'
	GROUP BY delivery_location";
	$rsodestFrameReport = mysql_query($date_rangeFrameReport);
	$totalRows_rsodestFrame = mysql_num_rows($rsodestFrameReport);

}

if ($report_type  == "frrn") {
	$date_rangeFrameReport = "SELECT a.service_type, a.item, sum(a.qty) AS itemCount, sum(a.price), price, delivery_location AS branch_id  FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no
	WHERE (supplied_date >= '$start_date' and supplied_date <= '$end_date') AND a.order_status = 'damaged'
	GROUP BY delivery_location";
	$rsodestFrameReport = mysql_query($date_rangeFrameReport);
	$totalRows_rsodestFrame = mysql_num_rows($rsodestFrameReport);

}

if ($report_type  == "pdr") {
    $pending_diagnostic = "SELECT count(*) AS itemCount, a.branch_id 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.branch_id";
	$pending_diagnostic1 = mysql_query($pending_diagnostic);
	$pending_diagnostic2 = mysql_num_rows($pending_diagnostic1);


	$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";
	$pending_diagnosticbr1 = mysql_query($pending_diagnosticbr);
	$pending_diagnosticbr2 = mysql_num_rows($pending_diagnosticbr1);

}


if ($report_type == "lrt") {
    $eye_type = $_GET['eyes_type'];

		if ($lens_type12 && $lens_additions123) {
			  $lens_type2 = "SELECT count(DISTINCT (b.process_claim_no)) AS lenseCount FROM patient_lens_type a INNER JOIN optical_examination b ON b.process_claim_no = a.process_claim_no WHERE a.lens_type LIKE '%$lens_type%' AND b.lens_type = '$lens_additions' AND (b.date_time_exam >= '$start_date' and b.date_time_exam <= '$end_date')";
			 // $lens_type2 = "SELECT * FROM `claims_details` a WHERE a.item LIKE '%$lens_type%' AND (a.date_added >= '$start_date' and a.date_added <= '$end_date') GROUP BY a.process_claim_no";
		}

		if ($lens_type && $lens_additions && $lens_extra_additions) {
			$lens_type2 = "SELECT count(DISTINCT (b.process_claim_no)) AS lenseCount FROM patient_lens_type a INNER JOIN optical_examination b ON b.process_claim_no = a.process_claim_no INNER JOIN patient_lens_addition c ON c.process_claim_no = a.process_claim_no WHERE a.lens_type LIKE '%$lens_type%' AND b.lens_type = '$lens_additions' AND C.addition = '$lens_extra_additions' AND (b.date_time_exam >= '$start_date' and b.date_time_exam <= '$end_date')";
		}

		if ($lens_type && $lens_additions) {
		    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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions'  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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' AND a.lens_type = '$lens_additions' 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 WHERE b.lens_type LIKE '%$lens_type%' 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 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 WHERE b.lens_type LIKE '%$lens_type%' 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 WHERE b.lens_type LIKE '%$lens_type%' 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 WHERE b.lens_type LIKE '%$lens_type%' 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 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 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 WHERE b.lens_type LIKE '%$lens_type%' 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);
}





function getLenstype($lens_type, $process_claim_no, $table, $courier){
	$result = mysql_query("SELECT * FROM $table WHERE process_claim_no = '$process_claim_no'", $courier);
$result1 = mysql_fetch_assoc($result);
$result2 = mysql_num_rows($result);
return $result3 = $result1['lens_type']."@@".$result2;
}

function getLenstypeadd($lens_type, $process_claim_no, $table, $courier){
	$result = mysql_query("SELECT * FROM $table WHERE process_claim_no = '$process_claim_no'", $courier);
$result1 = mysql_fetch_assoc($result);
$result2 = mysql_num_rows($result);
return $result3 = $result1['addition']."@@".$result2;
}
?>



<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
	<meta charset="utf-8" />
	<title> Optical Management System </title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta content="width=device-width, initial-scale=1" name="viewport" />
	<meta content="" name="description" />
	<meta content="" name="author" />
	<!-- BEGIN GLOBAL MANDATORY STYLES -->
	<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
	<!--<link href="../assets/global/css/font.css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />-->
	<script src="../assets/global/plugins/jquery.min.js" type="text/javascript"></script>
	<link href="../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
	<link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="../assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
	<link href="../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />

	<style type="text/css" media="all">
		body{
			margin: 0;
		}
		.text-danger strong {
			color: #9f181c;
		}
		.text-danger {
			color: #9f181c;
		}
		.receipt-main {
			background: #ffffff none repeat scroll 0 0;
			/*border-bottom: 12px solid #333333;*/
			border-top: 12px solid #9f181c;
			/*margin-top: 50px;*/
			margin-bottom: 50px;
			padding: 40px 30px !important;
			position: relative;
			box-shadow: 0 1px 21px #acacac;
			color: #333333;
			font-family: open sans;
		}
		.receipt-main p {
			color: #333333;
			font-family: open sans;
			line-height: 1.42857;
		}
		.receipt-footer h1 {
			font-size: 15px;
			font-weight: 400 !important;
			margin: 0 !important;
		}
		.receipt-main::after {
			background: #414143 none repeat scroll 0 0;
			content: "";
			height: 5px;
			left: 0;
			position: absolute;
			right: 0;
			top: -13px;
		}
		.receipt-main thead {
			background: #414143 none repeat scroll 0 0;
		}
		.receipt-main thead th {
			color:#fff;
		}
		.receipt-main .amount {
			text-align: right
		}
		.receipt-right h5 {
			font-size: 16px;
			font-weight: bold;
			margin: 0 0 7px 0;
		}
		.receipt-right p {
			font-size: 12px;
			margin: 0px;
		}
		.receipt-right p i {
			text-align: center;
			width: 18px;
		}
		.receipt-main td {
			padding: 9px 20px !important;
		}
		.receipt-main th {
			padding: 12px 15px !important;
		}
		.receipt-main td {
			font-size: 13px;
			font-weight: initial !important;
		}
		.receipt-main td p:last-child {
			margin: 0;
			padding: 0;
		}	
		.receipt-main td h2 {
			font-size: 20px;
			font-weight: 900;
			margin: 0;
			text-transform: uppercase;
		}
		.receipt-header-mid .receipt-left h1 {
			font-weight: 100;
			margin: 34px 0 0;
			text-align: right;
			text-transform: uppercase;
		}
		.receipt-header-mid {
			margin: 24px 0;
			overflow: hidden;
		}
		
		#container {
			background-color: #dcdcdc;
		}
	</style>

</head>

<body>

	<div class="container-fluid">
		<div class="row">
			<div class="receipt-main col-xs-12 col-sm-12 col-md-12">
				<div class="row">
					<div class="receipt-header">
						<div class="col-xs-6 col-sm-6 col-md-6">
							<div class="receipt-left">
								<img class="img-responsive" src="../images/app_pics/rns_logo.jpeg" style="width: 71px;">
							</div>
						</div>
						<div class="col-xs-6 col-sm-6 col-md-6 text-right">
							<div class="receipt-right">
								<h5>ROBERT AND SONS LTD.</h5>
								<p>+233034789/09678909 <i class="fa fa-phone"></i></p>
								<p>INFO@ROBERTANDSON.COM <i class="fa fa-envelope-o"></i></p>
								<p>ADABRAKA BRANCH <i class="fa fa-location-arrow"></i></p>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="receipt-header receipt-header-mid">
						<div class="col-xs-8 col-sm-8 col-md-8 text-left">
							<div class="receipt-right">
								<h3> <?php echo strtoupper($report_type_txt); ?> </h3>
								<h4 class="text-danger"> DATE RANGE :  <?php echo date('jS M, Y',  strtotime($start_date));?> - <?php echo date('jS M, Y',  strtotime($end_date)); ?> </h4>
							</div>
						</div>
						<div class="col-xs-4 col-sm-4 col-md-4">
							<div class="receipt-left">
								<h1>Report</h1>
							</div>
						</div>
					</div>
				</div>

				<?php if ($report_type == "rr") { ?>
					<div class="row">
						<div class="col-md-6">
							<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>BRANCH</th>
										<th>ITEM/SERVICE NAME</th>
										<th>QTY</th>
									</tr>
								</thead>
								<tbody>

									<?php if($totalRows_rsodestrr>0){ 
										$i=1;
										while ($row_rsodest = mysql_fetch_assoc($execute)){  ?>
											<tr>
												<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

												<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAll','loadSpecific', 'rr', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="cursor: pointer;"><?php echo strtoupper(branchName($row_rsodest['branch_id'], $courier)); ?></td>
												<td valign="top" style="cursor: pointer;">REGISTRATION</td>
												<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodest['count']; echo strtoupper($row_rsodest['count']); ?></td>

											</tr>



											<?php $i++; } 
										} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
										<tr>
											<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAll','loadSpecific', 'rr1', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="font-weight:bold; cursor: pointer;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
											<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
										</tr>
									</tbody>
								</table>

							</div>

							<div class="col-md-6">
								<div id="loadAll">
									<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>MEDIA</th>
												<th>QTY</th>


											</tr>
										</thead>
										<tbody>

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

														<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest2['mediaCount']); 
														$total_amountMedia += $row_rsodest2['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_amountMedia; ?> </td>
												</tr>
											</tbody>
										</table>

									</div>
									<div id="loadSpecific">

									</div>


								</div>

							</div>
						<?php } ?>


						<?php if ($report_type == "cor") { ?>
							<div class="row">
								<div class="col-md-6">
									<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>BRANCH</th>
												<th>ITEM/SERVICE NAME</th>
												<th>QTY</th>
											</tr>
										</thead>
										<tbody>

											<?php if($totalRows_rsodestCor>0){ 
												$i=1;
												while ($row_rsodest = mysql_fetch_assoc($execute)){  ?>
													<tr>
														<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

														<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAllCor','loadSpecificCor', 'cor', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="cursor: pointer;"><?php echo strtoupper(branchName($row_rsodest['branch_id'], $courier)); ?></td>
														<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['item']) ?></td>
														<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodest['itemCount']; echo strtoupper($row_rsodest['itemCount']); ?></td>

													</tr>



													<?php $i++; } 
												} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
												<tr>
													<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAllCor','loadSpecificCor', 'cor1', '<?php echo $start_date?>','<?php echo $end_date ?>')"  style="font-weight:bold; cursor: pointer;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
													<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
												</tr>
											</tbody>
										</table>

									</div>

									<div class="col-md-6">

										<div id="loadSpecificCor">

										</div>


										<div id="loadAllCor">
											<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</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>
										</div>


									</div>	
								</div>
							<?php } ?>


							<?php if ($report_type == "oph") { ?>
								<div class="row">
									<div class="col-md-6">
										<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>BRANCH</th>
													<th>ITEM/SERVICE NAME</th>
													<th>QTY</th>
												</tr>
											</thead>
											<tbody>

												<?php if($totalRows_rsodestOph>0){ 
													$i=1;
													while ($row_rsodest = mysql_fetch_assoc($execute)){  ?>
														<tr>
															<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

															<td style="cursor: pointer;" onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAlloph','loadSpecificoph', 'oph', '<?php echo $start_date?>','<?php echo $end_date ?>')"><?php echo strtoupper(branchName($row_rsodest['branch_id'], $courier)); ?></td>
															<td valign="top"><?php echo strtoupper('Ophthalmic') ?></td>
															<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodest['itemCount']; echo strtoupper($row_rsodest['itemCount']); ?></td>

														</tr>



														<?php $i++; } 
													} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
													<tr>
														<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAlloph','loadSpecificoph', 'oph1', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="font-weight:bold; cursor: pointer;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
														<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
													</tr>
												</tbody>
											</table>

										</div>

										<div class="col-md-6">
											<div id="loadSpecificoph">
											</div>
											<div id="loadAlloph">
												<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</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>
											</div>



										</div>	
									</div>
								<?php } ?>



								<?php if ($report_type == "frr") { ?>
									<div class="row">
										<div class="col-md-6">
											<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>BRANCH</th>
														<th>ITEM/SERVICE NAME</th>
														<th>QTY</th>
													</tr>
												</thead>
												<tbody>

													<?php if($totalRows_rsodestFrame>0){ 
														$i=1;

														while ($row_rsodestFrame = mysql_fetch_assoc($rsodestFrameReport)){
													//echo $row_rsodestFrame;
															?>
															<tr>
																<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

																<td><?php echo strtoupper(branchName($row_rsodestFrame['branch_id'], $courier)); ?></td>
																<td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodestFrame['item_service_type'].' '.'SOLD') ?></td>
																<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodestFrame['itemCount']; echo strtoupper($row_rsodestFrame['itemCount']); ?></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:bold;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
															<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
														</tr>
													</tbody>
												</table>

											</div>
										</div>



										<div class="row">
											<div class="col-md-12">
												<div id="loadSpecificfrr">
												</div>
												<div id="loadAllfrr">

												</div>	
												
												<table class="table table-bordered">
													<thead>
														<tr>
															<th>SN</th>
															<th>PRICE RANGE (GHS)</th>
															<th style="text-align:center;">ADABRAKA</th>
															<th style="text-align:center;">DANQUAH</th>
															<th style="text-align:center;">WEIJA</th>
															<th style="text-align:center;">KUMASI</th>
															<th style="text-align:center;">ADENTA</th>
															<th style="text-align:center;">TEMA</th>
															<th style="text-align:center;">AHODWO</th>
															<th style="text-align:center;">EAST LEGON</th>
															<th style="text-align:center;">MOBILE UNIT</th>
															<th style="text-align:center;">TOTAL</th>
														</tr>
													</thead>
													<tbody>

														<?php
														function getQty($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
															$getQty12 = "SELECT SUM(qty) AS qty, branch_id FROM claims_details a where a.item_service_type='Optical Frame' and branch_id = '$branch_id' AND unit_price BETWEEN $lower_price AND $upper_price and (a.date_added >= '$start_date' and a.date_added <= '$end_date')";
															$executeGetQty = mysql_query($getQty12, $courier);
															$resultGetQty = mysql_fetch_assoc($executeGetQty);
															return $result = $resultGetQty['qty'];
														}

														function getQtyDetails($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
															$getQty12 = "SELECT SUM(qty) AS qty, branch_id, item, unit_price, provider_item_id FROM claims_details a where a.item_service_type='Optical Frame' and branch_id = '$branch_id' AND unit_price BETWEEN $lower_price AND $upper_price 	and provider_item_id = '$provider_item_id' and (date_added >= '$start_date' and date_added <= '$end_date')";
															$executeGetQty = mysql_query($getQty12, $courier);
															$resultGetQty = mysql_fetch_assoc($executeGetQty);
															return $result = $resultGetQty['qty'];
														}



														$price_range = array('0-200','201-400','401-600','601-800','801-1000','1001-2000','2001-3500','3501-100000');
														$i=0;
														foreach($price_range AS $price){
															list($lower_price, $upper_price) = explode('-',$price);
															$i++
															?>
															<tr style="cursor:pointer;" onclick="$('.details_<?php echo str_replace("-","_",$price);?>').slideToggle();">
																<td><?php echo $i;?></td>
																<td style="font-weight:bold !important;"><?php echo $price; ?></td>
																<td style="font-weight:bold !important;"><?php $adabra = getQty('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																?></td>
																<td style="font-weight:bold !important;"><?php $dan = getQty('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																?></td>
																<td style="font-weight:bold !important;"><?php $weija = getQty('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																?></td>
																<td style="font-weight:bold !important;"><?php $ksi = getQty('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																<td style="font-weight:bold !important;"><?php $aden = getQty('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																<td style="font-weight:bold !important;"><?php $tema = getQty('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																<td style="font-weight:bold !important;"><?php $aho = getQty('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																<td style="font-weight:bold !important;"><?php $east = getQty('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																<td style="font-weight:bold !important;"><?php $mob = getQty('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>

																<td style="font-weight:bold !important;"><?php 
																$total_qty = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob;
																echo $total_qty;
																?></td>
															</tr>


															<tr class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																<td class="details_<?php echo str_replace("-","_",$price);?>" colspan="11" style="display:none;">
																	<div class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																		<?php
																		$list_items1 = "SELECT SUM(qty) AS qty, branch_id, item, unit_price, provider_item_id FROM claims_details a where a.item_service_type='Optical Frame' AND unit_price BETWEEN $lower_price AND $upper_price and (a.date_added >= '$start_date' and a.date_added <= '$end_date')  GROUP BY item";
																		$list_items = mysql_query($list_items1);
																		?>
																		<table class="table table-bordered">
																			<thead>
																				<tr>
																					<th>SN</th>
																					
																					<th style="text-align:center;">ITEM</th>
																					<th style="text-align:center;">PRICE</th>
																					<th style="text-align:center;">ADABRAKA</th>
																					<th style="text-align:center;">DANQUAH</th>
																					<th style="text-align:center;">WEIJA</th>
																					<th style="text-align:center;">KUMASI</th>
																					<th style="text-align:center;">ADENTA</th>
																					<th style="text-align:center;">TEMA</th>
																					<th style="text-align:center;">AHODWO</th>
																					<th style="text-align:center;">EAST LEGON</th>
																					<th style="text-align:center;">MOBILE UNIT</th>
																					<th style="text-align:center;">TOTAL</th>
																				</tr>
																			</thead>
																			<?php while($r=mysql_fetch_assoc($list_items)){
																				$provider_item_id1 = $r['provider_item_id'];
																				?>
																				<tr>
																					<td></td>
																					<td><?php echo $r['item']; ?></td>
																					<td style="font-weight:bold !important;"><?php echo number_format($r['unit_price'],2); ?></td>

																					<td style="font-weight:bold !important;"><?php $adabra = getQtyDetails('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra; };  ?></td>

																					<td style="font-weight:bold !important;"><?php $dan = getQtyDetails('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($dan == "" || is_null($dan)){echo "0";}else{echo $dan; };  $danTotal += getQtyDetails('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $weija = getQtyDetails('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($weija == "" || is_null($weija)){echo "0";}else{echo $weija; }; $weijaTotal += getQtyDetails('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $ksi = getQtyDetails('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi; };  $ksiTotal += getQtyDetails('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $aden = getQtyDetails('9',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden; }; $adenTotal += getQtyDetails('9',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $tema = getQtyDetails('3',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema; }; $temaTotal += getQtyDetails('3',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $aho = getQtyDetails('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho; }; $ahoTotal += getQtyDetails('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $east = getQtyDetails('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east; }; $eastTotal += getQtyDetails('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $mob = getQtyDetails('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob; }; $mobTotal += getQtyDetails('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																					<td style="font-weight:bold !important;"><?php $total = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob ; if($total == "" || is_null($total)){echo "0";}else{echo $total; }; ?></td>		
																				</tr>
																			<?php  } ?>
																			<tr> <td colspan="3">TOTAL</td>
																				
																				<td style="font-weight:bold !important;"><?php $adabra = getQty('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																				?></td>
																				<td style="font-weight:bold !important;"><?php $dan = getQty('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																				?></td>
																				<td style="font-weight:bold !important;"><?php $weija = getQty('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																				?></td>
																				<td style="font-weight:bold !important;"><?php $ksi = getQty('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																				<td style="font-weight:bold !important;"><?php $aden = getQty('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																				<td style="font-weight:bold !important;"><?php $tema = getQty('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																				<td style="font-weight:bold !important;"><?php $aho = getQty('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																				<td style="font-weight:bold !important;"><?php $east = getQty('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																				<td style="font-weight:bold !important;"><?php $mob = getQty('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>


																				<td style="font-weight:bold !important;"><?php if($total_qty == ""||is_null($total_qty)){echo "0";}else{echo $total_qty;} ?></td>
																			</tr>

																			
																		</table>
																	</div>
																</td>
															</tr>
														<?php } ?>
													</tbody>
												</table>
											<?php } ?>
										</div>
									</div>


									<?php if ($report_type == "frdr" || $report_type == "ftr" || $report_type == "frrn" ) { ?>
										<div class="row">
											<div class="col-md-6">
												<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
													<thead>
														<tr style="background-color: #333; color: #fff">
															<th>SN</th>
															<th>BRANCH</th>
															<th>ITEM/SERVICE NAME</th>
															<th>QTY</th>
														</tr>
													</thead>
													<tbody>

														<?php if($totalRows_rsodestFrame>0){ 
															$i=1;

															while ($row_rsodestFrame = mysql_fetch_assoc($rsodestFrameReport)){
													//echo $row_rsodestFrame;
																?>
																<tr>
																	<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

																	<td><?php echo strtoupper(branchName($row_rsodestFrame['branch_id'], $courier)); ?></td>

																	<td valign="top" style="cursor: pointer;"><?php if ($report_type == "frdr") {
																		echo strtoupper($row_rsodestFrame['service_type'].' '.'RECEIVED');
																	}else if ($report_type == "ftr") {
																		echo strtoupper($row_rsodestFrame['service_type'].' '.'TRANDFERRED');
																	}else if ($report_type == "frrn") {
																		echo strtoupper($row_rsodestFrame['service_type'].' '.'DAMAGED');
																	} ?>
																		
																	</td>
																	<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodestFrame['itemCount']; echo strtoupper($row_rsodestFrame['itemCount']); ?></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:bold;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
																<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
															</tr>
														</tbody>
													</table>

												</div>
											</div>



											<div class="row">
												<div class="col-md-12">
													<h2>FRAMES</h2>
													<table class="table table-bordered">
														<thead>
															<tr style="background-color: #333; color: #fff">
																<th>SN</th>
																<th>PRICE RANGE (GHS)</th>
																<th style="text-align:center;">ADABRAKA</th>
																<th style="text-align:center;">DANQUAH</th>
																<th style="text-align:center;">WEIJA</th>
																<th style="text-align:center;">KUMASI</th>
																<th style="text-align:center;">ADENTA</th>
																<th style="text-align:center;">TEMA</th>
																<th style="text-align:center;">AHODWO</th>
																<th style="text-align:center;">EAST LEGON</th>
																<th style="text-align:center;">MOBILE UNIT</th>
																<th style="text-align:center;">TOTAL</th>
															</tr>
														</thead>
														<tbody>

															<?php

															if ($report_type == "frdr") {
																function getQty($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}



															function getQtyDetails($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}

															}

															if ($report_type == "ftr") {
															
																function getQty($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}


															function getQtyDetails($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}


															}

															if ($report_type == "frrn") {
																function getQty($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}

															function getQtyDetails($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'ORDER BY a.price ASC";
																$executeGetQty = mysql_query($getQty12, $courier);
																$resultGetQty = mysql_fetch_assoc($executeGetQty);
																return $result = $resultGetQty['qty'];
															}


															}

															


															



															$price_range = array('0-200','201-400','401-600','601-800','801-1000','1001-2000','2001-3500','3501-100000');
															$i=0;
															foreach($price_range AS $price){
																list($lower_price, $upper_price) = explode('-',$price);
																$i++
																?>
																<tr style="cursor:pointer;" onclick="$('.details_<?php echo str_replace("-","_",$price);?>').slideToggle();">
																	<td><?php echo $i;?></td>
																	<td style="font-weight:bold !important;"><?php echo $price; ?></td>
																	<td style="font-weight:bold !important;"><?php $adabra = getQty('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																	?></td>
																	<td style="font-weight:bold !important;"><?php $dan = getQty('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																	?></td>
																	<td style="font-weight:bold !important;"><?php $weija = getQty('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																	?></td>
																	<td style="font-weight:bold !important;"><?php $ksi = getQty('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																	<td style="font-weight:bold !important;"><?php $aden = getQty('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																	<td style="font-weight:bold !important;"><?php $tema = getQty('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																	<td style="font-weight:bold !important;"><?php $aho = getQty('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																	<td style="font-weight:bold !important;"><?php $east = getQty('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																	<td style="font-weight:bold !important;"><?php $mob = getQty('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>
																	<td style="font-weight:bold !important;"><?php 
																	$total_qty = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob;
																	echo $total_qty;
																	?></td>
																</tr>


																<tr class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																	<td class="details_<?php echo str_replace("-","_",$price);?>" colspan="11" style="display:none;">
																		<div class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																			<?php

																				if ($report_type == "frdr") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'  GROUP BY a.item ORDER BY a.price ASC";
																			$list_items = mysql_query($list_items1);
																				}

																				if ($report_type == "ftr") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'  GROUP BY a.item ORDER BY a.price ASC";
																			$list_items = mysql_query($list_items1);
																				}


																				if ($report_type == "frrn") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type='Optical Frame') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'  GROUP BY a.item ORDER BY a.price ASC";
																			$list_items = mysql_query($list_items1);
																				}

																		




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

																						<th style="text-align:center;">ITEM</th>
																						<th style="text-align:center;">TYPE</th>
																						<th style="text-align:center;">PRICE</th>
																						<th style="text-align:center;">ADABRAKA</th>
																						<th style="text-align:center;">DANQUAH</th>
																						<th style="text-align:center;">WEIJA</th>
																						<th style="text-align:center;">KUMASI</th>
																						<th style="text-align:center;">ADENTA</th>
																						<th style="text-align:center;">TEMA</th>
																						<th style="text-align:center;">AHODWO</th>
																						<th style="text-align:center;">EAST LEGON</th>
																						<th style="text-align:center;">MOBILE UNIT</th>
																						<th style="text-align:center;">TOTAL</th>
																					</tr>
																				</thead>
																				<?php while($r=mysql_fetch_assoc($list_items)){
																					$provider_item_id1 = $r['item_id'];
																					?>
																					<tr>
																						<td></td>
																						<td><?php echo $r['item']; ?></td>
																						<td><?php echo $r['service_type']; ?></td>
																						<td style="font-weight:bold !important;"><?php echo number_format($r['price'],2); ?></td>

																						<td style="font-weight:bold !important;">
																							<?php 
																							$adabra = getQtyDetails('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); 
																							if($adabra == "" || is_null($adabra)){
																								echo "0";
																							}else{
																								echo $adabra;
																							};  
																							$adabraTotal += getQtyDetails('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date);
																							?></td>

																							<td style="font-weight:bold !important;"><?php $dan = getQtyDetails('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($dan == "" || is_null($dan)){echo "0";}else{echo $dan; };  $danTotal += getQtyDetails('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $weija = getQtyDetails('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($weija == "" || is_null($weija)){echo "0";}else{echo $weija; }; $weijaTotal += getQtyDetails('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $ksi = getQtyDetails('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi; };  $ksiTotal += getQtyDetails('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $aden = getQtyDetails('9',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden; }; $adenTotal += getQtyDetails('9',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $tema = getQtyDetails('3',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema; }; $temaTotal += getQtyDetails('3',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $aho = getQtyDetails('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho; }; $ahoTotal += getQtyDetails('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $east = getQtyDetails('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east; }; $eastTotal += getQtyDetails('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $mob = getQtyDetails('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob; }; $mobTotal += getQtyDetails('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																							<td style="font-weight:bold !important;"><?php $total = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob ; if($total == "" || is_null($total)){echo "0";}else{echo $total; }; ?></td>		
																						</tr>
																					<?php  } ?>
																					<tr> <td colspan="4">TOTAL</td>

																						<td style="font-weight:bold !important;"><?php $adabra = getQty('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																						?></td>
																						<td style="font-weight:bold !important;"><?php $dan = getQty('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																						?></td>
																						<td style="font-weight:bold !important;"><?php $weija = getQty('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																						?></td>
																						<td style="font-weight:bold !important;"><?php $ksi = getQty('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																						<td style="font-weight:bold !important;"><?php $aden = getQty('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																						<td style="font-weight:bold !important;"><?php $tema = getQty('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																						<td style="font-weight:bold !important;"><?php $aho = getQty('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																						<td style="font-weight:bold !important;"><?php $east = getQty('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																						<td style="font-weight:bold !important;"><?php $mob = getQty('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>
																						<td style="font-weight:bold !important;"><?php if($total_qty == ""||is_null($total_qty)){echo "0";}else{echo $total_qty;} ?></td>
																					</tr>
																				</table>
																			</div>
																		</td>
																	</tr>

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








												<div class="row">
													<div class="col-md-12">
														<h2>LENS</h2>
														<table class="table table-bordered">
															<thead>
																<tr style="background-color: #333; color: #fff">
																	<th>SN</th>
																	<th>PRICE RANGE (GHS)</th>
																	<th style="text-align:center;">ADABRAKA</th>
																	<th style="text-align:center;">DANQUAH</th>
																	<th style="text-align:center;">WEIJA</th>
																	<th style="text-align:center;">KUMASI</th>
																	<th style="text-align:center;">ADENTA</th>
																	<th style="text-align:center;">TEMA</th>
																	<th style="text-align:center;">AHODWO</th>
																	<th style="text-align:center;">EAST LEGON</th>
																	<th style="text-align:center;">MOBILE UNIT</th>
																	<th style="text-align:center;">TOTAL</th>
																</tr>
															</thead>
															<tbody>

																<?php
																if ($report_type == "frdr") {
																		function getQty1($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}


																function getQtyDetails1($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received' ORDER BY a.price ASC";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}
																}

																if ($report_type == "ftr") {
																		function getQty1($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}


																function getQtyDetails1($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred' ORDER BY a.price ASC";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}
																}

																if ($report_type == "frrn") {
																		function getQty1($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}


																function getQtyDetails1($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																	$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged' ORDER BY a.price ASC";
																	$executeGetQty = mysql_query($getQty12, $courier);
																	$resultGetQty = mysql_fetch_assoc($executeGetQty);
																	return $result = $resultGetQty['qty'];
																}
																}



															



																$price_range = array('0-200','201-400','401-600','601-800','801-1000','1001-2000','2001-3500','3501-100000');
																$i=0;
																foreach($price_range AS $price){
																	list($lower_price, $upper_price) = explode('-',$price);
																	$i++
																	?>
																	<tr style="cursor:pointer;" onclick="$('.details1_<?php echo str_replace("-","_",$price);?>').slideToggle();">
																		<td><?php echo $i;?></td>
																		<td style="font-weight:bold !important;"><?php echo $price; ?></td>
																		<td style="font-weight:bold !important;"><?php $adabra = getQty1('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																		?></td>
																		<td style="font-weight:bold !important;"><?php $dan = getQty1('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																		?></td>
																		<td style="font-weight:bold !important;"><?php $weija = getQty1('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																		?></td>
																		<td style="font-weight:bold !important;"><?php $ksi = getQty1('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																		<td style="font-weight:bold !important;"><?php $aden = getQty1('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																		<td style="font-weight:bold !important;"><?php $tema = getQty1('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																		<td style="font-weight:bold !important;"><?php $aho = getQty1('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																		<td style="font-weight:bold !important;"><?php $east = getQty1('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																		<td style="font-weight:bold !important;"><?php $mob = getQty1('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>
																		<td style="font-weight:bold !important;"><?php 
																		$total_qty = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob;
																		echo $total_qty;
																		?></td>
																	</tr>
																	<tr class="details1_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																		<td class="details1_<?php echo str_replace("-","_",$price);?>" colspan="11" style="display:none;">
																			<div class="details1_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																				<?php

																				if ($report_type == "frdr") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'  GROUP BY a.item ORDER BY a.price ASC";
																				$list_items = mysql_query($list_items1);
																				}


																				if ($report_type == "ftr") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'  GROUP BY a.item ORDER BY a.price ASC";
																				$list_items = mysql_query($list_items1);
																				}

																				if ($report_type == "frrn") {
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Lens') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'  GROUP BY a.item ORDER BY a.price ASC";
																				$list_items = mysql_query($list_items1);
																				}

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

																							<th style="text-align:center;">ITEM</th>
																							<th style="text-align:center;">TYPE</th>
																							<th style="text-align:center;">PRICE</th>
																							<th style="text-align:center;">ADABRAKA</th>
																							<th style="text-align:center;">DANQUAH</th>
																							<th style="text-align:center;">WEIJA</th>
																							<th style="text-align:center;">KUMASI</th>
																							<th style="text-align:center;">ADENTA</th>
																							<th style="text-align:center;">TEMA</th>
																							<th style="text-align:center;">AHODWO</th>
																							<th style="text-align:center;">EAST LEGON</th>
																							<th style="text-align:center;">MOBILE UNIT</th>
																							<th style="text-align:center;">TOTAL</th>
																						</tr>
																					</thead>
																					<?php while($r=mysql_fetch_assoc($list_items)){
																						$provider_item_id1 = $r['item_id'];
																						?>
																						<tr>
																							<td></td>
																							<td><?php echo $r['item']; ?></td>
																							<td><?php echo $r['service_type']; ?></td>
																							<td style="font-weight:bold !important;"><?php echo number_format($r['price'],2); ?></td>

																							<td style="font-weight:bold !important;">
																								<?php 
																								$adabra = getQtyDetails1('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); 
																								if($adabra == "" || is_null($adabra)){
																									echo "0";
																								}else{
																									echo $adabra;
																								};  
																								$adabraTotal1 += getQtyDetails1('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date);
																								?></td>

																								<td style="font-weight:bold !important;"><?php $dan = getQtyDetails1('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($dan == "" || is_null($dan)){echo "0";}else{echo $dan; };  $danTotal1 += getQtyDetails1('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $weija = getQtyDetails1('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($weija == "" || is_null($weija)){echo "0";}else{echo $weija; }; $weijaTotal1 += getQtyDetails1('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $ksi = getQtyDetails1('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi; };  $ksiTotal1 += getQtyDetails1('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $aden = getQtyDetails1('9',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden; }; $adenTotal1 += getQtyDetails1('9',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $tema = getQtyDetails1('3',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema; }; $temaTotal1 += getQtyDetails1('3',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $aho = getQtyDetails1('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho; }; $ahoTotal1 += getQtyDetails1('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $east = getQtyDetails1('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east; }; $eastTotal1 += getQtyDetails1('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $mob = getQtyDetails1('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob; }; $mobTotal1 += getQtyDetails1('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																								<td style="font-weight:bold !important;"><?php $total = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob ; if($total == "" || is_null($total)){echo "0";}else{echo $total; }; ?></td>		
																							</tr>
																						<?php  } ?>
																						<tr> <td colspan="4">TOTAL</td>

																							<td style="font-weight:bold !important;"><?php $adabra = getQty1('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																							?></td>
																							<td style="font-weight:bold !important;"><?php $dan = getQty1('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																							?></td>
																							<td style="font-weight:bold !important;"><?php $weija = getQty1('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																							?></td>
																							<td style="font-weight:bold !important;"><?php $ksi = getQty1('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																							<td style="font-weight:bold !important;"><?php $aden = getQty1('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																							<td style="font-weight:bold !important;"><?php $tema = getQty1('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																							<td style="font-weight:bold !important;"><?php $aho = getQty1('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																							<td style="font-weight:bold !important;"><?php $east = getQty1('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																							<td style="font-weight:bold !important;"><?php $mob = getQty1('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>

																							<td style="font-weight:bold !important;"><?php if($total_qty1 == ""||is_null($total_qty1)){echo "0";}else{echo $total_qty1;} ?></td>
																						</tr>
																					</table>
																				</div>
																			</td>
																		</tr>
																	<?php } ?>

																</tbody>
															</table>
														</div>
													</div>


													<div class="row">
														<div class="col-md-12">
															<h2>ACCESSORIES</h2>
															<table class="table table-bordered">
																<thead>
																	<tr style="background-color: #333; color: #fff">
																		<th>SN</th>
																		<th>PRICE RANGE (GHS)</th>
																		<th style="text-align:center;">ADABRAKA</th>
																		<th style="text-align:center;">DANQUAH</th>
																		<th style="text-align:center;">WEIJA</th>
																		<th style="text-align:center;">KUMASI</th>
																		<th style="text-align:center;">ADENTA</th>
																		<th style="text-align:center;">TEMA</th>
																		<th style="text-align:center;">AHODWO</th>
																		<th style="text-align:center;">EAST LEGON</th>
																		<th style="text-align:center;">MOBILE UNIT</th>
																		<th style="text-align:center;">TOTAL</th>
																	</tr>
																</thead>
																<tbody>

																	<?php
																	if ($report_type == "frdr") {
																			function getQty2($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}


																	function getQtyDetails2($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received' ORDER BY a.price ASC";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}
																	}

																	if ($report_type == "ftr") {
																		function getQty2($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}


																	function getQtyDetails2($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred' ORDER BY a.price ASC";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}
																	}

																	if ($report_type == "frrn") {
																		function getQty2($branch_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT a.item,SUM(a.qty) AS qty, delivery_location AS branch_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price and (b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}


																	function getQtyDetails2($branch_id, $provider_item_id, $courier, $lower_price, $upper_price, $start_date, $end_date){
																		$getQty12 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, item, a.price, item_id FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') and delivery_location = '$branch_id' AND a.price BETWEEN $lower_price AND $upper_price 	and item_id = '$provider_item_id' and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged' ORDER BY a.price ASC";
																		$executeGetQty = mysql_query($getQty12, $courier);
																		$resultGetQty = mysql_fetch_assoc($executeGetQty);
																		return $result = $resultGetQty['qty'];
																	}
																	}

																	



																	$price_range = array('0-200','201-400','401-600','601-800','801-1000','1001-2000','2001-3500','3501-100000');
																	$i=0;
																	foreach($price_range AS $price){
																		list($lower_price, $upper_price) = explode('-',$price);
																		$i++
																		?>
																		<tr style="cursor:pointer;" onclick="$('.details2_<?php echo str_replace("-","_",$price);?>').slideToggle();">
																			<td><?php echo $i;?></td>
																			<td style="font-weight:bold !important;"><?php echo $price; ?></td>
																			<td style="font-weight:bold !important;"><?php $adabra = getQty2('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																			?></td>
																			<td style="font-weight:bold !important;"><?php $dan = getQty2('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																			?></td>
																			<td style="font-weight:bold !important;"><?php $weija = getQty2('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																			?></td>
																			<td style="font-weight:bold !important;"><?php $ksi = getQty2('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																			<td style="font-weight:bold !important;"><?php $aden = getQty2('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																			<td style="font-weight:bold !important;"><?php $tema = getQty2('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																			<td style="font-weight:bold !important;"><?php $aho = getQty2('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																			<td style="font-weight:bold !important;"><?php $east = getQty2('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																			<td style="font-weight:bold !important;"><?php $mob = getQty2('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>
																			<td style="font-weight:bold !important;"><?php 
																			$total_qty = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob;
																			echo $total_qty;
																			?></td>
																		</tr>

																		<tr class="details2_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																			<td class="details2_<?php echo str_replace("-","_",$price);?>" colspan="11" style="display:none;">
																				<div class="details2_<?php echo str_replace("-","_",$price);?>" style="display:none;">
																					<?php

																					if($report_type == "frdr"){
																							$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'received'  GROUP BY a.item ORDER BY a.price ASC";
																					$list_items = mysql_query($list_items1);
																					}

																					if($report_type == "ftr"){
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'tranferred'  GROUP BY a.item ORDER BY a.price ASC";
																					$list_items = mysql_query($list_items1);
																					}


																					if($report_type == "frrn"){
																						$list_items1 = "SELECT SUM(a.qty) AS qty, delivery_location AS branch_id, a.item, a.price, item_id,a.service_type FROM transfer_order_details a INNER JOIN transfer_orders b ON b.purchase_order_no = a.purchase_order_no where (a.service_type = 'Optical Accessories') AND a.price BETWEEN $lower_price AND $upper_price and(b.supplied_date >= '$start_date' and b.supplied_date <= '$end_date') AND a.order_status = 'damaged'  GROUP BY a.item ORDER BY a.price ASC";
																					$list_items = mysql_query($list_items1);
																					}

																					



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

																								<th style="text-align:center;">ITEM</th>
																								<th style="text-align:center;">TYPE</th>
																								<th style="text-align:center;">PRICE</th>
																								<th style="text-align:center;">ADABRAKA</th>
																								<th style="text-align:center;">DANQUAH</th>
																								<th style="text-align:center;">WEIJA</th>
																								<th style="text-align:center;">KUMASI</th>
																								<th style="text-align:center;">ADENTA</th>
																								<th style="text-align:center;">TEMA</th>
																								<th style="text-align:center;">AHODWO</th>
																								<th style="text-align:center;">EAST LEGON</th>
																								<th style="text-align:center;">MOBILE UNIT</th>
																								<th style="text-align:center;">TOTAL</th>
																							</tr>
																						</thead>
																						<?php while($r=mysql_fetch_assoc($list_items)){
																							$provider_item_id1 = $r['item_id'];
																							?>
																							<tr>
																								<td></td>
																								<td><?php echo $r['item']; ?></td>
																								<td><?php echo $r['service_type']; ?></td>
																								<td style="font-weight:bold !important;"><?php echo number_format($r['price'],2); ?></td>

																								<td style="font-weight:bold !important;">
																									<?php 
																									$adabra = getQtyDetails2('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); 
																									if($adabra == "" || is_null($adabra)){
																										echo "0";
																									}else{
																										echo $adabra;
																									};  
																									$adabraTotal1 += getQtyDetails2('1',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date);
																									?></td>

																									<td style="font-weight:bold !important;"><?php $dan = getQtyDetails2('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($dan == "" || is_null($dan)){echo "0";}else{echo $dan; };  $danTotal2 += getQtyDetails2('7',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $weija = getQtyDetails2('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($weija == "" || is_null($weija)){echo "0";}else{echo $weija; }; $weijaTotal2 += getQtyDetails2('8',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $ksi = getQtyDetails2('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi; };  $ksiTotal2 += getQtyDetails2('2',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $aden = getQtyDetails2('9',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden; }; $adenTotal2 += getQtyDetails2('9',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $tema = getQtyDetails2('3',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema; }; $temaTotal2 += getQtyDetails2('3',$provider_item_id1, $courier, $lower_price, $upper_price, $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $aho = getQtyDetails2('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho; }; $ahoTotal2 += getQtyDetails2('13',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $east = getQtyDetails2('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east; }; $eastTotal2 += getQtyDetails2('12',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $mob = getQtyDetails2('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob; }; $mobTotal2 += getQtyDetails2('10',$provider_item_id1, $courier, $lower_price, $upper_price , $start_date, $end_date); ?></td>

																									<td style="font-weight:bold !important;"><?php $total = $adabra + $dan + $weija + $ksi + $aden + $tema + $aho + $east + $mob ; if($total == "" || is_null($total)){echo "0";}else{echo $total; }; ?></td>		
																								</tr>
																							<?php  } ?>
																							<tr> <td colspan="4">TOTAL</td>

																								<td style="font-weight:bold !important;"><?php $adabra = getQty2('1', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($adabra == "" || is_null($adabra)){echo "0";}else{echo $adabra;};
																								?></td>
																								<td style="font-weight:bold !important;"><?php $dan = getQty2('7', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($dan == "" || is_null($dan)){echo "0";}else{echo $dan;}
																								?></td>
																								<td style="font-weight:bold !important;"><?php $weija = getQty2('8', $courier, $lower_price, $upper_price, $start_date, $end_date); if ($weija == "" || is_null($weija)){echo "0";}else{ echo $weija;}
																								?></td>
																								<td style="font-weight:bold !important;"><?php $ksi = getQty2('2', $courier, $lower_price, $upper_price, $start_date, $end_date); if($ksi == "" || is_null($ksi)){echo "0";}else{echo $ksi;} ?></td>

																								<td style="font-weight:bold !important;"><?php $aden = getQty2('9', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aden == "" || is_null($aden)){echo "0";}else{echo $aden;} ?></td>

																								<td style="font-weight:bold !important;"><?php $tema = getQty2('3', $courier, $lower_price, $upper_price, $start_date, $end_date); if($tema == "" || is_null($tema)){echo "0";}else{echo $tema;} ?></td>
																								<td style="font-weight:bold !important;"><?php $aho = getQty2('13', $courier, $lower_price, $upper_price, $start_date, $end_date); if($aho == "" || is_null($aho)){echo "0";}else{echo $aho;} ?></td>
																								<td style="font-weight:bold !important;"><?php $east = getQty2('12', $courier, $lower_price, $upper_price, $start_date, $end_date); if($east == "" || is_null($east)){echo "0";}else{echo $east;} ?></td>
																								<td style="font-weight:bold !important;"><?php $mob = getQty2('10', $courier, $lower_price, $upper_price, $start_date, $end_date); if($mob == "" || is_null($mob)){echo "0";}else{echo $mob;} ?></td>

																								<td style="font-weight:bold !important;"><?php if($total_qty2 == ""||is_null($total_qty2)){echo "0";}else{echo $total_qty2;} ?></td>
																							</tr>
																						</table>
																					</div>
																				</td>
																			</tr>

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


													<?php if ($report_type == "pdr") { ?>
														<div class="row">
															<div class="col-md-6">
																<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
																	<thead>
																		<tr style="background-color: #333; color: white;">
																			<th>SN</th>
																			<th>BRANCH</th>
																			<th>ITEM/SERVICE NAME</th>
																			<th>QTY</th>
																		</tr>
																	</thead>
																	<tbody>

																		<?php if($pending_diagnostic2>0){ 
																			$i=1;
																			while ($row_rsodest = mysql_fetch_assoc($pending_diagnostic1)){  ?>
																				<tr>
																					<td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>

																					<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAllpdr','loadSpecificpdr', 'pdr', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="cursor: pointer;"><?php echo strtoupper(branchName($row_rsodest['branch_id'], $courier)); ?></td>
																					<td valign="top" style="cursor: pointer;">PENDING DIAGNOSTIC</td>
																					<td valign="top" style="cursor: pointer;"><?php $total_amount += $row_rsodest['itemCount']; echo strtoupper($row_rsodest['itemCount']); ?></td>

																				</tr>



																				<?php $i++; } 
																			} else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>';} ?>
																			<tr>
																				<td onclick="loadAdminReport('<?php echo $row_rsodest['branch_id'] ?>', 'loadAllpdr','loadSpecificpdr', 'pdr1', '<?php echo $start_date?>','<?php echo $end_date ?>')" style="font-weight:bold; cursor: pointer;" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
																				<td style="font-weight:bold;"> <?php echo $total_amount ; ?> </td>
																			</tr>
																		</tbody>
																	</table>

																</div>

																<div class="col-md-6">
																	<div id="loadAllpdr">
																		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
																			<thead>
																				<tr style="background-color: #333; color: white;">
																					<th>SN</th>
																					<th>NAME</th>
																					<th>QTY</th>
																				</tr>
																			</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>

																		</div>
																		<div id="loadSpecificpdr">

																		</div>
																	</div>
																</div>
															<?php } ?>


															<?php if ($report_type == "lrt") {
																	if ($lens_type12) { ?>
																		<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;">LENS TYPE</th>
																								<th style="text-align:center;">ADDITIONS</th>
																								<th style="text-align:center;">EXTRA ADDITIONS</th>
																								<th style="text-align:center;">COUNT</th>
																							</tr>
																						</thead>

																						<tbody>
																							<?php 
																						$count = 0;
																							while ($row = mysql_fetch_assoc($lens_type1)) {
																								$count ++;
																							 ?>
																							<tr>
																								<td><?php echo $count; ?></td>
																								<td><?php echo strtoupper($lens_type) ?></td>
																								<td><?php if($lens_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></td>
																								<td><?php if($lens_extra_additions == ""){echo "None";}else{ echo strtoupper($lens_extra_additions);} ?></td>
																								<td><?php echo $row['lenseCount']; ?></td>
																							</tr>
																						<?php } ?>
																						</tbody>
																					</table>
															<?php } 
															if ($lens_type) {?>

																	<div class="row">
																		<div class="col-md-6">
																			<table class="table table-bordered">
																						<thead>
																							<tr style="background-color: #333; color: #fff">
																								<th style="text-align:center;" colspan="4"><?php echo strtoupper($lens_type.'-'.$lens_additions) ?></th>
																							</tr>
																							<tr style="background-color: #333; color: #fff">
																								<th style="text-align:center;">NO</th>
																								<th style="text-align:center;">BRANCHES</th>
																								<th style="text-align:center;">ITEM</th>
																								<th style="text-align:center;">QTY</th>
																								
																							</tr>
																						</thead>

																						<tbody>
																							<?php 
																						
																						$count = 0;
																							while ($row = mysql_fetch_assoc($lens_type_summary1)) {
																								$count ++;
																							 ?>
																							<tr>
																								<td><?php echo $count; ?></td>
																							 <td onclick="loadAdminReportlrt('<?php echo $row['branch_id'] ?>', 'loadAlllrt','loadSpecificlrt', 'lrt', '<?php echo $start_date?>','<?php echo $end_date ?>', '<?php echo $lens_type ?>', '<?php echo $lens_additions ?>', '<?php echo $eye_type ?>')" style="cursor: pointer"><?php echo strtoupper(branchName($row['branch_id'], $courier)); ?></td>
																							 <td><?php echo "LENS SOLD" ?></td>
																							 <td><?php echo $row['count']; $totalQty += $row['count']; ?></td>
																							</tr>
																						<?php } ?>
																						<tr onclick="loadAdminReportlrt('<?php echo $row['branch_id'] ?>', 'loadAlllrt','loadSpecificlrt', 'lrt1', '<?php echo $start_date?>','<?php echo $end_date ?>', '<?php echo $eye_type ?>')">
															<td style="font-weight:bold; cursor: pointer" colspan="<?php if($payment_methods == 'insurance' || $payment_methods == 'company'){ echo 3;}else{ echo 3;} ?>">OVERALL TOTAL AMOUNT </td>
															<td style="font-weight:bold;"> <?php echo $totalQty ; ?> </td>
														</tr>
																						</tbody>
																					</table>
																		</div>

                                                                        <div class="col-md-6">
                                                                            <div id="loader_div" style="display: none">
                                                                                <img src="../images/loader.gif">
                                                                                Please wait.......
                                                                            </div>
                                                                        </div>

																	</div>

																	<div id="loadAlllrt">



                                                                        <?php if ($eye_type == 'all'){ ?>
                                                                            <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_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></td>
                                                                                                <td><?php echo $row['countl']; ?></td>
                                                                                            </tr>
                                                                                        <?php } ?>
                                                                                    </table>
                                                                                </div>
                                                                            </div>

                                                                    <?php } else { ?>

																			<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_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></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_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></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_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></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_additions == ""){ echo "None";}else{ echo strtoupper($lens_additions);} ?></td>
                                                                                                        <td><?php echo $row['count']; ?></td>
                                                                                                    </tr>

                                                                                                <?php }?>

																						<?php } ?>

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

																	<div id="loadSpecificlrt">
																		
																	</div>
														<?php } } ?>
														</body>

														<script type="text/javascript" src="../assets/scripts/leftmenu.js"></script>