require(['config'], function() { require([], function($) { pageObj.init(); }); }); /******************************************************** -------------------------------------------------------- - Object 목록 - -------------------------------------------------------- * const gridColModel = {} : 화면 Grid Object * * let pageObj = {} : 화면공통 Object * * let listObj = {} : 목록화면 Object * * let modifyObj = {} : 수정화면 Object * *******************************************************/ /*화면 변수*/ const COLLMNG02010_GRID_ID = '#ITP_COLLMNG02010_jqGrid'; const COLLMNG02010_GRID_LIST = '#ITP_COLLMNG02010_jqGrid_list'; const COLLMNG02010_GRID_PAGER = '#ITP_COLLMNG02010_jqGridPager'; const COLLMNG02010_GRID_EMPTY = '#ITP_COLLMNG02010_jqGridEmpty'; const COLLMNG02010_DETAIL_GRID_ID = '#ITP_COLLMNG02010_DETAIL_jqGrid'; const COLLMNG02010_DETAIL_GRID_LIST = '#ITP_COLLMNG02010_DETAIL_jqGrid_list'; const COLLMNG02010_DETAIL_GRID_PAGER = '#ITP_COLLMNG02010_DETAIL_jqGridPager'; const COLLMNG02010_DETAIL_GRID_EMPTY = '#ITP_COLLMNG02010_DETAIL_jqGridEmpty'; //let ITP_FORM_COLLMNG02010_DETAIL_IS_WRITING = false; let COLLMNG02010_GRID_LAST_ROW_ID; /*API URL*/ let API_DETAIL_GRID_LIST = '/api/rtnmng/inoutmng/spply-target-rtn-grid-list'; // 목록 let API_DETAIL_INIT_INFO = '/api/rtnmng/inoutmng/init-spply-col'; // 정보 let API_DETAIL_SAVE = '/api/rtnmng/inoutmng/save-spply-col'; // 수거서생성 /*화면 Grid ColModel*/ const gridColModel = { list: [ { index: 'BRAND_ID', name: 'brandId', label: ITP_MSG_LOCALE.label.brandId, //브랜드아이디 width: '13', 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: 'RTN_PODR_UNQ_NO', name: 'rtnPodrUnqNo', label: ITP_MSG_LOCALE.label.rtnPodrUnqNo, //반품발주번호 width: '10', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'RTN_PODR_DTL_NO', name: 'rtnPodrDtlNo', label: ITP_MSG_LOCALE.label.rtnPodrDtlNo, //반품발주항번 width: '10', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'ITEM_ID', name: 'itemId', label: ITP_MSG_LOCALE.label.itemId, //품목아이디 width: '10', fixed: false, align: 'center', minwidth: 150, sortable: false, hidden: false }, { index: 'ITEM_NM', name: 'itemNm', label: ITP_MSG_LOCALE.label.itemNm, //품목명 width: '10', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'RTN_WHS_ID', name: 'rtnWhsId', label: ITP_MSG_LOCALE.label.rtnWhsId, //수거창고아이디 width: '13', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'RTN_WHS_NM', name: 'rtnWhsNm', label: ITP_MSG_LOCALE.label.rtnWhsNm, //수거창고명 width: '15', fixed: false, align: 'left', minwidth: 220, sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'RTN_LOCATION', name: 'rtnLocation', label: ITP_MSG_LOCALE.label.rtnLocation, //납품수거LOCATION width: '15', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'UNIT_AMT', name: 'unitAmt', label: ITP_MSG_LOCALE.label.unitAmt, //단가 width: '6', fixed: false, align: 'right', sortable: false, hidden: false, formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' } }, { index: 'RTN_ODR_QTY', name: 'rtnOdrQty', label: ITP_MSG_LOCALE.label.rtnOdrQty, //rtnOdrAmt width: '10', fixed: false, align: 'right', sortable: false, hidden: false, formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' } }, { index: 'COL_REQ_DT', name: 'colReqDt', label: ITP_MSG_LOCALE.label.colReqDt, //수거요청일 width: '20', fixed: false, align: 'center', sortable: false, hidden: true, editable: false, sorttype: "date" } ], detail: [ { index: 'RTN_PODR_UNQ_NO', name: 'rtnPodrUnqNo', label: ITP_MSG_LOCALE.label.rtnPodrUnqNo, //반품발주번호 width: '10', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'RTN_PODR_DTL_NO', name: 'rtnPodrDtlNo', label: ITP_MSG_LOCALE.label.rtnPodrDtlNo, //반품발주항번 width: '10', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'ITEM_ID', name: 'itemId', label: ITP_MSG_LOCALE.label.itemId, //품목아이디 width: '10', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'ITEM_NM', name: 'itemNm', label: ITP_MSG_LOCALE.label.itemNm, //품목명 width: '10', fixed: false, align: 'left', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'UNIT', name: 'unit', label: ITP_MSG_LOCALE.label.unit, //단위 width: '6', fixed: false, align: 'center', sortable: false, hidden: false }, { index: 'UNIT_AMT', name: 'unitAmt', label: ITP_MSG_LOCALE.label.unitAmt, //단가 width: '6', fixed: false, align: 'right', sortable: false, hidden: false, formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' } }, { index: 'RTN_ODR_QTY', name: 'rtnOdrQty', label: ITP_MSG_LOCALE.label.rtnOdrQty, //반품발주수량 width: '10', fixed: false, align: 'right', sortable: false, hidden: false, formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' } }, { index: 'COL_QTY', name: 'colQty', label: ITP_MSG_LOCALE.label.colQty, //수거수량 width: '10', fixed: false, align: 'right', sortable: true, editable: true, edittype: 'text', editrules: { required: true, number: true }, classes: 'input_color', formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' }, editoptions: {"onKeyup": "this.value=this.value.replace(/[^0-9]/g,'');"} }, { index: 'RTN_RSN_DVSN_NM', name: 'rtnRsnDvsnNm', label: ITP_MSG_LOCALE.label.rtnRsnDvsnNm, //반품사유 width: '10', fixed: false, align: 'center', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'RTN_RSN_DVSN', name: 'rtnRsnDvsn', label: ITP_MSG_LOCALE.label.rtnRsnDvsn, //반품사유 width: '10', fixed: false, align: 'center', sortable: false, hidden: true }, { index: 'RTN_RSN', name: 'rtnRsn', label: ITP_MSG_LOCALE.label.rtnRsn, //비고 width: '10', fixed: false, align: 'center', sortable: false, hidden: false, classes: 'ui-ellipsis' }, { index: 'COL_AMT', name: 'colAmt', label: ITP_MSG_LOCALE.label.colAmt, // width: '10', fixed: false, align: 'right', sortable: false, hidden: false, formatter: 'integer', formatoptions: { defaultValue: '', thousandsSeparator: ',' } } ] }; /*화면공통 Object*/ let pageObj = { init: function () { this.ui.init(); this.event.init(); this.action(); }, ui: { init: function () { this.view(); this.grid(); this.ready(); }, view: function() { // 버튼 권한설정 fn_proc_btn_auth('COLLMNG02010'); // 공통코드 표시 $('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_COLLMNG02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE); $('#ITP_FORM_COLLMNG02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setDate(now.getDate()))); $('#ITP_FORM_COLLMNG02010_SEARCH_TO_DT').datepicker('setDate', new Date(now.setDate(now.getDate() + 30))); $('#ITP_FORM_COLLMNG02010_SEARCH #ITP_FORM_COLLMNG02010_SEARCH_SSPPLY_ID').val(fn_make_user_info.get('spplyId')); }, grid: function() { //itp_fn_jqgrid_resize(COLLMNG02010_GRID_ID, COLLMNG02010_GRID_LIST, 'lg'); itp_fn_fire_window_resize(); }, ready: function() { listObj.init(); } }, action: function () { var _this = this; // 수거창고 조회 버튼 클릭 $('#ITP_BTN_COLLMNG02010_SEARCH_RTN_WHS_ID').on('click', function() { _this.popup(); }); // 출하창고 텍스트 삭제 버튼 클릭 $('#ITP_BTN_COLLMNG02010_DELETE_RTN_WHS_ID').on('click', function() { $('#ITP_FORM_COLLMNG02010_SEARCH_SRTN_WHS_NM').val(''); $('#ITP_FORM_COLLMNG02010_SEARCH_SRTN_WHS_ID').val(''); }); }, popup: function (arg) { var popFn = this.callback.rtnwhs; var whsDvsn = ""; 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: { rtnwhs: function(rowDataPop) { if (rowDataPop) { $('#ITP_FORM_COLLMNG02010_SEARCH_SRTN_WHS_NM').val(rowDataPop.whsNm); $('#ITP_FORM_COLLMNG02010_SEARCH_SRTN_WHS_ID').val(rowDataPop.whsId); } } }, event: { init: function () { this.button(); }, button: function () { // 버튼 클릭 이벤트 $('button').each(function() { var id = $(this).attr('id'); $(this).on('click', function() { switch (id) { case 'ITP_BTN_COLLMNG02010_SRH' : listObj.button.search(); break; case 'ITP_BTN_COLLMNG02010_CUDW' : listObj.button.colcreat(); break; // 수거서생성 case 'ITP_BTN_COLLMNG02010_CRT' : modifyObj.button.save() ; break; // 생성 case 'ITP_BTN_COLLMNG02010_CANCELLIST' : modifyObj.button.cancel(); break; case 'ITP_BTN_COLLMNG02010_EXCEL' : listObj.excelDown(); break; // 엑셀 다운로드 } }); }); $('body').on('click', function(e) { var gridId = (COLLMNG02010_DETAIL_GRID_ID).replace('#', ''); var rids = $(COLLMNG02010_DETAIL_GRID_ID).jqGrid('getDataIDs'); var last_row_id = rids[rids.length - 1]; itp_fn_grid_reset_selection(e, last_row_id, gridId, 'COLLMNG02010_DETAIL'); modifyObj.button.recal(); }); } }, switchScreen: function(mode) { $('.itp_det_head').find('button[id^="ITP_BTN_COLLMNG02010_"]').each(function(i) { $(this).hide(); }); $('#ITP_TAB_COLLMNG02010').find('div[id$="_CONTAINER"]').each(function(i) { $(this).hide(); }); if(mode == 'LIST') { // 목록 $('#ITP_AJAX_COLLMNG02010_LIST_CONTAINER').show(); $('#ITP_BTN_COLLMNG02010_DELETE_RTN_WHS_ID').show(); fn_show_btn_auth_array(['#ITP_BTN_COLLMNG02010_SRH', '#ITP_BTN_COLLMNG02010_CUDW']); $('#ITP_FORM_COLLMNG02010_SEARCH_SBRAND_ID').val(fn_make_user_info.get('brandId')); $('#ITP_FORM_COLLMNG02010_SEARCH_SSPPLY_ID').val(fn_make_user_info.get('spplyId')); $('#ITP_BTN_COLLMNG02010_EXCEL').show(); } else if(mode == 'DETAIL') { // 수거서 작성 $('#ITP_AJAX_COLLMNG02010_DETAIL_CONTAINER').show(); fn_show_btn_auth_array(['#ITP_BTN_COLLMNG02010_CRT', '#ITP_BTN_COLLMNG02010_CANCELLIST']); $('#ITP_FORM_COLLMNG02010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId')); //pageObj.grid.init(param); } }, grid: { init: function(gridData) { this.gridId = COLLMNG02010_DETAIL_GRID_ID; this.gridList = COLLMNG02010_DETAIL_GRID_LIST; this.gridEmpty = COLLMNG02010_DETAIL_GRID_EMPTY; //var now = new Date(); //$('#ITP_TAB_COLLMNG02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE); //$('#ITP_FORM_COLLMNG02010_DETAIL_DLV_SCH_DT').datepicker('setDate', new Date(param.dlvSchDt)); //$('#ITP_FORM_COLLMNG02010_DETAIL .fnBrandNm').text(param.brandNm); //this.gridRows = param.recordData; this.unload(); this.load(gridData); }, gridId: '', button: {}, gridList: '', gridEmpty: '', gridRows: '', load: function(gridRows) { var _this = this; var option = { gridId: _this.gridId, colModel: gridColModel.detail, data: gridRows, loadComplete: function(data) { itp_fn_grid_load_complete(data, COLLMNG02010_DETAIL_GRID_ID, true, 'number', 'COLLMNG02010', modifyObj.itp_COLLMNG02010_search, modifyObj.empty, true, data.gridRecords, true); }, onCellSelect: function(rowid, cellIdx, cellValue) { COLLMNG02010_GRID_LAST_ROW_ID = itp_fn_set_data_editable(rowid, cellIdx, COLLMNG02010_GRID_LAST_ROW_ID, _this.gridId, ['rtnReqDtlNo']); } }; itp_fn_grid_make_local(option); }, clearData : function(mode) { $(COLLMNG02010_DETAIL_GRID_ID).jqGrid('clearGridData', true); $(COLLMNG02010_DETAIL_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px'); $(COLLMNG02010_DETAIL_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData); $(COLLMNG02010_DETAIL_GRID_EMPTY).show(); }, unload : function() { $.jgrid.gridUnload(this.gridId); } } }; /*목록화면 Object*/ let listObj = { init: function () { this.grid.init(); }, itp_COLLMNG02010_search: false, button: { search: function() { listObj.itp_COLLMNG02010_search = true; let param = $('#ITP_FORM_COLLMNG02010_SEARCH').serializeObject(); param.gridSize = $.jgrid.defaults.rowNum; param.gridPage = $.jgrid.defaults.page; $(COLLMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid'); }, colcreat: function() { var selectedIds = $(COLLMNG02010_GRID_ID).getGridParam('selarrrow'); if(selectedIds.length > 1) { // 1이상 선택시 alert("반품발주 한 건만 선택해주세요 (대표 반품발주)") ;//출력 return; //리턴 } var selRowData ; //변수선언 for (var i=selectedIds.length-1; i>=0;i--) { selRowData = $(COLLMNG02010_GRID_ID).jqGrid('getRowData', selectedIds[i]); //cell 선택 } if (selRowData == null) { itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.noData) return; } let param = {brandId: selRowData.brandId, rtnPodrUnqNo: selRowData.rtnPodrUnqNo, spplyId: fn_make_user_info.get('spplyId')}; pageObj.switchScreen('DETAIL'); itp_fn_form_clear_validate(null, '#ITP_FORM_COLLMNG02010_DETAIL'); modifyObj.init(param); } }, empty: { init: function() { }, itp_COLLMNG02010_param: {}, push: function() { }, back: function() { } }, grid: { init: function () { // 데이터 없을때 //itp_fn_jqgrid_resize(COLLMNG02010_GRID_ID, COLLMNG02010_GRID_LIST, 'lg'); itp_fn_fire_window_resize(); this.search(); }, colModel: gridColModel.list, search: function() { pageObj.switchScreen('LIST'); this.unload(); this.load(); }, load: function() { let param = $('#ITP_FORM_COLLMNG02010_SEARCH').serializeObject(); param.gridSize = $.jgrid.defaults.rowNum; var option = { multiselect: true, rownumbers: false, autowidth: true, gridId: COLLMNG02010_GRID_ID, colModel: gridColModel.list, param: param, url: DOMAIN + API_DETAIL_GRID_LIST, pager: COLLMNG02010_GRID_PAGER, loadComplete: function(data) { itp_fn_grid_load_complete(data, COLLMNG02010_GRID_ID, true, 'number', 'COLLMNG02010', listObj.itp_COLLMNG02010_search, listObj.empty, true, data.gridRecords, true); }, onPaging: function(action) { itp_fn_grid_paging(COLLMNG02010_GRID_ID, action, param); } }; itp_fn_grid_make_remote(option); }, button: { }, unload : function() { $.jgrid.gridUnload(COLLMNG02010_GRID_ID); }, clearData : function() { $(COLLMNG02010_GRID_ID).jqGrid('clearGridData', true); $(COLLMNG02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px'); $(COLLMNG02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData); $(COLLMNG02010_GRID_EMPTY).show(); } }, excelDown: function() { var param = { 'url': API_DETAIL_GRID_LIST, 'param': $('#ITP_FORM_COLLMNG02010_SEARCH').serializeObject(), 'gridColumns': $(COLLMNG02010_GRID_ID).jqGrid('getGridParam', 'colModel'), 'fileName': '공급사 수거서작성.xlsx', 'sheetName': '공급사 수거서리스트' }; itp_fn_remote_to_excel(param); } }; /*수정화면 Object*/ let modifyObj = { init: function (param) { this.load(param); }, button: { modify: function (param) { itp_fn_form_clear_validate(null, '#ITP_FORM_COLLMNG02010_DETAIL'); //const selectVal = $('#ITP_FORM_COLLMNG02010_VIEW_STORE_ID').val(); //const key = {brandId:fn_make_user_info.get('brandId'), storeId: selectVal, viewCd: 'R'}; //var param = $.param(key); //modifyObj.load(param); }, cancel: function() { $('body').trigger('click'); document.getElementById('ITP_FORM_COLLMNG02010_DETAIL').reset(); listObj.grid.search(); }, recal: function() { var ids = $(COLLMNG02010_DETAIL_GRID_ID).getDataIDs(); $.each(ids, function(idx, rowId) { var unitAmt = jQuery(COLLMNG02010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'unitAmt'); var colQty = jQuery(COLLMNG02010_DETAIL_GRID_ID).jqGrid('getCell', rowId, 'colQty'); if(unitAmt != null && unitAmt != '' && colQty != null && colQty != '') { jQuery(COLLMNG02010_DETAIL_GRID_ID).jqGrid('setRowData',rowId,{colAmt: parseInt(unitAmt)*parseInt(colQty)}); } }); const rowData = $(COLLMNG02010_DETAIL_GRID_ID).getRowData(); var colAmt = 0 ; $.each(rowData, function(key, value) { if (value.colAmt != null && value.colAmt != "" ) { colAmt = colAmt + parseInt(value.colAmt) ; } }); $('#ITP_FORM_COLLMNG02010_DETAIL .fnColAmt').text(itp_fn_number_comma(colAmt)); }, save: function() { $('body').trigger('click'); const formId = ('#ITP_FORM_COLLMNG02010_DETAIL'); itp_fn_form_clear_validate(null, formId); if (itp_fn_form_event.isValid(formId)) { var modalFn = { callBack: () => { itp_fn_form_event.removeChar('#ITP_FORM_COLLMNG02010_DETAIL'); var chkQtyYn = "N"; let gridInsertData = []; const rowData = $(COLLMNG02010_DETAIL_GRID_ID).getRowData(); $.each(rowData, function(key, value) { if (value.coltQty == '' || value.coltQty < 1 ) { alert("수거수량을 입력해주세요!"); chkQtyYn = "Y"; return false; } if (value.rtnOdrQty > value.coltQty ) { alert("수거수량이 반품발주수량보다 클수 없습니다!"); chkQtyYn = "Y"; return false; } gridInsertData.push(value); }); if (chkQtyYn == "Y") return; let param = $(formId).serializeObject(); param.viewCd = "C"; param.gridInsertData = gridInsertData; var searhFn = function () { //ITP_FORM_COLLMNG02010_DETAIL_IS_WRITING = false; pageObj.grid.clearData(); modifyObj.button.cancel(); } fn_ajax_call(API_DETAIL_SAVE, JSON.stringify(param), searhFn, 'POST'); } }; itp_fn_modal_confirm('수거서 생성 하시겠습니까?', modalFn); } } }, load: function(param) { fn_ajax_call(API_DETAIL_INIT_INFO, param, this.callback, 'GET'); }, callback: function(result) { pageObj.switchScreen('DETAIL'); $('#ITP_FORM_COLLMNG02010_DETAIL #ITP_FORM_COLLMNG02010_DETAIL_SPPLY_ID').val(fn_make_user_info.get('spplyId')); $('#ITP_FORM_COLLMNG02010_DETAIL .fnBrandNm').text(result.brandNm); // 브랜드 $('#ITP_FORM_COLLMNG02010_DETAIL #ITP_FORM_COLLMNG02010_DETAIL_BRAND_ID').val(result.brandId); // $('#ITP_FORM_COLLMNG02010_DETAIL #ITP_FORM_ORDMNG02010_DETAIL_COL_SCH_DT').val(result.colReqDt); // $('#ITP_FORM_COLLMNG02010_DETAIL #ITP_FORM_COLLMNG02010_DETAIL_RTN_WHS_ID').val(result.rtnWhsId); // $('#ITP_FORM_COLLMNG02010_DETAIL #ITP_FORM_COLLMNG02010_DETAIL_RTN_lOCATION').val(result.rtnLocation); // $('#ITP_FORM_COLLMNG02010_DETAIL .fnColAmt').text(result.rtnDodrTotalAmt); // $('#ITP_FORM_COLLMNG02010_DETAIL .fnRtnWhsNm').text(result.rtnWhsNm); // $('#ITP_FORM_COLLMNG02010_DETAIL .fnPickTelNo').text(result.pickTelNo); // $('#ITP_FORM_COLLMNG02010_DETAIL .fnRtnPodrUnqNo').text(result.rtnPodrUnqNo); // pageObj.grid.init( result.pickRtnDtlInfo); }, };