<?= $this->extend('layouts/main') ?>

<?= $this->section('content') ?>
<style>
    th {
        font-size: 11px;
        text-align: center;
    }

    td {
        text-align: center;
    }

    #smsList tbody tr {
        cursor: pointer;
    }

    .blockUI {
        z-index: 1500 !important;
    }

    .ellipsis {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }
</style>

<h1>현장확인요약실적</h1>

<div class="col-md-12 col-xl-12">
    <div class="main-card mb-3 card">
        <div class="card-body">
            <form class="row align-items-end" method="post" id="frm_srch_info">
                <div class="col-md-1">
                    <label class="form-label mb-1">유형</label>
                    <select class="form-control" name="schDateGb">
                        <option value="1" <?= $schDateGb == '1' ? 'selected' : '' ?>>예약일자</option>
                        <option value="2" <?= $schDateGb == '2' ? 'selected' : '' ?>>등록일자</option>
                    </select>
                </div>

                <div class="col-md-3">
                    <label class="form-label mb-1">기준일자</label>
                    <div class="row g-2">
                        <div class="col-5">
                            <input type="date" class="form-control" id="sdate" name="sdate" value="<?= $sdate ?>" />
                        </div>
                        <div class="col-2 d-flex align-items-center justify-content-center">~</div>
                        <div class="col-5">
                            <input type="date" class="form-control" id="edate" name="edate" value="<?= $edate ?>" />
                        </div>
                    </div>
                </div>

                <div class="col-md-1 d-grid">
                    <button type="submit" class="btn btn-primary" id="btnSearch">
                        검색
                    </button>
                </div>

            </form>
        </div>
    </div>
</div>

<div class="col-md-12 col-xl-12">
    <div class="main-card mb-3 card">
        <div class="card-header d-flex align-items-center">
            <h3 class="card-title mb-0">요약 실적</h3>
            <div class="ms-auto d-flex align-items-center gap-3">
                <!-- <button class="mb-2 me-2 border-0 btn-transition btn btn-shadow btn-outline-success"
                    id="excel-download">엑셀다운로드</button> -->
            </div>
        </div>
        <div class="card-body">
            <div class="row">
                <table class="table table-hover table-striped table-bordered">
                    <!-- <caption>조직별 실적</caption> -->
                    <thead>
                        <tr>
                            <th>구분</th>
                            <th>접수</th>
                            <th>예약취소</th>
                            <th>예약확인</th>
                            <th>방문전취소</th>
                            <th>방문후취소</th>
                            <th>촬영후취소</th>
                            <th>촬영</th>
                            <th>검수지연</th>
                            <th>검수실패</th>
                            <th>검수완료</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($st_list as $rkey => $row) {
                            $nCol = 0;
                            if (empty($rkey))
                                $rkey = 'cnt';
                            switch ($rkey) {
                                case 'cost':
                                    echo '<tr>
                            <td>단가</td>';
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['rcpt_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['resv_cancel_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['resv_assign_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['prev_visit_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['next_visit_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['next_shoot_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['shoot_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['delay_confirm_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['fail_confirm_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '<td><input type="text" name="stat_cost' . $nCol . '" id="stat_cost' . $nCol . '"
                                    value="' . $row['confirm_cnt'] . '" maxlength="6" size="6"
                                    onchange="stat_cost_onchange(' . $nCol . ')" /></td>';
                                    $nCol++;
                                    echo '
                        </tr>';
                                    break;

                                case 'amt':
                                    echo '<tr>
                            <td>금액</td>';
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['rcpt_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['resv_cancel_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['resv_assign_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['prev_visit_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['next_visit_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['next_shoot_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['shoot_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['delay_confirm_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['fail_confirm_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '<td>
                                <div id="stat_amt' . $nCol . '">' . $row['confirm_cnt'] . '</div>
                            </td>';
                                    $nCol++;
                                    echo '
                        </tr>';
                                    break;

                                default:
                                    echo '<tr onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'normal\'">';
                                    echo '<td>건수</td>';

                                    echo '<td>' . (empty($row['rcpt_cnt']) ? '-' : $row['rcpt_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['rcpt_cnt']) ? '0' : $row['rcpt_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['resv_cancel_cnt']) ? '-' : $row['resv_cancel_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['resv_cancel_cnt']) ? '0' : $row['resv_cancel_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['resv_assign_cnt']) ? '-' : $row['resv_assign_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['resv_assign_cnt']) ? '0' : $row['resv_assign_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['prev_visit_cnt']) ? '-' : $row['prev_visit_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['prev_visit_cnt']) ? '0' : $row['prev_visit_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['next_visit_cnt']) ? '-' : $row['next_visit_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['next_visit_cnt']) ? '0' : $row['next_visit_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['next_shoot_cnt']) ? '-' : $row['next_shoot_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['next_shoot_cnt']) ? '0' : $row['next_shoot_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['shoot_cnt']) ? '-' : $row['shoot_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['shoot_cnt']) ? '0' : $row['shoot_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['delay_confirm_cnt']) ? '-' : $row['delay_confirm_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['delay_confirm_cnt']) ? '0' : $row['delay_confirm_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['fail_confirm_cnt']) ? '-' : $row['fail_confirm_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['fail_confirm_cnt']) ? '0' : $row['fail_confirm_cnt']) . '" />';

                                    $nCol++;
                                    echo '<td>' . (empty($row['confirm_cnt']) ? '-' : $row['confirm_cnt']) . '</td>';
                                    echo '<input type="hidden" name="stat_cnt' . $nCol . '" id="stat_cnt' . $nCol . '"
                                value="' . (empty($row['confirm_cnt']) ? '0' : $row['confirm_cnt']) . '" />';

                                    echo '</tr>';
                                    break;
                            }

                        }
                        ?>
                        <tr>
                            <td colspan="<?php echo $nCol + 2 ?>">
                                <input type="hidden" name="col_cnt" id="col_cnt" value="<?php echo $nCol; ?>" />
                                <div id="stat_total">합계금액: <?= $totalAmount; ?> 원</div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="row">
                <h3>중개업소 현황</h3>
                <table class="table table-hover table-striped table-bordered" style="margin-bottom:10px">
                    <caption></caption>
                    <thead>
                        <tr>
                            <th>중개업소명</th>
                            <th>사업자번호</th>
                            <th>현장 접수건</th>
                            <th>현장 촬영건</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if (empty($st_agent)) {
                            ?>
                            <tr>
                                <td colspan="4" style="text-align: center;">데이터가 없습니다.</td>
                            </tr>
                            <?php
                        } else {
                            foreach ($st_agent as $row) {
                                ?>
                                <tr>
                                    <td><?= $row['agent_nm'] ?></td>
                                    <td><?= $row['agent_id'] ?></td>
                                    <td><?= number_format($row['rcpt_count']) ?></td>
                                    <td><?= number_format($row['shoot_count']) ?></td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">

    // const tpl = document.querySelector('.my-loader-template')
    let date = new Date()

    $(function () {


        // [검색] 버튼 눌렀을 때 다시 조회
        // $('#btnSearch').on('click', function () {
        //     table.ajax.reload()
        // });

    });


</script>
<?= $this->endSection() ?>