<?= $this->extend('layouts/front') ?>
<?= $this->section('content') ?>
<link href="/css/front/content.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/css/front/order.css" media="screen" rel="stylesheet" type="text/css" />
<div id="content">
  <div><?= html_entity_decode($viewDatas['currentCategory']->head) ?></div>
  <div class="container">
    <div class="row">
      <div class="col-10">
        <div class="top"><?= $this->include('templates/front/index_head') ?></div>
        <table class="table table-hover">
          <thead>
            <tr>
              <th>#</th>
              <?php foreach ($viewDatas['fields'] as $field) : ?><?= getFieldIndex_Column_OrderHelper($field, $viewDatas) ?><?php endforeach ?>
              <th>@</th>
            </tr>
          </thead>
          <tbody>
            <?php $cnt = 0 ?>
            <?php $order_cnt = 0 ?>
            <?php $order_price = 0 ?>
            <?php $order_sale = 0 ?>
            <?php foreach ($viewDatas['entitys'] as $entity) : ?>
              <tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status == DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
                <td nowrap>
                  <?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?>
                </td>
                <?php foreach ($viewDatas['fields'] as $field) : ?>
                  <td><?= getFieldIndex_Row_OrderHelper($field, $entity, $viewDatas) ?></td>
                <?php endforeach ?>
                <td>
                  <?php if ($entity->status != DEFAULTS['STATUS']) : ?>
                    <?= anchor(URLS['cancelCart'] . '/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
                  <?php endif ?>
                </td>
              </tr>
              <?php if ($entity->status == 'unuse') : ?>
                <?php $order_price += $entity->price ?>
                <?php $order_sale += $entity->sale ?>
                <?php $order_cnt++ ?>
              <?php endif ?>
              <?php $cnt++ ?>
            <?php endforeach ?>
          </tbody>
        </table>
      </div>
      <div id="order" class="col-2">
        <div class="orderbox">
          <?= form_open(URLS['Billing'], ['method' => 'post'], $viewDatas['forms']['hiddens']) ?>
          <?php foreach ($viewDatas['entitys'] as $entity) : ?>
            <?= form_hidden("order_uids[]", $entity->getPrimaryKey()) ?>
          <?php endforeach ?>
          <?= form_hidden("price", '') ?>
          <div class="title">결제정보</div>
          <div class="item">
            <span class="label">상품수</span>
            <span class="value"><?= $order_cnt ?>개</span>
          </div>
          <div class="item">
            <span class="label">상품금액</span>
            <span class="value"><?= number_format($order_price) ?>원</span>
          </div>
          <div class="item">
            <span class="label">할인금액</span>
            <span class="value"><?= number_format($order_sale) ?>원</span>
          </div>
          <div class="item total">
            <span class="label">총결제금액</span>
            <span class="value"><?= number_format($order_price - $order_sale) ?>원</span>
          </div>
          <div class="item submit">
            <?= $order_cnt ? form_submit('', '구매하기', array('', "class" => "btn btn-outline btn-primary")) : "결제할 주문건수가 없습니다." ?>
          </div>
          <?= form_close(); ?>
        </div>
      </div>
      <div class="bottom"><?= $viewDatas['pagination'] ?></div>
      <div><?= html_entity_decode($viewDatas['currentCategory']->tail) ?></div>
    </div>
  </div>
  <?= $this->endSection() ?>