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

/*화면 변수*/
const SETTMNG02010_GRID_ID = '#ITP_SETTMNG02010_jqGrid';
const SETTMNG02010_GRID_LIST = '#ITP_SETTMNG02010_jqGrid_list';
const SETTMNG02010_GRID_PAGER = '#ITP_SETTMNG02010_jqGridPager';
const SETTMNG02010_GRID_EMPTY = '#ITP_SETTMNG02010_jqGridEmpty';

const SETTMNG02010_DETAIL_GRID_ID = '#ITP_SETTMNG02010_DETAIL_jqGrid';
const SETTMNG02010_DETAIL_GRID_LIST = '#ITP_SETTMNG02010_DETAIL_jqGrid_list';
const SETTMNG02010_DETAIL_GRID_PAGER = '#ITP_SETTMNG02010_DETAIL_jqGridPager';
const SETTMNG02010_DETAIL_GRID_EMPTY = '#ITP_SETTMNG02010_DETAIL_jqGridEmpty';

let ITP_FORM_SETTMNG02010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_SETTMNG02010_DETAIL_IS_WRITING = false;
let SETTMNG02010_DETAIL_GRID_LAST_ROW_ID;

/*API URL*/
let STTL_STATE_DETAIL_GRID_LIST = '/api/sttl/state/detail-grid-list';
let STTL_INSPECT_STATE_STTL_CONFIRM = '/api/sttl/inspect/state/sttl-confirm';
let STTL_INSPECT_STATE_STTL_REJECT = '/api/sttl/inspect/state/sttl-reject';

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: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'SPPLY_NM', name: 'spplyNm',
			label: "공급사명",
			width: '10', fixed: false, align: 'left',
			sortable: false, hidden: false, classes: 'ui-ellipsis'
		},
		{
			index: 'STTL_MGNT_UNQ_NO', name: 'sttlMgntUnqNo',
			label: "정산번호", 
			minwidth: 180,
			width: '10', fixed: false, align: 'center',
			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: 'ACCT_BAL', name: 'acctBal',
			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: "품목코드",
			minwidth: 300,
			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: "입고/수거수량",
			minwidth: 100,
			width: '8', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		}, 
		{
			index: 'WHS_COL_DT', name: 'whsColDt',
			label: "입고/수거일자",
			minwidth: 100,
			width: '8', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'WHS_COL_AMT', name: 'whsColAmt',
			label: "입고/수거금액",
			minwidth: 100,
			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: 'center',
			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('SETTMNG02010');
			// 공통코드 표시
			$('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_SETTMNG02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);			
			$('#ITP_FORM_SETTMNG02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
			$('#ITP_FORM_SETTMNG02010_SEARCH_TO_DT').datepicker('setDate', new Date());
			
			// 권한에 따라 매장값 설정
			$('#ITP_FORM_SETTMNG02010_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 == '60') {
				$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
				$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_NM').val(fn_make_user_info.get('storeNm'));	
			}
		},
		grid: function() {
			itp_fn_jqgrid_resize(SETTMNG02010_GRID_ID, SETTMNG02010_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_SETTMNG02010_SRH'				: listObj.button.search();		break;	// 조회 버튼 클릭
						case 'ITP_BTN_SETTMNG02010_CANCELLIST'		: modifyObj.button.cancel(); 	break;	// 취소/목록 버튼
						case 'ITP_BTN_SETTMNG02010_CONFIRM'			: modifyObj.button.confirmSttl();	break;	// 정산확정 버튼
						case 'ITP_BTN_SETTMNG02010_REJECT'			: modifyObj.button.rejectSttl();	break;	// 정산반려 버튼
						case 'ITP_BTN_SETTMNG02010_SEARCH_SPPLY_POP'	: listObj.button.spplyPop();	break;	// 
						case 'ITP_BTN_SETTMNG02010_SEARCH_ERASE'		: listObj.button.spplyErase();	break;	// 
						case 'ITP_BTN_SETTMNG02010_EXCEL'			: listObj.excelDown();	break;	//  엑셀 다운로드
					}
				});
			});

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

		}, 
		change: function() {
			$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_GUBUN').on('change', function() {
				var gubunVal = $('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_GUBUN').val();
				if(gubunVal == '1') { // 매장
					$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_NM').attr('placeholder', '매장명');
					
					$(SETTMNG02010_GRID_ID).jqGrid('hideCol', ["spplyNm"]);
					$(SETTMNG02010_GRID_ID).jqGrid('showCol', ["storeNm"]);		
					// $(SETTMNG02010_GRID_ID).setColProp('spplyNm', {hidden: true});
					// $(SETTMNG02010_GRID_ID).setColProp('storeNm', {hidden: false});
								
				} else if(gubunVal == '2') { // 공급업체
					$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_NM').attr('placeholder', '공급사명');
					
					$(SETTMNG02010_GRID_ID).jqGrid('hideCol', ["storeNm"]);
					$(SETTMNG02010_GRID_ID).jqGrid('showCol', ["spplyNm"]);
					// $(SETTMNG02010_GRID_ID).setColProp('storeNm', {hidden: true});
					// $(SETTMNG02010_GRID_ID).setColProp('spplyNm', {hidden: false});
				}	
				listObj.button.search();	
				// itp_fn_jqgrid_resize(SETTMNG02010_GRID_ID, SETTMNG02010_GRID_LIST, 'lg');							
			});			
		}
	},
	switchScreen: function(mode) {
		if(mode == 'LIST') { // 목록
			$('#ITP_BTN_SETTMNG02010_MODIFY').hide();
			$('#ITP_BTN_SETTMNG02010_CANCELLIST').hide();
			$('#ITP_BTN_SETTMNG02010_DELETE').hide();
			$('#ITP_BTN_SETTMNG02010_REQUEST').hide();
			$('#ITP_BTN_SETTMNG02010_CONFIRM').hide();
			$('#ITP_BTN_SETTMNG02010_REJECT').hide();
			
			if(LOGIN_AUTH_TYPE_CD == '60') { // 공급사
				$('#ITP_BTN_SETTMNG02010_SEARCH_SPPLY_POP').hide();
				$('#ITP_BTN_SETTMNG02010_SEARCH_ERASE').hide();
			} else {
				$('#ITP_BTN_SETTMNG02010_SEARCH_SPPLY_POP').show();
				$('#ITP_BTN_SETTMNG02010_SEARCH_ERASE').show();
			}
			
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_SRH');
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_NEWREG');
			
			$('#ITP_AJAX_SETTMNG02010_LIST_CONTAINER').show();
			$('#ITP_AJAX_SETTMNG02010_DETAIL_CONTAINER').hide();
			
			$('#ITP_BTN_SETTMNG02010_EXCEL').show();
			
		} else if(mode == 'DETAIL') { // 보기
			$('#ITP_BTN_SETTMNG02010_SRH').hide();
			$('#ITP_BTN_SETTMNG02010_NEWREG').hide();
			$('#ITP_BTN_SETTMNG02010_DELETE').hide();
			
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_REQUEST');
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_CANCELLIST');
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_CONFIRM');
			fn_show_btn_auth('#ITP_BTN_SETTMNG02010_REJECT');

			$('#ITP_AJAX_SETTMNG02010_LIST_CONTAINER').hide();
			$('#ITP_AJAX_SETTMNG02010_DETAIL_CONTAINER').show();
		}
	}
};

/*목록화면 Object*/
let listObj = {
	init: function () {
		this.grid.init();
	},
	itp_SETTMNG02010_search: false,
	button: {
		search: function() {
			listObj.itp_SETTMNG02010_search = true;
			let param = $('#ITP_FORM_SETTMNG02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(SETTMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		}, 
		spplyPop: function() {
			fn_call_popup('biz', 'BIZPOP_STORE_SPPLY', '#ITP_ASIDE', function(result) {
				// alert(JSON.stringify(result));
				$('#ITP_FORM_SETTMNG02010_SEARCH_SPPLY_ID').val(result.spplyId);
				$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_NM').val(result.spplyNm);				
				listObj.button.search();
			}, null, 'S');
		}, 
		spplyErase: function() {
			$('#ITP_FORM_SETTMNG02010_SEARCH_SPPLY_ID').val('');
			$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_SPPLY_NM').val('');
			listObj.button.search();
		}
	},
	empty: {
		init: function() {
			var _this = this;
			this.push();
			$(SETTMNG02010_GRID_EMPTY).on('click', function() {
				_this.back();
				_this.itp_SETTMNG02010_param.gridSize = $.jgrid.defaults.rowNum;
				$(SETTMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_SETTMNG02010_param)}).trigger('reloadGrid');
			});
		},
		itp_SETTMNG02010_param: {},
		push: function() {
			let param = $('#ITP_FORM_SETTMNG02010_SEARCH').serializeObject();
			listObj.itp_SETTMNG02010_param = param;
		},
		back: function() {
			$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_ID').val(listObj.itp_SETTMNG02010_param.sstoreId);
			$('#ITP_FORM_SETTMNG02010_SEARCH_STORE_NM').val(listObj.itp_SETTMNG02010_param.sstoreNm);
			$('#ITP_FORM_SETTMNG02010_SEARCH_FROM_DT').val(listObj.itp_SETTMNG02010_param.fromDt);
			$('#ITP_FORM_SETTMNG02010_SEARCH_TO_DT').val(listObj.itp_SETTMNG02010_param.toDt);
			$('#ITP_FORM_SETTMNG02010_SEARCH_ITEM_NM').val(listObj.itp_SETTMNG02010_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_SETTMNG02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;

			var option = {
				gridId: SETTMNG02010_GRID_ID,
				colModel: gridColModel.list,
				param: param,
				url: DOMAIN + STTL_STATE_DETAIL_GRID_LIST,
				pager: SETTMNG02010_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, SETTMNG02010_GRID_ID, true, 'number', 'SETTMNG02010', listObj.itp_SETTMNG02010_search, listObj.empty, true, data.gridRecords, true);
					var ids = $(SETTMNG02010_GRID_ID).getDataIDs();
					$.each(ids, function(idx, rowId) {
						$(SETTMNG02010_GRID_ID).jqGrid('setCell', rowId, 'sttlMgntUnqNo', '', ITP_GRID_COL_STYLE.link);
					});
				},
				onPaging: function(action) {
					itp_fn_grid_paging(SETTMNG02010_GRID_ID, action, param);
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(SETTMNG02010_GRID_ID).jqGrid('clearGridData', true);
			$(SETTMNG02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(SETTMNG02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(SETTMNG02010_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(SETTMNG02010_GRID_ID);
		}
	},
	excelDown: function() {
		var param = {
			'url': STTL_STATE_DETAIL_GRID_LIST,
			'param': $('#ITP_FORM_SETTMNG02010_SEARCH').serializeObject(),
			'gridColumns': $(SETTMNG02010_GRID_ID).jqGrid('getGridParam', 'colModel'),
			'fileName': '정산검수현황.xlsx',
			'sheetName': '정산검수리스트'
		};
		itp_fn_remote_to_excel(param);
	}
};

/*상세화면 Object*/
let modifyObj = {
	init: function (param) {
		this.load(param);
		this.grid.init();
	},
	button: {
		cancel: function() {
			listObj.grid.search();
		}, 
		confirmSttl: function() {
			// 정산확정
			const formId = '#ITP_FORM_SETTMNG02010_DETAIL';
			let param = $(formId).serializeObject();
			
			// console.log(JSON.stringify(param));
			var confirmFn= {
				callBack: function() {
					//
					var searhFn = function() {
						listObj.grid.search();
					};
					fn_ajax_call(STTL_INSPECT_STATE_STTL_CONFIRM, JSON.stringify(param), searhFn, 'POST'); 	
				}
			};
			itp_fn_modal_confirm('정산 확정하시겠습니까?', confirmFn, null);
		}, 
		rejectSttl: function() {
			// 정산반려
			fn_call_popup('biz', 'BIZPOP_STTL_REJECT_REASON', '#ITP_ASIDE', function(result) {
				// API 호출
				let param = {};
				param.sttlMgntUnqNo = $('#ITP_FORM_SETTMNG02010_DETAIL_STTL_MGNT_UNQ_NO').val();
				param.sttlRjctRsn = result;
				
				fn_ajax_call(STTL_INSPECT_STATE_STTL_REJECT, JSON.stringify(param), function() {
					listObj.grid.search();						
				}, 'POST');				
			}, null, 'S');
		}
	}, 
	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_SETTMNG02010_DETAIL_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_SETTMNG02010_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_SETTMNG02010_DETAIL_STTL_MGNT_UNQ_NO').val(result.sttlMgntUnqNo);
		
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSupplyNm').text(result.spplyNm);
		
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlRjctRsn').text(result.sttlRjctRsn == null ? '' : result.sttlRjctRsn);
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlStNm').text(result.sttlStNm);
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlReqDt').text(result.sttlReqDt);  // 정산일자
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlReqAmt').text(itp_fn_number_comma(result.sttlReqAmt));
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlDt').text(result.sttlDt == null ? '' : result.sttlDt);  // 정산일자
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSttlAmt').text(itp_fn_number_comma(result.sttlAmt));
		
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnAcctBal').text(itp_fn_number_comma(result.acctBal));
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSysRegDttm').text(result.sysRegDttm);
		$('#ITP_FORM_SETTMNG02010_DETAIL .fnSysRegNm').text(result.sysRegNm);
		
		// 정산요청 상태
		if(result.sttlStCd == 'ST10') {
			$('#ITP_BTN_SETTMNG02010_CONFIRM').show();
			$('#ITP_BTN_SETTMNG02010_REJECT').show();
		} else {
			$('#ITP_BTN_SETTMNG02010_CONFIRM').hide();
			$('#ITP_BTN_SETTMNG02010_REJECT').hide();
		}		

		// 리스트 조회
		modifyObj.grid.init();
	},
	grid: {
		init: function() {
			this.unload();
			this.load();
		},
		colModel: gridColModel.view,
		load : function() {
			let param = $('#ITP_FORM_SETTMNG02010_DETAIL').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			//param.pagingYn = false; // 페이징안함
			var option = {
				gridId: SETTMNG02010_DETAIL_GRID_ID,
				colModel: gridColModel.view,
				param: param,
				url: DOMAIN + STTL_REQ_STL_GRID_LIST,
				pager: SETTMNG02010_DETAIL_GRID_PAGER,
				loadComplete: function(data) {
					itp_fn_grid_load_complete(data, SETTMNG02010_DETAIL_GRID_ID, true, undefined, 'SETTMNG02010_DETAIL');
				},
				onPaging: function(action) {
					var pagingFn = {
						callBack: function(args) {
							$(args).trigger('reloadGrid');
						}
					};
					if (itp_fn_check_grid_is_writing(SETTMNG02010_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, pagingFn, SETTMNG02010_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_paging(SETTMNG02010_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(SETTMNG02010_DETAIL_GRID_ID)) {
						itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.cancelData, sortingFn, SETTMNG02010_DETAIL_GRID_ID);
						return 'stop';
					} else {
						itp_fn_grid_sorting(SETTMNG02010_DETAIL_GRID_ID, index, sortOrder);
					}
				}
			};
			itp_fn_grid_make_remote(option);
		},
		clearData : function() {
			$(SETTMNG02010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
			$(SETTMNG02010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(SETTMNG02010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(SETTMNG02010_DETAIL_GRID_EMPTY).show();
		},
		unload : function() {
			$.jgrid.gridUnload(SETTMNG02010_DETAIL_GRID_ID);
		}
	}
	
};
