<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : RefundDetailForm.html
 * @desc    : 환불상세팝업
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.16   moon        최초 작성
 *******************************************************************************
 -->
	<div class="modalPopup" data-width="1000" data-height="900">
		<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<h2>환불컨펌 상세</h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupWithdrawDetail')"><i class="fa fa-times"></i></button>
		</div>
		<!-- //TITLE -->

			<form id="withdrawDetailForm" name="withdrawDetailForm" action="#" th:method="post" onSubmit="return false">
				<input type="hidden" name="orgChgReason" readonly/>
				<input type="hidden" name="orgEncloseFee" readonly/>
				
				<table class="frmStyle">
					<colgroup>
						<col style="width:20%;" />
						<col style="width:30%;" />
						<col style="width:20%;" />
						<col style="width:30%;" />
						<col />
					</colgroup>
					<tr>
						<th>회수구분</th>
						<td>
							<span id="wdGbNm"></span>
						</td>
						<th>도착일자</th>
						<td>
							<span id="arriValDt"></span>
						</td>
						
					</tr>
					<tr>
						<th>최종요청사유</th>
						<td>
							<span id="chgReasonNm"></span>
						</td>
						<th>귀책사유<i class="star"></i></th>
						<td>
							<span id="chgReasonText"></span>
						</td>
					</tr>
					<tr>
						<th>동봉비</th>
						<td>
							<input type="text" name="encloseFee" data-valid-type="integer" onchange="fnChangeAmt()" class="w100 aR"/>원
						</td>
						<th>착불비</th>
						<td>
							<input type="text" name="codFee" data-valid-type="integer" onChange="fnChangeAmt()" class="w100 aR"/>원
						</td>
					</tr>
					<tr>
						<th>추가결제비</th>
						<td colspan="3">
							<input type="text" name="addPayCost" data-valid-type="integer" readonly="readonly" onChange="fnChangeAmt()" class="w100 aR"/>원
						</td>
					</tr>
					<tr>
						<th>클레임메모</th>
						<td colspan="3">
							<span id="chgMemo"></span>
						</td>
					</tr>
					<tr>
						<th>회수메모</th>
						<td colspan="3">
							<span id="wdMemo"></span>
						</td>
					</tr>
				</table>
				<div id="divRefundInfo2">
					<h4>환불금액</h4>
					<table class="frmStyle">
						<colgroup>
							<col style="width:20%;"/>
							<col style="width:30%;"/>
							<col style="width:20%;"/>
							<col style="width:30%;"/>
						</colgroup>
						<tbody>
							<tr>
								<th>환불 금액</th>
								<td colspan="3"><span id="refundAmt"></span>원 </td>
							</tr>
						</tbody>
					</table>
				</div>
				<div id="divRefundInfo">
					<h4>환불예정금액</h4>
					<table class="frmStyle">
						<colgroup>
							<col style="width:20%;"/>
							<col style="width:30%;"/>
							<col style="width:20%;"/>
							<col style="width:30%;"/>
						</colgroup>
						<tbody>
							<tr>
								<th>총 결제 금액</th>
								<td colspan="3"><span id="spanPayAmt"></span>원 (상품 실결제 금액 : <span id="spanSumRealOrdAmt"></span>원, 배송금액 : <span id="spanSumDeliveryFee"></span>원, 배송비쿠폰할인금액: <span id="spanDelvCpnDcAmt"></span>원)</td>
							</tr>
							<tr>
								<th>주문 상품 금액</th>
								<td><span id="spanOrdAmt"></span>원</td>
								<th>취소 상품 금액</th>
								<td><span id="spanCnclRtnAmt"></span>원</td>
							</tr>
							<tr>
								<th>취소 사용 포인트</th>
								<td colspan="3"><span id="spanTotPntDcAmt"></span>원 (고객 포인트 : <span id="spanPntDcAmt"></span>원 + 상품 선포인트 : <span id="spanPrePntDcAmt"></span>원) </td>
							</tr>
							<tr>
								<th>취소 사용 쿠폰금액</th>
								<td colspan="3"><span id="spanCpnDcAmt"></span>원 (즉시할인쿠폰 : <span id="spanCpn1DcAmt"></span>원 + 상품쿠폰 : <span id="spanGoodsCpnDcAmt"></span>원 + 장바구니쿠폰 : <span id="spanCartCpnDcAmt"></span>원)</td>
							</tr>
							<tr>
								<th>취소 다다익선 금액</th>
								<td colspan="3"><span id="spanTmtbDcAmt"></span>원 (수량할인 : <span id="spanTmtb1DcAmt"></span>원 + 금액할인 : <span id="spanTmtb2DcAmt"></span>원)</td>
							</tr>
							
							<tr>
								<th>취소 고객 상품권 금액</th>
								<td><span id="spanGfcdUseAmt"></span>원</td>
								<th>추가 반품배송 금액</th>
								<td><span id="spanTotRtnDelvFee"></span>원</td>
							</tr>
							
							<tr>
								<th>취소 상품 실결제 금액</th>
								<td><span id="spanRealCnclRtnAmt"></span>원</td>
								<th>추가 배송 금액</th>
								<td><span id="spanTotDeliveryFee"></span>원</td>
							</tr>

							<tr>
								<th>환불 금액 합계</th>
								<td colspan="3"><span id="spanRefundAmt"></span>원</td>
							</tr>
						</tbody>
					</table>					
				</div>
				
				<div class="cardArea" style="height: 200px;">
					<h4 style="width:85%;">
						회수대상 상품 정보
					</h4>	
						<span class="btnRight"  id="pgBtn" >
							<label ><input type="checkbox" name="pgStats" value="N" th:if="${sessionInfo.roleCd == 'G001_0000'}">&nbsp;&nbsp;PG 전문 미전송</label>
						</span>
					<div id="refundGridList" style="width: 100%; height: 200px; padding-top:10PX;" class="ag-theme-balham"></div>
				</div>
			</form>
		
		</div>
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	var ordChgSq = [[${ordChgSq}]];	// 주문변경번호
	var ordNo    = [[${ordNo}]];	// 주문번호 
	var userNo   = [[${userNo}]]; 

	var ordChgCnt = 0;	//회수신청건수
	var chgGb = "반품";
	
	var toTalOrdQty = 0;	// 주문 총수량 
	var ordInQty  	= 0;	// 반품 입고총수량 
	var ordChgQty	= 0;	// 반품 신청총수량 
	var delvExpnYn  = "";   // 출고예외(확정후 품절,불량)여부
	var wdGb        = "";
	var mallGb      = "";
	var reFundInfo  = [[${refundConfirmPreInfo}]]; // 환불컨펌 정보 
	
	var columnDefsDetail = [
		{headerName: "주문변경번호", 	field: "ordChgSq",	width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "주문번호", 		field: "ordNo", 	width: 100, minWidth: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenOrderDetailPopup('" + params.value + "');\">" + params.value + "</a>";
			}
		},
		{headerName: "상품명", 		field: "goodsNm",	width: 150, minWidth: 100},
		{headerName: "상품코드", 		field: "goodsCd", 	width: 120, minWidth: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenGoodsDetailPopup('U','" + params.value + "','');\">" + params.value + "</a>";
			}
		},
		{headerName: "옵션1", 		field: "optCd1", 	width: 60, minWidth: 100, cellClass: 'text-center'},
		{headerName: "옵션2", 		field: "optCd2", 	width: 60, minWidth: 100, cellClass: 'text-center'},
		{headerName: "신청수량", 		field: "chgQty", 	width: 80, minWidth: 100, cellClass: 'text-center'},
		{headerName: "회수수량", 		field: "wdQty", 	width: 80, minWidth: 100, cellClass: 'text-center'},
		{headerName: "회수처리상태", 	field: "wdStat",	width: 120, minWidth: 100, cellClass: 'text-center'},
		{headerName: "회수처리", 		field: "chgStat",	width: 120, minWidth: 100, cellClass: 'text-center'
			, cellRenderer : function(params) {
				if (params.data.wdStatYn == 'N') {
					if (params.data.wdQty > 0) {
						return "<a href=\"javascript:void(0);\" class=\"btn btn-base btn-sm\">환불컨펌</a>";
					} else {
						return "";
					}
				} else if (params.data.wdStatYn == 'Y') {
					return "환불완료";
				}
			}
		},
		{headerName: "주문상세번호", 	field: "ordDtlNo", 	width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "등록일", 		field: "regDt", 	width: 100, minWidth: 100, cellClass: 'text-center'}
		
	];
	
	// Get withDrawDetailGridOptions
	var withdrawDetailGridOptions = gagaAgGrid.getGridOptions(columnDefsDetail);
	withdrawDetailGridOptions.rowSelection = 'multiple';
	
	var isCustomer = true;

	/*************************************************************************
	*  회수 상세내역 조회
	**************************************************************************/
	var initFlag = '';
	var fnRefundDetailSearch = function() {
		//initFlag = Init;
		var params = {};
		params.ordChgSq = ordChgSq;
		params.userNo = userNo;
		
		var jsonData = JSON.stringify(params);
		
		gagajf.ajaxJsonSubmit('/withdraw/detail/list', jsonData, fnWithdrawDetailCallback);
	}
	
	/*************************************************************************
	*  상세 정보 콜백 함수
	**************************************************************************/	
	var fnWithdrawDetailCallback = function(result) {
		reFundInfo = result.refundConfirmPreInfo; // 환불 컨펌 환불 정보
		
		if (result.dataList.length < 1) {
			mcxDialog.alert('회수데이터 오류입니다. 운영팀에 문의 해주세요! ');
			return;
		}
		
		var confirmCnt = 0;
		$(result.dataList).each(function(idx) {
			if (result.dataList[idx].wdStatYn == 'Y') {
				confirmCnt++;
			}
			ordInQty  = ordInQty + result.dataList[idx].wdQty;
			ordChgQty = ordChgQty + result.dataList[idx].chgQty;
		});
		
		// 전체 회수 완료 일 때. 제휴몰일때 
		if (result.dataList.length == confirmCnt || result.dataList[0].mallGb == 'G011_20') {
			setReadOnly(true);
			$('#pgBtn').hide();
			$('#divRefundInfo').hide();
			$('#divRefundInfo2').show();
		}
		
		// 회수리스트 설정
		withdrawDetailGridOptions.api.setRowData(result.dataList); 
		
		fnSetWithdrawInfo(result.dataList[0]);	// 회수정보 설정
	}
	
	/*************************************************************************
	*  회수정보 설정
	**************************************************************************/
	var fnSetWithdrawInfo = function(data) {
		
		toTalOrdQty = data.totalOrdQty;
		delvExpnYn  = data.delvExpnYn;
		wdGb        = data.wdGb;
		mallGb      = data.mallGb;
		
		reFundInfo.chgReasonNm = data.chgReasonNm;	// 변경사유
		reFundInfo.chgReason   = data.chgReason;	// 변경사유코드
		reFundInfo.accountNm   = data.accountNm;	// 환불계좌이름
		reFundInfo.accountNo   = data.accountNo;	// 환불계좌번호
		reFundInfo.bankCd      = data.bankCd;		// 환불계좌은행코드
		reFundInfo.custNo      = data.custNo;		// 고객번호
		reFundInfo.ordNm       = data.ordNm;		// 주문자명
		reFundInfo.delvAddrSq  = data.delvAddrSq;	// 회수지번호
		reFundInfo.delvExpnYn  = data.delvExpnYn;	// 확정후 품절,불량 여부
		reFundInfo.wdInvoiceNo = data.wdInvoiceNo;	// 회수송장번호
		reFundInfo.mallGb      = mallGb;			// 몰구분
		reFundInfo.ordNo       = ordNo;				// 주문번호
		reFundInfo.ordChgSq    = ordChgSq;			// 변경요청번호
		reFundInfo.wdGb        = wdGb;				// 회수구분

		// 환불컨펌 상세
		$("#wdGbNm").text(data.wdGbNm); 										// 회수구분 
		$("#arriValDt").text(data.arrivalDt); 									// arriValDt 도착일
		$("#chgReasonNm").text(data.chgReasonNm); 								// 최종요청사유 
		$("#chgReasonText").text(data.chgReasonText); 							// 귀책사유 
		$("#withdrawDetailForm input[name=encloseFee]").val(data.encloseFee); 	// 동봉비 
		$("#withdrawDetailForm input[name=codFee]").val(data.codFee); 			// 착불비 
		$("#withdrawDetailForm input[name=addPayCost]").val(data.addPayCost); 	// 추가결제비 
		$("#chgMemo").text(data.chgMemo); 										// 클레임메모 
		$("#wdMemo").text(data.wdMemo); 										// 회수메모 

		// 환불예정금액 
		$("#spanPayAmt").text(reFundInfo.spanPayAmt.addComma());					//총 결제 금액
		$("#spanSumRealOrdAmt").text(reFundInfo.spanSumRealOrdAmt.addComma());		//상품 실결제 금액
		$("#spanSumDeliveryFee").text(reFundInfo.spanSumDeliveryFee.addComma());	//배송금액
		$("#spanDelvCpnDcAmt").text(reFundInfo.spanDelvCpnDcAmt.addComma());		//배송비쿠폰할인금액
		
		$("#spanOrdAmt").text(reFundInfo.spanOrdAmt.addComma());					//주문 상품 금액
		$("#spanCnclRtnAmt").text(reFundInfo.spanCnclRtnAmt.addComma());			//취소 상품 금액
		
		$("#spanTotPntDcAmt").text(reFundInfo.spanTotPntDcAmt.addComma());			//취소 사용 포인트
		$("#spanPntDcAmt").text(reFundInfo.spanPntDcAmt.addComma());				//고객 포인트
		$("#spanPrePntDcAmt").text(reFundInfo.spanPrePntDcAmt.addComma());			//상품 선포인트
		
		$("#spanCpnDcAmt").text(reFundInfo.spanCpnDcAmt.addComma());				//취소 사용 쿠폰금액
		$("#spanCpn1DcAmt").text(reFundInfo.spanCpn1DcAmt.addComma());				//즉시할인쿠폰
		$("#spanGoodsCpnDcAmt").text(reFundInfo.spanGoodsCpnDcAmt.addComma());		//상품쿠폰
		$("#spanCartCpnDcAmt").text(reFundInfo.spanCartCpnDcAmt.addComma());		//장바구니쿠폰
		
		$("#spanTmtbDcAmt").text(reFundInfo.spanTmtbDcAmt.addComma());				//취소 다다익선 금액
		$("#spanTmtb1DcAmt").text(reFundInfo.spanTmtb1DcAmt.addComma());			//수량할인
		$("#spanTmtb2DcAmt").text(reFundInfo.spanTmtb2DcAmt.addComma());			//금액할인
		
		$("#spanGfcdUseAmt").text(reFundInfo.spanGfcdUseAmt.addComma());			//취소 고객 상품권 금액
		
		$("#spanRealCnclRtnAmt").text(reFundInfo.spanRealCnclRtnAmt.addComma());	//취소 상품 실결제 금액
		$("#spanTotDeliveryFee").text(reFundInfo.spanTotDeliveryFee.addComma());	//취소 환불 배송 금액
		
		$("#spanTotRtnDelvFee").text(reFundInfo.spanTotRtnDelvFee.addComma());		//반품 환불 배송 금액
		$("#spanTotExcDelvFee").text(reFundInfo.spanTotExcDelvFee.addComma());		//교환 환불 배송 금액
		
		// 귀책사유 고객
		if (data.chgReason == "G688_10") {
			isCustomer = true;
		} 
		// 귀책사유 회사
		else {
			isCustomer = false;
		}
		
		$("#refundAmt").text(data.refundAmt.addComma());
		
		if(delvExpnYn == "Y"){
			$('#withdrawDetailForm input[name=codFee]').attr('readonly', 'readonly');
			$('#withdrawDetailForm input[name=encloseFee]').attr('readonly', 'readonly');
			
		} else {
			if(wdGb == "W"){
				$('#withdrawDetailForm input[name=codFee]').attr('readonly', 'readonly');
			} else {
				$('#withdrawDetailForm input[name=codFee]').remove('readonly');	
			}
		}
		
		fnSetTotRefundData();
	}
	
	var addDeliveryFee   = 0;
	var addDeliveryFeeYn = "N";
	var codFeeAmt        = 0;
	var codFeeYn         = 'N';
	var enCloseFeeAmt    = 0;
	var enCloseFeeYn     = "N";
	
	/*************************************************************************
	*  환불 금액 계산
	**************************************************************************/		
	var fnSetTotRefundData = function() {
		var enCloseFee 		= $("#withdrawDetailForm input[name=encloseFee]").val(); 	//동봉비 
		var codFee     		= $("#withdrawDetailForm input[name=codFee]").val(); 		//착불비 
		var addPaycost	 	= $("#withdrawDetailForm input[name=addPayCost]").val(); 	//추가결제비
		
		addDeliveryFee   	= 0;
		addDeliveryFeeYn 	= "N";
		codFeeAmt        	= 0;
		codFeeYn         	= "N";
		enCloseFeeAmt    	= Number(enCloseFee);
		enCloseFeeYn     	= "N";
		
		// 2021.07.02 환불컨펌 환불금액계산
		var spanRealCnclRtnAmt 	= reFundInfo.spanRealCnclRtnAmt; // 취소상품실결제금액
		var spanTotDeliveryFee 	= reFundInfo.spanTotDeliveryFee; // 배송비
		var spanDelvCpnDcAmt	= reFundInfo.spanTotDeliveryFee; // 배송비쿠폰할인금액
		var spanTotRtnDelvFee	= reFundInfo.spanTotRtnDelvFee;  // 반품배송비
		
		// 출고예외(확정후 품절,불량)일 경우
		if (delvExpnYn == "Y") {
			// 총 주문수량  =  반품수량 배송비가 있을시 환불해줌
			if (toTalOrdQty == ordChgQty) {
				if (reFundInfo.spanSumDeliveryFee > 0) {
					addDeliveryFee = reFundInfo.spanSumDeliveryFee - reFundInfo.spanDelvCpnDcAmt;
					addDeliveryFeeYn = "Y";
				}
				//alert("총수량 출고예외");
				// 환불금액  = 취소 상품 실결제 금액 + 배송비 
				reFundInfo.spanRefundAmt = (reFundInfo.spanRealCnclRtnAmt + reFundInfo.spanSumDeliveryFee - reFundInfo.spanDelvCpnDcAmt);
			} else { // 총 주문수량  <>  반품수량   
				//alert("출고예외");
				reFundInfo.spanRefundAmt = reFundInfo.spanRealCnclRtnAmt;
			}
		} 
		// 반품일 경우
		else {  
			// 총 주문수량  =  반품수량
			if (toTalOrdQty == ordChgQty) {
				// 귀책사유고객
				if (isCustomer) {  
					// 회수요청
					if (wdGb == "W") { 
						// 환불금액  = 취소 상품 실결제 금액 + 배송비 - 추가배송비 - 반품배송비 
						if (Number(enCloseFee) > 0) {
							enCloseFeeYn = "Y";
						}
						
						// 환불비용 = (취소상품실결제금액 + 동봉비 + 추가결제비) - 반품배송비 - 착불비
						reFundInfo.spanRefundAmt = (spanRealCnclRtnAmt + Number(enCloseFee) + Number(addPaycost)) - spanTotRtnDelvFee - Number(codFee);
					}
					// 직접배송
					else {
						if(Number(codFee) > 0){
							codFeeAmt = Number(codFee);
							codFeeYn  = "Y";
						}
						if(Number(enCloseFee) > 0){
							enCloseFeeYn = "Y";
						}
						
						// 2021.07.02 환불컨펌 환불금액계산
						// 환불비용 = (취소상품실결제금액 + 동봉비 + 추가결제비) - 착불비
						reFundInfo.spanRefundAmt = (reFundInfo.spanRealCnclRtnAmt + Number(enCloseFee) + Number(addPaycost)) - Number(codFee);
					}
				} 
				// 회사귀책
				else { 
					if (reFundInfo.spanSumDeliveryFee > 0) {
						addDeliveryFee = reFundInfo.spanSumDeliveryFee - reFundInfo.spanDelvCpnDcAmt;
						addDeliveryFeeYn = "Y";
					}
					
					// 2021.07.02 환불컨펌 환불금액계산
					// 환불비용 = (취소상품실결제금액) + (원주문배송비- 배송비쿠폰할인금액)
					reFundInfo.spanRefundAmt = (reFundInfo.spanRealCnclRtnAmt + (reFundInfo.spanSumDeliveryFee - reFundInfo.spanDelvCpnDcAmt));
				}
			} 
			// 총 주문수량  <>  반품수량
			else {
				// 고객귀책
				if (isCustomer) {  
					// 회수요청
					if (wdGb == "W") {
						if (Number(enCloseFee) > 0) {
							enCloseFeeYn = "Y";
						}
						
						// 2021.07.02 환불컨펌 환불금액계산
						// 환불금액  = (취소상품실결제금액 + 동봉비 + 추가결제비) - (추가배송비 + 반품배송비)
						reFundInfo.spanRefundAmt = (reFundInfo.spanRealCnclRtnAmt + Number(enCloseFee) + Number(addPaycost)) - (spanTotDeliveryFee + spanTotRtnDelvFee);
					} 
					// 직접배송
					else {
						if(Number(codFee) > 0){
							codFeeAmt = Number(codFee);
							codFeeYn  = "Y";
						}
						if(Number(enCloseFee) > 0){
							enCloseFeeYn = "Y";
						}
						// 2021.07.02 환불컨펌 환불금액계산
						// 환불금액  = (취소상품실결제금액 + 동봉비 + 추가결제비) - (추가배송비)
						reFundInfo.spanRefundAmt = (reFundInfo.spanRealCnclRtnAmt + Number(enCloseFee) - Number(codFee)) - (spanTotDeliveryFee);
					}
				} 
				// 회사귀책
				else {
					// 2021.07.02 환불컨펌 환불금액계산
					// 환불금액  = (취소상품실결제금액)
					reFundInfo.spanRefundAmt = reFundInfo.spanRealCnclRtnAmt;
				}
			}
		}
		
		$("#spanRefundAmt").text(reFundInfo.spanRefundAmt.addComma());				//환불 금액 합계 
	}
	
	/*************************************************************************
	*  동봉비, 착불비, 추가결제비 변경시 재계산
	**************************************************************************/		
	var fnChangeAmt = function(){
		var enCloseFee = $("#withdrawDetailForm input[name=encloseFee]").val(); // 동봉비 
		var codFee     = $("#withdrawDetailForm input[name=codFee]").val(); 	// 착불비 
		var addPaycost = $("#withdrawDetailForm input[name=addPayCost]").val(); // 추가결제비 
		
		fnSetTotRefundData();
	}
	
	var ordInQty  	= 0;	// 반품 입고총수량 
	var ordChgQty	= 0;	// 반품 신청총수량 
	
	/*************************************************************************
	*  회수컨펌 클릭 시
	**************************************************************************/
	withdrawDetailGridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'chgStat') return;
		if (ordChgQty != ordInQty) {
			mcxDialog.alert('반품신청 수량과 회수입고수량이 맞지 않습니다.<br/>반품신청수량 : ' + ordChgQty + '<br/>회수입고수량 : ' + ordInQty);
			return;
		}
		
		// 회수컨펌
		fnWithdrawDetailConfirm();
	}
	

	/*************************************************************************
	*  회수 컨펌
	**************************************************************************/	
	var confirmFlag = true;
	var fnWithdrawDetailConfirm = function() {
		//var totPayAmt = $('#totPayAmt').text().replace(/,/gi,"");
		//var totRefundAmt = $('#totRefundAmt').text().replace(/,/gi,"");
		if (mallGb == 'G011_10') {
			
			// 아웃바운드 필요. (동동 및 계좌이체로 받아야함)
			if (reFundInfo.spanRefundAmt <= 0) { 
				mcxDialog.alert('환불금액 부족합니다.');
				return;
			}
			
			if (reFundInfo.spanRefundAmt > reFundInfo.spanPayAmt) {
				mcxDialog.alert('환불금액이 총 결제금액보다 큽니다.<br/>환불금액 : ' + reFundInfo.spanRefundAmt + '<br/>총 결제금액 : ' + reFundInfo.spanPayAmt);
				return;
			}
		}
		
		var pgStat = $('#withdrawDetailForm input:checkbox[name=pgStats]').is(":checked") ? "Y" : "N"; 
		reFundInfo.addDeliveryFee   = addDeliveryFee;
		reFundInfo.addDeliveryFeeYn = addDeliveryFeeYn;
		reFundInfo.codFee           = codFeeAmt;
		reFundInfo.codFeeYn         = codFeeYn;
		reFundInfo.pgStat           = pgStat;
		reFundInfo.enCloseFeeYn     = enCloseFeeYn;
		reFundInfo.enCloseFee       = enCloseFeeAmt;
		
		var jsonData = JSON.stringify(reFundInfo);
		
		if (!confirmFlag) {
			mcxDialog.alert('데이터 처리 중입니다.');
			return;
		}

		mcxDialog.confirm('환불컨펌 하시겠습니까?', {
			cancelBtnText	: "취소",
			sureBtnText		: "확인",
			sureBtnClick	: function(){
				gagajf.ajaxJsonSubmit('/withdraw/detail/confirm', jsonData, function(result) {
					//confirmFlag = true;
					fnSearch();
					$('#divRefundInfo').hide();
					$('#divRefundInfo2').show();
					fnRefundDetailSearch();
				});
			}
		});
	}

	// readonly 설정
	var setReadOnly = function(flag) {
		if (flag) {
			$('#withdrawDetailForm input[name=encloseFee]').attr('readonly', 'readonly');
			$('#withdrawDetailForm input[name=encloseFee]').addClass('formControl');
			
		} else {
			$('#withdrawDetailForm input[name=encloseFee]').remove('readonly');
			$('#withdrawDetailForm input[name=encloseFee]').removeClass('formControl');
			
		}
		
	}
	
	/*************************************************************************
	*  init
	**************************************************************************/
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('refundGridList', withdrawDetailGridOptions);
		$('#divRefundInfo2').hide();
		fnRefundDetailSearch();
		
	}); 

/*]]>*/
</script>
</html>
