<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CancelRequestForm.html
 * @desc    : 취소요청 화면
 *============================================================================
 * STYLE24
 * Copyright(C) 2019 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.12   jsh77b       최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1400" data-height="600">
	<div class="panelStyle">
		<div class="panelTitle">
			<h2>취소요청</h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupCancelRequestForm');"><i class="fa fa-times"></i></button>
		</div>
			
		<div class="panelContent" style="height:90%; overflow-y:auto; padding:0px 20px !important; ">
			<form id="cancelRequestFrm" name="cancelRequestFrm" action="/order/cancel" method="post" target="hdFrameForOrderCancel">
				<input type="hidden" name="chgGb" 		value="30" />
				<input type="hidden" name="ordDtlNos" 	value="" />
				<input type="hidden" name="chgQtys" 	value="" />
				<input type="hidden" name="ordNo" 	 	th:value="${ordNo}" />
				<input type="hidden" name="mallGb" 		th:value="${orderInfo.mallGb}" />
				<input type="hidden" name="delvFee" 	value="0" />
				<input type="hidden" name="pgStat"	 	value="" />
				<input type="hidden" name="chgReason"	value="" />
				<input type="hidden" name="chgReasonDesc" value="" />
				<input type="hidden" name="cncWait" 	th:value="${cncWait}" />
		
				<h3>주문정보</h3>
				<div id="gridOrderCancelRequestList" style="width:100%; height: 200px;" class="ag-theme-balham"></div>

				<h3>취소정보</h3>
				<div id="gridOrderCancelRequestToBeList" style="width:100%; height: 200px;" class="ag-theme-balham"></div>
				
				<h3>배송비정보</h3>
				<div id="gridDelvCdList" style="width:100%; height: 140px;" class="ag-theme-balham"></div>
				
				<div style="text-align:right; padding-bottom:5px; padding-top:5px;">
					<button type="button" class="btn btn-success" id="btnCancelRequestEscrow" onclick="fnCancelRequestEscrow();" style="display:none;">에스크로 결제생성</button>
					<label th:if="${sessionInfo.userId == 'jsshin'
									|| sessionInfo.userId == 'dlffyd7942'
									|| sessionInfo.userId == 'card007'
									|| sessionInfo.userId == 'hrkim'
									|| sessionInfo.userId =='666badboy'
									|| sessionInfo.userId =='yjyy83'}">
						<input type="checkbox" name="pgStats" value="N">PG 전문 미전송
					</label>
					<button type="button" class="btn btn-success" id="btnCancelRequestPartOk" onclick="fnCancelRequestPartOk();">요청</button>
				</div>
				
				<table class="frmStyle">
					<colgroup>
						<col style="width:160px;" />
						<col style="width:320px;" />
						<col style="width:160px;" />
						<col />
					</colgroup>
					<tbody>
						<tr>
							<th>취소사유 <i class="star"></i></th>
							<td>
								<select name="selectChgReason" onchange="fnChangeChgReason($(this).val());">
									<option value="">[선택하세요]</option>
									<option th:if="${chgReasonList}" th:each="oneData, status : ${chgReasonList}" th:value="|${oneData.cd}:${oneData.cdNm}|" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
								</select>
							</td>
							<th>귀책사유</th>
							<td><span id="imputeReason"></span></td>
						</tr>
						<tr>
							<th>요청메모</th>
							<td colspan="3">
								<textarea name="chgMemo" style="height:80px;" placeholder="취소사유를 300자내외로 작성해 주세요"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
				
				<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>원) </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 colspan="3"><span id="spanGfcdUseAmt"></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>
				
			</form>
		</div>
	</div>
</div>

<!-- data -->
<script th:inline="javascript">
/*<![CDATA[*/
var cancelRequestTargetList = [[${cancelRequestTargetList}]];

var temp1 = true;
var temp2 = false;

// specify the columns
var columnCancelReqList = [
	{
		headerName	: "주문상세정보",
		children	: [
			{headerName: "주문번호"		, field: "ordNo"			, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "주문상세"		, field: "ordDtlNo"			, width: 80		, cellClass: 'text-center'},
			{headerName: "주문상세"		, field: "ordDtlStat"		, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "주문상세상태"		, field: "ordDtlStatNm"		, width: 100	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품코드"		, field: "goodsCd"			, width: 100	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품명"			, field: "goodsNm"			, width: 200	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품타입"		, field: "goodsTypeNm"		, width: 100	, cellClass: 'text-center', hide: temp2}
		]
	},
	{
		headerName	: "주문상세단품정보",
		children	: [
			{headerName: "단품코드"		, field: "itemCd"			, width: 100	, cellClass: 'text-center', hide: temp2},
			{headerName: "단품명"			, field: "itemNm"			, width: 200	, cellClass: 'text-center', hide: temp2},
			{headerName: "칼라코드"		, field: "optCd1"			, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "사이즈코드"		, field: "optCd2"			, width: 80		, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "단품수량"		
				, field			: "itemQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "단품금액"		
				, field			: "itemPrice"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "단품옵션금액"		
				, field			: "optAddPrice"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문상세수량",
		children	: [
			{
				headerName		: "주문"		
				, field			: "ordQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소/요청"		
				, field			: "cnclRtnQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var cnclRtnReqQty = parseInt(params.data.cnclRtnQty) + parseInt(params.data.ordReqChgQty);
					return cnclRtnReqQty;
				}
			},
			{
				headerName		: "취소"		
				, field			: "ordCanChgQty"			
				, width			: 100		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var ordQty 			= parseInt(params.data.ordQty);
					var cnclRtnQty 		= parseInt(params.data.cnclRtnQty);
					var ordReqChgQty 	= parseInt(params.data.ordReqChgQty);
					var ordCanChgQty 	= ordQty - (cnclRtnQty +  ordReqChgQty);
					
					var strVal 			= "";
					strVal += "<select class='ordCanChgQty' name='ordCanChgQty' ordDtlNo='"+params.data.ordDtlNo+"' onChange='fnCalculateRefundAmt(this);'>";
					
					for (i=0 ; i<=ordCanChgQty ; i++) {
						if (i == params.data.ordCanChgQty) {
							strVal += "	<option value='"+i+"' selected>"+i+"</option>";
						} else {
							strVal += "	<option value='"+i+"'>"+i+"</option>";
						}
					}
				
					strVal += "</select>";
					return strVal;
				}
			}
		]
	},
	{
		headerName	: "주문단품금액",
		children	: [
			{
				headerName		: "주문"
				, field			: "ordAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소"		
				, field			: "cnclRtnAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "즉시할인"		
				, field			: "cpn1DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "다다익선1"		
				, field			: "tmtb1DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "다다익선2"		
				, field			: "tmtb2DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "상품쿠폰"		
				, field			: "goodsCpnDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "장바구니쿠폰"		
				, field			: "cartCpnDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "포인트"		
				, field			: "pntDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "선포인트"		
				, field			: "prePntDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "상품권"		
				, field			: "gfcdUseAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "실결제금액"		
				, field			: "realOrdAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문배송비정보",
		children	: [
			{
				headerName		: "배송비"		
				, field			: "delvFee"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "업체"			, field: "supplyCompCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{headerName: "배송비코드"		, field: "delvFeeCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "무료배송비"		
				, field			: "minOrdAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{
				headerName		: "기본배송비"		
				, field			: "orgDelvFee"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "전체취소가능"		, field: "allCanYn"			, width: 100	, cellClass: 'text-center', hide: temp2},
		]
	}
];
var gridOptionsCancelReqList = orderAgGrid.getGridOptions(columnCancelReqList);
// Add on options
gridOptionsCancelReqList.suppressRowClickSelection = true;
gridOptionsCancelReqList.rowSelection = 'multiple';


//specify the columns
var columnCancelReqToBeList = [
	{
		headerName	: "주문상세정보",
		children	: [
			{headerName: "주문번호"		, field: "ordNo"			, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "주문상세"		, field: "ordDtlNo"			, width: 80		, cellClass: 'text-center'},
			{headerName: "주문상세"		, field: "ordDtlStat"		, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "주문상세상태"		, field: "ordDtlStatNm"		, width: 100	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품코드"		, field: "goodsCd"			, width: 100	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품명"			, field: "goodsNm"			, width: 200	, cellClass: 'text-center', hide: temp1},
			{headerName: "상품타입"		, field: "goodsTypeNm"		, width: 100	, cellClass: 'text-center', hide: temp2}
		]
	},
	{
		headerName	: "주문상세단품정보",
		children	: [
			{headerName: "단품코드"		, field: "itemCd"			, width: 100	, cellClass: 'text-center', hide: temp2},
			{headerName: "단품명"			, field: "itemNm"			, width: 200	, cellClass: 'text-center', hide: temp2},
			{headerName: "칼라코드"		, field: "optCd1"			, width: 80		, cellClass: 'text-center', hide: temp1},
			{headerName: "사이즈코드"		, field: "optCd2"			, width: 80		, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "단품수량"		
				, field			: "itemQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "단품금액"		
				, field			: "itemPrice"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "단품옵션금액"		
				, field			: "optAddPrice"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문상세수량",
		children	: [
			{
				headerName		: "주문"		
				, field			: "ordQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소/요청"		
				, field			: "cnclRtnQty"			
				, width			: 80		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var cnclRtnReqQty = parseInt(params.data.cnclRtnQty) + parseInt(params.data.ordReqChgQty);
					return cnclRtnReqQty;
				}
			},
			{
				headerName		: "취소"		
				, field			: "ordCanChgQty"			
				, width			: 100		
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문단품금액",
		children	: [
			{
				headerName		: "주문"
				, field			: "ordAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소"		
				, field			: "cnclRtnAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "즉시할인"		
				, field			: "cpn1DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "다다익선1"		
				, field			: "tmtb1DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "다다익선2"		
				, field			: "tmtb2DcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "상품쿠폰"		
				, field			: "goodsCpnDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "장바구니쿠폰"		
				, field			: "cartCpnDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "포인트"		
				, field			: "pntDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "선포인트"		
				, field			: "prePntDcAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "상품권"		
				, field			: "gfcdUseAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "환불금액"		
				, field			: "realOrdAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문배송비정보",
		children	: [
			{
				headerName		: "배송비"		
				, field			: "delvFee"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "업체"			, field: "supplyCompCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{headerName: "배송비코드"		, field: "delvFeeCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "무료배송비"		
				, field			: "minOrdAmt"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{
				headerName		: "기본배송비"		
				, field			: "orgDelvFee"			
				, width			: 80		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "전체취소가능"		, field: "allCanYn"			, width: 100	, cellClass: 'text-center', hide: temp2},
		]
	}
];
var gridOptionsCancelReqToBeList = orderAgGrid.getGridOptions(columnCancelReqToBeList);

//specify the columns
var columnDelvCdList = [
	{
		headerName	: "배송코드기준금액",
		children	: [
			{headerName: "업체"			, field: "supplyCompCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{headerName: "배송비코드"		, field: "delvFeeCd"		, width: 100	, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "주문"
				, field			: "ordAmt"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소"		
				, field			: "cnclRtnAmt"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "환불"		
				, field			: "realOrdAmt"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "배송비정보",
		children	: [
			{
				headerName		: "배송비"		
				, field			: "delvFee"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{
				headerName		: "무료배송비"		
				, field			: "minOrdAmt"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{
				headerName		: "기본배송비"		
				, field			: "orgDelvFee"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "추가배송비여부"		, field: "addDelvFeeYn"		, width: 140	, cellClass: 'text-center', hide: temp2},
			{
				headerName		: "추가배송비"		
				, field			: "addDelvFee"			
				, width			: 100		
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
				, hide			: temp2
			},
			{headerName: "전체취소가능"		, field: "allCanYn"			, width: 100	, cellClass: 'text-center', hide: temp2},
		]
	}
];
var gridOptionsDelvCdList = orderAgGrid.getGridOptions(columnDelvCdList);
</script>

<!-- AgGrid 컬럼 세팅 -->
<script>
// 공통1. 주문상세 그리드 옵션 정보 적용
var orderAgGrid = {
	getGridOptions : function(colDefs) {
		return {
			columnDefs					: colDefs
			, detailCellRendererParams	: {
				detailGridOptions	: {
					columnDefs				: []
					, defaultColDef			: {
						resizable: true
					}
					, suppressLoadingOverlay: false
					, onGridReady			: function (params) {
						params.api.setDomLayout('autoHeight');
					}
					, onFirstDataRendered	: function (params) {
						params.api.sizeColumnsToFit();
					}
				}
				, getDetailRowData: function (params) {
					params.successCallback(params.data.orderDetailList);
				}
			}
			, defaultColDef: {
				resizable: true
			}
			, isRowMaster: function (dataItem) {
				return dataItem ? dataItem.orderDetailList.length > 1 : false;
			}
			, suppressRowTransform: true
			, enableRangeSelection: true
		};
	}
}
</script>

<script>
// 취소정보계산
var fnCalculateRefundAmt = function (obj) {
	// 취소정보담은목록
	var cancelRequestTargetToBeList = [];

	if (obj != null) {
		for (i=0 ; i<cancelRequestTargetList.length ; i++) {
			var orDtlNo 		= $(obj).attr("ordDtlNo");
			var ordCanChgQty 	= $(obj).val();
			
			if (cancelRequestTargetList[i].ordDtlNo == orDtlNo) {
				cancelRequestTargetList[i].ordCanChgQty = ordCanChgQty;
			}
		}
		// 주문정보 다시 셋팅 (체크해봐야할문제)
		gridOptionsCancelReqList.api.setRowData(cancelRequestTargetList);
	}
	
	/*
	// 취소 후 발생되는 배송정보 설정
	var delvFeeList 		= [];
	var delvObj				= new Object();
	var k					= 0;
	
	// 공급업체 와 배송정책코드가 같지안으면 주문금액, 취소금액 RESET
	delvObj.ordAmt 			= 0;
	delvObj.cnclRtnAmt 		= 0;
	delvObj.realOrdAmt 		= 0;
	delvObj.delvFee 		= cancelRequestTargetList[k].delvFee;
	delvObj.minOrdAmt 		= cancelRequestTargetList[k].minOrdAmt;
	delvObj.orgDelvFee 		= cancelRequestTargetList[k].orgDelvFee;
	delvObj.supplyCompCd 	= cancelRequestTargetList[k].supplyCompCd;
	delvObj.delvFeeCd 		= cancelRequestTargetList[k].delvFeeCd;
	delvObj.allCanYn		= cancelRequestTargetList[k].allCanYn;

	delvFeeList[k] 			= delvObj;
	
	var spanPayAmt			= 0; // 총 결제 금액
	var spanSumRealOrdAmt	= 0; // 상품 실결제 금액
	var spanSumDeliveryFee	= 0; // 배송금액
	var spanOrdAmt			= 0; // 주문 상품 금액
	var spanCnclRtnAmt		= 0; // 취소 상품 금액
	var spanTotPntDcAmt		= 0; // 취소 사용 포인트
	var spanPntDcAmt		= 0; // 고객 포인트
	var spanPrePntDcAmt		= 0; // 상품 선포인트
	var spanCpnDcAmt		= 0; // 취소 사용 쿠폰금액
	var spanCpn1DcAmt		= 0; // 즉시할인쿠폰
	var spanGoodsCpnDcAmt	= 0; // 상품쿠폰
	var spanCartCpnDcAmt	= 0; // 장바구니쿠폰
	var spanTmtbDcAmt		= 0; // 취소 다다익선 금액
	var spanTmtb1DcAmt		= 0; // 수량할인
	var spanTmtb2DcAmt		= 0; // 금액할인
	var spanGfcdUseAmt		= 0; // 취소 고객 상품권 금액
	var spanRealCnclRtnAmt	= 0; // 취소 상품 실결제 금액
	var spanTotDeliveryFee	= 0; // 환불 배송 금액
	var spanRefundAmt		= 0; // 환불 금액 합계

	// 취소정보 설정
	for (i=0 ; i<cancelRequestTargetList.length ; i++) {
		var obj 			= new Object();
		
		var itemQty 		= cancelRequestTargetList[i].itemQty;
		var ordQty 			= cancelRequestTargetList[i].ordQty;
		var cnclRtnQty 		= cancelRequestTargetList[i].cnclRtnQty;
		var ordReqChgQty 	= cancelRequestTargetList[i].ordReqChgQty;
		var ordCanChgQty 	= cancelRequestTargetList[i].ordCanChgQty;
		var itemPrice 		= cancelRequestTargetList[i].itemPrice;
		var optAddPrice 	= cancelRequestTargetList[i].optAddPrice;
		var ordAmt 			= cancelRequestTargetList[i].ordAmt;
		
		var cnclRtnAmt 		= cancelRequestTargetList[i].cnclRtnAmt;
		var cpn1DcAmt 		= cancelRequestTargetList[i].cpn1DcAmt;
		var tmtb1DcAmt 		= cancelRequestTargetList[i].tmtb1DcAmt;
		var tmtb2DcAmt 		= cancelRequestTargetList[i].tmtb2DcAmt;
		var goodsCpnDcAmt 	= cancelRequestTargetList[i].goodsCpnDcAmt;
		var cartCpnDcAmt 	= cancelRequestTargetList[i].cartCpnDcAmt;
		var pntDcAmt 		= cancelRequestTargetList[i].pntDcAmt;
		var prePntDcAmt 	= cancelRequestTargetList[i].prePntDcAmt;
		var gfcdUseAmt 		= cancelRequestTargetList[i].gfcdUseAmt;
		var realOrdAmt 		= cancelRequestTargetList[i].realOrdAmt;
		
		obj.ordNo			= cancelRequestTargetList[i].ordNo;
		obj.ordDtlNo		= cancelRequestTargetList[i].ordDtlNo;
		obj.goodsCd			= cancelRequestTargetList[i].goodsCd;
		obj.goodsNm			= cancelRequestTargetList[i].goodsNm;
		obj.itemCd			= cancelRequestTargetList[i].itemCd;
		obj.itemNm			= cancelRequestTargetList[i].itemNm;
		obj.optCd1			= cancelRequestTargetList[i].optCd1;
		obj.optCd2			= cancelRequestTargetList[i].optCd2;
		obj.itemQty			= itemQty;
		obj.ordQty			= ordQty;
		obj.cnclRtnQty		= cnclRtnQty;
		obj.ordReqChgQty	= ordReqChgQty;
		obj.ordCanChgQty	= ordCanChgQty;
		obj.itemPrice		= itemPrice;
		obj.optAddPrice		= optAddPrice;
		obj.ordAmt			= ordAmt;
		
		obj.cnclRtnAmt 		= ((itemPrice + optAddPrice) * itemQty) * ordCanChgQty;
		obj.cpn1DcAmt 		= cpn1DcAmt 		* (ordCanChgQty/ordQty);
		obj.tmtb1DcAmt 		= tmtb1DcAmt 		* (ordCanChgQty/ordQty);
		obj.tmtb2DcAmt 		= tmtb2DcAmt 		* (ordCanChgQty/ordQty);
		obj.goodsCpnDcAmt 	= goodsCpnDcAmt 	* (ordCanChgQty/ordQty);
		obj.cartCpnDcAmt 	= cartCpnDcAmt 		* (ordCanChgQty/ordQty);
		obj.pntDcAmt 		= pntDcAmt 			* (ordCanChgQty/ordQty);
		obj.prePntDcAmt 	= prePntDcAmt 		* (ordCanChgQty/ordQty);
		obj.gfcdUseAmt 		= gfcdUseAmt 		* (ordCanChgQty/ordQty);
		
		obj.realOrdAmt 		= obj.cnclRtnAmt - (obj.cpn1DcAmt  + obj.tmtb1DcAmt + obj.tmtb2DcAmt + obj.goodsCpnDcAmt + obj.cartCpnDcAmt + obj.pntDcAmt + obj.prePntDcAmt + obj.gfcdUseAmt);
		
		// 배송관련 설정		
		obj.ordDtlNo		= cancelRequestTargetList[i].ordDtlNo;
		obj.goodsTypeNm		= cancelRequestTargetList[i].goodsTypeNm;
		obj.delvFee			= cancelRequestTargetList[i].delvFee;
		obj.supplyCompCd	= cancelRequestTargetList[i].supplyCompCd;
		obj.delvFeeCd		= cancelRequestTargetList[i].delvFeeCd;
		obj.minOrdAmt		= cancelRequestTargetList[i].minOrdAmt;
		obj.orgDelvFee		= cancelRequestTargetList[i].orgDelvFee;
		
		// 주문상세상태
		obj.ordDtlStat		= cancelRequestTargetList[i].ordDtlSat;
		obj.ordDtlSatNm		= cancelRequestTargetList[i].ordDtlSatNm;
		obj.allCanYn		= cancelRequestTargetList[i].allCanYn;
		
		cancelRequestTargetToBeList[i] = obj;

		// 배송비 정책 기준으로 조건 처리
		if (delvFeeList[k].supplyCompCd == obj.supplyCompCd && delvFeeList[k].delvFeeCd == obj.delvFeeCd) {
			// 공급업체 와 배송정책코드가 같으면 주문금액, 취소금액 SUM
			delvFeeList[k].ordAmt 		+= obj.ordAmt;
			delvFeeList[k].cnclRtnAmt 	+= obj.cnclRtnAmt;
			delvFeeList[k].realOrdAmt 	+= obj.realOrdAmt;
			
			if (obj.allCanYn == "N") {
				delvFeeList[k].allCanYn = "N";
			}
		} else {			
			k++;
			
			var delvObj					= new Object();
			
			// 공급업체 와 배송정책코드가 같지안으면 주문금액, 취소금액 RESET
			delvObj.ordAmt 				= obj.ordAmt;
			delvObj.cnclRtnAmt 			= obj.cnclRtnAmt;
			delvObj.realOrdAmt 			= obj.realOrdAmt;
			
			delvObj.delvFee 			= obj.delvFee;
			delvObj.minOrdAmt 			= obj.minOrdAmt;			
			delvObj.orgDelvFee 			= obj.orgDelvFee;
			delvObj.supplyCompCd 		= obj.supplyCompCd;
			delvObj.delvFeeCd 			= obj.delvFeeCd;
			delvObj.allCanYn			= obj.allCanYn;
			
			delvFeeList[k] 				= delvObj;
		}
		
		spanSumRealOrdAmt	+= realOrdAmt;
		spanPntDcAmt		+= obj.pntDcAmt;
		spanPrePntDcAmt		+= obj.prePntDcAmt;
		spanCpn1DcAmt		+= obj.cpn1DcAmt;
		spanGoodsCpnDcAmt	+= obj.goodsCpnDcAmt;
		spanCartCpnDcAmt	+= obj.cartCpnDcAmt;
		spanTmtb1DcAmt		+= obj.tmtb1DcAmt;
		spanTmtb2DcAmt		+= obj.tmtb2DcAmt;
		spanGfcdUseAmt		+= obj.gfcdUseAmt;
		spanRealCnclRtnAmt	+= obj.realOrdAmt;
	}
	
	// 추가배송비 발생여부 , 추가배송비, 배송비정책단위 전체취소 여부
	for (i=0 ; i<delvFeeList.length ; i++) {
		var obj = delvFeeList[i];
		
		// 무료배송비용 > (주문금액 - 취소금액)
		if (obj.minOrdAmt > (obj.ordAmt - obj.cnclRtnAmt)) {
			// 2020.12.28 
			// case : 배송정책 기준으로 1,2 상품 주문 후 1번 출고 후 1번반품 2번취소 할 경우 전체 취소 가 아니므로 배송비 부과 있을지 모르겠음 주문업체 단위로 배송되기 때문에 발생하지 않을것 같음
			if ((obj.ordAmt - obj.cnclRtnAmt) == 0) {
				if (obj.allCanYn == "N") {
					obj.addDelvFeeYn 	= "Y";
					obj.addDelvFee 		= obj.orgDelvFee;
				} else {
					// 전체취소의 경우에 해당
					obj.addDelvFeeYn 	= "N";
					obj.addDelvFee 		= 0;
				}
			} else {
				// 취소신청화면에서 대부분 아래의 조건에 해당
				obj.addDelvFeeYn 	= "Y";
				obj.addDelvFee 		= obj.orgDelvFee;
			}
			
			//obj.addDelvFeeYn 	= "Y";
			//obj.addDelvFee 		= obj.orgDelvFee;
		} else {
			obj.addDelvFeeYn 	= "N";
			obj.addDelvFee 		= 0;
		}
		
		spanSumDeliveryFee	+= obj.delvFee;
		spanOrdAmt			+= obj.ordAmt;
		spanCnclRtnAmt		+= obj.cnclRtnAmt;
		spanTotDeliveryFee  += obj.addDelvFee;
				
		delvFeeList[i] = obj;
	}

	gridOptionsCancelReqToBeList.api.setRowData(cancelRequestTargetToBeList);
	gridOptionsDelvCdList.api.setRowData(delvFeeList);
	
	// 환불금액표시
	spanPayAmt 			= spanSumRealOrdAmt + spanSumDeliveryFee;
	spanTotPntDcAmt 	= spanPntDcAmt + spanPrePntDcAmt;
	spanCpnDcAmt 		= spanCpn1DcAmt + spanGoodsCpnDcAmt + spanCartCpnDcAmt;
	spanTmtbDcAmt 		= spanTmtb1DcAmt + spanTmtb2DcAmt;
	spanRefundAmt 		= spanRealCnclRtnAmt - spanTotDeliveryFee;
	
	$("#spanPayAmt").text(spanPayAmt.addComma());					//총 결제 금액
	$("#spanSumRealOrdAmt").text(spanSumRealOrdAmt.addComma());		//상품 실결제 금액
	$("#spanSumDeliveryFee").text(spanSumDeliveryFee.addComma());	//배송금액
	
	$("#spanOrdAmt").text(spanOrdAmt.addComma());					//주문 상품 금액
	$("#spanCnclRtnAmt").text(spanCnclRtnAmt.addComma());			//취소 상품 금액
	
	$("#spanTotPntDcAmt").text(spanTotPntDcAmt.addComma());			//취소 사용 포인트
	$("#spanPntDcAmt").text(spanPntDcAmt.addComma());				//고객 포인트
	$("#spanPrePntDcAmt").text(spanPrePntDcAmt.addComma());			//상품 선포인트
	
	$("#spanCpnDcAmt").text(spanCpnDcAmt.addComma());				//취소 사용 쿠폰금액
	$("#spanCpn1DcAmt").text(spanCpn1DcAmt.addComma());				//즉시할인쿠폰
	$("#spanGoodsCpnDcAmt").text(spanGoodsCpnDcAmt.addComma());		//상품쿠폰
	$("#spanCartCpnDcAmt").text(spanCartCpnDcAmt.addComma());		//장바구니쿠폰
	
	$("#spanTmtbDcAmt").text(spanTmtbDcAmt.addComma());				//취소 다다익선 금액
	$("#spanTmtb1DcAmt").text(spanTmtb1DcAmt.addComma());			//수량할인
	$("#spanTmtb2DcAmt").text(spanTmtb2DcAmt.addComma());			//금액할인
	
	$("#spanGfcdUseAmt").text(spanGfcdUseAmt.addComma());			//취소 고객 상품권 금액
	
	$("#spanRealCnclRtnAmt").text(spanRealCnclRtnAmt.addComma());	//취소 상품 실결제 금액
	$("#spanTotDeliveryFee").text(spanTotDeliveryFee.addComma());	//환불 배송 금액
	
	$("#spanRefundAmt").text(spanRefundAmt.addComma());				//환불 금액 합계
	*/
	
	// 환불금액계산호출
	var jsonData = JSON.stringify(cancelRequestTargetList);
	gagajf.ajaxJsonSubmit(
		'/order/cancel/refundAmt'
		, jsonData
		, function(result) {
			gridOptionsCancelReqToBeList.api.setRowData(result.cancelOrderRefundList);
			gridOptionsDelvCdList.api.setRowData(result.cancelDelvRefundList);
			
			$("#spanPayAmt").text(result.spanPayAmt.addComma());					//총 결제 금액
			$("#spanSumRealOrdAmt").text(result.spanSumRealOrdAmt.addComma());		//상품 실결제 금액
			$("#spanSumDeliveryFee").text(result.spanSumDeliveryFee.addComma());	//배송금액
			
			$("#spanOrdAmt").text(result.spanOrdAmt.addComma());					//주문 상품 금액
			$("#spanCnclRtnAmt").text(result.spanCnclRtnAmt.addComma());			//취소 상품 금액
			
			$("#spanTotPntDcAmt").text(result.spanTotPntDcAmt.addComma());			//취소 사용 포인트
			$("#spanPntDcAmt").text(result.spanPntDcAmt.addComma());				//고객 포인트
			$("#spanPrePntDcAmt").text(result.spanPrePntDcAmt.addComma());			//상품 선포인트
			
			$("#spanCpnDcAmt").text(result.spanCpnDcAmt.addComma());				//취소 사용 쿠폰금액
			$("#spanCpn1DcAmt").text(result.spanCpn1DcAmt.addComma());				//즉시할인쿠폰
			$("#spanGoodsCpnDcAmt").text(result.spanGoodsCpnDcAmt.addComma());		//상품쿠폰
			$("#spanCartCpnDcAmt").text(result.spanCartCpnDcAmt.addComma());		//장바구니쿠폰
			
			$("#spanTmtbDcAmt").text(result.spanTmtbDcAmt.addComma());				//취소 다다익선 금액
			$("#spanTmtb1DcAmt").text(result.spanTmtb1DcAmt.addComma());			//수량할인
			$("#spanTmtb2DcAmt").text(result.spanTmtb2DcAmt.addComma());			//금액할인
			
			$("#spanGfcdUseAmt").text(result.spanGfcdUseAmt.addComma());			//취소 고객 상품권 금액
			
			$("#spanRealCnclRtnAmt").text(result.spanRealCnclRtnAmt.addComma());	//취소 상품 실결제 금액
			$("#spanTotDeliveryFee").text(result.spanTotDeliveryFee.addComma());	//환불 배송 금액
			
			$("#spanRefundAmt").text(result.spanRefundAmt.addComma());				//환불 금액 합계
			
			//alert("a");
			//$('#btnSearch').trigger('click');
		}
	);
}

//  사유
var fnChangeChgReason = function(reasonCd){
	var arrREasonCd = reasonCd.split(":");
	
	// 취소, 반품, 교환 사유 판단
	if (arrREasonCd[0] == 'G686_10') {
		$("#imputeReason").text("고객");
		isImputationCustomers = true;
	} else {
		$("#imputeReason").text("회사");
		isImputationCustomers = false;
	}

	$('#cancelRequestFrm input[name=chgReason]').val(arrREasonCd[0]);
	$('#cancelRequestFrm input[name=chgReasonDesc]').val(arrREasonCd[1]);

	//fnCalculateRefundAmt();			//환불예정금액 계산.
}

// 에스크로 전체취소, 부분취소 요청
var fnCancelRequestPartOk = function () {
	// 취소, 반품, 교환 신청 정보 목록
	//cancelRequestTargetList;
	
	var jsonData = JSON.stringify(cancelRequestTargetList);
	
	gagajf.ajaxJsonSubmit(
		'/order/cancel/'
		, jsonData
		, function() {
			$('#btnSearch').trigger('click');
		}
	);
	
}

$(document).ready(function() {	
	// Create a agGrid
	gagaAgGrid.createGrid('gridOrderCancelRequestList'		, gridOptionsCancelReqList);			// 주문정보
	gridOptionsCancelReqList.api.setRowData(cancelRequestTargetList);
	
	gagaAgGrid.createGrid('gridOrderCancelRequestToBeList'	, gridOptionsCancelReqToBeList);		// 취소정보
	
	gagaAgGrid.createGrid('gridDelvCdList'					, gridOptionsDelvCdList);				// 배송비 정보
	
	// 취소정보계산
	fnCalculateRefundAmt(null);
});
</script>
</html>





