const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
spread.setSheetCount(2);
const planSheet = spread.getSheet(0);
planSheet.name('공정 계획');
const summarySheet = spread.getSheet(1);
summarySheet.name('요약');
spread.suspendPaint();
// --- 공정 계획 시트 ---
const planHeaders = ['공정명', '진도율(%) — 직접 입력해보세요'];
[150, 230].forEach((w, c) => {
planSheet.setColumnWidth(c, w);
planSheet.setValue(0, c, planHeaders[c]);
planSheet.getCell(0, c).backColor('#1565C0').foreColor('#FFFFFF').font('bold 12px sans-serif').hAlign(GC.Spread.Sheets.HorizontalAlign.center);
});
planSheet.setRowHeight(0, 36);
const processes = ['원재료 투입', '절단 가공', '용접', '도장', '품질 검사'];
const initProgress = [100, 100, 65, 30, 0];
processes.forEach((p, r) => {
planSheet.setValue(r + 1, 0, p);
planSheet.setValue(r + 1, 1, initProgress[r]);
planSheet.setRowHeight(r + 1, 32);
planSheet.getCell(r + 1, 0).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
planSheet.getCell(r + 1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center).backColor('#E3F2FD');
});
// --- 요약 시트 ---
summarySheet.setColumnWidth(0, 200);
summarySheet.setColumnWidth(1, 140);
['전체 진도율', '완료 공정 수', '평균 진도율'].forEach((label, r) => {
summarySheet.setValue(r, 0, label);
summarySheet.setRowHeight(r, 40);
summarySheet.getCell(r, 0).backColor('#1B5E20').foreColor('#FFFFFF').font('bold 13px sans-serif').hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center);
});
function updateSummary() {
const total = processes.length;
let completed = 0, sum = 0;
for (let r = 1; r <= total; r++) {
const val = planSheet.getValue(r, 1) || 0;
sum += val;
if (val >= 100) completed++;
}
const avg = Math.round(sum / total);
const pct = Math.round((completed / total) * 100);
summarySheet.suspendEvent();
summarySheet.setValue(0, 1, pct + '%');
summarySheet.setValue(1, 1, completed + ' / ' + total + '개');
summarySheet.setValue(2, 1, avg + '%');
const color = avg >= 80 ? '#C8E6C9' : avg >= 50 ? '#FFF9C4' : '#FFCDD2';
[0, 1, 2].forEach(r => summarySheet.getCell(r, 1).backColor(color).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center).font('bold 14px sans-serif'));
summarySheet.resumeEvent();
}
updateSummary();
// CellChanged: 진도율(col 1) 값 변경 시에만 집계 갱신
planSheet.bind(GC.Spread.Sheets.Events.CellChanged, function(sender, args) {
if (args.propertyName === 'value' && args.col === 1 && args.row >= 1) {
updateSummary();
}
});
spread.resumePaint();