<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Trip Data</h2>
              
  <table class="table">
    <thead>
                <tr>
                    <th> Sl No.</th>
                    <th> Invoice No </th>
                    <th> Status </th>
                    <th> Product </th>
                    <th> Quantity </th>
                    <th> Customer </th>
                    <th> Mobile </th>
                    <th> Date </th>
                    <th> Delevery Date </th>
                    <th> Payment Mode </th>
                    <th> Total Amount </th>
                    <th> Shipping Address </th>
                    <th> Delevery Boy </th>
                </tr>
              </thead>
              <tbody>
                <?php  
                $date_today=date('Y-m-d');
                $start=0;
                $accommodation='t.date';
                

//$this->db->where('booking_status', '1')->order_by("order_id", "desc")->get('order_history')->result_array();

                $recordSet=$this->db->select('oh.shipping_id,oh.prd_id,oh.order_id,oh.invoice_no,oh.status,oh.total,oh.delevery_date,oh.pqun,s.name,s.mobile, s.time,s.mode,s.delivery_add,s.state,s.city,s.pin,p.p_title,p.product_size')->from('order_history as oh')->join('shipping as s', 'oh.shipping_id = s.id', 'LEFT')->join('product as p', 'oh.prd_id = p.prd_id', 'LEFT')->where('oh.booking_status','1')->order_by('oh.order_id','desc')->get()->result_array();
                 //echo $this->db->last_query();

                   
                
                for($i=0;$i<count($recordSet);$i++)
                   { $start++;
                    $row_delevery_boy = $this->db->select('*')->where('tech_id',$recordSet[$i]['seller_id'])->get('technician_info')->result_array();
                    
                                            
                    $rowcancel = $this->db->select('*')->where('order_id',$recordSet[$i]['order_id'])->get('order_cancel')->result_array();

                    

                ?>
                <tr>
                  <td scope="row"><?php echo $recordSet[$i]['order_id']; ?></td>
                  <td class="center"><?php echo $recordSet[$i]['invoice_no']; ?>
                    
                    <button class="btn btn-danger"  type="button" data-toggle="modal" data-target="#admin_cancel_modal<?php echo $recordSet[$i]['order_id']; ?>">Cancel</button>
                  </td>

                  <td class="center"> <button <?php if($recordSet[$i]['status']=='Canceled') { ?> title="Cancel Reason" <?php } else { ?> title="Change Status" <?php } ?> class="btn <?php if($recordSet[$i]['status']=='Canceled') { ?> btn-danger <?php } else if($recordSet[$i]['status']=='Completed'){ ?> btn-success <?php } else { ?> btn-primary <?php } ?> " <?php if($recordSet[$i]['status']!='Canceled' ) { if($recordSet[$i]['status']!='Completed') { if($recordSet[$i]['status']!='Admin Cancel Order') { ?> onclick="status_modal('<?php echo $recordSet[$i]['order_id']; ?>');" <?php } } } ?> type="button" <?php if($recordSet[$i]['status']=='Canceled' ) { ?>  data-toggle="modal" data-target="#cancelreason<?php echo $recordSet[$i]['order_id']; ?>" <?php } ?> <?php if($recordSet[$i]['status']=='Admin Cancel Order' ) { ?>  data-toggle="modal" data-target="#cancelreason<?php echo $recordSet[$i]['order_id']; ?>" <?php } ?>><?php echo $recordSet[$i]['status']; ?> <i class="fa fa-pencil" aria-hidden="true" style="color:#fff;"></i></button></td>
                  
                  <td class="center"><?php echo $rowproduct[0]['p_title']; ?></td>
                  
                  <td class="center"><?php echo $rowproduct[0]['product_size']; ?><?php echo $rowproduct[0]['product_unit']; ?> X <?php echo $recordSet[$i]['pqun']; ?></td>
                  
                  <td class="center"><?php echo $row_shipping[0]['name']; ?></td>
                  <td class="center"><?php echo $row_shipping[0]['mobile']; ?></td>
                  <td class="center"><?php echo $row_shipping[0]['time']; ?></td>
                  <td class="center"><?php echo $recordSet[$i]['delevery_date']; ?></td>
                  <td class="center"><?php echo $row_shipping[0]['mode']; ?></td>
                  <td class="center"><i class="fa fa-inr" aria-hidden="true"></i> <?php echo $recordSet[$i]['total']; ?></td>

                  <td class="center"  onclick="map_modal('<?php echo $row_shipping[0]['delivery_add']; ?>');"><?php echo $row_shipping[0]['state']; ?>,<?php echo $row_shipping[0]['city']; ?>,<?php echo $row_shipping[0]['pin']; ?>,<?php echo $row_shipping[0]['delivery_add']; ?></td>
                  <td class="center"> <button  title="Change Status" class="btn btn-primary" type="button" onclick="deleveryasign('<?php echo $recordSet[$i]['order_id']; ?>');"><?php if($row_delevery_boy[0]['name']!=''){ echo $row_delevery_boy[0]['name']; } else { echo 'Not Assigned'; } ?> <i class="fa fa-pencil" aria-hidden="true" style="color:#fff;"></i></button></td>
                </tr>
                                    <!-- The Modal -->
<div class="modal fade" id="admin_cancel_modal<?php echo $recordSet[$i]['order_id']; ?>">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Order Cancel</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <div class="alert alert-success StatUpd" style="display: none;">
        <strong>Order Canceled Successfully!</strong>
      </div>
      </div>
      <form id="admincancel<?php echo $recordSet[$i]['order_id']; ?>" method="post">
      <!-- Modal body -->
      <div class="modal-body">
        <div class="form-group">
            <label for="recipient-name" class="col-form-label">Cancel Reason:</label>
            <input type="text" class="form-control" name="cancel_reason" placeholder="Cancel Reason">
            <input type="hidden" name="order_id" value="<?php echo $recordSet[$i]['order_id'];?>">
            <input type="hidden" name="update" value="order_status_update"><br>
          </div>
      </div>
      
      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Save</button>
      </div>
      </form>
    </div>
  </div>
</div>

<script>
    $(document).ready(function(e) {
        $("#admincancel<?php echo $recordSet[$i]['order_id']; ?>").on('submit', function(e) {
            e.preventDefault();
                $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url();?>Product_order/admin_cancel/',
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData: false,
                    beforeSend: function() {
                        $('.addbtn').hide();
                        $('.addload').show();
                    },
                    success: function(msg) {
                        if (msg == 'success') {
                            $(".StatUpd").show();
                            $('.StatUpd').delay(3000).hide(200);
                            $('.addbtn').show();
                          $('.addload').hide();
                            setInterval(function() {
                                location.reload();
                            }, 3000);
                        } 
                    }
                });
        });
    });
</script>

                                    <?php if($recordSet[$i]['status']=='Canceled') { ?>
                                                

                                              <div class="modal fade" id="cancelreason<?php echo $recordSet[$i]['order_id']; ?>">
                                                <div class="modal-dialog">
                                                  <div class="modal-content">

                                                    <!-- Modal Header -->
                                                    <div class="modal-header">
                                                      <h4 class="modal-title">Cancel Reason</h4>
                                                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                      
                                                    </div>
                                                    
                                                    <!-- Modal body -->
                                                    <div class="modal-body">
                                                      
                                                        <p><?php echo $rowcancel['0']['reason']; ?></p>
                                                        
                                                    </div>
                                                    
                                                    <!-- Modal footer -->
                                                    <div class="modal-footer">
                                                      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                      
                                                    </div>
                                                  </div>
                                                </div>
                                              </div>



                                            <?php 
                                              } 
                                             if($recordSet[$i]['status']=='Admin Cancel Order') { ?>
                                                

                                              <div class="modal fade" id="cancelreason<?php echo $recordSet[$i]['order_id']; ?>">
                                                <div class="modal-dialog">
                                                  <div class="modal-content">

                                                    <!-- Modal Header -->
                                                    <div class="modal-header">
                                                      <h4 class="modal-title">Cancel Reason</h4>
                                                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                      
                                                    </div>
                                                    
                                                    <!-- Modal body -->
                                                    <div class="modal-body">
                                                      
                                                        <p><?php echo $rowcancel['0']['reason']; ?></p>
                                                        
                                                    </div>
                                                    
                                                    <!-- Modal footer -->
                                                    <div class="modal-footer">
                                                      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                      
                                                    </div>
                                                  </div>
                                                </div>
                                              </div>



                                            <?php } ?>

              <?php } ?>
              </tbody>
  </table>
</div>

</body>
</html>
