<? include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); 

	$action=$_REQUEST['action'];
	if($action=='show'){


	
	$stdate=$_POST['stdate'];
	$enddate=$_POST['enddate'];
	$farmid=$_POST['rdfid'];

	if($farmid=='0'){

		header("Locaation:repcashsales.php");
	}else{
		$getf=f(q("SELECT * FROM tbl_farmer WHERE faid='$farmid'"));
		$rdfname=$getf['faname'];
		$sql="SELECT * FROM tbl_cash_sales WHERE csfarmer='$farmid' AND csdate BETWEEN '$stdate' AND '$enddate' ORDER BY csid ASC";
		$title="Cash Farmer Sales Report of ".$rdfname." from ".$stdate." and ".$enddate;
	}


}else{

	header("Locaation:repcashsales.php");
}



	?>
	<title><?=$title?></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">
	<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
	<style type="text/css">
		th{

    	font-size: 12px !important;
    }
    td{

    	font-size: 10px !important;
    }
	</style>
</head>
<body>

<table class="stripe hover multiple-select-row data-table-export nowrap">
							<thead>
								<tr>
									<th class="table-plus datatable-nosort">Entry By</th>
									<th>Date</th>
									<th>Particulars</th>
									<th>Unit Name</th>
									<th>Vehicle No</th>
									<th>Bill No</th>
									<th>Chick's Company</th>
									<th>Piece</th>
									<th>Rate</th>
									<th>PS</th>	
									<th>Rate</th>
									<th>BS</th>
									<th>Rate</th>
									<th>BF</th>
									<th>Rate</th>
									<th>Freight Charge</th>
									<th>Medicine</th>
									<th>Credit Amount</th>
								</tr>
							</thead>
							<tbody>
								<?
									$getc=mysqli_query($con,$sql);
									while($arr=mysqli_fetch_array($getc)){
										$getuname=f(q("SELECT * FROM tbl_login WHERE l_uid='$arr[csadded]'"));
										$getf=f(q("SELECT * FROM tbl_farmer WHERE faid='$arr[csfarmer]'"));
										$getl=f(q("SELECT * FROM tbl_liftman WHERE lfid='$arr[csliftman]'"));
										$getu=f(q("SELECT * FROM tbl_unit WHERE unid='$arr[csunit]'"));

										$gets=f(q("SELECT * FROM tbl_csale_det WHERE csdsid='$arr[csid]' AND csdtype='chicks'"));
										$proids=$gets['csdprodid'];
										$getprod=f(q("SELECT * FROM tbl_manu WHERE maid=(SELECT mamanu FROM tbl_product WHERE maid='$proids')"));

										$getps=f(q("SELECT * FROM tbl_csale_det WHERE csdsid='$arr[csid]' AND csdprodname LIKE'%PS%'"));

										$getbs=f(q("SELECT * FROM tbl_csale_det WHERE csdsid='$arr[csid]' AND csdprodname LIKE'%BS%'"));

										$getbf=f(q("SELECT * FROM tbl_csale_det WHERE csdsid='$arr[csid]' AND csdprodname LIKE'%BF%'"));

										$getbm=f(q("SELECT SUM(csdtotal) as medtot FROM tbl_csale_det WHERE csdsid='$arr[csid]' AND csdtype='medicine'"));


								?>
								<tr>
									<td class="table-plus"><?=$getuname['l_name']?></td>
									
									
									<td ><?=$arr['csdate']?></td>
									<td><?=$arr['csac']?></td>
									<td ><?=$getu['unname']?></td>
									<td ><?=$arr['csvno']?></td>
									<td ><?=$arr['csbill']?></td>	
									<td ><?=$getprod['maname']?></td>
									<td ><?=$gets['csdquan']?></td>
									<td ><?=$gets['csdrate']?></td>
									<td ><?=$getps['csdquan']?></td>
									<td ><?=$getps['csdrate']?></td>
									<td ><?=$getbs['csdquan']?></td>
									<td ><?=$getbs['csdrate']?></td>
									<td ><?=$getbf['csdquan']?></td>
									<td ><?=$getbf['csdrate']?></td>
									<td ><?=$arr['csfrieght']?></td>
									<td ><?=$getbm['medtot']?></td>
									
									<td ><?=$arr['cstotal']?></td>
									
									
								</tr>
								<? } ?>	
							</tbody>
						</table>


	<?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>
	<script type="text/javascript">
		
	</script>
</body>
</html>