<?php
error_reporting(0);
?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:10px;
        padding-right:10px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
input[type="date"],input[type="text"],select
{
    width:100%;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    
    <div id="fullbody"> 
<div id="navbar" class="bg-info"><?php include "navbar.php"?></div>
<div id="content">
<br>
<h3>Edit Second Transaction</h3>
<br>
<!-- entry for edit  -->
<?php 
$tkt = $_GET['edi'];
$table=$_GET['table'];
$crcedit=mysqli_query($connect,"select *,(select customerdetails.name from customerdetails where customerdetails.code = $table.customer && status!='deleted' )as cusname,(select productdetail.productname from productdetail where productdetail.productcode = $table.product  )as proname from $table where status !='deleted' && ticket = '$tkt' and status !='cancel'");
while($crc_dis = mysqli_fetch_array($crcedit))
{
?>
<form action="updatesecond_trans.php" method="post" id="form1">
            <!--  -->
    <!-- entry for edit  -->    
    <div class="row">
  <div class="col-sm-2"><label>Bill-Type</label></div>:
  <div class="col-sm-8"><select class="required " id="billType" name="billtype">
             <?php  
             if($table == 'second_transaction'){
              echo '<option value="gst">Quotation</option><option value="est">Quotation</option><option value="est">Purchase</option>';
             }else if($table == 'second_transaction_est'){
              echo '<option value="est">Quotation</option><option value="gst">Quotation</option><option value="est">Purchase</option>';
             }else if(($table == 'purchasedetails')){
              echo '<option value="est">Purchase</option><option value="gst">Quotation</option>
               <option value="est">Quotation</option>';
             }else{
              echo '<option>--Select Billing--</option><option value="est">Purchase</option><option value="gst">Quotation</option>
              <option value="est">Quotation</option>';
             }

             ?>
              </select></div>
              <input type="hidden" value="<?php echo $table == 'second_transaction'?'gst':'est' ?>" name="billtypeori">
</div><br>
    <div class="row">
              <div class="col-sm-2"><label>Vehicle/Tkt-no</label></div>:
              <div class="col-sm-3"><select class="form-control selectpro" id="ticketselect" name="ticketadd">
              <option value="<?php echo $crc_dis['ticket'] ?>"><?php echo $crc_dis['ticket'] ?></option>
            
              </select></div>
              <!-- salescode -->
              
        <?php
            $procountgst = mysqli_query($connect,"select count(salescode)as code,CURRENT_DATE as date from second_transaction where second_transaction.status !='deleted'");
        while($disproe = mysqli_fetch_array($procountgst))
        {
            $salescodee = $disproe['code']+10951;
            $salescodegst = 'SMC21/'.$salescodee;
           $date = $disproe['date'];
  $datefr = date_create($date);
  $datefrom = date_format($datefr,"d-m-Y");
		}
        
        ?>
        <input type="hidden" id="salescodegst" value="<?php  echo $salescodegst ?>">
        <!-- salescode -->
        
        <div class="col-sm-2"><label>Vehicle No</label></div>:
     <div class="col-sm-3"><select class="form-control selectpro" id="vehicleAdd" name="vehicleno" required>
              <option value="<?php echo $crc_dis['vehicleno'] ?>"><?php echo $crc_dis['vehicleno'] ?></option>
              <?php 
              $vehicle=$crc_dis['vehicleno'];
$veh=mysqli_query($connect,"select distinct vehicleno from cftdetails where status !='deleted'&& vehicleno!='$vehicle'");
while($vehshow = mysqli_fetch_array($veh))
{
?>
<option value="<?php echo $vehshow['vehicleno'] ?>"><?php  echo $vehshow['vehicleno'] ?></option>
        <?php }?>          
  
              </select></div>
            </div><br>
            <!--  -->
            <div class="row">
    <div class="col-sm-2"><label>Chakka Type</label></div>:
     <div class="col-sm-3"><select class="required" name="chakkaname" id="chakkaType" required>
     <option value="<?php echo $crc_dis['chakka'] ?>"><?php echo $crc_dis['chakka'] ?></option>
     </select></div>
     <div class="col-sm-2"><label> Load Type</label></div>:
     <input type="hidden" id="oriLoadType" value="<?php echo $crc_dis['processtype']?>">
              <div class="col-sm-3"><select class="required " id="loadType" name="loadtype">
              <?php   if($crc_dis['processtype']=="Empty"){
                echo '<option value="Empty">Out</option><option value="Load">In</option>';
              }if($crc_dis['processtype']=="Load"){
                echo '<option value="Load">In</option><option value="Empty">Out</option>';
              } ?>
              </select></div>
           
                          </div><br>
                          <div class="row">
                          <div class="col-sm-2"><label>Customer</label></div>:
              <div class="col-sm-3"><select class="form-control selectpro"  name="customeradd" id="customerAdd">
              <option value="<?php echo $crc_dis['customer'] ?>"><?php echo $crc_dis['cusname'] ?></option>
              <?php 
              $customer=$crc_dis['customer'];
$cus=mysqli_query($connect,"select * from customerdetails where status !='deleted' && code!='$customer'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>          
              </select>
              <input type="hidden" class="form-control"  autocomplete="off"name="customerori" id="customeraddori" value="<?php echo $crc_dis['customer'] ?>" >
                          </div>
                          <div class="col-sm-2"><label>Block Date</label></div>
	<div class="col-sm-3"><input type="text" class="required" name="blockdate" placeholder="Block Date" readonly id="blockDate"></div>
           
            </div><br>
    <!--  -->
    <div class="row">
     <div class="col-sm-2"><label>Delivery/Intake place</label></div>:
     <div class="col-sm-3"><input type="text" class="required deliveryOri"  autocomplete="off"name="delivery" value="<?php echo $crc_dis['delivery'] ?>" ><input type="hidden" class="form-control deliveryOri"  autocomplete="off"name="deliveryori" value="<?php echo $crc_dis['delivery'] ?>" ></div>
     <div class="col-sm-2"><label id="limitName">Credit Limit</label></div>:
     <div class="col-sm-3"><input type="text" class="required"  autocomplete="off"name="limitvalue" id="limitValue"><input type="hidden" class=""  autocomplete="off"name="limitvalue" id="advanceLimitValue"></div>
    </div><br>
    <div class="row">
              <div class="col-sm-2"><label>Material</label></div>:
              <div class="col-sm-3"><select class="form-control selectpro" name="productadd" id="productAdd">
                            <option value="<?php echo $crc_dis['product'] ?>"><?php echo $crc_dis['proname'] ?></option>
              <?php 
              $product = $crc_dis['product'];
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode !='$product'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['productcode'] ?>"><?php  echo $cusshow['productname'] ?></option>
        <?php }?>   
              </select></div>
              <input type="hidden" id="productadddori" value="<?php echo $crc_dis['product'] ?>"  name="productaddori">
              <input type="hidden"  value="<?php echo $crc_dis['salescode'] ?>"  name="salescode">
              <input type="hidden" id="productnameadd" value="<?php echo $crc_dis['proname'] ?>"name="productnameadd">
              <!-- <div class="col-sm-2"><label>Delivery-Site</label></div>:
     <div class="col-sm-3">
       <input type="text" class="form-control"  autocomplete="off"name="delivery" id="deliveryadd"  ></div> -->
               <div class="col-sm-2"><label>Price</label></div>:
     <div class="col-sm-3">
       <input type="text" class="required" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>  value="<?php echo $crc_dis['price'] ?>" autocomplete="off"name="priceadd" id="priceadd">
       <input type="hidden" value="<?php echo $crc_dis['price'] ?>" class="form-control"  autocomplete="off"name="priceaddori" id="priceaddori">
     </div> 
            </div><br>
    <!--  -->
    <!--  -->
  
    <div class="row">
     <div class="col-sm-2"><label>Empty Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="required"  autocomplete="off"name="emptyweightadd" value="<?php echo $crc_dis['emptyweight'] ?>" id="emptyWeightAdd" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>></div>
     <div class="col-sm-2"><label>Load Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="required"  autocomplete="off"name="loadweightadd" id="loadWeightAdd" value="<?php echo $crc_dis['loadweight'] ?>" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>></div>
     <div class="col-sm-1"><input type="button" class="btn btn-warning" id="getweightbutton" value="Get Weight" style="height:40px;"></div>
     <input type="hidden" id="unitConversion" name="unitvalue" >
     <input type="hidden" id="dateOri" value="<?php echo $crc_dis['curdate'] ?>">
    </div><br>
    <!--  -->
    <div class="row">
     <div class="col-sm-2"><label>Nett Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="required"  autocomplete="off"name="netweightadd" value="<?php echo $crc_dis['netweight'] ?>" id="netWeightAdd" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>readonly></div>
     <div class="col-sm-2"><label>Nett Qty</label></div>:
     <div class="col-sm-3"><input type="text" class="required"value="<?php echo $crc_dis['netqty'] ?>"  autocomplete="off"name="netqtyadd" id="netQtyAdd">
     <input type="hidden" id="netQtyOri" value="<?php echo $crc_dis['netqty'] ?>" name="netqtyori" ><input type="hidden"  value="<?php echo $crc_dis['tablename'] ?>" name="tablename" ></div>
     <!--  -->
  
    </div><br>   
    <div class="row">
    <div class="col-sm-2"><label>Total Amount</label></div>:
     <div class="col-sm-3"><input type="text" class="required"  autocomplete="off"name="totalamtadd" id="totalAmtAdd" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?> readonly value="<?php echo $crc_dis['totalamount'] ?>">
     <input type="hidden" class="form-control"  autocomplete="off"name="totalamtaddold" id="oldtotalamtadd" readonly></div>
     <div class="col-sm-2"><label>Vehicle Capacity</label></div>:
              <div class="col-sm-3"><input type="text" readonly class="required cft" autocomplete="off"  name="cft">
              <input type="hidden" readonly class="required cft" autocomplete="off" name="cftori">
             </div>      
</div>
      <br>
     
	  <div class="row">
	<div class="col-sm-2"><label>Driver Amount</label></div>:
     <div class="col-sm-3"><input type="number" class="required"  autocomplete="off" name="driver_amount" value="<?php echo $crc_dis['driver_amount'] ?>"></div>
     
	<div class="col-sm-2"><label>Mode Of Transaction:</label></div>
	<div class="col-sm-3"><select class="required" name="modetrans">
    <option value="<?php echo $crc_dis['modeof'] ?>"><?php echo $crc_dis['modeof'] ?></option>
    <option value="cash">Cash</option>
    <option value="credit">Credit</option>
    <option value="donation">Donation</option>
    <option value="purchase">Purchase</option>
  </select>
  </div>
	
	</div>
    
    <!--<div class="row">
    <div class="col-sm-2"><label>UPI/Mobile.No:</label></div>
    <div class="col-sm-3"><input type="text" class="required"  name="upi_number" id="upi_number" value="<?php echo $crc_dis['upi_number'] ?>">
    </div>
    </div>-->
    <br>
    
    <div class="row">
	<?php 
	$datetime = mysqli_query($connect,"select CURRENT_DATE()as dat,CURRENT_TIME()as tme ");
while($datime = mysqli_fetch_array($datetime))
{
	?>
	<div class="col-sm-2"><label>Date/time</label></div>
	<div class="col-sm-3"><input type="text" class="form-control" name="datesecd" placeholder="Date"  <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?> value="<?php echo $crc_dis['date'] ?>"><input type="text" class="form-control" name="timesecd" placeholder="Date"  <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?> value="<?php echo $crc_dis['time'] ?>"></div>
    
    </div>
  
  <div class="row">
      <div class="col-sm-2"><label>Remarks</label></div>:
     <div class="col-sm-8"><input type="text" class="required"  autocomplete="off"name="remarkadd" value="<?php echo $crc_dis['remark'] ?>">
     <input type="hidden" class="required"  autocomplete="off"name="financialyear" value="<?php echo $crc_dis['financialyear'] ?>"></div>
            </div><br>
            <?php }?>
            <div id="einvoiceSection" >
  <div class="row" style="display:none;">
      <div class="col-sm-12"><h5>Dispatch Details </h5></div>
      <br><br>
      <div class="col-sm-2"><label>District</label></div>:
      <div class="col-sm-3"><input type="text"  placeholder="District" autocomplete="off"name="dispatchdistrict" value="<?php echo $crc_dis['dispatch_district'] ?>" id="dispatchDistrict"><input type="hidden"   placeholder="Pincode" value="Tamilnadu" autocomplete="off" id="dispatchStateName" name="dispatchStateName"></div>
     
      
     
      <div class="col-sm-2"><label>Pincode</label></div>:
      <div class="col-sm-3"><input type="number"   placeholder="Pincode" autocomplete="off" id="dispatchPincode" name="dispatchPincode" value="<?php echo $crc_dis['dispatch_pincode'] ?>" >       </div>      
  </div><br>
      <!-- Dispatch Details -->
    <!-- Eway Details -->
  <div class="row" style="display:none;">
      <div class="col-sm-12"><h5>E-way Bill </h5></div>
      <br><br>
      <div class="col-sm-2"><label>Transport Id</label></div>:
      <div class="col-sm-3"><input type="text"  placeholder="Transport Id"  autocomplete="off" name="transportId" id="totalAmtAdd" value="<?php echo $crc_dis['eway_trans_id'] ?>" ></div>
      <div class="col-sm-2"><label>Transport Name</label></div>:
      <div class="col-sm-3"><input type="text"   placeholder="Transport Name" autocomplete="off" id="transportName" name="transportName" value="<?php echo $crc_dis['eway_trans_name'] ?>" ></div><br><br>
      <div class="col-sm-2"><label>Distance</label></div>:
      <div class="col-sm-3"><input type="number"  placeholder="Distance" autocomplete="off"name="distance" id="distance" value="<?php echo $crc_dis['eway_distance'] ?>" ></div>
      </div><br>
</div>
            <input type="button" class="btn btn-success"  style="float:left;margin-left:10px;height:40px;" value="Submit" id="validationButton">
            <input type="hidden" class="btn btn-success" data-toggle="modal" data-target="#addpro" style="float:left;margin-left:10px;height:40px;" value="Submit" id="submitButton">
    </div><br>
<!-- entry for edit -->
        </div>
        
        <!-- Modal footer -->
      
         
       
        
<div class="modal fade" id="addpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> Credit Have Been Updated Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning editsubmit" ><span class="spinner-border spinner-border-sm subspin2" data-dismiss="modal"></span>Ok</button>
        </div>
        
      </div>
    </div>
  </div>
  
<!-- modal for add -->
                  </form>
  <?php 
}
?>
<!-- modal for edit -->
</div>
  <!-- modal for add confirm -->
<input type="button" class="btn btn-success close"data-toggle="modal"  data-backdrop="static" style="display:none" id="priceshowbutton" data-target="#priceshow" >
<div class="modal" id="priceshow">
    <div class="modal-dialog modal-sm">
      <div class="modal-content bg-warning ">
      
        <!-- Modal Header -->
       
        
        <!-- Modal body -->
        <div class="modal-body ">
          <!-- nodal entry -->
          <lable>Product</lable>:<h3 class="productdisplay"></h3>
          <lable>unit Price</lable>:<h3 class="pricedisplay"></h3>
          <!-- modal entry -->
</div>
        
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Ok</button>
        </div>
        
      </div>
    </div>
  </div>
        <!-- modal to display price -->
              
        <!--overall entry div over  -->
        
        
    </div>
   <!--  -->
  </div>
</div>
</form>
  <!-- tab for rate -->
 
</div>
<!-- tab for entry area-->
<!-- modal to blockdate -->
<button type="button" class="btn btn-primary" id="alertAdvance" data-toggle="modal" data-target="#advanceLimit" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="advanceLimit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close"  data-dismiss="alert">&times;</button>
    <strong>Advance Limit Exceeds</strong>
  </div>
  </div>
  </div>
        

<!-- modal for blockdate -->
<input type="button" class="btn btn-success close"data-toggle="modal"  data-backdrop="static" style="display:none" id="blockButton" data-target="#block" >
<div class="modal" id="block">
    <div class="modal-dialog modal-sm">
      <div class="modal-content bg-warning ">
      
        <!-- Modal Header -->
       
        
        <!-- Modal body -->
        <div class="modal-body ">
         <h4>Reached Block Date</h4>
</div>
        
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary reloadPage"  data-dismiss="modal">Ok</button>
        </div>
        
      </div>
    </div>
  </div>
        
<!-- modal for delete -->
<!-- modal for credit -->

<input type="button" class="btn btn-success close"data-toggle="modal"  data-backdrop="static" style="display:none" id="creditButton" data-target="#creditLimitChk" >
<div class="modal" id="creditLimitChk">
    <div class="modal-dialog modal-sm">
      <div class="modal-content " style="background-color:rgba(237, 140, 123)">
      
        <!-- Modal Header -->
       
        
        <!-- Modal body -->
        <div class="modal-body ">
         <h4>Credit Limit Exceeds</h4>
</div>
        
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary reloadPage"  data-dismiss="modal">Ok</button>
        </div>
        
      </div>
    </div>
  </div>
        <!-- modal to credit -->


<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script>
  $(document).ready(function(){
    //$("#showcredit").hide();
    $(".subspin").hide();
    $(".subspin2").hide();
$(".addsubmit").click(function(){
$(".subspin").show();
});
$(".editsubmit").click(function(){
$(".subspin2").show();
//$(".subspin2").hide();
});
  });
</script>

<!-- <script src="js/editcredit.js"></script> -->
<!-- <script src="restriction/credit.js"></script> -->
<script src="js/editsecond.js"></script>
</body>
</html> 