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

require_once("config/configDB.php");


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


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

$invoice   = $rowInvoiceCount['invoice']+1;

$sql_supplier = mysqli_query($conn,"SELECT sh.supplier_id,cm.sname FROM purchaseheader as sh  join supplier_master as cm on cm.id=sh.supplier_id WHERE cm.isdelete='1' GROUP BY sh.supplier_id order by cm.sname asc");
$row_supplier = '';

?>
<!DOCTYPE html>
<html>
<head>
    <title>Payment Entry</title>
    <?php require 'header.php' ?>


<script>
function billvalid()
{
	
	if (document.form1.purchase_bill_no.value == "")
	{	
		alert ("Please Select Particular bill.");
		document.form1.purchase_bill_no.focus();
		return false;
	}
	
}

</script>
</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
    <form class="form-horizontal" action="paypurchaseInsert.php" method="post" onSubmit="return checkForm(this);" autocomplete="off">
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Cash No</label>
      <div class="col-sm-5">
      <input type="text" class="form-control" name="cashno" value="<?php echo "CASH-".$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 type="text" class="form-control datepicker-collection" name="collectiondate" required>
      </div>
      
    </div>
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">supplier name</label>
      <div class="col-sm-5">
      <select class="form-control input-lg supplierName-select-box" name="supplierName">
        <option value="">Please Select the supplier </option>
        <?php
        while($row = mysqli_fetch_array($sql_supplier)){
        ?>
        <option value="<?php echo $row['supplier_id'] ?>" > <?php echo $row['sname']; ?> </option>
        <?php
        //echo "<option value='".$row['id']."'>".$row['sname']."</option>";
        }
        ?>
        </select>
      </div>
    </div>
    <!-- <div class="form-group">
      <label class="control-label col-sm-3" for="email">Total Amount</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="tamount">
      </div>
    </div> -->
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Total Pending</label>
      <div class="col-sm-5">
        <input type="text" class="form-control supplier-pending-amount" id="pamount" name="pending" readonly>
      </div>
      
    </div>
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Pending Bill List</label>
      <div class="col-sm-5">
      <select class="form-control pend_bill_list" id="pend_bill_list" name="purchase_bill_no">
        
        
        </select>
      </div>
      
    </div>
  
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Pending Bill Amount</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="pamount" id="pbillamount" readonly>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Amount</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="amount" required>
      </div>
    </div> 

     <div class="form-group">
      <label class="control-label col-sm-3" for="email">Payment Type</label>
      <div class="col-sm-5">
      <select class="form-control collect-paymenttype" id="paymenttype" name="paymenttype">
        <option value="cash">CASH</option>
        <option value="cheque">CHEQUE</option>
        <option value="online">ONLINE</option> 
        <option value="UPI">UPI</option>        
      </select>

      </div>
     
    </div> 
    <div class="form-group" paymentreference>
      <label class="control-label col-sm-3" for="email">Reference number</label>
     <div class="col-sm-3">
        <input type="text" class="form-control " name="paymentreference">
      </div>
      </div>
   
    <div class="form-group">        
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" id="smbt" name="myButton" class="btn btn-default">Submit</button>
      </div>
    </div>
  </form>   
</div>


    <?php require 'footer.php' ?>
   
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
    <script type="text/javascript" language="javascript" src="js/purchasepayment.js"></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;
  };
	$(document).ready(function(){
		var date_input=$('input[name="collectiondate"]'); //our date input has the name "date"
		var container=$('form >  .datepicker-collection').length>0 ? $('form > .datepicker-collection ').parent() : "body";
		date_input.datepicker({
			format: 'dd-mm-yyyy',
			container: container,
			todayHighlight: true,
			autoclose: true,
        });

    
        var paymentType = $('.collect-paymenttype').val();
        console.log(paymentType);
        if(paymentType == 'cash') {
            $('.paymentreference').hide();
        } else {
            $('.paymentreference').show();
        }
        

	});
</script>
</body>
</html>