<!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" style="padding-top:0;">
		<!-- TITLE -->
		<div class="main-title">
			<h1>매장명 : <span th:text="${delvLocNm}"></span></h1>
		</div>
		<!-- //TITLE -->
	
		<!-- 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="#tab3#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="ordDtlStat" value="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><input type="text" class="w300" name="recipNm" maxlength="10"/></td>
									<th>출고여부</th>
									<td>
										<select class="w150" name="delvArGb">
											<option value="">전체</option>
											<option value="P">출고대기</option>
											<option value="Y">출고수락</option>
											<option value="N">출고거부</option>
										</select>
									</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 lh80" ></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="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="40" selected>배송준비중</option>
											<option value="50">배송중</option>
											<option value="60">배송완료</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>

							<div id="deliveryGrid" style="width: 99%; height: 500px;" class="ag-theme-balham lh80" ></div>
				
						<!-- //TAB2 CONTENTS AREA -->
					</form>
					</div>
				</li>
				<!-- //TAB2 : 출고대기목록 -->
				<!-- TAB3 : 정산 내역 -->
				<li class="tab" id="tab3">
					<div class="panelStyle">
					<!-- TAB3 CONTENTS AREA -->
					<form id="usacList">
						<input type="hidden" name="delvLocCd" th:value="${delvLocCd}">
							<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 lh80" ></div>
					</form>
					</div>
					<!-- //TAB3 CONTENTS AREA -->
				</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}">
							<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 lh80" ></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 g017Init = {'cd' :'0', 'cdNm' :'[선택]'};
	var g017ObjectList = [[${g017List}]];
	g017ObjectList.push(g017Init);
	var g017List       =  gagajf.convertToArray(g017ObjectList);
	delete g017List[90];
	delete g017List[40];


	//출고대기 그리드
	var columnwatingApplyDefs = [

		{headerName: "출고", field: "chulgo", width: 50, cellClass: 'text-center', headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true
			, checkboxSelection: function (params) {
				return  (params.data.ordDtlStat == '35' && params.data.delvArGb == 'Y') ? true : false;
			}
		},

		{headerName: "수락", field: "delvArGbY", width: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				var btnText = '';
				if(params.value === 'P'){
					btnText ='<a href="javascript:void(0);" onclick="fnApplyDelvLoc(\''+params.data.ordNo+'\',\''+params.data.ordDtlNo+'\')" class="btn btn-success btn-lg">수락</a>';
				}
				return btnText;
			}
		},
		{headerName: "거부", field: "delvArGbN", width: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				var btnText = '';
				if(params.value === 'P') {
					btnText= '<a href="javascript:void(0);"  class="btn btn-success btn-lg">거부</a>';

				}
				return btnText;
			}
		},
		{headerName: "거부사유", field: "rejectReason", width: 80, minWidth: 75, cellClass: 'text-center', sortable: true ,
			cellEditor: 'agSelectCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat === '35' && params.data.delvArGb === 'P') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(g017List) },
			valueFormatter: function (params) {
				var dataValue = '0';
				if(!gagajf.isNull(params.value)) {
					dataValue = params.value;
				}
				return gagaAgGrid.lookupValue(g017List, dataValue);
			},
			valueParser: function (params) { return gagaAgGrid.lookupKey(g017List, 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: 130, height: 80, cellClass: 'text-center',
			cellRenderer: function(params) {
				if (params.data.imgType != "B"){
					return '<img width="60" src="'+ uploadGoodsUrl+params.value + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value +'\')"/>';
				}else{
					return '<img width="60" src="'+ params.value+goodsImgParam + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value+goodsImgBigParam +'\')"/>';
				}
			}
		},
		{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-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: "orderNm", width: 130, cellClass: 'text-center' },
		{headerName: "수령자", field: "recipNm", width: 130, cellClass: 'text-center'},
		{headerName: "송장번호", field: "invoiceNo", width: 120, cellClass: 'text-center'},
		{headerName: "우편번호", field: "recipPostNo", 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 == '40' && 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 == '40' && 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: 130, height: 80, cellClass: 'text-center', editable :false,
			cellRenderer: function(params) {
				if (params.data.imgType != "B"){
					return '<img width="60" src="'+ uploadGoodsUrl+params.value + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value +'\')"/>';
				}else{
					return '<img width="60" src="'+ params.value+goodsImgParam + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value+goodsImgBigParam +'\')"/>';
				}
			}
		},
		{headerName: "상품명", field: "goodsNm", width: 200, cellClass: 'text-left', editable :false},
		{headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "사이즈", field: "sizeCd", width: 85, cellClass: 'text-center' , editable :false},
		{
			headerName: "주문수량",  field: "ordQty", 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: "orderNm", width: 130, cellClass: 'text-center' , editable :false},
		{headerName: "수령자", field: "recipNm", width: 130, cellClass: 'text-center', editable :false},
		{headerName: "우편번호", field: "recipPostNo", 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>';
				}
				return btnText;
			}
		},
		{headerName: "거부사유", field: "rejectReason", width: 100, minWidth: 75, cellClass: 'text-center', sortable: true ,
			cellEditor: 'agSelectCellEditor',
			editable : function (params) { return  (params.data.ordDtlStat === '40' && params.data.delvArGb === 'Y') ? true : false;},
			cellEditorParams: { values: gagaAgGrid.extractValues(g017List) },
			valueFormatter: function (params) {
				var dataValue = '0';
				if(!gagajf.isNull(params.value)) {
					dataValue = params.value;
				}
				return gagaAgGrid.lookupValue(g017List, dataValue);
			},
			valueParser: function (params) { return gagaAgGrid.lookupKey(g017List, params.newValue); },
			singleClickEdit: true
		}

	];

	//정산내역 그리드
	var columnUsacDefs = [
		{headerName: "이미지", field: "imgPath1", width: 130, height: 80, cellClass: 'text-center',
			cellRenderer: function(params) {
				if (params.data.imgType != "B"){
					return '<img width="60" src="'+ uploadGoodsUrl+params.value + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value +'\')"/>';
				}else{
					return '<img width="60" src="'+ params.value+goodsImgParam + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value+goodsImgBigParam +'\')"/>';
				}
			}
		},
		{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: 130, height: 80, cellClass: 'text-center',
			cellRenderer: function(params) {
				if (params.data.imgType != "B"){
					return '<img width="60" src="'+ uploadGoodsUrl+params.value + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value +'\')"/>';
				}else{
					return '<img width="60" src="'+ params.value+goodsImgParam + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \''+ params.value+goodsImgBigParam +'\')"/>';
				}
			}
		},
		{headerName: "거부일시", field: "delvBanStdt", width: 150, cellClass: 'text-center'
		},
		{headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center'},
		{headerName: "사이즈", field: "sizeCd", 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 gridUsacOptions = gagaAgGrid.getGridOptions(columnUsacDefs);
	var gridBanDelvOptions = gagaAgGrid.getGridOptions(columnBanDelvDefs);
	gridWaitingOptions.rowHeight = 80; //이미지가 있을경우 높이 지정해야함.
	gridDeliveryOptions.rowHeight = 80;
	gridUsacOptions.rowHeight = 80; //이미지가 있을경우 높이 지정해야함.
	gridBanDelvOptions.rowHeight = 80; //이미지가 있을경우 높이 지정해야함.

	//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');
	});

	// 정산내역 조회
	$('#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-1').trigger('click');
		$('#btnWaitSearch').trigger('click');
	};

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


	// 출고수락
	var fnApplyDelvLoc = function(ordNo, ordDtlNo) {
		var params = {};
		params.ordNo = ordNo;
		params.ordDtlNo = ordDtlNo;
		params.delvArGb = 'Y';  // 수락
		mcxDialog.confirm('출고수락 하시겠습니까?', {
			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'){
			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.delvArGb = 'N';  // 거부
				params.rejectReason = event.data.rejectReason;
				mcxDialog.confirm('거부 하시겠습니까?', {
					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 == '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.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);
					}
				});
			}
		}
	}



	/*
	// 출고거부
	var fnBanDelivery = function(ordNo, ordDtlNo) {
		// 거부사유 팝업 선택 후 저장


		var params = {};
		params.ordNo = ordNo;
		params.ordDtlNo = ordDtlNo;
		params.delvArGb = 'N';  // 거부
		mcxDialog.confirm('거부 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				var jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/pos/delivery/assign/save', jsonData, fnSetDelvCallback);
			}
		});
	};
	*/
	// Cnplus엑셀다운로드
	// $('#btnCnplus').on('click', function() {
	//
	// 	var selectedData = gridWaitingOptions.api.getSelectedNodes();
	// 	var chk ="Y";
	// 	$.each(selectedData, function(idx, row) {
	//
	// 		if(row.data.delvArGb == "P") {
	// 			gridWaitingOptions.api.deselectIndex(row.rowIndex);
	// 		}
	// 	});
	//
	// 	mcxDialog.confirm('출고처리 하시겠습니까?', {
	// 		cancelBtnText: "취소",
	// 		sureBtnText: "확인",
	// 		sureBtnClick: function(){
	// 			fnSaveCnplus();
	// 		}
	// 	});
	// });

	// 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');
			}
		});
	});

	// CNPlus 엑셀 다운로드 저장
	var fnSaveCnplus = function() {
		var selectedData = gagaAgGrid.selectedRowData(gridWaitingOptions);
		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);
			}
		});

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

	// CNPlus 엑셀 다운로드
	var fnSaveCnplusCallback = function(dataList) {
		if (dataList.length === 0)
			return;
		var resultMessage = '';
		var ordDtlNoArr = [];
		$.each(dataList, function(idx, data) {
			resultMessage += '주문번호 : '+data.ordNo +' 주문상세번호 : '+data.ordDtlNo+ '결과 메시지 : '+ data.message +'<br/>';
			if(data.status === 200) {
				if(!gagajf.isNull(data.ordDtlNo)) {
					ordDtlNoArr.push(data.ordDtlNo);
				}
			}
		});
		$('#waitingOrder input[name=ordDtlNos]').val(ordDtlNoArr.join(','));
		mcxDialog.confirm(resultMessage+ 'CNPlus양식 엑셀 다운로드 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				fnExcelDownLoad('#waitingOrder');
			}
		});
	};

	//엑셀다운로드
	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 =="50" || row.data.ordDtlStat =="60" || row.data.ordDtlStat =="70"){
					gridDeliveryOptions.api.deselectIndex(row.rowIndex);
				}

				if(row.data.shipCompCd == "7"){
					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() {
		$('#tab3').trigger('click');
		$('#btnDeliveySearch').trigger('click');
		mcxDialog.alert('입력이 완료되었습니다.');
	};

	// 가이드 문서
	var fnPpt = function(){
		//var openWin = window.open("https://img.pastelmall.com/pastelmall_images/shop/guide.pdf", 'ppt_popup', "top=100, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=yes" );
	}
	// 가이드 동영상
	var fnVideo = function(){
		//var openWin = window.open("", 'video_popup', "top=100, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=yes" );
		//openWin.document.body.innerHTML = '<video id="myVideo1" autoplay loop controls muted style="width:950px;"><source src="https://img.pastelmall.com/pastelmall_images/shop/guide.mp4" type="video/mp4">Your browser does not support HTML5 video.</video>';
	};


	$(document).ready(function() {
		gagaAgGrid.createGrid('watingGrid', gridWaitingOptions);
		gagaAgGrid.createGrid('deliveryGrid', gridDeliveryOptions);
		gagaAgGrid.createGrid('usacGrid', gridUsacOptions);
		gagaAgGrid.createGrid('banDelvGrid', gridBanDelvOptions);
		cfnCreateCalendar('#deliveryTerms', 'deliveryStDate', 'deliveryEdDate', true, '조회');
		cfnCreateCalendar('#waitTerms', 'waitOrdStDate', 'waitOrdEdDate', true, '조회');
		cfnCreateCalendar('#usacTerms', 'usacStDate', 'usacEdDate', true, '조회');
		cfnCreateCalendar('#banDelvTerms', 'banDelvStDate', 'banDelvEdDate', true, '조회');

		setTimeout(fnSetDate, 100);
	});

	var fnSetDate = function(){
		cfnChangeCalendar('1m', $('#deliveryStDate'), $('#deliveryEdDate'));
		cfnChangeCalendar('7d', $('#waitOrdStDate'), $('#waitOrdEdDate'));
		cfnChangeCalendar('1m', $('#usacStDate'), $('#usacEdDate'));
		cfnChangeCalendar('1m', $('#banDelvStDate'), $('#banDelvEdDate'));

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

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