<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Imprest</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>                        
                        
						<table style="width:100%;">
                        
                        <tr><td style="width:50%;">

                        
							<h1>
								Imprest
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>                        
						</div><!-- /.page-header -->
<br />

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->
                                
<script src="assets/js/jquery.js"></script>

<script>

  $(".bank").live('change',function()
		  {
		  var bank=$(this).val();
		  var dataString = 'bank='+ bank;
		  //alert(dataString);
		  $.ajax
		  ({
		  type: "GET",
		  url: "getacc.php",
		  data: dataString,
		  cache: false,
		  success: function(resp)
		  {
		  //alert(resp);
		  //var company=$(resp).filter('#company').text();
		  //alert(company);
		  $('.account').html($('#account',resp).html());
		  }
		  });
		  });
		  
</script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#work').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>
								
<?php
	
if(isset($_GET['id']))
{
	
$id=$_GET['id'];

if(isset($_POST['submit']))
{

$id=$_POST['id'];
$date=$_POST['date'];
$factory=$_POST['factory'];
$description=$_POST['description'];
$amount=$_POST['amount'];

if($factory)
{

$date=date('Y-m-d',strtotime($date));

$up=mysql_query("update imprest set date='$date',factory='$factory',description='$description',amount='$amount' where ID='$id'");

if($up)
{

header("location:viewimprest.php?s=1");

}

}

else
{
	
header("location:viewimprest.php?s=2");
	
}

}

else
{

$imac=mysql_query("select * from imprest where ID='".$id."'");
$imac1=mysql_fetch_array($imac);

$b=mysql_query("select * from bank where ID='$cus1[account]'");
$b1=mysql_fetch_array($b);

if($cus1['chequedate']!='0000-00-00')
{
	$cdate=date('d-m-Y',strtotime($cus1['chequedate']));
}

echo'<form action="viewimprest.php?id='.$id.'" method="post" id="work">

<input type="hidden" name="id" value="'.$id.'" />

<center><table width="70%" id="page" style="line-height:35px;">







<tr><td id="page">Date <span class="red">*</span></td><td width="2%">:</td> <td id="page"><input type="text" name="date" autocomplete="off" class="datepicker" id="required" title="*" value="'.date('d-m-Y',strtotime($imac1['date'])).'" /></td></tr>



<tr><td id="page">Factory <span class="red">*</span></td><td width="2%">:</td> <td id="page"><select name="factory" id="required" title="*" style="width:220px;">

<option value="">Select Factory</option>';





$cus=mysql_query("select * from factory order by factory asc");



while($cus1=mysql_fetch_array($cus))



{



$imprac="<option value='".$cus1['ID']."'>".$cus1['factory']."</option>";
$imprac=str_replace("<option value='".$imac1['factory']."'","<option value='".$imac1['factory']."' selected",$imprac);
echo $imprac;



}







echo'</select></td></tr>




<tr><td id="page">Description <span class="red">*</span></td><td width="2%">:</td> <td id="page"><textarea name="description" style="width:220px; height:70px;" id="required" title="*">'.$imac1['description'].'</textarea></td></tr>







<tr><td id="page" style="width:180px;">Amount <span class="red">*</span></td><td width="2%">:</td> <td id="page"><input size="25" type="text" name="amount" autocomplete="off" id="required" title="*" value="'.$imac1['amount'].'" /></td></tr>


</table>

<br /><table><tr><td id="page"><button type="submit" class="btn btn-sm btn-primary" name="submit" value="Add">Save</button></td></tr></table></center>

</form>';

}

}

else
	{
	
	if (isset($_GET['s'])) 
	{
	 $status=$_GET['s'];
		 if($status=='1')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					Values Edited Successfully !
			  </div>';
		}
		elseif($status=='2')
		 {
		 echo '<div class="alert alert-danger">
				<a class="close" data-dismiss="alert">x</a>
					Values Not Edited. Try Again.
			  </div>';
		}
		elseif($status=='5')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					Values Deleted Successfully !
			  </div>';
		}
	}




echo'<table style="width:99%; margin:auto;">
                                        
                                        <tr><td style="width:20%;">
                                        <a href="imprest.php"><button class="btn btn-minier btn-info">+ Create New</button></a>
                                        </td>
                                        
                                        <td style="width:50%;"></td>
                                        
                                        <td style="width:30%;">
                                        <div class="clearfix" style="padding-top:5px;">
											<div class="pull-right tableTools-container"></div>
										</div>
                                        </td>
                                        
                                        </tr>
                                        
                                        </table>';
									
echo'<table id="dynamic-table" class="table table-striped table-bordered table-hover">';

echo"<thead><tr><th width='7%'>S.No</th><th style='width:12%;'>Date</th><th width='25%'>Factory</th><th width='20%'>Amount (Rs.)</th><th style='width:8%;'>Edit</th></tr></thead>
<tbody>";

$select="select * from imprest where date between '$aca1[fromdate]' and '$aca1[todate]' order by ID asc";
$select1=mysql_query($select);
$sno=0;
while($value=mysql_fetch_array($select1))
{
$sno=$sno+1;

$cus=mysql_query("select * from factory where ID='$value[factory]'");
$cus1=mysql_fetch_array($cus);
		
echo"<tr><td>".$sno."</td><td>".date('d-m-Y',strtotime($value['date']))."</td><td>$cus1[factory]</td><td style='text-align:right;'>$value[amount]</td><td>

													   <div class='hidden-sm hidden-xs btn-group'>
													   
															<a href='viewimprest1.php?id=".$value['ID']."' title='View'>
																<i class='ace-icon fa fa-search-plus bigger-100 blue'></i></a> &nbsp;
																
															<a href='viewimprest.php?id=".$value['ID']."' title='Edit'>
																<i class='ace-icon fa fa-pencil bigger-100 green'></i></a> &nbsp;
																
															<a href='del.php?id=".$value['ID']."&desc=imprest' title='Delete'>
																<i class='ace-icon fa fa-trash-o bigger-100 red'></i></a>
															
														 </div>

</td></tr>";
}

echo"</tbody></table>";

	}
	

?>                                
                               
								

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					

</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();
?>