<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsWmsIncomelotSkuForm.html
 * @desc    : WMS입고단품목록 화면
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.06.28   eskim       최초 작성
 *******************************************************************************
 -->	
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<form id="goodsWmsIncomelotForm" name="goodsWmsIncomelotForm" action="#" th:action="@{'/goods/wms/incomelot/sku/list'}">
 		<!-- 패널 영역1 -->
		<div class="panelStyle" >
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 하나를 꼭 입력해 주세요.</h3>
			</div>
			<div class="panelContent">
				<table class="frmStyle">
					<colgroup>
						<col width="10%"/>
						<col width="70%"/>
						<col width="10%"/>
						<col/>
					</colgroup>
					<tr>
						<th>업체/브랜드<em class="required" title="필수"></em></th>
						<td>
							<select name="supplyCompCd" id="supplyCompCd">
								<option value="" th:if="${sessionInfo.roleCd} != 'B000'">[전체]</option>
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<select name="brandCd" id="brandCd">
								<option value="">[전체]</option>
							</select>
						</td>
						<th rowspan="2">상품코드<em class="required" title="필수"></em></th>
						<td rowspan="2">
							<textarea class="textareaR2 w100p" name="condition" id="condition"></textarea>
						</td>
					</tr>
					<tr>
						<th>입고일<em class="required" title="필수"></em></th>
						<td id="sellTerms"></td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-gray btn-lg" id="btnInit" >초기화</button>
						<button type="button" class="btn btn-info btn-lg" id="btnSearch" >조회</button>
					</li>
				</ul>
			</div>
			<!-- //검색조건 영역 -->
		</div>
		<!-- 패널 영역1 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<li class="right">
					검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="50" selected="selected">50개씩 보기</option>
						<option value="100">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<!-- <option value="1000">1000개씩 보기</option> -->
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			<!-- 검색결과 영역 -->
			<div id="gridList" style="width: 100%; height: 500px;" class="ag-theme-balham"></div>
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="goodsListPagination"></div>
				</li>
			</ul>
			<!-- 검색결과 영역 -->
		</div>
		</form>
		<!-- //패널 영역2 -->
	</div>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	var sessRoleCd = [[${sessionInfo.roleCd}]];
	var columnDefs = [
		{headerName: 'No', width: 60, cellClass: 'text-center', valueGetter: function(params) { return params.node.rowIndex + 1 }},
		{headerName: "입고번호", field: "lotno", width: 100, cellClass: 'text-center'},
		{headerName: "브랜드", field: "brandCd", width: 100, cellClass: 'text-center'},
		{headerName: "브랜드명", field: "brandname", width: 130, cellClass: 'text-center'},
		{headerName: "WMS상품번호", field: "productno", width: 120, cellClass: 'text-center'},
		{headerName: "SKU코드", field: "skucode", width: 120, cellClass: 'text-center'},
		{headerName: "WMS상품명", field: "productname", width: 300, cellClass: 'text-left'},
		{headerName: "상품코드", field: "goodsCd" , width: 120, cellClass: 'text-center'},
		{headerName: "검품", field: "normalqty" , width: 120, cellClass: 'text-right'},
		{headerName: "양품", field: "brokenqty" , width: 120, cellClass: 'text-right'},
		{headerName: "총수량", field: "totalqty" , width: 120, cellClass: 'text-right'},
		{headerName: "등록일시", field: "dateincome", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDD").format("YYYY-MM-DD") : '';
			}
		}
		
	];
	
	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// 중복 선택 가능
	//gridOptions.rowSelection = 'multiple';
	gridOptions.suppressRowClickSelection = true;

	// 초기화 클릭시
	$('#btnInit').on('click', function() {
		fnInit();
	});
	
	var fnInit = function(){
		$('#goodsWmsIncomelotForm')[0].reset();
		//$("#goodsWmsIncomelotForm input[type=radio]").removeClass("checked");
		$("#goodsWmsIncomelotForm input[type=checkbox]").removeClass("checked");
		//$("#goodsWmsIncomelotForm input[type=radio]").parent("label").removeClass("checked");
		$("#goodsWmsIncomelotForm input[type=checkbox]").parent("label").removeClass("checked");
		$("#goodsWmsIncomelotForm input[type=radio][checked]").parent("label").addClass("checked");
	}
	
	// 조회클릭시
	$('#btnSearch').on('click', function() {
		$("#goodsWmsIncomelotForm input[name=pageNo]").val('1');
		fnGoodsWmsIncomelotListSearch();
	});

	// 조회
	var fnGoodsWmsIncomelotListSearch = function(gbn) {

		if(!fnConditionCheck()) return;
		
		//gagaAgGrid.fetch($('#goodsWmsIncomelotForm').prop('action'), gridOptions, '#goodsWmsIncomelotForm');
		
		gagaPaging.init('goodsWmsIncomelotForm', fnSearchCallBack, 'goodsListPagination', $('#goodsWmsIncomelotForm').find('#pageSize').val());
		gagaPaging.load($("#goodsWmsIncomelotForm input[name=pageNo]").val());
	}

	var fnSearchCallBack = function(result){

		$('#goodsWmsIncomelotForm').find('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
		$('#goodsWmsIncomelotForm').find('#pageNo').val(result.pageing.pageable.pageNo.addComma());
		$('#goodsWmsIncomelotForm').find('#pgNo').html(result.pageing.pageable.pageNo.addComma());
		$('#goodsWmsIncomelotForm').find('#endPgNo').html(result.pageing.pageable.totalPage.addComma());
		gridOptions.api.setRowData(result.goodsList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	
	//페이징
	$('#goodsWmsIncomelotForm select[name=pageSize]').on('change', function() {
		$("#goodsWmsIncomelotForm input[name=pageNo]").val('1');
		fnGoodsWmsIncomelotListSearch();
	});
	
	
	//검색 조건 확인
	var fnConditionCheck = function(){
		var formId = '#goodsWmsIncomelotForm';
		var form = document.goodsWmsIncomelotForm;
		
		var searchFlag = false;
		var cnt = 0;

		/* if( !gagajf.isNull($("#goodsWmsIncomelotForm select[name=supplyCompCd]").val())
				|| !gagajf.isNull($("#goodsWmsIncomelotForm input[name=condition]").val())
				|| (!gagajf.isNull($("#goodsWmsIncomelotForm input[name=stDate]").val()) && !gagajf.isNull($("#goodsWmsIncomelotForm input[name=edDate]").val()))
			){
			searchFlag = true;
		}else{ */
			for (i = 0; i < form.elements.length; i++ ) {
				var el = form.elements[i];
				
				if ($(el).prop("type") == "text" || $(el).prop("type") == "textarea" || ($(el).prop("type") == "select-one"  &&  el.name != "search" && el.name != "pageSize" )) {
					if (!(el.value == null || el.value == "")) {
						cnt++;
					}
				}
			}
			
			if(cnt > 0) searchFlag = true;
			
		/* } */
		
		if(searchFlag == false){
			mcxDialog.alert("검색조건을 입력하세요.");
			return false;
		}
		
		var fromDate = $('#goodsWmsIncomelotForm input[name=stDate]').val();
		var toDate = $('#goodsWmsIncomelotForm input[name=edDate]').val();
		
		if (!gagajf.isNull(fromDate) || !gagajf.isNull(toDate)) {
			
			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("입고일 조회시 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#goodsWmsIncomelotForm input[name=stDate]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alert("입고 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#goodsWmsIncomelotForm input[name=stDate]').focus();
					}
				});
				return false;
			} 
		}

		return true;
	}
	
	//업체변경시
	$('#goodsWmsIncomelotForm select[name=supplyCompCd]').on('change', function() {
		var actionUrl = '/renderer/supplyCompany/brand/list/' + $(this).val();

		if(sessRoleCd == "B000"){
			actionUrl = '/renderer/brand/AuthBrandlist';
		}
		$("#goodsWmsIncomelotForm select[name=brandCd] option:gt(0)").remove();

		cfnCreateCombo(actionUrl, $('#goodsWmsIncomelotForm select[name=brandCd]'), "[전체]", "");
	});
	
	$(document).ready(function() {

		cfnCreateCalendar('#sellTerms', 'stDate', 'edDate', true, '등록일');
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);

	});

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