<?php
session_start();
if(!isset($_SESSION['LOGIN_STATUS']))
{
header('location:../index.php');
}
require "../model/configuration.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><?php echo $_SESSION['title'];?></title>
    <link rel='stylesheet' type='text/css' href='../css/fonts.googleapis.com/css_cd14c140.css' />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" type="text/css" href="../vendor/bootstrap/css/bootstrap.min.css" />
    <!-- Theme CSS -->
    <link rel="stylesheet" type="text/css" href="../css/vendor.css" />
    <link rel="stylesheet" type="text/css" href="../css/theme.css" />
    <link rel="stylesheet" type="text/css" href="../css/utility.css" />
    <link rel="stylesheet" type="text/css" href="../css/custom.css" />
  </head>
  <body class="dashboard-page">
    <script> var boxtest = localStorage.getItem('boxed'); if (boxtest === 'true') {document.body.className+=' boxed-layout';} </script>
    <!-- Start: Theme Preview Pane -->
    <!-- Start: Header -->
    <header class="navbar navbar-fixed-top">
      
      <?php include_once("../include/top_menu.php");?>
    </header>
    <!-- Start: Main -->
    <div id="main">
      
      <!-- Start: Sidebar -->
      <?php include_once("../include/left_menu.php");?>
      <!-- Start: Content -->
      <section id="content_wrapper">
        <div id="topbar">
          <div class="topbar-left">
            <ol class="breadcrumb">
              <li class="crumb-icon"><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
              <li class="crumb-link"><a href="#">Salary</a></li>
              <li class="crumb-trail">Salary Report</li>
            </ol>
          </div>
          
        </div>
        
        
        <div id="content">
          <div class="row">

          
            
            <form action="#" method="POST">
            <div class="col-md-6">
              <div class="panel panel-visible">
                <div class="panel-heading">
                  <div class="panel-title hidden-xs"> <span class="glyphicon glyphicon-tasks"></span>Salary Report</div>
                </div>
                <div class="panel-body pbn">
                  <table class="table table-striped table-bordered table-hover" >
                    <thead>
                      <tr>
                        <th>Staff</th>
                        <th>Month</th>
                        <th class="text-center hidden-xs">Actions</th>
                      </tr>
                    </thead>
                    <tbody>
                     
                                
                    
                      <tr>
                        
                        <td class="hidden-xs">
                        <select class="form-control user-success" name="staff_name" required="required"> 
                        <option value="">---------Select----------</option>
                         <?php
                              
                      $sqry=$db->execute("select * from staff where delet='0'");
                              while($row=$sqry->fetch_assoc())
                            { ?>
                       <option value="<?php echo $row['staff_id'];?>"> <?php echo $row['staff_name'];?></option>
                       <?php
                       } 
                       ?>

                        </select>
                        </td>

                        <td><input type="month" class="form-control" name="mnth" required="" ></td>
                        <td class="hidden-xs text-center">
                          <input type="submit" class="btn btn-info" name="sal_rpt" value="Search" />

                        </td>
                      </tr>
                      
                    </tbody>
                  </table>
                </div>
              </div>
              
            </div>
                </form>
      
          
      
          
          <?php
          if(isset($_POST['sal_rpt']))
          {
          ?>
          <div class="col-md-6">
              <div class="panel">
                <div class="panel-heading"> <span class="panel-title"> <span class="glyphicon glyphicon-lock"></span>  <?php 
                                        $stfid =$_POST['staff_name'];
                                                   
                                                    $qrystaff=$db->execute("select * from staff where staff_id='".$stfid."' and delet='0'");
                                                    $staff=$qrystaff->fetch_assoc();
                                                    
                                                    
                                                    echo $staff['staff_name']; ?> </span> </div>
                <div class="panel-body">
                  

<table class="table table-striped table-bordered table-hover dt-responsive" width="100%"><!-- id="sample_1"-->
                                       
                                        <form action="#" method="post">
                                        <tbody>
                                        <?php
                                        list($y,$m)=explode('-',$_POST['mnth']);
                                   $totaldaysinmonth=cal_days_in_month(CAL_GREGORIAN,$m,$y);
                                         $trrtotamt=0;
                                        $totalattandance=0;
                                        $trrqury=$db->execute("select SUM(status) as attandance from staff_attendence where staffid='$stfid' and  mnthyear='".$_POST['mnth']."' and delet='0'");//order_no,
                                        $trrrow=$trrqury->fetch_assoc();
										//if($trrrow['attandance']>25){
											//$ttatt=25;
										//}
										
										//else{
											$ttatt=$trrrow['attandance'];
										//}
                                        $trsleave=$db->execute("select * from staff_attendence where staffid='$stfid' and status='0' and mnthyear='".$_POST['mnth']."' and delet='0'");//order_no,
										if($trrrow['attandance']>25){
                                       $totalleave=0;
										}
										else{
											 $totalleave=$trsleave->num_rows;
										}
							
                                            $squry=$db->execute("select * from staff_salary where staff_id='$stfid'");
                                            $saldetails=$squry->fetch_assoc();
                                            $totsal=$totalleave*$saldetails['amount'];
                                            
                                             $stfsal=$db->execute("select * from staff_sal_details where staffid='$stfid' and  mnthyear='".$_POST['mnth']."' and delet='0'");//order_no,
                                                    while($stfsalrow=$stfsal->fetch_assoc())
                                                  {
                                                        $trrtotamt=$trrtotamt+$stfsalrow['amount'];
                                                  }
                                                  /* if($trrrow['attandance']>=$totaldaysinmonth)
                                                   {
                                                     $salary = $saldetails['basic_salary']-$totsal; 
                                                    }
                                                    else
                                                    {*/
                                                      $salary = ($ttatt*$saldetails['amount']);//-$totsal;
                                                    //}
                                                    $total=$salary-$trrtotamt;
                                                    
                                                  

                                            
                                        ?>
                                        <tr><th class="all">Month</th><td><?php echo date('M-Y', strtotime($_POST['mnth']));?> </td></tr>
                                        <tr> <th class="min-phone-l">Total Attendance</th><td><?php echo $ttatt;?></td></tr>
                                        <tr> <th class="min-phone-l">Total Leave</th><td><?php echo $totalleave;?></td></tr>
                                         <tr> <th class="min-phone-l">Basic Pay</th><td><?php echo  $saldetails['basic_salary'];?></td></tr>
                                         <tr> <th class="min-phone-l">Total Deduction</th><td><?php echo $totsal;?></td></tr> 
                                          <tr> <th class="min-phone-l">Total Salary</th><td><?php echo $salary;?></td></tr> 
                                          <tr> <th class="min-phone-l">Debit Amount</th><td><?php echo $trrtotamt;?></td></tr>
                                          <tr> <th class="min-phone-l">Balance Amount</th><th><u><?php echo $total;?></u></th></tr>
                                         <?php
                                         
                                         ?>      
                                           
                                        </tbody>
                                        </form>
                                    </table>






                </div>
              </div>
            </div>
          
          <?php 
        }
          ?>
              </div>
          <?php //include_once("dashboard_content.php");?>
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
        </div>
        
        
      </section>
      
      <!-- Start: Right Sidebar -->
      
    </div>
    <!-- End #Main -->
    <!-- jQuery -->
    <script type="text/javascript" src="../vendor/jquery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../vendor/jquery/jquery_ui/jquery-ui.min.js"></script> <!-- Bootstrap -->
    <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
    <!-- Page Plugins -->
    <script type="text/javascript" src="../vendor/plugins/validate/jquery.validate.js"></script>
    <script type="text/javascript" src="../vendor/plugins/morris/morris.js"></script>
    <script type="text/javascript" src="../vendor/plugins/datatables/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="../vendor/plugins/datatables/js/datatables.js"></script>
    <script type="text/javascript" src="../vendor/plugins/jvectormap/jquery-jvectormap.min.js"></script>
    <script type="text/javascript" src="../vendor/plugins/datepicker/bootstrap-datepicker.js"></script>
    <script type="text/javascript" src="../vendor/plugins/jquerymask/jquery.maskedinput.min.js"></script>
    <script type="text/javascript" src="../vendor/editors/xeditable/js/bootstrap-editable.js"></script>
    <!-- Flot Plugins -->
    <script type="text/javascript" src="../vendor/plugins/jqueryflot/jquery.flot.min.js"></script>
    <!-- Theme Javascript -->
    <script type="text/javascript" src="../js/utility/spin.min.js"></script>
    <script type="text/javascript" src="../js/utility/underscore-min.js"></script>
    <script type="text/javascript" src="../js/main.js"></script>
    <script type="text/javascript" src="../js/ajax.js"></script>
    <script type="text/javascript" src="../js/custom.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function () {
      
      "use strict";
      // Init Theme Core
    Core.init();
      // Enable Ajax Loading
    Ajax.init();
    
      
        
      // validate the comment form when it is submitted
      $("#altForm").validate();
      //Init jquery Date Picker
      $('.datepicker').datepicker()
      
      
        // Init Datatables with Tabletools Addon
    $('#datatable').dataTable( {
      "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [ -1 ] }],
      "oLanguage": { "oPaginate": {"sPrevious": "", "sNext": ""} },
      "iDisplayLength": 5,
      "aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
      "sDom": 'T<"panel-menu dt-panelmenu"lfr><"clearfix">tip',
      "oTableTools": {
        "sSwfPath": "./vendor/plugins/datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
      }
      });
    
    // Add Placeholder text to datatables filter bar
    $('.dataTables_filter input').attr("placeholder", "Enter Filter Terms Here....");
    
    // Manually Init Chosen on Datatables Filters
      $("select[name='datatable_length']").chosen();
    
    // Init Xeditable Plugin
    $.fn.editable.defaults.mode = 'popup';
    $('.xedit').editable();
      
      
    });
    </script>
  </body>
</html>