<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : SupplyCompanyFeeConfirmForm.html
 * @desc    : 입점업체 정산확정 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.09.02   gagamel     최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/settle/supply/company/fee/confirm/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
<!-- 						<col style="width:25%;"/> -->
<!-- 						<col style="width:10%;"/> -->
						<col/>
					</colgroup>
					<tr>
						<th>정산기준월<i class="required" title="필수" aria-hidden="true"></i></th>
						<td>
							<input type="text" class="schMonth w60" name="settleYm" id="settleYm" maxlength="7" required="required"/>
							<button type="button" class="btn icn schBtn" data-id="settleYm"><i class="fa fa-calendar" aria-hidden="true"></i></button>
						</td>
<!-- 						<th>공급업체</th> -->
<!-- 						<td> -->
<!-- 							<select name="supplyCompCd"> -->
<!-- 								<option value="">[전체]</option> -->
<!-- 								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option> -->
<!-- 							</select> -->
<!-- 						</td> -->
					</tr>
				</table>
				
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#searchForm')[0].reset();">초기화</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- 검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="left">
					<span class="infoTxt cBlue">* 항목 설명</span>
					<!-- 아이콘 툴팁 -->
					<div class="iconTooltip marL10">
						<i class="fa fa-info" aria-hidden="true"></i>
						<span class="left" style="width: 600px;">
							<strong>1.계산서발행금액</strong>: ROUND(수수료 - (자사쿠폰분담액 + 자사다다익선분담액), 0) (< 0 인 경우 0으로 표기)<br/>
							<strong>2.공급가액</strong>: INT(계산서발행금액 / 1.1)<br/>
							<strong>3.세액</strong>: 계산서발행금액 - 공급가액<br/>
							<strong>4.지급금액</strong>: (상품총액 – 수수료 + 자사쿠폰분담액 + 자사다다익선분담액) + 배송비 - 기타차감<br/>
							<strong>5.총지급금액</strong>: 지급금액 - 미수금<br/>
							<strong>6.상태</strong>: 전자계약여부 = 'N' then [보류] else 지급금액 < 0 then [미수금] else [정상]
						</span>
					</div>
					<!-- //아이콘 툴팁 -->
				</li>
				<li class="right">
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 570px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let columnDefs = [
		{ headerName: "정산연월", field: "usacYm", width: 80, cellClass: 'text-center', hide: true },
		{ headerName: "공급벤더코드", field: "supplyVendorCd", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "공급벤더", field: "supplyVendorNm", width: 200 },
// 		{ headerName: "공급업체코드", field: "supplyCompCd", width: 100, cellClass: 'text-center', hide: true },
// 		{ headerName: "공급업체", field: "supplyCompNm", width: 200 },
		{
			headerName: "판매수량", field: "sellQty", width: 100, cellClass: 'text-center',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "판매총액", field: "sellAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "상품총액", field: "realSellAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "수수료", field: "sellFeeAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "공급가액", field: "supplyAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "세액", field: "taxAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "쿠폰할인총액", field: "cpnDcAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "자사쿠폰분담액", field: "selfCpnDcAmt", width: 120, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "입점쿠폰분담액", field: "supplyCompCpnDcAmt", width: 120, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "다다익선할인총액", field: "tmtbDcAmt", width: 120, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "자사다다익선분담액", field: "selfTmtbDcAmt", width: 150, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "입점다다익선분담액", field: "supplyCompTmtbDcAmt", width: 150, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "계산서발행금액", field: "billAmt", width: 120, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "배송비", field: "delvFee", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "기타차감", field: "etcDeductAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle: { color: '#B50808', 'background-color': '#FF9AA2' }
		},
		{
			headerName: "지급금액", field: "giveAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		},
		{
			headerName: "미수금", field: "receivableAmt", width: 100, cellClass: 'text-right',
			editable: true, cellEditor: 'numericCellEditor', cellEditorParams: { maxlength: 12, validType: 'integer', required: true },
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(Number(params.value)); },
			cellStyle: { color: '#fffff', 'background-color': '#aaaaff' }
		},
		{
			headerName: "총지급금액", field: "totGiveAmt", width: 100, cellClass: 'text-right',
			cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); },
			cellStyle : function(params) { if (Number(params.value) < 0) return { 'color' : 'red' } }
		}
	];

	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	gridOptions.stopEditingWhenGridLosesFocus = true;
	
	// 검색
	$('#btnSearch').on('click', function() {
		// 입력 값 체크
		if (!gagajf.validation('#searchForm'))
			return false;
		
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		if (gridOptions.api.getDisplayedRowCount() <= 0) {
			mcxDialog.alert("조회된 데이터가 없습니다. 조회 후 다운로드 하세요.");
			return false;
		}
		
		gagaAgGrid.exportToExcel('입점업체정산 목록', gridOptions);
	});
	
	$(document).ready(function() {
		$('#settleYm').val((new Date()).before(0, 1, 0).format("YYYY-MM"));
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
