<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');
endif;


$t_des="";
$t_id1 =0;

if(isset($_REQUEST['t_id']))

  { 

    $t_id1=$_GET['t_id'];

    $stringParts = explode("*", $t_id1);

    echo $t_id1;
    $t_id  = $stringParts[0];
    $t_des= $stringParts[1];

    

    if ($t_des==1){
 
      $cval=0;

    }

    else {

      $cval=1;

    }

 mysqli_query($con,"update tran_master set t_end=$cval where t_id='$t_id' ")or die(mysqli_error());




  }





?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>SalesHub | Transaction Setting </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">

          <div class="page-header">
            <h3 class="page-title">
                Day Start 
            </h3>
          
          </div>
          <div class="col-22 grid-margin">
              <div class="card">
                <div class="card-body">
              
                          
    <form class="needs-validation" novalidate method="post" action="day_start_add.php" enctype="multipart/form-data" onsubmit="return validateForm()">                   
                    <div class="row">                     
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Root: </label>
                          <div class="col-sm-9">
                            <select class="form-control select2" style="width: 100%;" name="r_id" id="r_id" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from root_master  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['r_id'];?>"><?php echo $rowd['r_name'];?></option>        
          <?php }?>
          </select> 
                          </div>
                        </div>

 <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Employee: </label>
                          <div class="col-sm-9">
                            <select class="form-control select2" style="width: 100%;" name="emp_id" id="emp_id" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from employee_master  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['emp_id'];?>"><?php echo $rowd['emp_name'];?></option>        
          <?php }?>
          </select> 
                          </div>
                        </div>





                      </div>
                                              
                  <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Date: </label>
                          <div class="col-sm-8">
                            <input type="date" class="form-control" id="tdate" name="tdate" >

                          </div>
                        </div>

                    </div> <!-------End of first form raw------->

            

</div>

    

  <div class="row">                     
  <div class="col-md-6">
  <div class="form-group row">


</div>
</div>
<div class="col-md-4">
                    

  </div> <!-------End of first form raw------->
<div class="col-md-2">
                 
  </div> <!-------End of first form raw------->
</div>






                     <button type="submit" class="btn btn-primary">Save</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
                </div>
              </div>
            </div>



  <div class="content-wrapper">
          <div class="col-lg-22 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h6 >Draft </h6>
                  <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back
                    
                  </button>
                  </p>
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>#</th>                         
                          <th>Date</th>
                          <th>root</th>  
                           <th>Employee</th>                        
                          <th>Day End</th> 
                           <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT tran_master.t_id,tran_master.t_date,root_master.r_name,tran_master.t_end,employee_master.emp_id,employee_master.emp_name ,tran_master.r_id FROM tran_master
LEFT JOIN root_master ON tran_master.r_id=root_master.r_id 
LEFT JOIN employee_master ON tran_master.emp_id=employee_master.emp_id

")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                
                $tran_date=$row['t_date']; 
                $r_name=$row['r_name'];
                $t_end=$row['t_end'];
                $t_id=$row['t_id']; 
                $emp_name=$row['emp_name']; 
                $emp_id=$row['emp_id']; 
                $r_id=$row['r_id'];

                if ($t_end==1) {
               $dayactive="Yes";
             }
             
              if ($t_end==0) {
               $dayactive="No";
             }


               
              

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo date('Y-m-d', strtotime($row['t_date']));?></td>
                         <td><?php echo $r_name;?></td>
                         <td><?php echo $emp_name;?></td>
                        
                       <td><?php if ($row['t_end']>0) { ?> &#10004;<?php } else { ?> &#10006; <?php } ?><a href="day_start.php?t_id=<?php echo $row['t_id'];echo "*";echo $t_end;?>"> Change</a></td>   

        <td><a href="#addvoucher<?php echo $row['t_id'];?>" data-target="#addvoucher<?php echo $row['t_id'];?>"data-toggle="modal"     </div> <i class="fas fa-edit "></i>  </i> </a> </td>
              </td> 

      <!----------------------Model ------------------------------->
     <div id="addvoucher<?php echo $row['t_id'];?>" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog" style="width:80%; aria-hidden="true>
          <div class="modal-content" style="height:auto">        
          <div class="modal-body">

             <form class="form-horizontal" method="post" action="day_start_edit.php" enctype='multipart/form-data'>

               <div class="form-group">
              <label for="exampleInputEmail1">Root </label>
         

               <select class="form-control select2" style="width: 100%;" name="root_edit" id="root_edit" required >           
          <?php            
          $querydoc=mysqli_query($con,"select * from root_master"
)or die(mysqli_error());          
          while($rowr=mysqli_fetch_array($querydoc)){
            if ($row['r_id']==$rowr['r_id']){ ?>            
            <option value="<?php echo $rowr['r_id'];?>" selected><?php echo $rowr['r_name'];?></option>
            <?php } else {
          ?>
          <option value="<?php echo $rowr['r_id'];?>"><?php echo $rowr['r_name'];?></option>        
          <?php } }?>
          </select> 


              <input type="hidden" class="form-control" id="tid_edit" name="tid_edit" value="<?php echo $row['t_id'];?>">

              <input type="hidden" class="form-control" id="rid_edit" name="rid_edit" value="<?php echo $row['r_id'];?>">
               </div>


                  <div class="form-group">
                  <label for="exampleInputPassword1">Date</label>
                <input type="date" class="form-control" id="date_edit" name="date_edit" value="<?php echo date('Y-m-d', strtotime($row['t_date'])); ?>">

                  </div>  

                   
<div class="form-group">
                  <label for="exampleInputPassword1">Employee</label>
 <select class="form-control select2" style="width: 100%;" name="emp" id="emp" required >           
          <?php            
          $querydoc=mysqli_query($con,"select * from employee_master"
)or die(mysqli_error());          
          while($rowd=mysqli_fetch_array($querydoc)){
            if ($row['emp_id']==$rowd['emp_id']){ ?>            
            <option value="<?php echo $rowd['emp_id'];?>" selected><?php echo $rowd['emp_name'];?></option>
            <?php } else {
          ?>
          <option value="<?php echo $rowd['emp_id'];?>"><?php echo $rowd['emp_name'];?></option>        
          <?php } }?>
          </select>                  
</div>


                   <div class="modal-footer">
                   <button type="submit" class="btn btn-primary">Save changes</button>
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                   </div>                   
          </form>

   


          </div>
        </div>
      </div>
    </div>
<!--------------- End of Model ------------------------------------>
 

</tr>

 <?php }  ?>

                      </tbody>
                    </table>



        </div>  <!----- <div class="content-wrapper">------>
        </div>
          
          
  </div>

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
</div>
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 

    //````````route````````````````````````````````````
    if($('#bname').val().trim().length == 0) {
           alert("Please enter the route you visited !!!");               
            return false;
    } ////``````````````````````````````````````````

    



 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



