<?php
$usr_level = session('usr_level');
$usr_sq = session('usr_sq');
$usr_nm = session('usr_nm');

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

<?= $this->section('content') ?>

<style>
    th {
        font-size: 11px;
        text-align: center;
    }

    /* 테이블 헤더 좌우 여백 조정 */
    #resultList thead th {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    td {
        text-align: center;
    }

    #resultList tbody tr {
        cursor: pointer;
    }

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

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

    .card-header {
        display: flex !important;
        align-items: center;
    }

    .card-header-tab {
        justify-content: flex-start !important;
    }

    .table-scroll {
        max-height: 300px;
        overflow-y: scroll;
    }

    .swal2-cancel {
        background-color: #ff0000 !important;
        color: #fff !important;
    }

    #resultList.dataTable {
        width: max-content !important;
    }

    table.dataTable td,
    table.dataTable th {
        white-space: nowrap;
    }

    /* 테이블이 내용만큼 커지고, wrapper가 스크롤 담당 */
    .table-responsive {
        overflow-x: auto !important;
    }

    /* 테이블 폭: 내용에 따라 자동 조정, 스크롤 필요시 표시 */
    .table-responsive #resultList {
        width: 100% !important;
        table-layout: auto !important;
    }

    /* 줄바꿈 허용 - 공백 기준으로 줄바꿈 */
    #resultList th,
    #resultList td {
        white-space: normal !important;
        word-wrap: break-word;
    }

    /* tw-* 클래스가 DataTable의 inline 스타일보다 우선순위 높이기 */
    #resultList th.tw-30,
    #resultList td.tw-30 { width: 30px !important; max-width: 30px !important; min-width: 30px !important; }
    #resultList th.tw-50,
    #resultList td.tw-50 { width: 50px !important; max-width: 50px !important; min-width: 50px !important; }
    #resultList th.tw-70,
    #resultList td.tw-70 { width: 70px !important; max-width: 70px !important; min-width: 70px !important; }
    #resultList th.tw-80,
    #resultList td.tw-80 { width: 80px !important; max-width: 80px !important; min-width: 80px !important; }
    #resultList th.tw-90,
    #resultList td.tw-90 { width: 90px !important; max-width: 90px !important; min-width: 90px !important; }
    #resultList th.tw-100,
    #resultList td.tw-100 { width: 100px !important; max-width: 100px !important; min-width: 100px !important; }
    #resultList th.tw-120,
    #resultList td.tw-120 { width: 120px !important; max-width: 120px !important; min-width: 120px !important; }
    #resultList th.tw-130,
    #resultList td.tw-130 { width: 130px !important; max-width: 130px !important; min-width: 130px !important; }
    #resultList th.tw-140,
    #resultList td.tw-140 { width: 140px !important; max-width: 140px !important; min-width: 140px !important; }
    #resultList th.tw-150,
    #resultList td.tw-150 { width: 150px !important; max-width: 150px !important; min-width: 150px !important; }
    #resultList th.tw-180,
    #resultList td.tw-180 { width: 180px !important; max-width: 180px !important; min-width: 180px !important; }
    #resultList th.tw-200,
    #resultList td.tw-200 { width: 200px !important; max-width: 200px !important; min-width: 200px !important; }
    #resultList th.tw-250,
    #resultList td.tw-250 { width: 250px !important; max-width: 250px !important; min-width: 250px !important; }

    /* PC에서 가로 스크롤이 잘리는 대표 구간들 강제 해제 */
    .main-card,
    .card,
    .card-body {
        overflow-x: visible !important;
    }

    /* 만약 레이아웃 wrapper가 숨기고 있으면 이것도 */
    .app-main__outer,
    .app-main__inner,
    .app-main {
        overflow-x: visible !important;
    }

    /* flex 환경에서 필수 */
    .app-main,
    .app-main__outer,
    .app-main__inner,
    .card,
    .card-body {
        min-width: 0;
    }

    /* 검색 영역 행마다 구분선 추가 */
    #frm_srch_info .row.g-3 {
        padding: 12px 0;
        border-bottom: 1px solid #e9ecef;
    }

    #frm_srch_info .row.g-3:last-child {
        border-bottom: none;
    }
</style>

<div class="col-md-12 col-xl-12">
    <div class="main-card mb-3 card">
        <div class="card-header bg-white border-bottom shadow-sm">
            <div class="d-flex flex-wrap align-items-center gap-3 card-header-tab">
                <div>
                    <h4 class="mb-0 fw-bold text-dark">현장확인V2 매물 접수 현황</h4>
                </div>
            </div>
        </div>
        <div class="card-body">
      <form id="frm_srch_info" method="get" onsubmit="return false;">

        <!-- 검색 폼 -->
        <div class="row g-3">
          <div class="col-md-1">
            <label class="form-label mb-1">매물ID</label>
            <input type="text" class="form-control" name="rcpt_atclno" id="rcpt_atclno"
              onkeypress="atcl_no_enter(event)">
          </div>

          <div class="col-md-4">
            <label class="form-label mb-1">일자별조회</label>
            <div class="input-group input-group-sm">
              <select class="form-select" name="schDateGb">
                <option value="1" selected>예약일자</option>
                <option value="2">등록일자</option>
              </select>
              <input type="date" class="form-control" name="sdate" id="sdate" placeholder="시작일">
              <span class="input-group-text">~</span>
              <input type="date" class="form-control" name="edate" id="edate" placeholder="종료일">
            </div>
          </div>

          <div class="col-md-3">
            <label class="form-label mb-1">관할조직</label>
            <div class="d-flex gap-1">
              <select name="bonbu" id="bonbu" class="form-select form-select-sm">
                <option value="">-본부-</option>
                <?php foreach ($bonbu as $d): ?>
                  <option value="<?= $d['dept_sq'] ?>">
                    <?= $d['dept_nm'] ?>
                  </option>
                <?php endforeach; ?>
              </select>
              <select name="team" id="team" class="form-select form-select-sm">
                <option value="">-팀-</option>
              </select>
              <select name="damdang" id="damdang" class="form-select form-select-sm">
                <option value="">-담당자-</option>
              </select>
            </div>
          </div>

          <div class="col-md-3">
            <label class="form-label mb-1">지역별조회</label>
            <div class="d-flex gap-1">
              <select name="srcSido" id="srcSido" class="form-select form-select-sm">
                <option value="">-시/도-</option>
                <?php foreach ($sido as $s): ?>
                  <option value="<?= $s['region_cd'] ?>">
                    <?= $s['region_nm'] ?>
                  </option>
                <?php endforeach; ?>
              </select>
              <select name="srcGugun" id="srcGugun" class="form-select form-select-sm">
                <option value="">-시/군/구-</option>
              </select>
              <select name="srcDong" id="srcDong" class="form-select form-select-sm">
                <option value="">-읍/면/동-</option>
              </select>
            </div>
          </div>

          <div class="col-md-3">
            <label class="form-label mb-1">현재상태</label>
            <div class="d-flex gap-1">
              <select name="rcpt_stat1" class="form-select form-select-sm">
                <option value="">예약확인지연</option>
                <?php foreach ($codes as $c): ?>
                  <?php if ($c['category'] === "STEP_VERIFICATION"): ?>
                    <option value="<?= $c['cd'] ?>"><?= $c['cd_nm'] ?></option>
                  <?php endif; ?>
                <?php endforeach; ?>
              </select>
              <select name="rcpt_stat2" id="srcGugun" class="form-select form-select-sm">
                <option value="">-상태2-</option>
              </select>
              <select name="rcpt_stat3" id="srcDong" class="form-select form-select-sm">
                <option value="">-상태3-</option>
              </select>
            </div>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">거래구분</label>
            <select class="form-select" name="rcpt_product_info1">
              <option value="">전체</option>
              <?php foreach ($codes as $c): ?>
                <?php if ($c['category'] === "NHN_DEAL_TYPE"): ?>
                  <option value="<?= $c['cd'] ?>"><?= $c['cd_nm'] ?></option>
                <?php endif; ?>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">동영상촬영여부</label>
            <select class="form-select" name="exp_movie_yn">
              <option value="">전체</option>
              <option value="Y">촬영</option>
              <option value="N">미촬영</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">홍보확인서여부</label>
            <select class="form-select" name="conf_img_yn">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">분양권</label>
            <select class="form-select" name="parcel_out_yn">
              <option value="">전체</option>
              <option value="Y"> Y</option>
              <option value="N"> N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">CP ID</label>
            <select class="form-select" name="rcpt_cpid">
              <option value="">전체</option>
              <?php foreach ($codes as $c): ?>
                <?php if ($c['category'] === "CP_ID"): ?>
                  <option value="<?= $c['cd'] ?>"><?= $c['cd_nm'] ?></option>
                <?php endif; ?>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">매물종류</label>
            <select class="form-select" name="rcpt_product">
              <option value="">전체</option>
              <?php foreach ($codes as $c): ?>
                <?php if ($c['category'] === "ARTICLE_TYPE"): ?>
                  <option value="<?= $c['cd'] ?>"><?= $c['cd_nm'] ?></option>
                <?php endif; ?>
              <?php endforeach; ?>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">면적확인</label>
            <select class="form-select" name="exp_spc_yn">
              <option value="">전체</option>
              <option value="Y"> Y</option>
              <option value="N"> N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">체크리스트</label>
            <select class="form-select" name="check_list_img_yn">
              <option value="">전체</option>
              <option value="Y"> Y
              </option>
              <option value="N"> N
              </option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">평면도유무</label>
            <select class="form-select" name="ground_plan_yn">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">평면도요청</label>
            <select class="form-select" name="ground_plan">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">직거래</label>
            <select class="form-select" name="direct_trad_yn">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">360촬영여부</label>
            <select class="form-select" name="image_360_yn">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">검증방식</label>
            <select class="form-select" name="isSiteVRVerification">
              <option value="">전체</option>
              <option value="N">현장확인</option>
              <option value="Y">현장확인V2</option>
            </select>
          </div>

          <div class="col-md-1">
            <label class="form-label mb-1">프로모션</label>
            <select class="form-select" name="isPromotionApply">
              <option value="">전체</option>
              <option value="Y">Y</option>
              <option value="N">N</option>
            </select>
          </div>

          <!-- 검색유형 -->
          <div class="col-md-1">
            <label class="form-label mb-1">검색유형</label>
            <select class="form-select" name="srchType">
              <option value="">선택</option>
              <option value="1">중개사명</option>
              <option value="2">주소</option>
              <option value="3">사업자번호</option>
            </select>
          </div>

          <!-- 검색어 -->
          <div class="col-md-2">
            <label class="form-label mb-1">검색어</label>
            <input type="text" class="form-control" name="srchTxt" placeholder="검색어 입력">
          </div>

          <div class="col-md-1 d-grid">
            <label class="form-label mb-1 invisible">검색</label>
            <button type="button" class="btn btn-primary" id="btnSearch">
              <i class="pe-7s-search me-1"></i>검색
            </button>
          </div>
        </div>

      </form>

    </div>
  </div>

  <div class="main-card mb-3 card">
    <div class="card-header d-flex align-items-center">
      <div class="d-flex align-items-center flex-wrap" style="gap: 8px; flex: 1">

      </div>

      <div class="ml-auto">
        <button class="btn btn-sm btn-outline-success" id="excel-download">
          <i class="fa fa-fw" aria-hidden="true" title="file-excel-o"></i>
          엑셀다운로드
        </button>
      </div>
    </div>
    <div class="card-body">
      <div class="table-responsive">
        <table id="resultList" class="table table-hover table-striped table-bordered">
          <thead>
            <tr>
              <th>검증방식</th>
              <th>프로모션</th>
              <th>현재상태</th>
              <th>매물ID</th>
              <th>접수(등록)일자</th>
              <th>예약일자</th>
              <th>방문희망시간</th>
              <th>촬영완료일자</th>
              <th>CP ID</th>
              <th>중개사명</th>
              <th>주소</th>
              <th>매물종류</th>
              <th>거래구분</th>
              <?php
              if ($usr_level != '45') {
                ?>
                <th>관할조직(팀)</th>
                <th>방문담당</th>
                <?php
              }
              ?>
              <th>분양권</th>
              <th>홍보확인서</th>
            </tr>
          </thead>
          <tbody>
            <!-- 여기는 비워둠: AJAX로 채움 -->
          </tbody>
        </table>
      </div>

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

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css" />
<link href="https://unpkg.com/dropzone@6.0.0-beta.1/dist/dropzone.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script defer src="/architectui/assets/js/datatable.kor.js"></script>
<script type="text/javascript">

  const bonbuArr = <?= json_encode($bonbu, JSON_UNESCAPED_UNICODE); ?>;
  const teamArr = <?= json_encode($team, JSON_UNESCAPED_UNICODE); ?>;
  const userArr = <?= json_encode($user, JSON_UNESCAPED_UNICODE); ?>;

  const date = new Date();
  var table;

  $(function () {

    initReceiptDate();

    $("#srcSido, #srcGugun, #srcSido2, #srcGugun2").on("change", function (e) {

      const targetId = this.id;

      const isSecond = this.id.endsWith("2");

      const params = {
        srcSido: isSecond
          ? $("#srcSido2").val()
          : $("#frm_srch_info [name=srcSido]").val(),

        srcGugun: isSecond
          ? $("#srcGugun2").val()
          : $("#frm_srch_info [name=srcGugun]").val(),
      };


      $.ajax({
        url: "/manage/areas/getAreaList",
        method: "POST",
        dataType: "json",
        data: params,
        beforeSend: function () {
          blockUI.blockPage({
            message: tpl
          })
        },
        complete: function () {
          blockUI.unblockPage()
        },
        success: function (result) {

          switch (targetId) {
            case "srcSido":
              $("#srcGugun").empty()
              var str = "";
              str += "<option value=''>시/군/구</option>";

              if ($("#srcSido").val() !== "") {
                if (result.length > 0) {
                  for (var i = 0; i < result.length; i++) {
                    str += "<option value='" + result[i]['region_cd'] + "'>" + result[i].region_nm + "</option>";
                  }
                }
              }

              $("#srcGugun").append(str);

              break;

            case "srcGugun":
              $("#srcDong").empty()
              var str = "";
              str += "<option value=''>읍/면/동</option>";

              if (result.length > 0) {
                for (var i = 0; i < result.length; i++) {
                  str += "<option value='" + result[i]['region_cd'] + "'>" + result[i].region_nm + "</option>";
                }
              }

              $("#srcDong").append(str);
              break;
          }
        }
      });
    });


    $("#bonbu, #team, #bonbu2, #team2").on("change", function (e) {
      const targetId = this.id;


      var str = "";
      if (targetId === "bonbu" || targetId === "bonbu2") {
        const dept_sq = $("#" + targetId).val();

        str += `<option value="">-팀-</option>`;
        if (teamArr.length > 0) {
          for (var i = 0; i < teamArr.length; i++) {

            // 이 팀이 현재 본부에 속한 팀인지 체크
            if (String(teamArr[i].pdept_sq) === String(dept_sq)) {
              str += `
                              <option value="${teamArr[i].dept_sq}">${teamArr[i].dept_nm}</option>
                          `;
            }
          }
        }

        if (targetId === "bonbu") {
          $("#team").html(str);
        } else if (targetId === "bonbu2") {
          $("#team2").html(str);
        }

      } else if (targetId === "team" || targetId === "team2") {
        const dept_sq = $("#" + targetId).val();

        str += `<option value="">-담당자-</option>`;
        if (userArr.length > 0) {
          for (var i = 0; i < userArr.length; i++) {

            // 이 팀이 현재 본부에 속한 팀인지 체크
            if (String(userArr[i].dept_sq) === String(dept_sq)) {
              str += `
                              <option value="${userArr[i].usr_id}">${userArr[i].usr_nm}</option>
                          `;
            }
          }
        }

        if (targetId === "team") {
          $("#damdang").html(str);
        } else if (targetId === "team2") {
          $("#damdang2").html(str);
        }
      }

    });


    // 검증방식 onchange
    $("#vrfcreq_way").on("change", function (e) {
      const val = e.target.value;

      var str = "";
      str += `<option value="">-선택-</option>`;
      if (e.val !== "") {
        $.getJSON("/common/common/getVrfcCode?type=" + val, function (result) {
          var total = result.length;
          for (var i = 0; i < total; i++) {
            var cateNm = result[i].cd_nm;

            if (total == 1) {
              str += "<option value=\"" + result[i].cd + "\" selected>" + cateNm + "</option>";
            } else {
              str += "<option value=\"" + result[i].cd + "\">" + cateNm + "</option>";
            }
          }

          $("#vrfc_type_sub").html(str);
        });
      } else {
        $("#vrfc_type_sub").html(str);
      }


    });


    $("#btnSearch").on("click", function () {
      table.ajax.reload();
    });


    table = $('#resultList').DataTable({
      language: lang_kor,
      serverSide: true,
      processing: true,
      ajax: {
        url: '/article/receipt2/getResultList',
        type: 'GET',
        beforeSend: function () {
          blockUI.blockPage({
            message: tpl
          })
        },
        complete: function () {
          blockUI.unblockPage()
        },
        data: function (d) {

          d.rcpt_atclno = $("#frm_srch_info [name=rcpt_atclno]").val(); // 매물ID
          d.schDateGb = $("#frm_srch_info [name=schDateGb]").val(); // 일자유형
          d.sdate = $("#frm_srch_info [name=sdate]").val();           // 시작일
          d.edate = $("#frm_srch_info [name=edate]").val();           // 종료일

          d.bonbu = $("#frm_srch_info [name=bonbu]").val();           // 본부
          d.team = $("#frm_srch_info [name=team]").val();             // 팀
          d.user = $("#frm_srch_info [name=user]").val();             // 담당자

          d.sido = $("#frm_srch_info [name=srcSido]").val();          // 시도
          d.gugun = $("#frm_srch_info [name=srcGugun]").val();        // 시군구
          d.dong = $("#frm_srch_info [name=srcDong]").val();          // 읍면동

          d.rcpt_stat1 = $("#frm_srch_info [name=rcpt_stat1]").val();     // 상태1
          d.rcpt_stat2 = $("#frm_srch_info [name=rcpt_stat2]").val();     // 상태2
          d.rcpt_stat3 = $("#frm_srch_info [name=rcpt_stat3]").val();     // 상태3

          d.rcpt_product_info1 = $("#frm_srch_info [name=rcpt_product_info1]").val(); // 거래구분
          d.exp_movie_yn = $("#frm_srch_info [name=exp_movie_yn]").val();             // 동영상촬영여부
          d.conf_img_yn = $("#frm_srch_info [name=conf_img_yn]").val();               // 홍보확인서여부
          d.parcel_out_yn = $("#frm_srch_info [name=parcel_out_yn]").val();           // 분양권
          d.rcpt_cpid = $("#frm_srch_info [name=rcpt_cpid]").val();                   // CPID
          d.rcpt_product = $("#frm_srch_info [name=rcpt_product]").val();             // 매물종류
          d.exp_spc_yn = $("#frm_srch_info [name=exp_spc_yn]").val();                 // 면적확인
          d.check_list_img_yn = $("#frm_srch_info [name=check_list_img_yn]").val();   // 체크리스트
          d.ground_plan_yn = $("#frm_srch_info [name=ground_plan_yn]").val();         // 평면도유무
          d.ground_plan = $("#frm_srch_info [name=ground_plan]").val();               // 평면도요청

          d.direct_trad_yn = $("#frm_srch_info [name=direct_trad_yn]").val();         // 직거래
          d.image_360_yn = $("#frm_srch_info [name=image_360_yn]").val();             // 360촬영여부

          d.isSiteVRVerification = $("#frm_srch_info [name=isSiteVRVerification]").val(); //검증방식
          d.isPromotionApply = $("#frm_srch_info [name=isPromotionApply]").val(); // 프로모션

          d.srchType = $("#frm_srch_info [name=srchType]").val();                     // 검색유형
          d.srchTxt = $("#frm_srch_info [name=srchTxt]").val();                       // 검색어


          d.start = d.start || 0
          d.length = d.length || 10
        },
      },
      "columnDefs": [
        { className: 'text-center', targets: '_all' },
        { 'targets': '_all', "defaultContent": "" },
      ],
      columns: [
        { data: 'exp_movie_yn', render: fn_verify_render },
        { data: 'ground_plan_yn', render: fn_promo_render },
        { data: 'rcpt_stat_nm' },
        { data: 'rcpt_atclno' },
        { data: 'insert_tm' },
        { data: null, render: fn_rsrv_render },
        { data: 'rsrv_tm_hour' },
        { data: 'photo_save_dt' },
        { data: 'rcpt_cpid' },
        { data: null, render: fn_agent_render },
        { data: null, render: fn_addr_render },
        { data: null, render: fn_prd_render },
        { data: 'rcpt_product_info1' },
        <?php if ($usr_level != "45"): ?>
                                    { data: 'dept_nm' },
          { data: 'usr_nm' },
        <?php endif; ?>
        { data: 'parcel_out_yn' },
        { data: 'conf_img_yn' },
      ],
      // 옵션들 예시
      destroy: true,
      deferRender: true,
      scrollX: false,
      autoWidth: false,
      paging: true,
      searching: false,
      ordering: false,
    });

    // 테이블 row click
    $('#resultList tbody').on('click', 'tr', function (e) {
      if ($(e.target).closest('td.dt-no-rowclick').length) return;

      const rowData = table.row(this).data();
      if (!rowData) return;

      const rcpt_atclno = rowData.rcpt_atclno;
      location.href = "<?= site_url('article/dept/detail') ?>/" + rcpt_atclno;
    });


    // 엑셀 다운로드 click
    $("#excel-download").on("click", function () {
      $.ajax({
        url: "/article/receipt2/excel",
        method: "GET",
        dataType: "json",
        data: $("#frm_srch_info").serialize(),
        beforeSend: function () {
          blockUI.blockPage({
            message: tpl
          })
        },
        complete: function () {
          blockUI.unblockPage()
        },
        success: function (result) {
          downloadExcel(result.data);
        }
      });
    });

  });


  // 접수기간 초기화 
  function initReceiptDate() {

    const before3 = new Date();
    before3.setDate(date.getDate() - 2);

    const fmt = d => d.toISOString().slice(0, 10);

    $('#sdate').val(fmt(before3));
    $('#edate').val(fmt(date));

  }

  function atcl_no_enter(event) {
    if (event.keyCode == 13) {
      table.ajax.reload()
    }
  }

  /** datatable render */
  function fn_verify_render(data, type, row) {
    var str = "";

    if (row.isSiteVRVerification == "Y") {
      str = "현장V2";
    } else {
      str = "현장";
    }

    return str;
  }

  function fn_promo_render(data, type, row) {
    var str = "";

    if (row.isSiteVRVerification == "Y") {
      str = row.isPromotionApply;
    }

    return str;
  }

  function fn_rsrv_render(data, type, row) {
    var str = "";

    str = row.rsrv_date + " " + row.rsrv_tm_ap;

    return str;
  }

  function fn_agent_render(data, type, row) {
    var str = "";

    if (row.direct_trad_yn == 'Y') {
      str = row.sellr_nm;
    } else {
      str = row.agent_nm;
      if (row.agent_id != null) {
        str += "(" + row.agent_id + ")";
      }
    }

    return str;
  }

  function fn_addr_render(data, type, row) {
    var str = "";

    if (row.rcpt_jibun_addr == null || row.rcpt_jibun_addr == "") {
      str = row.addr + "<br/>" + row.rcpt_hscp_nm + " " + row.rcpt_dtl_addr + " " + row.rcpt_ho;
    } else {
      str = row.addr + "<br/>" + row.rcpt_hscp_nm + " " + row.rcpt_li_addr + " " + row.rcpt_jibun_addr + " " + row.rcpt_etc_addr;
    }

    return str;
  }

  function fn_prd_render(data, type, row) {
    var str = "";

    if (row.rcpt_product_nm != null && row.rcpt_product_nm != "") {
      str = row.rcpt_product_nm;
    } else {
      str = row.rcpt_product;
    }

    return str;
  }
  /** datatable render */

  // 엑셀 다운로드
  function downloadExcel(data) {
    const ws = XLSX.utils.json_to_sheet(data);
    // ws['!cols'] = [
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 150 },
    //     { wpx: 120 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    //     { wpx: 100 },
    // ];

    const wb = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "Sheet1");

    const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });

    const blob = new Blob([wbout], { type: 'application/octet-stream' });

    const link = document.createElement("a");
    link.href = URL.createObjectURL(blob);
    link.download = "현장확인V2_매물_접수_현황_" + getDateTimeString() + ".xlsx";
    link.click();
    URL.revokeObjectURL(link.href);
  }

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