forked from HANYANG/HANYANG_MES
267 lines
10 KiB
JavaScript
267 lines
10 KiB
JavaScript
|
|
//Grid용 클래스. 블록 처리용
|
|
class Tb_class {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.tblList = "";
|
|
_this.ajax_url = "./stock.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: 'getStockList',
|
|
BP_CD: sdata?.BP_CD||'',
|
|
IO_DT_ST: sdata?.IO_DT_ST||'',
|
|
MNG_SN_ID: sdata?.MNG_SN_ID||'',
|
|
IO_DT_ED: sdata?.IO_DT_ED||'',
|
|
WH_LOC: sdata?.WH_LOC||'',
|
|
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({
|
|
BP_CD: conf?.BP_CD||'',
|
|
MNG_SN_ID: sdata?.MNG_SN_ID||'',
|
|
IO_DT_ST: conf?.IO_DT_ST||'',
|
|
IO_DT_ED: conf?.IO_DT_ED||'',
|
|
WH_LOC: conf?.WH_LOC||'',
|
|
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;
|
|
let stdate = document.getElementById("S_IO_DT_ST").value;
|
|
let endate = document.getElementById("S_IO_DT_ED").value;
|
|
|
|
_this.tblList.setFilter(function(data){ //필터링
|
|
return (
|
|
true
|
|
&& ( !document.getElementById("S_BP_NM") || ( (data.DLVY_BP_CD+"|"+data.DLVY_BP_NM).search(document.getElementById("S_BP_NM").value) !== -1 ) )
|
|
&& ( (!stdate || stdate <= data['IO_DT']) && (!endate || endate >= data['IO_DT']) )
|
|
// && ( !document.getElementById("S_IN_TYPE") || ( (data.IO_KIND).search(document.getElementById("S_IN_TYPE").value) !== -1 ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//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});
|
|
};
|
|
|
|
//등록
|
|
putStockList (){
|
|
let _this = this;
|
|
let postdata = {
|
|
'mode': 'putStockList',
|
|
'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(_this.searchData);
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
shGFormatter ( cell ) {
|
|
let _this = this;
|
|
return varsSHAPE_GRP[cell.getValue()]?.Code_Exp;
|
|
};
|
|
|
|
//시작 실행
|
|
init () {
|
|
let _this = this;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "4%", },
|
|
{ field: "DLVY_BP_NM", title: "거래처", width: "13%", },
|
|
{ field: "MNG_SN_ID", title: "S/N", width: "13%", },
|
|
{ field: "IO_DT", title: "입고일", width: "10%", },
|
|
{ field: "ITEM_CD", title: "품명", width: "12%", formatter:_this.shGFormatter, },
|
|
{ field: "ITEM_STATUS", title: "상태", width: "10%", formatter: tb_common_funtions.formatterSelect, formatterParams:{ values: varsITEN_STATUS }, },
|
|
{ field: "CUR_OP_CD", title: "현공정상태", width: "12%", formatter: tb_common_funtions.formatterSelect, formatterParams: {values: varOPGRP.reduce( (r,v) => {
|
|
return Object.assign(r, v.OPTIONS.reduce( (rev,vo) => {
|
|
rev[vo.OP_CD]=vo.OP_NM; return rev;
|
|
}, {} ) );
|
|
}, {} ),}, },
|
|
{ field: "WH_CD", title: "창고", width: "13%", formatter:(tgt)=>{ let s = varLOCGRP.filter(r=>r['WH_CD']===tgt.getValue())[0]; return s?.WH_NM }, },
|
|
{ field: "LOC_CD", title: "로케이션", width: "13%",
|
|
editor: tb_common_funtions.editorGrpSelect,
|
|
editorParams:{values:varLOCGRP.map( v => {
|
|
return { name: v.WH_NM, code: v.WH_CD, options: v.OPTIONS.reduce( (retv,vo) => {
|
|
retv[vo.LOC_CD+'|'+vo.WH_CD]=vo.LOCATION_NM; return retv;
|
|
}, {} ) };
|
|
} ), cfunc:(cell,value)=>{let spval = value.split('|'); cell.getRow().update({WH_CD:spval[1]}); return value;} },
|
|
formatter: tb_common_funtions.formatterSelect,
|
|
formatterParams: {values:varLOCGRP.reduce( (r,v) => {
|
|
return Object.assign(r, v.OPTIONS.reduce( (rev,vo) => {
|
|
rev[vo.LOC_CD+'|'+vo.WH_CD]=vo.LOCATION_NM; return rev;
|
|
}, {} ) );
|
|
}, {} ),},
|
|
},
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblStockList",{
|
|
layout: "fitColumns",
|
|
height: "100%",
|
|
data: [], //기본 데이터
|
|
columns: fields, //컬럼 설정
|
|
columnDefaults: { //컬럼 공통 규칙
|
|
sorter:()=>{},
|
|
headerSort: false,
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header",//Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
},
|
|
footerElement:'<ul class="pagination justify-content-center align-items-center mb-1"><li><a class="pn_link npage btn btn-light"><span class="f_page">1</span></a></li></ul>',
|
|
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
|
|
});
|
|
|
|
_this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
|
|
_this.getMainList();
|
|
});
|
|
|
|
_this.tblList.on("cellEdited", (cell) => { //Tabulator cell Edited
|
|
_this.cellEdited && Tb_funcs.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 = {
|
|
BP_CD: document.querySelector('#S_BP_CD').value||'',
|
|
MNG_SN_ID: document.querySelector('#S_MNG_SN_ID').value||'',
|
|
IO_DT_ST: document.querySelector('#S_IO_DT_ST').value||'',
|
|
IO_DT_ED: document.querySelector('#S_IO_DT_ED').value||'',
|
|
WH_LOC: document.querySelector('#S_WH_LOC').value||'',
|
|
LINE_NUM: document.querySelector('#S_LINE_NUM').value||'',
|
|
NOW_PAGE: 1,
|
|
}; // _this.searchData 는 전체적으로 이용되므로 간략화 금지
|
|
_this.getMainList(_this.searchData);
|
|
}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnPutStock").addEventListener(evt,()=>{_this.putStockList()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#S_BP_NM").addEventListener(evt,()=>{_this.popBP()}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnExcelDown").addEventListener(evt,()=>{_this.excelDataLoad(_this.tblList,'재고 리스트')}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_CD, #S_BP_NM, #S_MNG_SN_ID, #S_IO_DT_ST, #S_IO_DT_ED, #S_WH_LOC").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
|
|
};
|
|
|
|
excelDataLoad(table_block, title) { //페이징 처리된 리스트에서 엑셀 전체 다운
|
|
let _this = this;
|
|
let filename = title + "_"+luxon.DateTime.now().toFormat('yyyyMMdd')+".xlsx";
|
|
let itemlist = varOPGRP.reduce( (r,v) => {
|
|
return Object.assign(r, v.OPTIONS.reduce( (rev,vo) => {
|
|
rev[vo.OP_CD]=vo.OP_NM; return rev;
|
|
}, {} ) );
|
|
}, {} );
|
|
let whlist = varLOCGRP.reduce( (ret,row) => { ret[row.WH_CD] = row.WH_NM; return ret; }, {} );
|
|
let lolist = varLOCGRP.reduce( (ret,row) => { let op = row.OPTIONS.reduce( (rt,ro) => { rt[ro.LOC_CD+'|'+ro.WH_CD] = ro.LOCATION_NM; return rt; }, {} ); ret = {...ret, ...op }; return ret; }, {} );
|
|
|
|
ajax_json({
|
|
url: _this.ajax_url,
|
|
data: {..._this.searchData, mode: 'getStockList', LINE_NUM: 999999999 },
|
|
success: function (data) {
|
|
if (data.code) {
|
|
tb_common_funtions.tabu2xls(table_block, filename, title, data.data.map( row => {
|
|
row.ITEM_CD = varsSHAPE_GRP[row.ITEM_CD]?.Code_Exp;
|
|
row.ITEM_STATUS = varsITEN_STATUS[row.ITEM_STATUS];
|
|
row.CUR_OP_CD = itemlist[row.CUR_OP_CD];
|
|
row.WH_CD = whlist[row.WH_CD];
|
|
row.LOC_CD = lolist[row.LOC_CD];
|
|
row.OUT_DIA = Math.round(row.OUT_DIA*10)/10;
|
|
row.IN_DIA = Math.round(row.IN_DIA*10)/10;
|
|
row.THICK = Math.round(row.THICK*10)/10;
|
|
row.WIDTH = Math.round(row.WIDTH*10)/10;
|
|
row.LENGTH = Math.round(row.LENGTH*10)/10;
|
|
return row;
|
|
} ));
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {}
|
|
});
|
|
};
|
|
}
|
|
|
|
const Tb_funcs = new Tb_class();
|
|
Tb_funcs.init(); |