<?php
$this->load->view("top");
$cart = $this->cart->contents();
$discount_amount = $this->session->userdata('discount_amount');
$posted_data = $this->session->userdata('posted_data');
?>

<section class="checkout_page ">
  <div class="container">
    <div class="row">
      <div class="col-xxl-9 col-xl-9 col-lg-9 col-md-9 col-sm-8 col-12">
        <div class="cart_left">
          <h1>Order Review</h1>
          <div class="panel-group checkout-steps" id="accordion">
            <!-- checkout-step-1  -->
            <section class="panel panel-default checkout-step-01">
              <h4 class="checkout_title">
                <a data-toggle="collapse" class="collapsed complate_bg"><span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"></path></svg></span>User Logged In </a>
              </h4>
            </section>
            <!-- checkout-step-02  -->
            <section class="panel panel-default checkout-step-02">
              <h4 class="checkout_title">
                <a data-toggle="collapse" data-toggle="collapse" class="collapsed complate_bg">
                  <span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"></path></svg></span>Delivery Address</a></h4>
            </section>
            <!-- checkout-step-03  -->
            <div class="panel panel-default checkout-step-03">
              <h4 class="checkout_title">
                <a data-toggle="collapse" data-toggle="collapse" class="collapse">
                  <span>3</span>Order Summary </a></h4>
              <div id="collapseThree" class="panel-collapse collapse show">
                <div class="panel-body">
                  <?php
                  echo form_open('cart/make_payment', 'name="cart_frm" id="cart_frm" ');
                  echo error_message();
                  echo validation_message();
                  ?>
                  <div class="summary">
                    <p class="summary_p">Order confirmation email will be sent to <a href="javascript:void()"><?php echo $this->session->userdata('username'); ?></a></p>


                    <table class="desktop_view">
                      <thead>
                        <tr>
                          <th>Product</th>
                          <th class="text-left">Unit Price</th> 
                          <th class="text-center">QTY</th> 
                          <th class="text-center">Sub Total</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
                        $totalAmount = $discountAmt = $total_shipping = 0;
                        $i = 1;
                        foreach ($cart as $items) {
                          $link = ($this->session->userdata('user_id') > 0) ? 'href="' . site_url() . 'cart/add_to_wishlist/' . $items['pid'] . '"' : 'href="#" data-toggle="modal" data-target="#log-modal"';
                          $pprice = ($items['discount_price'] > 0) ? $items['discount_price'] : $items['product_price'];
                          $totalAmount += ($pprice * $items['qty']);
                          $discountAmt += $pprice * $items['qty'];

                          $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
                          if (!is_array($items['options']['Size'])) {
                            $size_name = get_db_field_value("wps_sizes", "size_name", "WHERE size_id = '" . $items['options']['Size'] . "'");
                          }
                          if (!is_array($items['options']['Color'])) {
                            $color_name = get_db_field_value("wps_colors", "color_name", "WHERE color_id = '" . $items['options']['Color'] . "'");
                          }
                          $amount = $pprice * $items['qty'];
                          //$percent = $items['options']['GST'];
                          //$gst_amount = $amount-($amount*(100/(100+$percent)));
                          //$withoutgst = number_format(($amount - $gst_amount),2);
                          ?>
                          <tr>
                            <td data-label="PRODUCT">
                              <div class="cart_image">
                                <a href="<?= site_url() . $url['friendly_url']; ?>" title="<?= $items['origname']; ?>"><img src="<?php echo get_image('products', $items['img'], '141', '141', 'R', $url['friendly_url']); ?>" alt="<?= $items['origname']; ?>" title="<?= $items['origname']; ?>"></a>
                              </div>
                              <div class="cart_info">
                                <a href="<?= site_url() . $url['friendly_url']; ?>"><?= $items['origname']; ?></a>
                                <!--<p>This Yellow long sleeved colourblocked T-shirt from Dillinger is a great way to look stylish as ever.</p>-->
                                <p>
                                  <?php
                                  if ($items['options']['Color'] != '' && $items['options']['Size'] != '') {
                                    ?>
                                    <strong>Color</strong>: <?php echo $color_name; ?>, <strong>Size:</strong> <?php echo $size_name; ?>
                                    <?php
                                  } elseif ($items['options']['Color'] == '' && $items['options']['Size'] != '') {
                                    ?>
                                    <strong>Size:</strong> <?php echo $size_name; ?>
                                    <?php
                                  } elseif ($items['options']['Color'] != '' && $items['options']['Size'] == '') {
                                    ?>
                                    <strong>Color</strong>: <?php echo $color_name; ?>
                                    <?php
                                  }
                                  ?>
                                </p>
                              </div>
                            </td>
                            <td class="text-center" data-label="UNIT PRICE">
                              <div class="pro-price-cart details_price">
                                <div class="pro-home-price">
                                  <?php
                                  if ($items['discount_price'] > 0) {
                                    $percent = (($items['product_price'] - $items['discount_price']) * 100) / $items['product_price'];
                                    ?>
                                    <span class="product_price">₹ <?php echo number_format($items['discount_price']); ?></span>
                                    <span class="product_del">₹ <?php echo number_format($items['product_price']); ?></span>
                                    <span class="discount_value"><?= number_format($percent); ?>% Off</span>
                                    <?php
                                  } else {
                                    ?>
                                    <span class="product_price">₹ <?php echo number_format($items['product_price']); ?></span>
                                    <?php
                                  }
                                  ?>
                                </div>
                              </div>
                            </td>
                            <td class="text-center" data-label="QTY">
                              <div class="details_qty">
                                <input type="text"  readonly="readonly" name="<?php echo $i; ?>[qty]" id="qty_<?php echo $i; ?>" value="<?php echo $items['qty']; ?>" class="qty qty_value" maxlength="10">

                                
                              </div>
                            </td>
                            <td class="text-center" data-label="TOTAL">
                              <div class="pro-price-cart details_price">
                                <div class="pro-home-price">
                                  <span class="product_price">₹ <?php echo number_format($pprice * $items['qty']); ?></span>
                                </div>
                              </div>    
                            </td>
                          </tr>
                          <?php
                          $i++;
                        }
                        ?>

                      </tbody>
                    </table>

                     <div class="cart-box mobile_view">
                      <?php
                        $totalAmount = $discountAmt = $total_shipping = 0;
                        $i = 1;
                        foreach ($cart as $items) {
                          $link = ($this->session->userdata('user_id') > 0) ? 'href="' . site_url() . 'cart/add_to_wishlist/' . $items['pid'] . '"' : 'href="#" data-toggle="modal" data-target="#log-modal"';
                          $pprice = ($items['discount_price'] > 0) ? $items['discount_price'] : $items['product_price'];
                          $totalAmount += ($pprice * $items['qty']);
                          $discountAmt += $pprice * $items['qty'];

                          $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
                          if (!is_array($items['options']['Size'])) {
                            $size_name = get_db_field_value("wps_sizes", "size_name", "WHERE size_id = '" . $items['options']['Size'] . "'");
                          }
                          if (!is_array($items['options']['Color'])) {
                            $color_name = get_db_field_value("wps_colors", "color_name", "WHERE color_id = '" . $items['options']['Color'] . "'");
                          }
                          $amount = $pprice * $items['qty'];
                          //$percent = $items['options']['GST'];
                          //$gst_amount = $amount-($amount*(100/(100+$percent)));
                          //$withoutgst = number_format(($amount - $gst_amount),2);
                          ?>
            <div class="cart_item">
            <a class="cart-img" href="<?= site_url() . $url['friendly_url']; ?>" title="<?= $items['origname']; ?>"><img src="<?php echo get_image('products', $items['img'], '141', '141', 'R', $url['friendly_url']); ?>" alt="<?= $items['origname']; ?>" title="<?= $items['origname']; ?>"></a>

            <div class="cart-content">
                <h4><a href="<?= site_url() . $url['friendly_url']; ?>"><?= $items['origname']; ?></a></h4>
                        <ul class="option_2">
                          <?php
                          if ($items['options']['Color'] != '' && $items['options']['Size'] != '') {
                            ?>
                            <li>Color: <?php echo $color_name; ?></li>, <li>Size: <?php echo $size_name; ?></li>
                            <?php
                          } elseif ($items['options']['Color'] == '' && $items['options']['Size'] != '') {
                            ?>
                            <li>Size: <?php echo $size_name; ?></li>
                            <?php
                          } elseif ($items['options']['Color'] != '' && $items['options']['Size'] == '') {
                            ?>
                            <li>Color: <?php echo $color_name; ?></li>
                            <?php
                          }
                          ?>

                          <li>Qty: <?php echo $items['qty']; ?></li>
                        </ul>
                <div class="price">

                  <?php
                          if ($items['discount_price'] > 0) {
                            $percent = (($items['product_price'] - $items['discount_price']) * 100) / $items['product_price'];
                            ?>
                            ₹ <?php echo number_format($items['discount_price']); ?>
                            <del>₹ <?php echo number_format($items['product_price']); ?></del>
                            <span class="discount_value"><?= number_format($percent); ?>% Off</span>
                            <?php
                          } else {
                            ?>
                            <span>₹ <?php echo number_format($items['product_price']); ?></span>
                            <?php
                          }
                          ?>
                          <p>You Saved ₹ 99!</p>
                </div>                
            </div>
          </div>
              <div class="divider"></div>
              <?php
                          $i++;
                        }
                        ?>
        </div>



                    <a class="checkout_btn" href="<?php echo site_url(); ?>cart/make_payment" title="Pay">Pay <?php $deliveryCharge = delivery_charge(0, $totalAmount);
                        echo display_price(($totalAmount - $discount_amount) + $deliveryCharge);
                        ?></a>
                  </div>
<?php echo form_close(); ?>
                </div>
              </div>


            </div>
            <!-- checkout-step-04  -->
            <div class="panel panel-default checkout-step-04">
              <h4 class="checkout_title">
                <a data-toggle="collapse" class="collapsed">
                  <span>4</span>Payment Options</a></h4>

            </div>
            <!-- checkout-step-04  -->
          </div>
          <!-- /.checkout-steps -->
        </div>
      </div>
      <div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-4 col-12">
        <div class="cart_right_title">Cart Details</div>
        <div class="cart_right">
          <table class="table table-totals">
            <tbody>
              <?php
              $totalAmount = $discountAmt = $total_shipping = 0;
              $i = 1;
              foreach ($cart as $items) {
                $link = ($this->session->userdata('user_id') > 0) ? 'href="' . site_url() . 'cart/add_to_wishlist/' . $items['pid'] . '"' : 'href="#" data-toggle="modal" data-target="#log-modal"';
                $pprice = ($items['discount_price'] > 0) ? $items['discount_price'] : $items['product_price'];
                $totalAmount += ($pprice * $items['qty']);
                $discountAmt += $pprice * $items['qty'];
                $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();

                $i++;
              }
              ?>
              <tr>
                <td>Sub Total</td>
                <td><?= display_price($totalAmount); ?></td>
              </tr>
<?php if ($discount_amount > 0) { ?>
                <tr>
                  <td>Discount Price</td>
                  <td>- <?= display_price($discount_amount); ?></td>
                </tr>
<?php } ?>
              <tr>
                <td>Delivery Charges</td>
                <td class="free"><?php
                  $deliveryCharge = delivery_charge(0, $totalAmount);
                  echo ($deliveryCharge > 0) ? display_price($deliveryCharge) : 'Free';
                  ?></td>
              </tr>
             <!--  <tr>
                <td>GST</td>
               <td class="free"><?php
                  $gst = number_format($gst_amount, 2);
                  echo display_price($gst);
                  ?></td>
              </tr> -->
            </tbody>
            <tfoot>
              <tr>
                <td>Amount Payable</td>
                <td><?= display_price(($totalAmount - $discount_amount) + $deliveryCharge); ?></td>
              </tr>
            </tfoot>
          </table>
          <!--  <a class="order_btn" href="javascript:void()" title="Place Order">Place Order</a> -->

          <p class="safe_info"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M5.338 1.59a61.44 61.44 0 0 0-2.837.856.481.481 0 0 0-.328.39c-.554 4.157.726 7.19 2.253 9.188a10.725 10.725 0 0 0 2.287 2.233c.346.244.652.42.893.533.12.057.218.095.293.118a.55.55 0 0 0 .101.025.615.615 0 0 0 .1-.025c.076-.023.174-.061.294-.118.24-.113.547-.29.893-.533a10.726 10.726 0 0 0 2.287-2.233c1.527-1.997 2.807-5.031 2.253-9.188a.48.48 0 0 0-.328-.39c-.651-.213-1.75-.56-2.837-.855C9.552 1.29 8.531 1.067 8 1.067c-.53 0-1.552.223-2.662.524zM5.072.56C6.157.265 7.31 0 8 0s1.843.265 2.928.56c1.11.3 2.229.655 2.887.87a1.54 1.54 0 0 1 1.044 1.262c.596 4.477-.787 7.795-2.465 9.99a11.775 11.775 0 0 1-2.517 2.453 7.159 7.159 0 0 1-1.048.625c-.28.132-.581.24-.829.24s-.548-.108-.829-.24a7.158 7.158 0 0 1-1.048-.625 11.777 11.777 0 0 1-2.517-2.453C1.928 10.487.545 7.169 1.141 2.692A1.54 1.54 0 0 1 2.185 1.43 62.456 62.456 0 0 1 5.072.56z"/><path d="M10.854 5.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793l2.646-2.647a.5.5 0 0 1 .708 0z"/></svg> Safe and Secure Payments. Easy returns. 100% Authentic products.</p>
        </div>
      </div>
    </div>
  </div>
</section>



<?php $this->load->view("bottom"); ?>
<script src="<?php echo site_url(); ?>assets/developers/js/common.js"></script> 