<?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>
<script src="ajax/ticket.js"></script>

<script src="restriction/ticket_restriction.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;
}
.row input
{
    height:30px;
}
#menu1 select
{
    height:35px;
    /* padding-bottom:8px; */
}
#ticketFetch
{
width:250px;
float:right;
margin-bottom:20px;
}
select,input[type="text"],input[type="date"]{
  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";include "config.php"?></div>
<div id="content">
<br>
<h3>First Transaction</h3>
<br>
<!-- table -->
<div>
  <!-- tab for rate -->
  <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='ticket'");
while($per=mysqli_fetch_array($usper))
{
          ?>
           <span id="print" style="display:none"><?php echo $per['dataprint'] ?></span>
<span id="edit" style="display:none"><?php echo $per['dataedit'] ?></span>
  <ul class="nav nav-pills" role="tablist">
    <li class="nav-item">
      <a class="nav-link active" data-toggle="pill" href="#home">List</a>
    </li>
    <?php if($per['dataadd'] =='1'){ ?><li class="nav-item">
      <a class="nav-link" data-toggle="pill" href="#menu1">Entry</a>
    </li><?php }?>
    
  </ul>

  <!-- Tab panes -->
  <div class="tab-content" style="border:1px solid lightgrey">
    <!--  -->
    <div id="home" class="container tab-pane active"><br>
    <!-- entry list div -->
    <input type="text" id="ticketFetch" class="form-control" placeholder="Search">
    <table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protabe">
    <thead >
<tr>
  <th>S.no</th>
    <th>Ticket</th>
    <th>Vehicle No</th>
    <th>Customer</th>
    <th>Load Type</th>
    <th>Second</th>
    <?php if($per['dataprint'] =='1'){ ?> <th>Print</th><?php }?>
    <?php if($per['dataedit'] =='1'){ ?> <th>Edit</th><?php }?>
</tr>

    </thead>
    <tbody id="tableTbody">
        <tr>
        <?php 
$tktshow=mysqli_query($connect,"select ticket,vehicleno,loadtype,process,(select customerdetails.name from customerdetails where customerdetails.code = ticket.customer && status !='deleted' )as cusname from ticket where status!='deleted' order by concat(date,time) desc limit 200 ");
while($tkktshow = mysqli_fetch_array($tktshow))
{
  $sno+=1;
?>
<td><?php echo $sno    ?></td>
        <td><?php echo $tkktshow['ticket'];    ?></td>
    <td><?php echo $tkktshow['vehicleno'];    ?></td>
    <td><?php echo $tkktshow['cusname'];    ?></td>
    <td><?php echo $tkktshow['loadtype'];    ?></td>
    <td>
    <div <?php if($tkktshow['process'] ==''){echo 'style="display:block"';} else {echo 'style="display:none"';}  ?>>
      <div class=" text-primary spinner-grow spinner-grow-sm"></div>
   <div class="spinner-grow text-success  spinner-grow-sm"></div>
  <div class="spinner-grow text-info  spinner-grow-sm"></div>
  <div class="spinner-grow text-warning  spinner-grow-sm"></div>     </div>
      <!-- spinner -->
      <!-- tick -->
      <div <?php if($tkktshow['process'] != '' ){echo 'style="display:block;color:green"';} else {echo 'style="display:none"';}  ?>><i class="fas fa-check"></i></div>
      <!-- tick -->
      <div></div>
    </td>
    <?php if($per['dataprint'] =='1'){ ?> <td><a href="billslipticket.php?print=<?php echo $tkktshow['ticket'] ?> " target="_blank"><i class="fas fa-print"></i></a></td><?php }?>
    <?php if($per['dataedit'] =='1'){ ?>     <td><a href="editticket.php?ticket=<?php echo $tkktshow['ticket'];?>"><i class="fas fa-edit edit"></i></a></td><?php }?>
            <!-- <td><a data-toggle="modal" data-target="#prd-1"><i  class="fas fa-trash-alt dele"></a></i></td> -->
        </tr>
        <?php
}}
        ?>
    </tbody>



</table>
    <!-- entry div table -->
    </div>
    <script>
    function printsl(e)
{
  //e.preventDefault();
  document.getElementById("finalSubmit").disabled=true;
  //cosole.log(document.getElementById("finalSubmit"));
	var varBillNumber = document.getElementById("ticketno").value;
  var customer = document.getElementById("customerAdd").value;
  var product = document.getElementById("productAdd").value;
  var trip = document.getElementById("tripNo").value;
  var quantity = document.getElementById("cftValue").value;
  var vehicleno = document.getElementById("vehicleNo").value;
//window.open("");
		window.open("billslipticketon.php?tkt="+varBillNumber+"&&customer="+customer+"&&product="+product+"&&trip="+trip+"&&quantity="+quantity+"&&vehicle="+vehicleno+"","OriginalWindowa40",'width=722,height=950,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,left=25,top=25');
return false;
}
</script>
    <!-- entrydiv -->
    <div id="menu1" class="container tab-pane fade"><br>
    <!-- enter the entry list -->
    <form action="insertticket.php"  method="post" > 
    <div class="row">
     <div class="col-sm-2"><label>New Ticket No</label></div>:
     <?php 
              error_reporting(0);
              include "financial_year_calculation.php";
              $accountyear = $financialYearStart."-".$financialYearEnd;
              $code = mysqli_query($connect,"select count(id) as count from ticket where status !='deleted'&& financialyear ='$accountyear'");
              while($row=mysqli_fetch_array($code))
              {
                $codsin = mysqli_query($connect,"select count(id) as count from single_transaction where status !='deleted'&& financialyear ='$accountyear'");
              while($roww=mysqli_fetch_array($codsin))
              {
                $code = $row['count'];
                $codsin = $roww['count'];
                  $codee = $code + $codsin;
                  $year_code=substr($financialYearEnd,2);
              $codeco = $year_code."-". ($codee+1);
              }}
              ?>
     <div class="col-sm-3"><input type="text" class="required" autocomplete="off" readonly value="T<?php echo $codeco ?>" name="ticket" id="ticketno"></div>
   
              <div class="col-sm-2"><label> Load Type</label></div>:
              <div class="col-sm-3"><select class="required" id="loadType" name="weight" required>
              <option value="">--Select weight--</option>
              <option>Load</option>
              <option>Empty</option>
              <!--<option>Return</option>-->
              </select></div>
    </div><br>
    <!--  -->
    <div class="row">
    <div class="col-sm-2"><label>Customer</label></div>:
              <div class="col-sm-3"><select class="required selectpro" id="customerAdd" name="customer" required>
              <option value="">--Select Customer--</option>
              <?php 
$cus=mysqli_query($connect,"select * from customerdetails where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>          
  
              </select></div>
              <div class="col-sm-2"><label>Vehicle No</label></div>:
     <div class="col-sm-3"><select class="required selectpro" id="vehicleNo"  name="vehicleno" required>
              <option value="">--Select Vehicle--</option>
              <?php 
$veh=mysqli_query($connect,"select distinct vehicleno from cftdetails where status !='deleted'");
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 selectpro" id="chakkaType"  name="chakka" >
              <option value="">--Select Vehicle No to fetch Chakka--</option>
             
              </select></div>
              <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='readonly'");
while($per=mysqli_fetch_array($usper))
{
          ?>
              <div class="col-sm-2"><label>Vehicle Capacity</label></div>:
              <div class="col-sm-3"><input type="text" class="required" autocomplete="off" name="vehiclecapacity" id="cftValue" <?php echo $per['datashow']==1?"":"readonly" ?> required><input type="hidden" class="required" autocomplete="off" name="oricapacity" id="cftValueOri" required></div>
              
                
            </div><br>
            <!--  -->
   
    <div class="row">
          <div class="col-sm-2"><label>Product</label></div>: 
              <div class="col-sm-3"><select class="required selectpro" id="productAdd" name="product" readonly>
                <option value="">--Select Product--</option>
              <?php 
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['productcode'] ?>"><?php  echo $cusshow['productname'] ?></option>
        <?php }?>          


              </select></div>
              <div class="col-sm-2"><label>Weight</label></div>:
     <div class="col-sm-3"><input type="text"  class="required" autocomplete="off"  id="getweight" name="emptyweight" <?php echo $per['datashow']==1?"":"readonly" ?> ></div>
     <div class="col-sm-1"><input type="button" class="btn btn-warning" id="getweightbutton" value="Get Weight" style="height:40px;"></div>
    </div><br>
    <!--  -->
   
    <div class="row">
            <div class="col-sm-2"><label id="limitName">Credit Limit</label></div>:
	<div class="col-sm-3"><input type="text" class="required" name="limitvalue" placeholder="Credit Limit"  id="limitValue"readonly><input type="hidden" class="" name="" placeholder="Credit Limit"  id="advanceLimitValue"readonly></div>
            
              <div class="col-sm-2"><label>Trip No</label></div>:
     <div class="col-sm-3"><input type="text" class="required" id="tripNo" autocomplete="off"  name="tripno" ></div>
            </div><br>
            <!--  -->
            <div class="row">
            <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"  id="blockDate"readonly></div>
            
              <div class="col-sm-2"><label>Delivery/Intake place</label></div>:
     <div class="col-sm-3"><input type="text" class="required" autocomplete="off" id="deliveryAdd" name="delivery" ></div>
            </div><br>
            
            <!--  -->
            <!--<div class="row">
            <div class="col-sm-2"><label>Mode Of Transaction:</label></div>:
     <div class="col-sm-3"><select class="required" id="modeTrans" name="modetrans">
    <option value="">--Select Mode--</option>
    <option value="Cash">Cash</option>
    <option value="credit">Credit</option>
    <option value="BANK-GPAY">BANK-GPAY</option>
    <option value="Cash-UPI">Cash-UPI</option>
    <option value="donation">Donation</option>
    <option value="purchase">Purchase</option>
  </select></div>
  
  <div class="col-sm-2"><label>UPI id/Mobile&nbsp;No</label></div>:
     <div class="col-sm-3"><input type="text" class="required" autocomplete="off"  name="upi_number" ></div>
            </div>-->
            
            <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</label></div>:
	<div class="col-sm-3"><input type="date" id="dateTkt" class="" name="datetkt" placeholder="Date" value="" <?php echo $per['datashow']==1?"":"readonly" ?>></div>
  <div class="col-sm-2"><label>Time</label></div>
  <div class="col-sm-3"><input type="text" class="" name="timetkt" placeholder="Time" value="" <?php echo $per['datashow']==1?"":"readonly" ?>></div>

	<?php }}?>
	</div><br>
    
    <!--  -->
    <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="remark"></div>
    </div><br>
	
    <!--  -->
	
    <?php 
$cus=mysqli_query($connect,"select * from ticket where status !='deleted' and process !='completed'");
while($cusshow = mysqli_fetch_array($cus))
{
$vehicle = $cusshow['vehicleno'];
?>
<input type="hidden" value="<?php echo $vehicle ?>" class="vehicleallcomp">
<?php
}
?>

    <!--  -->
    <!-- <div class="row">
     <div class="col-sm-2"><label>Date & Time</label></div>:
     <div class="col-sm-3">--><!--</div>
     
    </div><br> -->
    <!--  -->
    <!-- enter the entry list -->
            <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">
<br><br>
            <!-- entry div over  -->
        </div>
                <!-- modal for add confirm -->
<div class="modal" 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> Ticket Have Been Generated Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit"   id="finalSubmit"class="btn btn-warning addsubmit" ><span class="spinner-border spinner-border-sm subspin" ></span>Ok</button>
        </div>
</form>
      </div>
    </div>
  </div>
  <script>
  $(document).ready(function(){
    //$("#showcredit").hide();
    $(".subspin").hide();
    $(".subspin2").hide();
$(".addsubmit").click(function(){
$(".subspin").show();
});
$(".editsubmit").click(function(){
$(".subspin2").show();
//$(".subspin2").hide();
});
  });
</script>
<!-- modal for add confirm -->
        <!--overall entry div over  -->
        <!-- alert5 for digit -->
<!-- <button type="button" class="btn btn-primary vehiclealertno" data-toggle="modal" data-target="#myModal" style="display:none">
      </button> -->

  <!-- The Modal -->
  <!-- <div class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-warning alert-dismissible fade show">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Vehicle Number Should contain 8 or 10 digit</strong>
  </div>
  </div>
        </div> -->
<!-- alert -->

        
    </div>
   <!--  -->
  </div>
</div>

  <!-- tab for rate -->
</div>
<!-- tab for entry area-->

     
      

<!-- table -->


<!-- main-content-div -->
</div>
<!-- main-content-div -->
</div>
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
    
</script>
<script>
  $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
  $(this).closest(".select2-container").siblings('select:enabled').select2('open');
});
</script>
<!-- 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>
        
<!-- alert -->
<!-- alert5 for vehicle in -->
<button type="button" class="btn btn-primary" id="vehicleInsideAlert" data-toggle="modal" data-target="#vehiclein" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="vehiclein">
    <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>Vehicle Have Been Already Entered ! Please Check Vehicle No</strong>
  </div>
  </div>
        </div>
<!-- alert -->
<!-- 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 -->



<!-- alert5 -->
<!-- <button type="button" class="btn btn-primary alertalpha" id="blockButton" data-toggle="modal" data-target="#textmodal" style="display:none">
      </button> -->

  <!-- The Modal -->
  <!-- <div class="modal fade" id="textmodal">
    <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>Special Characters Are Not Allowed</strong>
  </div>
  </div>
        </div>
     -->

 <!-- alert -->



<script src="js/ticket.js" type="text/javascript"></script>
<script src="restriction/ticket.js" type="text/javascript"></script>
</body>