<?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 collection_customer where status=''");
 
$rowInvoiceCount=mysqli_fetch_array($sqlInvoiceCount,MYSQLI_ASSOC);

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

$sql_customer = mysqli_query($conn,"SELECT sh.customer_id,cm.cname FROM saleheader as sh  join customer_master as cm on cm.id=sh.customer_id WHERE   sh.status='' GROUP BY sh.customer_id order by cm.cname");
$row_customer = '';

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

</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
    <form class="form-horizontal" action="collectionInsert.php" method="post" autocomplete="off" onSubmit="return checkForm(this);" >
    <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 "COL-".$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">
      </div>
      
    </div>
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Customer name</label>
      <div class="col-sm-5">
      <select class="form-control input-lg customerName-select-box" name="customerName">
        <option value="">Please Select the Customer </option>
        <?php
        while($row = mysqli_fetch_array($sql_customer)){
        ?>
        <option value="<?php echo $row['customer_id'] ?>" > <?php echo $row['cname']; ?> </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 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 customer-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="sale_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" id="amount">
      </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>
    var checkForm = function(form) {

    //
    // validate form fields
    //

    form.myButton.disabled = true;
    return true;
  };
  </script>
   
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
    <script type="text/javascript" language="javascript" src="js/collection.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>
	$(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();
        }
        
		$("#amount").keyup(function(){
 
 var billamt=$.isNumeric($("#pbillamount").val());//$("#pbillamount").val();
 var amount=$.isNumeric($("#amount").val());//$("#amount").val();
 
 if(amount>billamt)
 {
 $("#smbt").hide();
 }
 else
 {
 $("#smbt").show();
 }
 
 
});
		

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