<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>Expense Types | <?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-list-ul fa-lg"></i> EXPENSE TYPES</h4>
					<p>Employee Working Areas 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="expense-types">Expense Types</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> Register New Type</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
									<form action="#" method="POST" id="registerNewExpenseTypeForm">
										<div class="row">
											<div class="form-group col-md-12">
												<label class="control-label">Expense Type Name</label>
												<input class="form-control font-weight-bold" type="text" name="txtExpenseTypeNameRegisterNewExpenseType" id="txtExpenseTypeNameRegisterNewExpenseType" placeholder="Enter expense type name" required>
											</div>
											<div class="form-group col-md-12">
												<label class="control-label">Description</label>
												<textarea class="form-control" rows="2" name="txtExpenseTypeDescriptionRegisterNewExpenseType" id="txtExpenseTypeDescriptionRegisterNewExpenseType" placeholder="Enter area description" required></textarea>
												<input class="form-control" type="hidden" name="txtRegisteredByRegisterNewExpenseType" id="txtRegisteredByRegisterNewExpenseType" value="<?php echo $_SESSION['userIdd']; ?>" required>
												<input class="form-control" type="hidden" name="txtRegisterDateRegisterNewExpenseType" id="txtRegisterDateRegisterNewExpenseType" 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="btnRegisterNewExpenseType" id="btnRegisterNewExpenseType"><i class="fa fa-fw fa-lg fa-save"></i>Register Type</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> Expense Types List</h5>
									<hr />
								</div>
    							<div class="col-md-12">
    								<table class="table table-bordered table-sm" id="expenseTypesTable">
    									<thead>
    										<tr class="text-center bg-dark text-white" height="35px">
                                                <th class="align-middle">No</th>
                                                <th class="align-middle">Expense Type Name</th>
                                                <th class="align-middle">Description</th>
                                                <th class="align-middle">Action</th>
    										</tr>
    									</thead>
    									<tbody>
    										<?php
    										    $count_expense_types = 1;
    											$getExpenseTypes = mysqli_query($conn, "SELECT * FROM expense_types ORDER BY expenseTypeID ASC") or die(mysqli_error($conn));
    											while ($types_rs = mysqli_fetch_array($getExpenseTypes)) { ?>
                                                    <tr>
                                                        <td class="align-middle text-center"><?php echo $count_expense_types; ?></td>
                                                        <td class="align-middle font-weight-bold"><?php echo $types_rs[2]; ?></td>
                                                        <td class="align-middle"><?php echo $types_rs[3]; ?></td>
                                                        <td class="align-middle text-center" width="25%">
                                                            <div class="btn-group col-md-12">
                                                                <button type="button" class="btn btn-primary" data-toggle="dropdown">Action</button>
                                                                <button type="button" class="btn btn-primary 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 btnUpdateExpenseType" id="<?php echo "Update". $types_rs[1]; ?>" data-id="<?php echo $types_rs[1]; ?>" data-toggle="modal" data-target="#updateExpenseTypeModal"><i class="fa fa-edit"></i> Edit</a>
                                                                    <a href="#" class="dropdown-item text-danger btnDeleteExpenseType" id="<?php echo "Delete". $types_rs[1]; ?>" data-id="<?php echo $types_rs[1]; ?>"><i class="fa fa-trash"></i> Delete</a>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr><?php
                                                    $count_expense_types++;
    											}
    										?>
    									</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">
		    $("#expenseTypesTable").DataTable({"pageLength": 100, "order": []})
		</script>

	</body>
</html>