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

$userid=$_SESSION['hrm_id'];
$t_des="";
$t_id1 =0;


 $querydoc=mysqli_query($con,"select * from tran_master LEFT JOIN root_master ON tran_master.r_id=root_master.r_id where t_end=0 and userid=$userid ")or die(mysqli_error());

   $count=mysqli_num_rows($querydoc);
   if ($count>0){ 

       while($row=mysqli_fetch_array($querydoc)){ 
            $r_id=$row['r_id'];  
            $r_name=$row['r_name'];  
        }

   }

else {

      echo "<script type='text/javascript'>alert('Root should be assign for this data!!!');</script>";
        echo "<script>document.location='day_start.php'</script>";
}




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">
                 Sales Start
            </h3>
          
          </div>
          <div class="col-22 grid-margin">
              <div class="card">
                <div class="card-body">
              
                          
    <form class="needs-validation" novalidate method="post" action="sales_dashboard.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">Customer: </label>
                          <div class="col-sm-9">
                             <select class="form-control select2" style="width: 100%;" name="cus_id" id="cus_id" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from customer_master where r_id=$r_id ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['cus_id'];?>"><?php echo $rowd['cus_name'];?></option>        
          <?php }?>
          </select> 
                          </div>
                        </div>


                      </div>
            

            

</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">Next</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>Day End</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 FROM tran_master
LEFT JOIN root_master ON tran_master.r_id=root_master.r_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']; 


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


               
              

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['t_date'];?></td>
                         <td><?php echo $r_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> 

      
 

</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>



