-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
207 lines (166 loc) · 7.07 KB
/
scripts.js
File metadata and controls
207 lines (166 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// 현재 날짜를 입력 필드의 기본값으로 설정
document.addEventListener('DOMContentLoaded', function() {
const today = new Date();
const formattedDate = today.toISOString().slice(0, 10); // YYYY-MM-DD 형식
document.getElementById('date-input').value = formattedDate;
// 모달 창 관련 요소 추가
setupModal();
});
// 모달 창 설정 함수
function setupModal() {
// 모달 오버레이 및 컨테이너 생성
const modalOverlay = document.createElement('div');
modalOverlay.className = 'modal-overlay';
modalOverlay.id = 'report-modal';
const modalContainer = document.createElement('div');
modalContainer.className = 'modal-container';
const closeButton = document.createElement('button');
closeButton.className = 'modal-close';
closeButton.innerHTML = '×';
closeButton.onclick = function() {
document.getElementById('report-modal').style.display = 'none';
};
const modalBody = document.createElement('div');
modalBody.className = 'modal-body';
modalBody.id = 'modal-body';
// 요소 조립
modalContainer.appendChild(closeButton);
modalContainer.appendChild(modalBody);
modalOverlay.appendChild(modalContainer);
document.body.appendChild(modalOverlay);
// ESC 키로 모달 닫기
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
document.getElementById('report-modal').style.display = 'none';
}
});
// 모달 외부 클릭시 닫기
modalOverlay.addEventListener('click', function(event) {
if (event.target === modalOverlay) {
modalOverlay.style.display = 'none';
}
});
}
// 전체 항목 선택/해제 기능
function selectAllItems(checked) {
// 출장비 체크박스
document.getElementById("visit-check").checked = checked;
// 모든 메인 카테고리 체크박스
const categories = ['cpu', 'mb', 'ram', 'psu', 'gpu'];
categories.forEach(cat => {
const mainCheckbox = document.getElementById(`${cat}-check`);
mainCheckbox.checked = checked;
// 서브 항목들 체크/언체크
checkAllSubItems(`${cat}-items`, checked);
// 세부 항목 표시/숨김
const details = document.getElementById(`${cat}-details`);
if (checked) {
details.style.display = "block";
} else {
details.style.display = "none";
}
});
}
// 세부 항목 토글 기능
function toggleDetails(id) {
const details = document.getElementById(id);
if (details.style.display === "block") {
details.style.display = "none";
} else {
details.style.display = "block";
}
}
// 모든 하위 항목 체크/해제 기능
function checkAllSubItems(itemsName, checked) {
const items = document.getElementsByName(itemsName);
for (const item of items) {
item.checked = checked;
}
}
// 날짜 포맷 함수 (YYYY-MM-DD를 YYYY년 MM월 DD일로 변환)
function formatDate(dateString) {
const date = new Date(dateString);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}년 ${month}월 ${day}일`;
}
// 내역서 내용을 A4 용지 한 장에 맞추기 위한 자동 크기 조정 함수
function adjustReportToFitA4() {
const reportContainer = document.querySelector('.report-container');
const reportContent = document.querySelector('.report-content');
if (!reportContainer || !reportContent) return;
// A4 용지의 실제 크기 (mm 단위를 픽셀로 대략 변환)
const A4_HEIGHT_PX = 1123; // 297mm * 3.78 pixels/mm (대략적인 변환)
// 컨테이너에 auto-fit-text 클래스 추가
reportContent.classList.add('auto-fit-text');
// 문서의 실제 높이 구하기
const contentHeight = reportContent.scrollHeight;
// 문서가 A4 용지보다 크면 비율 조정
if (contentHeight > A4_HEIGHT_PX) {
// 크기 조정 비율 계산 - 약간 더 작게 만들어 여유 있게
const scale = (A4_HEIGHT_PX / contentHeight) * 0.98;
// CSS transform을 사용하여 크기 조정
reportContent.style.transform = `scale(${scale})`;
// 변환 후 높이가 100%가 되도록 컨테이너 높이 조정
reportContainer.style.height = `${A4_HEIGHT_PX}px`;
// 원래 내용물의 높이를 유지하면서 변환
reportContent.style.height = `${contentHeight}px`;
reportContent.style.transformOrigin = 'top left';
console.log(`내용이 A4 용지보다 ${Math.round((1-scale)*100)}% 더 커서 ${scale.toFixed(2)}배로 축소합니다.`);
}
}
function adjustEmptySpace(itemCount) {
// 항목 수에 따라 빈 공간을 더 작게 조정
const tableContainer = document.querySelector('.table-container');
const emptySpace = document.querySelector('.empty-space');
if (!tableContainer || !emptySpace) return;
// 항목 수가 많을수록 빈 공간을 더 줄임
const height = Math.max(10, 120 - (itemCount * 15)) + 'px';
emptySpace.style.minHeight = height;
}
// 저장하기 기능 (인쇄 다이얼로그를 통해 PDF로 저장)
function saveToPrint() {
// 인쇄 전에 A4 사이즈에 맞게 조정
adjustReportToFitA4();
// 약간의 시간 간격을 두고 인쇄 다이얼로그 실행
setTimeout(() => {
window.print();
}, 200);
}
// 함수: 세부 항목 가져오기
function getDetailItems(itemsName) {
const items = document.getElementsByName(itemsName);
const details = [];
items.forEach(item => {
if (item.checked) {
details.push(item.parentElement.textContent.trim());
}
});
return details;
}
// 초기화 - 모든 세부항목 체크박스에 하위 항목 하나라도 체크하면 상위 체크박스도 체크
document.addEventListener('DOMContentLoaded', function() {
const categories = ['cpu', 'mb', 'ram', 'psu', 'gpu'];
categories.forEach(cat => {
const items = document.getElementsByName(`${cat}-items`);
items.forEach(item => {
item.addEventListener('change', function() {
const mainCheckbox = document.getElementById(`${cat}-check`);
// 하위 항목이 하나라도 체크되어 있으면 상위 체크박스 체크
let anyChecked = false;
for (const subItem of items) {
if (subItem.checked) {
anyChecked = true;
break;
}
}
mainCheckbox.checked = anyChecked;
// 상위 체크박스 체크되면 세부 항목 표시
if (anyChecked && document.getElementById(`${cat}-details`).style.display !== "block") {
toggleDetails(`${cat}-details`);
}
});
});
});
});