/********************************************************
 --------------------------------------------------------
 - Object 목록								            -
 --------------------------------------------------------
 * const gridColModel = {}	: 화면 Grid Object			*
 * let pageObj = {}			: 화면공통 Object			*
 * let listObj = {}			: 목록화면 Object			*
 * let modifyObj = {}			: 상세화면 Object			*
 *******************************************************/

/*화면 변수*/
const SETTMNG03010_GRID_ID = '#ITP_SETTMNG03010_jqGrid';
const SETTMNG03010_GRID_LIST = '#ITP_SETTMNG03010_jqGrid_list';
const SETTMNG03010_GRID_PAGER = '#ITP_SETTMNG03010_jqGridPager';
const SETTMNG03010_GRID_EMPTY = '#ITP_SETTMNG03010_jqGridEmpty';

const SETTMNG03010_DETAIL_GRID_ID = '#ITP_SETTMNG03010_DETAIL_jqGrid';
const SETTMNG03010_DETAIL_GRID_LIST = '#ITP_SETTMNG03010_DETAIL_jqGrid_list';
const SETTMNG03010_DETAIL_GRID_PAGER = '#ITP_SETTMNG03010_DETAIL_jqGridPager';
const SETTMNG03010_DETAIL_GRID_EMPTY = '#ITP_SETTMNG03010_DETAIL_jqGridEmpty';

let ITP_FORM_SETTMNG03010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_SETTMNG03010_DETAIL_IS_WRITING = false;
let SETTMNG03010_DETAIL_GRID_LAST_ROW_ID;

/*API URL*/
let STTL_STATE_DETAIL_GRID_LIST = '/api/sttl/state/detail-grid-list';
let STTL_STATE_STTL_END = '/api/sttl/state/sttl-end';

let STTL_REQ_INFO_STTL = '/api/sttl/req/info-sttl';
let STTL_REQ_STL_GRID_LIST = '/api/sttl/req/stl-grid-list';

let LOGIN_AUTH_TYPE_CD;

/*화면 Grid ColModel*/
const gridColModel = {
	list: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},		
		{
			index: 'BRAND_NM', name: 'brandNm',
			label: "브랜드",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: "매장명",
			width: '10', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'LOAN_DVSN_NM', name: 'loanDvsnNm',
			label: "정산타입", 
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: false
		},
		{
			index: 'SPPLY_NM', name: 'spplyNm',
			label: "공급사명",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STTL_MGNT_UNQ_NO', name: 'sttlMgntUnqNo',
			label: "정산번호", 
			width: '10', fixed: false, align: 'center',
			minwidth: 180,
			sortable: false, hidden: false
		},
		{
			index: 'STTL_ST_CD', name: 'sttlStCd',
			label: "정산상태코드", 
			width: '8', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STTL_ST_NM', name: 'sttlStNm',
			label: "정산상태", 
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: false
		},		
		{
			index: 'STTL_REQ_DT', name: 'sttlReqDt',
			label: "정산요청일",
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'STTL_REQ_AMT', name: 'sttlReqAmt',
			label: "정산요청금액",
			width: '10', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}, 
		{
			index: 'STTL_DT', name: 'sttlDt',
			label: "정산확정일",
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'STTL_REQ_AMT', name: 'sttlAmt',
			label: "정산확정금액",
			width: '10', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'UNPAID_AMT', name: 'unpaidAmt',
			label: "미납금액",
			width: '10', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}, 
		{
			index: 'STTL_REG_MGR_NM', name: 'sttlRegMgrNm',
			label: "등록자",
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text', classes: 'ui-ellipsis'
		}
	],
	view: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STTL_MGNT_DTL_NO', name: 'sttlMgntDtlNo',
			label: '정산관리상세번호',
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},		
		{
			index: 'BRAND_NM', name: 'brandNm',
			label: "브랜드",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'STORE_NM', name: 'storeNm',
			label: "매장명",
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'ITEM_ID', name: 'itemId',
			label: "품목코드",
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'ITEM_NM', name: 'itemNm',
			label: "품목명",
			width: '10', fixed: false, align: 'left',
			sortable: false, editable: false, edittype: 'text',
			classes: 'ui-ellipsis'
		},
		{
			index: 'UNIT', name: 'unit',
			label: "단위",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'UNIT_AMT', name: 'unitAmt',
			label: "단가",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'PODR_QTY', name: 'podrQty',
			label: "발주수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'DLV_QTY', name: 'dlvQty',
			label: "납품수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'WHS_COL_QTY', name: 'whsColQty',
			label: "입고/수거수량",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}, 
		{
			index: 'WHS_COL_DT', name: 'whsColDt',
			label: "입고/수거일자",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'WHS_COL_AMT', name: 'whsColAmt',
			label: "입고/수거금액",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'STTL_DVSN_NM', name: 'sttlDvsnNm',
			label: "정산구분",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'PODR_UNQ_NO', name: 'podrUnqNo',
			label: "발주번호",
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'PODR_DTL_NO', name: 'podrDtlNo',
			label: "발주항번",
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		}
	]
};

require(['config'], function() {
	require([
		'kakao.map.util'
	], function($) {
		pageObj.init();
	});
});

/*화면공통 Object*/
let pageObj = {
	init: function () {
		this.ui.init();
		this.event.init();
	},
	ui: {
		init: function () {
			this.view();
			this.grid();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('SETTMNG03010');
			
			// 공통코드 표시
			$('select').each(function() {
		        if($(this).data('select-code')) {
		            fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
		        }
		    });

			// 조회일자 지정
			var now = new Date();
			$('#ITP_TAB_SETTMNG03010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);			
			$('#ITP_FORM_SETTMNG03010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
			$('#ITP_FORM_SETTMNG03010_SEARCH_TO_DT').datepicker('setDate', new Date());
			
			// 권한에 따라 매장값 설정
			$('#ITP_FORM_SETTMNG03010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
			LOGIN_AUTH_TYPE_CD = fn_make_user_info.get('authTpCd'); // 권한타입
			if(LOGIN_AUTH_TYPE_CD == '50') {
				$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
				$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_NM').val(fn_make_user_info.get('storeNm'));	
			}
			
		},
		grid: function() {
			itp_fn_jqgrid_resize(SETTMNG03010_GRID_ID, SETTMNG03010_GRID_LIST, 'lg');
			listObj.empty.init();
			itp_fn_fire_window_resize();
		},
		ready: function() {
			listObj.init();
		}
	},
	event: {
		init: function () {
			this.button();
			this.change();
		},
		button: function () {
			// 버튼 클릭 이벤트
			$('button').each(function() {
				var id = $(this).attr('id');
				$(this).on('click', function() {
					switch (id) {
						case 'ITP_BTN_SETTMNG03010_SRH'				: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_SETTMNG03010_CANCELLIST'		: modifyObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_SETTMNG03010_STTL_END'		: modifyObj.button.endSttl(); 	break;	// 정산확정 버튼
						case 'ITP_BTN_SETTMNG03010_SEARCH_STORE_POP'	: listObj.button.storePop();	break;	// 매장검색 팝업
						case 'ITP_BTN_SETTMNG03010_SEARCH_ERASE'		: listObj.button.storeErase();	break;	// 매장 지움
						case 'ITP_BTN_SETTMNG03010_EXCEL'			: listObj.excelDown();	break;	// 엑셀 다운로드
					}
				});
			});

			$('body').on('click', function(e) {
				var gridId = SETTMNG03010_DETAIL_GRID_ID.replace('#', '');
				var rids = $(SETTMNG03010_DETAIL_GRID_ID).jqGrid('getDataIDs');
				var last_row_id = rids[rids.length - 1];
				itp_fn_grid_reset_selection(e, last_row_id, gridId, 'SETTMNG03010_DETAIL');
			});

		}, 
		change: function() {
			$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_GUBUN').on('change', function() {
				var gubunVal = $('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_GUBUN').val();
				if(gubunVal == '1') { // 매장
					$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_NM').attr('placeholder', '매장명');
					
					$(SETTMNG03010_GRID_ID).jqGrid('hideCol', ["spplyNm"]);
					$(SETTMNG03010_GRID_ID).jqGrid('showCol', ["storeNm"]);		
					// $(SETTMNG03010_GRID_ID).setColProp('spplyNm', {hidden: true});
					// $(SETTMNG03010_GRID_ID).setColProp('storeNm', {hidden: false});
								
				} else if(gubunVal == '2') { // 공급업체
					$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_NM').attr('placeholder', '공급사명');
					
					$(SETTMNG03010_GRID_ID).jqGrid('hideCol', ["storeNm"]);
					$(SETTMNG03010_GRID_ID).jqGrid('showCol', ["spplyNm"]);
					// $(SETTMNG03010_GRID_ID).setColProp('storeNm', {hidden: true});
					// $(SETTMNG03010_GRID_ID).setColProp('spplyNm', {hidden: false});
				}	
				listObj.button.search();	
				// itp_fn_jqgrid_resize(SETTMNG03010_GRID_ID, SETTMNG03010_GRID_LIST, 'lg');							
			});			
		}
	},
	switchScreen: function(mode) {
		if(mode == 'LIST') { // 목록
			$('#ITP_BTN_SETTMNG03010_MODIFY').hide();
			$('#ITP_BTN_SETTMNG03010_CANCELLIST').hide();
			$('#ITP_BTN_SETTMNG03010_DELETE').hide();
			$('#ITP_BTN_SETTMNG03010_STTL_END').hide();
			
			if(LOGIN_AUTH_TYPE_CD == '50') { // 매장관리자
				$('#ITP_BTN_SETTMNG03010_SEARCH_STORE_POP').hide();
				$('#ITP_BTN_SETTMNG03010_SEARCH_ERASE').hide();
			} else {
				$('#ITP_BTN_SETTMNG03010_SEARCH_STORE_POP').show();
				$('#ITP_BTN_SETTMNG03010_SEARCH_ERASE').show();
			}
			
			fn_show_btn_auth('#ITP_BTN_SETTMNG03010_SRH');
			fn_show_btn_auth('#ITP_BTN_SETTMNG03010_NEWREG');
			
			$('#ITP_AJAX_SETTMNG03010_LIST_CONTAINER').show();
			$('#ITP_AJAX_SETTMNG03010_DETAIL_CONTAINER').hide();
			
			$('#ITP_BTN_SETTMNG03010_EXCEL').show();
			
		} else if(mode == 'DETAIL') { // 보기
			$('#ITP_BTN_SETTMNG03010_SRH').hide();
			$('#ITP_BTN_SETTMNG03010_NEWREG').hide();
			$('#ITP_BTN_SETTMNG03010_DELETE').hide();
			
			fn_show_btn_auth('#ITP_BTN_SETTMNG03010_STTL_END');
			fn_show_btn_auth('#ITP_BTN_SETTMNG03010_CANCELLIST');

			$('#ITP_AJAX_SETTMNG03010_LIST_CONTAINER').hide();
			$('#ITP_AJAX_SETTMNG03010_DETAIL_CONTAINER').show();
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_SETTMNG03010_search: false,
	button: {
		search: function() {
			listObj.itp_SETTMNG03010_search = true;
			let param = $('#ITP_FORM_SETTMNG03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(SETTMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		}, 
		storePop: function() {
			fn_call_popup('biz', 'BIZPOP_BRAND_STORE', '#ITP_ASIDE', function(result) {
				// alert(JSON.stringify(result));
				$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_ID').val(result[0].storeId);
				$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_NM').val(result[0].storeNm);				
				listObj.button.search();
			}, null, 'S');
		}, 
		storeErase: function() {
			$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_ID').val('');
			$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_SPPLY_NM').val('');
			listObj.button.search();
		}
	},
	empty: {
		init: function() {
			var _this = this;
			this.push();
			$(SETTMNG03010_GRID_EMPTY).on('click', function() {
				_this.back();
				_this.itp_SETTMNG03010_param.gridSize = $.jgrid.defaults.rowNum;
				$(SETTMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_SETTMNG03010_param)}).trigger('reloadGrid');
			});
		},
		itp_SETTMNG03010_param: {},
		push: function() {
			let param = $('#ITP_FORM_SETTMNG03010_SEARCH').serializeObject();
			listObj.itp_SETTMNG03010_param = param;
		},
		back: function() {
			$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_ID').val(listObj.itp_SETTMNG03010_param.sstoreId);
			$('#ITP_FORM_SETTMNG03010_SEARCH_STORE_NM').val(listObj.itp_SETTMNG03010_param.sstoreNm);
			$('#ITP_FORM_SETTMNG03010_SEARCH_FROM_DT').val(listObj.itp_SETTMNG03010_param.fromDt);
			$('#ITP_FORM_SETTMNG03010_SEARCH_TO_DT').val(listObj.itp_SETTMNG03010_param.toDt);
			$('#ITP_FORM_SETTMNG03010_SEARCH_ITEM_NM').val(listObj.itp_SETTMNG03010_param.sitemNm);
		}
	},
	grid: {
		init: function () {
			// 데이터 없을때
			listObj.empty.push();
			this.search();
		},
		colModel: gridColModel.list,
		search: function() {
			pageObj.switchScreen('LIST');
			this.unload();
			this.load();
		},
		load: function() {			
			let param = $('#ITP_FORM_SETTMNG03010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;

			var option = {
				gridId: SETTMNG03010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + STTL_STATE_DETAIL_GRID_LIST,
				pager: SETTMNG03010_GRID_PAGER,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					var cm = $(this).jqGrid('getGridParam', 'colModel');
					var colNm = cm[cellIdx].name;
					if (colNm == 'sttlMgntUnqNo') {
						const sttlMgntUnqNoVal = $(this).jqGrid('getCell', rowId, 'sttlMgntUnqNo');
						
						const key = {sttlMgntUnqNo: sttlMgntUnqNoVal, viewCd: 'R'};
						var param = $.param(key);
						modifyObj.init(param);
					}
				},
				loadComplete: function(data) {
					console.log(data);
					itp_fn_grid_load_complete(data, SETTMNG03010_GRID_ID, true, 'number', 'SETTMNG03010', listObj.itp_SETTMNG03010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(SETTMNG03010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(SETTMNG03010_GRID_ID).jqGrid('setCell', rowId, 'sttlMgntUnqNo', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(SETTMNG03010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(SETTMNG03010_GRID_ID).jqGrid('clearGridData', true);
			$(SETTMNG03010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(SETTMNG03010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(SETTMNG03010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(SETTMNG03010_GRID_ID);
		}
	},
	excelDown: function() {
		var param = {
			'url': STTL_STATE_DETAIL_GRID_LIST,
			'param': $('#ITP_FORM_SETTMNG03010_SEARCH').serializeObject(),
			'gridColumns': $(SETTMNG03010_GRID_ID).jqGrid('getGridParam', 'colModel'),
			'fileName': '정산현황.xlsx',
			'sheetName': '정산현황리스트'
		};
		itp_fn_remote_to_excel(param);
	}
};

/*상세화면 Object*/
let modifyObj = {
	init: function (param) {
		this.load(param);
	},
	button: {
		cancel: function() {
			listObj.grid.search();
		}, 
		endSttl: function() {
			// 정산확정
			const formId = '#ITP_FORM_SETTMNG03010_DETAIL';
			let param = $(formId).serializeObject();
			var confirmFn= {
				callBack: function() {
					var searhFn = function() {
						listObj.grid.search();
					};
					fn_ajax_call(STTL_STATE_STTL_END, JSON.stringify(param), searhFn, 'POST'); 	
				}
			};
			var sttlReqAmt =  parseInt($('#ITP_FORM_SETTMNG03010_DETAIL_STTL_REQ_AMT').val());
			var acctBal =  parseInt($('#ITP_FORM_SETTMNG03010_DETAIL_ACCT_BAL').val());
			
			if(acctBal > 0) {
				if(acctBal >= sttlReqAmt) {
					itp_fn_modal_confirm('계좌잔액에서 지급처리가 진행됩니다.\n정산 확정하시겠습니까?', confirmFn, null);						
				} else {
					itp_fn_modal_confirm('일부금액이 계좌잔액에서 지급처리가 진행됩니다.\n정산 확정하시겠습니까?', confirmFn, null);	
				}					
			} else {
				itp_fn_modal_confirm('정산 확정하시겠습니까?', confirmFn, null);
			}
		}
	}, 
	load: function(param) {
		fn_ajax_call(STTL_REQ_INFO_STTL, param, this.callback, 'GET');
	},
	callback: function (result) {
		// console.log(result);
		pageObj.switchScreen('DETAIL');
		$('#ITP_FORM_SETTMNG03010_DETAIL_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_SETTMNG03010_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_SETTMNG03010_DETAIL_STTL_MGNT_UNQ_NO').val(result.sttlMgntUnqNo);
		$('#ITP_FORM_SETTMNG03010_DETAIL_ACCT_BAL').val(result.acctBal); // 계좌잔액
		$('#ITP_FORM_SETTMNG03010_DETAIL_STTL_REQ_AMT').val(result.sttlReqAmt); // 정산요청금액
		
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnStoreNm').text(result.storeNm);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnLoanDvsnNm').text(result.loanDvsnNm);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnAcctBal').text(itp_fn_number_comma(result.acctBal));
		
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlRjctRsn').text(result.sttlRjctRsn == null ? '' : result.sttlRjctRsn);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlStNm').text(result.sttlStNm);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlReqDt').text(result.sttlReqDt);  // 정산요청일자
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlReqAmt').text(itp_fn_number_comma(result.sttlReqAmt));
		// $('#ITP_FORM_SETTMNG03010_DETAIL_STTL_DT').val(result.sttlDt);  // 정산일자
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlDt').text(result.sttlDt == null ? '' : result.sttlDt);  // 정산요청일자
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSttlAmt').text(itp_fn_number_comma(result.sttlAmt));
		
		// $('#ITP_FORM_SETTMNG03010_DETAIL .fnRcptYn').text(result.rcptYn == null ? '' : result.rcptYn);
		// $('#ITP_FORM_SETTMNG03010_DETAIL .fnRcptDt').text(result.rcptDt == null ? '' : result.rcptDt);
		
		if(result.rcptYn == null) {
			$('#ITP_FORM_SETTMNG03010_DETAIL .fnRcptYnDate').text('');	
		} else if(result.rcptYn == 'N') {
			$('#ITP_FORM_SETTMNG03010_DETAIL .fnRcptYnDate').text('N');
		} else if(result.rcptYn == 'Y') {
			$('#ITP_FORM_SETTMNG03010_DETAIL .fnRcptYnDate').text('Y (' + result.rcptDt + ')');
		}
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnUnpaidAmt').text(itp_fn_number_comma(result.unpaidAmt));
		
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSysRegDttm').text(result.sysRegDttm);
		$('#ITP_FORM_SETTMNG03010_DETAIL .fnSysRegNm').text(result.sysRegNm);
		
		if(result.sttlStCd == 'ST10') { // 정산요청
			$('#ITP_BTN_SETTMNG03010_STTL_END').show();
		} else {
			$('#ITP_BTN_SETTMNG03010_STTL_END').hide();
		}

		// 리스트 조회
		modifyObj.grid.init();
	},
	grid: {
		init: function() {
			this.unload();
			this.load();
		},
		load : function() {
			let param = $('#ITP_FORM_SETTMNG03010_DETAIL').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.pagingYn = false; // 페이징안함

			var option = {
				gridId: SETTMNG03010_DETAIL_GRID_ID,
				colModel: gridColModel.view,
				param: param,
				url: DOMAIN + STTL_REQ_STL_GRID_LIST,
				pager: SETTMNG03010_DETAIL_GRID_PAGER,
				loadComplete: function(data) {
					itp_fn_grid_load_complete(data, SETTMNG03010_DETAIL_GRID_ID, true, undefined, 'SETTMNG03010_DETAIL');
				},
				onPaging: function(action) {
					var pagingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(SETTMNG03010_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, pagingFn, SETTMNG03010_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_paging(SETTMNG03010_DETAIL_GRID_ID, action, param);
					}
				},
				onSortCol: function(index, columnIndex, sortOrder) {
					var sortingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(SETTMNG03010_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, sortingFn, SETTMNG03010_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_sorting(SETTMNG03010_DETAIL_GRID_ID, index, sortOrder);
					}
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(SETTMNG03010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
			$(SETTMNG03010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(SETTMNG03010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(SETTMNG03010_DETAIL_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(SETTMNG03010_DETAIL_GRID_ID);
		}
	}
};
