FilePond.registerPlugin(FilePondPluginFileValidateType); //Grid용 클래스. 블록 처리용 class Tb_class_ncr { constructor(){ let _this = this; _this.tblList = ""; _this.ajax_url = "./ncr.ajax.php"; } //리스트 로드 getMainList (sdata) { let _this = this; let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력 ajax_json({ url: _this.ajax_url, data: { mode: 'getNcrList', WORKER_NM: sdata?.WORKER_NM||'', WRK_DT_ST: sdata?.WRK_DT_ST||'', WRK_DT_ED: sdata?.WRK_DT_ED||'', OFLD: sdata?.OFLD||'', OASC: sdata?.OASC||'', LINE_NUM: sdata?.LINE_NUM||'', NOW_PAGE: sdata?.NOW_PAGE||'', }, success: function (data) { if (data.code) { _this.tblList.setData(data.data); _this.tblList.getRows().forEach(row=>row.getData()['JUDG_CD'] && row.getCell('CHECK').getElement().querySelector('input').setAttribute('disabled',true)); //진행된 수주현항 선택 못하도록 처리 //page putPagiNation({ ...sdata, TARGET: ".tabulator-footer-contents", PREB_PAGE: data?.data[0]?.PREB_PAGE, NEXB_PAGE: data?.data[0]?.NEXB_PAGE, LAST_PAGE: data?.data[0]?.LAST_PAGE, PAGE_LISTS: data?.data[0]?.PAGE_LISTS?.split('|'), callback: (conf)=>{ _this.getMainList({ WORKER_NM: conf?.WORKER_NM||'', WRK_DT_ST: conf?.WRK_DT_ST||'', WRK_DT_ED: conf?.WRK_DT_ED||'', OFLD: conf?.OFLD||'', OASC: conf?.OASC||'', LINE_NUM: conf?.LINE_NUM||'', NOW_PAGE: conf?.NOW_PAGE||'', }); } }); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function () { window.clearTimeout(talert); _this.tblList.clearAlert(); _this.setFilter(); } }); return true; }; //검색 조건 Clear clearInput (){ let _this = this; _this.setFilter(); }; setFilter () { return false; let _this = this; _this.tblList.setFilter(function(data){ //필터링 return ( true // && ( !document.getElementById("S_BIZ_AREA_NM") || ( (data.BIZ_AREA_CD+"|"+data.BIZ_AREA_NM).search(document.getElementById("S_BIZ_AREA_NM").value) !== -1 ) ) // && ( !document.getElementById("S_BP_NM") || ( (data.BP_CD+"|"+data.BP_NM).search(document.getElementById("S_BP_NM").value) !== -1 ) ) // && ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) ) ) }, '=', true); }; //Row 추가 addRow(){ let _this = this; _this.tblList.addRow({_STATUS_:'I'},true); } //Row 클릭 콜백 rowClick (e, tgt){ let _this = this; if( e.target.classList.contains("btnfile") ){ //첨부파일시 Row클릭금지 return; } let rowData = tgt.getData(); Tb_ncr_pop.modalNcr(rowData.NCR_NO); }; //Cell 클릭 콜백 cellClick (e, tgt){ let _this = this; _this.tgt = tgt; // switch( tgt.getField() ){ // case "BP_NM": // popPartnerList({tgt_id:'',tgt_name:'BP_NM',tgt_addr:'',tgt_currency:''}, tgt.getRow()._row); // break; // } }; //Cell 변경 콜백 cellEdited (cell){ let _this = this; cell.getData()._STATUS_ = cell.getData()._STATUS_||'U'; }; popBP () { let _this = this; popPartnerList({tgt_id:'#S_BP_CD',tgt_name:'#S_BP_NM'}); }; //sort columnSort(e,tgt) { let _this = this; let sorters = tgt.getTable().getSorters()[0]; _this.getMainList({..._this.searchData,OFLD:sorters?.field,OASC:sorters?.dir}); }; //등록 putNcr (){ let _this = this; let postdata = { 'mode': 'delNcr', 'reqdata': JSON.stringify(_this.tblList.getData().filter(row=> row._STATUS_)), }; ajax_json({ url: _this.ajax_url, data: postdata, success: function (data) { if (data.code) { kuls_success("적용 되었습니다."); _this.getMainList(); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function () { } }); return true; }; popDrawList ( cell ){ let _this = this; //팝업 템플릿 로드 후 모달 출력 Tb_draw.init(cell.getComponent().getRow()); }; shGFormatter ( cell ) { let _this = this; return varsSHAPE_GRP[cell.getValue()]?.Code_Exp; }; popDrawList ( cell ){ let _this = this; //팝업 템플릿 로드 후 모달 출력 Tb_draw.init(cell.getComponent().getRow()); }; delNcr (){ let _this = this; _this.tblList.getSelectedRows().forEach(row => { row.update({_STATUS_:'D'}); row.getElement().classList.add("del-row"); }); }; //시작 실행 init () { let _this = this; const fields = [ { field: "CHECK",formatter:"rowSelection", titleFormatter: "rowSelection", title: "No", width: "4%", noxls:true }, //{ formatter:"rowSelection", titleFormatter: "rowSelection", width: "4%", }, { field: "NCR_NO", title: "NCR NO", width: "10%", }, { field: "FOUND_DT", title: "발생일", width: "7%", }, { field: "FOUND_TM", title: "발생시간", width: "8%", }, { field: "MNG_SN_ID", title: "일련번호", width: "11%", }, { field: "MNG_NO", title: "수주번호", width: "9%", }, { field: "DLVY_BP_NM", title: "고객", width: "9%", }, { field: "ITEM_CD", title: "품명", width: "8%", formatter:_this.shGFormatter, }, { field: "", title: "규격", columns:[ { field:"OUT_DIA", title:"OD", hozAlign:"center", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"IN_DIA", title:"ID", hozAlign:"center", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"THICK", title:"T", hozAlign:"center", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"WIDTH", title:"W", hozAlign:"center", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, { field:"LENGTH", title:"L", hozAlign:"center", width:"5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':3}; }, }, ], }, { field: "MATR_TYPE", title: "재질", width: "8%", }, { field: "NCR_QTY", title: "수량", width: "5%", formatter: tb_common_funtions.formatterNumber, formatterParams: function() { return {'precision':0}; }, }, { field: "FOUND_TYPE", title: "발견유형", width: "8%", editor:'list', cssClass:"user-list", editorParams:{ values: varsFOUND_TYPE }, formatter: tb_common_funtions.formatterSelect, formatterParams:{ values: varsFOUND_TYPE }, }, { field: "", title: "도면", columns:[ { field:"ASS_DRAW", title:"도면번호", width:"10%", }, { field:"", title:"", width:"2%", formatter: tb_common_funtions.formatterButton, formatterParams:{ btnTitle:'', btnClass:'btn btn-sm btn-nobd fa-regular fa-image btnfile', cfunc: (cell)=> { _this.popDrawList(cell) }, event: ['click', 'keyup'], }, }, ], }, { field: "JUDG_EMP_NM", title: "작업자", width: "8%", }, { field: "NCR_CD", title: "부적합사유", width: "8%", editor:'input', }, { field: "JUDG_CD", title: "판정", width: "8%", editor:'list', cssClass:"user-list", editorParams:{ values: varsJUDG_CD }, formatter: tb_common_funtions.formatterSelect, formatterParams:{ values: varsJUDG_CD }, }, ]; _this.tblList = new Tabulator("#tblNcrList",{ layout: "fitColumns", height: "100%", data: [], //기본 데이터 columns: fields, //컬럼 설정 columnDefaults: { //컬럼 공통 규칙 sorter:()=>{}, headerSort: false, vertAlign: "middle", hozAlign: "center", resizable: "header",//Resize 는 헤더에서만 가능 headerHozAlign: "center", //헤더 정렬 headerSortTristate: true, //데이터 정렬 => 정/역/초기화 }, footerElement:'
', headerSortElement: "", //정렬 아이콘 }); _this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트 _this.getMainList(); }); _this.tblList.on("rowClick", (e,tgt) => { //Tabulator Row Click _this.rowClick && Tb_ncr.rowClick(e,tgt); }); _this.tblList.on("cellClick", (e,tgt) => { //Tabulator cell Click _this.cellClick && Tb_ncr.cellClick(e,tgt); }); _this.tblList.on("cellEdited", (cell) => { //Tabulator cell Edited _this.cellEdited && Tb_ncr.cellEdited(cell); }); _this.tblList.on("headerClick", (e,tgt) => { //Tabulator cell Edited _this.columnSort && _this.columnSort(e,tgt); }); ['click','keypress'].forEach(evt => document.querySelector("#bntListSearch").addEventListener(evt,()=>{ _this.searchData = { WORKER_NM: document.querySelector('#S_WORKER_NM').value||'', WRK_DT_ST: document.querySelector('#S_WRK_DT_ST').value||'', WRK_DT_ED: document.querySelector('#S_WRK_DT_ED').value||'', LINE_NUM: document.querySelector('#S_LINE_NUM').value||'', NOW_PAGE: 1, }; // _this.searchData 는 전체적으로 이용되므로 간략화 금지 _this.getMainList(_this.searchData); })); ['click','keypress'].forEach(evt => document.querySelector("#btnAddNcr").addEventListener(evt,()=>{Tb_ncr_pop.modalNcr()})); ['click','keypress'].forEach(evt => document.querySelector("#btnPutNcr").addEventListener(evt,()=>{_this.putNcr()})); ['click','keypress'].forEach(evt => document.querySelector("#btnDelNcr").addEventListener(evt,()=>{_this.delNcr()})); ['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_WORKER_NM, #S_WRK_DT_ST, #S_WRK_DT_ED").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_ncr.setFilter()}))); }; } class Tb_class_ncr_pop { constructor(){ let _this = this; _this.ajax_url = "./ncr.ajax.php"; _this.download_url = "/include/getFile.php"; _this.tblList = ""; _this.putNcrModal = ""; _this.NCR_NO = ""; } // 부적합 등록 팝업 modalNcr ( NCR_NO ){ let _this = this; _this.NCR_NO = NCR_NO; vnLoad( '', './ncr.pop.inc.php', '', function(loadHtml){ _this.putNcrModal = kuls_modal(loadHtml); document.querySelector(".btn_close").addEventListener("click", ()=>_this.putNcrModal.delete()); _this.init(); }); }; getNcr () { let _this = this; if( !_this.NCR_NO ) return; ajax_json({ url: _this.ajax_url, type: "POST", data: { mode: 'getNcr', NCR_NO: _this.NCR_NO, }, success: function (data) { if( data.code ){ Object.keys(data.data).forEach(key => { switch( key ){ case "SO_QTY": for( let a=1 ; a<=data.data[key] ; a++ ){ let opt = document.createElement('option'); opt.value = '#'+a; opt.text = '#'+a; document.querySelector("#MNG_SN_ID").append(opt); } case "OUT_DIA": document.querySelector("#ITEM_SPEC").value = [data.data['OUT_DIA'],data.data['IN_DIA'],data.data['THICK'],data.data['WIDTH'],data.data['LENGTH'],].filter(v=>v).map(v=>parseInt(v)).join(' x '); break; case "ITEM_CD": data.data[key] = Tb_so_pop.shGFormatter(data.data[key]); break; } if( document.getElementById(key) ){ document.getElementById(key).setAttribute("data-defval", data.data[key]); } }); formSetVal(document.forms['frmNcr']); data.data.ATTS.forEach( att => { _this.addFileDiv( att ); } ); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function(){ } }); return false; }; putNcr = (e) => { e.preventDefault(); let _this = this; let formdata = new FormData(document.frmNcr); if( formdata.get("NCR_NO_OLD") ){ formdata.append("mode", "setNcr"); }else{ formdata.append("mode", "putNcr" ); } ajax_form({ url: _this.ajax_url, type: "POST", data: formdata, success: function (data) { if( data.code ){ kuls_success("적용 되었습니다."); //_this.getRepairInfo(formdata.get("FACLT_CD")); _this.putNcrModal.delete(); Tb_ncr.getMainList(); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function(){ } }); }; uploadFile (){ let _this = this; _this.uploader.browse(); }; delFile (){ let _this = this; document.querySelectorAll("#pic_block .img_block:has(input:checked)").forEach( tgt => tgt.classList.add("d-hide") ); }; addFileDiv ( finfo ){ let _this = this; let fid = finfo.file_id||(finfo.tmp_name||''); let nid = finfo.nid||''; let sid = finfo.sid||''; let vdiv = document.createElement("div"); let vgbn = document.createElement("input"); let vfid = document.createElement("input"); let vsid = document.createElement("input"); let vchk = document.createElement("input"); let file_url = _this.download_url+"?gubun="+(finfo.gubun||'') +"&nid="+nid +"&sid="+sid +"&file_id="+fid +"&tmp_name="+(finfo.tmp_name||'') +"&name="+(finfo.file_name||'') +"&size="+(finfo.file_size||''); vdiv.classList.add('img_block'); vdiv.style.backgroundImage = `url('${file_url}')`; vdiv.setAttribute("data-url", file_url); vdiv.setAttribute("data-filename", finfo.file_name); vdiv.addEventListener("click", function(e){ pop_filedown(e.target.getAttribute('data-url'), e.target.getAttribute('data-filename').split(".").pop()); }); vgbn.type="hidden"; vgbn.name="file_gubun[]"; vgbn.value=finfo.gubun; vdiv.append(vgbn); vfid.type="hidden"; vfid.name="file_id[]"; vfid.value=fid; vdiv.append(vfid); vsid.type="hidden"; vsid.name="sid[]"; vsid.value=sid; vdiv.append(vsid); vchk.addEventListener("click",(e)=>{ e.stopPropagation(); }) vchk.type="checkbox"; vchk.name="file_del[]"; vchk.value=fid; vdiv.append(vchk); document.querySelector("#pic_block").append(vdiv); } init() { let _this = this; document.querySelector("form[name=frmNcr]").addEventListener("submit", _this.putNcr); ['click','keypress'].forEach(evt => document.querySelector("#MNG_NO").addEventListener(evt, ()=>{ Tb_so_pop.modalSo(); })); ['click','keypress'].forEach(evt => document.querySelector("#JUDG_EMP_NM").addEventListener(evt, ()=>{ popEmployeeList('#JUDG_EMP_NO', '#JUDG_EMP_NM', 'BA01'); })); jQuery("#FOUND_DT").datetimepicker({ allowTimes: [...Array(24*60).keys()].map(idx=>Math.floor(idx/60).toString().padStart(2,'0')+':'+(idx%60).toString().padStart(2,'0')), format: "Y-m-d H:i", defaultTime: luxon.DateTime.now().toFormat("HH:")+Math.floor(luxon.DateTime.now().toFormat("mm")/10).toString().padEnd(2,'0'), }).addClass("dtime_picker"); //멀티파일 업로더 if (!_this.uploader) { _this.uploader = FilePond.create(document.getElementById("attfilepond"), { ...filepond_ko_KR, name: 'upfile', allowMultiple: true, maxParallelUploads: 3, allowProcess: false, instantUpload: true, allowFileTypeValidation: true, acceptedFileTypes: ['image/*'], server: { url: _this.ajax_url + "?mode=putTempFile", process: { onload: function (data) { data = JSON.parse(data); let fdata = data.data; let file_name = fdata['file_name']; let tmp_name = fdata['tmp_name']; let file_size = fdata['file_size']; let file_type = fdata['file_type']; _this.addFileDiv( {gubun:'temp', tmp_name, file_name, file_size, file_type} ); //let file_url = _this.download_url+"?gubun="+rowData['gubun']+"&nid="+rowData['nid']+"&sid="+rowData['sid']+"&file_id="+rowData['file_id']+"&tmp_name="+rowData['tmp_name']+"&name="+rowData['file_name']+"&size="+rowData['file_size']; }, }, }, allowFileSizeValidation: true, maxFileSize: 100000000, credits: {}, }); document.querySelector("#attfilepond").addEventListener('FilePond:addfilestart', (e) => { document.querySelector("#pic_block .ploading").classList.remove("d-hide"); document.querySelector("form[name=frmNcr] .btn_prim").disabled = true; }); document.querySelector("#attfilepond").addEventListener('FilePond:processfiles', (e) => { document.querySelector("#pic_block .ploading").classList.add("d-hide"); document.querySelector("form[name=frmNcr] .btn_prim").disabled = false; }); } ['click','keypress'].forEach(evt => document.querySelector("#btnAddPic").addEventListener(evt,()=>{_this.uploadFile()})); ['click','keypress'].forEach(evt => document.querySelector("#btnDelPic").addEventListener(evt,()=>{_this.delFile()})); _this.getNcr(); }; } class Tb_class_so_pop { constructor(){ let _this = this; _this.ajax_url = "./ncr.ajax.php"; _this.tblList = ""; _this.putSoModal = ""; } // 설비 등록 팝업 modalSo (){ let _this = this; vnLoad( '', './so.pop.inc.php', '', function(loadHtml){ _this.putSoModal = kuls_modal(loadHtml); document.querySelector(".btn_close").addEventListener("click", ()=>_this.putSoModal.delete()); _this.init(); }); }; getSoList (sdata) { let _this = this; ajax_json({ url: _this.ajax_url, type: "POST", data: { mode: 'getSoList', MNG_NO: sdata?.MNG_NO||'', BP_NM: sdata?.BP_NM||'', OFLD: sdata?.OFLD||'', OASC: sdata?.OASC||'', LINE_NUM: sdata?.LINE_NUM||'', NOW_PAGE: sdata?.NOW_PAGE||'', }, success: function (data) { if( data.code ){ _this.tblList.setData(data.data); //page putPagiNation({ ...sdata, TARGET: ".tabulator-footer-contents", PREB_PAGE: data?.data[0]?.PREB_PAGE, NEXB_PAGE: data?.data[0]?.NEXB_PAGE, LAST_PAGE: data?.data[0]?.LAST_PAGE, PAGE_LISTS: data?.data[0]?.PAGE_LISTS?.split('|'), callback: (conf)=>{ _this.getMainList({ MNG_NO: conf?.MNG_NO||'', BP_NM: conf?.BP_NM||'', OFLD: conf?.OFLD||'', OASC: conf?.OASC||'', LINE_NUM: conf?.LINE_NUM||'', NOW_PAGE: conf?.NOW_PAGE||'', }); } }); }else{ kuls_alert(data.mesg); } }, error: function (request, status, error) { kuls_alert(error.message); }, complete: function(){ } }); return false; }; shGFormatter ( code ) { let _this = this; return varsSHAPE_GRP[code]?.Code_Exp; }; shFormatter ( cell ) { let _this = this; return varsSHAPE_TYPE[cell.getValue()]; }; init() { let _this = this; const fields = [ { field: "LIST_NUM", title: "No", width: "6%", minWidth: 50, headerSort: false, hozAlign:'center', }, { field: "MNG_NO", title: "수주번호", width: "25%", minWidth: 200, }, { field: "SHAPE_TYPE", title: "형상", width: "20%", minWidth: 50, formatter: _this.shFormatter }, { field: "ORDR_BP_NM", title: "거래처", width: "15%", minWidth: 100, }, { field: "SO_QTY", title: "수량", width: "10%", minWidth: 40, formatter: "money", formatterParams:{precision:0}}, { field: "REQ_DLVY_DT", title: "납기요청일", width: "14%", minWidth: 100, }, ]; _this.tblList = new Tabulator("#pop_so_list", { layout:"fitColumns", data: [], //기본 데이터 height: "100%", columns: fields, //컬럼 설정 columnDefaults: { //컬럼 공통 규칙 vertAlign:"middle", hozAlign: "center", resizable: "header",//Resize 는 헤더에서만 가능 headerHozAlign: "center", //헤더 정렬 headerSortTristate:true, //정렬 => 정/역/초기화 }, footerElement:'', headerSortElement: "", //정렬 아이콘 }); const setPopPartnerData = function(e,tgt){ //Row 더블클릭 실행 let row = tgt._row; let spec = [ parseInt(row.data['OUT_DIA'])||'', parseInt(row.data['IN_DIA'])||'', parseInt(row.data['THICK'])||'', parseInt(row.data['WIDTH'])||'', parseInt(row.data['LENGTH'])||'' ].filter(v=>v); if( document.querySelector("form[name=frmNcr] #MNG_NO") ) document.querySelector("form[name=frmNcr] #MNG_NO").value = row.data['MNG_NO']; if( document.querySelector("form[name=frmNcr] #DLVY_BP_NM") ) document.querySelector("form[name=frmNcr] #DLVY_BP_NM").value = row.data['ORDR_BP_NM']; if( document.querySelector("form[name=frmNcr] #ITEM_CD") ) document.querySelector("form[name=frmNcr] #ITEM_CD").value = _this.shGFormatter(row.data['ITEM_CD']); if( document.querySelector("form[name=frmNcr] #ITEM_SPEC") ) document.querySelector("form[name=frmNcr] #ITEM_SPEC").value = spec.join(' x '); if( document.querySelector("form[name=frmNcr] #MATR_TYPE") ) document.querySelector("form[name=frmNcr] #MATR_TYPE").value = row.data['MATR_TYPE']; if( document.querySelector("form[name=frmNcr] #ASS_DRAW") ) document.querySelector("form[name=frmNcr] #ASS_DRAW").value = row.data['ASS_DRAW']; if( document.querySelector("form[name=frmNcr] #MNG_SN_ID") ){ let tgt = document.querySelector("form[name=frmNcr] #MNG_SN_ID"); tgt.options.length = 0; for( let a=1 ; a<=row.data['SO_QTY'] ; a++ ){ let opt = document.createElement("option"); opt.text = '#'+a; opt.value = '#'+a; tgt.append(opt); } } _this.putSoModal.delete(); }; ['click','keypress'].forEach(evt => document.querySelector("#awn-popup-wrapper #btnSearch").addEventListener(evt,function() { //검색어 입력 이벤트 _this.getSoList({ MNG_NO: document.querySelector("#S_MNG_NO").value, BP_NM: document.querySelector("#S_BP_NM").value, }); })); document.querySelectorAll(".awn-popup-search input").forEach(tgt => { tgt.addEventListener("keypress", (e)=>{ if( e.key == "Enter" ){ document.querySelector(".awn-popup-search button.btn_prim").dispatchEvent(new Event("click")); } }); }); _this.tblList.on("rowDblClick", setPopPartnerData); //Row 더블클릭 이벤트 _this.tblList.on("tableBuilt", function(){ //초기 데이터 불러오기 이벤트 _this.getSoList(); }); }; } const Tb_ncr = new Tb_class_ncr(); const Tb_ncr_pop = new Tb_class_ncr_pop(); const Tb_so_pop = new Tb_class_so_pop(); const Tb_draw = new drawManager(); Tb_ncr.init();