<?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">Supplier 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>

								Supplier 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">
  <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']))







{







$date=$_POST['date'];







$supplier=$_POST['supplier'];







$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($supplier && $amount)







{







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







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







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







}















if($insert){







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







}







else{







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







}











}







else







{















echo '

<br>









<form action="creditor_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:20px;" type="text" name="date" id="datepicker" title="Select Date"  autocomplete="off" /required1></td></tr>







<tr><td id="page">Supplier <span class="red"></span></td><td></td> <td id="page"><select class="form-control" style="width:30ch; margin-bottom:20px;" name="supplier" style="width:220px;" id="required1" title="Select Supplier"><option value="">Select Supplier</option>';







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



while($sl1=mysqli_fetch_assoc($sl))



{







$chk=mysqli_query($conn,"select * from creditor_ledger where supplier='".$sl1['ID']."'");



$chk1=mysqli_num_rows($chk);







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 class="form-control" style="width:30ch; margin-bottom:20px;" 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 class="form-control" style="width:30ch; margin-bottom:20px;" 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 class="form-control"  style="width:30ch; height:20ch; margin-bottom:20px;" 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 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();

?>