<?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();

}

$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();

            $sql = "SELECT sum(qty) FROM do_detail WHERE store_id = '".$store_id."' and item_status = 'Not Approved'";

            $statement = $connect->prepare($sql);

            $statement->execute(); // no need to add `$sql` here, you can take that out

            $doitems = $statement->fetchColumn();

            $doitems = round($doitems);

              $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);

              $sql = "SELECT count(*) FROM customers ";

            $statement = $connect->prepare($sql);

            $statement->execute(); // no need to add `$sql` here, you can take that out

            $tot_customers = $statement->fetchColumn();

            $tot_customers = round($tot_customers);

            

            $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($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">Invoice 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>

              ';}?>

             
                  </td></tr>

                  <tr><td>

                <?php if($cash_invoices_new=='ON')

                {

                  echo '

                <a href="csale_new?add=1" class="btn btn-secondary">Cash Sale</a>  ';

                }?>

                <?php if($wholesale_invoices_new=='ON')

                {

                  echo '

               <a href="sales_new?add=1" class="btn btn-info">Credit Sale</a>
               <a href="gsales_new?add=1" class="btn btn-primary">GST 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_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>

            </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>';}?>

              

               </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-8">

                 

          <div class="card">

            <div class="card-header">

              <h5>Top 10 Items</h5>

            </div>

            <!-- /.card-header -->

            <div class="card-body">

               <?php if($user_type=='admin')

                     echo '

                     

                        <div id="chart"></div>

                      ';?>

            </div>

          </div>

         

     </div>

      <div class="col-md-4">

            <div class="card">

              <div class="card-header">

                <h5>Top 5 Items</h5>

              </div>

              <!-- /.card-header -->

              <div class="card-body">

                 <?php if($user_type=='admin')

                       echo '

                       

                          <div id="donut_chart"></div>

                        ';?>

              </div>

            </div>

        </div>

     

        

      

     

    

      

      <?php include('include/footer.php'); ?>

    </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 : 'chart',

 data:[<?php echo $itemchart_data; ?>],

 xkey:'item_name',

 ykeys:['qty','profit','cost'],

 labels:['Qty','Profit','Cost'],

 hideHover:'auto',

 

});

</script>

<script>

$(document).ready(function(){

var donut_chart = Morris.Donut({

  element: 'donut_chart',

  data: <?php echo $singleitemchart_data;?>

  });

});

  

</script>

</body>

</html>

