<?php
if (!isset($_SESSION)) {
    session_start();
}

require_once("Connections/constants.php");
include("function/function.php");
$apikey = $_SESSION['benefit_api_key'];
$facility_name = $_SESSION['facility_name'];
$password = $_SESSION['password'];
$providerId = $_SESSION['provider_id'];
$policyNo =  $_SESSION['member_id'];


    $SAVE_PERSONAL_MEDICATION1 = array(
        'APIKEY' => '5146fc1e5b01711fd2db12297beca4ea',
        'PROVIDERID' =>$providerId,
        'POLICYNO' =>$policyNo,
        'INSCOMPANYCODE' =>trim($facility_name)
    );
    
    $get_saved_record_all = benefitsAPI($SAVE_PERSONAL_MEDICATION1);
    $get_saved_record_json_all = json_decode($get_saved_record_all, "true");
    $savedRecord_out_patient = $get_saved_record_json_all['Out-Patient-Limit'];
    $savedRecord_In_Patient_Limit = $get_saved_record_json_all['In-Patient-Limit'];
    $savedRecord_out_uti = $get_saved_record_json_all['Out-Patient'];
    $savedRecord_In_Patient_uti = $get_saved_record_json_all['In-Patient'];

    $savedRecord_benefit = $get_saved_record_json_all['results'];
    // foreach ($savedRecord_benefit as $savedRecord_benefit1) {
    // 	echo $name = $savedRecord_benefit1['benefit_group_name'].$savedRecord_benefit1['group_balance'];
    // }
    
?>
<!-- <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js" async defer></script> -->
  <script src="<?php echo BASE_URL ?>assets/js/google_chart.js" type="text/javascript"></script>

<div class="kt-portlet__body" style="height:auto; overflow-y: auto;">
	<h4 style="text-align: center; padding-top: 15px">BENEFIT INFORMATION</h4>
  <div class="row">
   <div class="col-md-12">
    <div class="row">

 	<div class="col-md-6">
      <div id="donutchart" style="width: 100%; height: 500px;"></div>
    </div>

     <div class="col-md-6">
     <div id="top_x_div" style="width: 100px; height: 500px;"></div>
    </div>
    </div>
    </div>
</div>
</div>




<script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Item', 'Amount'],
          ['Out-Patient-Limit',     <?php echo $savedRecord_out_patient ?>],
          ['In-Patient-Limit',      <?php echo $savedRecord_In_Patient_Limit ?>],
          ['Out-Patient Utilized',  <?php echo $savedRecord_out_uti ?>],
          ['In-Patient Utilized', <?php echo $savedRecord_In_Patient_uti ?>],
          
        ]);

        var options = {
          title: '',
          pieHole: 0.4,
        };

        var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
        chart.draw(data, options);
      }
    </script>

    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawStuff);

      function drawStuff() {
        var data = new google.visualization.arrayToDataTable([
          ['Item', 'Amount'],
          

          <?php 
          	foreach ($savedRecord_benefit as $savedRecord_benefits) {
          		
          	echo "['".$savedRecord_benefits['benefit_group_name']."', ".$savedRecord_benefits['group_balance']."],";
          	}
           ?>

        
        ]);

        var options = {
          title: 'Item',
          width: 500,
          legend: { position: 'none' },
          chart: { title: '',
                   subtitle: '' },
          bars: 'horizontal', // Required for Material Bar Charts.
          axes: {
            x: {
              0: { side: 'top', label: 'Amount'} // Top x-axis.
            }
          },
          bar: { groupWidth: "90%" }
        };

        var chart = new google.charts.Bar(document.getElementById('top_x_div'));
        chart.draw(data, options);
      };
    </script>

