<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>

<!-- Page Body -->
<div class="content-pop" data-doctx="${pageName}">
    <div class="d-flex flex-row justify-content-evenly">
        <!-- 수납 정보 -->
        <div class="col-xl-12 mx-1">
            <div class="card">
                <!-- 업무 버튼 -->
                <div class="container-page-btn">
                    <label class="col-form-label bg-label-danger pe-2 w-px-120 text-sm-center">수납 정보</label>
                    <!-- 버튼 우측 정렬 -->
                    <span class="container-window-btn-right">
                        <button type="button" class="btn btn-primary w-px-120" name="btnCreateRcvmt" title="수납 등록" disabled>
                            수납 등록
                        </button>
                        <button type="button" class="btn btn-primary w-px-120" name="btnUpdateRcvmtRtrc" title="수납 취소" disabled>
                            수납 취소
                        </button>
                        <button type="button" class="btn btn-primary w-px-120" name="btnRemoveRcvmt" title="수납 삭제" disabled>
                            수납 삭제
                        </button>
                    </span> <!-- <span class="container-window-btn-right"> -->
                </div> <!-- <div class="container-page-btn"> -->

                <div class="row g-1">
                    <!-- DataTables(그리드) -->
                    <div class="card-datatable text-nowrap">
                        <div class="dataTables_wrapper dt-bootstrap5 no-footer">
                            <div class="table-responsive ox-scroll oy-scroll h-px-350" name="tableRspnsRcvmt">
                                <table class="table-layout-fixed dataTable datatables-ajax table table-bordered no-footer" aria-describedby="DataTables_Table_0_info">
                                    <thead class="sticky-thead">
                                        <tr name="theadTrRcvmt" data-search-target="[data-doctx='${pageName}']">
                                            <th class="cmn sorting" style="width: 100px" data-field="RCVMT_RTRCN_NM">수납취소</th>
                                            <th class="cmn sorting" style="width: 140px" data-field="RCVMT_INPT_SE_NM">수납입력구분</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_SN">수납일련번호</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_SE_NM">수납구분</th>
                                            <th class="cmn sorting" style="width: 100px" data-field="DEPT_CD">부서코드</th>
                                            <th class="cmn sorting" style="width: 140px" data-field="SPCL_BIZ_CD">특별회계사업코드</th>
                                            <th class="cmn sorting" style="width: 100px" data-field="FYR">회계연도</th>
                                            <th class="cmn sorting" style="width: 100px" data-field="ACNTG_SE_CD">회계구분</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="TXITM_CD">세목코드</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="LEVY_NO">부과번호</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_YMD">수납일자</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="ACNTG_YMD">회계일자</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="TSF_YMD">이체일자</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_AMT">수납금액</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_PCPTAX">수납본세</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_ADAMT">수납가산금</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_INT">수납이자</th>
                                            <th class="cmn sorting" style="width: 200px" data-field="RCVMT_BANK_NM">수납은행명</th>
                                            <th class="cmn sorting" style="width: 160px" data-field="PAY_MTHD_SE_NM">납부방법구분</th>
                                            <th class="cmn sorting" style="width: 200px" data-field="EPAYNO">전자납부번호</th>
                                            <th class="cmn sorting" style="width: 200px" data-field="VR_ACTNO">가상계좌번호</th>
                                            <th class="cmn sorting" style="width: 140px" data-field="RCVMT_RTRCN_DT">수납취소일시</th>
                                            <th class="cmn sorting" style="width: 160px" data-field="RCVMT_RTRCN_RSN">수납취소사유</th>
                                            <th class="cmn sorting" style="width: 120px" data-field="RCVMT_STTS_NM">수납상태</th>
                                            <th class="cmn sorting" style="width: 180px" data-field="REG_DT">등록일시</th>
                                            <th class="cmn sorting" style="width: 140px" data-field="RGTR_NM">등록사용자</th>
                                            <th class="cmn dummy-th"></th>
                                        </tr>
                                    </thead>
                                    <tbody name="tbodyRcvmtList">
                                    </tbody>
                                    <template is="curly-brackets" name="tmpltRcvmtRows">
                                        <tr data-key="{data-index}">
                                            <td class="text-center text-red" onclick">{RCVMT_RTRCN_NM}</td>
                                            <td class="text-center" onclick>{RCVMT_INPT_SE_NM}</td>
                                            <td class="text-center" onclick>{RCVMT_SN}</td>
                                            <td class="text-center" onclick>{RCVMT_SE_NM}</td>
                                            <td class="text-center" onclick>{DEPT_CD}</td>
                                            <td class="text-center" onclick>{SPCL_BIZ_CD}</td>
                                            <td class="text-center" onclick>{FYR}</td>
                                            <td class="text-center" onclick>{ACNTG_SE_CD}</td>
                                            <td class="text-center" onclick>{TXITM_CD}</td>
                                            <td class="text-center" onclick>{LEVY_NO}</td>
                                            <td class="text-center" onclick>{RCVMT_YMD}</td>
                                            <td class="text-center" onclick>{ACNTG_YMD}</td>
                                            <td class="text-center" onclick>{TSF_YMD}</td>
                                            <td class="text-end"    onclick>{RCVMT_AMT}</td>
                                            <td class="text-end"    onclick>{RCVMT_PCPTAX}</td>
                                            <td class="text-end"    onclick>{RCVMT_ADAMT}</td>
                                            <td class="text-end"    onclick>{RCVMT_INT}</td>
                                            <td class="text-start"  onclick>{RCVMT_BANK_NM}</td>
                                            <td class="text-start"  onclick>{PAY_MTHD_SE_NM}</td>
                                            <td class="text-center" onclick>{EPAYNO}</td>
                                            <td class="text-center" onclick>{VR_ACTNO}</td>
                                            <td class="text-center" onclick>{RCVMT_RTRCN_DT}</td>
                                            <td class="text-center" onclick>{RCVMT_RTRCN_RSN}</td>
                                            <td class="text-center" onclick>{RCVMT_STTS_NM}</td>
                                            <td class="text-center" onclick>{REG_DT}</td>
                                            <td class="text-center" onclick>{RGTR_NM}</td>
                                            <td class="cmn dummy-td"></td>
                                        </tr>
                                    </template>
                                    <template name="tmpltNotFoundRcvmt">
                                        <tr class="odd">
                                            <td valign="top" colspan="27" class="dataTables_empty text-center">수납정보 이력 정보를 찾지 못했습니다.</td>
                                        </tr>
                                    </template>
                                </table>
                            </div>
                        </div>
                    </div> <!-- DataTables(그리드) -->
                </div> <!-- <div class="row g-1"> -->

                <p></p>

                <!-- 입력 영역 -->
                <form name="frmEditRcvmt">
                    <!-- hidden -->
                    <input type="hidden" name="rcvmtId" data-map="RCVMT_ID" />
                    <input type="hidden" name="levyId" data-map="LEVY_ID" />

                    <div class="row g-1">
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="acntgSeCd">회계구분</label>
                            <input is="id-input" type="text" class="form-control w-15" name="acntgSeCd" data-map="ACNTG_SE_CD" readonly />
                            <input is="id-input" type="text" class="form-control w-50" name="acntgSeNm" data-map="ACNTG_SE_NM" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="txitmCd">세목코드</label>
                            <input is="id-input" type="text" class="form-control w-20" name="txitmCd" data-map="TXITM_CD" readonly />
                            <input is="id-input" type="text" class="form-control w-45" name="txitmNm" data-map="TXITM_NM" readonly />
                        </div>
                        <div class="col-md-3">
                            <label class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="fyr">회계연도</label>
                            <input is="id-input" type="text" class="form-control w-20" name="fyr" data-map="FYR" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="levyNo">부과번호</label>
                            <input is="id-input" type="text" class="form-control w-20" name="levyNo" data-map="LEVY_NO" readonly />
                            <input is="id-input" type="text" class="form-control w-15" name="ispySn" data-map="ISPY_SN" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtSn">수납순번</label>
                            <input is="id-input" type="text" class="form-control w-15" name="rcvmtSn" data-map="RCVMT_SN" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtYmd">수납일자</label>
                            <input is="id-input" type="text" class="form-control w-30" name="rcvmtYmd" data-map="RCVMT_YMD" data-fmt-type="day" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="acntgYmd">회계일자</label>
                            <input is="id-input" type="text" class="form-control w-30" name="acntgYmd" data-map="ACNTG_YMD" data-fmt-type="day" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="pstmrkYmd">이체일자</label>
                            <input is="id-input" type="text" class="form-control w-30" name="tsfYmd" data-map="TSF_YMD" data-fmt-type="day" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtAmt">수납금액</label>
                            <input is="id-input" type="text" class="form-control w-30 text-end" name="rcvmtAmt" data-map="RCVMT_AMT" data-fmt-type="number" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtPcptax">수납본세</label>
                            <input is="id-input" type="text" class="form-control w-30 text-end" name="rcvmtPcptax" data-map="RCVMT_PCPTAX" data-fmt-type="number" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtAdamt">수납가산금</label>
                            <input is="id-input" type="text" class="form-control w-30 text-end" name="rcvmtAdamt" data-map="RCVMT_ADAMT" data-fmt-type="number" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtInt">수납이자</label>
                            <input is="id-input" type="text" class="form-control w-30 text-end"  name="rcvmtInt" data-map="RCVMT_INT" data-fmt-type="number" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtSeNm">수납구분</label>
                            <input is="id-input" type="text" class="form-control w-30" name="rcvmtSeNm" data-map="RCVMT_SE_NM" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcvmtBankNm">수납은행</label>
                            <input is="id-input" type="text" class="form-control w-50" name="rcvmtBankNm" data-map="RCVMT_BANK_NM" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="payMthdSeNm">납부방식</label>
                            <input is="id-input" type="text" class="form-control w-50" name="payMthdSeNm" data-map="PAY_MTHD_SE_NM" readonly />
                        </div>
                        <div class="col-md-3">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end text-red" for="rcvmtRtrcnDt">수납취소일자</label>
                            <input is="id-input" type="text" class="form-control w-30 text-red" name="rcvmtRtrcnDt" data-map="RCVMT_RTRCN_DT" data-fmt-type="day" readonly />
                        </div>
                        <div class="col-md-6">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="regDt">등록일시</label>
                            <input is="id-input" type="text" class="form-control w-25" name="regDt" data-map="REG_DT" data-fmt-type="dt" readonly />
                            <input is="id-input" type="text" class="form-control w-20" name="rgtrNm" data-map="RGTR_NM" readonly />
                        </div>
                        <div class="col-md-6">
                            <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="mdfcnDt">수정일시</label>
                            <input is="id-input" type="text" class="form-control w-25" name="mdfcnDt" data-map="MDFCN_DT" data-fmt-type="dt" readonly />
                            <input is="id-input" type="text" class="form-control w-20" name="mdfrNm" data-map="MDFR_NM" readonly />
                        </div>
                    </div> <!-- <div class="row g-1"> -->
                </form>
                <!-- 입력 영역 -->
            </div> <!-- <div class="card"> -->
        </div> <!-- <div class="col-xl-12 mx-1"> -->
        <!-- 수납 정보 -->
    </div> <!-- <div class="d-flex flex-row justify-content-evenly"> -->
</div> <!-- <div class="content-pop"> -->

<script>
    LoadScript("sprt02070Script", wctx.url("/resources/js/fims/sprt/sprt02070.js?ver=${ver}"));

    /**************************************************************************
     * Global Variable
     **************************************************************************/
    pageObject["${pageName}"] = newDoctxFinder("${pageName}");

    /**************************************************************************
     * script 진입
     **************************************************************************/
    $(document).ready(function() {
        // pageObject
        let $P = pageObject["${pageName}"];

        // datasetControl
        $P.ctrlRcvmt = newSprt02070Control("${pageName}", "[data-doctx=${pageName}]", "${pageNameMain}");

        /**************************************************************************
         * 사용자 함수(function)
         **************************************************************************/
        // 수정 callback
        $P.callbackUpdate = (obj) => {
            // 서버에 전송할 data(파라미터) 생성
            let params = {
                  callPurpose: "update"
                , sggCd: $P.ctrlRcvmt.getValue("SGG_CD")                        // 시군구 코드
                , taskSeCd: $P.ctrlRcvmt.getValue("TASK_SE_CD")                 // 업무 구분 코드
                , rcvmtId: $P.ctrlRcvmt.getValue("RCVMT_ID")                    // 수납 ID
                , rcvmtRtrcnYn: "Y"                                             // 수납 취소 여부
                , btnTitle: obj.btnTitle                                        // 버튼 title
                , rcvmtRtrcnRsn: obj.reason                                     // 수납 취소 사유
            };

            $P.ctrlRcvmt.save(params);
        }

        // 사유 callback
        $P.callbackRsn = (obj) => {
            // 서버에 전송할 data(파라미터) 생성
            let params = {
                  callPurpose: "remove"
                , sggCd: $P.ctrlRcvmt.getValue("SGG_CD")                        // 시군구 코드
                , taskSeCd: $P.ctrlRcvmt.getValue("TASK_SE_CD")                 // 업무 구분 코드
                , rcvmtId: $P.ctrlRcvmt.getValue("RCVMT_ID")                    // 수납 ID
                , btnTitle: obj.btnTitle                                        // 버튼 title
                , delRsn: "[개별총정보-" + obj.btnTitle + "] " + obj.reason     // 삭제 사유
            };

            $P.ctrlRcvmt.remove(params);
        }

        // 정보 새로고침
        $P.fnRefresh = () => {
            let ctrlMain = pageObject["${pageNameMain}"].ctrlMain;

            // 단속 ID 가 없다면.. return
            let crdnId = ctrlMain.getValue("CRDN_ID");                          // 단속 ID
            if (!crdnId) return;

            let params = {
                  callPurpose: "refresh"
                , sggCd: ctrlMain.getValue("SGG_CD")
                , taskSeCd: ctrlMain.getValue("TASK_SE_CD")
                , crdnId: ctrlMain.getValue("CRDN_ID")
                , delYn: "N"
            };

            ajax.get({
                  url: wctx.url("/sprt/sprt02/070/info.do")
                , headers: { Accept: "application/json; charset=utf-8" }        // json
                , data: params || {}
                , success: (resp) => {
                    // 초기화
                    $P.findn("frmEditRcvmt").reset();                           // 수납 화면
                    $P.ctrlRcvmt.dataset.clear();                               // 수납 Dataset

                    // sprt02010-main 단속 정보
                    ctrlMain.setData([resp.totalInfo]);

                    // 수납 정보
                    $P.ctrlRcvmt.setData(resp.rcvmts);
                }
            });
        }

        /**************************************************************************
         * 버튼 clickEvent
         **************************************************************************/
        // 수기 수납 등록
        $P.fnCreateRcvmt = (btnTitle) => {
            // 단속 ID 가 없다면.. return
            let ctrlMain = pageObject["${pageNameMain}"].ctrlMain;              // sprt02010 control
            let crdnId = ctrlMain.getValue("CRDN_ID");                          // 단속 ID
            if (!crdnId) return;

            let params = {
                  callPurpose: "create"
                , btnTitle: btnTitle
                , sggCd: ctrlMain.getValue("SGG_CD")                            // 시군구 코드
                , taskSeCd: ctrlMain.getValue("TASK_SE_CD")                     // 업무 구분 코드
                , crdnId: ctrlMain.getValue("CRDN_ID")                          // 단속 ID
                , delYn: "N"
            };

            $P.ctrlRcvmt.getInfo(params);
        }

        // 수기 수납 취소
        $P.fnUpdateRcvmtRtrcn = (btnTitle) => {
            // 수납 ID 가 없다면.. return
            let rcvmtId = $P.ctrlRcvmt.getValue("RCVMT_ID");                    // 수납 ID
            if (!rcvmtId) return;

            // 수납 취소 메세지 확인
            dialog.alert({
                  content: btnTitle + " 작업 진행시 과오납이 발생합니다."
                        + "<br>" + "계속 진행하시겠습니까?"
                , onOK: async() => {
                    // 삭제 사유 입력
                    fetch(wctx.url("/resources/html/inputRsnDialog.html"))
                        .then(function(resp) { return resp.text(); })
                        .then(function(template) {
                            dialog.open({
                                  id: "inputDelRsnDialog"
                                , title: btnTitle
                                , size: "lg"
                                , content: template
                                , init: () => { AppSupport.setDialogZindex(); }
                                , onOK: () => {
                                    $P.callbackRsn({
                                          btnTitle: btnTitle                    // 버튼 title
                                        , reason: $("#reason").val()            // 삭제 사유
                                    });
                                }
                            });
                        });
                }
            });
        }

        // 수기 수납 삭제
        $P.fnRemoveRcvmt = (btnTitle) => {
        	// 수납 ID 가 없다면.. return
            let rcvmtId = $P.ctrlRcvmt.getValue("RCVMT_ID");                    // 수납 ID
            if (!rcvmtId) return;

            // 수납 입력 구분이 03(수기) 일때만 삭제 가능
            let rcvmtInptSeCd = $P.ctrlRcvmt.getValue("RCVMT_INPT_SE_CD");
            let rcvmtInptSeNm = $P.ctrlRcvmt.getValue("RCVMT_INPT_SE_NM");
            if (rcvmtInptSeCd != "03")
            	return dialog.alert({
                      content: "[" + btnTitle + "]" + " 작업은 수납입력 구분이 '수기' 자료만 처리 가능합니다."
                            + "<br>" + "수납 입력 구분 : " + rcvmtInptSeNm
                            + "<br><br>" + "[" + btnTitle + "]" + " 실행이 취소되었습니다."
                    , init: () => { AppSupport.setDialogZindex(); }
                    , onOK: () => { }
                });

            // 삭제 메세지 확인
            dialog.alert({
                  content: "선택하신 " + $P.ctrlRcvmt.prefixName + " 정보를 삭제하시겠습니까?"
                , onOK: () => {
                    // 삭제 사유 입력
                    fetch(wctx.url("/resources/html/inputRsnDialog.html"))
                        .then(function(resp) { return resp.text(); })
                        .then(function(template) {
                            dialog.open({
                                  id: "inputDelRsnDialog"
                                , title: btnTitle
                                , size: "lg"
                                , content: template
                                , init: () => { AppSupport.setDialogZindex(); }
                                , onOK: () => {
                                    $P.callbackRsn({
                                          btnTitle: btnTitle                    // 버튼 title
                                        , reason: $("#reason").val()            // 삭제 사유
                                    });
                                }
                            });
                        });
                }
            });
        }

        /**************************************************************************
         * 초기 셋팅
         **************************************************************************/
        // 이벤트 설정
        $P.setEvent = () => {
            // 업무 버튼 이벤트
            $P.$findn("btnCreateRcvmt").on("click", function() {
                $P.fnCreateRcvmt($P.$findn("btnCreateRcvmt").attr("title"));            // 수납 등록
            });
            $P.$findn("btnUpdateRcvmtRtrc").on("click", function() {
                $P.fnUpdateRcvmtRtrcn($P.$findn("btnUpdateRcvmtRtrc").attr("title"));   // 수납 취소
            });
            $P.$findn("btnRemoveRcvmt").on("click", function() {
                $P.fnRemoveRcvmt($P.$findn("btnRemoveRcvmt").attr("title"));            // 수납 삭제
            });

            // DataTables width 변경 조정
            Componentization.fnMakeResizableTable($P.findn("tableRspnsRcvmt"));
        }

        // 초기 화면 설정
        $P.fnReset = () => {
        	// 초기화
            $P.findn("frmEditRcvmt").reset();                                   // 수납 화면 초기화
            $P.ctrlRcvmt.dataset.clear();                                       // 수납 Dataset 초기화

            // 화면 호출(callPurpose)이 view라면 버튼 비활성화 disabled = true
            if (pageObject['${pageNameMain}'].callPurpose != "view") {
                // 주정차위반, 전용차로위반과태료 외에는 수납 등록, 취소, 삭제 기능이 없어야 한다.
                let taskSeCd = pageObject["${pageNameMain}"].ctrlMain.getValue("TASK_SE_CD");
                if ("BPV,PVS,RVS".indexOf("taskSeCd") != -1) {
                    $P.$findn("btnCreateRcvmt").prop("disabled", false);
                    $P.$findn("btnUpdateRcvmtRtrc").prop("disabled", false);
                    $P.$findn("btnRemoveRcvmt").prop("disabled", false);
                } else {
                    $P.$findn("btnCreateLevy").prop("disabled", true);
                    $P.$findn("btnUpdateRcvmtRtrc").prop("disabled", true);
                    $P.$findn("btnRemoveRcvmt").prop("disabled", true);
                }
            }
        }

        /**************************************************************************
         * 최초 실행 함수
         **************************************************************************/
        // 1. 이벤트 설정
        $P.setEvent();

        // 2. 초기 화면 설정
        $P.fnReset();

        // 3. Dataset 설정
        $P.ctrlRcvmt.setData(${rcvmts});
    });

</script>
