<?php

include("db/cn.php");
include("common/tx.php");
ob_start();

if(isset($_SESSION['user_name']) && isset($_SESSION['user_role'])&& isset($_SESSION['outlet_name'])
&& isset($_SESSION['outlet_address'])) {
    $userName = $_SESSION['user_name'];
    $userRole = $_SESSION['user_role'];
	$outlet_address = $_SESSION['outlet_address'];
	$outlet_name = $_SESSION['outlet_name'];
}


//-------------------------------------
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["paid_emp"])){
$dateTime= date("Y-m-d");
$emp_name = $_POST["empName"];
$emp_paid = $_POST["emp_paid"];
$emp_des = $_POST["emp_des"];
$paidBy = $_POST['paid_by'];
	

 mysqli_query($connection,"insert into salari_paid(emp_name,emp_paid,emp_des,date_time,paid_by)
 values('".$emp_name."','".$emp_paid."','".$emp_des."','".$dateTime."','".$paidBy."')");
 

}

if(isset($_GET['delete_id'])){
    $id = $_GET['delete_id'];
    mysqli_query($connection,"DELETE FROM salari_paid where id = '$id'");
     echo "<script type='text/javascript'>window.location.href = 'pay_amount.php';</script>";
}

ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title><?php echo $tx; ?></title>

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
   <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@200;300;400;500;600;700&display=swap" rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="../css/sb-admin-2.min.css" rel="stylesheet">
        <link href="../css/sb-admin-2.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<style>
body {
    font-family: 'Quicksand', sans-serif;
    
}
		    .chart-container {
      position: relative;
      background: rgba(255, 255, 255, 0.9);
      border-radius: 10px;
      padding: 15px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    }

    canvas {
      max-width: 100%;
      height: auto;
    }
.bg-gradient-primary{
    
	background:#0A4657;
	color:#fff;	
	
	}

.btn-primary{
	background:#0A4657;
	color:#fff;
	 border:1px #0A4657 solid;
	
	}  
.btn-primary:hover{
  
  background:#fff;
  border:1px #0A4657 solid;
	color:#0A4657;
	
	}	 
    .chart-container {
      position: relative;
      background: rgba(255, 255, 255, 0.9);
      border-radius: 10px;
      padding: 15px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    }

    canvas {
      max-width: 100%;
      height: auto;
    }
	
	.fa-download:hover{
		color:#953E39;
		}
		
		/* Basic styling */
      .tab {
        display: none;
        padding: 20px;
    }
    .active {
        display: block;
    }
    .tab-buttons {
        display: flex;
    }
    .tab-button {
        cursor: pointer;
        padding: 10px 10px;
        background-color: #ffff;
        border: 1px solid #0A5064;
        border-radius: 5px 5px 0 0;
        margin-right: 5px;
		color:#212529;
		font-weight:700;
    }
    .tab-button.active {
        background-color: #212529;
		color:#fff;
    }

    /* Background colors for tab content */
    #tab1 {
        background-color: #fff;
		color:#212529;
		padding:20px;
    }
    #tab2 {
        color:#212529;
		background-color: ;
    }
    #tab3 {
		color:#212529;
        background-color: ;
    }
h3, h4, label{
    font-weight:700;
    color:#000;
}    
td, .btn, option{
    font-weight:700;
}
  </style>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <!-- Sidebar -->
        <?php
        include("common/sd.php");
		?>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <!-- Topbar Search -->
                    
  <?php include('common/log.php');  ?>

                    <!-- Topbar Navbar -->
                    
                </nav>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                
               <div class="container-fluid">
                   <h3>Employee Pay Amount</h3>

<br />
<div class="row">
    <div class="col-4">
         <form class="shadow-sm" method="post" action="" enctype="multipart/form-data" 
         style="padding:25px; border-radius:10px;background:#fff; ">

    <div class="form-group mb-3">
        <label>Employee Name</label>
        
        <select name="empName" class="form-control font-weight-bold">
        <option value="">Select Employee Name</option>
        <?php 
         $c = mysqli_query($connection,"select * from e_salary");
         while($rr = mysqli_fetch_array($c)){
        ?>
        <option class=" font-weight-bold" value="<?php echo $rr['emp_name']; ?>"><?php echo $rr['emp_name']; ?></option>
        <?php
         }
        ?>
        </select>    
    </div>

    <div class="form-group mb-3">
        <label>Description</label>
        <input type="text" name="emp_des" class="form-control">
    </div>

    <div class="form-group mb-3">
        <label>Amount</label>
        <input type="text" name="emp_paid" class="form-control">
    </div>

    <div class="form-group mb-4">
        <label>Paid By</label>
        <select name="paid_by" class="form-control font-weight-bold">
            <option value="">Select Method</option>
            <option value="cash">Cash</option>
         <option value="bank1">Ibrahim Meezan</option>
                                        <option value="bank2">Adil Meezan </option>
                                        <option value="bank3">HBL Bank</option>
                                        <option value="bank3">JazzCash</option>
            <option value="other">Other</option>
        </select>
    </div>

    <button type="submit" name="paid_emp" class="btn btn-dark w-100">
        Add Paid Amount
    </button>

</form>

    </div>

    <div class="col-8">
        <table class=" table table-stripped text-center  ">
  <tr class="bg-dark text-white">
    <td>Date</td>
    <td>Name</td>
    <td>Description</td>
    <td>Amount(Rs)</td>
    <td>Method</td>
    <td>Edit</td>
    <td>Delete</td>
    
  </tr>
  <tbody id="paidTableBody">
  <?php
  // Using a UNION to simulate FULL OUTER JOIN
   $query = "
    select * from salari_paid 
  ";

  $result = mysqli_query($connection, $query);

  while ($row = mysqli_fetch_array($result)) {
    $date_time = $row["date_time"];
    $paidBy = $row["paid_by"];
    $empName = $row["emp_name"];
    $emp_desc = $row["emp_des"] ? $row["emp_des"] : '-';
    $emp_adp = $row["emp_paid"] ? ' ' . $row["emp_paid"] : '-';
    
	
  
  ?>
  <tr>
    <td><?php echo $date_time; ?></td>
    <td><?php echo $empName; ?></td>
    <td><?php echo $emp_desc; ?></td>
    <td><?php echo $emp_adp; ?></td>
     <td class="text-capitalize"><?php echo $paidBy; ?></td>
     <td><a href="edit_pay_amount.php?id=<?php echo $row['id']; ?>" class="btn btn-primary"><i class="fas fa-edit"></i></a></td>
    <td><a href="pay_amount.php?delete_id=<?php echo $row['id']; ?>" class="btn btn-danger">X</a></td>
   
   
      </tr>
  <?php
  }
  ?>
  </tbody>
</table>
    </div>
</div>
</div>


    
            
                <!-- /.container-fluid -->

            </div>
            <br><br>
            <!-- End of Main Content -->

            <!-- Footer -->
            <?php include("common/main_ft.php");  ?>
            <!-- End of Footer -->

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="">Logout</a>
                </div>
            </div>
        </div>
    </div>

   <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin-2.min.js"></script>

</body>

</html>