<?php
include(dirname(__FILE__) . '/../header.php');
?>
<h2>予約詳細</h2>

<table class="inp">
<tr><th width="240px">予約id :</th>
<td><?php echo $resid ?></td></tr>
<tr><th>予約日 :</th>
<td><?php echo $reservation['created'] ?></td></tr>
<tr><th>ステータス :</th>
<td>
<?php

// $reservation_detail を以下の配列に変換する。
// $tmp_reservation_detail[$day][$room_no][$guesttypeid] = array()
$tmp_reservation_detail = array();
foreach ($reservation_detail as $tmp)
{
    $day = $tmp['day'];
    $room_no = $tmp['room_no'];
    $guesttypeid = $tmp['guesttypeid'];
    $tmp_reservation_detail[$day][$room_no][$guesttypeid] = $tmp;
}

// $reservation_options を以下の配列に変換する。
// $tmp_reservation_options[$day][$optionid] = array()
$tmp_reservation_options = array();
foreach ($reservation_options as $tmp)
{
    $day = $tmp['day'];
    $optionid = $tmp['optionid'];
    $tmp_reservation_options[$day][$optionid] = $tmp;
}

if ($reservation['status'] == 1) { echo '仮予約'; }
else if ($reservation['status'] == 2) { echo '本予約'; }
else if ($reservation['status'] == 0) { echo 'キャンセル'; }
if ($reservation['status'] == 1 || $reservation['status'] == 2)
{
    echo '&nbsp;(';
    if ($reservation['status'] == 1)
    {
        // 仮予約 -> 本予約
        echo '<a href="' . site_url('admin/res/changeStatus/' . $hotelid . '/' . $resid . '/2') . '">→本予約<a/>';
        echo '&nbsp;';
    }
    echo '&nbsp;';
    if ($reservation['status'] == 1 || $reservation['status'] == 2)
    {
        // -> キャンセル
        echo '<a href="' . site_url('admin/res/changeStatus/' . $hotelid . '/' . $resid . '/0') . '">→キャンセル<a/>';
    }
    echo ')';
}
?>
</td></tr>
<tr><th>チェックイン～チェックアウト :</th>
<td>
<?php
echo $reservation['cin'];
echo '(' . $this->Common_model->week($reservation['cin']) . ')';
echo '～';
echo $reservation['cout'];
echo '(' . $this->Common_model->week($reservation['cout']) . ')';
?>
</td></tr>
<tr><th>プラン :</th>
<td><?php echo $plan['plan_name'] ?></td></tr>
<tr><th>部屋タイプ :</th>
<td><?php echo $roomtype['roomtype_name'] ?></td></tr>
<tr><th>部屋数 :</th>
<td><?php echo $reservation['room_num'] . '部屋'; ?></td></tr>
<tr><th>人数 :</th>
<td>
<?php 
foreach ($tmp_reservation_detail as $tmp)
{
    $tmp_reservation_detail_1 = $tmp;
    break;
}
$m = 0;
foreach ($tmp_reservation_detail_1 as $i)
{
    echo ($m + 1) . '部屋' . "<br />\n";
    foreach ($i as $j)
    {
        $guesttypeid = $j['guesttypeid'];
        $guesttype_name = $guesttypes[$guesttypeid]['guesttype_name'];
        $num = $j['num'];
        echo $guesttype_name . " x " . $num . "人";
        echo "<br />\n";
    }
    $m++;
}
?></td></tr>
<tr><th>料金 :</th>
<td>
<?php
$n = 0;
foreach ($tmp_reservation_detail as $i)
{
    echo ($n + 1) . '日目' . "<br />\n";
    $m = 0;
    foreach ($i as $j)
    {
        echo ($m + 1) . '部屋' . "<br />\n";
        foreach ($j as $k)
        {
            $guesttypeid = $k['guesttypeid'];
            $guesttype_name = $guesttypes[$guesttypeid]['guesttype_name'];
            $num = $k['num'];
            $subtotal = $k['subtotal'];
            echo $guesttype_name . " x " . $num . "人 = " . number_format($subtotal) . "円";
            echo "<br />\n";
        }
        $m++;
    }
    $n++;
}
?>
</td>
</tr>

<tr><th>オプション :</th>
<td>
<?php
$n = 0;
foreach ($tmp_reservation_options as $i)
{
    echo ($n + 1) . '日目' . "<br />\n";
    foreach ($i as $option)
    {
        echo $option['option_name'] . ' : ';
        echo number_format($option['price']) . '円 x ';
        echo $option['num'] . ' ' . $option['unitname'] . ' = ';
        $option_subtotal = $option['price'] * $option['num'];
        echo number_format($option_subtotal) . ' 円' . "<br />\n";
    }
    $n++;
}
?>
</td>
</tr>

<tr><th>合計 :</th>
<td><?php echo number_format($reservation['total_price']) . '円' ?></td></tr>
<tr><th>チェックイン時刻 :</th>
<td><?php echo substr($reservation['cin_hour'], 0, 5); ?></td></tr>
<tr><th>備考 :</th>
<td><?php echo $reservation['memo']; ?></td></tr>

</table>
<br />
<table class="inp">
<tr><th width="240px">氏名（かな） :</th>
<td><?php echo $reservation_member['name'] . '（' . $reservation_member['name_kana'] . '）' ?></td></tr>
<tr><th>住所 :</th>
<td>
<?php
echo '〒' . $reservation_member['postcode'] . "<br />";
echo $reservation_member['prefecture'] . ' ' . $reservation_member['city'];
?></td></tr>
<tr><th>電話 :</th>
<td>
<?php echo $reservation_member['phone']; ?></td></tr>
<tr><th>Eメールアドレス :</th>
<td>
<?php echo $reservation_member['email']; ?></td></tr>

</table>
<?php
echo '<a href="' . site_url('admin/res/index/' . $hotelid) . '">予約リストに戻る<a/>';
?>

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