<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{
include 'dbc.php';
date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;
$userid=$_SESSION["userid"];
$sql9="Select * from customer where user_id='$userid' order by bname";
$result9 = $conn->query($sql9);
$sql7="Select * from customer where user_id='$userid' order by bname";
$result7 = $conn->query($sql7);
  
  $sql = "SELECT * FROM customer where user_id='$userid'";
$result=$conn->query($sql);
while($row = $result->fetch_assoc())
 
  {
 
$trecord=$trecord + 1;
  }
  $sql1 = "select * from customer where user_id='$userid'";
$result1=$conn->query($sql1);
while($ppp = $result1->fetch_assoc())
{
  $ven_name=$ppp["bname"];
  $id=$ppp["id"]; 
 $qtyret=0;
  $netqty =0;
$tcost = 0; 
$qtysale=0;
$qtypur=0;
$qtysalest=0;
$qtydr=0;
$qtycr=0;
  $sql2 = "select * from invoice where cname='$ven_name' and user_id='$userid'";
$result2=$conn->query($sql2);
while($ppp1 = $result2->fetch_assoc())
{
  $qtysale= $qtysale + $ppp1["netamount"];   
 } 
  $sql2st = "select * from invoice_st where cname='$ven_name' and user_id='$userid'";
$result2st=$conn->query($sql2st);
while($ppp1st = $result2st->fetch_assoc())
{
  $qtysalest= $qtysalest + $ppp1st["tnetamount"];   
 } 
$sql3 = "select * from cashrec where ven_name='$ven_name' and user_id='$userid'";
$result3=$conn->query($sql3);
while($ppp3 = $result3->fetch_assoc())
{
  $qtypur= $qtypur + $ppp3["netamount"];   
 } 
 
 $sqlret = "select * from invoice_return where cname='$ven_name' and user_id='$userid'";
$resultret=$conn->query($sqlret);
while($pppret = $resultret->fetch_assoc())
{
  $qtyret= $qtyret + $pppret["netamount"];   
 } 
 
 $sqldr = "select * from cdebitnote where ven_name='$ven_name' and user_id='$userid'";
$resultdr=$conn->query($sqldr);
while($pppdr = $resultdr->fetch_assoc())
{
  $qtydr= $qtydr + $pppdr["netamount"];   
 } 
 
 $sqlcr = "select * from ccreditnote where ven_name='$ven_name' and user_id='$userid'";
$resultcr=$conn->query($sqlcr);
while($pppcr = $resultcr->fetch_assoc())
{
  $qtycr= $qtycr + $pppcr["netamount"];   
 } 
$netqty = ($qtysale + $qtysalest + $qtydr) - ($qtypur + $qtyret + $qtycr);

  $tnetqty=$tnetqty + $netqty;
    }
	

  
?>
<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
   <?php include("includes/header.php") ?>
</head>

<body>


    <!-- Left Panel -->

 
    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        <header id="header" class="header">

             <?php include("includes/customer_menu.php") ?>

        </header><!-- /header -->
        <!-- Header-->

        <div class="breadcrumbs">
            <div class="col-sm-6">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1><? echo "" . $_SESSION["userid"]; ?></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li class="active"><? echo "" . $_SESSION["username"]; ?></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="content mt-3">

           
<div class="col-sm-6 col-lg-3">
                <div class="card text-white bg-flat-color-1">
                    <div class="card-body pb-0">
                        <div class="dropdown float-right">
                            
                            
                        </div>
                        <h4 class="mb-0">
                            <span class="count"><?php echo $trecord; ?></span>
							
                        </h4>
                        <p class="text-light">Total Customers</p>

                        <div class="chart-wrapper px-0" style="height:70px;" height="70">
                            <canvas id="widgetChart1"></canvas>
                        </div>

                    </div>

                </div>
            </div>
			<div class="col-sm-6 col-lg-3">
                <div class="card text-white bg-flat-color-2">
                    <div class="card-body pb-0">
                        <div class="dropdown float-right">
                            
                            
                        </div>
                        <h4 class="mb-0">
						
                            <span class="count"><?php echo $tnetqty; ?></span>
                        </h4>
                        <p class="text-light">Total Receivable Amount </p>

                        <div class="chart-wrapper px-0" style="height:70px;" height="70">
                            <canvas id="widgetChart2"></canvas>
                        </div>

                    </div>
                </div>
            </div>
<div class="col-sm-6 col-lg-3">
                <div class="card text-white bg-flat-color-3">
                    <div class="card-body pb-0">
                        <div class="dropdown float-right">
                            
                            
                        </div>
                        <h4 class="mb-0">
						  <span class="count"><?php echo $trecord; ?></span>
							
                        </h4>
                        <p class="text-light">Total Customers</p>


                    </div>

                    <div class="chart-wrapper px-0" style="height:70px;" height="70">
                        <canvas id="widgetChart3"></canvas>
                    </div>
                </div>
            </div>
			
			<div class="col-sm-6 col-lg-3">
                <div class="card text-white bg-flat-color-4">
                    <div class="card-body pb-0">
                        <div class="dropdown float-right">
                            
                            
                        </div>
                        <h4 class="mb-0">
						 <span class="count"><?php echo $tnetqty; ?></span>
                        </h4>
                        <p class="text-light">Total Receivable Amount </p>

                        <div class="chart-wrapper px-3" style="height:70px;" height="70">
                            <canvas id="widgetChart4"></canvas>
                        </div>

                    </div>
                </div>
            </div>
            
            <!--/.col-->

            
            <!--/.col-->

            
            <!--/.col-->

            
           
		   
		    <!--/.col-->

            
             

            


          
					
					
					
					
					

          

           
			
			
			
					
					
					
					
					
						
											
											
											
											
											
					
					
					
					
        </div> <!-- .content -->
    </div><!-- /#right-panel -->

    <!-- Right Panel -->

   <?php include("includes/footermenu.php") ?>

</body>

</html>
<?php
}
?>