<?php 
    session_start();
    if(!$_SESSION['id']){
        header('location:index.php');
    }
    require_once '../system/conn.php';
?>
<!doctype html>
<html lang="en" class="semi-dark">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="assets/css/pace.min.css" rel="stylesheet" />
	<script src="assets/js/pace.min.js"></script>
    <link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
    <link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
    <link href="assets/plugins/datatable/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/bootstrap-extended.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/icons.css" rel="stylesheet">
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <link href="assets/css/dark-theme.css" rel="stylesheet" />
    <link href="assets/css/semi-dark.css" rel="stylesheet" />
    <link href="assets/css/header-colors.css" rel="stylesheet" />
    <title>Previous Bank Sheet (<?php echo $_POST['year'].' - '.$_POST['month'] ?>)</title>
  </head>
  <body>
    <div class="wrapper">
    <?php include'system/header.php'?>
	    <div class="page-content-wrapper">
         <div class="page-content">
          <!--start breadcrumb-->
          <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
            <?php $dateObj   = DateTime::createFromFormat('!m', $_POST['month'] );
            $monthName = $dateObj->format('F'); ?>
            <div class="breadcrumb-title pe-3">Previous Bank Sheet (<?php echo $_POST['year'].' - '.$monthName ?>)</div>
            <div class="ms-auto">
               <a href="excel-previous-bank-sheet.php?m=<?php echo $_POST['month']; ?>&y=<?php echo $_POST['year']; ?>"><button type="button" class="btn btn-primary px-5">Excel Download</button></a>
            </div>
          </div>
			<hr/>
            
            
                <div class="card">
					<div class="card-body">
						<div class="table-responsive">
							<table id="example2" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>SR No</th>
            							<th>Employee Name</th>
            							<th>Branch</th>
            							<th>Designation</th>
            							<th>Employee Code</th>
                                        <th>Account No.</th>
                                        <th>Net Pay</th>
									</tr>
								</thead>
								<tbody>
								    <?php
								        
                                        $year = $_POST['year'];
                                        $month = $_POST['month'];
                                        $cnt = 1;
                                        $stmt = $conn->prepare(" SELECT `name`, `branch`, `designation`, `emp_id`, `ac_no`, `net_pay` FROM `prv_emp_salary` WHERE `month`='$month' AND `year`='$year' AND `block`='' AND `cheque`='' UNION SELECT '', '','','','TOTAL', SUM(`net_pay`) from `prv_emp_salary` WHERE `month`='$month' and `year`='$year' ");
                                        $stmt->execute();
                                        $sql = $stmt->fetchAll();
                                        foreach($sql as $row) 
                                        { 
                                    ?>
                                    <tr>
                                        <td><?php echo $cnt;?></td>
                                        <td><?php echo $row['name'];?></td>
                                        <td>
                                        <?php
                                          $sth1 = $conn->prepare("SELECT * FROM `branch` where id='".$row['branch']."' ");
                                          $sth1->execute();
                                          $row2 = $sth1->fetch(PDO::FETCH_ASSOC);
                                          echo $row2['name']; ?>
                                        </td>
                                        <td><?php echo $row['designation']?></td>
                                        <td><?php echo $row['emp_id']?></td>
                                        <td><?php echo $row['ac_no'];?></td>
                                        <td><?php echo $row['net_pay'];?></td> 
                                    </tr>
                                    <?php $cnt=$cnt+1;} ?>
								</tbody>
								<tfoot>
									<tr>
										<th>SR No</th>
            							<th>Employee Name</th>
            							<th>Branch</th>
            							<th>Designation</th>
            							<th>Employee Code</th>
                                        <th>Account No.</th>
                                        <th>Net Pay</th>
									</tr>
								</tfoot>
							</table>
						</div>
					</div>
			    </div>

          </div>
          <!-- end page content-->
         </div>

<?php include'system/footer.php'?>