<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$user_type = $_SESSION["user_type"];
$user_session = $_SESSION["user_session"];
$amt=4;
$id1 = base64_decode($_GET['id']);
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
$dataPoints = array();
$dataPoints_value = array();
$kj=0;
if(isset($_POST['sub']))
{
	$type_graph=$_POST['graph_type'];
	if($type_graph=='FTD')
	{
		date_default_timezone_set('Asia/Calcutta');
		$cdate  = date("Y-m-d");
		$ctime = date('h:i:sa');
		$select_product = mysqli_query($con,"select * from tbl_insurance_company where admin_id='$admin_id'");
		if(mysqli_num_rows($select_product)>0)
		{     
			while($fetch_product=mysqli_fetch_assoc($select_product))
			{
				$comp_name=$fetch_product['company_name'];
				$comp_id=$fetch_product['company_id'];
				$select_detail = mysqli_query($con,"select sum(tbl_customer_premium.premium_amt) as final_net_amt from tbl_customer,tbl_customer_premium,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_customer_premium.customer_id=tbl_customer.customer_id and tbl_customer_premium.policy_no=tbl_policy_master.policy_no and tbl_policy_master.company_id='$comp_id' and tbl_customer_premium.status='Complete' and tbl_customer_premium.complete_date='$cdate' group by tbl_policy_master.company_id");
				if(mysqli_num_rows($select_detail)>0)
				{ 
					while($fetch_data=mysqli_fetch_assoc($select_detail))
					{
						$amt=$fetch_data['final_net_amt'];
						$dataPoints[$kj]=$amt;
						$dataPoints_value[$kj]=$comp_name;
						$kj++;
					}
				}
			}
		}
	}
	else if($type_graph=='MTD')
	{
		$cdate11  = date("m");
		$cdate12  = date("Y");
		if(strlen($cdate11)==1)
			$cdate11="0".$cdate11;
		$cdate1 = $cdate12."-".$cdate11."-01";
		$cdate2 = $cdate12."-".$cdate11."-30";
		$cdate2=date("Y-m-t", strtotime($cdate2));
		$select_product = mysqli_query($con,"select * from tbl_insurance_company where admin_id='$ver'");
		if(mysqli_num_rows($select_product)>0)
		{     
			while($fetch_product=mysqli_fetch_assoc($select_product))
			{
				$data= array();
				$comp_id=$fetch_product['company_id'];
				$comp_name=$fetch_product['company_name'];
				$select_detail = mysqli_query($con,"select sum(tbl_customer_premium.premium_amt) as final_net_amt from tbl_customer,tbl_customer_premium,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_customer_premium.customer_id=tbl_customer.customer_id  and tbl_customer_premium.policy_no=tbl_policy_master.policy_no and tbl_policy_master.company_id='$comp_id' and tbl_customer_premium.status='Complete' and tbl_customer_premium.complete_date>='$cdate1' and tbl_customer_premium.complete_date<='$cdate2' group by tbl_policy_master.company_id");
				if(mysqli_num_rows($select_detail)>0)
				{ 
					while($fetch_data=mysqli_fetch_assoc($select_detail))
					{
						$amt=$fetch_data['final_net_amt'];
						$dataPoints[$kj]=$amt;
						$dataPoints_value[$kj]=$comp_name;
						$kj++;
					}
				}
			}
		}
	}
	else
	{
		$cdate12  = date("Y");
		$cdate1 = $cdate12."-01-01";
		$select_product = mysqli_query($con,"select * from tbl_insurance_company where admin_id='$ver'");
		if(mysqli_num_rows($select_product)>0)
		{     
			while($fetch_product=mysqli_fetch_assoc($select_product))
			{
				$data= array();
				$comp_id=$fetch_product['company_id'];
				$comp_name=$fetch_product['company_name'];
				$select_detail = mysqli_query($con,"select sum(tbl_customer_premium.premium_amt) as final_net_amt from tbl_customer,tbl_customer_premium,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_customer_premium.customer_id=tbl_customer.customer_id and tbl_customer_premium.policy_no=tbl_policy_master.policy_no and tbl_policy_master.company_id='$comp_id' and tbl_customer_premium.status='Complete' and tbl_customer_premium.complete_date>='$cdate1' group by tbl_policy_master.company_id");
				if(mysqli_num_rows($select_detail)>0)
				{ 
					while($fetch_data=mysqli_fetch_assoc($select_detail))
					{
						$amt=$fetch_data['final_net_amt'];
						$dataPoints[$kj]=$amt;
						$dataPoints_value[$kj]=$comp_name;
						$kj++;
					}
				}
			}
		}
	}
}
else
{
	$type_graph='FTD';
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	$ctime = date('h:i:sa');
	$select_product = mysqli_query($con,"select * from tbl_insurance_company where admin_id='$admin_id'");
	if(mysqli_num_rows($select_product)>0)
	{     
		while($fetch_product=mysqli_fetch_assoc($select_product))
		{
			$comp_name=$fetch_product['company_name'];
			$comp_id=$fetch_product['company_id'];
			$select_detail = mysqli_query($con,"select sum(tbl_customer_premium.premium_amt) as final_net_amt from tbl_customer,tbl_customer_premium,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_customer_premium.customer_id=tbl_customer.customer_id and tbl_customer_premium.policy_no=tbl_policy_master.policy_no and tbl_policy_master.company_id='$comp_id' and tbl_customer_premium.status='Complete' and tbl_customer_premium.complete_date='$cdate' group by tbl_policy_master.company_id");
			if(mysqli_num_rows($select_detail)>0)
			{ 
				while($fetch_data=mysqli_fetch_assoc($select_detail))
				{
					$amt=$fetch_data['final_net_amt'];
					$dataPoints[$kj]=$amt;
					$dataPoints_value[$kj]=$comp_name;
					$kj++;
				}
			}
		}
	}	
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>BTCOVER : Admin Dashboard</title>
    <!-- Custom CSS -->
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/jquery-minicolors/jquery.minicolors.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/quill/dist/quill.snow.css">
	<link href="assets/libs/flot/css/float-chart.css" rel="stylesheet">
    <link href="dist/css/style.min.css" rel="stylesheet">
  <script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	theme: "light2", // "light1", "light2", "dark1", "dark2"
	title:{
		text: "<?php echo $type_graph; ?>"
	},
	axisY: {
		title: "Policy Amount"
	},
	data: [{        
		type: "column",  
		showInLegend: true, 
		legendMarkerColor: "grey",
		legendText: "Insurance Company",
		dataPoints: [   
		<?php
			for($hj=0;$hj<sizeof($dataPoints);$hj++) { ?>
				{y: <?php echo $dataPoints[$hj]; ?>,label:"<?php echo $dataPoints_value[$hj]; ?>"},
		<?php } ?>      
		
			
		]
	}]
});
chart.render();

}
</script>
</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
  
	 <div id="main-wrapper">
   <?php include("header.php"); ?>
    
     <?php include("menu.php"); ?>
	
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Transaction Detail</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<li class="breadcrumb-item active" aria-current="page">Transaction Detail</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <form class="form-horizontal" method="post" name="form"  enctype="multipart/form-data">
                                <div class="card-body">
                                   <div class="form-group row">
                                   <div class="col-md-4">	
									<div class="form-group ">
                                      <select class="select2 form-control custom-select" style="width: 100%; height:36px;" name="graph_type" id="graph_type" >
                                           <option value='FTD' SELECTED>FTD</option>
										   <option value='MTD'>MTD</option>
										   <option value='YTD'>YTD</option>
                                      </select>
                                    </div>
                                </div>
								<div class="col-md-4">	
								 <button type="submit" name="sub" class="btn btn-success">Search</button>
								</div>
								
								 </div>
							 </form>
							<div class="col-md-12">
							<div class="card">
                            <div class="card-body">
                               <div id="chartContainer" style="height: 370px; width: 100%;"></div>
								<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
                            </div>
                        </div>
                    </div>
							
							
							
                        </div>
                    
          

                    </div>
              
                </div>
                <!-- editor -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
             <footer class="footer text-center">
                  2019 &copy; All Rights Reserved by BTCOVER. Designed and Developed by <a href="http://www.belltechnology.in/">Bell Technology</a>.
            </footer>
          
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
   <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!-- this page js -->
   
  <script src="dist/canvasjs.min.js"></script>
   
    <script src="assets/libs/flot/jquery.flot.js"></script>
   <script src="assets/libs/chart/matrix.charts.js"></script>
   <script src="assets/libs/chart/turning-series.js"></script>
    
    <script>
        //***********************************//
        // For select 2
        //***********************************//
        $(".select2").select2();

        /*colorpicker*/
        $('.demo').each(function() {
        //
        // Dear reader, it's actually very easy to initialize MiniColors. For example:
        //
        //  $(selector).minicolors();
        //
        // The way I've done it below is just for the demo, so don't get confused
        // by it. Also, data- attributes aren't supported at this time...they're
        // only used for this demo.
        //
        $(this).minicolors({
                control: $(this).attr('data-control') || 'hue',
                position: $(this).attr('data-position') || 'bottom left',

                change: function(value, opacity) {
                    if (!value) return;
                    if (opacity) value += ', ' + opacity;
                    if (typeof console === 'object') {
                        console.log(value);
                    }
                },
                theme: 'bootstrap'
            });

        });
        /*datwpicker*/
        jQuery('.mydatepicker').datepicker();
        jQuery('#datepicker-autoclose').datepicker({
            autoclose: true,
            todayHighlight: true
        });
        var quill = new Quill('#editor', {
            theme: 'snow'
        });

    </script>
</body>

</html>