<?php 
require_once("config/configDB.php"); 
require "userPermission.php";

require "financial_year_calculation.php";
$accountyear    = $financialYearStart."-".$financialYearEnd;


$sql_employee = mysqli_query($conn,"SELECT id,ename FROM employee_master WHERE isdelete='1' order by ename ASC ");
$row_employee = '';



$sqlInvoiceCount = mysqli_query($conn,"SELECT count(*) as invoice FROM employee_advance_collection where  accountyear='$accountyear' and status=''");
 
$rowInvoiceCount=mysqli_fetch_array($sqlInvoiceCount,MYSQLI_ASSOC);

$invoice1   = sprintf('%03d',$rowInvoiceCount['invoice']+1);

$acyear="ADVC/".$syr."-".$eyr."/";

$invoice= $acyear.$invoice1;



date_default_timezone_set('Asia/Kolkata');
$currentTime = date( 'h:i:s A', time () );


?>

<!DOCTYPE html>
<html>
<head>
    <title>Advance Add</title>
    <?php require 'header.php' ?>
    <style>
    
    .table-grid{
        display: grid;
        width:95%;
        max-width: 95vw;
        margin:0px auto;
        height:100px;
        background-color: sandybrown;
        grid-template-columns: 200px repeat(8, auto) 90px;
    }
    .each-section{
        background-color: aqua;
        display:grid;
        grid-template-rows: 50% 50%;
    }
    .each-section div{
        background-color: white;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0px 10px;
        border: 1px solid #ccc;
    }
    .section-label{
        font-weight:700;
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size:14px;
       
    }
    .section-input{
        background-color: #eee !important;
    }
    
    @media screen and (max-width:720px){
        .table-grid{
            display: flex;
            flex-direction: column;
            height:auto;
        }
        .each-section{
            grid-template-rows: 100%;
            grid-template-columns: 40% 60%;
            padding: 0px 0px;
        }
        .each-section div{
            padding: 10px;
        }
        .section-input input[type=button]{
            width:80%;
        }
    }
</style>


    
</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<form class="form-horizontal" action="Advance_collection_addInsert.php" method="post" onSubmit="return checkForm(this);" autocomplete="off">

<h3 align="center" >Employee Advance Collection</h3>

<div class="form-group">
      <label class="control-label col-sm-3" for="email">Cash No</label>
      <div class="col-sm-5">
     <input class="form-control input-lg" type="text" name="advance_no" value="<?php echo $invoice; ?>" readonly>
      </div>

    </div>
    
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Date</label>
      <div class="col-sm-5">
    <input class="form-control input-lg "  type="date" name="advance_date" autocomplete="off" required>
      </div>

    </div>
    
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Emp.Name</label>
      <div class="col-sm-5">
    <select class="form-control input-lg selectpicker" data-show-subtext="true" data-live-search="true" name="employee_id" id="employee_id" required>
        <option value="">Please Select the Employee </option>
        <?php
        while($row4 = mysqli_fetch_array($sql_employee)){
        ?>
        <option value="<?php echo $row4['id'] ?>" > <?php echo $row4['ename']; ?> </option>
        <?php
        //echo "<option value='".$row['id']."'>".$row['cname']."</option>";
        }
        ?>
        </select>
      </div>

    </div>

 <div class="form-group">
      <label class="control-label col-sm-3" for="email">Total&nbsp;Advance&nbsp;Amount</label>
      <div class="col-sm-5">
    <input class="form-control input-lg "  type="text" name="advance_amount" id="advance_amount" autocomplete="off" required readonly>
      </div>

    </div>
    
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Collecting&nbsp;Amount</label>
      <div class="col-sm-5">
    <input class="form-control input-lg "  type="number" name="advance_collection_amount" autocomplete="off" required>
      </div>

    </div>
    
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Mode</label>
      <div class="col-sm-5">
    <select class="form-control input-lg selectpicker" data-show-subtext="true" data-live-search="true" name="transaction_mode" required>
        <option value="">Please Select the Mode </option>
        <option value="Cash">Cash</option>
        <option value="Phonepe">Phonepe</option>
         <option value="Gpay">Gpay</option>
        <option value="Bank">Bank</option>
        </select>
      </div>

    </div>
    
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Remark</label>
      <div class="col-sm-5">
    <textarea class="form-control input-lg "  name="remarks" autocomplete="off"></textarea>
      </div>

    </div>


<div class="form-group">        
    <div class="col-sm-12 text-center">
        <button type="submit" name="myButton" id="myButton" class="btn btn-default ">Submit</button>
    </div>
</div>

</form>
</div>
    <?php require 'footer.php' ?>
    <script type="text/javascript">var sql_product = "<?= $sql_product ?>";</script>
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
   
    <!-- Include jQuery -->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<script>

  var checkForm = function(form) {

    //
    // validate form fields
    //

    form.myButton.disabled = true;
    return true;
  };


</script>

    

<script>
	 $('#employee_id').change(function(){  
	  var queryx=$(this).val();
	   //alert(queryx);
                $.ajax({  
                     url:"pickadvance.php",   
                     method:"POST",  
                     data:{query:queryx},
                     success:function(data1)  
                     {
						 var data0 = data1.split("||");
                          $('#advance_amount').val("");  
                          $('#advance_amount').val(data0[0]); 
						  
						  //alert(data0[0] ); 
                          
							
					 }
				});
		});
	
	
	
	</script>
 
    

</body>
</html>