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

<c:set var="pageKorName" scope="request">출력대상-교부청구서,채권신고서</c:set>

<div class="d-flex flex-row justify-content-evenly" data-doctx="${pageName}">
	<div class="card p-3">
		<div class="row mb-3 justify-content-start">
			<div class="col-md-12">
				<div class="float-start">
					<button type="button" name="btnPrintRequestForDelivery" class="btn btn-info">교부청구서출력</button>
					<button type="button" name="btnPrintReportOnClaims" class="btn btn-info">채권신고서출력</button>
				</div>
			</div>
		</div>

		<div class="card-datatable text-nowrap mb-3">
			<div class="dataTables_wrapper dt-bootstrap5 no-footer">
				<div class="table-responsive ox-scroll oy-scroll h-px-300">
					<table name="table" class="table-layout-fixed dataTable datatables-ajax table table-bordered no-footer">
						<thead class="sticky-thead" >
							<tr name="theadTr">
								<th style="width:120px">시군구명</th>
								<th style="width:180px">과태료명</th>
								<th style="width:120px">대체차량번호</th>
								<th style="width:120px">차량번호</th>
								<th style="width:120px">단속구분</th>
								<th style="width:200px">단속일시</th>
								<th style="width:200px">단속장소</th>
								<th style="width:120px">고지번호</th>
								<th style="width:120px">수납일자</th>
								<th style="width:120px">처리상태</th>
								<th style="width:120px">수납금액</th>
								<th style="width:120px">잔액</th>
								<th style="width:120px">성명</th>
								<th style="width:400px">주소</th>
								<th style="width:400px">번지</th>
							</tr>
						</thead>
						<tbody name="tbody">
						</tbody>
						<template is="curly-brackets" name="found">
							<tr data-key="CRDN_ID" onclick="pageObject['${pageName}'].clickGrid(this);">
								<td>SGG_NM</td>
								<td>TASK_SE_NM</td>
								<td>RPM_SZR_VHRNO</td>
								<td>VHRNO</td>
								<td>CRDN_SE_NM</td>
								<td>CRDN_YMD_TM</td>
								<td>CRDN_PLC</td>
								<td>GOJI_NO</td>
								<td>RCVMT_YMD</td>
								<td>CRDN_STTS_NM</td>
								<td>RCVMT_AMT</td>
								<td>LAST_AMT</td>
								<td>RTPYR_NM</td>
								<td>RTPYR_ADDR</td>
								<td>RTPYR_DTL_ADDR</td>
							</tr>
						</template>
					</table>
				</div>
			</div>
		</div>

		<form name="frmEdit">

			<div class="row g-1">
				<div class="col-md-4">
					<label is="name-label" for="docNo"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
						문서번호
					</label>
					<input type="text" is="id-input" name="docNo"
						class="form-control" maxlength="100" required />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="caseNo"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
						사건번호
					</label>
					<input type="text" is="id-input" name="caseNo"
						class="form-control" maxlength="100" required />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="receiver"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
						수신처 지정
					</label>
					<input type="text" is="id-input" name="receiver"
						class="form-control" maxlength="100" required />
				</div>
				<div class="col-md-6">
					<label is="name-label" for="rtpyrNm"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					납부자명
					</label>
					<input type="text" is="id-input" name="rtpyrNm"
						class="form-control" data-map="RTPYR_NM" maxlength="100" />
				</div>
				<div class="col-md-6">
					<label is="name-label" for="rtpyrNo"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					납부자번호
					</label>
					<input type="text" is="id-input" name="rtpyrNo"
						class="form-control privacy" data-map="RTPYR_NO" maxlength="100" />
					<input type="text" is="id-input" name="mask-rtpyrNo"
						class="form-control privacy-mask" disabled value="******"/>
				</div>
				<div class="col-md-12">
					<label is="name-label" for="vhrno"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					물건
					</label>
					<input type="text" is="id-input" name="vhrno"
						class="form-control w-px-500" data-map="VHRNO" maxlength="100" />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="rtpyrFullAddr"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					주소(소재지)
					</label>
					<input type="text" is="id-input" name="rtpyrFullAddr"
						class="form-control w-px-500" data-map="RTPYR_FULL_ADDR" maxlength="300" />
				</div>
			</div>
		</form>

	</div>

	<template name="checkActnoTemplate">
		<form name="frm">
			<div class="card">
				<div class="row g-1">
					<div class="col-md-12">
						<label is="name-label" for="dtbnBankNm" data-ref-doctx="${pageName}"
							class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">은행형</label>
						<input type="text" is="id-input" name="dtbnBankNm" class="form-control"
						data-ref-doctx="${pageName}" />
					</div>
					<div class="col-md-12">
						<label is="name-label" for="dtbnActno" data-ref-doctx="${pageName}"
							class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">계좌번호</label>
						<input type="text" is="id-input" name="dtbnActno" class="form-control"
						data-ref-doctx="${pageName}" />
					</div>
				</div>
			</div>
			<div>
				<span class="container-page-btn">
					<span class="container-window-btn-right">
						<button type="button" class="btn btn-primary" name="btnChangeActno"
						title="변경">
						변경
						</button>
						<button type="button" class="btn btn-primary" name="btnConfirmActno"
						title="확인">
						확인
						</button>
					</span>
				</span>
			</div>
		</form>
	</template>
</div>



<script>

pageObject["${pageName}"] = newDoctxFinder("${pageName}");
pageObject["${pageName}"].provided = {};

pageObject.childReq = [];
pageObject.childReq.push({
	getInfo : function(){ return null; },
});

$(document).ready(function(){

	var $P = pageObject["${pageName}"];

	$P.crdnIds = ${crdnIds};

	if(pageObject.parentRes.length > 0){
		$P.provided = pageObject.parentRes.pop();
	} else {
		$P.provided = pageObject.childReq.pop();
	}

	//그리드클릭
	$P.clickGrid = (element) => {
		var key = element.dataset.key;

		$P.$findn("tbody").setCurrentRow(key);

		var info = $P.provided.getInfo(key);
		var formFields = new FimsFormFields($P.selectorn("frmEdit"));
		formFields.set(null,info);
	}

	//교부청구서 파일 생성
	$P.fnMakeRequestForDeliveryFile = () => {

		if(!AppSupport.customValidate($P.$findn("frmEdit").find("input"))) return;

		$P.checkActno();
	}

	//계좌번호확인
	$P.checkActno = () => {

		ajax.post({
			url : wctx.url("/user/stngInfo.do"),
			data : { type : "dept" },
			success : (resp) => {

				let dialogName = "checkActnoDialog";
				let dialogId = dialogName+"-"+uuid();

				dialog.open({
					id : dialogId,
					title : "계좌번호 확인",
					content : $P.findn("checkActnoTemplate").innerHTML,
					size : "md",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

						let refDlgId = $P.refDlgId(dialogName);

						$("#"+refDlgId).find("[name='btnChangeActno']").on("click", function(){
							$P.checkActnoCallback(true,refDlgId);
						});
						$("#"+refDlgId).find("[name='btnConfirmActno']").on("click", function(){ $
							$P.checkActnoCallback(false,refDlgId);
						});

						if(resp.stngInfo != null){
							$("#"+refDlgId).find("[name='dtbnBankNm']").val(resp.stngInfo.DTBN_BANK_NM);
							$("#"+refDlgId).find("[name='dtbnActno']").val(resp.stngInfo.DTBN_ACTNO);
						}
					},
					onClose : () => {}
				});

			}
		});
	}

	//계좌번호확인callback
	$P.checkActnoCallback = (change, callbackDialogId) => {

		var url = wctx.url("/sprt/sprt01/120/makeRequestForDeliveryFileFromHwpFormat.do");
		var formFields = new FimsFormFields($P.selectorn("frmEdit"));
		var globalVariable = formFields.get();

		var changed = false;
		if(change){

			var dtbnBankNm = $("#"+callbackDialogId).find("[name='dtbnBankNm']").val();
			var dtbnActno = $("#"+callbackDialogId).find("[name='dtbnActno']").val();

			$.ajax({
				type: 'GET',
				url: wctx.url('/user/updateDtbnActno.do'),
				data: {
					"dtbnBankNm" : dtbnBankNm,
					"dtbnActno" : dtbnActno
				},
				async: false
			}).done(function(data, textStatus, xhr) {
				if(data.saved){
					changed = true;
				} else {
					alert("교부 계좌 변경에 실패하였습니다.");
				}
			});
		}

		if(!change || changed){
			dialog.close(callbackDialogId);
			$P.fnMakeFile(url, globalVariable);
		}

	}

	//채권신고서 파일 생성
	$P.fnMakeReportOnClaimsFile = () => {

		if(!AppSupport.customValidate($P.$findn("frmEdit").find("input"))) return;

		var url = wctx.url("/sprt/sprt01/120/makeReportOnClaimsFileFromHwpFormat.do");
		var formFields = new FimsFormFields($P.selectorn("frmEdit"));
		var globalVariable = formFields.get();

		$P.fnMakeFile(url, globalVariable);
	}

	$P.fnMakeFile = (url, globalVariable) => {
		var globalVariableInfo = JSON.stringify(globalVariable);

		var parameter = toQuery({
			crdnIds : $P.crdnIds.join(","),
			globalVariableInfo : globalVariableInfo
		});

		document.location.href = url + "?" + parameter;
	}

	//버튼이벤트
	$P.$findn("btnPrintRequestForDelivery").on("click", () => $P.fnMakeRequestForDeliveryFile() );
	$P.$findn("btnPrintReportOnClaims").on("click", () => $P.fnMakeReportOnClaimsFile() );

	//첫번째 줄 클릭
	$P.$findn("tbody").find("tr:eq(0)").click();

	//보안모드
    fn_securityModeToggle($("#securityMode--top").is(":checked"));
});

</script>