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

$gtp=mysqli_query($conn,"select * from admin where username='$user'");
$gtp1=mysqli_fetch_assoc($gtp);

include 'top.php';
?>


<div id="page-wrapper" >
          <div id="page-inner">
<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">Receipt</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

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

$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");
$aca1=mysqli_fetch_assoc($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Receipt
							</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>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
  <style>
    .datepicker-wrapper {
      position: relative;
    }
  </style>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
  <script>
    $(function() {
      // Initialize the datepicker
      $("#datepicker").datepicker({
        format: "mm/dd/yyyy",
        autoclose: true,
        todayHighlight: true
      });

      // Adjust the positioning of the datepicker dropdown
      $("#datepicker").on("show", function(e) {
        var inputOffset = $(this).offset();
        var inputHeight = $(this).outerHeight();
        var datepickerDropdown = $(".datepicker-dropdown");

        datepickerDropdown.css({
          top: inputOffset.top + inputHeight + 10,
          left: inputOffset.left
        });
      });
    });
  </script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css">
 <style>
    /* Custom CSS for Chosen select */
    .chosen-container {
      width: 25ch;
    }

    .chosen-container-single .chosen-single {
      border-radius: 4px;
      border: 1px solid #f0f0f0; /* Change the border color here */
      height:34px;
	  margin-bottom:10px;
      background-color: #fff;
      background-image: none;
      box-shadow: 0 0 0 1px #c0c0c0;
    }

    .chosen-container-single .chosen-single span {
      padding: 5px;
      text-transform: uppercase;
    }

    .chosen-container-single .chosen-search input[type="text"] {
      border-radius: 4px;
      border: 1px solid #c0c0c0;
      height: 34px;
    }

    .chosen-container-active .chosen-single {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-single:hover {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-search input[type="text"] {
      border-color: #7f7f7f;
    }
  </style>
<script>
$(document).ready(function() {
  $(".chosen-select").chosen();
});

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

		  {

		  $('.account').html($('#account',resp).html());

		  }

		  });

		  });

		  

$(".customer").live('change',function()

		  {

		  var customer=$(this).val();

		  

		  var customer=customer.replace('&', '%26');

		  

		  var dataString = 'customer='+ customer;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getbal.php",

		  data: dataString,

		  cache: false,

		  success: function(html)

		  {

		  //alert(html);

			var bal=$(html).filter('#bal').text();

	

			$('.bal').html(bal);

		  }

		  });

		  });


</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($_POST['submit']))







{







$date=$_POST['date'];



$customer=$_POST['customer'];



$receiptno=$_POST['receiptno'];



$description=$_POST['description'];



$amount=$_POST['amount'];



$type=$_POST['paymentmode'];



$account=$_POST['account'];



$chequeno=$_POST['chequeno'];



$chequedate=$_POST['chequedate'];



$cid=$_POST['cid'];



$redpage=$_POST['redpage'];


$upimobileno=$_POST['upimobileno'];




if($customer)







{







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





if($chequedate!='')

{

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

}





$insert="INSERT into receipt(date,customer,description,amount,paymentmode,account,chequeno,chequedate,upimobileno) values('$date','$customer','$description','$amount','$type','$account','$chequeno','$cdate','$upimobileno')";







mysqli_query($conn,$insert) or die(mysqli_error($conn));







}











if($insert){





if($redpage!='')

{

	header("location:".$redpage."?customer=".$cid."&s=1");

}

else

{

header("location:receipt.php?s=1" . urlencode($Message));

}







}







else{







echo "<script type='text/javascript'>alert('Field Missing.');</script><META HTTP-EQUIV = 'Refresh' Content = '1; URL =receipt.php'>";







}







}







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>



					Receipt Added Successfully !



			  </div>';



		}



	}



$cid=$_GET['custid'];

$redpage=$_GET['redpage'];



echo '<form action="receipt.php" method="post" id="work">



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

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



<br />







<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 class="form-control" style="width:30ch; margin-bottom:10px;" type="text" name="date" autocomplete="off" class="datepicker" id="datepicker" title="*" autocomplete="off" /required></td></tr>



<tr><td id="page">Customer <span class="red"></span></td><td width="2%"></td> <td id="page"><select class="form-control chosen-select"style="width:30ch; margin-bottom:10px;" name="customer" class="customer" id="required" title="*" style="width:220px;">

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





$cus=mysqli_query($conn,"select * from customer order by name asc");



while($cus1=mysqli_fetch_assoc($cus))



{



echo"<option value='".$cus1['ID']."'>".$cus1['name']."</option>";



}







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





<tr><td id="page">Balance </td><td width="2%"></td> <td id="page"><div class="bal"></div></td></tr>





<tr><td id="page">Description <span class="red"></span></td><td width="2%"></td> <td id="page"><textarea class="form-control"  style="width:30ch; height:20ch; margin-bottom:10px;" name="description" style="width:220px; height:70px;" id="required" title="*"></textarea></td></tr>







<tr><td id="page" style="width:180px;">Amount <span class="red"></span></td><td width="2%"></td> <td id="page"><input  class="form-control" style="width:30ch; margin-bottom:10px;"size="25" type="text" name="amount" autocomplete="off" id="required" title="*" autocomplete="off" /></td></tr>';







?>







<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";
	
	
	
	document.getElementById("gpay").style.display = element=="gpay"?"block":"none";



}



</script>







<table width="70%" id="page">







<tr><td id="page" style="width:180px;">Payment Mode <span class="red"></span></td><td width="2%"></td> <td id="page"><select class="form-control" style="width:30ch; margin-bottom:10px;" 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>



<option value="gpay">G-Pay</option>



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







</table>







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



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

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

<tr><td style="width:180px;">Mobile No.</td><td style="padding:0 0px 0 3px;"></td><td><input class="form-control" style="width:30ch; margin-bottom:20px; margin-left:10px" type="text" name="upimobileno" /></td></tr>

</table>

</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:180px;">Bank name <font color="red"></font> </td><td style="padding-right:13px;"></td><td id="page">







<select style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="bank" class="bank" style="width:220px;"><option value="">Select Bank</option>







<?php







$bn=mysqli_query($conn,"select * from bank group by bank");



while($bn1=mysqli_fetch_assoc($bn))



{







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







}







?>







</select>







</td></tr>







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







<select style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" name="account" class="account" style="width:220px;"><option value="">Select Account Name</option></select>







</td></tr>





<tr><td id="page" width="180">Cheque No </td><td width="11"></td><td id="page"><input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" type="text" name="chequeno" autocomplete="off" /></td></tr>



<tr><td id="page" width="180">Cheque Date </td><td width="11"></td><td id="page"><input style="width: 30ch;padding-left:10px; margin-bottom:10px; height:34px;border-radius: 5px;border: 1px solid #c0c0c0;" type="text" name="chequedate" class="popupdatepicker" autocomplete="off" /></td></tr>





</table>



</DIV>







<?php



echo'<br>



<center><button style="margin-left:-90px;" class="btn btn btn-primary" type="submit" name="submit" value="Add">Save</button></center>




</form>';







}



	



?>                                
                               
							<br>
<br>
	

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

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


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

 header("location:login.php");
 
}

ob_flush();

?>