<?php
include('db_con.php');
include('db_coni.php');
if (isset($_SESSION['user_id'])) {
        $user_type = $_SESSION['user_type'];
        $user_id = $_SESSION['user_id'];
        $user_name = $_SESSION['user_name'];
        $branch_id = $_SESSION['branch_id'];
        $branch_name = $_SESSION['branch_name'];
        $store_id = $_SESSION['store_id'];
        $store_name = $_SESSION['store_name'];
        $user_acc_no = $_SESSION['user_acc_no'];
}else{
    header('Location: login');
    die();
}
$mac = $_SERVER['REMOTE_ADDR'];
$sql="select IFNULL(sum(d.debit-d.credit),0) from jv_detail d, jv m,accounts a where m.jv_id=d.jv_id and a.acc_no=d.acc_no and a.acc_parent = 101";
  $statement = $connect->prepare($sql);
            $statement->execute(); 
            $cashinhand = $statement->fetchColumn();
            $sql="select IFNULL(sum(d.debit-d.credit),0) from jv_detail d, jv m,accounts a where m.jv_id=d.jv_id and a.acc_no=d.acc_no and a.acc_parent = 102";
  $statement = $connect->prepare($sql);
            $statement->execute(); 
            $cashinbank = $statement->fetchColumn();
            $sql="select IFNULL(sum(d.debit-d.credit),0) from jv_detail d, jv m where m.jv_id=d.jv_id and d.acc_no='".$user_acc_no."'";
  $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $cashinhand_user = $statement->fetchColumn();
          
            $doitems =0;
              $sql = "SELECT count(*) FROM items ";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $tot_items = $statement->fetchColumn();
            $tot_items = round($tot_items);
           
            $tot_customers = 0;
            
            $tot_items_status = $tot_items / 10;
            $tot_customers_status = $tot_customers / 10;
            $doitems_status = $doitems/100;
            $cashinhand_user_status = $cashinhand_user / 10000;
            $cashinhand_user = number_format($cashinhand_user,2);
            $cashinhand_status = $cashinhand /100000;
            $cashinbank_status = $cashinbank /100000;
     include('charts.php');
     $rights_id = $user_id;
     include('user_permissions.php');        
?>
<!DOCTYPE html>
<html>
<head>
<title><?php  if(basename(__FILE__, '.php'=='dashboard')){echo 'Dashboard - Inventory Management System';}?></title>
  <?php include('include/head.php'); ?>
  
</head>
<body>
  <?php include('include/header.php'); ?>
  <?php include('include/sidebar.php'); ?>
<div class="main-container">
    <div class="pd-ltr-20 xs-pd-20-10">
      <div class="row clearfix progress-box">
        <div class="col-lg-3 col-md-6 col-sm-12 mb-30">
          <div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
            <div class="project-info clearfix">
              <div class="project-info-left">
                <div class="icon box-shadow bg-blue text-white">
                  <i class="fa fa-briefcase"></i>
                </div>
              </div>
              <div class="project-info-right">
                <span class="no text-blue weight-500 font-24"><?php echo $cashinhand_user;?></span>
                <p class="weight-400 font-18">Cash in Hand</p>
              </div>
            </div>
            <div class="project-info-progress">
              <div class="row clearfix">
                <div class="col-sm-6 text-muted weight-500">Target</div>
                <div class="col-sm-6 text-right weight-500 font-14 text-muted">1,000,000</div>
              </div>
              <div class="progress" style="height: 10px;">
                <div class="progress-bar bg-blue progress-bar-striped progress-bar-animated" role="progressbar" <?php echo 'style="width: '.$cashinhand_user_status.'%"';?>  aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-lg-3 col-md-6 col-sm-12 mb-30">
          <div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
            <div class="project-info clearfix">
              <div class="project-info-left">
                <div class="icon box-shadow bg-light-green text-white">
                  <i class="fa fa-handshake-o"></i>
                </div>
              </div>
              <div class="project-info-right">
                <span class="no text-light-green weight-500 font-24"><?php echo $doitems;?></span>
                <p class="weight-400 font-18"><?php if($doitems > 0){echo'<a href="do" target="_blank"> Pending Approval</a>';}?></p>
              </div>
            </div>
            <div class="project-info-progress">
              <div class="row clearfix">
                <div class="col-sm-6 text-muted weight-500">Target</div>
                <div class="col-sm-6 text-right weight-500 font-14 text-muted">10,000</div>
              </div>
              <div class="progress" style="height: 10px;">
                <div class="progress-bar bg-light-green progress-bar-striped progress-bar-animated" role="progressbar" <?php echo 'style="width: '.$doitems_status.'%"';?> aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-lg-3 col-md-6 col-sm-12 mb-30">
          <div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
            <div class="project-info clearfix">
              <div class="project-info-left">
                <div class="icon box-shadow bg-light-orange text-white">
                  <i class="fa fa-shopping-cart"></i>
                </div>
              </div>
              <div class="project-info-right">
                <span class="no text-light-orange weight-500 font-24"><?php if($user_type=='admin') {echo '<a class="text-light-orange" href="rpt_sub_accounts_preview?print=1&acc_no=101" target="_blank">'.$cashinhand.'</a>';}else{echo $cashinhand_user;}?></span>
                <p class="weight-400 font-18">Total Cash</p>
              </div>
            </div>
            <div class="project-info-progress">
              <div class="row clearfix">
                <div class="col-sm-6 text-muted weight-500">Target</div>
                <div class="col-sm-6 text-right weight-500 font-14 text-muted">10,000,000</div>
              </div>
              <div class="progress" style="height: 10px;">
                <div class="progress-bar bg-light-orange progress-bar-striped progress-bar-animated" role="progressbar"  <?php echo 'style="width: '.$cashinhand_status.'%"';?> aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-lg-3 col-md-6 col-sm-12 mb-30">
          <div class="bg-white pd-20 box-shadow border-radius-5 margin-5 height-100-p">
            <div class="project-info clearfix">
              <div class="project-info-left">
                <div class="icon box-shadow bg-light-purple text-white">
                  <i class="fa fa-user-o"></i>
                </div>
              </div>
              <div class="project-info-right">
                <span class="no text-light-purple weight-500 font-24"><?php if($user_type=='admin') {echo '<a class="text-light-purple" href="rpt_sub_accounts_preview?print=1&acc_no=102" target="_blank">'.$cashinbank.'</a>';}else{echo $cashinhand_user;}?></span>
                <p class="weight-400 font-18">Banks</p>
              </div>
            </div>
            <div class="project-info-progress">
              <div class="row clearfix">
                <div class="col-sm-6 text-muted weight-500">Target</div>
                <div class="col-sm-6 text-right weight-500 font-14 text-muted">10,000,000</div>
              </div>
              <div class="progress" style="height: 10px;">
                <div class="progress-bar bg-light-purple progress-bar-striped progress-bar-animated" role="progressbar"   <?php echo 'style="width: '.$cashinbank_status.'%"';?> aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="page-header">
          <div class="row">
            <div class="col-md-12 col-sm-12 col-sm-6">
              <div class="title">
                <table class="table table-responsive table-bordered">
                  <tr><td>
                   
                
                <?php if($gl_reports_cash_flow=='ON')
                {
                  echo '<a href="rpt_cash_flow_report" target="_blank" class="btn btn-warning"><i class="fa fa-currency"> Cash Book</i></a> ';  
                }?>
                 <?php if($items_inquiry=='ON')
                {
                  echo '<a href="inventory_detail" target="_blank" class="btn btn-danger"><i class="fa fa-info"> Item Inquiry</i></a> ';  
                }?>
                 <?php if($accounts_receivable_reports_aging_invoices=='ON')
                {
                  echo '<a href="rpt_ar_aging_detail" target="_blank" class="btn btn-success"><i class="fa fa-currency">Customer Aging Report</i></a> ';  
                }?>
                
                
                 <?php if($inventory_reports_item_ledger=='ON')
                {
                  echo 
               '<a href="rpt_item_ledger?add=1" class="btn btn-secondary"> Item Ledger </a>
              ';}?>
               <?php if($rpt_sale_target=='ON')
               {
                echo '<a href="rpt_sale_target" class="btn btn-success">Sales Target</a>';
               }?>
            
                  </td></tr>
                  <tr><td>
                <?php if($cash_invoices_new=='ON')
                {
                  echo '
                <a href="csale_new?add=1" class="btn btn-success">Cash Sale</a>  ';
                }?>
                <?php if($wholesale_invoices_new=='ON')
                {
                  echo '
               <a href="wsale_new?add=1" class="btn btn-primary">Credit Sale</a>';}?>
                 <?php if($return_wholesale_new=='ON')
                {
                  echo '
                <a href="wsr_new?add=1" class="btn btn-warning"> Credit Sale Return</a>';}?>
                <?php if($return_retail_new=='ON')
                {
                  echo '
               <a href="csr_new?add=1" class="btn btn-danger"> Cash Sale Return </a>';}?>
                <?php if($accounts_receivable_payments_new=='ON')
                {
                  echo '
               <a href="ar_cash_receipt_new?add=1" class="btn btn-info"> Cash Receipt </a>';}?>
                <?php if($accounts_receivable_payments_new=='ON')
                {
                  echo '
               <a href="ar_cheque_receipt_new?add=1" class="btn btn-secondary"> Cheque Receipt </a>';}?>
                 <?php if($accounts_receivable_reports_cl=='ON')
                {
                  echo '
                <a href="cl" class="btn btn-primary"> Account Ledger </a>';}?>
                <a href="quotation" class="btn btn-warning"> Quotations </a>
              </div>
            </td>
          </tr>
          <?php echo '<tr>
            <td>
              '.$mac.'
            </td>
           </tr>';?>
            </table>
               <br />
            </div>
             <div class="col-md-12 col-sm-12">
              <div class="title">
                <table class="table table-responsive table-bordered">
                  <tr> 
                    <td>
                <?php if($purchase_new=='ON')
                {
                  echo '
               <a href="purchase_new?add=1" class="btn btn-success"> New Purchases</a>';}?>
                <?php if($purchase_return_new=='ON')
                {
                  echo '
                <a href="pr_new?add=1" class="btn btn-warning">Purchase Return</a>';}?>
                <?php if($accounts_payable_payments_new=='ON')
                {
                  echo '
               <a href="ap_cash_payment_new?add=1" class="btn btn-info"> Cash Payment </a>';}?>
                <?php if($accounts_payable_payments_new=='ON')
                {
                  echo '
               <a href="ap_cheque_payment_new?add=1" class="btn btn-danger"> Cheque Payment </a>';}?>
                <?php if($accounts_payable_reports_vl=='ON')
                {
                  echo '
               <a href="vl" class="btn btn-primary" target="_blank"> Vendor Ledger </a>';}?>         
               
             
               </td>
           </tr>
           <tr>
            <td>
              <a href="todo" class="btn btn-danger"><i class="fa fa-edit">&nbsp;Todo List</i></a>
            </td>
           </tr>
         </table>
              </div>
               <br />
            </div>
           
          </div>
        </div>
     
        <div class="row">
        
 
      <div class="col-md-12">
                 
          <div class="card">
            <div class="card-header">
              <h5>This Month Sale</h5>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
                    <?php if($user_type=='admin')
                    {
                      echo ' <div id="this_month_chart"></div>';
                    }?>
                       
              
            </div>
          </div>
    <br />
      </div>
   
   
 
      <div class="col-md-12">
                 
          <div class="card">
            <div class="card-header">
              <h5>Last Month Sale </h5>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
                <?php if($user_type=='admin')
                {
                  echo ' <div id="last_month_chart"></div>';
                }?>
                       
                  
            </div>
          </div>
      </div>
     </div>
        
      
    </div>
  </div>
  <?php include('include/script.php'); ?>
    <script src="vendors/raphael/raphael.min.js"></script>
 <script src="vendors/morrisjs/morris.min.js"></script>
    <script src="data/morris-data.js"></script>
    
 
<script>
Morris.Bar({
 element : 'this_month_chart',
 data:[<?php echo $this_month_data; ?>],
 xkey:'dated',
 ykeys:['sale','cost','profit'],
 labels:['Sale','Cost','Profit'],
 hideHover:'auto',
 
});
</script>
<script>
Morris.Bar({
 element : 'last_month_chart',
 data:[<?php echo $last_month_data; ?>],
 xkey:'dated',
 ykeys:['sale','cost','profit'],
 labels:['Sale','Cost','Profit'],
 hideHover:'auto',
 
});
</script>
</body>
</html>
