<%--
  Class Name : RefundDetail.jsp
  Description : Refund 상세 페이지
  Modification Information

      수정일         수정자                   수정내용
    -------    --------    ---------------------------
     2021.06.10    이준호          최초 생성

    author   : 이준호
    since    : 2021.06.10

--%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="ec" uri="/WEB-INF/tld/ecnet_tld.tld"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<title>환불요청 상세</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<script type="text/javascript" src="<c:url value='/js/EgovCalPopup.js'/>"></script>
<script type="text/javaScript" language="javascript">
$(document).ready(function(){
	$(".amount").each(function(value){
		if(!value){
			$(".amount").append("원");
		}
	});
	
	$("#refundLoss").focusout(function() {
		var refundMoneyB = $("#refundMoneyB").val();
		var refundMoneyC = $("#refundMoneyC").val();
		var refundLoss = $("#refundLoss").val();
		var refundMoneyE =refundMoneyB - refundMoneyC - refundLoss;
		
		refundMoneyE = refundMoneyE.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");// 정규식을 이용 금액 단위(,) 추가
		$("#inputRefundMoneyE").text(refundMoneyE+" 원");
	});
	
	
	var refundStatus = $("#refundStatus").val();
	if(refundStatus == "3"){
// 		$("#trnsfCash").attr("disabled",true);
// 		$("#refundPoint").attr("disabled",true);
// 		$("#refundLoss").attr("disabled",true);
// 		$("input[name='refundCheck']").attr('disabled',true);
	}
	
	refundMoneyCal(); //환불정산
	
});

//환불정산 기능
function refundMoneyCal(){
	
	var refundMoneyA = $("#refundMoneyA").val();
	
	var refundMoneyB = Math.round(refundMoneyA * 1.1);
	$("#refundMoneyB").val(refundMoneyB);
	
	var refundMoneyC = Math.round(refundMoneyB * 0.1);
	$("#refundMoneyC").val(refundMoneyC);
	
	var refundLoss = $("#refundLoss").val();
	refundLoss = Math.round(refundLoss * 0.1);
	
	var refundMoneyE = Number(refundMoneyB) - Number(refundMoneyC) - Number(refundLoss);
	
	refundMoneyB = refundMoneyB.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
	$("#refundMoneyBTxt").text(refundMoneyB+" 원");
	
	refundMoneyC = refundMoneyC.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
	$("#refundMoneyCTxt").text(refundMoneyC+" 원");
	
	refundMoneyE = refundMoneyE.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");// 정규식을 이용 금액 단위(,) 추가
	$("#inputRefundMoneyE").text(refundMoneyE+" 원");
	
	refundLoss = refundLoss.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
	$("#refundLoss").val(refundLoss);
	
	
	var refundPoint = $("#refundPoint").val();
	refundPoint = refundPoint.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
	$("#refundPoint").val(refundPoint);
	
	
}

//회원상세 페이지 팝업
function fnSelectMber(mberId) {
	document.modiForm.mberId.value = mberId;
	window.open("about:blank", 'popupSelectMber', 'width=900, height=1800, top=100, left=100, fullscreen=no, menubar=no, status=no, toolbar=no, titlebar=yes, location=no, scrollbar=no');
	document.modiForm.action = "<c:url value='/uss/umt/user/EgovGnrlselectedUserView.do'/>";
	document.modiForm.target = "popupSelectMber";
	document.modiForm.submit();
}

// 환불 리스트 이동
function golist(pageNo){
	var searchForm = document.searchForm;
	searchForm.action = "<c:url value='/uss/ion/pay/RefundList.do'/>";
	searchForm.submit();
}

//메모 저장
function fn_memoSave(){
	var url = "<c:url value='/uss/ion/pay/updateRefundMemoAjax.do'/>";
	var data = new FormData(document.writeForm);
	$.ajax({
		type: "POST"
		, url: url
		, data: data
		, dataType:'json'
		, async: false
		, processData: false
		, contentType: false
		, cache: false
		, success: function (returnData, status) {
			if(status == 'success'){
				alert("저장 되었습니다.");
			} else if(status== 'fail'){
				alert("저장에 실패하였습니다.");
			}
		}
		,error: function (e) { alert("저장에 실패하였습니다."); console.log("ERROR : ", e); }
	});
}

//환불 내용 저장
function RefundAjax(type){
	
	
	var radioVal = $('input[name="refundCheck"]:checked').val();
	if(!radioVal){
		alert("처리상태를 선택해주세요");
		return;
	}
	
	var url = "";
	if(type == "I"){
		if(radioVal == "4"){	/*	처리불가	*/
			url = "/uss/ion/pay/updateCancelRefundAjax.do"
		}else if(radioVal == "3"){	/*	처리완료	*/
			url = "/uss/ion/pay/updateCompleteRefundAjax.do"
			
			var trnsfCash = $("#trnsfCash").val();
			if(trnsfCash == null || trnsfCash == "" || trnsfCash == "0" || trnsfCash == "0.0"){
				alert("송금 금액을 입력해 주세요");
				 $('#trnsfCash').focus();
				return;
			}
		}
	}else if(type == "U"){
		url = "/uss/ion/pay/updateRestRefundAjax.do"
		
		$("#refundStatus").val(radioVal);
		if(radioVal == "4"){ // 처리불가
			// 처리불가 상태일 경우 손해배상액, 환불포인트, 송금액 0원으로 
			$("#refundPoint").val(0);	// 포인트 0원
			$("#refundLoss").val(0);	// 손해배상액 0원
			$("#trnsfCash").val(0);		// 송금액 0원
			
		}else if(radioVal == "3"){ // 처리완료
			
			var refundPoint = $("#refundPoint").val();
			refundPoint = refundPoint.toString().replace(/[^\d]+/g, "");
			$("#refundPoint").val(refundPoint);
			
			var refundLoss = $("#refundLoss").val();
			refundLoss = refundLoss.toString().replace(/[^\d]+/g, "");
			$("#refundLoss").val(refundLoss);
			
			var trnsfCash = $("#trnsfCash").val();
			trnsfCash = trnsfCash.toString().replace(/[^\d]+/g, "");
			$("#trnsfCash").val(trnsfCash);
		}
	}
	

	if(!confirm("저장하시겠습니까?")){
		return;
	}
	
	var data = new FormData(document.writeForm);
	_fileForm2.forEach(function(obj, idx) {
		if (obj) data.append("file"+idx, obj.fileObj);
	});
	
	$.ajax({
		type: "POST"
		, enctype: 'multipart/form-data'
		, url: url
		, data: data
		, dataType:'json'
		, async: false
		, processData: false
		, contentType: false
		, cache: false
		, success: function (returnData, status) {
			if(returnData.status == 'success'){
				alert("저장 되었습니다.");
				location.reload(true);
			} else if(returnData.status== 'fail'){
				alert("저장에 실패하였습니다. !!");
			} else if(returnData.status== 'moreThanUserMoney'){
				alert(returnData.msg);
			} else if(returnData.status== 'moreThanUserPoint'){
				alert(returnData.msg);
			} 
		}
		,error: function (e) { alert("저장에 실패하였습니다."); console.log("ERROR : ", e); }
	});
}

</script>
<style type="text/css">
.pageCont .tbType1 thead tr th {line-height:1.3em;vertical-align:middle;border-left:1px solid #d5d5d5;background:#f7f7f7;}
.pageCont .tbType1 thead tr th:first-child {border-left:0 none;}
.pageCont .tbType1 tbody tr td {overflow:inherit;text-overflow:inherit;white-space:normal;text-align:center;word-break:break-all;padding-left:10px;padding-right:10px;border-left:1px solid #d5d5d5;}
.pageCont .tbType1 tbody tr td:first-child {border-left:0 none;}
.pageCont .tbType1 tbody tr td table {width:100%;}
.pageCont .tbType1 tbody tr td table tbody tr {border:0 none;}
.pageCont .tbType1 tbody tr td input[type=number] {width:calc(100% - 20px);box-sizing:border-box;}
.pageCont .tbType1 tbody tr td input[type=text] {width:calc(100% - 20px);box-sizing:border-box;}
.pageCont .tbType1 tbody tr td .refund_cehck {display:inline-block;line-height:40px;vertical-align:middle;}
.pageCont .tbType1 tbody tr td .refund_cehck input[type=radio]+label {margin-top:2px;}
.pageCont .tbType1 tbody tr td .refund_cehck input[type=radio]+label+label {display:inline-block;padding:0 0 0 4px;}
.pageCont .tbType1 tbody tr td .refund_confirm {display:inline-block;margin:2px 0 0;vertical-align:middle;}
.pageCont .tbType1 tbody tr td .refund_confirm li {display:none;}
.pageCont .tbType1 tbody tr td .refund_confirm li select {width:210px;margin:0 8px 0 0;}
.pageCont .fileWrap {width:100%;}
</style>
</head>
<body>
<form name="writeForm" method="post">
	<input type="hidden" name="refundId" id="refundId" value="<c:out value='${refundVO.refundId}'/>">
	<input type="hidden" name="pageIndex" value="<c:out value='${searchVO.pageIndex}'/>"/>
	<input type="hidden" name="searchSortCnd" value="<c:out value="${searchVO.searchSortCnd}" />" />
	<input type="hidden" name="searchSortOrd" value="<c:out value="${searchVO.searchSortOrd}" />" />
	<input type="hidden" name="searchCondition" value="<c:out value="${searchVO.searchCondition}" />" />
	<input type="hidden" name=searchKeyword value="<c:out value="${searchVO.searchKeyword}" />" />
	<input type="hidden" name="pageUnit" value="<c:out value="${searchVO.pageUnit}" />" />
	<input type="hideen" name="mberId" value="<c:out value='${refundVO.mberId}'/>"/>
	
	<!-- 드래그앤 드롭 파라미터 -->
	<input type="hidden" name="limitcount" value="1" /><!-- 최대 첨부파일 갯수 -->
	
	<div class="contWrap">
		<div class="pageTitle">
			<div class="pageIcon"><img src="/pb/img/pageTitIcon4.png" alt=""></div>
			<h2 class="titType1 c_222222 fwBold">환불요청 상세</h2>
			<p class="tType6 c_999999">환불요청 상세 페이지 입니다.</p>
		</div>
		<div class="pageCont">
			<div class="pageTitle02 type01">
				<h3>인적사항</h3>
			</div>
			<table class="tbType1">
				<colgroup>
					<col style="width:16%;" />
					<col style="width:auto;" />
					<col style="width:16%;" />
					<col style="width:16%;" />
					<col style="width:auto;" />
				</colgroup>
				<thead>
					<tr>
						<th>아이디</th>
						<th>성명</th>
						<th>일반연락처</th>
						<th>환불연락처</th>
						<th>이메일</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td onclick="javascript:fnSelectMber('<c:out value="${refundVO.mberId}"/>'); return false;" style="cursor:pointer;">
							<c:out value='${refundVO.mberId}'/>
						</td>
						<td>
							<c:out value='${refundVO.mberNm}'/>
						</td>
						<td>
							<c:out value='${mberInfoVO.mberPhoneNo}'/>
						</td>
						<td>
							<c:out value='${refundVO.dpsitPhoneNo}'/>
						</td>
						<td>
							<c:out value='${mberInfoVO.mberEmailAdres}'/>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="pageTitle02">
				<h3>환불신청 내역</h3>
				<p>(부가세 별도)</p>
			</div>
			<table class="tbType1">
				<colgroup>
					<col style="width:16%;" />
					<col style="width:auto;" />
					<col style="width:13%;" />
					<col style="width:13%;" />
					<col style="width:auto;" />
					<col style="width:auto;" />
				</colgroup>
				<thead>
					<tr>
						<th>신청일시</th>
						<th>환불사유</th>
						<th>보유캐시</th>
						<th>보유포인트</th>
						<th>첨부파일(통장사본)</th>
						<th>첨부파일(증빙서류)</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
							<c:out value='${refundVO.frstRegisterPnttm}'/>
						</td>
						<td>
						<c:choose>
							<c:when test="${refundVO.refundReason eq '999'}">
								[환불사유 직접 입력]
								<br/>
								${refundVO.refundReasonEtc}
							</c:when>
							<c:otherwise>
								<ec:code code="${refundVO.refundReason}" codeId="ITN050"/>
							</c:otherwise>
						</c:choose>
						</td>
						<td class="amount">
							<fmt:formatNumber value="${mberInfoVO.mberMoney}" type="number" />
						</td>
						<td>
							<fmt:formatNumber value="${mberInfoVO.mberPoint}" type="number" />
						</td>
						<td>
							<c:if test="${refundVO.bankAtchFileId ne ''}">
								<c:import url="/cmm/fms/selectBBSFileInfs.do" charEncoding="utf-8">
									<c:param name="param_atchFileId" value="${refundVO.bankAtchFileId}" />
								</c:import>	
							</c:if>
						</td>
						<td>
							<c:if test="${refundVO.docuAtchFileId ne ''}">
								<c:import url="/cmm/fms/selectBBSFileInfs.do" charEncoding="utf-8">
									<c:param name="param_atchFileId" value="${refundVO.docuAtchFileId}" />
								</c:import>	
							</c:if>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="pageTitle02">
				<h3>환불정산 내역</h3>
				<p>(부가세 포함)</p>
			</div>
			<table class="tbType1">
				<colgroup>
					<col style="width:auto;" />
				</colgroup>
				<thead>
					<tr>
						<th>환불요청액(A)<br>(VAT 별도)</th>
						<th>환불요청액(B=A*1.1)<br>(VAT 포함)</th>
						<th>환불수수료<br>(C=B*10%)</th>
						<th>손해배상액<br>(D, 2배 이내)</th>
						<th>최종환불액(E=B-C-D)</th>
						<th>환불포인트</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="amount">
							<c:set value="${refundVO.refundMoney}" var="refundMoneyA" />
							<fmt:formatNumber value="${refundMoneyA}" type="number"/>
							<input type="hidden" id="refundMoneyA" value="${refundMoneyA}">
							<input type="hidden" id="refundMoneyB">
							<input type="hidden" id="refundMoneyC">
							<input type="hidden" id="refundCash" name="refundCash" value="${refundMoneyA}"/>
						</td>
						<td class="amount" id="refundMoneyBTxt">
						</td>
						<td class="amount" id="refundMoneyCTxt">
						</td>
						<td class="amount">
<%-- 							<fmt:formatNumber value="${refundVO.refundLoss}" type="text" pattern="#,###" var="refundLoss_1"/> --%>
							<input type="text" id="refundLoss" name="refundLoss" value="${refundVO.refundLoss}"
							maxlength="20" oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');"
							/>
						</td>
						<td class="amount" id="inputRefundMoneyE">
						</td>
						<td>
							<input type="hidden" name="beforePoint" value="${refundVO.refundPoint}">
							<input type="text" id="refundPoint" name="refundPoint" value="${refundVO.refundPoint}" 
							maxlength="20" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"
							/>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="pageTitle02">
				<h3>관리자</h3>
			</div>
			<table class="tbType1">
				<colgroup>
					<col style="width:13%;" />
					<col style="width:16%;" />
					<col style="width:16%;" />
					<col style="width:auto;" />
					<col style="width:22%;" />
				</colgroup>
				<thead>
					<tr>
						<th>처리자</th>
						<th>처리일시</th>
						<th>송금액</th>
						<th>첨부파일(관리자)</th>
						<th>처리상태</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
						<c:if test="${adminInfo.refundHandleId ne null}">
							<c:out value='${adminInfo.refundHandleId}'/>
							(<c:out value='${adminInfo.refundHandleName}'/>)
						</c:if>
						</td>
						<td>
							<c:out value='${refundVO.refundHandlePnttm}'/>
						</td>
						<td>
							<fmt:formatNumber value="${refundVO.trnsfCash}" type="text" pattern="#,###" var="trnsfCash_1"/>
							<input type="text" id="trnsfCash" name="trnsfCash" value="${trnsfCash_1}"
							maxlength="20" oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');"
							/> 원
						</td>
						<td id="admAtchFile">
							<c:if test="${refundVO.admAtchFileId ne ''}">
								<c:import url="/cmm/fms/selectBBSFileInfs.do" charEncoding="utf-8">
									<c:param name="param_atchFileId" value="${refundVO.admAtchFileId}" />
								</c:import>	
							</c:if>
						</td>
						<td>
							<div class="refund_cehck">
								<input type="hidden" name="beforeRefundStatus" id="beforeRefundStatus" value="${refundVO.refundStatus}">
								<input type="hidden" name="refundStatus" id="refundStatus" value="${refundVO.refundStatus}">
								<input type="radio" name="refundCheck" id="refundCheckF" value="4" <c:if test="${refundVO.refundStatus eq '4'}">checked="checked"</c:if>/><label for="refundCheckF">처리불가</label>
								<input type="radio" name="refundCheck" id="refundCheckT" value="3" <c:if test="${refundVO.refundStatus eq '3'}">checked="checked"</c:if>/><label for="refundCheckT">처리완료</label>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			
			<table class="tbType2 tbType2_refund">
				<colgroup>
					<col style="width: 20%">
					<col style="width: 80%">
				</colgroup>
				<tbody>
					<!-- 메모영역 -->
					<tr>
						<th><span>메모</span></th>
						<td>
							<textarea name="refundMemo" id="refundMemo" class="refund_memo">${refundVO.refundMemo}</textarea>
							<input type="button" class="btnType1 bg_88888" value="메모저장" onclick="fn_memoSave(); return false;">
						</td>
					</tr>
				</tbody>
			</table>
			
			<c:if test="${refundVO.refundStatus eq '1'}">
			
			<table class="tbType2" style="margin:30px 0 0;">
				<colgroup>
					<col style="width: 20%">
					<col style="width: 80%">
				</colgroup>
				<tbody>
					<tr>
						<th>
							<span>관리자 파일 첨부</span>
						</th>
						<td class="upload_area">
							<div class="file_upload_box no_img_box fileWrap">
								<table>	
									<colgroup>
										<col style="width: 60%">
										<col style="width: 10%">
										<col style="width: 20%">
										<col style="width: 10%">
									</colgroup>
									<thead>
										<tr>
										<th>파일명</th>
										<th>크기</th>
										<th>등록일시</th>
										<th>삭제</th>
										</tr>
									</thead>
								</table>
							</div>
							<div class="fileWrap fileAfter file_list_div">
								<table>
									<colgroup>
										<col style="width: 60%">
										<col style="width: 10%">
										<col style="width: 20%">
										<col style="width: 10%">
									</colgroup>
									<thead>
										<tr>
											<th>파일명</th>
											<th>크기</th>
											<th>등록일시</th>
											<th>삭제</th>
										</tr>
									</thead>
									<tbody id="tbody_fiielist">
										<c:forEach var="fileList" items="${resultFileList}" varStatus="status">
		                        			<tr class="item_${fileList.atchFileId}_${fileList.fileSn} uploaded_obj">
												<input type="hidden" name="fileSize" class="item_file_size" value="${fileList.fileMg}">
												<td class="file_name">
													<img src="/direct/img/upload_hwp_img.png" alt="" />
													<span class="file_name_text">${fileList.orignlFileNm}</span>
												</td>
												<td>
													<span class="file_size_text" value="<c:out value="${fileList.fileMg}"/>"></span>
												</td>
												<td>
													<c:out value="${fileList.creatDt}"/>
												</td>
												<td>
													<input type="button" class="delBtn" onclick="delAtchFile('${fileList.atchFileId}', '${fileList.fileSn}'); return false;">
												</td>
											</tr>
										</c:forEach>
									</tbody>
								</table>
							</div>
							<div class="fileInfo file_list_div">
								<ul class="inline">
									<li>
										<p>최대 <span class="c_e40000 fwBold limitcount_li">1</span>개 ｜ <span class="c_e40000 fwBold upload_number">50MB</span>제한</p>
									</li>
									<li>
										<p><span class="c_456ded fwBold totalfileCount">1</span>개 ｜ <span class="c_456ded fwBold totalfileSize">72.01KB</span></p>
									</li>
								</ul>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			
			</c:if>
			<div class="btnWrap">
				<input type="button" class="btnType1 bg_888888" value="목록" onclick="golist('1'); return false;">
				<c:choose>
					<c:when test="${refundVO.refundStatus eq '1' || refundVO.refundStatus eq '2'}">
						<input type="button" class="btnType1 bg_888888" value="저장" onclick="RefundAjax('I'); return false;">
					</c:when>
					<c:when test="${refundVO.refundStatus ne '1' || refundVO.refundStatus ne '2'}">
						<input type="button" class="btnType1 bg_888888" value="수정 저장" onclick="RefundAjax('U'); return false;"/>
					</c:when>
				</c:choose>
			</div>
			
			<span id="PayListLoad"/>
	 	</div>
	</div>
</form>
	
<form name="searchForm" id="searchForm" method="post" action="<c:out value='/refund/refund/RefundList.do'/>">
	<input type="hidden" name="refundId" value=""/>
	<input type="hidden" name="pageIndex" value="<c:out value='${searchVO.pageIndex}'/>"/>
	<input type="hidden" name="searchSortCnd" value="<c:out value="${searchVO.searchSortCnd}" />" />
	<input type="hidden" name="searchSortOrd" value="<c:out value="${searchVO.searchSortOrd}" />" />
	<input type="hidden" name="searchCondition" value="<c:out value="${searchVO.searchCondition}" />" />
	<input type="hidden" name="searchKeyword" value="<c:out value="${searchVO.searchKeyword}" />" />
	<input type="hidden" name="pageUnit" value="<c:out value="${searchVO.pageUnit}" />" />
</form>
<form name="payCancelForm" id="payCancelForm" method="post" action="">
	<input type="hidden" name="refundId" value="<c:out value='${refundVO.refundId}'/>"/>
	<input type="hidden" name="moid" value=""/>
	<input type="hidden" name="payCancleDiv" value=""/>
</form>

<form name="modiForm" id="modiForm" method="post">
	<input name="mberId" type="hidden" />
</form>

</body>
</html>
