<?php 

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

$edit_id  = $_GET['id'];
$sql      = mysqli_query($conn,"SELECT `invoice`, `invoicedate`, `vehicleno`, `givenby`, `receivedby`, `remarks` FROM internalpro_explosive_hdr WHERE id='$edit_id' "); 
$row      = mysqli_fetch_array($sql,MYSQLI_ASSOC);


$invoice          = $row['invoice'];
$tdate_temp       = new DateTime(stripslashes($row['invoicedate']));
$invoicedate 		  = $tdate_temp->format('d-m-Y');
$vehicleno        = $row['vehicleno'];
$givenby          = $row['givenby'];
$receivedby       = $row['receivedby'];
$remarks          = $row['remarks'];

$sqlVehicleQuery = mysqli_query($conn,"SELECT id, vehicleno  FROM vehicle_master WHERE isdelete=1 ");

$Details_Result  = mysqli_query($conn,"SELECT  ppsd.explosiveID, spm.explosivename ,ppsd.explosiveqty  FROM internalpro_explosive_dtl as ppsd 
LEFT JOIN explosive_master as spm ON spm.id=ppsd.explosiveID
WHERE  ppsd.hdr_id='$edit_id'");


?>
<!DOCTYPE html>
<html>
<head>
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>
</head>
<body>
  <?php require 'menu.php' ?>
  <div class="container-fluid">
    <h3 class="text-center"><strong>Internal Explosive Service Details</strong></h3>
    <form class="form-horizontal" action="inExplosiveProUpdate.php" method="post" id="inexplosiveProFrom">
      <div class="col-sm-12 row">
        <div class=" col-sm-1"></div>
        <div class=" col-sm-3 form-group">
          <label class="control-label">Invoice No</label>
          <input class="form-control input-lg" type="text" name="invoice" value="<?php echo $invoice; ?>" readonly >
          <input type="hidden" value=<?php echo $edit_id; ?> name="edit_id">
        </div>
        <div class="col-sm-3"></div>
        <div class="col-sm-3 form-group">
          <label class="control-label">Date</label>
          <input class="form-control input-lg datepicker-invoicedate"  type="text" name="invoicedate" value="<?php echo $invoicedate; ?>" autocomplete="off" readonly>
        </div>
        
      </div>
      <div class=" col-sm-12 row"><br></div>
      <div class=" col-sm-12 row">
        <div class=" col-sm-1"></div>
        <div class=" col-sm-3 form-group">
          <label class="control-label">Vehicle No</label>
          <select class="form-control input-lg selectpicker select-vehicle-details" data-live-search="true" name="vehicleno" id="vehicleno">
            <option disabled selected>Select your Option</option>
            <?php   while($prow = mysqli_fetch_array($sqlVehicleQuery)) { ?>
                <option value="<?php echo $prow['id'] ?>" <?php if( $prow['id']  == $vehicleno ): ?> selected="selected"<?php endif; ?> > <?php echo $prow['vehicleno']; ?> </option>
            <?php  }  ?>
          </select> 
        </div>
        
        <div class="col-sm-3 form-group">
          <label class="control-label">Given By</label>
          <input class="form-control input-lg" type="text" name="givenby" value="<?php echo $givenby; ?>" placeholder="Given By">
        </div>
        <div class="col-sm-3 form-group">
          <label class="control-label">Received By</label>
          <input class=" form-control input-lg" type="text" name="receivedby" value="<?php echo $receivedby; ?>" placeholder="Received By">
        </div>
      </div>
      <div class=" col-sm-12 row"><br></div>
      <div class="col-sm-12 row">
        <div class="col-sm-1"></div>
        <div class="col-sm-9 form-group">
          <label class="control-label">Remarks</label>
          <textarea name="remarks" class="form-control" rows="2" cols="50" placeholder="Describe yourself here." ><?php echo $remarks; ?></textarea>
        </div>                                                                                 
  
      </div>

      <div class=" col-sm-12 row"><br></div>
      <div class="container-fluid">
        <div class="col-sm-4" style="padding-top: 10px;margin-top: 10px;">          
        <table class="table  table-striped table-bordered dt-responsive" style="overflow-x:auto;" id="saleAdd">
            <tr>
              <th>Explosive Name</th>
              <td><select class="form-control explosive-select-box  input-lg selectpicker" data-live-search="true" name="explosivedetails" id="explosivedetails">
              <option disabled selected>Select your explosive Option</option>
              <?php echo  $sqlexplosiveName; ?>
              </select>
              </td>
            </tr>  
            <tr>
            <th>Available Qty</th>
              <td><input class="form-control aqty-input" type="text" id="aqty" readonly></td>
            </tr>
            <tr>
              <th>Invoice Qty</th>
              <td><input class="form-control eqty-input" type="text" id="eqty" autocomplete="off"></td>
            </tr>
            <tr>
              <th>Action</th>
              <td><input type="button" class="btn btn-default add-inexplosivePro" value="Add"></td>
            </tr>
          
        </table>
        </div>

        <div class="col-sm-8 " style="padding-top: 10px;margin-top: 10px;">          
          <table class="table table-responsive table-striped table-bordered dt-responsive nowrap" id="inexplosiveProDetailsAdd" cellspacing="0">
            <thead>
              <tr>
                <th>Explosive</th>
                <th>Qty</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>

            <?php

              $trlength = 0;
              while($drow = mysqli_fetch_array($Details_Result))
              {
                $trlength++;
                $DetailsTable = '';
                $DetailsTable ='<tr id="'.$trlength.'">';
                $explosiveName=$drow['explosivename'];


                $DetailsTable .='<td class="product_name">'.$explosiveName.'<input class="form-control" name="explosiveID[]"  value="'.$drow['explosiveID'].'" type="hidden"></td>';
                $DetailsTable .='<td>'.$drow['explosiveqty'].'<input class="form-control" name="explosiveqty[]" type="hidden" value="'.$drow['explosiveqty'].'" ></td>';
                $DetailsTable .='<td><input type="button" class="btn btn-default removeDetails" id="removeDetails" value="-"></td>';
                $DetailsTable .='</tr>';
                echo $DetailsTable;

              }

            ?>              
            </tbody>
          
          </table>
        </div>

      </div>     
      

<div class="container-fluid">
                                                                                       
  
</div>

    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default btn-lg">Save</button>
      </div>
    </div>
    </form>   
  </div>
  <?php require 'footer.php' ?>
 
  <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
  <script type="text/javascript" src="inExplosiveProScript.js"></script>
<script>
	$(document).ready(function(){
	  var date_input=$('input[name="invoicedate"]'); //our date input has the name "date"
		var container=$('form >  .datepicker-invoicedate').length>0 ? $('form > .datepicker-invoicedate').parent() : "body";
		date_input.datepicker({
			  format: 'dd-mm-yyyy',
        container: container,
			  todayHighlight: true,
			  autoclose: true,
    });
    

    $('#inexplosiveProFrom').bootstrapValidator({
        // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
          invoice: {
                message: 'The invoice number is not valid',
                validators: {
                    notEmpty: {
                        message: 'The invoice number is required and cannot be empty'
                    }
                }
            },
          invoicedate: {
                message: 'The invoice date is not valid',
                validators: {
                    notEmpty: {
                        message: 'The invoice date is required and cannot be empty'
                    }
                }
          },  
          givenby: {
                message: 'The given by is not valid',
                validators: {
                    notEmpty: {
                        message: 'The given by is required and cannot be empty'
                    }
                }
            },
            receivedby: {
                message: 'The received by is not valid',
                validators: {
                    notEmpty: {
                        message: 'The received by is required and cannot be empty'
                    }
                }
            },
            remarks: {
              message: 'The remarks is not valid',
                validators: {
                    notEmpty: {
                        message: 'The remarks is required and cannot be empty'
                    }
                }
            }
        }
    });

   

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