<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>Advanced Salaries | <?php echo $_SESSION['systemName']; ?></title>
	</head>
	<body class="app sidebar-mini">

		<!-- Navbar-->
		<?php include("library/header.php");?>
		<!-- Sidebar menu-->
		<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
		<?php include("library/sidebar.php");?>
  
		<main class="app-content">
			<div class="app-title">
				<div>
					<h4 class="text-primary"><i class="fa fa-money fa-lg"></i> ADVANCED SALARIES</h4>
					<p>Advanced Salaries List Page</p>
				</div>
				<ul class="app-breadcrumb breadcrumb">
					<li class="breadcrumb-item"><i class="fa fa-home"></i></li>
					<li class="breadcrumb-item"><a href="advanced-salaries">Advanced Salaries</a></li>
				</ul>
			</div>
      
			<?php include("models/admin_config.php");?>
			<?php include("models/system_config.php");?>

			<div class="row">
				
				<div class="col-md-4">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
                                    <h5 class="text-primary"><i class="fa fa-plus-square"></i> New Advanced Salary</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
									<form action="#" method="POST" id="registerNewAdvancedSalaryForm">
										<div class="row">
										    <div class="form-group col-md-12">
                                                <label class="control-label">Employee Name</label>
                                                <select class="form-control" name="cmbEmployeeIddNewAdvancedSalary" id="cmbEmployeeIddNewAdvancedSalary" style="font-size: 16px; width: 100%;" required>
                
                                                </select>
                                            </div>
                                            <div class="form-group col-md-12">
                                                <label class="control-label">Payment Type</label>
                                                <select class="form-control" name="cmbPaymentTypeNewAdvancedSalary" id="cmbPaymentTypeNewAdvancedSalary" style="font-size: 16px; width: 100%;" required>
                                                    <option value="">Select Type</option>
                                                    <option value="Order Payment">Order Payment</option>
                                                    <option value="Money Payment">Money Payment</option>
                                                </select>
                                            </div>
											<div class="form-group col-md-12">
												<label class="control-label">Paid Amount</label>
												<input class="form-control font-weight-bold" type="number" name="txtPaidAmountNewAdvancedSalary" id="txtPaidAmountNewAdvancedSalary" step="0.01" placeholder="Enter paid amount" required>
											</div>
											<div class="form-group col-md-12">
												<label class="control-label">Description</label>
												<textarea class="form-control" rows="2" name="txtPaymentDescriptionNewAdvancedSalary" id="txtPaymentDescriptionNewAdvancedSalary" placeholder="Enter payment description" required></textarea>
												<input class="form-control" type="hidden" name="txtRegisteredByNewAdvancedSalary" id="txtRegisteredByNewAdvancedSalary" value="<?php echo $_SESSION['userIdd']; ?>" required>
												<input class="form-control" type="hidden" name="txtRegisterDateNewAdvancedSalary" id="txtRegisterDateNewAdvancedSalary" value="<?php echo date("Y-m-d H:i:s"); ?>" required>
											</div>
											<div class="form-group col-md-12 text-right">
												<button type="submit" class="btn btn-success" name="btnRegisterNewAdvancedSalary" id="btnRegisterNewAdvancedSalary"><i class="fa fa-fw fa-lg fa-save"></i>Register Payment</button>
											</div>
										</div>
									</form> 							
					            </div>
						    </div>
					    </div>
				    </div>
			    </div>
			
			    <div class="col-md-8">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
									<h5 class="text-primary"><i class="fa fa-list-ul"></i> Advanced Salaries List</h5>
									<hr />
								</div>
    							<div class="col-md-12">
    								<table class="table table-bordered table-sm" id="advancedSalariesTable">
    									<thead>
    										<tr class="text-center bg-dark text-white" height="35px">
                                                <th class="align-middle">Employee Name</th>
                                                <th class="align-middle">Type</th>
                                                <th class="align-middle">Amount</th>
                                                <th class="align-middle">Username</th>
                                                <th class="align-middle">Date</th>
                                                <th class="align-middle">Action</th>
    										</tr>
    									</thead>
    									<tbody>
    										<?php
    											$getAdvancedSalaries = mysqli_query($conn, "SELECT advanced_salaries.paymentID, employees.employeeName, employees.employeeMobileNo, advanced_salaries.paymentType, advanced_salaries.paidAmount, system_users.Username, advanced_salaries.registerDate
                                                FROM advanced_salaries
                                                JOIN employees ON advanced_salaries.employeeID = employees.employeeID
                                                JOIN system_users ON advanced_salaries.registeredBy = system_users.userID
                                                ORDER BY advanced_salaries.registerDate DESC") or die(mysqli_error($conn));
    											while ($advanced_salaries_rs = mysqli_fetch_array($getAdvancedSalaries)) { ?>
                                                    <tr>
                                                        <td class="align-middle"><?php echo $advanced_salaries_rs[1]. " (". $advanced_salaries_rs[2] .")"; ?></td>
                                                        <td class="align-middle"><?php echo $advanced_salaries_rs[3]; ?></td>
                                                        <td class="align-middle text-center"><?php echo "$". number_format($advanced_salaries_rs[4], 2); ?></td>
                                                        <td class="align-middle"><?php echo $advanced_salaries_rs[5]; ?></td>
                                                        <td class="align-middle text-center"><?php echo date("d F", strtotime($advanced_salaries_rs[6])); ?></td>
                                                        <td class="align-middle text-center">
                                                            <div class="btn-group col-md-12">
                                                                <button type="button" class="btn btn-primary btn-sm" data-toggle="dropdown">Action</button>
                                                                <button type="button" class="btn btn-primary btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown">
                                                                    <span class="caret"></span>
                                                                </button>
                                                                <div class="dropdown-menu" style="min-width: 8rem;">
                                                                    <a href="#" class="dropdown-item text-primary btnUpdateAdvancedSalary" id="<?php echo "Update". $advanced_salaries_rs[0]; ?>" data-id="<?php echo $advanced_salaries_rs[0]; ?>" data-toggle="modal" data-target="#updateAdvancedSalariesModal"><i class="fa fa-edit"></i> Edit</a>
                                                                    <a href="#" class="dropdown-item text-danger btnDeleteAdvancedSalary" id="<?php echo "Delete". $advanced_salaries_rs[0]; ?>" data-id="<?php echo $advanced_salaries_rs[0]; ?>"><i class="fa fa-trash"></i> Delete</a>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr><?php
    											}
    										?>
    									</tbody>
    								</table>
    							</div>
						</div>
					</div>
				</div>


			</div>
			
		</main>
  
		<!-- Essential javascripts for application to work-->
		<?php include("library/footer.php");?>  
		<?php include("library/scripts.php");?>
		
		<script type="text/javascript">
		    $("#advancedSalariesTable").DataTable({"pageLength": 100, "order": []})
		    $("#cmbEmployeeIddNewAdvancedSalary, #cmbPaymentTypeNewAdvancedSalary").select2({tags: false})

		</script>

	</body>
</html>