<?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/singleentry.js"></script>
<script src="ajax/singleentryedit.js"></script>
<script src="restriction/single_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;
}
#menu1 input
{
    height:30px;
}
.row input
{
    height:30px;
}
#menu1 select
{
    height:35px;
    /* padding-bottom:8px; */
}
    @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 ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Single-Entry Transaction</h3>
<br>

<!-- table -->
<div>
  <!-- tab for rate -->
  <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='singleentry'");
while($per=mysqli_fetch_array($usper))
{
          ?>
  <ul class="nav nav-pills" role="tablist">
     <li class="nav-item">
      <a class="nav-link active" data-toggle="pill" href="#home"><span style="color:#000000;">List</span></a>
    </li>
    <?php if($per['dataadd'] =='1'){ ?><li class="nav-item">
      <a class="nav-link" data-toggle="pill" href="#menu1"><span style="color:#000000;">Entry</span></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 -->
    <table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protable">
    <thead >
<tr>
  <th>sno</th>
    <th>Ticket</th>
    
    <th>Customer</th>
    <th>Material</th>
    <th>Weight</th>
    <th>NetQty</th>
    <?php if($per['dataprint'] =='1'){ ?> <th>Print</th><?php }?>
    <?php if($per['dataedit'] =='1'){ ?> <th>Edit</th><?php }?>
</tr>

    </thead>
    <tbody>
    <?php 
$cus=mysqli_query($connect,"select *,(select customerdetails.name from customerdetails where customerdetails.code = single_transaction.customer && status!='deleted' )as cusname,(select productdetail.productname from productdetail where productdetail.productcode = single_transaction.product )as proname from single_transaction where status !='deleted' order by concat(entrydate,entrytime) desc");
while($cusshow = mysqli_fetch_array($cus))
{
  $sno +=1;
?>

        
        <tr>
        <td><?php echo $sno?></td>
        <td><?php echo $cusshow['ticket'] ?></td>
    <td><?php echo $cusshow['cusname'] ?></td>
    <td><?php echo $cusshow['proname'] ?></td>
    <td><?php echo $cusshow['netweight'] ?></td>
    <td><?php echo number_format($cusshow['quantity'],2,'.','') ?></td>
    <?php if($per['dataprint'] =='1'){ ?><td><a href="billslipsingle.php?print=<?php echo $cusshow['ticket'] ?> " target="_blank"><i class="fas fa-print"></i></a></td><?php }?>
    <?php if($per['dataedit'] =='1'){ ?>    <td><a href="editsingleentry.php?ticket=<?php echo $cusshow['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>
    <!-- entrydiv -->
    <script>
    function printstl()
{
	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("netqtyadd").value;
  var empty = document.getElementById("emptyweight").value;
  var load = document.getElementById("loadweightadd").value;
  var netweight = document.getElementById("netweightadd").value;
  var vehicle = document.getElementById("vehicleno").value;
  document.getElementById("singleSubmit").disabled = true;
		window.open("billslipsingleon.php?tkt="+varBillNumber+"&&customer="+customer+"&&product="+product+"&&trip="+trip+"&&quantity="+quantity+"&&emptyweight="+empty+"&&loadweight="+load+"&&netweight="+netweight+"&&vehicle="+vehicle+" ","OriginalWindowa40",'width=722,height=950,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,left=25,top=25');
}
</script>
    <div id="menu1" class="container tab-pane fade"><br>
    <!-- enter the entry list -->
    <form action="insertsingleentry.php" onSubmit="printstl()" method="post">
    <div class="row">
              <div class="col-sm-2"><label>Ticket-no</label></div>:
              <?php 
              error_reporting(0);
              include "financial_year_calculation.php";
              $accountyear = $financialYearStart."-".$financialYearEnd;
              $tktcode = 0;
              $singleCount = 0;

              $ticketResult = mysqli_query($connect, "select count(id) as count from ticket where status !='deleted' && financialyear ='$accountyear'");
              if ($ticketResult) {
                $ticketRow = mysqli_fetch_assoc($ticketResult);
                $tktcode = $ticketRow['count'];
              }

              $singleResult = mysqli_query($connect, "select count(id) as single_count from single_transaction where status !='deleted' && financialyear ='$accountyear'");
              if ($singleResult) {
                $singleRow = mysqli_fetch_assoc($singleResult);
                $singleCount = $singleRow['single_count'];
              }

              $codee = $tktcode + $singleCount;
              $year_code = substr($financialYearEnd,2);
              $codeco = $year_code."-". ($codee+1);
              
              ?>
     <div class="col-sm-3"><input type="text" class="form-control" id="ticketno" autocomplete="off" readonly value="T<?php echo $codeco ?>" name="ticket"></div>
<div class="col-sm-2"><label>Customer</label></div>:
              <div class="col-sm-3"><select class="form-control selectpro" id="customeradd" name="customer">
              <option value="0">--Select Customer--</option>
              <?php 
$cus=mysqli_query($connect,"select * from customerdetails where single_entry = '1' && status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>          
              </select></div>
            </div><br>
            <!--  -->
    
   
            <!--  -->
            <div class="row">
     <div class="col-sm-2"><label> vehicle No</label></div>:
     <div class="col-sm-3"><select class="form-control selectpro" id="vehicleno" name="vehicle">
     <option value="0">--Select Vehicle--</option>
              <?php 
$cus=mysqli_query($connect,"select * from vehiclemaster where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['vehicleno'] ?>"><?php  echo $cusshow['vehicleno'] ?></option>
        <?php }?>          
              
              </select></div>
     <!-- <div class="col-sm-2"><label> Trip No</label></div>: -->
     <div class="col-sm-2"><label>Trip</label></div>:
     <div class="col-sm-3"><input type="text" id="tripno" class="form-control" name="trip"></div>
    </div><br>
    <!--  -->
    <div class="row">
     
     <div class="col-sm-2"><label>Material In/Out</label></div>:
     
              <div class="col-sm-3"> <select class="form-control" name="matentrytype"><option value="">--Material Type--</option><option value="">Material In</option><option value="">Material Out</option></select>
              <!-- <input class="form-control" name="matentrytype" readonly value="Material In"> -->
            </div>
            <div class="col-sm-2"><label>Material</label></div>:
              <div class="col-sm-3"><select class="form-control selectpro" id="productadd" name="product">
              <option value="0">--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>
              <input type="hidden" id="unitconversion" name="unitvalue" >
            </div>
    </div>
    <br>
    <!--  -->
    
<!--  -->
    <!-- <div class="row"> -->
            
              <!-- <div class="col-sm-2"><label>Sales type</label></div>:
     <div class="col-sm-3"><select class="form-control" name="salestype" id="salestypeadd">
         <option value="0">--Select Type--</option>
         <option>Site</option>
         <option>Bunker</option>
          <option>Credit</option> 
         <option>Contract</option>
     </select></div> -->
<!-- </div> -->
              <!-- <br> -->
            <!--  -->
            <!-- <div class="row">
     <div class="col-sm-3"><label>Entry Date & Time</label></div>:
     <div class="col-sm-4"><input type="text" class="form-control" name="entrydate"></div>
    </div><br> -->
    <!--  -->
    <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='readonly'");
while($per=mysqli_fetch_array($usper))
{
          ?>
    <div class="row">
     <div class="col-sm-2"><label>Empty Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" id="emptyweight" name="emptyweight" <?php echo $per['datashow']==1?"":"readonly" ?>></div>
     <div class="col-sm-2"><label>Load Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" id="loadweightadd" name="loadweight" <?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>Nett Weight</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" id="netweightadd" name="netweight" <?php echo $per['datashow']==1?"":"readonly" ?>></div>
     <div class="col-sm-2"><label>Quantity</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" id="netqtyadd" name="quantity"><input type="hidden" class="form-control" id="netqtyori" name="quantityori"></div>
    </div><br>
    <!--  -->
    <?php } ?>
	 <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="text" class="form-control" name="datesinen" placeholder="Date" value="<?php echo $datime['dat'] ?>" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>></div>
	<div class="col-sm-2"><label>time</label></div>
	<div class="col-sm-3"><input type="text" class="form-control" name="timesinen" placeholder="Date" value="<?php echo $datime['tme'] ?>" <?php $user=$_SESSION['log']; if($user != 'admin'){ echo "readonly";} ?>></div>
	<?php }?>
	</div><br>
    <div class="row">
     <!-- <div class="col-sm-2"><label>Adjustment</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" name="adjustment"></div> -->
     <div class="col-sm-2"><label>Delivery-Site</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" name="delivery" id="deliveryadd"></div>
     <div class="col-sm-2"><label>Remarks</label></div>:
     <div class="col-sm-3"><input type="text" class="form-control" name="remark"></div>
     
    </div><br>
    
    <!--  -->
    
    
     
    <!--  -->
     <div class="row">
     <div class="col-sm-1"><input type="button" class="btn btn-success" data-toggle="modal" data-target="#addpro" style="float:left;margin-left:10px;height:40px;" id="submitbut" value="Submit"></div>
    </div><br> 
    <!--  -->
            

        
    <!-- enter the entry list -->
            
<br><br>
            <!-- entry div over  -->
        </div>
                <!-- modal for add confirm -->
<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> Single-Entry Transaction Have Been Generated Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning" id="singleSubmit">Ok</button>
        </div>
        
      </div>
    </div>
  </div>
  
<!-- modal for add confirm -->
        <!--overall entry div over  -->
        
        
    </div>
   <!--  -->
  </div>
</div>
</form>
  <!-- tab for rate -->
</div>
<!-- tab for entry area-->
        <!-- Modal body -->
        <div class="modal-body">
           
<!-- modal for delete -->
<!-- The Modal -->
<div class="modal fade" id="prd-1">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(247, 2, 80,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body" >
         Are You Sure Want To Delete !.
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
        <a href="#?dele=1"><button type="button" class="btn btn-success" data-dismiss="modal">Yes</button></a>
          <button type="button" class="btn btn-warning" data-dismiss="modal">No</button>
        </div>
        
      </div>
    </div>
  </div>
<!-- ,odal for delete -->
<!-- table -->


<!-- main-content-div -->
</div>
<!-- main-content-div -->
</div>
<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>
</body>
