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

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



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



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



}







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=mysqli_query($conn,"select * from debitor_ledger where customer='$id' order by ID desc");

$ch=mysqli_num_rows($sl);

$sl1=mysqli_fetch_assoc($sl);



//echo"$sl1[amount]";



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

$sup1=mysqli_fetch_assoc($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 class="form-control" style="width:30ch; margin-bottom:10px;" type="text" name="date" value="'.$date.'" autocomplete="off" id="datepicker" title="Select Date" class="datepicker" /required></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  class="form-control" style="width:30ch; margin-bottom:10px;" 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 class="form-control" style="width:30ch; margin-bottom:10px;" 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 class="form-control" style="width:30ch; margin-bottom:10px;" 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 class="form-control" style="width:30ch; margin-bottom:10px;" 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 -->
					</div><!-- /.main-content -->
					</div><!-- /.main-content -->







<?php



include 'bottom.php';



}

else

{



 header("location:login.php");

 

}



ob_flush();



?>