<?php 

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

require_once("config/configDB.php");

$id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM collection_customer WHERE id='$id' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

$cashno   = $row['cashno'];
$collectiondate   = new DateTime($row['collectiondate']);$collectiondate 	=$collectiondate->format('d-m-Y');//$sDate 	= new DateTime($sDate);
$loaner   = $row['customerID'];
//$tamount   = $row['tamount'];
$pending   = $row['pending'];
$paymenttype   = $row['paymenttype'];
$paymentreference   = $row['paymentreference'];
$amount     = $row['amount'];
$saleID=$row['saleID'];


$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 cm.isdelete='1' GROUP BY sh.customer_id ");
$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="collectionUpdate.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 $cashno; ?>" readonly>
      <input type="hidden" value='<?php echo $id; ?>' name="edit_id">
      </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" value="<?php echo $collectiondate; ?>"  autocomplete="off">
      </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" name="customerName" readonly>
        
        <?php
        while($row = mysqli_fetch_array($sql_customer)){
        ?>
        <?php if( $loaner == $row['customer_id'] ) { ?>

        <option value="<?php echo $row['customer_id'] ?>" <?php if( $loaner == $row['customer_id'] ): ?> selected="selected"<?php endif; ?> > <?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" value="<?php //echo $tamount; ?>" >
      </div>
    </div> -->
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Total Pending amount</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="pending" value="<?php echo $pending; ?>" readonly>
      </div>
      
    </div>
    <div class="form-group">
      <label class="control-label col-sm-3" for="email">Bill.No</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="sale_bill_no" value="<?php echo $saleID; ?>" 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" value="<?php echo $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="sel1" name="paymenttype">
        <option value="cash" <?php if( $paymenttype == "cash" ): ?> selected="selected"<?php endif; ?> >CASH</option>
        <option value="cheque" <?php if( $paymenttype == "cheque" ): ?> selected="selected"<?php endif; ?> >CHEQUE</option>
        <option value="online" <?php if( $paymenttype == "online" ): ?> selected="selected"<?php endif; ?> >ONLINE</option>
         <option value="UPI" <?php if( $paymenttype == "UPI" ): ?> selected="selected"<?php endif; ?> >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" value="<?php echo $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" 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();
    }    
        

  });
  
  $('.collect-paymenttype').on('change',function(){

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

});
</script>

</body>
</html>