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

/********************************************************
 --------------------------------------------------------
 - Object 목록								            -
 --------------------------------------------------------
 * const gridColModel = {}	: 화면 Grid Object			*
 * let pageObj = {}			: 화면공통 Object			*
 * let listObj = {}			: 목록화면 Object			*
 * let viewObj = {}			: 상세화면 Object			*
 * let modifyObj = {}		: 수정화면 Object			*
 * let createObj = {}		: 신규화면 Object			*
 *******************************************************/
console.log(CONN_KEY)
/*화면 변수*/
const POMNG01010_DETAIL_GRID_ID = '#ITP_POMNG01010_DETAIL_jqGrid';
const POMNG01010_DETAIL_GRID_LIST = '#ITP_POMNG01010_DETAIL_jqGrid_list';
const POMNG01010_DETAIL_GRID_PAGER = '#ITP_POMNG01010_DETAIL_jqGridPager';
const POMNG01010_DETAIL_GRID_EMPTY = '#ITP_POMNG01010_DETAIL_jqGridEmpty';  // ==>dwkim html확인필요

let POMNG01010_DETAIL_GRID_LAST_ROW_ID;

/*API URL*/
let API_DETAIL_INIT_INFO = '/api/pomng/init-pchReq'
let API_DETAIL_SAVE = '/api/pomng/save-pchReq';

/*화면 Grid ColModel   ==>선택박스 항목 추가 부분  */
const gridColModel = {
	detail: [
		{
			index: 'VIEW_CD', name: 'viewCd',
			label: ITP_MSG_LOCALE.label.viewCd,
			width: '10', fixed: false, align: 'center',
			sortable: false, hidden: true
		},
		{
			index: 'ITEM_ID', name: 'itemId',
			label: ITP_MSG_LOCALE.label.itemId,
			width: '14', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text',
			editrules: { required: true }
		},
		{
			index: 'ITEM_NM', name: 'itemNm',
			label: ITP_MSG_LOCALE.label.itemNm,
			width: '32', fixed: false, align: 'left',
			sortable: false, editable: false, edittype: 'text',
			editrules: { required: true }, classes: 'ui-ellipsis'
		},
		{
			index: 'UNIT', name: 'unit',
			label: ITP_MSG_LOCALE.label.unit,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text'
		},
		{
			index: 'UNIT_AMT', name: 'unitAmt',
			label: ITP_MSG_LOCALE.label.unitAmt,
			width: '6', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'PCH_REQ_QTY', name: 'pchReqQty',
			label: ITP_MSG_LOCALE.label.pchReqQty, //수량
			width: '14', fixed: false, align: 'right',
			sortable: false, editable: true, edittype: 'text',
			classes: 'input_color',
			editoptions: {"onKeyup": "this.value=this.value.replace(/[^0-9]/g,'');", maxlength: 10}, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},
		{
			index: 'PCH_REQ_AMT', name: 'pchReqAmt',
			label: ITP_MSG_LOCALE.label.pchReqAmt,
			width: '14', fixed: false, align: 'right',
			sortable: false, editable: false, edittype: 'text', hidden: false, 
			formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
		},

		{
			index: 'BRAND_UNIT_UNQ_NO', name: 'brandUnitUnqNo',
			label: ITP_MSG_LOCALE.label.brandUnitUnqNo,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text', hidden: true
		},
		{
			index: 'STORE_UNIT_UNQ_NO', name: 'storeUnitUnqNo',
			label: ITP_MSG_LOCALE.label.storeUnitUnqNo,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text', hidden: true
		},
		{
			index: 'UNIT_GUBUN', name: 'unitGubun',
			label: ITP_MSG_LOCALE.label.unitGubun,
			width: '10', fixed: false, align: 'center',
			sortable: false, editable: false, edittype: 'text', hidden: true
		}
	]
};

/*화면공통 Object*/
let pageObj = {
	init: function() {
		this.ui.init();
		this.event.init();
		this.action();
	},
	action: function () {
		var _this = this;
		// 납품장소 조회 버튼 클릭
		$('#ITP_FORM_POMNG01010_SEARCH_WHS_NM').on('click', function() {
			_this.popup();
		});
		// 납품장소 텍스트 삭제 버튼 클릭
		$('#ITP_FORM_POMNG01010_DELETE_WHS_NM').on('click', function() {
			$('#ITP_FORM_POMNG01010_DETAIL_WHS_NM').val('');
			$('#ITP_FORM_POMNG01010_DETAIL_WHS_ID').val('');
			$('#ITP_FORM_POMNG01010_DETAIL_LOCATION_NM').val('');
			$('#ITP_FORM_POMNG01010_DETAIL_LOCATION').val('');
			
		});
	},
	popup: function () {
		// 팝업
		var popFn = this.callback.create;
		
		var whsDvsn = "";
		if (fn_make_user_info.get('storeId') == '' ) {
			whsDvsn = "W01";
		} else {
			whsDvsn = "W02";
		}
		
		const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId'),whsDvsn: whsDvsn};
		fn_call_popup('biz', 'BIZPOP_WHS_LOCATION', '#ITP_ASIDE', popFn, key, 'S');
		
	},
	callback: {
		create: function(rowDataPop) {
			console.log(rowDataPop);
			if(rowDataPop) {
				$('#ITP_FORM_POMNG01010_DETAIL_WHS_NM').val(rowDataPop.whsNm);
				$('#ITP_FORM_POMNG01010_DETAIL_WHS_ID').val(rowDataPop.whsId);
				$('#ITP_FORM_POMNG01010_DETAIL_LOCATION_NM').val(rowDataPop.locationNm);
				$('#ITP_FORM_POMNG01010_DETAIL_LOCATION').val(rowDataPop.location);
			}
			
		}
	},
	itp_POMNG01010_param: {},  // ==>dwkim 
	itp_POMNG01010_search: false,  // ==>dwkim 
	ui: {
		init: function() {
			this.view();
			this.grid();
			this.ready();
		},
		view: function() {
			// 버튼 권한설정
			fn_proc_btn_auth('POMNG01010');
			
			// 공통코드 표시
			$('select').each(function() {
				if ($(this).data('select-code')) {
					fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
				}
			});

			// 조회일자 지정
			//var now = new Date(date.getDate() + 5);
			var now = new Date();
			$('#ITP_TAB_POMNG01010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
			$('#ITP_FORM_POMNG01010_DETAIL_DLV_REQ_DT').datepicker('setDate', new Date(now.setDate(now.getDate() + 5)));
			
			//납품장소 필드 readonly
			$('#ITP_FORM_POMNG01010_DETAIL_WHS_NM').attr('readonly', true);
			$('#ITP_FORM_POMNG01010_DETAIL_LOCATION_NM').attr('readonly', true);
			
		},
		grid: function() {
			itp_fn_jqgrid_resize(POMNG01010_DETAIL_GRID_ID, POMNG01010_DETAIL_GRID_LIST, 'lg');
			
			//itp_fn_fire_window_resize();
		},
		ready: function() {
			createObj.init();
		}
	},
	event: {
		init: function() {
			this.button();
		},
		button: function() {
			// 버튼 클릭 이벤트
			$('button').each(function() {
				var id = $(this).attr('id');
				$(this).on('click', function() {
					switch (id) {
						case 'ITP_BTN_POMNG01010_SRH': createObj.button.save("PR20"); break;	// 구매요청
						case 'ITP_BTN_POMNG01010_NEWREG': createObj.button.save("PR00"); break;	// 임시저장
						case 'ITP_BTN_POMNG01010_DETAIL_ADDROW': pageObj.grid.button.addRow(); break;	// 품목추가
						case 'ITP_BTN_POMNG01010_DETAIL_DELROW': pageObj.grid.button.delRow(); break;	// 품목삭제
					}
				});
			});
			
			$('body').on('click', function(e) {
				var gridId = POMNG01010_DETAIL_GRID_ID.replace('#', '');
				var rids = $(POMNG01010_DETAIL_GRID_ID).jqGrid('getDataIDs');
				var last_row_id = rids[rids.length - 1];
				
				itp_fn_grid_reset_selection(e, last_row_id, gridId, 'POMNG01010_DETAIL');	
				
				pageObj.grid.recal();			
			});

		}
	},
	grid: {
		init: function(mode, gridData) {
			this.mode = mode;
			this.gridId = POMNG01010_DETAIL_GRID_ID;
			this.unload();  // ==>dwkim 
			this.load(gridData);
		},
		mode: 'DETAIL',
		gridId: '',
		button: {
			addRow: function() {
				// 팝업
				var popFn = function(rowDataPop) {
					console.log(rowDataPop);
					// 기존등록 데이터
					var exists = '';
					const rowData = $(POMNG01010_DETAIL_GRID_ID).getRowData();
					$.each(rowData, function(key, value) {
						exists = exists + value.brandUnitUnqNo + ';';
					});

					$.each(rowDataPop, function(key, value) {
						if (exists.indexOf(value.brandUnitUnqNo) < 0 && value.podrPssblDvsn == 'PO01') {
							value['viewCd'] = "C";
							$(POMNG01010_DETAIL_GRID_ID).jqGrid('addRowData', value.brandUnitUnqNo, value, 'last');
						}
					});
					$(POMNG01010_DETAIL_GRID_EMPTY).hide();
				};
				const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId')};
				fn_call_popup('biz', 'BIZPOP_ITEM', '#ITP_ASIDE', popFn, key, 'S');  // ==>dwkim 추후 작업 진행  파라메타 설명필요
			},
			delRow: function() {
				itp_fn_grid_del_row(POMNG01010_DETAIL_GRID_ID);
				// 그리드 포문으로 금액 재계산후 구매요청금액에 넣어줌
				pageObj.grid.recal();  //==>dwkim 왜 호출이 안될까요
			}
		},
		load: function(gridData) {  // ==>dwkim  오픈시 데이타 가져오는 부분 넣으면 되는건지 여부 gird가 아님
			var _this = this;
			var option = {
				gridId: this.gridId,
				colModel: gridColModel.detail,
				data: gridData,
				multiselect: true,
				// cellEdit: true,
				onCellSelect: function(rowId, cellIdx, cellValue) {
					POMNG01010_DETAIL_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowId, cellIdx, POMNG01010_DETAIL_GRID_LAST_ROW_ID, POMNG01010_DETAIL_GRID_ID, ['pchReqQty']);
		   		},
				loadComplete: function(data) {
					_this.clearData();
				}
			};
			itp_fn_grid_make_local(option);
		},
		clearData: function() {
			// console.log(this.gridId);
			$(POMNG01010_DETAIL_GRID_ID).jqGrid('clearGridData', true);
			$(POMNG01010_DETAIL_GRID_LIST).find('.ui-jqgrid .ui-jqgrid-bdiv').css('overflow-x', 'hidden');
			$(POMNG01010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
			$(POMNG01010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
			$(POMNG01010_DETAIL_GRID_EMPTY).show();
		},
		recal: function() {
			
			var ids = $(POMNG01010_DETAIL_GRID_ID).getDataIDs();
			$.each(ids, function(idx, rowId) {
				
				var viewCd = jQuery(POMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'viewCd');
				var unitAmt = jQuery(POMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'unitAmt');
				var pchReqQty = jQuery(POMNG01010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'pchReqQty');
				
				if(viewCd != 'D' && unitAmt != null && unitAmt != '' && pchReqQty != null && pchReqQty != '') {		
					jQuery(POMNG01010_DETAIL_GRID_ID).jqGrid('setRowData',rowId,{pchReqAmt: parseInt(unitAmt)*parseInt(pchReqQty)});
				}
			});
			
			const rowData = $(POMNG01010_DETAIL_GRID_ID).getRowData();
			var pchReqAmt = 0 ;
			$.each(rowData, function(key, value) {
				// console.log(JSON.stringify(rowData));
				if (value.pchReqAmt != null && value.pchReqAmt != "" && value.viewCd != "D") {
					pchReqAmt = pchReqAmt + parseInt(value.pchReqAmt) ;
				}				
			});
			$('#ITP_FORM_POMNG01010_DETAIL .fnPchReqAmt').text(itp_fn_number_comma(pchReqAmt));
		},
		unload: function() {
			$.jgrid.gridUnload(this.gridId);
		}
	}
};

/*신규화면 Object  */
let createObj = {
	init: function() {
		$('#ITP_FORM_POMNG01010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
		$('#ITP_FORM_POMNG01010_DETAIL_STORE_ID').val(fn_make_user_info.get('storeId'));
		//let param = 'brandId=' + LOGIN_USER_INFO.brandId + "&spplyId=" + LOGIN_USER_INFO.spplyId;
		this.load();
	},
	newinit: function() {
		$('#ITP_FORM_POMNG01010_DETAIL_BRAND_ID').val(fn_make_user_info.get('brandId'));
		$('#ITP_FORM_POMNG01010_DETAIL_STORE_ID').val(fn_make_user_info.get('storeId'));
		$('#ITP_FORM_POMNG01010_DETAIL_PCH_REQ_NM').val('');
		$('#ITP_FORM_POMNG01010_DETAIL_NOTE').val('');
		var now = new Date();
		$('#ITP_TAB_POMNG01010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
		$('#ITP_FORM_POMNG01010_DETAIL_DLV_REQ_DT').datepicker('setDate', new Date(now.setDate(now.getDate() + 5)));
		
		
		this.load();  //==>dwkim 초기화 하여 다시 초기 데이타 가져와 뿌려줌
		const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId')};
		fn_ajax_call(API_DETAIL_INIT_INFO, key, this.callback, 'GET');
	},
	button: {
		save: function(arg) {
			$('body').trigger('click');
			
			const formId = '#ITP_FORM_POMNG01010_DETAIL';
			itp_fn_form_clear_validate(null, formId);
			$('#ITP_FORM_POMNG01010_DETAIL_PCH_REQ_ST_CD').val(arg);
			
			var dlvReqDt = $('#ITP_FORM_POMNG01010_DETAIL_DLV_REQ_DT').val();
			var itemcnt  = $(POMNG01010_DETAIL_GRID_ID).getGridParam('reccount');
			var dlvReqAmt = $('#ITP_FORM_POMNG01010_DETAIL .fnPchReqAmt').text();
			var apprArg = {};
			
			var pchActAtm = itp_fn_currency_unfmatter($('#ITP_FORM_POMNG01010_DETAIL .fnPchActAmt').text(),"","");
			var pchReqAtm = itp_fn_currency_unfmatter($('#ITP_FORM_POMNG01010_DETAIL .fnPchReqAmt').text(),"","");
			var mallId = $('#ITP_FORM_POMNG01010_DETAIL_MALL_ID').val();
			
			//정산 타입이 무정산이면 스킵
			var apprTypeCd = "Y" // Y 정상결재, NP 선불, NA 후불   
			var loanDvsn = $('#ITP_FORM_POMNG01010_DETAIL_LOAN_DVSN').val();
			
			if (loanDvsn != null && loanDvsn != "") {
				
				if (loanDvsn != 'LD03' && arg == 'PR20' ) {
					if (parseFloat(pchActAtm) < parseFloat(pchReqAtm)) {
						
						dlvReqAmt = itp_fn_number_comma(String(parseInt(pchReqAtm) - parseInt(pchActAtm)));
						console.log(dlvReqAmt);
						if (mallId == '') {
							if (loanDvsn == 'LD01') {
								apprTypeCd = 'NPN';
							} else {
								apprTypeCd = 'NAN';
							}
						} else {
							if (loanDvsn == 'LD01') {
								apprTypeCd = 'NP';
							} else {
								apprTypeCd = 'NA';
							}
							
						}
					} else {
						dlvReqAmt = 0 ;
					}
				}  else if (loanDvsn == 'LD03' && arg == 'PR20' ) {
					
					dlvReqAmt = 0 ;
					
				} 
			}        
			
			if (itp_fn_form_event.isValid(formId)) {
				// 품목대상 정보 확인 필요
				var records = $(POMNG01010_DETAIL_GRID_ID).getGridParam('reccount');
				if (records == 0) {
					alert( "요청할 품목내역이 없습니다.");
					return ;
				}
				
				
				var now = new Date();
					var today = now.getFullYear() +
									"." + (now.getMonth()+1 > 9 ? (now.getMonth()+1).toString() : "0" + (now.getMonth()+1).toString()) +
									"." + (now.getDate() > 9 ? now.getDate().toString() : "0" + now.getDate().toString());
				
				var dlvReqDt = $('#ITP_FORM_POMNG01010_DETAIL_DLV_REQ_DT').val();
				if (today > dlvReqDt) {
					alert("납품요청일은 오늘 이후이어야 합니다.");
					return;
				}	
			
				const rowChkData = $(POMNG01010_DETAIL_GRID_ID).getRowData();
				var chkQtyYn = "N";
				$.each(rowChkData, function(key, value) {
					if (value.pchReqQty == '' || value.pchReqQty < 1 ) {
						alert("요청수량을 입력해주세요!");
						chkQtyYn = "Y";
						return false;
					}
				});
				if (chkQtyYn == "Y") return;
				
				if (arg == 'PR20') {
					
					apprArg.dlvReqDt = dlvReqDt;
					apprArg.itemcnt = itemcnt;
					apprArg.pchReqAtm = itp_fn_number_comma(pchReqAtm);
					apprArg.pchPssblAtm = itp_fn_number_comma(pchActAtm);
					apprArg.dlvReqAmt = dlvReqAmt;
					
					console.log(apprArg);
					
					if (apprTypeCd == "Y") {  // 여신 구분, 여신금액
						
						var prIngFn =  {
							callBack: function(args) {
									createObj.button.saveLastReq(arg);
								}
							};
						itp_fn_modal_confirm_req1(apprArg, prIngFn, arg);
							
					} else // 금액 부족시 
						createObj.button.saveApprReq(apprArg,apprTypeCd, arg);
				} else {
					console.log("===");
					console.log(arg);
					createObj.button.saveReq(apprArg);
				}
			}
				
		},
		saveReq: function(arg) {
			const formId = '#ITP_FORM_POMNG01010_DETAIL';
			
			var saveFn = {
				callBack: function(args) {
					$(formId).val(arg);
					let gridInsertData = [];
					let gridUpdateData = [];
					let gridDeleteData = [];
					
					const rowData = $(POMNG01010_DETAIL_GRID_ID).getRowData();
					
					$.each(rowData, function(key, value) {
						if (value.viewCd !== 'R') {
							if (value.viewCd === 'C') {
								gridInsertData.push(value);
							} else if (value.viewCd === 'U') {
								gridUpdateData.push(value);
							} else if (value.viewCd === 'D') {
								gridDeleteData.push(value);
							}
						}
					});
					
					//if (chkQtyYn == "Y") return;
					
					let param = $(formId).serializeObject();
					param.gridInsertData = gridInsertData;
					param.gridUpdateData = gridUpdateData;
					param.gridDeleteData = gridDeleteData;
					console.log(JSON.stringify(param));
					var searhFn = function() {
						createObj.newinit();
					};
					fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');				
				}
			};
		itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.tmpSave, saveFn, null);
		},
		saveApprReq: function(param, apprTypeCd, arg) {
			
			var apprFn =  {
				callBack: function(args) {
						// 결재금액이 부족하여 결재란으로 이동처리
					var popFn = function(rowDataPop) {
						// 결재 성공시 승인처리함 
						createObj.button.saveLastReq(arg);
					};			
					// 결제 팝업 : LD01(선불(충전)), LD02(후불(신용))
					// 결제타입코드 : 10(선불(충전)), 20(후불(결제)), 30(후불(선결제))		
					// 구매요청 번호 전달 - 
					//var loanDvsn = $('#ITP_FORM_LOANMNG02010_SEARCH_STORE_LOAN_DVSN').val();
					var pchActAtm = itp_fn_currency_unfmatter($('#ITP_FORM_POMNG01010_DETAIL .fnPchActAmt').text(),"","");
					var pchReqAtm = itp_fn_currency_unfmatter($('#ITP_FORM_POMNG01010_DETAIL .fnPchReqAmt').text(),"","");
					
					
					var args = {'payTpCd': '40',
					'brandId':   fn_make_user_info.get('brandId'), 
					'storeId':   fn_make_user_info.get('storeId'),
					'prchReqUnqNo': $('ITP_FORM_POMNG01010_DETAIL_PCH_REQ_UNQ_NO').val(),
					'goodsAmt':  pchReqAtm-pchActAtm}; 
					
					fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', popFn, args, 'S');
				}
			};
				
			var apprNFn =  {
				callBack: function(args) {
						// 임시저장 처리한다.
					arg = 'PR00';
					$('#ITP_FORM_POMNG01010_DETAIL_PCH_REQ_ST_CD').val(arg);
					
					createObj.button.saveLastReq(arg);
				}
			};
						//console.log(apprTypeCd) ;
			if (apprTypeCd == 'NP') {  // 선불
				itp_fn_modal_confirm_req2(param, apprFn, arg);
			} else if (apprTypeCd == 'NA') { //후불
				itp_fn_modal_confirm_req3(param, apprFn, arg);
			} else if (apprTypeCd == 'NPN') { //선불 pg없음 임시저장으로
				itp_fn_modal_confirm_req4(param, apprNFn, arg);
			} else if (apprTypeCd == 'NAN') { //후불  pg없음 임시저장으로
				itp_fn_modal_confirm_req5(param, apprNFn, arg);
			}
		},
		saveLastReq: function(arg) {
			const formId = '#ITP_FORM_POMNG01010_DETAIL';
			
			$(formId).val(arg);
			let gridInsertData = [];
			let gridUpdateData = [];
			let gridDeleteData = [];
			
			const rowData = $(POMNG01010_DETAIL_GRID_ID).getRowData();
			
			$.each(rowData, function(key, value) {
				if (value.viewCd !== 'R') {
					if (value.viewCd === 'C') {
						gridInsertData.push(value);
					} else if (value.viewCd === 'U') {
						gridUpdateData.push(value);
					} else if (value.viewCd === 'D') {
						gridDeleteData.push(value);
					}
				}
			});
			
			//if (chkQtyYn == "Y") return;
			
			let param = $(formId).serializeObject();
			param.gridInsertData = gridInsertData;
			param.gridUpdateData = gridUpdateData;
			param.gridDeleteData = gridDeleteData;
			console.log(JSON.stringify(param));
			var searhFn = function() {
				createObj.newinit();
			};
			fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST');				
				
		},	
			
	},
	load: function() {
		const key = {brandId:fn_make_user_info.get('brandId'),storeId:fn_make_user_info.get('storeId')};
		fn_ajax_call(API_DETAIL_INIT_INFO, key, this.callback, 'GET');
	},
	callback: function(result) {
		console.log(result);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_VIEW_CD').val('C');

		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_BRAND_ID').val(result.brandId);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_STORE_ID').val(result.storeId);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_LOAN_DVSN').val(result.loanDvsn);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_LOAN_MGNT_UNQ_NO').val(result.loanMgntUnqNo);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_PCH_REQ_DVSN').val(result.pchReqDvsn);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_WHS_ID').val(result.whsId);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_WHS_NM').val(result.whsNm);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_LOCATION').val(result.location);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_LOCATION_NM').val(result.locationNm);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_MALL_ID').val(result.mallId);
		
		$('#ITP_FORM_POMNG01010_DETAIL .fnBrandNm').text(result.brandNm);
		$('#ITP_FORM_POMNG01010_DETAIL .fnPchReqDept').text(result.reqDept);
		$('#ITP_FORM_POMNG01010_DETAIL .fnPchReqMgrNm').text(result.userNm);
		$('#ITP_FORM_POMNG01010_DETAIL .fnPchReqAmt').text("0");
		$('#ITP_FORM_POMNG01010_DETAIL .fnLoanDvsnNm').text(result.loanDvsnNm);
		var pchActAmt
		if(result.ordUseAmt == 'Infinity' || result.ordUseAmt == Infinity || result.ordUseAmt == 0){
			pchActAmt = 0;
		} else {
			pchActAmt = result.ordUseAmt
		}
		$('#ITP_FORM_POMNG01010_DETAIL .fnPchActAmt').text(itp_fn_number_comma(pchActAmt));		
		$('#ITP_FORM_POMNG01010_DETAIL .fnPchReqUnqNo').text(result.pchReqUnqNo);
		$('#ITP_FORM_POMNG01010_DETAIL #ITP_FORM_POMNG01010_DETAIL_PCH_REQ_UNQ_NO').val(result.pchReqUnqNo);

		pageObj.grid.init();
	}
};
