<?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']))



{



$id=$_POST['id'];



$date=$_POST['date'];



$customer=$_POST['customer'];



$narration=$_POST['narration'];



$paymenttype=$_POST['type'];



$amount=$_POST['amount'];



if($customer && $amount)



{



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



$insert="UPDATE debitor_ledger set date='$date',customer='$customer',paymenttype='$paymenttype',amount='$amount',remarks='$narration' where ID='$id'";



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



}







if($insert){



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



}



else{



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



}





}



else

{



$id=$_GET['id'];



$sl=mysql_query("select * from debitor_ledger where customer='$id' order by ID desc");

$ch=mysql_num_rows($sl);

$sl1=mysql_fetch_array($sl);



//echo"$sl1[amount]";



$sup=mysql_query("select * from customer where ID='$sl1[customer]'");

$sup1=mysql_fetch_array($sup);



if($ch>0)

{



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



}



else

{



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



}



echo'<form action="editdebitor_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" value="'.$date.'" autocomplete="off" id="required1" title="Select Date" class="datepicker" /></td></tr>



<tr><td id="page">Customer <span class="red">*</span></td><td>:</td> <td id="page">

<input type="hidden" name="id" value="'.$sl1['ID'].'" />

<input type="hidden" name="customer" value="'.$id.'" /><input type="text" id="required1" readonly="true" title="Select Customer" value="'.$sup1['name'].'"></td></tr>



<tr><td id="page">Payment Type <span class="red">*</span></td><td>:</td><td id="page"><select name="type" id="required1" title="Select Type" style="width:220px;">';



?>



<option value="debit" <?php if($sl1['paymenttype']=='debit'){ echo'selected="selected"'; } ?>>Debit</option>

<option value="credit" <?php if($sl1['paymenttype']=='credit'){ echo'selected="selected"'; } ?>>Credit</option>



<?php



echo'</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" value="'.$sl1['amount'].'" /></td></tr>



<tr><td id="page">Narration </td><td>:</td><td id="page"><textarea name="narration" rows="3" cols="30">'.$sl1['remarks'].'</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();



?>