<?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">Customer Opening</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>

								Customer Opening

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

	

jQuery(function($){

		   

	// simple jQuery validation script

	$('#course').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']))







{







$date=$_POST['date'];







$customer=$_POST['customer'];







$narration=$_POST['narration'];







$paymenttype=$_POST['type'];







$amount=$_POST['amount'];











		$d=date("m",strtotime($date));



		if($d>03)



		{



		$y=date("Y",strtotime($date));



		$y1=$y+1;		



		



		$dd=date($y);



		$dd1=date($y1);	



		}



		elseif($d<=03)



		{



		$y1=date("Y",strtotime($date));



		$y=$y1-1;	



		



		$dd=date($y);



		$dd1=date($y1);	



		}



		



		$financial=$dd.'-'.$dd1;



		







if($customer && $amount)







{







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







$insert="INSERT into debitor_ledger(date,customer,paymenttype,amount,remarks) values('$date','$customer','$paymenttype','$amount','$narration')";







mysql_query($insert) or die(mysql_error());







}















if($insert){







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







}







else{







header("location:debitor_ledger.php?s=2" . urlencode($Message));







}











}







else







{















echo '

<br>









<form action="debitor_obl.php" method="post" id="customer">







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







<tr><td id="page">Date <span class="red">*</span></td><td>:</td> <td id="page"><input type="text" name="date" id="required1" title="Select Date" class="datepicker" autocomplete="off" /></td></tr>







<tr><td id="page">Customer <span class="red">*</span></td><td>:</td> <td id="page"><select name="customer" style="width:220px;" id="required1" title="Select Customer"><option value="">Select Customer</option>';







$sl=mysql_query("select * from customer order by name asc");



while($sl1=mysql_fetch_array($sl))



{







$chk=mysql_query("select COUNT(ID) from debitor_ledger where customer='".$sl1['ID']."'");



$chk1=mysql_result($chk,0);







if($chk1==0)



{



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



}







}







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







<tr><td id="page">Payment Type <span class="red">*</span></td><td>:</td><td id="page"><select name="type" style="width:220px;" id="required1" title="Select Type"><option value="debit">Debit</option><option value="credit">Credit</option></select></td></tr>







<tr><td id="page">Amount <span class="red">*</span></td><td>:</td><td id="page"><input size="50" type="text" name="amount" id="required1" title="Enter Amount" autocomplete="off" /></td></tr>







<tr><td id="page">Narration </td><td>:</td><td id="page"><textarea name="narration" style="width:220px; height:70px;"></textarea></td></tr>';







echo'<tr><td colspan="2"></td><td id="page"><button id="save" type="submit" name="submit" value="Add" class="btn btn-sm btn-primary">Save</button></td><td id="page"></td></tr>







</table></center>







</form>';







}



?>

                                                                

        

								



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

?>