<? include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	<title>Company Master</title>
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/jquery.dataTables.css">
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/dataTables.bootstrap4.css">
	<link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/responsive.dataTables.css">
</head>
<body>
	<?php include('include/header.php'); ?>

	<?php include('include/sidebar.php'); 
	$blid=$_REQUEST['blid'];
	$getbill=f(q("SELECT * FROM obill WHERE bl_trn='$blid'"));



	$action=$_REQUEST['action'];
	if($action=='save'){
		if($psave==1){
		$pay_date=$_POST['pay_date'];
		$pay_amt=$_POST['pay_amt'];
			$csadded=$_SESSION['murgibhai'];


	$res=mysqli_query($con,"INSERT INTO tbl_opay SET pay_date='$pay_date',pay_amt='$pay_amt',pay_bill='$getbill[blid]',pay_by='$csadded'");

	// if($res){

	// 	$instrn=mysqli_query($con,"INSERT INTO tbl_trans SET trn_ac='$custid',trn_name='$checkexpiry[name]',trn_amt='$amtpaid',trn_date='$strtdt',trn_type='DEPOSIT AC',trn_gst=1,trn_grate='18',trn_gamt='$gstamt',trn_memo='Bill Amount received for $checkexpiry[name]'");
	// }
		}else{
			echo "<script>alert('You are not Authorized to Save');</script>";

		}

	}elseif($action=='update'){
		if($pupdate==1){
			$cid=$_REQUEST['cid'];
		$pay_date=$_POST['pay_date'];
		$pay_amt=$_POST['pay_amt'];
			$csadded=$_SESSION['murgibhai'];

	$res=mysqli_query($con,"UPDATE tbl_opay SET pay_date='$pay_date',pay_amt='$pay_amt',pay_bill='$getbill[blid]',pay_by='$csadded' WHERE pay_id='$cid'");
		}else{
			echo "<script>alert('You are not Authorized to Update');</script>";

		}

	}elseif($action=='edit'){

		$cid=$_REQUEST['cid'];
		$edit=f(q("SELECT * FROM tbl_opay WHERE pay_id='$cid'"));

	}elseif($action=='delete'){

		$cid=$_REQUEST['cid'];
		$edit=f(q("DELETE FROM tbl_opay WHERE pay_id='$cid'"));

	}

	
	


	?>
	<div class="main-container">
		<div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Pay for Bill No: <?php echo $blid?></h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="index.php">Home</a></li>
									
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							<!-- <div class="dropdown">
								<a class="btn btn-secondary dropdown-toggle" href="#" role="button" data-toggle="dropdown">
									January 2018
								</a>
								<div class="dropdown-menu dropdown-menu-right">
									<a class="dropdown-item" href="#">Export List</a>
									<a class="dropdown-item" href="#">Policies</a>
									<a class="dropdown-item" href="#">View Assets</a>
								</div>
							</div> -->
						</div>
					</div>
				</div>
				<!-- Default Basic Forms Start -->
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<form action="<?=$_SERVER['PHP_SELF']?>?action=<?php if($action=='edit'){?>update&cid=<?php echo $cid?><?php }else{?>save<?php } ?>&blid=<?php echo $blid?>" method="POST" enctype="multipart/form-data">
					
					<div class="clearfix" style="min-height: 30px;"></div>
					
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Bill Amount</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="bl_amt" placeholder="Johnny Brown" value="<?=$getbill['bl_amt']?>">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Pay Date</label>
							<div class="col-sm-12 col-md-4">
								<input class="form-control" name="pay_date" type="date" value="<?=$edit['pay_date']?>">
							</div>
							<label class="col-sm-12 col-md-2 col-form-label">Pay Amount</label>
							<div class="col-sm-12 col-md-4">
								<input class="form-control" name="pay_amt" type="text" value="<?=$edit['pay_amt']?>">
							</div>
						</div>
						
						
						<div class="pull-right">
							<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> Save / Update</button>
							<!-- <a href="#basic-form1" class="btn btn-primary btn-sm scroll-click" rel="content-y"  data-toggle="collapse" role="button"><i class="fa fa-code"></i> Source Code</a> -->
						</div><br><br><br>
						</form>
					</div>
					
					<div class="collapse collapse-box" id="basic-form1" >
						
					</div>
				</div>
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<div class="clearfix mb-20">
						<div class="pull-left">
							<h5 class="text-blue">Payment List for <?php echo $blid?></h5>
						</div>
					</div>
					<div class="row">
						<table class="stripe hover multiple-select-row data-table-export nowrap">
							<thead>
								<tr>
									<th class="table-plus datatable-nosort">Date</th>
									<th class="table-plus datatable-nosort">Pay Amount</th>
									
									<th>Action</th>	
								</tr>
							</thead>
							<tbody>
								<?
									$getc=mysqli_query($con,"SELECT * FROM tbl_opay WHERE pay_bill='$getbill[blid]' ORDER BY pay_id DESC");
									while($arr=mysqli_fetch_array($getc)){
								?>
								<tr>
									<td class="table-plus"><?=$arr['pay_date']?></td>
									<td class="table-plus"><?=$arr['pay_amt']?></td>	
									
									<td>
									<a href="<?=$_SERVER['PHP_SELF']?>?action=edit&cid=<?=$arr['pay_id']?>">EDIT</a><br>
									<a href="<?=$_SERVER['PHP_SELF']?>?action=delete&cid=<?=$arr['pay_id']?>" onclick="return confirm('Are you sure you want to delete this item?');">DELETE</a><br>
										

									</td>
								</tr>
								<? } ?>	
							</tbody>
						</table>
					</div>
				</div>
				

			</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>
	<script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
	<script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
	<!-- buttons for Export datatable -->
	<script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
	<script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
	<script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
	<script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
	<script>
		$('document').ready(function(){
			$('.data-table').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: false,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
			});
			$('.data-table-export').DataTable({
				scrollCollapse: true,
				autoWidth: false,
				responsive: true,
				columnDefs: [{
					targets: "datatable-nosort",
					orderable: false,
				}],
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
				"language": {
					"info": "_START_-_END_ of _TOTAL_ entries",
					searchPlaceholder: "Search"
				},
				dom: 'Bfrtip',
				buttons: [
				'copy', 'csv', 'pdf', 'print'
				]
			});
			var table = $('.select-row').DataTable();
			$('.select-row tbody').on('click', 'tr', function () {
				if ($(this).hasClass('selected')) {
					$(this).removeClass('selected');
				}
				else {
					table.$('tr.selected').removeClass('selected');
					$(this).addClass('selected');
				}
			});
			var multipletable = $('.multiple-select-row').DataTable();
			$('.multiple-select-row tbody').on('click', 'tr', function () {
				$(this).toggleClass('selected');
			});
		});
	</script>
</body>
</html>