<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];


if($_REQUEST['sales_year']==''){
 $fdate=date('Y-01-01');
 $tdate=date('Y-12-31');
 $year=date('Y');
 $yr=date('y');
 }else{
 $fdate=$_REQUEST['sales_year'].'-01-01';
 $tdate=$_REQUEST['sales_year'].'-12-31';
 $year = date('Y',strtotime($fdate));
 $yr = date('y',strtotime($fdate));
 }

$yr_sales_amt = find_a_field($conn,'sales_invoice','sum(total_amt)','jv_date BETWEEN "'.$fdate.'" AND "'.$tdate.'"');

$page_title="Dashboard";

?>


<!DOCTYPE html>
<html lang="en">

<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->

<body>

  <!-- ======= Header ======= -->
  
  <?php require_once('inc_files/inc_header.php');?>
  
  <!-- End Header -->

  <!-- ======= Sidebar/Menubar ======= -->
  
  <?php require_once('inc_files/inc_menu.php');?>
  
  <!-- End Sidebar/Menubar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">
      <div class="row">

        <!-- Left side columns -->
        <div class="col-lg-8">
          <div class="row">

            <!-- Sales Card -->
            <div class="col-xxl-4 col-md-6" >
              <div class="card info-card sales-card">

                

                <div class="card-body">
                  <h5 class="card-title">Cash in Hand <span>| Today </span></h5>
				  
<?php 
				  
if($_POST['fdate']==''){
$_POST['fdate']=date('Y-01-01');
}

if($_POST['tdate']==''){
$_POST['tdate']=date('Y-m-d');
}

		 $sql = "select group_id, group_name from ledger_group where group_id=11001";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $group_id=$info->group_id;
		 $group_name=$info->group_name;
		}
		
		 $sql = "select a.ledger_group_id, sum(j.dr_amt-j.cr_amt) as cash_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.ledger_group_id=11001 and j.jv_date <='".$_POST['tdate']."' group by a.ledger_group_id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $cash_amt[$info->ledger_group_id]=$info->cash_amt;
		 }

?>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-currency-dollar"></i>
                    </div>
                    <div class="ps-3">
                      <h6 style="font-size:18px;">
    <?php echo number_format($cash_closing_balance=$cash_amt[11001],2); 
	//if($cash_closing_balance>0) echo number_format($cash_closing_balance,2).'(Dr)'; elseif($cash_closing_balance<0) echo number_format(((-1)*$cash_closing_balance),2).' (Cr)';else echo "0.00"; ?></h6>
                      <span class="text-muted small pt-2 ps-1">Currency</span><span class="text-success small pt-1 fw-bold"> BDT</span> 

                    </div>
                  </div>
				   
				   <br>
	<center> <a href="61_account_03.php?show=show&fdate=<?=$_POST['fdate']?>&tdate=<?=$_POST['tdate']?>&gl_group=<?=$group_id.' :: '.$group_name?>" target="_blank" style="text-decoration:none; "><span class="badge bg-primary" ><i class="bi bi-check-circle me-1"></i> View Details</span></a></center>
				
                </div>

              </div>
            </div><!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">

                

                <div class="card-body">
                  <h5 class="card-title">Cash at Bank <span>| Today </span></h5>
				  
 <?php 
				  
if($_POST['fdate']==''){
$_POST['fdate']=date('Y-01-01');
}

if($_POST['tdate']==''){
$_POST['tdate']=date('Y-m-d');
}

		$sql = "select group_id, group_name from ledger_group where group_id=11002";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $group_id=$info->group_id;
		 $group_name=$info->group_name;
		}

		 $sql = "select a.ledger_group_id, sum(j.dr_amt-j.cr_amt) as bank_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.ledger_group_id=11002 and j.jv_date <='".$_POST['tdate']."' group by a.ledger_group_id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $bank_amt[$info->ledger_group_id]=$info->bank_amt;
		 }

?>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-currency-dollar"></i>
                    </div>
                    <div class="ps-3">
                      <h6 style="font-size:18px;">
    <?php echo number_format($bank_closing_balance=$bank_amt[11002],2); 
	//if($bank_closing_balance>0) echo number_format($bank_closing_balance,2).'(Dr)'; elseif($bank_closing_balance<0) echo number_format(((-1)*$bank_closing_balance),2).' (Cr)';else echo "0.00"; ?></h6>
                       <span class="text-muted small pt-2 ps-1">Currency</span><span class="text-success small pt-1 fw-bold"> BDT</span>

                    </div>
                  </div>
				  
				  <br>
				 <center><a href="61_account_03.php?show=show&fdate=<?=$_POST['fdate']?>&tdate=<?=$_POST['tdate']?>&gl_group=<?=$group_id.' :: '.$group_name?>" target="_blank" style="text-decoration:none; "><span class="badge bg-success" ><i class="bi bi-check-circle me-1"></i> View Details</span></a></center>
				  
				  
                </div>

              </div>
            </div><!-- End Revenue Card -->

            <!-- Customers Card -->
            <div class="col-xxl-4 col-xl-12">

              <div class="card info-card customers-card">

                

                <div class="card-body">
				
				<div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>
					
					<?php
						 $sql = 'select * from year where 1';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
					<li><a class="dropdown-item" href="home.php?sales_year=<?php echo $data->year;?>"><?php echo $data->year;?></a></li>
					 <?php }?>

                   
                  </ul>
                </div>
				
 <?php   

 if($_REQUEST['sales_year']==''){
 $fdate=date('Y-01-01');
 $tdate=date('Y-12-31');
 $year=date('Y');
 $yr=date('y');
 }else{
 $fdate=$_REQUEST['sales_year'].'-01-01';
 $tdate=$_REQUEST['sales_year'].'-12-31';
 $year = date('Y',strtotime($fdate));
 $yr = date('y',strtotime($fdate));
 }
 
 ?>
   <h5 class="card-title">Net Earnings <span>| <?php echo $year;?></span></h5>
				  
<?php 
				  

		$sql = "select sum(j.cr_amt-j.dr_amt) as revenue_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=3 and j.jv_date between '".$fdate."' and '".$tdate."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $revenue_amt=$info->revenue_amt;
		 }
		 
		 $sql = "select sum(j.dr_amt-j.cr_amt) as expense_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=4 and j.jv_date between '".$fdate."' and '".$tdate."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $expense_amt=$info->expense_amt;
		 }
		 
		 $net_earnings_amt=$revenue_amt-$expense_amt;

?>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-currency-dollar"></i>
                    </div>
                    <div class="ps-3">
                      <h6 style="font-size:18px;">
    <?php echo number_format($net_earnings_amt,2); 
	//if($net_earnings_amt>0) echo number_format($net_earnings_amt,2).'(Dr)'; elseif($net_earnings_amt<0) echo number_format(((-1)*$net_earnings_amt),2).' (Cr)';else echo "0.00"; ?></h6>
                      <span class="text-muted small pt-2 ps-1">Currency</span><span class="text-success small pt-1 fw-bold">  BDT</span>

                    </div>
                  </div>
				  
				   <br>
				 <center><a href="61_business_01.php?show=show&fdate=<?=$fdate;?>&tdate=<?=$tdate;?>" target="_blank" style="text-decoration:none; "><span class="badge bg-danger" ><i class="bi bi-check-circle me-1"></i>View Details</span></a></center>

                </div>
              </div>

            </div><!-- End Customers Card -->

           
            <div class="col-12">
              <div class="card">
			  
			  <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>
					
					<?php
						 $sql = 'select * from year where 1';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
					<li><a class="dropdown-item" href="home.php?sales_year=<?php echo $data->year;?>"><?php echo $data->year;?></a></li>
					 <?php }?>

                   
                  </ul>
                </div>
			  
            <?php /*?><div class="card-body">
<?php   

 if($_REQUEST['sales_year']==''){
 $fdate=date('Y-01-01');
 $tdate=date('Y-12-31');
 $year=date('Y');
 $yr=date('y');
 }else{
 $fdate=$_REQUEST['sales_year'].'-01-01';
 $tdate=$_REQUEST['sales_year'].'-12-31';
 $year = date('Y',strtotime($fdate));
 $yr = date('y',strtotime($fdate));
 }
 
 ?>
              <h5 class="card-title">Monthly Sales Bar Chart <span>| Year <?php echo $year;?></span></h5>
	  <?php   

 		 $sql = "select year(m.jv_date) as year, month(m.jv_date) as mon, sum(s.total_amt) as sales_amt from journal_master m, sales_invoice s, item_info i 
		where m.jv_no=s.jv_no and s.item_id=i.item_id and m.jv_date between '".$fdate."' and '".$tdate."'  group by  month(m.jv_date), year(m.jv_date)";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $sales_amt[$info->year][$info->mon]=$info->sales_amt;
		 }	  
	 
	  ?>

              <!-- Bar Chart -->
              <canvas id="barChart" style="max-height: 400px;"></canvas>
              <script>
                document.addEventListener("DOMContentLoaded", () => {
                  new Chart(document.querySelector('#barChart'), {
                    type: 'bar',
                    data: {
                      labels: ['Jan <?php echo $yr?>', 'Feb <?php echo $yr?>', 'Mar <?php echo $yr?>', 'Apr <?php echo $yr?>', 'May <?php echo $yr?>', 'Jun <?php echo $yr?>', 'Jul <?php echo $yr?>', 'Aug <?php echo $yr?>', 'Sep <?php echo $yr?>', 'Oct <?php echo $yr?>', 'Nov <?php echo $yr?>', 'Dec <?php echo $yr?>'],
                      datasets: [{
                        label: 'Sales Chart',
                        data: [<?php echo $sales_amt[$year][1]; ?>, <?php echo $sales_amt[$year][2]; ?>, <?php echo $sales_amt[$year][3]; ?>, <?php echo $sales_amt[$year][4]; ?>, <?php echo $sales_amt[$year][5]; ?>, <?php echo $sales_amt[$year][6]; ?>, <?php echo $sales_amt[$year][7]; ?>, <?php echo $sales_amt[$year][8]; ?>, <?php echo $sales_amt[$year][9]; ?>, <?php echo $sales_amt[$year][10]; ?>, <?php echo $sales_amt[$year][11]; ?>, <?php echo $sales_amt[$year][12]; ?>],
                        backgroundColor: [
                          'rgba(255, 99, 132, 0.2)',
                          'rgba(255, 159, 64, 0.2)',
                          'rgba(255, 205, 86, 0.2)',
                          'rgba(75, 192, 192, 0.2)',
                          'rgba(54, 162, 235, 0.2)',
                          'rgba(153, 102, 255, 0.2)',
                          'rgba(201, 203, 207, 0.2)'
                        ],
                        borderColor: [
                          'rgb(255, 99, 132)',
                          'rgb(255, 159, 64)',
                          'rgb(255, 205, 86)',
                          'rgb(75, 192, 192)',
                          'rgb(54, 162, 235)',
                          'rgb(153, 102, 255)',
                          'rgb(201, 203, 207)'
                        ],
                        borderWidth: 1
                      }]
                    },
                    options: {
                      scales: {
                        y: {
                          beginAtZero: true
                        }
                      }
                    }
                  });
                });
              </script>
              <!-- End Bar CHart -->

            </div><?php */?>
          </div>
            </div><!-- End Recent Sales -->

           

          </div>
        </div><!-- End Left side columns -->

        <!-- Right side columns -->
		
		
		<?php if($yr_sales_amt>0) {?>
        <?php /*?><div class="col-lg-4">

        <div class="card">
		
		<div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>
					
					<?php
						 $sql = 'select * from year where 1';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
					<li><a class="dropdown-item" href="home.php?sales_year=<?php echo $data->year;?>"><?php echo $data->year;?></a></li>
					 <?php }?>

                   
                  </ul>
                </div>
		
            <div class="card-body">
			
<?php   

if($_REQUEST['sales_year']==''){
$fdate_q1=date('Y-01-01');
$tdate_q1=date('Y-03-31');

$fdate_q2=date('Y-04-01');
$tdate_q2=date('Y-06-30');

$fdate_q3=date('Y-07-01');
$tdate_q3=date('Y-09-30');

$fdate_q4=date('Y-10-01');
$tdate_q4=date('Y-12-31');

$year=date('Y');
$current_yr=date('y');
}else{
$fdate_q1=$_REQUEST['sales_year'].'-01-01';
$tdate_q1=$_REQUEST['sales_year'].'-03-31';

$fdate_q2=$_REQUEST['sales_year'].'-04-01';
$tdate_q2=$_REQUEST['sales_year'].'-06-30';

$fdate_q3=$_REQUEST['sales_year'].'-07-01';
$tdate_q3=$_REQUEST['sales_year'].'-09-30';

$fdate_q4=$_REQUEST['sales_year'].'-10-01';
$tdate_q4=$_REQUEST['sales_year'].'-12-31';

$year = date('Y',strtotime($fdate_q1));
$current_yr = date('y',strtotime($fdate_q1));
}
  
?>
			
			
              <h5 class="card-title">Quarterly Earnings Chart <span>| Year <?php echo $year;?></span></h5>
			  
			  
<?php 

		$sql = "select sum(j.cr_amt-j.dr_amt) as q1_revenue_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=3 and j.jv_date between '".$fdate_q1."' and '".$tdate_q1."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q1_revenue_amt=$info->q1_revenue_amt;
		 }
		 
		 $sql = "select sum(j.dr_amt-j.cr_amt) as q1_expense_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=4 and j.jv_date between '".$fdate_q1."' and '".$tdate_q1."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q1_expense_amt=$info->q1_expense_amt;
		 } 
		 $q1_net_earnings=$q1_revenue_amt-$q1_expense_amt;
		 
		 
		 $sql = "select sum(j.cr_amt-j.dr_amt) as q2_revenue_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=3 and j.jv_date between '".$fdate_q2."' and '".$tdate_q2."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q2_revenue_amt=$info->q2_revenue_amt;
		 }
		 
		 $sql = "select sum(j.dr_amt-j.cr_amt) as q2_expense_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=4 and j.jv_date between '".$fdate_q2."' and '".$tdate_q2."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q2_expense_amt=$info->q2_expense_amt;
		 }
		 $q2_net_earnings=$q2_revenue_amt-$q2_expense_amt;
		 
		 
		 $sql = "select sum(j.cr_amt-j.dr_amt) as q3_revenue_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=3 and j.jv_date between '".$fdate_q3."' and '".$tdate_q3."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q3_revenue_amt=$info->q3_revenue_amt;
		 }
		 
		 $sql = "select sum(j.dr_amt-j.cr_amt) as q3_expense_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=4 and j.jv_date between '".$fdate_q3."' and '".$tdate_q3."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q3_expense_amt=$info->q3_expense_amt;
		 }
		 $q3_net_earnings=$q3_revenue_amt-$q3_expense_amt;
		 
		 
		 $sql = "select sum(j.cr_amt-j.dr_amt) as q4_revenue_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=3 and j.jv_date between '".$fdate_q4."' and '".$tdate_q4."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q4_revenue_amt=$info->q4_revenue_amt;
		 }
		 
		 $sql = "select sum(j.dr_amt-j.cr_amt) as q4_expense_amt from journal j, accounts_ledger a 
		where j.ledger_id=a.ledger_id and a.acc_class=4 and j.jv_date between '".$fdate_q4."' and '".$tdate_q4."' ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q4_expense_amt=$info->q4_expense_amt;
		 }
		 $q4_net_earnings=$q4_revenue_amt-$q4_expense_amt;
		 
		 $tot_net_earnings=($q1_net_earnings+$q2_net_earnings+$q3_net_earnings+$q4_net_earnings);
		 
		 $q1_percent=round(($q1_net_earnings/$tot_net_earnings)*100);
		 $q2_percent=round(($q2_net_earnings/$tot_net_earnings)*100);
		 $q3_percent=round(($q3_net_earnings/$tot_net_earnings)*100);
		 $q4_percent=round(($q4_net_earnings/$tot_net_earnings)*100);

?>

              <!-- Pie Chart -->
              <div id="pieChart"></div>

              <script>
                document.addEventListener("DOMContentLoaded", () => {
                  new ApexCharts(document.querySelector("#pieChart"), {
                    series: [<?php echo $q1_percent;?>, <?php echo $q2_percent;?>, <?php echo $q3_percent;?>, <?php echo $q4_percent;?>],
                    chart: {
                      height: 350,
                      type: 'pie',
                      toolbar: {
                        show: true
                      }
                    },
                    labels: ['Jan - Mar, <?php echo $current_yr;?>', 'Apr - Jun, <?php echo $current_yr;?>', 'Jul - Sep, <?php echo $current_yr;?>', 'Oct - Dec, <?php echo $current_yr;?>']
                  }).render();
                });
              </script>
              <!-- End Pie Chart -->
			  
			 
				 <center><a href="61_business_06.php?show=show&fdate=<?=$fdate_q1;?>&tdate=<?=$tdate_q4;?>" target="_blank" style="text-decoration:none; ">
				 <span class="badge bg-secondary"><i class="bi bi-check-circle me-1"></i>View Details</span></a></center>

            </div>
			
			 
			
			
          </div>
		  
		  
		  
		  
		  
		  <div class="card">
		  
		  <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>
					
					<?php
						 $sql = 'select * from year where 1';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
					<li><a class="dropdown-item" href="home.php?sales_year=<?php echo $data->year;?>"><?php echo $data->year;?></a></li>
					 <?php }?>

                   
                  </ul>
                </div>
		  
		  
            <div class="card-body">
			
<?php   

if($_REQUEST['sales_year']==''){
$fdate_q1=date('Y-01-01');
$tdate_q1=date('Y-03-31');

$fdate_q2=date('Y-04-01');
$tdate_q2=date('Y-06-30');

$fdate_q3=date('Y-07-01');
$tdate_q3=date('Y-09-30');

$fdate_q4=date('Y-10-01');
$tdate_q4=date('Y-12-31');

$year=date('Y');
$current_yr=date('y');
}else{
$fdate_q1=$_REQUEST['sales_year'].'-01-01';
$tdate_q1=$_REQUEST['sales_year'].'-03-31';

$fdate_q2=$_REQUEST['sales_year'].'-04-01';
$tdate_q2=$_REQUEST['sales_year'].'-06-30';

$fdate_q3=$_REQUEST['sales_year'].'-07-01';
$tdate_q3=$_REQUEST['sales_year'].'-09-30';

$fdate_q4=$_REQUEST['sales_year'].'-10-01';
$tdate_q4=$_REQUEST['sales_year'].'-12-31';

$year = date('Y',strtotime($fdate_q1));
$current_yr = date('y',strtotime($fdate_q1));
}
  
?>
			
			
              <h5 class="card-title">Quarterly Sales Chart <span>| Year <?php echo $year;?></span></h5>
			  
		<?php 

		$sql = "select sum(s.total_amt) as q1_sales_amt from journal_master m, sales_invoice s, item_info i 
		where m.jv_no=s.jv_no and s.item_id=i.item_id and m.jv_date between '".$fdate_q1."' and '".$tdate_q1."'  ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q1_sales_amt=$info->q1_sales_amt;
		 }
		 
		  $sql = "select sum(s.total_amt) as q2_sales_amt from journal_master m, sales_invoice s, item_info i 
		where m.jv_no=s.jv_no and s.item_id=i.item_id and m.jv_date between '".$fdate_q2."' and '".$tdate_q2."'  ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q2_sales_amt=$info->q2_sales_amt;
		 }
		 
		 
		 $sql = "select sum(s.total_amt) as q3_sales_amt from journal_master m, sales_invoice s, item_info i 
		where m.jv_no=s.jv_no and s.item_id=i.item_id and m.jv_date between '".$fdate_q3."' and '".$tdate_q3."'  ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q3_sales_amt=$info->q3_sales_amt;
		 }
		 
		 $sql = "select sum(s.total_amt) as q4_sales_amt from journal_master m, sales_invoice s, item_info i 
		where m.jv_no=s.jv_no and s.item_id=i.item_id and m.jv_date between '".$fdate_q4."' and '".$tdate_q4."'  ";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $q4_sales_amt=$info->q4_sales_amt;
		 }
	
		  $tot_sales_amt=($q1_sales_amt+$q2_sales_amt+$q3_sales_amt+$q4_sales_amt);
		 
		 $q1_sales_percent=round(($q1_sales_amt/$tot_sales_amt)*100);
		 $q2_sales_percent=round(($q2_sales_amt/$tot_sales_amt)*100);
		 $q3_sales_percent=round(($q3_sales_amt/$tot_sales_amt)*100);
		 $q4_sales_percent=round(($q4_sales_amt/$tot_sales_amt)*100);

?>

              <!-- Donut Chart -->
              <div id="donutChart"></div>

              <script>
                document.addEventListener("DOMContentLoaded", () => {
                  new ApexCharts(document.querySelector("#donutChart"), {
                    series: [<?php echo $q1_sales_percent;?>, <?php echo $q2_sales_percent;?>, <?php echo $q3_sales_percent;?>, <?php echo $q4_sales_percent;?>],
                    chart: {
                      height: 350,
                      type: 'donut',
                      toolbar: {
                        show: true
                      }
                    },
                    labels: ['Jan - Mar, <?php echo $current_yr;?>', 'Apr - Jun, <?php echo $current_yr;?>', 'Jul - Sep, <?php echo $current_yr;?>', 'Oct - Dec, <?php echo $current_yr;?>'],
                  }).render();
                });
              </script>
              <!-- End Donut Chart -->

            </div>
          </div>
		
		  

        </div><?php */?><!-- End Right side columns -->
		<?php }?>
		
		

      </div>
    </section>

  </main><!-- End #main -->

 <!-- ======= Footer ======= -->
 <?php require_once('inc_files/inc_footer.php'); ?>
<!-- ======= Footer ======= -->

</body>

</html>