<?php include('common/header.php'); ?>
  <!-- Main Sidebar Container -->
<?php include('common/sidenav.php'); ?>





  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
  

    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>All Shipment</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="addshipment.php" class="btn btn-danger"><i class="fa fa-plus">Add New</i></a></li>
            <!--  <li class="breadcrumb-item active"><a href="#">Dashboard</a></li>-->
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">


            <div class="card">
              <div class="card-header">
                <h3 class="card-title">Lists</h3>
              </div>
        
              <!-- /.card-header -->
              <div class="card-body">
               <?php $role = $_SESSION['sess_role']; ?>
               <?php if($role =='Admin'){?>
                 <!-- admin check table -->
                
               <table id="example1" width="100%"  class="table table-striped">
                  <thead class="bg bg-danger">
                  <tr>
                    <th>S No</th>
                    <th>Slip No</th>
                    <th>SM No#</th>
                    <th>Vendor</th>
                    <th>Vehicle</th>
                    <th>Date</th>
                    <th>Material</th>
                    <th>Qty</th>
                    <th>Measurement</th>
                    <th>Rate</th>
                    <th>Amount</th>
                    <th>Diesel</th>
                    <th>Mcost</th>
                    <th>VehM</th>
                    <th>Tax/D-exp/O-exp</th>
                  
                    <th>Status</th>
                    <th>Added By</th>
                    <th>Action</th>
                   
                  </tr>
                  </thead>
                  <tbody>

  <?php
    include('includes/config.php');
               
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `shipment` as s WHERE  s.s_status!=2 ORDER BY s.s_date ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      $measuretotal = $row['measurement_total'];
      $type =$row['type'];
  ?>
                  <tr>
                      <?php $id = $row['sh_id']; ?>
                    <td><?php echo $no; ?></td>
                    <td><?php echo $row['slip_no']; ?></td>
                    <td><?php echo $row['order_num']; ?></td>
                    <td><?php echo $row['vendor_id']; ?></td>
                    <td><?php echo $row['measure_id']; ?></td>
                      <td><?php $prdate = $row['s_date']; 
                      echo date("d/m/Y", strtotime($prdate)); ?>
         
                      </td>
                   
                    <td><?php echo $row['material_id']; ?></td>
                    <td><?php echo $row['qty']; ?></td>
                     <td><?php echo $row['measurement_total']; ?></td>
                    <td><?php echo $row['s_rate']; ?></td>
                   <td><?php echo $row['ship_total']; ?></td>
                   <td><?php echo $row['s_diesel']; ?></td>
                   <td><?php echo $row['material_cost']; ?></td>
                    <td><?php echo $row['veh_maintaince']; ?></td>
                   <td><?php echo $row['tax_driver_exp']; ?></td>
                            
                     
                     
                    
                    <td>
                        <?php $status = $row['s_status']; ?>
                        <?php if($status == 0){?>
                        <span class="text-info">Pending</span>
                        <?php } ?>
                        <?php if($status == 1){?>
                        <span class="text-success">Delivered</span>
                        <?php } ?>
                      
                    </td>
                    <td><?php echo $row['user_id']; ?></td>
                            
                     <td>
                        <?php if($measuretotal != 0) { ?>
                        <a href="shipmentedit.php?id=<?php echo $row['sh_id']; ?>">
                  <i class="fas fa-edit"></i>
                  <?php } else if($type =='time') { ?> 
                   <a href="shipmenthedit.php?id=<?php echo $row['sh_id']; ?>">
                  <i class="fas fa-edit"></i>
                  <?php } else { ?>
                  <a href="shipmentfedit.php?id=<?php echo $row['sh_id']; ?>">
                  <i class="fas fa-edit"></i>
                  <?php } ?>
                          ||
                        <a  onclick="return confirm('Are you sure to Remove this Slip No: <?php echo $row['slip_no']; ?> ?')" href="shipmentdelete.php?id=<?php echo $id; ?>"  ><i style="font-size:15px; color:red;"  class="fa fa-trash"></i></a>
                        <!--||
                          <a onclick="window.open(this.href); return false;" href="shipmentview.php?id=<?php echo $row['sh_id']; ?>">
                  <i class="fas fa-print"></i>-->
                 
                    </td>
                   
                   
                   
                  </tr>

                    


    <?php
    }

  
  ?>
 
                  </tbody>
                </table>
                     
                <?php } ?>
                <!-- admin check table end -->
                
                <!-- user table -->
                 <?php if($role =='User'){?>
                 <!-- User check table -->
                
               <table id="example1" width="100%" class="table table-striped">
                  <thead class="bg bg-danger">
                  <tr>
                    <th>S No</th>
                    <th>Slip No</th>
                    <th>SM No#</th>
                    <th>Vendor</th>
                     <th>Vehicle</th>
                     <th>Date</th>
                    <th>Material</th>
                    <th>Qty</th>
                     <th>Measurement</th>
                    <th>Rate</th>
                    <th>Amount</th>
                    <th>Diesel</th>
                    <th>Mcost</th>
                    <th>VehM</th>
                    <th>Tax/D-exp/O-exp</th>
                   
                    <th>Status</th>
                    <th>Added By</th>
                    <th>Action</th>
                   
                  </tr>
                  </thead>
                  <tbody>

  <?php
 // $user =  $_SESSION['sess_user_id'];
 $user = $_SESSION['sess_user'];
    include('includes/config.php');
               
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `shipment` as s Where s.user_id='$user' AND s.s_status!=2 ORDER BY s.s_date ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      
  ?>
                   <tr>
                      <?php $id = $row['sh_id']; ?>
                    <td><?php echo $no; ?></td>
                    <td><?php echo $row['slip_no']; ?></td>
                    <!--<td><center><img src="uploads/laptop/<?php// echo $row['image'];?>" height="100px" width="70px"/></center>
                          </td>-->
                    <td><?php echo $ordernumber = $row['order_num']; ?></td>
                    <td><?php echo $row['vendor_id']; ?></td>
                    <td><?php echo $row['measure_id']; ?></td>
                      <td><?php $prdate = $row['s_date']; 
                      echo date("d/m/Y", strtotime($prdate)); ?>
         
                      </td>
                   
                    <td><?php echo $row['material_id']; ?></td>
                    <td><?php echo $row['qty']; ?></td>
                     <td><?php echo $row['measurement_total']; ?></td>
                    <td><?php echo $row['s_rate']; ?></td>
                   <td><?php echo $row['ship_total']; ?></td>
                    <td><?php echo $row['s_diesel']; ?></td>
                   <td><?php echo $row['material_cost']; ?></td>
                    <td><?php echo $row['veh_maintaince']; ?></td>
                   <td><?php echo $row['tax_driver_exp']; ?></td>
                     
                            
                     
                     
                    
                    <td>
                        <?php $status = $row['s_status']; ?>
                        <?php if($status == 0){?>
                        <span class="text-info">Pending</span>
                        <?php } ?>
                        <?php if($status == 1){?>
                        <span class="text-success">Delivered</span>
                        <?php } ?>
                      
                    </td>
                    <td><?php echo $row['user_id']; ?></td>
                            
                    <td>
                        <?php
 include_once ('includes/config.php');
   
// Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

if(isset($_POST['submit']))
{
 

$dstatus = $_POST["status"];
$shipid = $_POST['shipid'];

 // Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 
  else
  

     $query = "Update `shipment` SET s_status='".$dstatus."' WHERE sh_id='$shipid'";
     //order add
     $resnew = mysqli_query($con, $query);
    
 echo"<script type='text/javascript'>alert('Status Successfully Updated!);</script>";
echo "<script>(window.location.href='shipment.php');</script>";
$con->close();
      
       
}

 ?>
                       <form method="post">
                           <select class="form-control" name="status">
                                <option value="<?php echo $row['s_status']; ?>">Selected <?php $status = $row['s_status']; ?>
                                    <?php if($status ==1) { ?>
                                     Delivered
                                    <?php } elseif($status ==0) { ?>
                                     Pending
                                    <?php } ?>
                                    </option>
                                    <option value="0">Pending</option>
                                    <option value="1">Delivered</option>
                                    <input hidden type="text" name="shipid" value="<?php echo $row['sh_id'];?>">
                           </select>
                           <button type="submit" name="submit" class='btn btn-danger'>Save</button>
                       </form>
                       
                       
                       
                    </td>
                   
                   
                   
                  </tr>

                    


    <?php
    }

  
  ?>
 
                  </tbody>
                </table>
                     
                <?php } ?>
              
                
                <!--  user table end-->
                
                
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->



<script>
  //show a confirmation and redirect to the delete profile script
  function deleteProfile() {
    if (confirm("Do you really want to delete your profile?")) {
        //location.href = '/deleteuser.php';
    }
}
</script>


  </div>
  <!-- /.content-wrapper -->


<?php include('common/footer.php'); ?>