<?php
$this->load->view("top");
$fieldType = $this->session->userdata('field_type');
?>

<section class="my_account_page">
  <div class="container">
    <div class="row">
      <div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-3 col-12">
        <?php $this->load->view('members/left'); ?>
      </div>

                  <div class="col-xxl-9 col-xl-9 col-lg-9 col-md-9 col-sm-9 col-12">
                       <?php
            echo error_message();
            echo validation_message();
            if (is_array($orders) && !empty($orders)) {
              ?>
                    <div class="right_side">
                        <h1>My Orders</h1>
                        <div class="wps_right my_order">
                            <?php
                  foreach ($orders as $key => $val) {
                    $orderDets = $this->order_model->get_order_detail($val['order_id']);
                    ?> 
                            <!--- Start Here-->
                            <div class="order_item">
                                <div class="order_top">
                                    <div class="row">
                                        <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-6 col-12">
                                            <a class="orderID" rel="noopener noreferrer" href="<?php echo site_url(); ?>members/order_details/<?php echo $val['order_id']; ?>"><?php echo $val['invoice_number']; ?></a>
                                        </div>
                                        <div class="col-xxl-8 col-xl-8 col-lg-8 col-md-8 col-sm-6 col-12 text-right">
                                            <a class="need_btn" href="<?php echo site_url(); ?>members/order_details/<?php echo $val['order_id']; ?>" title="Track"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A31.493 31.493 0 0 1 8 14.58a31.481 31.481 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94zM8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10z"/><path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/></svg> Track</a>
                                        </div>
                                    </div>
                                </div>
                                      <?php
                        if (is_array($orderDets) && !empty($orderDets)) {
                          foreach ($orderDets as $o => $pageVal) {
                            $furl = get_db_field_value("wps_products", "friendly_url", "WHERE products_id = '" . $pageVal['products_id'] . "'");
                            $img = get_db_field_value("wps_products_media", "media", "WHERE products_id = '" . $pageVal['products_id'] . "'");

                            $productName = get_db_field_value("wps_products", "product_name", "WHERE products_id = '" . $pageVal['products_id'] . "'");
                            ?>
                                <div class="order_body">
                                    <div class="row">
                                        <div class="col-xxl-5 col-xl-5 col-lg-5 col-md-5 col-sm-5 col-12">
                                            <div class="row">
                                                <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-4 col-12">
                                                    <a href="<?=$furl;?>" title="<?php echo $productName; ?>"> <img src="<?php echo get_image('products', $img, '112', '112', 'R'); ?>" alt="<?php echo $productName; ?>" title="<?php echo $productName; ?>"></a>
                                                </div>
                                                <div class="col-xxl-8 col-xl-8 col-lg-8 col-md-8 col-sm-6 col-12">
                                                    <div class="order_info">
                                                             <a href="<?= $furl; ?>" title="<?php echo $productName; ?>" target="_blank"><?php echo $productName; ?></a>
<!--                                                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>-->
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-xxl-7 col-xl-7 col-lg-7 col-md-7 col-sm-7 col-12">
                                            <div class="row">
                                                <div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-3 col-12">
                                                    <div class="order_price"><?php echo display_price($pageVal['product_price'] * $pageVal['quantity']); ?></div>
                                                </div>
                                                <div class="col-xxl-5 col-xl-5 col-lg-5 col-md-5 col-sm-5 col-12">
                                                    <div class="delivered">
                                                         <?php
                                      if ($val['order_status'] == '0') {
                                        echo '<p>Order Placed on dated ' . getDateFormat($val['order_received_date'], 2) . '</p>';
                                      } elseif ($val['order_status'] == '1') {
                                        echo '<p>Order Confirmed on dated ' . getDateFormat($val['order_confirmed_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '2') {
                                        echo '<p>Order Dispatched on dated ' . getDateFormat($val['order_dispatched_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '3') {
                                        echo '<p>In Transit on dated ' . getDateFormat($val['order_in_transit_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '4') {
                                        echo '<p>Out for delivery on dated ' . getDateFormat($val['order_out_for_delivery_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '5') {
                                        echo '<p>Cancelled on dated ' . getDateFormat($val['order_cancelled_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '6') {
                                        echo '<p>Returned on dated ' . getDateFormat($val['order_returned_date'], 6) . '</p>';
                                      } elseif ($val['order_status'] == '7') {
                                        echo '<p>Request for Return on dated ' . getDateFormat($val['order_request_for_return_date'], 6) . '</strong>';
                                      } elseif ($val['order_status'] == '8') {
                                        echo '<p>Delivered on dated ' . getDateFormat($val['order_delivery_date'], 6) . '</p> <small>Your item has been delivered</small>';
                                      }
                                      ?>
                                               
                                                    </div>
                                                </div>
                                                <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-5 col-12">
                                                    <a class="review_product" href="<?php echo site_url(); ?>members/post_review/<?php echo $pageVal['products_id']; ?>" title="Rate & Review Product"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/></svg> Rate & Review</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                                
                                <?php } }?>
                                <div class="order_foot">
                                    <div class="row">
                                        <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                            <p>Ordered On <?php echo date('d M Y H:i A', strtotime($val['order_received_date'])); ?></p>
                                        </div>
                                        <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                            <p class="text-right">Order Total <strong> <?php echo display_price($pageVal['product_price'] * $pageVal['quantity']); ?></strong></p>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                        <?php } ?> 
                    </div>
                      <?php }  else {  ?> 
                          <div class="right_side">
                        <h1>My Orders</h1>
                        <div class="wps_right my_order">
                <div class="text-center mt10 thank-you">
                <h4 class="mb-70 thankyou-text">Sorry, No Orders Found!</h4>
                <a href="<?= site_url('products'); ?>" class="checkout_btn" title="Continue Shopping">Continue Shopping</a>
              </div>
                             </div>
                       </div>      
                      <?php  } ?>
                </div>
        
        
        
        
        
        
    </div>
  </div>
</section>

<?php $this->load->view("bottom"); ?>