568 lines
16 KiB
JavaScript
568 lines
16 KiB
JavaScript
/*
|
|
* @Overview 생산계획등록
|
|
*/
|
|
|
|
class Tb_main_class {
|
|
constructor(container) {
|
|
this.ajaxUrl = "./reg_plan.ajax.php";
|
|
this.tbList = "";
|
|
this.lastGroupId = 0;
|
|
this.container = document.querySelector(container);
|
|
this.table = this.container.querySelector(".hy-table");
|
|
this.addBtn = this.container.querySelector(".add-btn");
|
|
this.removeBtn = this.container.querySelector(".remove-btn");
|
|
}
|
|
|
|
|
|
/*
|
|
* @Overview 생산계획등록
|
|
* @Parameter DATABASE로부터 받은 데이터
|
|
* @function DB 데이터 가공하여 테이블에 바인딩.
|
|
*/
|
|
manageData(data) {
|
|
|
|
// console.log(data);
|
|
let _this = this;
|
|
let arr = new Array();
|
|
|
|
const result = Object.groupBy(data.data, ({ id }) => id)
|
|
|
|
|
|
|
|
for(let i=0; i<=Object.values(result).length; i++){
|
|
// console.log(Object.values(result)[]);
|
|
let makingITEM = Object.values(result)[i]?.map(function(rst){
|
|
let tempITEM ={};
|
|
|
|
// let date = rst.PLAN_DT.date.slice(0, 10);
|
|
|
|
let date = rst.PLAN_DT.slice(0, 10).replace(/-/g, '_');
|
|
|
|
let arr = new Array();
|
|
tempITEM['id'] = rst.id
|
|
tempITEM['PLAN_FACLT_CD'] = rst.PLAN_FACLT_CD
|
|
tempITEM['PLAN_FACLT_NM'] = rst.PLAN_FACLT_NM
|
|
tempITEM['WRK_TEAM'] = rst.WRK_TEAM
|
|
tempITEM['SEPER'] = "그룹"
|
|
tempITEM[`AM_PLAN_QTY_${date}`] = rst.AMITEM
|
|
tempITEM[`PM_PLAN_QTY_${date}`] = rst.PMITEM
|
|
tempITEM[`NI_PLAN_QTY_${date}`] = rst.NIITEM
|
|
_this.lastGroupId = parseInt(rst.id);
|
|
return tempITEM;
|
|
})
|
|
|
|
let makingQTY = Object.values(result)[i]?.map(function(rst){
|
|
let tempQTY ={};
|
|
let date = rst.PLAN_DT.slice(0, 10).replace(/-/g, '_');
|
|
let arr = new Array();
|
|
tempQTY['id'] = rst.id
|
|
tempQTY['SEPER'] = "계획"
|
|
tempQTY['PLAN_FACLT_CD'] = rst.PLAN_FACLT_CD
|
|
tempQTY['PLAN_FACLT_NM'] = rst.PLAN_FACLT_NM
|
|
tempQTY['WRK_TEAM'] = rst.WRK_TEAM
|
|
tempQTY[`AM_PLAN_QTY_${date}`] = rst.AMQTY
|
|
tempQTY[`PM_PLAN_QTY_${date}`] = rst.PMQTY
|
|
tempQTY[`NI_PLAN_QTY_${date}`] = rst.NIQTY
|
|
_this.lastGroupId = parseInt(rst.id);
|
|
return tempQTY;
|
|
})
|
|
|
|
let makingPRD = Object.values(result)[i]?.map(function(rst){
|
|
let tempPRD ={};
|
|
let date = rst.PLAN_DT.slice(0, 10).replace(/-/g, '_');
|
|
let arr = new Array();
|
|
tempPRD['id'] = rst.id
|
|
tempPRD['SEPER'] = "실적"
|
|
tempPRD['PLAN_FACLT_CD'] = rst.PLAN_FACLT_CD
|
|
tempPRD['PLAN_FACLT_NM'] = rst.PLAN_FACLT_NM
|
|
tempPRD['WRK_TEAM'] = rst.WRK_TEAM
|
|
tempPRD[`AM_PLAN_QTY_${date}`] = rst.AMPRD
|
|
tempPRD[`PM_PLAN_QTY_${date}`] = rst.PMPRD
|
|
tempPRD[`NI_PLAN_QTY_${date}`] = rst.NIPRD
|
|
|
|
_this.lastGroupId = parseInt(rst.id);
|
|
return tempPRD;
|
|
})
|
|
|
|
const sumObjItem = {};
|
|
const sumObjQty = {};
|
|
const sumObjPrd = {};
|
|
|
|
|
|
if(makingITEM !==undefined){
|
|
makingITEM.forEach(obj => {
|
|
Object.keys(obj).forEach(key => {
|
|
sumObjItem[key] = obj[key];
|
|
});
|
|
});
|
|
|
|
makingQTY.forEach(obj => {
|
|
Object.keys(obj).forEach(key => {
|
|
sumObjQty[key] = obj[key];
|
|
});
|
|
});
|
|
|
|
makingPRD.forEach(obj => {
|
|
Object.keys(obj).forEach(key => {
|
|
sumObjPrd[key] = obj[key];
|
|
});
|
|
});
|
|
|
|
|
|
arr.push(sumObjItem);
|
|
arr.push(sumObjQty);
|
|
arr.push(sumObjPrd);
|
|
}
|
|
|
|
}
|
|
return arr;
|
|
}
|
|
|
|
/*
|
|
* @Overview 데이터 조회 함수
|
|
* @Parameter ajax 비동기통신에서 프로시져 사용할 "mode" / input 태그의 id에 해당하는 test
|
|
*/
|
|
getMainList(mode, ...test) {
|
|
|
|
const talert= window.setTimeout(()=> { this.tbList.alert("Loading ...") }, 1000);
|
|
let arr = test;
|
|
// console.log(arr);
|
|
// let testList = new Array();
|
|
let data = new Object();
|
|
for (let i = 0; i < arr.length; i++) {
|
|
let temp = [arr[i]];
|
|
// console.log(temp);
|
|
// if (document.getElementById(arr[i]).type == "checkbox") {
|
|
// data[temp] = document.getElementById(temp).checked ? "Y" : "N";
|
|
// } else {
|
|
data[temp] = document.getElementById(temp)?.value;
|
|
// }
|
|
}
|
|
data.mode = mode;
|
|
// let USEFLAG = document.getElementById("USE_FLG").checked?"Y":"N"; //사용여부
|
|
ajax_json({
|
|
url: this.ajaxUrl,
|
|
data: data,
|
|
|
|
success: (data) => {
|
|
|
|
if (data.code) {
|
|
//DB에서 받아온 데이터 가공하는 manageData 함수 참조
|
|
this.tbList.setData(this.manageData(data));
|
|
} else {
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: (req, status, err) => {
|
|
kuls_alert(err.message);
|
|
},
|
|
complete: () => {
|
|
window.clearTimeout(talert);
|
|
this.tbList.clearAlert();
|
|
// this.setFilter();
|
|
// this.tbList.getRows().forEach(row=>{
|
|
// row.getCell("PLAN_FACLT_CD").getElement().addEventListener("click",(e)=>{
|
|
// this.rowClick(e,row);
|
|
// })
|
|
// });
|
|
},
|
|
});
|
|
|
|
return true;
|
|
}
|
|
/*
|
|
* @Overview 데이터 필터 함수
|
|
* @Parameter 없음
|
|
*/
|
|
setFilter() {
|
|
this.tbList ="";
|
|
this.init();
|
|
|
|
this.getMainList(
|
|
"getPlanList",
|
|
"team_pop",
|
|
"product_pop",
|
|
"sub_product_pop",
|
|
"plan_date"
|
|
);
|
|
}
|
|
|
|
/*
|
|
* @Overview 테이블 행 추가 함수
|
|
* @Parameter 없음
|
|
* @function 기본키, _STATUS_:I 값을 넣은 행 추가
|
|
*/
|
|
addRow() {
|
|
|
|
this.lastGroupId += 1;
|
|
|
|
// Tabulator 인스턴스에 데이터 추가
|
|
this.tbList.addRow({
|
|
SEQ_NO: this.lastGroupId,
|
|
SEPER: "그룹",
|
|
_STATUS_: "I",
|
|
SEPER_ID: "GRP",
|
|
});
|
|
|
|
this.tbList.addRow({
|
|
SEQ_NO: this.lastGroupId,
|
|
SEPER: "계획",
|
|
_STATUS_: "I",
|
|
SEPER_ID: "PLAN",
|
|
});
|
|
|
|
this.tbList.addRow({
|
|
SEQ_NO: this.lastGroupId,
|
|
SEPER: "실적",
|
|
SEPER_ID: "PRD",
|
|
});
|
|
|
|
}
|
|
|
|
/*
|
|
* @Overview 테이블 행 삭제 함수
|
|
* @Parameter 없음
|
|
* @function 선택된 모든 행 삭제
|
|
*/
|
|
removeRow() {
|
|
const selectedRows = this.tbList.getRows().filter((row) => {
|
|
return row.getData().check === "Y";
|
|
});
|
|
|
|
if (selectedRows.length > 0) {
|
|
kuls_confirm("삭제", "하시겠습니까?", () => {
|
|
// 선택된 각 행 삭제
|
|
selectedRows.forEach((row) => {
|
|
// STAUS D로 바꾸기
|
|
row.getData()._STATUS_ = row.getData()._STATUS_ == "I" ? null : "D";
|
|
|
|
const rowElement = row.getElement();
|
|
rowElement.classList.add("remove-row");
|
|
});
|
|
});
|
|
} else {
|
|
kuls_alert("삭제할 행을 선택해주세요.");
|
|
}
|
|
}
|
|
|
|
/*
|
|
* @Overview 테이블 행 클릭 함수
|
|
* @Parameter 셀
|
|
* @function 클릭한 테이블 행의 전체 그룹 선택(3줄씩)
|
|
*/
|
|
groupRowClick(e, tgt) {
|
|
const rows = tgt.getRows();
|
|
|
|
rows.forEach((row) => {
|
|
if (row.isSelected()) {
|
|
row.deselect();
|
|
tgt.getElement().classList.remove("select");
|
|
} else {
|
|
row.select();
|
|
tgt.getElement().classList.add("select");
|
|
}
|
|
});
|
|
}
|
|
|
|
/*
|
|
* @Overview 테이블 셀 클릭 함수
|
|
* @Parameter 이벤트, 타겟
|
|
* @function 클릭한 셀에 따라 각각 다른 이벤트 설정
|
|
* @function 팝업, 체크박스 등
|
|
*/
|
|
cellClick(e, tgt) {}
|
|
|
|
/*
|
|
* @Overview 테이블 셀 수정 함수
|
|
* @Parameter 셀
|
|
* @function 셀 편집이 이후 저장될수 있도록 _STATUS_:U로 데이터 업데이트
|
|
* @function 팀, 설비 열의 경우 한번만 수정해도 같이 수정되도록 함.
|
|
*/
|
|
cellEdited(cell) {
|
|
let _this = this;
|
|
const std = cell.getRow().getData().id;
|
|
|
|
cell.getRow().getGroup().getRows().filter(function(data){
|
|
return data._row.data.id === std ?data._row.data._STATUS_ = 'U' : ''
|
|
})
|
|
|
|
}
|
|
|
|
/*
|
|
* @Overview 데이터 편집 함수
|
|
* @Parameter 없음
|
|
* @function _STATUS_ 값이 있는 데이터만 추려서 없으면 생성, 있으면 수정하기
|
|
*/
|
|
putData() {
|
|
let _this = this;
|
|
let talert = window.setTimeout(() => { _this.tbList.alert("Loading ...") }, 1000);
|
|
const result = Object.groupBy(this.tbList.getData().filter((row) => row._STATUS_), ({ id }) => id)
|
|
// console.log(JSON.stringify(result));
|
|
|
|
|
|
|
|
// 저장 시 상태 변화 없는 row 요청 X
|
|
|
|
|
|
if (this.tbList.getData().filter((row) => row._STATUS_).length == 0) {
|
|
// this.getMainList();
|
|
return false;
|
|
}
|
|
|
|
const blankObj = [];
|
|
const reqData = [];
|
|
|
|
this.tbList.getRows().forEach((row) => {
|
|
// console.log(row.getData('_STATUS_'))
|
|
if (row.getData()["_STATUS_"]) {
|
|
if (
|
|
Object.keys(row._row.data)
|
|
.filter((key) => key !== "_STATUS_" && key !== "USE_FLG")
|
|
.every((key) => {
|
|
const value = row._row.data[key];
|
|
return value === undefined || value === "";
|
|
})
|
|
) {
|
|
blankObj.push(row);
|
|
} else {
|
|
reqData.push(row.getData());
|
|
}
|
|
}
|
|
});
|
|
|
|
let postdata = {
|
|
mode: "putPlan",
|
|
reqdata: JSON.stringify(result),
|
|
date : document.getElementById('plan_date').value
|
|
};
|
|
|
|
|
|
|
|
ajax_json({
|
|
url: this.ajaxUrl,
|
|
data: postdata,
|
|
success: function (data) {
|
|
if (data.code) {
|
|
kuls_success("저장되었습니다.");
|
|
_this.getMainList("getPlanList",
|
|
"team_pop",
|
|
"sub_product_pop",
|
|
"plan_date");
|
|
} else {
|
|
// kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert("잘못된 값을 입력하였습니다"); //프로시져에서 반환 메시지 수정 필요
|
|
},
|
|
complete: function () {
|
|
window.clearTimeout(talert);
|
|
_this.tbList.clearAlert();
|
|
|
|
},
|
|
});
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
* @Overview 날짜 가져오는 함수
|
|
* @Parameter 없음
|
|
* @function 현재 날짜 부터 일주일간 리스트화 하기
|
|
*/
|
|
getDate() {
|
|
const columns = [];
|
|
const daysToAdd = 7; // Including today and the next 6 days
|
|
// console.log(document.querySelector("#date_st").value);
|
|
for (let i = 0; i < daysToAdd; i++) {
|
|
const date = new Date(document.querySelector("#plan_date").value);
|
|
date.setDate(date.getDate() + i);
|
|
|
|
// Formatting the date to "MM월 DD일" format
|
|
let year = date.getFullYear();
|
|
let month = ("0" + (date.getMonth() + 1)).slice(-2); // Adding leading zero
|
|
let day = ("0" + date.getDate()).slice(-2); // Adding leading zero
|
|
let formattedDate = `${month}월 ${day}일`;
|
|
const varsITEM_GRP2 = {
|
|
"":"",
|
|
...varsITEM_GRP,
|
|
}
|
|
|
|
columns.push({
|
|
title: formattedDate,
|
|
columns: [
|
|
{
|
|
field: "AM_PLAN_QTY_" + year + "_" + month + "_" + day,
|
|
title: "오전",
|
|
hozAlign: "center",
|
|
editor: tb_custom_editor.regPlan,
|
|
editorParams:{checkPoint: 'SEPER',values: varsITEM_GRP2,},
|
|
formatter: tb_custom_formatter.selectOrNum,
|
|
formatterParams:{checkPoint: 'SEPER'},
|
|
width: '50',
|
|
editable: (cell) => {
|
|
return cell.getRow().getPosition() % 3 !== 0;
|
|
},
|
|
},
|
|
{
|
|
field: "PM_PLAN_QTY_" + year + "_" + month + "_" + day,
|
|
title: "오후",
|
|
hozAlign: "center",
|
|
editor: tb_custom_editor.regPlan,
|
|
editorParams:{checkPoint: 'SEPER',values: varsITEM_GRP2,},
|
|
formatter: tb_custom_formatter.selectOrNum,
|
|
formatterParams:{checkPoint: 'SEPER'},
|
|
width: '50',
|
|
editable: (cell) => {
|
|
return cell.getRow().getPosition() % 3 !== 0;
|
|
},
|
|
},
|
|
{
|
|
field: "NI_PLAN_QTY_" + year + "_" + month + "_" + day,
|
|
title: "야간",
|
|
hozAlign: "center",
|
|
width: '50',
|
|
editor: tb_custom_editor.regPlan,
|
|
editorParams:{checkPoint: 'SEPER',values: varsITEM_GRP2,},
|
|
formatter: tb_custom_formatter.selectOrNum,
|
|
formatterParams:{checkPoint: 'SEPER'},
|
|
editable: (cell) => {
|
|
return cell.getRow().getPosition() % 3 !== 0;
|
|
},
|
|
},
|
|
],
|
|
});
|
|
}
|
|
|
|
return columns;
|
|
}
|
|
|
|
/*
|
|
* @Overview 최초 실행 함수
|
|
* @Parameter 없음
|
|
*/
|
|
init() {
|
|
let fields = "";
|
|
// field 정의
|
|
fields = [
|
|
|
|
{field: "id", title: "id", width: '100', editor:"input",visible:false},
|
|
{field: "WRK_TEAM", title: "설비그룹", width: '100' ,visible: false},
|
|
{field: "PLAN_FACLT_CD", title: "설비", width: '100',frozen:true, formatter: tb_custom_formatter.rowspan_3},
|
|
{field: "PLAN_FACLT_NM", title: "설비명", width: '100',frozen:true, formatter: tb_custom_formatter.rowspan_3},
|
|
{field: "SEPER", title: "구분", width: '100'},
|
|
// 날짜 필드 동적으로 넣을것 오늘부터 7일까지
|
|
...this.getDate(),
|
|
];
|
|
let commonFieldData = "";
|
|
commonFieldData = {
|
|
headerSort: true,
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header", //Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
};
|
|
// this.tbList = "";
|
|
this.tbList = null; // 변수를 null로 설정
|
|
this.tbList = new Tabulator(this.table, {
|
|
layout: "fitColumns",
|
|
clipboard:true,
|
|
clipboardCopySelector: "table",
|
|
clipboardPasteParser: function(clipboard){
|
|
console.log(clipboard)
|
|
return clipboard.split("\n").map(function(row){
|
|
let cells = row.split("\t");
|
|
return {name: cells[0], age: cells[1], col: cells[2], dob: cells[3]};
|
|
});
|
|
},
|
|
clipboardPasteAction:"replace",
|
|
// data: [
|
|
// { groupId: this.lastGroupId, SEPER: "그룹" },
|
|
// { groupId: this.lastGroupId, SEPER: "계획" },
|
|
// { groupId: this.lastGroupId, SEPER: "실적" },
|
|
// ], //기본 데이터
|
|
columns: fields, //컬럼 설정
|
|
groupBy: "WRK_TEAM",
|
|
groupHeader: (value, count, data) =>{
|
|
// console.log(data)
|
|
return data[0].WRK_TEAM;
|
|
},
|
|
columnDefaults: commonFieldData,
|
|
groupStartOpen: true,
|
|
headerSortElement: "<i class='bi'></i>"
|
|
});
|
|
this.tbList.on("cellEdited", (e, tgt) => {
|
|
this.cellEdited && this.cellEdited(e, tgt);
|
|
});
|
|
}
|
|
init2(){
|
|
|
|
// 데이터 불러오기
|
|
this.tbList.on("tableBuilt", () => {
|
|
this.getMainList(
|
|
"getPlanList",
|
|
"team_pop",
|
|
"product_pop",
|
|
"sub_product_pop",
|
|
"plan_date"
|
|
);
|
|
});
|
|
// console.log(this.tbList.getRows());
|
|
|
|
// row 클릭 시에
|
|
this.tbList.on("groupClick", (e, tgt) => {
|
|
this.groupRowClick && this.groupRowClick(e, tgt);
|
|
});
|
|
// cell 클릭 시에
|
|
this.tbList.on("cellClick", (e, tgt) => {
|
|
this.cellClick && this.cellClick(e, tgt);
|
|
});
|
|
|
|
|
|
// cell 수정 시에
|
|
|
|
// // 추가
|
|
// ["click", "keypress"].forEach((evt) => {
|
|
// this.addBtn.addEventListener(evt, () => {
|
|
// console.log("test");
|
|
// this.addRow && this.addRow();
|
|
// });
|
|
// });
|
|
// // 삭제
|
|
// ["click", "keypress"].forEach((evt) => {
|
|
// this.removeBtn.addEventListener(evt, () => {
|
|
// // 삭제 함수
|
|
// this.removeRow();
|
|
// });
|
|
// });
|
|
// 엑셀
|
|
["click", "keypress"].forEach((evt) => {
|
|
const excelBtn = document.querySelector("#excel_data");
|
|
excelBtn.addEventListener(evt, () => {
|
|
tb_common_funtions.tabu2xls3(this.tbList, "생산계획", "생산계획")
|
|
});
|
|
});
|
|
// 조회
|
|
["click", "keypress"].forEach((evt) => {
|
|
const filterBtn = document.querySelector("#filter_btn");
|
|
filterBtn.addEventListener(evt, () => {
|
|
// setFilter 또는 setData
|
|
this.init();
|
|
|
|
this.setFilter();
|
|
// this.getMainList("getPlanList","team_pop","product_pop","sub_product_pop");
|
|
});
|
|
});
|
|
// 저장
|
|
["click", "keypress"].forEach((evt) => {
|
|
const putBtn = document.querySelector("#put_btn");
|
|
putBtn.addEventListener(evt, () => {
|
|
this.putData();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
const Tb_production_plan = new Tb_main_class("#main_table");
|
|
Tb_production_plan.init();
|
|
Tb_production_plan.init2(); |