<?php 

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

require_once("config/configDB.php"); 

$id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM supplier_payment 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['supplierID'];
//$tamount   = $row['tamount'];
$pending   = $row['pending'];
$paymenttype   = $row['paymenttype'];
$paymentreference   = $row['paymentreference'];
$amount     = $row['amount'];

$purchase_bill_no=$row['purchaseID'];


$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 ");
$row_supplier = '';


?>
<!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="paypurchaseUpdate.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">supplier name</label>
      <div class="col-sm-5">
      <select class="form-control input-lg supplierName-select" name="supplierName" readonly>
        
        <?php
        while($row = mysqli_fetch_array($sql_supplier)){
        ?>
        <?php if( $loaner == $row['supplier_id'] ) { ?>

        <option value="<?php echo $row['supplier_id'] ?>" <?php if( $loaner == $row['supplier_id'] ): ?> selected="selected"<?php endif; ?> > <?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">Bill.No</label>
      <div class="col-sm-5">
        <input type="text" class="form-control" name="purchase_bill_no" value="<?php echo $purchase_bill_no; ?>" readonly >
      </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">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>