<?php 

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

$sql_InvoiceQuery   = mysqli_query($conn,"SELECT count(*) as code FROM gold_rate where status=''");
$rowInvoiceCount    = mysqli_fetch_array($sql_InvoiceQuery,MYSQLI_ASSOC);
$code_count      = $rowInvoiceCount['code']+1;

?>

<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>

</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<h2 class="text-center">Today Rate</h2><br>
    <form class="form-horizontal" action="rateInsert.php" method="post" id="employeeMasterForm" onSubmit="return checkForm(this);">
    
    <div class="form-group">
      <label class="control-label col-sm-2" for="email"> Ref Code *</label>
        <div class="col-sm-4">
          <input type="text" class="form-control input-lg"  name="refcode" autocomplete="off" value="<?php echo "RT-".$code_count; ?>" required readonly>
        </div> 
        <label class="control-label col-sm-2" for="email">Date</label>
      <div class="col-sm-4">
        <input type="date" class="form-control input-lg"  name="rate_date" autocomplete="off" required > 
      </div>
    </div>
    
    
    
    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Gold Rate/Gram *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="gold_rate" autocomplete="off" required > 
      </div>
       <label class="control-label col-sm-2" for="email">Silver Rate/Gram *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="silver_rate" autocomplete="off" required  >
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Old Gold Rate/Gram *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="old_gold_rate" autocomplete="off" required > 
      </div>
       <label class="control-label col-sm-2" for="email">Old Silver Rate/Gram *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="old_silver_rate" autocomplete="off" required  >
      </div>
    </div>
    
    

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

<div class="datatable-header ">
        <h3 class="text-center"><strong>Current Rate</strong></h3>
        <table id="productMasterDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%" >
            <thead>
                <tr>
			
                    <th style="text-align:center">Date</th>
                <th style="text-align:center">Gold Rate/G</th>
                <th style="text-align:center">Silver Rate/G</th>
                <th style="text-align:center">old Gold Rate/G</th>
                <th style="text-align:center">old Silver Rate/G</th>
               
               
                </tr>
            </thead>
            <tbody>
            <?php
			$sql_rt=mysqli_query($conn,"select * from gold_rate where status=''");
			while($row_rt=mysqli_fetch_array($sql_rt))
			{
			
			$date=date_create($row_rt['rate_date'])
			?>
            <tr>
            <td align="center"><?php echo  date_format($date,"d-m-Y");;?></td>
            <td align="center"><?php echo $row_rt['gold_rate'];?></td>
             <td align="center"><?php echo $row_rt['silver_rate'];?></td>
             <td align="center"><?php echo $row_rt['old_gold_rate'];?></td>
             <td align="center"><?php echo $row_rt['old_silver_rate'];?></td>
             </tr>
             <?php
			 }
			 ?>
            </tbody>
           
        </table>
    </div>


    <?php require 'footer.php' ?>
    <script>

  var checkForm = function(form) {

    //
    // validate form fields
    //

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

</script>
    
</body>
</html>