<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="https://cdn.amcharts.com/lib/5/percent.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>

<div class="content-wrapper">
                <div class="main-content">
                    <!--/.navbar-->
                    <!--Content Header (Page header)-->
                    <div class="content-header row align-items-center m-0">
                        <nav aria-label="breadcrumb" class="col-sm-4 order-sm-last mb-3 mb-sm-0 p-0 ">
                            <ol class="breadcrumb d-inline-flex font-weight-600 fs-13 bg-white mb-0 float-sm-right">
                                <li class="breadcrumb-item"><a href="#">IP</a></li>
                                <li class="breadcrumb-item active"><?php echo $client->client_ip;?></li>
                            </ol>
                        </nav>
                        <div class="col-sm-8 header-title p-0">
                            <div class="media">
                                <div class="header-icon text-success mr-3"><i class="typcn typcn-spiral"></i></div>
                                <div class="media-body">
                                    <h1 class="font-weight-bold"><?php echo $client->client_comp_name;?></h1>
                                    <small><?php echo $client->client_name.' '.$client->client_contact;?></small>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--/.Content Header (Page header)--> 
                    <div class="body-content">
                        <div class="row">
                        <div class="col-md-8">
                        <div class="row">
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-primary text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Out Calls</div>
                                    <div class="fs-32 text-monospace"><?php echo $out=$this->db->get_where("e_cdr_20240825",array("fee>"=>0,"callerip"=>$client->client_ip))->num_rows();?></div>
                                </div>
                            </div>
                            
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-warning text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Purchase</div>
                                    <div class="fs-32 text-monospace">$<?php $this->db->select_sum('fee'); 
									  $this->db->where("callerip",$client->client_ip); 
									  $this->db->where("fee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo $fee1=round($br->fee,2);
									  
									  ?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-danger text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Sell</div>
                                    <div class="fs-32 text-monospace"> $<?php $this->db->select_sum('agentfee'); 
									  $this->db->where("callerip",$client->client_ip); 
									  $this->db->where("agentfee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo  $fee2=round($br->agentfee,2);?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-dark text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Margin</div>
                                    <div class="fs-32 text-monospace">$<?php echo $margin1=$fee2-$fee1;?></div>
                                </div>
                            </div>
                            
                            
                            
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-success text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">In Calls</div>
                                    <div class="fs-32 text-monospace"><?php echo $in=$this->db->get_where("e_cdr_20240825",array("fee>"=>0,"calleeip"=>$client->client_ip))->num_rows();?></div>
                                </div>
                            </div>
                            
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-warning text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Purchase</div>
                                    <div class="fs-32 text-monospace">$<?php $this->db->select_sum('agentfee'); 
									  $this->db->where("calleeip",$client->client_ip); 
									  $this->db->where("agentfee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo $fee11=round($br->agentfee,2);
									  
									  ?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-danger text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Sell</div>
                                    <div class="fs-32 text-monospace"> $<?php $this->db->select_sum('fee'); 
									  $this->db->where("calleeip",$client->client_ip); 
									  $this->db->where("fee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo  $fee22=round($br->fee,2);?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-dark text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Margin</div>
                                    <div class="fs-32 text-monospace">$<?php echo $margin2=$fee22-$fee11;?></div>
                                </div>
                            </div>
                            
                            
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-info text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">In Calls</div>
                                    <div class="fs-32 text-monospace"><?php echo $in+$out;?></div>
                                </div>
                            </div>
                            
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-warning text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Purchase</div>
                                    <div class="fs-32 text-monospace">$<?php echo $tot_purchase=$fee11+$fee1;?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-danger text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Sell</div>
                                    <div class="fs-32 text-monospace"> $<?php echo $tot_sell=$fee22+$fee2;?></div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-3">
                                <!--Active users indicator--> 
                                <div class="p-2 bg-dark text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Margin</div>
                                    <div class="fs-32 text-monospace">$<?php echo $tot_margin=$margin1+$margin2;?></div>
                                </div>
                            </div>
                           <!-- <div class="col-md-3 col-lg-4">
                                <div class="p-2 bg-info text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Right now</div>
                                    <div class="fs-32 text-monospace">90</div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-4">
                                <div class="p-2 bg-info text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Right now</div>
                                    <div class="fs-32 text-monospace">90</div>
                                </div>
                            </div>
                            <div class="col-md-3 col-lg-4"> 
                                <div class="p-2 bg-info text-white rounded mb-3 p-3 shadow-sm text-center">
                                    <div class="opacity-50 header-pretitle fs-11 font-weight-bold text-uppercase">Right now</div>
                                    <div class="fs-32 text-monospace">90</div>
                                </div>
                            </div>-->
                        </div>
                        </div>
                        <div class="col-md-12 col-lg-12 col-xl-4 mb-4">
                                <div class="card">
                                    <div class="card-header">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div>
                                                <h6 class="fs-17 font-weight-600 mb-0">Pie Chart</h6>
                                            </div>
                                            
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <div class="chart mb-3">
                                            <div id="chartdiv" style="width: 100%;  height: 250px;"></div>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="row">
                            
                            <div class="col-md-12 col-lg-12 col-xl-12">
                                <div class="card mb-4">
                                    <div class="card-header">
                                        <h2 class="fs-18 font-weight-bold mb-0">Bar chart</h2>
                                    </div>
                                    <div class="card-body">
                                        <div id="barChart" style="width: 100%;  height: 500px;"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-12">
                                <div class="card">
                                    <div class="card-header">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div>
                                                <h6 class="fs-17 font-weight-600 mb-0">Out Calls</h6>
                                            </div>
                                            
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <table class="table table-bordered">
                                        <thead><tr bgcolor="#CCCCCC"><th>S.No.</th>
                                                   <th>Call To</th>
                                                   <th>Total Calls</th>
                                                   <th>Connected</th>
                                                   <th>Not Connected</th>
                                                   <th>Purchase</th>
                                                   <th>Sell</th>
                                                   <th>Margin</th>
                                                   </tr></thead>
                                        <tbody>
                                        <?php 
										$this->db->select("*");
										$this->db->from("e_cdr_20240825");
										$this->db->group_by("calleeip");
										$this->db->where("callerip",$client->client_ip);
										$data=$this->db->get()->result();
										$total_call=$total_conn=$total_not=$total_fee=$vendor_fee=$margin1=0;
										$i=1;foreach($data as $d){?>
											<tr>
                                            <td><?php echo $i;?></td>
                                            <td><?php echo $d->callerrtpip;?></td>
  <td><?php echo $total=$this->db->get_where("e_cdr_20240825",
  array("callerip"=>$client->client_ip,"calleeip"=>$d->calleeip))->num_rows();$total_call=$total_call+$total;?></td>
                                            <td><?php echo $conn=$this->db->get_where("e_cdr_20240825",
  array("callerip"=>$client->client_ip,"calleeip"=>$d->calleeip,"fee>"=>0))->num_rows();
  $total_conn=$total_conn+$conn;?></td>
                                             <td><?php echo $total-$conn;$total_not=$total_not+$not;?></td>
                                            <td>$<?php $this->db->select_sum('fee'); 
									  $this->db->where("callerip",$client->client_ip); 
									  $this->db->where("calleeip",$d->calleeip); 
									  $this->db->where("fee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo $fee1=round($callerfee=$br->fee,2);
									  $total_fee=$total_fee+$fee1;?></td>
                                            <td>$<?php $this->db->select_sum('agentfee'); 
									  $this->db->where("callerip",$client->client_ip); 
									  $this->db->where("calleeip",$d->calleeip); 
									  $this->db->where("agentfee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo  $fee2=round($calleefee=$br->agentfee,2);
									  $vendor_fee=$vendor_fee+$fee2;?></td>
                                            <td>$<?php echo $margin=$fee2-$fee1;
											$margin1=$margin1+$margin;?></td>
                                            </tr>
											<?php $i++;}
										?>
                                        </tbody>
                                        <tfoot><tr bgcolor="#FF9900">
                                        <th></th>
                                        <th>Total</th>
                                        <th><?php echo $total_call;?></th>
                                        <th><?php echo $total_conn;?></th>
                                        <th><?php echo $total_not;?></th>
                                        <th><?php echo $total_fee;?></th>
                                        <th><?php echo $vendor_fee;?></th>
                                        <th><?php echo $margin1;?></th></tr>
                                        </tfoot>
                                        </table>
                                    </div>
                                </div>
                                <div class="card">
                                    <div class="card-header">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div>
                                                <h6 class="fs-17 font-weight-600 mb-0">In Calls</h6>
                                            </div>
                                            
                                        </div>
                                    </div><div class="card-body">
                                        <table class="table table-bordered">
                                        <thead><tr bgcolor="#CCCCCC"><th>S.No.</th>
                                                   <th>Call From</th>
                                                   <th>Total Calls</th>
                                                   <th>Connected</th>
                                                   <th>Not Connected</th>
                                                   <th>Purchase</th>
                                                   <th>Sell</th>
                                                   <th>Margin</th>
                                                   </tr></thead>
                                        <tbody>
                                        <?php 
										$this->db->select("*");
										$this->db->from("e_cdr_20240825");
										$this->db->group_by("callerip");
										$this->db->where("calleeip",$client->client_ip);
										$data=$this->db->get()->result();
										$total_call=$total_conn=$total_not=$total_fee=$vendor_fee=$margin1=0;
										$i=1;foreach($data as $d){?>
											<tr>
                                            <td><?php echo $i;?></td>
                                            <td><?php echo $d->callerip;?></td>
  <td><?php echo $total=$this->db->get_where("e_cdr_20240825",
  array("calleeip"=>$client->client_ip,"callerip"=>$d->callerip))->num_rows();$total_call=$total_call+$total;?></td>
                                            <td><?php echo $conn=$this->db->get_where("e_cdr_20240825",
  array("calleeip"=>$client->client_ip,"callerip"=>$d->callerip,"fee>"=>0))->num_rows();
  $total_conn=$total_conn+$conn;?></td>
                                             <td><?php echo $not=$total-$conn;$total_not=$total_not+$not;?></td>
                                            <td>$<?php $this->db->select_sum('fee'); 
									  $this->db->where("calleeip",$client->client_ip); 
									  $this->db->where("callerip",$d->callerip); 
									  $this->db->where("fee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo $fee1=round($callerfee=$br->fee,2);
									  $total_fee=$total_fee+$fee1; ?></td>
                                            <td>$<?php $this->db->select_sum('agentfee'); 
									  $this->db->where("calleeip",$client->client_ip); 
									  $this->db->where("callerip",$d->callerip); 
									  $this->db->where("agentfee>",0); 
									  $br=$this->db->get('e_cdr_20240825')->row();
									  echo  $fee2=round($calleefee=$br->agentfee,2);
									  $vendor_fee=$vendor_fee+$fee2;?></td>
                                            <td>$<?php echo $margin=$fee2-$fee1;
											$margin1=$margin1+$margin;?></td>
                                            </tr>
											<?php $i++;}
										?>
                                        </tbody>
                                        <tfoot><tr bgcolor="#FF9900">
                                        <th></th>
                                        <th>Total</th>
                                        <th><?php echo $total_call;?></th>
                                        <th><?php echo $total_conn;?></th>
                                        <th><?php echo $total_not;?></th>
                                        <th><?php echo $total_fee;?></th>
                                        <th><?php echo $vendor_fee;?></th>
                                        <th><?php echo $margin1;?></th></tr>
                                        </tfoot>
                                        </table></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div><!--/.body content-->
                </div><!--/.main content-->
                <footer class="footer-content">
                    <div class="footer-text d-flex align-items-center justify-content-between">
                        <div class="copy">© 2024 CRM</div>
                    </div>
                </footer><!--/.footer content-->
                <div class="overlay"></div>
            </div><!--/.wrapper-->
        </div>
        <script>
		am5.ready(function() {

// Create root element
// https://www.amcharts.com/docs/v5/getting-started/#Root_element
var root = am5.Root.new("chartdiv");

// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
  am5themes_Animated.new(root)
]);

// Create chart
// https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
var chart = root.container.children.push(
  am5percent.PieChart.new(root, {
    endAngle: 270
  })
);

// Create series
// https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Series
var series = chart.series.push(
  am5percent.PieSeries.new(root, {
    valueField: "value",
    categoryField: "category",
    endAngle: 270
  })
);

series.states.create("hidden", {
  endAngle: -90
});

// Set data
// https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Setting_data
series.data.setAll([{
  category: "OUTCALLS",
  value:<?php echo $out;?>
}, {
  category: "INCALLS",
  value: <?php echo $in;?>
}]);

series.appear(1000, 100);


var root = am5.Root.new("barChart");


// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
  am5themes_Animated.new(root)
]);


// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
var chart = root.container.children.push(am5xy.XYChart.new(root, {
  panX: false,
  panY: false,
  paddingLeft: 0,
  wheelX: "panX",
  wheelY: "zoomX",
  layout: root.verticalLayout
}));


// Add legend
// https://www.amcharts.com/docs/v5/charts/xy-chart/legend-xy-series/
var legend = chart.children.push(
  am5.Legend.new(root, {
    centerX: am5.p50,
    x: am5.p50
  })
);

var data = [{
  "Month": "SEP",
  "purchase":<?php echo $tot_purchase;?>,
  "sell": <?php echo $tot_sell;?>,
  "margin": <?php echo $tot_margin;?>,
}]


// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var xRenderer = am5xy.AxisRendererX.new(root, {
  cellStartLocation: 0.1,
  cellEndLocation: 0.9,
  minorGridEnabled: true
})

var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
  categoryField: "Month",
  renderer: xRenderer,
  tooltip: am5.Tooltip.new(root, {})
}));

xRenderer.grid.template.setAll({
  location: 1
})

xAxis.data.setAll(data);

var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
  renderer: am5xy.AxisRendererY.new(root, {
    strokeOpacity: 0.1
  })
}));


// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
function makeSeries(name, fieldName) {
  var series = chart.series.push(am5xy.ColumnSeries.new(root, {
    name: name,
    xAxis: xAxis,
    yAxis: yAxis,
    valueYField: fieldName,
    categoryXField: "Month"
  }));

  series.columns.template.setAll({
    tooltipText: "{name}, {categoryX}:{valueY}",
    width: am5.percent(90),
    tooltipY: 0,
    strokeOpacity: 0
  });

  series.data.setAll(data);

  // Make stuff animate on load
  // https://www.amcharts.com/docs/v5/concepts/animations/
  series.appear();

  series.bullets.push(function () {
    return am5.Bullet.new(root, {
      locationY: 0,
      sprite: am5.Label.new(root, {
        text: "{valueY}",
        fill: root.interfaceColors.get("alternativeText"),
        centerY: 0,
        centerX: am5.p50,
        populateText: true
      })
    });
  });

  legend.data.push(series);
}

makeSeries("Purchase", "purchase");
makeSeries("Sell", "sell");
makeSeries("Margin", "margin");


// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
chart.appear(1000, 100);

}); // end am5.ready()




		</script>
        <script src="<?php echo base_url();?>admin_assets/plugins/metisMenu/metisMenu.min.js"></script>
        <script src="<?php echo base_url();?>admin_assets/plugins/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
        <!-- Third Party Scripts(used by this page)-->
        <script src="<?php echo base_url();?>admin_assets/plugins/datatables/dataTables.min.js"></script>
        <script src="<?php echo base_url();?>admin_assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
        <!--Page Active Scripts(used by this page)-->
        <!--Page Scripts(used by all page)-->
        <script src="<?php echo base_url();?>admin_assets/dist/js/sidebar.js"></script>
        
    </body>
</html>