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



<?php
include_once ('includes/config.php');

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

if(isset($_POST['save'])) {
  $statusArray = $_POST['status'];

  foreach($statusArray as $m_id => $dstatus) {
  
  
  
      if ($dstatus == "3") {
      // Permanently delete the user record
      $query = "DELETE FROM `shipment` WHERE sh_id='$m_id'";
    } else if($dstatus == "0") {
      // Update the user status
       $query = "UPDATE `shipment` SET s_status='".$dstatus."' WHERE sh_id='$m_id'";
    }
    $resnew = mysqli_query($con, $query);
  }

//  echo "<script type='text/javascript'>alert('Status Successfully Updated!');</script>";
  //echo "<script>window.location.href='shipmenttrashlist.php';</script>";
  
  
  
    echo "<div class='container'><div class='custom-alert'>Record Successfully Updated</div></div>";
        echo "<script>setTimeout(function() { window.location.href='shipmenttrashlist.php'; }, 1000);</script>";
        exit(); // Prevent the rest of the code from executing	 	
  

  $con->close();
}
?>       
               

  <!-- 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>Shipment Trash</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 -->
                <form method="post">
               <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>Tax/D-exp/O-exp</th>
                     <th>Added By</th>
                    <th>Status</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.sh_id ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      $measuretotal = $row['measurement_total'];
      $type =$row['type'];
        $status = $row['s_status'];
        $statusText = $status == 1 ? 'Active' : 'Deactive';
      
  ?>
                  <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 $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['tax_driver_exp']; ?></td>
                            
                     <td><?php echo $row['user_id']; ?></td>
                    
                     
                    
                    <td>
                      <select class="form-control" name="status[<?php echo $id; ?>]">
                        <option value="2">Select</option>
                         <option value="0">Recover</option>
                         <option value="3">Permanently Delete </option>
                        </select>
                      
                    </td>
                            
                   
                   
                   
                   
                  </tr>

                    


    <?php
    }

  
  ?>
 
                  </tbody>
                     <tfooter>
        <tr>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th><button type="submit" name="save" id="updateBtn" class="btn btn-danger" style="display: none;">Update Status</button>
            </th>
            
              
        </tr>
    </tfooter>
                </table>
                            
                     </form>

               
                  
      
               
               
               
               
                <?php } ?>
                <!-- admin check table end -->
               
               
               
               
               
  
      

                
                
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->


=

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


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