<?php
session_start();

if ($_SESSION['company'] == "") { 
    exit("Please Login");
}
if ($_SESSION['CURRENT_USER'] == "") { 
    exit("Please Login");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Search Credit Note</title> 
	<style type="text/css">
		tfoot input {
			width: 100%;
			padding: 3px;
			box-sizing: border-box;
		}
	</style>
	<link  href="new/vendor/new/multi/jquery.dataTables.min.css" rel="stylesheet" type="text/css"> 
	<script src="new/vendor/new/multi/jquery-3.5.1.js" ></script>
	<script src="new/vendor/new/multi/jquery.dataTables.min.js" ></script>
	
	<script language="JavaScript" src="js/crn.js"></script>
</head>
<body>



	<table id="example" class="display" style="width:100%">
		<thead>
			<tr>
				<th>CRN No</th>
				<th>Customer</th>
				<th>Date</th>
				<th>Amount</th> 
			</tr>
		</thead>
		<tbody>
			<?php
			$stname = "";
			if (isset($_GET['stname'])) {
				$stname = $_GET["stname"];
			}
			?>
			<input type="hidden" value="" id="cur" />

			<?php
			require_once("connectioni.php");
			if ($_SESSION["company"]!="") {           
                $sql = "SELECT * FROM cred where CANCELL!='1'  and company='".$_SESSION["company"]."' and C_DATE>='2022-01-01' order by C_DATE desc ";
            }else{
                	$sql = "SELECT * FROM cred where CANCELL!='1' and C_DATE>='2022-01-01'  order by C_DATE desc   ";
                 
            }  
                            
		

			$result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
			while($row = mysqli_fetch_array($result)){
				echo "<tr>               
				<td onclick=\"crnno('".$row['C_REFNO']."');\">".$row['C_REFNO']."</a></td>";
				
				$sql1="SELECT * FROM vendor where CODE='".$row["C_CODE"]."'";
				$result1 =mysqli_query($GLOBALS['dbinv'],$sql1) ; 
				if($row1 = mysqli_fetch_array($result1)){
					echo "<td onclick=\"crnno('".$row['C_REFNO']."');\">".$row1["NAME"]."</a></td>";
				}	
				echo "<td align=\"center\" onclick=\"crnno('".$row['C_REFNO']."');\">".$row['C_DATE']."</a></td>
				<td align=\"right\" onclick=\"crnno('".$row['C_REFNO']."');\">".$row['C_PAYMENT']."</a></td>
				
				</tr>";
			}
			?>

		</tbody>
		<tfoot>
			<tr>
				<th>CRN No</th>
				<th>Customer</th>
				<th>Date</th>
				<th>Amount</th> 
			</tr>
		</tfoot>
	</table>

</body>
</html>
<script type="text/javascript">
	$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
    	var title = $(this).text();
    	$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

    // DataTable
    var table = $('#example').DataTable({
    	
    	lengthChange: true,
    	fixedHeader: true,
    	responsive: true,
    	"deferRender": true,
    	"order": [[ 0, 'desc' ]],
    	lengthMenu: [[ 15, 25, 50,100, -1 ],[ '15 rows', '25 rows', '50 rows', '100 rows', 'Show all' ]],
    	initComplete: function () {
            // Apply the search
            this.api().columns().every( function () {
            	var that = this;

            	$( 'input', this.footer() ).on( 'keyup change clear', function () {
            		if ( that.search() !== this.value ) {
            			that
            			.search( this.value )
            			.draw();
            		}
            	} );
            } );
        }
    });

} );
</script>