<?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">Expense</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>

								Expense

							</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 -->



						<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;

	});

	

});	



</script>                                

								

                                

                                

<?php        











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







$id = $_POST['id'];







$date = $_POST['date'];







$amount=$_POST['amount'];







$name=$_POST['name'];







$description = $_POST['description'];







$category = $_POST['category'];





$factory=$_POST['factory'];





$type=$_POST['paymentmode'];







$account=$_POST['account'];







$chequeno=$_POST['chequeno'];







$chequedate=$_POST['chequedate'];







 // now we insert it into the database



 



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



 



if($date && $amount && $description)







{ 





if($chequedate!='')



{



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



}





$in= "INSERT INTO expense(ID,date,name,amount,description,category,paymentmode,account,chequeno,chequedate,factory)







			VALUES('$id','$date','$name','$amount','$description','$category','$type','$account','$chequeno','$cdate','$factory')";



			







$in1 = mysql_query($in) or die(mysql_error());











if($in1)







{







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







}







}



else



{



 header("location:expense.php?s=2");



}







}











 else 







 {	



 



 if (isset($_GET['s'])) 



	



	{



	 $status=$_GET['s'];



		 if($status=='1')



		 {



           echo'<div class="alert alert-success alert-dismissable" style="width:80%; margin:auto;">



                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>



                <span style="text-align:left;">Expense Added Successfully.</span>



                </div><br />';



		}



		if($status=='2')



		 {



           echo'<div class="alert alert-danger alert-dismissable" style="width:80%; margin:auto;">



                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>



                <span style="text-align:left;">Field Missing. Enter Values For All Fields.</span>



                </div><br />';



		}



				



	}



 



?>







<form id="work" action="expense.php" method="post">







<?php



$n=mysql_query("select MAX(ID) as id from expense");



$n1=mysql_fetch_array($n);







$nid=$n1['id']+1;



?>







<table width="70%" style="margin:auto; line-height:35px;">







<tr><td width="32%">Exp.No <span class="red">*</span></td><td width="11">:</td><td><input type="text" name="id" readonly="true" readonly="readonly" value="<?php echo $nid; ?>" autocomplete="off" /></td></tr>







<tr><td width="32%">Date <span class="red">*</span></td><td width="11">:</td><td><input autocomplete="off" type="text" class="datepicker" name="date" required value="<?php echo date('d-m-Y') ?>" autocomplete="off" /></td></tr>





<tr><td width="32%">Factory <span class="red">*</span></td><td width="11">:</td><td>



<select name="factory" style="width:220px;" id="required" title="*">



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



<?php



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

while($fac1=mysql_fetch_array($fac))

{

echo"<option value='".$fac1['ID']."'>".$fac1['factory']."</option>";

}



?>



</select>



</td></tr>





<tr><td>Select Category <span class="red">*</span></td><td>:</td><td><select name="category" id="required" title="*" style="width:220px;"><option value="">Select Category</option>



<?php







$sel=mysql_query("select * from exp_category order by ID ASC");



while($sel1=mysql_fetch_array($sel))



{



echo"<option value='".$sel1['category']."'>".$sel1['category']."</option>";



}







?>



</select></td></tr>







<tr><td>Name <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="name" id="required" title="*" autocomplete="off" /></td></tr>







<tr><td>Amount <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="amount" id="required" title="*" autocomplete="off" /></td></tr>







<tr><td>Reason <span class="red">*</span></td><td>:</td><td><textarea name="description" style="width:220px; height:65px;" id="required" title="*"></textarea></td></tr>







</td></tr></table>











<script type="text/javascript">







function showstuff(element){







    document.getElementById("Cash").style.display = element=="Cash"?"block":"none";







    document.getElementById("Bank").style.display = element=="Bank"?"block":"none";







}







</script>















<table width="70%" style="margin:auto; line-height:35px;">















<tr><td id="page" style="width:32%;">Payment Mode <span class="red">*</span></td><td style="padding:0 1px 0 0;">:</td> <td id="page">



<select name="paymentmode" onchange="showstuff(this.value)" style="width:220px;" id="required" title="*" class="paymentmode">



<option value="">Select Payment Mode</option>







<option value="Cash">Cash</option>  







<option value="Bank">Bank</option>







</select></td></tr>















</table>















<DIV ID="Cash" style="display:none; margin:0px; float:left;"></DIV>















<center><DIV ID="Bank" style="display:none; margin:auto; width:70%;">







<table style="width:100%; line-height:35px;">















<tr><td id="page" style="width:32%;">Bank name <font color="red">*</font> </td><td width="11">:</td><td id="page">















<select name="bank" class="bank" style="width:220px;"><option value="">Select Bank</option>















<?php















$bn=mysql_query("select * from bank group by bank");







while($bn1=mysql_fetch_array($bn))







{















echo"<option value='".$bn1['bank']."'>".$bn1['bank']."</option>";















}















?>















</select>















</td></tr>















<tr><td id="page">Account name <font color="red">*</font> </td><td width="11">:</td><td id="page">















<select name="account" class="account" style="width:220px;"><option value="">Select Account Name</option></select>















</td></tr>











<tr><td id="page">Cheque No </td><td width="11">:</td><td id="page"><input type="text" name="chequeno" autocomplete="off" /></td></tr>







<tr><td id="page">Cheque Date </td><td width="11">:</td><td id="page"><input type="text" name="chequedate" class="popupdatepicker" autocomplete="off" /></td></tr>











</table>







</DIV>





<br />





<center><button type="submit" class="btn btn-sm btn-primary" value="Login" name="submit">Submit</button></center>







</table>







</form>







<?php







}







?>            

        

								



										<!-- 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();

?>