<%@ 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="btnExcel" class="btn btn-excel">엑셀</button>
					<button type="button" name="btnPrintCrdnList" class="btn btn-info">단속내역서출력</button>
					<button type="button" name="btnPrintCrdnConfirm" class="btn btn-info">단속확인서출력</button>
					<label>
						<input type="checkbox" name="privateInfoYn" class="form-check-input"/>
						개인정보 비공개(내역서)
					</label>
				</div>
			</div>
		</div>

		<div class="card-datatable text-nowrap">
			<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:200px">주소</th>
								<th style="width:200px">번지</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>


	</div>
</div>

<script>

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

$(document).ready(function(){

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

	$P.crdnIds = ${crdnIds};

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

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

	//단속내역서 파일 생성
	$P.fnMakeCrdnListFile = () => {

		var privateInfoYn = "Y";
		if($P.$findn("privateInfoYn").is(":checked")){
			privateInfoYn = "N";
		}

		var url = wctx.url("/sprt/sprt01/110/makeCrdnListFileFromHwpFormat.do");
		var parameter = toQuery({
			crdnIds : $P.crdnIds.join(","),
			privateInfoYn : privateInfoYn
		});

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

	$P.fnMakeCrdnConfirmFile = () => {
		var url = wctx.url("/sprt/sprt01/110/makeCrdnConfirmFileFromHwpFormat.do");
		var parameter = toQuery({
			crdnIds : $P.crdnIds.join(",")
		});

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

	$P.fnExcelDown = () => {
		var query = {};

		var cellDefs = AppSupport.getCellDefs(
			$P.$findn("theadTr").find("th").not(".dummy-th"),
    		$($P.findn("found").content).find("td").not(".dummy-td")
    	);
		query.cellDefs = cellDefs;

    	query.download = "xls";
    	query.crdnIDs = $P.crdnIds.join(",");
    	var queryStr = toQuery(query);

    	document.location.href = wctx.url("/sprt/sprt01/010/list.do") + "?" + queryStr;
	}

	//버튼 이벤트
	$P.$findn("btnPrintCrdnList").on("click", () => $P.fnMakeCrdnListFile() );
	$P.$findn("btnPrintCrdnConfirm").on("click", () => $P.fnMakeCrdnConfirmFile() );
	$P.$findn("btnExcel").on("click", () => $P.fnExcelDown());

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

</script>