	<?php if(isset($_SESSION['msg']) ){?>
	<div class="alert alert-info">                
	<h4>Info!</h4>
	<?php echo $_SESSION['msg']; unset($_SESSION['msg']); ?>
	</div> <?php }  ?> 
<div class="row-fluid" >
    <div class="span12">    
	<div class="head clearfix">
        <div class="isw-ok"></div>
        <h1>View Employee List</h1>
     </div>   
    <div class="block-fluid">
        <form class="form-horizontal" onsubmit="return get_validation();" action="" method="post" enctype="multipart/form-data">
        <div class="row-form clearfix">
           <div class="span3">
                <label>Invoice type</label>
                <select name="invoice_type" onchange="get_invoice_type(this.value);">
                <option value="0">ALL</option>
                <option value="1">Invoice No</option>                       
                </select>
            </div>
            <div class="span3" id="invoice_no_div" style="display:none;">
            <label>Invoice No</label>
            <input type="text" name="invoice_no" id="invoice_no" />
            </div>
            <div class="span1">        
               <label>Month</label>		
                <select name="month">
                    <option value="">Month</option>
                    <option value="01">Jan</option>
                    <option value="02">Feb</option>
                    <option value="03">Mar</option>
                    <option value="04">Apr</option>
                    <option value="05">May</option>
                    <option value="06">Jun</option>
                    <option value="07">Jul</option>
                    <option value="08">Aug</option>
                    <option value="09">Sep</option>
                    <option value="10">Oct</option>
                    <option value="11">Nov</option>
                    <option value="12">Dec</option>
               </select>
           </div>
            <div class="span1">        
             <label>Year</label>		
             <select name="year">
                    <option value="">Year</option>
                    <?php 
                    for($i=2010;$i<2056;$i++){?>
                    
                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
                    <?php } ?>
               </select>
           </div>
           <div class="span2">
           	<label>&nbsp;</label>
            <input type="submit" name="Search" class="btn btn-block" value="Search"/>
           </div>         
        </div>     
        </form>           
    </div>
    </div>
    </div>
<?php
if(isset($_POST['Search']))
{
	unset($_SESSION['invoice_type']);unset($_SESSION['view_qry']);
	$sqlQuery = "";		
	if(!empty($_POST['invoice_no']))
	{
		$sqlQuery .= " and `invoice_no`='".$_POST['invoice_no']."'";
	}
	if(!empty($_POST['month']))
	{
		$sqlQuery .= " and `month`='".$_POST['month']."'";
	}
	if(!empty($_POST['year']))
	{
		$sqlQuery .= " and `year`='".$_POST['year']."'";
	}	
	$sql		= " SELECT * FROM `tbl_invoice` where `bill_mode` !='SALE' $sqlQuery";
	$_SESSION['invoice_qry']		 = $sql;
}
?>   
<?php
if(isset($_SESSION['invoice_qry']))
{
	//echo $_SESSION['invoice_qry'];die;
	$menu		= mysql_query($_SESSION['invoice_qry'])or die(mysql_error());
	$count		= mysql_num_rows($menu);
?>     
    <div class="row-fluid" >
    <div class="span12">    
    	<div class="head clearfix">
        <div class="isw-ok"></div>
        <h1>View Invoice List&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Total Records  : <?php echo $count;?></h1>  
     </div>   
   		<div class="block-fluid">
        	<table cellpadding="0" cellspacing="0" width="100%" class="table" id="example">
                <thead>
                    <tr>
                        <th>S.No.</th>
                        <th>Invoice No</th>
                       	<th>Invoice Date</th>
                        <th>Month</th>
                        <th>Year</th>
                        <th>State</th>
                        <th>Amount</th>
                        <th>Print</th>
                        <th>Delete</th>
                    </tr>
                </thead>                 
                <tbody>
					<?php
					$i=1;
                    while($show_menu = mysql_fetch_array($menu)) 
                    {
						$a			 = "<img height='20' width='20' src='images/right.png'/>";
						$b			 = "<img height='20' width='20' src='images/wrong.png'/>";
						
                    ?>	
                    	<tr>
                        <td><?php echo $i++; ?></td>
                        <td ><?php echo ($show_menu['invoice_prefix']); ?><?php echo ($show_menu['invoice_no']); ?></td>
                        <td><?php echo ($show_menu['date']); ?></td>
                        <td><?php echo ($show_menu['month']); ?></td>
                        <td><?php echo ($show_menu['year']); ?></td>
                        <td><?php echo ucwords($show_menu['state']); if($show_menu['bill_for']=='RSP'){ echo "<span style='color:red;'>-RSP</span>";}?></td>
                        <td><?php echo ($show_menu['amt']); ?></td>                        
                        <td class="center" style="text-align:center">
                        	<a target="_blank" href="pages/invoice/print_invoice.php?invoice_no=<?php echo $show_menu['invoice_no'];?>&invoice_prefix=<?php echo $show_menu['invoice_prefix'];?>"><img src="images/print.png" style="width: 20px;" border="0"></a>
                        </td>
                        <td class="center" style="text-align:center">
                        	<a onclick="return confirm_delete();" href="home.php?page=view_invoice&invoice_no=<?php echo $show_menu['invoice_no'];?> "><img src="images/delete.png" style="width: 20px;" border="0"></a>
                        </td>
                    </tr>
               	   <?php } ?> 
               	   
               	   <?php 
				   /*$menu_1             = mysql_query( " SELECT DISTINCT `bill_no`,`date`,`grand_total` FROM `tbl_sale` WHERE 1 ")or die(mysql_error());
				    while($show_menu_1 = mysql_fetch_array($menu_1)) 
					{					
					?>	
                    	<tr>
                        <td><?php echo $i++; ?></td>
                        <td >RHLLP/2018-2019/<?php echo ($show_menu_1['bill_no']); ?></td>
                        <td><?php echo ($show_menu_1['date']); ?></td>
                        <td></td>
                        <td></td>
                        <td>Ryka</td>
                        <td><?php echo ($show_menu_1['grand_total']); ?></td>                        
                        <td class="center" style="text-align:center">
                        	<a target="_blank" href="pages/invoice/sale_invoice.php?invoice_no=<?php echo ($show_menu_1['bill_no']); ?>&invoice_prefix=RHLLP/2018-2019/"><img src="images/print.png" style="width: 20px;" border="0"></a>
                        </td>
                        <td class="center" style="text-align:center"></td>
                    </tr>
               	   <?php } */?>  
                </tbody>            
            </table> 
        </div>    
   </div>
   </div>            
<?php }
if(isset($_GET['invoice_no']))
{
	$invoice_no		= $_GET['invoice_no'];	
	$sql1			= mysql_query(" DELETE FROM `tbl_invoice` WHERE `invoice_no`='$invoice_no' ")or die(mysql_error());
	$sql2			= mysql_query(" DELETE FROM `tbl_isr_details` WHERE `invoice_no`='$invoice_no' ")or die(mysql_error());
	$_SESSION['msg']= " Successfully Deleted Invoice No: ".$invoice_no;
	header("location:home.php?page=view_invoice");
}
?>
<script>
function confirm_delete(row_num,delete_id)
{
	if (confirm("Delete Account?"))
	{
		showModal(row_num,delete_id);
		  return true;
	}
	else
	{
	   return false;
	}
}  
function get_invoice_type(val)
{
	if(val==0)
	{
		$("#invoice_no_div").css("display","none");
		document.querySelector('#invoice_no').required = false;
	}
	else
	{
		$("#invoice_no_div").css("display","block");
		document.querySelector('#invoice_no').required = true;
	}
}
$(document).ready(function() {
    var table = $('#example').DataTable( {
		"order": [[ 2, "asc" ]],
		"pageLength": 50,stateSave: true,
        fixedHeader: {
            header: true,
            footer: true
        }
    } );
	 table.on( 'order.dt search.dt', function () {
        table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw(); } );
	</script>    