<?php include('../config/setup.php'); ?>

<?php include "head.php" ?>
	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php'); ?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php'); ?>
			<!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php'); ?>


		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title">Commission Master</h4>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-body">
									<div class="d-flex justify-content-center">
									    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#addpackage">
											<i class="fas fa-plus"></i> Add 
										</button>
									</div>
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover">
											<thead>
												<tr>
													<th>S.No</th>
													<th>Type</th>
													<th>Commission</th>
													<th>Status</th>
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
											    <?php 
											        $sno = 1;
											        $sql = "SELECT * FROM commission_master ";
											        $res = $config->query($sql);
											        while($pack = $res->fetch_assoc()){
											            $type = $pack['type'];
											            $status = $pack['status'];
											    ?>
												<tr>
													<td><?= $sno;?></td>
													<td><?= $type ?></td>
													<td><?= $type == 'Amount' ? 'Rs. '.$pack["value"] : $pack["value"].' %' ;?></td>
													<td>
													    <?php
    														if ($status == 1) { ?>
    															<label class="btn btn-success btn-sm text-white">Active</label>
    														<?php
    														} else {
    														?>
    															<label class="btn btn-danger btn-sm text-white">In-Active</label>
    														<?php
    														}
														?>
														</td>
													<td class="d-flex align-items-center" style="column-gap:10px;">
														<a href="" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editpack<?php echo $sno; ?>"> <i class="fas fa-pencil-alt"></i> </a>
														<form method="post" action="add.php" >
															<input type="hidden" class="form-control" id="id" name="id" value="<?= $pack['id'] ?>">
															<input type="hidden" class="form-control" name="action" value="comm_del">
															<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you confirm to delete this category?');"><i class="fas fa-trash"></i> </button>
														</form>
													</td>
														<!-- Modal -->
													<div class="modal fade" id="editpack<?php echo $sno; ?>" 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">Edit</h5>
																	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																		<span aria-hidden="true">&times;</span>
																	</button>
																</div>
																<div class="modal-body">
																	<form method="post" enctype="multipart/form-data" action="add.php">
																		<div class="form-group">
																			<label for="type">Type</label>
																			<input type="hidden" class="form-control" id="id" name="id" value="<?= $pack['id'] ?>">
																			<select class="form-control" id="type" name="type" >
                                        									    <option value="Amount" <?= $type == 'Amount'? 'selected' : '' ;?>>Amount</option>
                                        									    <option value="Percentage" <?= $type == 'Percentage'? 'selected' : '' ;?>>Percentage</option>
                                        									</select>
																		</div>
																		<div class="form-group">
																			<label for="value">Commission</label>
																			<input type="text" class="form-control" id="value" name="value" placeholder="" value="<?= $pack['value'] ?>">
																		</div>
																		<div class="form-group">
																			<label for="status"> Status</label>
																			<select class="form-control" id="status" name="status">
																				<option value="1" <?= $status == '1'? 'selected' : '' ;?>>Active</option>
																				<option value="0"  <?= $status == '0'? 'selected' : '' ;?>>In-Active</option>
																			</select>
																		</div>
																		<div class="form-group">
															                <input type="hidden" class="form-control" name="action" value="comm_edit">
																			<button class="btn btn-success" type="submit" name="submit">Submit</button>
																		</div>
																	</form>
																</div>
																<div class="modal-footer">
																	<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
																</div>
															</div>
														</div>
													</div>
												</tr>
												<?php $sno++; } ?>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<!-- Modal -->
			<div class="modal fade" id="addpackage" 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">Add</h5>
							<button type="button" class="close" data-dismiss="modal" aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
						</div>
						<div class="modal-body">
							<form method="post" action="add.php" enctype="multipart/form-data">
								<div class="form-group">
									<label for="type">Type</label>
									<select class="form-control" id="type" name="type" >
									    <option value="Amount">Amount</option>
									    <option value="Percentage">Percentage</option>
									</select>
								</div>
								<div class="form-group">
									<label for="value">Commission</label>
									<input type="number" class="form-control" id="value" name="value" placeholder="">
								</div>
								<div class="form-group">
									<label for="status"> Status</label>
									<select class="form-control" id="status" name="status">
										<option value="1">Active</option>
										<option value="0">In-Active</option>
									</select>
								</div>
								<div class="form-group">
									<input type="hidden" class="form-control" name="action" value="comm_add" placeholder="">
									<button class="btn btn-success" type="submit" name="submit">Add New</button>
								</div>
							</form>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

						</div>
					</div>
				</div>
			</div>



			<?php include('footer.php'); ?>
		</div>
		<!-- End Custom template -->
	</div>
	<!--   Core JS Files   -->
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>

	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script>
		$(document).ready(function() {
			$('#basic-datatables').DataTable({});
		});
	</script>
</body>

</html>