/******************************************************** -------------------------------------------------------- - Object 목록 - -------------------------------------------------------- * const gridColModel = {} : 화면 Grid Object * * let pageObj = {} : 화면공통 Object * * let listObj = {} : 목록화면 Object * *******************************************************/ /*화면 변수*/ const STOCKMNG03010_GRID_ID = '#ITP_STOCKMNG03010_jqGrid'; const STOCKMNG03010_GRID_LIST = '#ITP_STOCKMNG03010_jqGrid_list'; const STOCKMNG03010_GRID_PAGER = '#ITP_STOCKMNG03010_jqGridPager'; const STOCKMNG03010_GRID_EMPTY = '#ITP_STOCKMNG03010_jqGridEmpty'; let ITP_FORM_STOCKMNG03010_IS_DUPLICATE = false; let ITP_FORM_STOCKMNG03010_IS_WRITING = false; let STOCKMNG03010_GRID_LAST_ROW_ID; /*API URL*/ let STOCK_BASE_MNG_DETAIL_GRID_LIST = '/api/stock/base/mng/detail-grid-list'; let WHS_MNG_DETAIL_GRID_LIST = '/api/whs/mng/detail-grid-list'; let WHS_MNG_LOCATION_GRID_LIST = '/api/whs/mng/location-grid-list'; let STOCK_BASE_MNG_SAVE = '/api/stock/base/mng/save'; let API_ITEM_CLASS_LEVEL = '/api/item/class-level-list'; //품목분류 level 검색 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_ID', name: 'brandId', label: "브랜드ID", width: '0', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'LOCATION', name: 'location', label: "로케이션", width: '0', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'BRAND_NM', name: 'brandNm', label: ITP_MSG_LOCALE.label.brandNm, //브랜드 width: '10', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'STORE_NM', name: 'storeNm', label: "매장명", width: '10', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'WHS_ID', name: 'whsId', label: "창고번호", width: '8', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'WHS_NM', name: 'whsNm', label: "창고명", width: '13', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'LOCATION_NM', name: 'locationNm', label: "로케이션명", width: '10', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'ITEM_ID', name: 'itemId', label: "품목번호", width: '13', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'ITEM_NM', name: 'itemNm', label: "품목명", width: '10', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'UNIT', name: 'unit', label: "단위", width: '4', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'PRP_STCK_QTY', name: 'prpStckQty', label: "적정재고수량", classes: 'input_color', width: '9', fixed: false, align: 'right', sortable: false, editable: true, edittype: 'text', editrules: {required: false}, editoptions: {"onKeyup": "this.value=this.value.replace(/[^0-9]/g,'');", maxlength: 10}, formatter: 'integer', formatoptions: {thousandsSeparator: ','} }, { index: 'SFT_STCK_RT', name: 'sftStckRt', label: "안전재고비율(%)", classes: 'input_color', width: '9', fixed: false, align: 'right', sortable: false, editable: true, edittype: 'text', editrules: {required: false, maxValue: 100}, editoptions: {"onKeyup": "this.value=this.value.replace(/[^0-9]/g,'');", maxlength: 3} } ] }; require(['config'], function() { require([ ], 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('STOCKMNG03010'); // 브랜드ID 지정 $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId')); $('#ITP_FORM_STOCKMNG03010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId')); LOGIN_AUTH_TYPE_CD = fn_make_user_info.get('authTpCd'); // 권한타입 pageObj.fnWhsList(function() { pageObj.fnLocationList(); }); // 창고리스트 // 공통코드 표시 // fn_make_select(CODE_LIST, 'WHS_DVSN', 'ITP_FORM_STOCKMNG03010_WHS_DVSN'); // 조회일자 지정 $('#ITP_TAB_STOCKMNG03010 .input-group.date').datepicker(ITP_DATE_LANGUAGE); // 분류 itemClassLevel.list(1, true); }, grid: function() { itp_fn_jqgrid_resize(STOCKMNG03010_GRID_ID, STOCKMNG03010_GRID_LIST, 'lg'); listObj.empty.init(); }, 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_STOCKMNG03010_SRH' : listObj.button.search(); break; // 조회 버튼 case 'ITP_BTN_STOCKMNG03010_SAVE' : listObj.button.save(); break; // 저장 버튼 case 'ITP_BTN_STOCKMNG03010_DETAIL_ADDROW' : listObj.button.addItem(); break; // 품목추가 버튼 case 'ITP_BTN_STOCKMNG03010_DETAIL_DELROW' : listObj.button.removeItem(); break; // 품목삭제 버튼 // case 'ITP_BTN_STOCKMNG03010_EXCEL' : listObj.excelDown(); break; // 엑셀 } }); }); $('body').on('click', function(e) { var gridId = STOCKMNG03010_GRID_ID.replace('#', ''); var rids = $(STOCKMNG03010_GRID_ID).jqGrid('getDataIDs'); var last_row_id = rids[rids.length - 1]; itp_fn_grid_reset_selection(e, last_row_id, gridId, 'STOCKMNG03010'); }); }, change: function () { // 창고 변경 $('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID').on('change', function() { pageObj.fnLocationList(function() { listObj.button.search(); // 조회 }); // 로케이션 리스트 }); $('#ITP_FORM_STOCKMNG03010_SEARCH_LOCATION').on('change', function() { listObj.button.search(); // 조회 }); } }, switchScreen: function(mode) { if(mode == 'LIST') { // 목록 itp_fn_fire_window_resize(); fn_show_btn_auth('#ITP_BTN_STOCKMNG03010_SRH'); $('#ITP_AJAX_STOCKMNG03010_LIST_CONTAINER').show(); $('#ITP_BTN_STOCKMNG03010_EXCEL').show(); } }, fnWhsList: function(fnCall) { const brandIdVal = $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(); const storeIdVal = $('#ITP_FORM_STOCKMNG03010_SEARCH_STORE_ID').val(); const whsDvsnVal = LOGIN_AUTH_TYPE_CD == '50' ? 'W02' : 'W01'; // 본사/매장 구분 const param = {sbrandId: brandIdVal, sstoreId: storeIdVal, swhsDvsn: whsDvsnVal, pagingYn: false}; fn_ajax_call(WHS_MNG_DETAIL_GRID_LIST, JSON.stringify(param), function(result) { fn_make_select_whs(result.gridRows, 'ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID'); if (fnCall !== undefined || typeof fnCall !== 'undefined') fnCall(); }, 'POST'); }, fnLocationList: function(fnCall) { const brandIdVal = $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(); const whsIdVal = $('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID').val(); const param = {brandId: brandIdVal, whsId: whsIdVal, pagingYn: false}; fn_ajax_call(WHS_MNG_LOCATION_GRID_LIST, JSON.stringify(param), function(result) { fn_make_select_location(result.gridRows, 'ITP_FORM_STOCKMNG03010_SEARCH_LOCATION'); if (fnCall !== undefined || typeof fnCall !== 'undefined') fnCall(); }, 'POST'); } }; /*목록화면 Object*/ let listObj = { init: function () { this.form(); this.grid.init(); }, itp_STOCKMNG03010_search: false, button: { search: function() { listObj.itp_STOCKMNG03010_search = true; let param = $('#ITP_FORM_STOCKMNG03010_SEARCH').serializeObject(); param.gridSize = $.jgrid.defaults.rowNum; param.gridPage = $.jgrid.defaults.page; $(STOCKMNG03010_GRID_ID).data('grid-param',param); $(STOCKMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid'); }, save: function() { $('body').trigger('click'); $('#ITP_FORM_STOCKMNG03010_WHS_ID').val($('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID').val()); $('#ITP_FORM_STOCKMNG03010_LOCATION').val($('#ITP_FORM_STOCKMNG03010_SEARCH_LOCATION').val()); const formId = '#ITP_FORM_STOCKMNG03010'; itp_fn_form_clear_validate(null, formId); let gridInsertData = []; let gridUpdateData = []; let gridDeleteData = []; const rowData = $(STOCKMNG03010_GRID_ID).getRowData(); if(rowData.length < 1) { itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.grid.noData); return; } $.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(gridInsertData.length < 1 && gridUpdateData.length < 1 && gridDeleteData.length < 1) { itp_fn_modal_alert_ajax('변경된 데이터가 없습니다.'); return; } let param = $(formId).serializeObject(); param.gridInsertData = gridInsertData; param.gridUpdateData = gridUpdateData; param.gridDeleteData = gridDeleteData; //console.log(JSON.stringify(param)); var searhFn = function() { ITP_FORM_STOCKMNG03010_DETAIL_IS_WRITING = false; listObj.grid.search(); }; fn_ajax_call(STOCK_BASE_MNG_SAVE, JSON.stringify(param), searhFn, 'POST'); }, addItem: function() { console.log("============="); var brandId = $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(); var args = {'brandId': brandId}; fn_call_popup('biz', 'BIZPOP_ITEM', '#ITP_ASIDE', listObj.button.addRowCallback, args, 'S'); }, addRowCallback: function(rowDataPop) { var brandId = $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(); var brandNm = $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_NM').val(); var whsId = $('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID').val(); var whsNm = $('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID option:selected').text(); var location = $('#ITP_FORM_STOCKMNG03010_SEARCH_LOCATION').val(); var locationNm = $('#ITP_FORM_STOCKMNG03010_SEARCH_LOCATION option:selected').text(); // 기존등록 데이터 체크 var exists = ''; const rowData = $(STOCKMNG03010_GRID_ID).getRowData(); $.each(rowData, function(key, value) { exists = exists + value.itemId + ';'; }); $.each(rowDataPop, function(key, value) { if(exists.indexOf(value.itemId) < 0) { // 행추가 $(STOCKMNG03010_GRID_ID).jqGrid('addRow', {position: 'last'}); var rids = $(STOCKMNG03010_GRID_ID).jqGrid('getDataIDs'); var last_row_id = rids[rids.length - 1]; $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'viewCd', 'C'); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'normalYn', 'Y'); // 정상여부 $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'brandId', brandId); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'brandNm', brandNm); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'whsId', whsId); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'whsNm', whsNm); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'location', location); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'locationNm', locationNm); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'itemId', value.itemId); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'itemNm', value.itemNm); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'unit', value.unit); $(STOCKMNG03010_GRID_ID).jqGrid('setCell', last_row_id, 'stckQty', value.stckQty); } }); $(STOCKMNG03010_GRID_EMPTY).hide(); }, removeItem: function() { itp_fn_grid_del_row(STOCKMNG03010_GRID_ID); } }, form: function() { $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS1').on('change', function() { ($(this).val() === '') ? itemClassLevel.clear(2, true): itemClassLevel.list(2, true); }); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS2').on('change', function() { ($(this).val() === '') ? itemClassLevel.clear(3, true): itemClassLevel.list(3, true); }); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS3').on('change', function() { ($(this).val() === '') ? itemClassLevel.clear(4, true): itemClassLevel.list(4, true); }); }, empty: { init: function() { var _this = this; this.push(); $(STOCKMNG03010_GRID_EMPTY).on('click', function() { _this.back(); _this.itp_STOCKMNG03010_param.gridSize = $.jgrid.defaults.rowNum; $(STOCKMNG03010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_STOCKMNG03010_param)}).trigger('reloadGrid'); }); }, itp_STOCKMNG03010_param: {}, push: function() { let param = $('#ITP_FORM_STOCKMNG03010_SEARCH').serializeObject(); listObj.itp_STOCKMNG03010_param = param; }, back: function() { $('#ITP_FORM_STOCKMNG03010_SEARCH_WHS_ID').val(listObj.itp_STOCKMNG03010_param.swhsId); $('#ITP_FORM_STOCKMNG03010_SEARCH_LOCATION').val(listObj.itp_STOCKMNG03010_param.slocation); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS1').val(listObj.itp_STOCKMNG03010_param.sitemClass1); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS2').val(listObj.itp_STOCKMNG03010_param.sitemClass2); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS3').val(listObj.itp_STOCKMNG03010_param.sitemClass3); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_CLASS4').val(listObj.itp_STOCKMNG03010_param.sitemClass4); $('#ITP_FORM_STOCKMNG03010_SEARCH_ITEM_NM').val(listObj.itp_STOCKMNG03010_param.sitemNm); } }, grid: { init: function () { // 데이터 없을때 listObj.empty.push(); this.search(); }, colModel: gridColModel.list, search: function() { pageObj.switchScreen('LIST'); this.unload(); this.load(); }, load: function() { $('#ITP_FORM_STOCKMNG03010_BRAND_ID').val(fn_make_user_info.get('brandId')); $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId')); $('#ITP_FORM_STOCKMNG03010_SEARCH_BRAND_NM').val(fn_make_user_info.get('brandNm')); let param = $('#ITP_FORM_STOCKMNG03010_SEARCH').serializeObject(); param.gridSize = $.jgrid.defaults.rowNum; var option = { gridId: STOCKMNG03010_GRID_ID, colModel: gridColModel.list, param: param, url: DOMAIN + STOCK_BASE_MNG_DETAIL_GRID_LIST, pager: STOCKMNG03010_GRID_PAGER, multiselect: true, rownumbers: false, onCellSelect: function(rowId, cellIdx, cellValue) { STOCKMNG03010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowId, cellIdx, STOCKMNG03010_GRID_LAST_ROW_ID, STOCKMNG03010_GRID_ID); }, loadComplete: function(data) { console.log(data); itp_fn_grid_load_complete(data, STOCKMNG03010_GRID_ID, true, 'number', 'STOCKMNG03010', listObj.itp_STOCKMNG03010_search, listObj.empty, true, data.gridRecords, true); var ids = $(STOCKMNG03010_GRID_ID).getDataIDs(); $.each(ids, function(idx, rowId) { // $(STOCKMNG03010_GRID_ID).jqGrid('setCell', rowId, 'whsNm', '', ITP_GRID_COL_STYLE.link); }); }, onPaging: function(action) { itp_fn_grid_paging(STOCKMNG03010_GRID_ID, action, param); } }; itp_fn_grid_make_remote(option); }, clearData : function() { $(STOCKMNG03010_GRID_ID).jqGrid('clearGridData', true); $(STOCKMNG03010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px'); $(STOCKMNG03010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData); $(STOCKMNG03010_GRID_EMPTY).show(); }, unload : function() { $.jgrid.gridUnload(STOCKMNG03010_GRID_ID); } }/*, excelDown: function() { var param = { 'url': STOCK_BASE_MNG_DETAIL_GRID_LIST, 'param': $('#ITP_FORM_STOCKMNG03010_SEARCH').serializeObject(), 'gridColumns': $(STOCKMNG03010_GRID_ID).jqGrid('getGridParam', 'colModel'), 'fileName': '재고기준정보.xlsx', 'sheetName': '재고기준정보리스트' }; itp_fn_remote_to_excel(param); }*/ }; var itemClassLevel = { isList: true, level: 1, keys: function() { var keys = {sBrandId:fn_make_user_info.get('brandId'), sItemLevel: this.level}; for(var i=1; i