<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragments/header :: header"></head>
<body>
<th:block th:replace="common/fragments/variables :: variables"></th:block>

<!--
 *******************************************************************************
 * @source  : PosMainForm.html
 * @desc    : POS Main Page
 *============================================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.13   moon        최초 작성
 *******************************************************************************
 -->

<div id="main">
		<!-- TITLE -->
		<div class="main-title">
		</div>
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
	
		<!-- TABS SPACE -->
		<div class="tabs">
			<!-- TABS NAVI -->
			<ul class="tabsNav p-left">
				<li class="on"><a href="#tab1#top" id="tab1-1">출고대기목록</a></li>
				<li><a href="#tab2#top">출고목록</a></li>
				<li><a href="#tab2-1#top">확정대기목록</a></li>
				<li><a href="#tab4#top">출고거부이력</a></li>
			</ul>
			<!-- //TABS NAVI -->
			<!-- TABS CONTENTS -->
			<ul class="tabsCont">
				<!-- TAB1 : 출고대기목록 -->
				<li class="tab on" id="tab1">
					<div class="panelStyle">
					<!-- TAB2 CONTENTS AREA -->
					<form id="waitingOrder">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
						<input type="hidden" name="delvFeeRate" th:value="${delvFeeRate}">
						<input type="hidden" name="supplyCompCd" th:value="${supplyCompCd}">
						<input type="hidden" name="delvArGb" value="P"/>
						<input type="hidden" name="ordDtlStat" value="G013_35"/>
						<input type="hidden" name="ordDtlNos">
							<h4>출고대기</h4>
							<table class="frmStyle">
								<colgroup>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col/>
								</colgroup>
								<tbody>
								<tr>
									<th>주문번호</th>
									<td><input type="text" class="w300" name="ordNo"/></td>
									<th>수령자</th>
									<td colspan="5"><input type="text" class="w300" name="recipNm" maxlength="10"/></td>
								</tr>
								<tr>
									<th>조회기간</th>
									<td colspan="5" id="waitTerms"></td>
								</tr>
								</tbody>
							</table>
							<ul class="panelBar">
								<li class="center">
									<button type="button" class="btn btn-base btn-lg" id="btnWaitSearch">조회</button>
									<!-- <button type="button" class="btn btn-base btn-lg" id="btnCnplus">Cnplus엑셀다운로드</button>  -->
								</li>
							</ul>
							
						<div id="watingGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh60" ></div>

						<!-- //TAB2 CONTENTS AREA -->
					</form>
					</div>
				</li>
				<!-- //TAB1 : 출고대기목록 -->
				<!-- TAB2 : 출고목록 -->
				<li class="tab" id="tab2">
					<div class="panelStyle">
					<!-- TAB2 CONTENTS AREA -->
					<form id="deliveryInfo">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
						<input type="hidden" name="delvFeeRate" th:value="${delvFeeRate}">
						<input type="hidden" name="supplyCompCd" th:value="${supplyCompCd}">
						<input type="hidden" name="delvArGb" value="Y"/>
						<input type="hidden" name="ordDtlNos">

							<h4>출고목록</h4>
							<table class="frmStyle">
								<colgroup>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col/>
								</colgroup>
								<tbody>
								<tr>
									<th>주문번호</th>
									<td><input type="text" class="w300" name="ordNo"/></td>
									<th>수령자</th>
									<td><input type="text" class="w300" name="recipNm" maxlength="10"/></td>
									<th>주문상세상태</th>
									<td>
										<select class="w150" name="ordDtlStat">
											<option value="all">전체</option>
											<option value="G013_30" selected>상품준비중</option>
											<option value="G013_40">배송준비중</option>
										</select>
									</td>
								</tr>
								<tr>
									<th>조회기간</th>
									<td colspan="5" id="deliveryTerms"></td>
								</tr>
								</tbody>
							</table>
							<ul class="panelBar">
								<li class="center">
								<button type="button" class="btn btn-base btn-lg" id="btnDeliveySearch">조회</button>
								<button type="button" class="btn btn-base btn-lg" id="btnReCnplus">Cnplus엑셀다운로드</button>
								<button type="button" class="btn btn-base btn-lg" id="btnDeliveySave">송장번호저장</button>
								</li>
							</ul>
							<label class="off">
								<a href="javascript:void(0);" id="deliveryExcelList" style="display: none;">송장생성된주문 Cnplus엑셀다운로드</a>
							</label>
							<div id="deliveryGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh60" ></div>
				
						<!-- //TAB2 CONTENTS AREA -->
					</form>
					</div>
				</li>
				<!-- //TAB2 : 출고목록 -->
				
				<!-- TAB2-1 : 확정대기목록 -->
				<li class="tab" id="tab2-1">
					<div class="panelStyle">
					<!-- TAB2-1 CONTENTS AREA -->
					<form id="confirmation">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
						<input type="hidden" name="delvFeeRate" th:value="${delvFeeRate}">
						<input type="hidden" name="supplyCompCd" th:value="${supplyCompCd}">
						<input type="hidden" name="ordDtlNos">
						<input type="hidden" name="delvArGb" value="Y"/>

							<h4>확정대기목록</h4>
							<table class="frmStyle">
								<colgroup>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col/>
								</colgroup>
								<tbody>
								<tr>
									<th>주문번호</th>
									<td><input type="text" class="w300" name="ordNo"/></td>
									<th>수령자</th>
									<td><input type="text" class="w300" name="recipNm" maxlength="10"/></td>
									<th>주문상세상태</th>
									<td>
										<select class="w150" name="ordDtlStat">
											<option value="all">전체</option>
											<option value="G013_40" selected>배송준비중</option>
											<option value="G013_50">배송중</option>
											<option value="G013_60">배송완료</option>
										</select>
									</td>
								</tr>
								<tr>
									<th>조회기간</th>
									<td colspan="5" id="confirmTerms"></td>
								</tr>
								</tbody>
							</table>
							<ul class="panelBar">
								<li class="center">
								<button type="button" class="btn btn-base btn-lg" id="btnConfirmSearch">조회</button>
								<button type="button" class="btn btn-base btn-lg" id="btnConfirmSave">출고확정</button>
								</li>
							</ul>
							<div id="confirmGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh60" ></div>
				
						<!-- //TAB2-1 CONTENTS AREA -->
					</form>
					</div>
				</li>
				<!-- //TAB2-1 : 확정대기목록 -->				
				
				<!-- TAB3 : 정산 내역 
				<li class="tab" id="tab3" >
					<div class="panelStyle">

					<form id="usacList">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
						<input type="hidden" name="delvFeeRate" th:value="${delvFeeRate}">
						<input type="hidden" name="supplyCompCd" th:value="${supplyCompCd}">
							<h4>정산 내역</h4>
							<table class="frmStyle">
								<colgroup>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col style="width:23%;"/>
									<col style="width:10%;"/>
									<col/>
								</colgroup>
								<tbody>
								<tr>
									<th>조회기간</th>
									<td colspan="3" id="usacTerms"></td>
								</tr>
								</tbody>
							</table>
							<ul class="panelBar">
								<li class="center">
								<button type="button" class="btn btn-base btn-lg" id="btnSearchUsac">조회</button>
								</li>
							</ul>
							<div id="usacGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh60" ></div>
					</form>
					</div>

				</li>
				//TAB3 : 정산 내역 -->
				<!-- TAB4 : 출고거부 내역 -->
				<li class="tab" id="tab4">
					<div class="panelStyle">
					<!-- TAB4 CONTENTS AREA -->
					<form id="banDelv">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
						<input type="hidden" name="delvFeeRate" th:value="${delvFeeRate}">
						<input type="hidden" name="supplyCompCd" th:value="${supplyCompCd}">
							<h4>출고거부 내역</h4>
							<table class="frmStyle">
								<colgroup>
									<col style="width:10%;"/>
									<col style="width:80%;"/>
									<col style="width:10%;"/>
									<col/>
								</colgroup>
								<tbody>
								<tr>
									<th>상품코드</th>
									<td><input type="text" class="w300" id="goodsCd" name="goodsCd"/></td>
								</tr>
								<tr>
									<th>조회기간</th>
									<td colspan="3" id="banDelvTerms"></td>
								</tr>
								</tbody>
							</table>
							<ul class="panelBar">
								<li class="center">
								<button type="button" class="btn btn-base btn-lg" id="btnBanDelvSearch">조회</button>
								</li>
							</ul>
							<div id="banDelvGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh60" ></div>
					
					</form>
					</div>
					<!-- //TAB4 CONTENTS AREA -->
				</li>
				<!-- //TAB4 : 출고거부 내역 -->
			</ul>
			<!-- //TABS CONTENTS -->
	
		<!-- //TABS SPACE -->
	</div>
</div>

<script th:inline="javascript">
	/*<![CDATA[*/
	var goodsImgParam    = "?width=60&height=60";
	var goodsImgBigParam = "?width=600&height=600";
	var delvarGbList     =  {"P" : "출고대기", "Y" : "출고수락", "N" : "출고거부"};
	var uploadGoodsUrl   = [[${@environment.getProperty('upload.goods.view')}]];
	var shipCompanyList  =  gagajf.convertToArray([[${shipCompanyList}]]);
	var orderDtlSateList =  gagajf.convertToArray([[${orderDtlSateList}]]);

	var g300Init = {'cd' :'0', 'cdNm' :'[선택]'};
	var g300ObjectList = [[${g300List}]];
	g300ObjectList.push(g300Init);
	var g300List       =  gagajf.convertToArray(g300ObjectList);
	delete g300List["G300_90"];
	delete g300List["G300_40"];
	
	var delvLocCd = [[${delvLocCd}]]; 
	
	//출고대기 그리드
	var columnwatingApplyDefs = [

		{headerName: "수락", field: "delvArGbY", width: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				var btnText = '';
				if(params.value === 'P'){
					btnText = '<button type="button"class="btn btn-success" onClick="fnApplyDelvLoc(\''+params.data.ordNo+'\',\''+params.data.ordDtlNo+'\',\''+params.data.ordQty+'\',\''+params.data.goodsType+'\')"> 수락 </button>';
				}
				return btnText;
			}
		},
		{headerName: "거부", field: "delvArGbN", width: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				var btnText = '';
				if(params.value === 'P') {
					btnText = '<button type="button"class="btn btn-success" onClick="javascript:void(0);"> 거부 </button>';
				}
				return btnText;
			}
		},
		{headerName: "거부사유", field: "rejectReason", width: 80, minWidth: 75, cellClass: 'text-center', sortable: true ,
			cellEditor: 'agSelectCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat === 'G013_35' && params.data.delvArGb === 'P') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(g300List) },
			valueFormatter: function (params) {
				var dataValue = '0';
				if(!gagajf.isNull(params.value)) {
					dataValue = params.value;
				}
				return gagaAgGrid.lookupValue(g300List, dataValue);
			},
			valueParser: function (params) { return gagaAgGrid.lookupKey(g300List, params.newValue); },
			singleClickEdit: true
		},
		{
			headerName: "출고여부", field: "delvArGb", width: 130, cellClass: 'text-center' ,
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(delvarGbList, params.value); },
		},
		{headerName: "이미지", field: "imgPath1", width: 100, height: 60, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
			}
		},
		{headerName: "상품명", field: "goodsNm", width: 200, cellClass: 'text-left'},
		{headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center' },
		{headerName: "컬러", field: "optCd1", width: 85, cellClass: 'text-center' },
		{headerName: "사이즈", field: "optCd2", width: 85, cellClass: 'text-center' },
		{headerName: "주문수량",  field: "saleQty", width: 80, cellClass: 'text-center',
			valueFormatter: function(params) {return params.value.addComma();}
		},
		{headerName: "주문번호", field: "ordNo", width: 90, cellClass: 'text-center'},
		{headerName: "주문상세번호", field: "ordDtlNo", width: 90, cellClass: 'text-center', hide: true},
		{headerName: "주문일시", field: "ordDt", width: 150, cellClass: 'text-center',
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{headerName: "주문자", field: "ordNm", width: 130, cellClass: 'text-center' },
		{headerName: "수령자", field: "recipNm", width: 130, cellClass: 'text-center'},
		{headerName: "송장번호", field: "invoiceNo", width: 120, cellClass: 'text-center'},
		{headerName: "우편번호", field: "recipZipcode", width: 90, cellClass: 'text-center'},
		{headerName: "주소", field: "recipAddr", width: 450, cellClass: 'text-left'},
		{headerName: "전화번호", field: "recipPhnno", width: 120, cellClass: 'text-center'},
		{headerName: "배송메모", field: "delvMemo", width: 120, cellClass: 'text-center'}


	];

	//출고그리드
	var columnDeliveryDefs= [
		{width: 40, minWidth: 40, cellClass: 'text-right', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "송장번호", field: "invoiceNo", width: 120, cellClass: 'text-center',
			cellEditor: 'textCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat == 'G013_30' && params.data.delvArGb == 'Y') ? true : false;},
			cellEditorParams: { maxlength: 15 }
		},

		{headerName: "택배사", field: "shipCompCd", width: 100, minWidth: 75, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat == 'G013_30' && params.data.delvArGb == 'Y') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(shipCompanyList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(shipCompanyList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(shipCompanyList, params.newValue); }
		},

		{headerName: "이미지", field: "imgPath1", width: 100, height: 60, cellClass: 'text-center', 
			cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
			}		
		},
		{headerName: "상품명", 	field: "goodsNm", width: 200, cellClass: 'text-left', editable :false},
		{headerName: "상품코드", 	field: "goodsCd", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "컬러", 		field: "optCd1", width: 85, cellClass: 'text-center' , editable :false},
		{headerName: "사이즈", 	field: "optCd2", width: 85, cellClass: 'text-center' , editable :false},
		{headerName: "주문수량",  field: "saleQty", width: 80, cellClass: 'text-center', editable :false,
			valueFormatter: function(params) {return params.value.addComma();}
		},
		{headerName: "주문번호", field: "ordNo", width: 90, cellClass: 'text-center', editable :false},
		{headerName: "주문상세번호", field: "ordDtlNo", width: 90, cellClass: 'text-center', editable :false},
		{headerName: "주문상세상태", field: "ordDtlStat", width: 130, cellClass: 'text-center', editable :false,
			cellEditorParams: { values: gagaAgGrid.extractValues(orderDtlSateList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(orderDtlSateList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(orderDtlSateList, params.newValue); }
		},
		{headerName: "주문상세번호", field: "ordDtlNo", width: 90, cellClass: 'text-center', hide: true, editable :false},
		{
			headerName: "주문일시", field: "ordDt", width: 150, cellClass: 'text-center', editable :false,
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{
			headerName: "출고일시", field: "delvStdt", width: 150, cellClass: 'text-center', editable :false,
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{headerName: "주문자", field: "ordNm", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "수령자", field: "recipNm", width: 130, cellClass: 'text-center', editable :false},
		{headerName: "우편번호", field: "recipZipcode", width: 90, cellClass: 'text-center'},
		{headerName: "주소", field: "recipAddr", width: 450, cellClass: 'text-left'},
		{headerName: "전화번호", field: "recipPhnno", width: 120, cellClass: 'text-center'},
		{headerName: "배송메모", field: "delvMemo", width: 120, cellClass: 'text-center'},

		{headerName: "수락취소", field: "delvArGbCnl", width: 120, cellClass: 'text-center',
			cellRenderer: function(params) {
				var btnText = '';
				if(params.value === 'Y') {
					// btnText= '<a href="javascript:void(0);"  class="btn btn-success btn-lg">수락취소</a>';
					btnText= '<button type="button"class="btn btn-success" onClick="javascript:void(0);"> 수락취소 </button>';
				}
				return btnText;
			}
		},
		{headerName: "거부사유", field: "rejectReason", width: 100, minWidth: 75, cellClass: 'text-center', sortable: true ,
			cellEditor: 'agSelectCellEditor',
			editable : function (params) { return  ((params.data.ordDtlStat == 'G013_30' || params.data.ordDtlStat == 'G013_40') && params.data.delvArGb == 'Y') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(g300List) },
			valueFormatter: function (params) {
				var dataValue = '0';
				if(!gagajf.isNull(params.value)) {
					dataValue = params.value;
				}
				return gagaAgGrid.lookupValue(g300List, dataValue);
			},
			valueParser: function (params) { return gagaAgGrid.lookupKey(g300List, params.newValue); },
			singleClickEdit: true
		}

	];

	//확정대기 그리드
	var columnConfirmDefs= [
		{width: 40, minWidth: 40, cellClass: 'text-right', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "송장번호", field: "invoiceNo", width: 120, cellClass: 'text-center',
			cellEditor: 'textCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat == 'G013_30' && params.data.delvArGb == 'Y') ? true : false;},
			cellEditorParams: { maxlength: 15 }
		},

		{headerName: "택배사", field: "shipCompCd", width: 100, minWidth: 75, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat == 'G013_30' && params.data.delvArGb == 'Y') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(shipCompanyList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(shipCompanyList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(shipCompanyList, params.newValue); }
		},

		{headerName: "이미지", field: "imgPath1", width: 100, height: 60, cellClass: 'text-center', 
			cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
			}		
		},
		{headerName: "상품명", 	field: "goodsNm", width: 200, cellClass: 'text-left', editable :false},
		{headerName: "상품코드", 	field: "goodsCd", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "컬러", 		field: "optCd1", width: 85, cellClass: 'text-center' , editable :false},
		{headerName: "사이즈", 	field: "optCd2", width: 85, cellClass: 'text-center' , editable :false},
		{headerName: "주문수량",  field: "saleQty", width: 80, cellClass: 'text-center', editable :false,
			valueFormatter: function(params) {return params.value.addComma();}
		},
		{headerName: "주문번호", field: "ordNo", width: 90, cellClass: 'text-center', editable :false},
		{headerName: "주문상세번호", field: "ordDtlNo", width: 90, cellClass: 'text-center', editable :false},
		{headerName: "주문상세상태", field: "ordDtlStat", width: 130, cellClass: 'text-center', editable :false,
			cellEditorParams: { values: gagaAgGrid.extractValues(orderDtlSateList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(orderDtlSateList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(orderDtlSateList, params.newValue); }
		},
		{headerName: "주문상세번호", field: "ordDtlNo", width: 90, cellClass: 'text-center', hide: true, editable :false},
		{
			headerName: "주문일시", field: "ordDt", width: 150, cellClass: 'text-center', editable :false,
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{
			headerName: "출고일시", field: "delvStdt", width: 150, cellClass: 'text-center', editable :false,
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{headerName: "주문자", field: "ordNm", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "수령자", field: "recipNm", width: 130, cellClass: 'text-center', editable :false},
		{headerName: "우편번호", field: "recipZipcode", width: 90, cellClass: 'text-center'},
		{headerName: "주소", field: "recipAddr", width: 450, cellClass: 'text-left'},
		{headerName: "전화번호", field: "recipPhnno", width: 120, cellClass: 'text-center'},
		{headerName: "배송메모", field: "delvMemo", width: 120, cellClass: 'text-center'},

	];

	
	//정산내역 그리드
	/*
	var columnUsacDefs = [
		{headerName: "이미지", field: "imgPath1", width: 100, height: 60, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
			}
		},
		{headerName: "상품명", field: "goodsNm", width: 200, cellClass: 'text-left'},
		{headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center' },
		{headerName: "사이즈", field: "sizeCd", width: 85, cellClass: 'text-center' },
		{
			headerName: "출고수량", field: "ordQty", width: 80, cellClass: 'text-right',
			valueFormatter: function(params) {return params.value.addComma();}
		},
		{
			headerName: "발생일시", field: "occurDt", width: 150, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{
			headerName: "출고일시", field: "delvStdt", width: 150, cellClass: 'text-center',
		    cellRenderer: function (params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{headerName: "출고구분", field: "usacGbNm", width: 100, cellClass: 'text-center' },
		{headerName: "실결제금액", field: "realAmt", width: 95, cellClass: 'text-right'
			,valueFormatter: function(params) {
				return params.value.addComma();
			}
		},
		{headerName: "수수료율", field: "delvFeeRate", width: 95, cellClass: 'text-right'
			,cellRenderer: function(params) {
				return params.value === 0 ? '': params.value+'%';
			}
		},
		{headerName: "수수료", field: "delvFeeAmt", width: 95, cellClass: 'text-right'
			,valueFormatter: function(params) {
				return params.value.addComma();
			}
		},
		{headerName: "주문번호", field: "ordNo", width: 90, cellClass: 'text-center'},
		{headerName: "주문상세", field: "ordDtlNo", width: 90, cellClass: 'text-center', hide: true}
	];
	*/
	//출고거부 이력 그리드
	var columnBanDelvDefs = [
		{headerName: "이미지", field: "imgPath1", width: 100, height: 60, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
			}
		},
		{headerName: "거부일시", field: "delvBanStdt", width: 150, cellClass: 'text-center'
		},
		{headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center'},
		{headerName: "컬러", field: "optCd1", width: 80, cellClass: 'text-center'},
		{headerName: "사이즈", field: "optCd2", width: 80, cellClass: 'text-center'},
		{headerName: "주문번호", field: "ordNo", width: 100, cellClass: 'text-center'},
		{headerName: "거부사유", field: "rejectReason", width: 100, cellClass: 'text-center'}
	];

	var gridWaitingOptions = gagaAgGrid.getGridOptions(columnwatingApplyDefs);
	var gridDeliveryOptions = gagaAgGrid.getGridOptions(columnDeliveryDefs);
	var gridConfirmOptions = gagaAgGrid.getGridOptions(columnConfirmDefs);
	//var gridUsacOptions = gagaAgGrid.getGridOptions(columnUsacDefs);
	var gridBanDelvOptions = gagaAgGrid.getGridOptions(columnBanDelvDefs);
	
	gridWaitingOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.
	gridDeliveryOptions.rowHeight = 60;
	gridConfirmOptions.rowHeight = 60;
	//gridUsacOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.
	gridBanDelvOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.

	//gridDeliveryOptions.rowSelection = 'multiple';
	//gridWaitingOptions.rowSelection = 'multiple';

	gridDeliveryOptions.defaultColDef.editable = true;
	gridDeliveryOptions.stopEditingWhenGridLosesFocus = true;
	gridWaitingOptions.isRowSelectable = function(rowNode) {
		return rowNode.data.delvArGb == 'Y';
	}

	// 출고대기 주문조회
	$('#btnWaitSearch').on('click', function () {
		if(!gagajf.validation('#waitingOrder'))
			return;
		gagaAgGrid.fetch('/pos/wait/order/list',gridWaitingOptions, '#waitingOrder');
	});

	// 출고조회
	$('#btnDeliveySearch').on('click', function () {
		if(!gagajf.validation('#deliveryInfo'))
			return;
		gagaAgGrid.fetch('/pos/delivery/order/list',gridDeliveryOptions, '#deliveryInfo');
	});
	
	// 확정대기 조회
	$('#btnConfirmSearch').on('click', function () {
		if(!gagajf.validation('#confirmation'))
			return;
		gagaAgGrid.fetch('/pos/confirm/order/list',gridConfirmOptions, '#confirmation');
	});
	

	// 정산내역 조회
	/*
	$('#btnSearchUsac').on('click', function () {
		gagaAgGrid.fetch('/pos/usac/list',gridUsacOptions, '#usacList');
	});
	*/

	// 출고거부 조회
	$('#btnBanDelvSearch').on('click', function () {
		gagaAgGrid.fetch('/pos/ban/delivery/list',gridBanDelvOptions, '#banDelv');
	});

	var fnSetDelvCallback = function() {
		$('#tab1').trigger('click');
		$('#btnWaitSearch').trigger('click');
	};

	var fnCancelCallback = function() {
		$('#tab2').trigger('click');
		$('#btnDeliveySearch').trigger('click');
	};


	// 출고수락
	var fnApplyDelvLoc = function(ordNo, ordDtlNo, ordQty, goodsType) {
		
		var params = {};
		params.ordNo     = ordNo;
		params.ordDtlNo  = ordDtlNo;
		params.delvLocCd = delvLocCd;
		params.ordQty    = ordQty
		params.delvArGb  = 'Y';  // 수락
		
		var msg ="";
		if("G056_S" == goodsType){
			msg ="세트상품입니다.<br>관련상품 모두 출고수락 하시겠습니까?";
		} else {
			msg ="출고수락 하시겠습니까?";
		}
		mcxDialog.confirm(msg, {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				var jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/pos/delivery/assign/save', jsonData, fnSetDelvCallback);
			}
		});			
	};

	// 출고거부
	gridWaitingOptions.onCellClicked = function(event) {
		if (event.colDef.field == 'delvArGbN' && event.data.delvArGb == 'P'){
			if(gagajf.isNull(event.data.rejectReason) || event.data.rejectReason === '0'){
				mcxDialog.alert('거부 사유를 선택해주세요.');
			} else {
				var params = {};
				params.ordNo        = event.data.ordNo;
				params.ordDtlNo     = event.data.ordDtlNo;
				params.delvLocCd    = delvLocCd;
				params.ordQty       = event.data.ordQty
				params.delvArGb     = 'N';  // 거부
				params.rejectReason = event.data.rejectReason;
				
				var msg = "";
				if("G056_S" == event.data.goodsType){
					msg = "세트상품입니다.<br>관련상품 모두 거부 하시겠습니까?";
				} else {
					msg = "거부 하시겠습니까?";
				}
				
				mcxDialog.confirm(msg, {
					cancelBtnText: "취소",
					sureBtnText: "확인",
					sureBtnClick: function(){
						var jsonData = JSON.stringify(params);
						gagajf.ajaxJsonSubmit('/pos/delivery/assign/save', jsonData, fnSetDelvCallback);
					}
				});
			}
		}
	}

	// 수락취소
	gridDeliveryOptions.onCellClicked = function(event) {
		if (event.colDef.field == 'delvArGbCnl' && (event.data.ordDtlStat == 'G013_30' || event.data.ordDtlStat == 'G013_40')){
			if(gagajf.isNull(event.data.rejectReason) || event.data.rejectReason === '0'){
				mcxDialog.alert('수락취소 사유를 선택해주세요.');
			} else {
				var params = {};
				params.ordNo = event.data.ordNo;
				params.ordDtlNo = event.data.ordDtlNo;
				params.delvLocCd = event.data.delvLocCd;
				params.ordQty    = event.data.ordQty
				params.delvArGb = 'N';  // 거부
				params.rejectReason = event.data.rejectReason;
				mcxDialog.confirm('수락취소 하시겠습니까?<br/> 다른출고처로 지정됩니다.', {
					cancelBtnText: "취소",
					sureBtnText: "확인",
					sureBtnClick: function(){
						var jsonData = JSON.stringify(params);
						gagajf.ajaxJsonSubmit('/pos/delivery/assign/save/cancel', jsonData, fnCancelCallback);
					}
				});
			}
		}
	}

	// Cnplus엑셀다운로드
	$('#btnReCnplus').on('click', function() {

		var selectedData = gagaAgGrid.selectedRowData(gridDeliveryOptions);
		var dataLength = selectedData.length;
		if (dataLength === 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
		var ordDtlNoArr = [];
		$.each(selectedData, function(idx, data) {
			if(!gagajf.isNull(data.ordDtlNo)) {
				ordDtlNoArr.push(data.ordDtlNo);
			}
		});

		$('#deliveryInfo input[name=ordDtlNos]').val(ordDtlNoArr.join(','));
		mcxDialog.confirm('CNPlus양식 엑셀 다운로드 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				fnExcelDownLoad('#deliveryInfo');
			}
		});
	});

	//엑셀다운로드
	var fnExcelDownLoad = function(formId) {
		var params =  $(formId).serialize();
		if(formId==='#waitingOrder') {
			$('#orderExcelList').attr({ href : '/pos/order/excel/list?' + params }).get(0).click();
		}
		if(formId==='#deliveryInfo') {
			$('#deliveryExcelList').attr({ href : '/pos/order/excel/list?' + params }).get(0).click();
		}
	};


	// 송장번호 등록 버튼
	$('#btnDeliveySave').on('click', function() {

		var selectData = gagaAgGrid.selectedRowData(gridDeliveryOptions);
		var dataLength = selectData.length;
		if (dataLength === 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}

		var selectedData = gridDeliveryOptions.api.getSelectedNodes();

		var chk ="Y";
		$.each(selectedData, function(idx, row) {

			if(!gagajf.isNull(row.data.ordDtlNo)) {
				// 송장번호 저장 완료건들 체크 풀기
				if(row.data.ordDtlStat =="G013_40" || row.data.ordDtlStat =="G013_50" || row.data.ordDtlStat =="G013_60" || row.data.ordDtlStat =="G013_70"){
					gridDeliveryOptions.api.deselectIndex(row.rowIndex);
				}

				if(row.data.shipCompCd == "D1029"){
					var invoNo = row.data.invoiceNo;

					//송장번호 자리수 체크 12자리
					var invoNoLen  = invoNo.length;
					if(invoNoLen != 12){
						mcxDialog.alert('['+invoNo+']은 잘못된 송장번호 형식입니다.');
						chk = "N";
						return false;
					}
					// 송장번호 유효성 체크 [ 앞2자리 제외하고 3번째자리부터 9개숫자를 7로나눈 나머지가 12번째 숫자임.]
					var invoNolast = invoNo.substring(11,12);
					var chkInvono = invoNo.substring(2,11);
					var invonoMod = chkInvono % 7 ;

					if(invoNolast != invonoMod ){
						mcxDialog.alert('['+invoNo+']은 잘못된 송장번호 형식입니다.');
						chk = "N";
						return false;
					}
				}

				if(gagajf.isNull(row.data.invoiceNo)){
					mcxDialog.alert('송장번호를 입력해 주세요.');
					chk = "N";
					return false;
				}
			}
		});


		var selectedData2 = gagaAgGrid.selectedRowData(gridDeliveryOptions);
		var dataLength2 = selectedData2.length;
		if (dataLength2 === 0) {
			mcxDialog.alert('이미 완료된 대상입니다.');
			return;
		}

		if(chk == "N") return false;
		mcxDialog.confirm('송장번호등록 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				fnSaveInvoice();
			}
		});

	});

	// 송장번호 등록
	var fnSaveInvoice = function(){
		var selectedData = gagaAgGrid.selectedRowData(gridDeliveryOptions);
		var dataLength = selectedData.length;
		if (dataLength === 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
		var ordDtlNoArr = [];
		$.each(selectedData, function(idx, data) {
			if(!gagajf.isNull(data.ordDtlNo)) {
				ordDtlNoArr.push(data.ordDtlNo);
			}
		});

		$('#deliveryInfo input[name=ordDtlNos]').val(ordDtlNoArr.join(','));
		var jsonData = JSON.stringify(selectedData);
		gagajf.ajaxJsonSubmit('/pos/invoice/save/invoiceno', jsonData, fnInvoiceCallback);
	}

	var fnInvoiceCallback = function() {
		$('#tab2').trigger('click');
		$('#btnDeliveySearch').trigger('click');
		mcxDialog.alert('입력이 완료되었습니다.<br>확정대기목록에서 출고확정 하세요.');
	};


	
	// 출고확정 
	$('#btnConfirmSave').on('click', function() {

		var selectData = gagaAgGrid.selectedRowData(gridConfirmOptions);
		var dataLength = selectData.length;
		if (dataLength === 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}

		var selectedData = gridConfirmOptions.api.getSelectedNodes();

		$.each(selectedData, function(idx, row) {

			if(!gagajf.isNull(row.data.ordDtlNo)) {
				// 출고확정 완료건들 체크 풀기
				if(row.data.ordDtlStat =="G013_50" || row.data.ordDtlStat =="G013_60" || row.data.ordDtlStat =="G013_70"){
					gridConfirmOptions.api.deselectIndex(row.rowIndex);
				}
			}
		});

		var selectedData2 = gagaAgGrid.selectedRowData(gridConfirmOptions);
		var dataLength2 = selectedData2.length;
		if (dataLength2 === 0) {
			mcxDialog.alert('이미 완료된 대상입니다.');
			return;
		}

		mcxDialog.confirm('출고확정 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				fnConfirmSave();
			}
		});

	});
	
	// 출고확정 저장 
	var fnConfirmSave = function(){
		var selectedData = gagaAgGrid.selectedRowData(gridConfirmOptions);
		var dataLength = selectedData.length;
		if (dataLength === 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
		var ordDtlNoArr = [];
		$.each(selectedData, function(idx, data) {
			if(!gagajf.isNull(data.ordDtlNo)) {
				ordDtlNoArr.push(data.ordDtlNo);
			}
		});

		$('#confirmation input[name=ordDtlNos]').val(ordDtlNoArr.join(','));
		var jsonData = JSON.stringify(selectedData);
		gagajf.ajaxJsonSubmit('/pos/confirm/save', jsonData, fnConfirmCallback);
	}
	
	// 출고확정 콜백 
	var fnConfirmCallback = function() {
		$('#tab2-1').trigger('click');
		$('#btnConfirmSearch').trigger('click');
		mcxDialog.alert('출고확정 되었습니다.');
	};
	

	$(document).ready(function() {
		
		gagaAgGrid.createGrid('watingGrid',  gridWaitingOptions);
		gagaAgGrid.createGrid('deliveryGrid',gridDeliveryOptions);
		gagaAgGrid.createGrid('confirmGrid',gridConfirmOptions);
		gagaAgGrid.createGrid('banDelvGrid', gridBanDelvOptions);
		
		
		
		
		cfnCreateCalendar('#deliveryTerms', 'deliveryStDate', 'deliveryEdDate', true, '조회');
		cfnCreateCalendar('#waitTerms',     'waitOrdStDate',  'waitOrdEdDate',  true, '조회');
		cfnCreateCalendar('#confirmTerms',  'confirmStDate',  'confirmEdDate', true, '조회');		
		cfnCreateCalendar('#banDelvTerms',  'banDelvStDate',  'banDelvEdDate',  true, '조회');

		
		 setTimeout(fnSetDate, 100);
		
		
		
	});

	var fnSetDate = function(){
		cfnChangeCalendar('2d', $('#deliveryStDate'), $('#deliveryEdDate'));
		cfnChangeCalendar('1d', $('#waitOrdStDate'), $('#waitOrdEdDate'));
		cfnChangeCalendar('2d', $('#confirmStDate'), $('#confirmEdDate'));
		cfnChangeCalendar('1m', $('#banDelvStDate'), $('#banDelvEdDate'));

		$('#btnWaitSearch').trigger('click');
	}

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