/* 페이징 관련 변수 */
let stockStatusTotalCount   = 0;
let stockStatusTotalPages   = 0;

/*aggird*/
let stockStatusAgGridData = [];

let stockStatusSelectId = "";

/****************************************************************************
* 현재까지 전체 입고 수량/금액, 출고 수량/금액 확인
****************************************************************************/
function fn_selectTotalStockStatus(){
	let formData = new FormData();
	formData.append("menuClass", menuClass);
	formData.append("stockStatusSearchKeywordParam", stockStatusSearchKeywordParam);
	formData.append("stockStatusSearchStartDate", stockStatusSearchStartDate);
	formData.append("stockStatusSearchEndDate", stockStatusSearchEndDate);
	formData.append("stockStatusSearchDateType", stockStatusSearchDateType);
	formData.append("stockStatusTreatmentId", stockStatusTreatmentId);
	formData.append("stockStatusCompanyId", stockStatusCompanyId);

	$.ajax({
		url: encodeURI('/webstockstatus/selectTotalStockStatus.do'),
		data: formData,
		dataType: "json",
		processData: false,
		contentType: false,
		type: 'POST',
		async: true,
		success: function(data){
			if('0'==data.msgCode){
				$("#inTotalQuantity").text(data.rows[0].inTotalQuantity);
				$("#inTotalAmount").text(data.rows[0].inTotalAmount);
				$("#outTotalQuantity").text(data.rows[0].outTotalQuantity);
				$("#outTotalAmount").text(data.rows[0].outTotalAmount);
			}
			else{
				modalEvent.danger("조회 오류", data.msgDesc);
			}
		},
		error : function(xhr, status, error) {
			modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
		},
		beforeSend:function(){
			// 로딩열기
			stockStatusGridOptions.api.showLoadingOverlay();
		},
		complete:function(){
			
		}
	});
}

/****************************************************************************
* 검색 날짜 설정
//(A:오늘, B:3일, C:7일, D:최근30일, E:최근90일, F:이번달, G:올해, H:지난주, I:지난달)
****************************************************************************/
function fn_stockStatusSetDate(param){
	if("A"==param){
		// 오늘
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchStartDate = year+'-'+month+'-'+day;
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
	}
	else if("B"==param){
		// 3일
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 3);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchStartDate = year+'-'+month+'-'+day;
	}
	else if("C"==param){
		// 이번주
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 7);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchStartDate = year+'-'+month+'-'+day;
	}
	else if("D"==param){
		// 최근30일
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		//최근30일
		toDate.setDate(toDate.getDate() - 30);
		startYear  = toDate.getFullYear();
		startMonth = toDate.getMonth() + 1;
		startDay   = toDate.getDate();
		
		if(startMonth < 10) startMonth = "0" + startMonth;
		if(startDay < 10) startDay = "0" + startDay;
		
		stockStatusSearchStartDate = startYear+'-'+startMonth+'-'+startDay;
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
	}
	else if("E"==param){
		// 최근90일
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 90);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchStartDate = year+'-'+month+'-'+day;
	}
	else if("F"==param){
		//F:이번달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		stockStatusSearchStartDate = year+'-'+month+'-01';
	}
	else if("G"==param){
		// G:올해
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		stockStatusSearchStartDate = year+'-01-01';
	}
	else if("H"==param){
		// H:지난주, I:지난달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		stockStatusSearchStartDate = year+'-01-01';
	}
	else if("I"==param){
		// I:지난달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		stockStatusSearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		stockStatusSearchStartDate = year+'-01-01';
	}
	
	$("#stockStatusSearchStartDate").val(stockStatusSearchStartDate).trigger("change");
	$("#stockStatusSearchEndDate").val(stockStatusSearchEndDate).trigger("change");
}

function fn_setTreatmentCombo(){
	// 대상
	const target = $("#stockStatusTreatmentId").siblings("ul.select_option_list");
	// 조회 데이터 셋팅
	let comboHTML = '<li id="li_treatmentAll" class="option_list_item">재고구분 전체</li>';
	target.empty().html(comboHTML).trigger("create");

	// 데이터 조회
	let category = fn_selectCategoryList2();
	let reservationCategory = category.find(cat => cat.categoryName === '재고구분');

	if (reservationCategory) {
		fn_selectModalOtherOption2(reservationCategory.categoryCode);
	}
	// 콤보 이벤트
	target.find("li.option_list_item").click(function () {
		// 1. 선택값 셋팅
		let selectIdArr = $(this).prop("id").split('_');
		let selectId    = selectIdArr[1];
		let selectName  = $(this).text();

		if(selectId.match("All")){
			selectId = '';
		}
		
		$(this).parent().siblings("button").text(selectName);
		$(this).parent().siblings("input").val(selectId);
	});
}

/****************************************************************************
* 거래처 콤보데이타 설정
****************************************************************************/
function fn_setCompanyCombo(){
	// 대상
	const target = $("#stockStatusCompanyId").siblings("ul.select_option_list");

	// 데이터 조회
	let comboData = fn_selectListCompanyOption();
	
	// 조회 데이터 셋팅
	let comboHTML = '<li id="li_companyAll" class="option_list_item">거래처 전체</li>';
	
	for(let i = 0; i < comboData.length; i++){
		let muCompanyId     = comboData[i].muCompanyId;
		let companyName     = comboData[i].companyName;
		
		comboHTML += '<li id="li_'+muCompanyId+'" class="option_list_item">';
		comboHTML += '	<span>'+companyName+'</span>';
		comboHTML += '</li>';
	}
	target.empty().html(comboHTML).trigger("create");
	
	// 콤보 이벤트
	target.find("li.option_list_item").click(function () {
		// 1. 선택값 셋팅
		let selectIdArr = $(this).prop("id").split('_');
		let selectId    = selectIdArr[1];
		let selectName  = $(this).text();

		if(selectId.match("All")){
			selectId = '';
		}
		
		$(this).parent().siblings("button").text(selectName);
		$(this).parent().siblings("input").val(selectId);
	});
}

/****************************************************************************
* 입출고 현황 정보 리스트 조회
****************************************************************************/
function fn_selectListStockStatusJson(){
	let formData = new FormData();
	formData.append("menuClass", menuClass);
	formData.append("stockStatusSearchKeywordParam", stockStatusSearchKeywordParam);
	formData.append("stockStatusSort", stockStatusSort);
	formData.append("stockStatusDir", stockStatusDir);
	formData.append("stockStatusStart", stockStatusStart);
	formData.append("stockStatusLimit", stockStatusLimit);
	formData.append("stockStatusSearchStartDate", stockStatusSearchStartDate);
	formData.append("stockStatusSearchEndDate", stockStatusSearchEndDate);
	formData.append("stockStatusSearchDateType", stockStatusSearchDateType);
	formData.append("stockStatusTreatmentId", stockStatusTreatmentId);
	formData.append("stockStatusCompanyId", stockStatusCompanyId);

	$.ajax({
		url: encodeURI('/webstockstatus/selectListStockStatus.do'),
		data: formData,
		dataType: "json",
		processData: false,
		contentType: false,
		type: 'POST',
		async: true,
		success: function(data){
			if('0'==data.msgCode){
				// 페이징 처리
				stockStatusTotalCount  = data.totalCount;
				//$("#txt_stockStatusTotalCount").text(stockStatusTotalCount);

				stockStatusTotalPages = Math.ceil(stockStatusTotalCount/stockStatusLimit);
				
				// 리스트 조회
				stockStatusAgGridData = data.rows;
				stockStatusGridOptions.api.setRowData(stockStatusAgGridData);
				
				// if(0<data.rows.length){
				// 	//페이징 처리
				// 	window.pagObj = $('#stockStatusPagination').twbsPagination({
				// 		startPage    : ((stockStatusStart/stockStatusLimit)+1),
				// 		totalPages   : (stockStatusTotalPages==0)?1:stockStatusTotalPages,
				// 		visiblePages : 10,
				// 		initiateStartPageClick: false,
				// 		prev         : '<img src="/image/web/page_navigation_arrow.svg" alt="prev"/>',
				// 		next         : '<img src="/image/web/page_navigation_arrow.svg" alt="next"/>',
				// 		first        : '',
				// 		last         : '',
				// 		onPageClick: function (event, page) {
				// 			fn_stockStatusPagination(page);
				// 		}
				// 	}).on('page', function (event, page) {
				// 		//console.info(page + ' (from event listening)');
				// 	});
				// }
				// else{
				//
				// }
			}
			else{
				modalEvent.danger("조회 오류", data.msgDesc);
			}
		},
		error : function(xhr, status, error) {
			modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
		},
		beforeSend:function(){
			// 로딩열기
			stockStatusGridOptions.api.showLoadingOverlay();
		},
		complete:function(){
			
		}
	});
}

/****************************************************************************
* 검색하기
****************************************************************************/
function fn_stockStatusSearch(param){
	if("A"!=param && "Y"!=selectUseYn){
		modalEvent.warning("", "조회 권한이 없습니다.");
		return false;
	}
	
	fn_stockStatusPaginReset();

	stockStatusSearchDateType  = $("#stockStatusSearchDateType").val();
	stockStatusSearchStartDate = $("#stockStatusSearchStartDate").val();
	stockStatusSearchEndDate   = $("#stockStatusSearchEndDate").val();
	
	stockStatusTreatmentId   = $("#stockStatusTreatmentId").val();
	stockStatusCompanyId     = $("#stockStatusCompanyId").val();
	
	stockStatusSearchKeywordParam = $("#stockStatusSearchKeyword").val();

	fn_selectListStockStatusJson();
	// 현재까지 전체 입고 수량/금액, 출고 수량/금액 확인
	fn_selectTotalStockStatus();
}


/****************************************************************************
* 초기화하기
****************************************************************************/
function fn_stockStatusReset(){
	fn_stockStatusSetDate('D');
	$("#stockStatusSearchDateType option:eq(0)").prop("selected", true);
	
	$("#stockStatusSearchKeyword").val("");

	fn_stockStatusSearch();
}

/****************************************************************************
* 페이징 처리
****************************************************************************/
function fn_stockStatusPagination(param){
	stockStatusStart = (parseInt(param)-1)*stockStatusLimit;
	
	fn_selectListStockStatusJson();
}

/****************************************************************************
* 페이징 리셋
****************************************************************************/
function fn_stockStatusPaginReset(){
	stockStatusSearchKeywordParam = '';

	stockStatusStart        = 0;
	stockStatusLimit        = 100;
	stockStatusTotalCount   = 0;
	stockStatusTotalPages   = 0;
	
	//페이징 초기화
	if($("#stockStatusPagination").data("twbs-pagination")){
		$("#stockStatusPagination").twbsPagination("destroy");
	}
}


/****************************************************************************
* 검색 엔터 이벤트
****************************************************************************/
function fn_stockStatusEnter(e){
	if(e.which){
		// 파이어폭스
		if(13 == e.which) {
			//로그인 액션 스크립트
			fn_stockStatusSearch();
		}
	}
	else{
		// 윈도우, 사파리, 크롬
		if(13 == event.keyCode) {
			//로그인 액션 스크립트
			fn_stockStatusSearch();
		}
	}
}

/****************************************************************************
* 정렬 이벤트
****************************************************************************/
function fn_alignEvent(param, param2){
	let align = "";
	
	if("A"==param){
		align = "오늘";
		
		fn_stockStatusSetDate('A');
	}
	else if("B"==param){
		align = "최근30일";
		
		fn_stockStatusSetDate('D');
	}
	else if("C"==param){
		align = "최근90일";
		
		fn_stockStatusSetDate('E');
	}
	else if("D"==param){
		align = "이번주";
		
		fn_stockStatusSetDate('C');
	}
	else if("E"==param){
		align = "이번달";
		
		fn_stockStatusSetDate('F');
	}
	else if("F"==param){
		align = "올해";
		
		fn_stockStatusSetDate('G');
	}
	else if("G"==param){
		align = "지난주";
		
		fn_stockStatusSetDate('H');
	}
	else if("H"==param){
		align = "지난달";
		
		fn_stockStatusSetDate('I');
	}
	else{
		align = "";
	}
	$("#stockStatusSearchDateType").val(param);
	$("#stockStatusSearchDateType").siblings("button").text(align);
}

/****************************************************************************
* 완료
****************************************************************************/
function fn_stockStatusOk(){
	fn_stockStatusReset();
}

function fn_insertStockStatusPopup(){
	if("Y"!=insertUseYn){
		modalEvent.warning("", "등록 권한이 없습니다.");
		return false;
	}
	
	let reqParam =  {};
	stockStatusInsertModal.popup(function(obj, reqParam) {
		fn_stockStatusOk();
	}, reqParam);
}

/****************************************************************************
* 입출고내역 화면으로 이동.
****************************************************************************/
function fn_selectListStockHistoryIntro(param, param2, param3){
	if("Y"==updateUseYn){
		// 수정가능
		let pagingParam = "?menuClass="+menuClass;
		pagingParam    += "&stockStatusSearchKeywordParam="+stockStatusSearchKeywordParam;
		pagingParam    += "&stockStatusSort="+stockStatusSort;
		pagingParam    += "&stockStatusDir="+stockStatusDir;
		pagingParam    += "&stockStatusStart="+stockStatusStart;
		pagingParam    += "&stockStatusLimit="+stockStatusLimit;
		pagingParam    += "&stockStatusSearchStartDate="+stockStatusSearchStartDate;
		pagingParam    += "&stockStatusSearchEndDate="+stockStatusSearchEndDate;
		pagingParam    += "&stockStatusSearchDateType="+stockStatusSearchDateType;
		pagingParam    += "&stockStatusTreatmentId="+stockStatusTreatmentId;
		pagingParam    += "&stockStatusCompanyId="+stockStatusCompanyId;
		pagingParam    += "&muTreatmentId="+param;
		pagingParam    += "&muProductId="+param2;
		pagingParam    += "&muCompanyId="+param3;
		
		fn_leftFormAction("/webstockhistory/selectListStockHistoryIntro.do"+pagingParam);
	}
	else{
		modalEvent.warning("", "수정 권한이 없습니다.");
		return false;
	}
	
}

/****************************************************************************
* 엑셀 다운 다운로드
****************************************************************************/
function fn_downloadStockStatusExcel(){
	if("Y"==downloadUseYn){
		let pagingParam = "?menuClass="+menuClass;
		pagingParam    += "&stockStatusSearchKeywordParam="+stockStatusSearchKeywordParam;
		pagingParam    += "&stockStatusSort="+stockStatusSort;
		pagingParam    += "&stockStatusDir="+stockStatusDir;
		pagingParam    += "&stockStatusStart="+stockStatusStart;
		pagingParam    += "&stockStatusLimit="+stockStatusLimit;
		pagingParam    += "&stockStatusSearchStartDate="+stockStatusSearchStartDate;
		pagingParam    += "&stockStatusSearchEndDate="+stockStatusSearchEndDate;
		pagingParam    += "&stockStatusSearchDateType="+stockStatusSearchDateType;
		pagingParam    += "&stockStatusTreatmentId="+stockStatusTreatmentId;
		pagingParam    += "&stockStatusCompanyId="+stockStatusCompanyId;
		
		let url = encodeURI("/webstockstatus/downloadStockStatusExcel.do"+pagingParam);
		$("#stockStatusSelectListForm").prop("action",url);
		$("#stockStatusSelectListForm").submit();
	}
	else{
		modalEvent.warning("", "내려받기 권한이 없습니다.");
		return false;
	}
}

let stockStatusColumnDefs = [
	/*{field: "checkbox", headerName:"", minWidth: columnWidth, maxWidth: columnWidth, headerCheckboxSelection: true, checkboxSelection: true},*/
	/* {field: "rowNum", headerName:"번호", minWidth: columnWidth, maxWidth: columnWidth, sortable: false}, */
	{field: "rowNum", headerName:"번호", minWidth:60,sortable: false, cellStyle:{textAlign: 'center'}},
	{field: "treatmentName", headerName:"재고구분", minWidth: 110, maxWidth: 110},
	{field: "productName", headerName:"제품명", minWidth: 350, cellStyle:{cursor: 'pointer', color:'#3985EA'}},
	{field: "companyName", headerName:"거래처명", minWidth: 350},
	{field: "inTotalQuantity", headerName:"입고수량", minWidth: 130, maxWidth: 130, cellStyle:{textAlign: 'right'}},
	{field: "inTotalAmount", headerName:"입고금액", minWidth: 215, maxWidth: 215, cellStyle:{textAlign: 'right'}},
	{field: "outTotalQuantity", headerName:"출고수량", minWidth: 130, maxWidth: 130, cellStyle:{textAlign: 'right'}},
	{field: "outTotalAmount", headerName:"출고금액", minWidth: 215, maxWidth: 215, cellStyle:{textAlign: 'right'}}
];

// let the grid know which columns and what data to use
let stockStatusGridOptions = {
	suppressRowTransform: true,
	columnDefs: stockStatusColumnDefs,
	defaultColDef: {		// 리스트 기본 설정
		flex: 1,
		sortable: true,		//정렬 여부
		resizable: true,	//리사이즈
		editable: false,	// 그리드에서 데이터 수정
		cellStyle:{textAlign:'left',fontSize:'14px',padding:'0'},
		//suppressSizeToFit:true,		//자동 맞춤
		//enableRowGroup: true,		// 그룹 묶음
		enablePivot: true,
		enableValue : true
	},
	//suppressMultiSort:true,  //단일솔트 true가 단일, false가 다중 shift + sort 시
	headerHeight : 41, // header 높이
	rowHeight : 41, // row 높이
	rowData : stockStatusAgGridData,
	suppressRowClickSelection : true, // 로우 클릭시 체크박스 선택 true no, false yes
	localeText : {
		noRowsToShow : '조회 결과가 없습니다.'
	}, //데이터 없을 시 나오는 문구
	rowSelection : 'multiple', // row 다중 선택
	debug : false,
	onCellClicked: function(event){ //셀 클릭 이벤트
		/* alert(event.column.colId); */
		if('productName'==event.column.colId){
			fn_selectListStockHistoryIntro(event.data.muTreatmentId, event.data.muProductId, event.data.muCompanyId);
		}
	},
	onSelectionChanged: function(event){ //체크박스 선택
		let selectRows = [];
		selectRows = event.api.getSelectedRows();
		
		stockStatusSelectId = '';
		for(let i=0; i<selectRows.length; i++){
			stockStatusSelectId += selectRows[i].muStockStatusId + ",";
		}
		stockStatusSelectId = stockStatusSelectId.substring(0, stockStatusSelectId.lastIndexOf(','));
	},
	onSortChanged: function(event){
		 //정렬
		stockStatusSort = ''; //기존 정렬 초기화
		let columnArr = event.columnApi.getColumnState();
		if(0<columnArr.length){
			//sort index 순으로 재정렬
			columnArr.sort(function(a,b){
				return a.sortIndex - b.sortIndex;
			});
			
			let nullCnt = 0;
			for(let i=0; i<columnArr.length; i++){
				let gridSortModel = columnArr[i].colId;
				let gridSort = columnArr[i].sort;
				
				if(gridSort != null){
					stockStatusStart = 0;
					stockStatusSort += gridSortModel+' '+ gridSort + ',';
				}
				else{
					nullCnt++;
					if(nullCnt == columnArr.length){
						stockStatusSort = '';
						stockStatusDir = '';
						stockStatusStart = 0;
					}
				}
			}
		}
		stockStatusSort = stockStatusSort.substring(0,stockStatusSort.lastIndexOf( ",")); //맨끝 콤마 지우기

		fn_stockStatusSearch();
	}
};

// lookup the container we want the Grid to use
let stockStatusGridDiv = document.querySelector('#stockStatusGrid');

// create the grid passing in the div to use together with the columns & data we want to use
new agGrid.Grid(stockStatusGridDiv, stockStatusGridOptions);


/****************************************************************************
* 페이지 init
****************************************************************************/
function fn_pageInit(){
	
	// 재고구분(진료) 콤보
	fn_setTreatmentCombo();
	
	// 거래처 콤보
	fn_setCompanyCombo();
	
	// 날짜 datepicker
	fn_searchDatePicker("#divStockStatusSearchStartDate", "#divStockStatusSearchEndDate");
	
	if(!stockStatusSearchStartDate&&!stockStatusSearchEndDate){
		// 검색 오늘날짜 셋팅
		fn_stockStatusSetDate('D');
	}else{
		$("#stockStatusSearchStartDate").val(stockStatusSearchStartDate).trigger("change");;
		$("#stockStatusSearchEndDate").val(stockStatusSearchEndDate).trigger("change");;
	}
	
	
	if(!stockStatusTreatmentId){
		
	}else{
		$('#li_'+stockStatusTreatmentId).click();
	}
	
	if(!stockStatusCompanyId){
		
	}else{
		$('#li_'+stockStatusCompanyId).click();
	}
	
	// 초기 페이징 처리
	$("#stockStatusSearchKeyword").val(stockStatusSearchKeywordParam);
	fn_stockStatusSearch("A");
	
}

/****************************************************************************
* 페이지 event
****************************************************************************/
function fn_pageEvent(){
	// 검색 input
	$(document).on('keypress', '#stockStatusSearchKeyword', function(e) {
		fn_stockStatusEnter(e);
	});
	
	// 검색 조회 버튼
	$("#btnSearchStockStatus").click(function () {
		fn_stockStatusSearch();
	});
	
	// 입출고 현황 내려받기
	$("#btnDownloadStockStatus").click(function () {
		fn_downloadStockStatusExcel();
	});
	
	// 기간 선택 콤보 이벤트
	const target = $("#stockStatusSearchDateType").siblings("ul.select_option_list");
	target.find("li.option_list_item").click(function () {
		let selectIdArr = $(this).prop("id").split('_');
		let selectId    = selectIdArr[1];
		let selectName  = $(this).text();
		
		$(this).parent().siblings("button").text(selectName);
		$(this).parent().siblings("input").val(selectId);
		
		fn_alignEvent(selectId);
	});
}

$(function(){
	// 페이지 init
	fn_pageInit();
	
	// 페이지 event
	fn_pageEvent();
});