Spaces:
Sleeping

doluong6 commited on
Commit
2dcd807
·
verified ·
1 Parent(s): 8d1d46a

Delete static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +0 -276
static/script.js DELETED
@@ -1,276 +0,0 @@
1
- // Đăng nhập đơn giản
2
- function login() {
3
- const u = document.getElementById("username").value;
4
- const p = document.getElementById("password").value;
5
- if (u === "admin" && p === "1234") {
6
- document.getElementById("login").style.display = "none";
7
- document.getElementById("dashboard").style.display = "block";
8
- hienThiTongQuan();
9
- } else {
10
- alert("Sai tên đăng nhập hoặc mật khẩu!");
11
- }
12
- }
13
-
14
- // Gọi API tổng quan khi đăng nhập thành công
15
-
16
- async function hienThiDanhSachPYC() {
17
- try {
18
- const res = await fetch("/dem_pyc_tat_ca");
19
- const data = await res.json();
20
-
21
- // Nếu API trả về số đang xử lý trong key 'tong_dang_xu_ly'
22
- if (data.tong_dang_xu_ly !== undefined) {
23
- document.getElementById("pycCount").textContent = data.tong_dang_xu_ly;
24
- }
25
- // Nếu bạn đã gán luôn vào 'tong_so_pyc' thì dùng dòng dưới:
26
- else if (data.tong_so_pyc !== undefined) {
27
- document.getElementById("pycCount").textContent = data.tong_so_pyc;
28
- } else {
29
- document.getElementById("pycCount").textContent = "Không tải được";
30
- }
31
- } catch (err) {
32
- console.error("Lỗi khi gọi API PYC:", err);
33
- document.getElementById("pycCount").textContent = "Lỗi";
34
- }
35
- }
36
-
37
-
38
- async function hienThiSoPYCHoanThanh() {
39
- try {
40
- const res = await fetch("/dem_pyc_hoan_thanh");
41
- const data = await res.json();
42
-
43
- if (res.ok && data.tong_so_hoan_thanh !== undefined) {
44
- document.getElementById("completedRequests").textContent = data.tong_so_hoan_thanh;
45
- } else {
46
- document.getElementById("completedRequests").textContent = "Không tải được";
47
- }
48
- } catch (err) {
49
- console.error("Lỗi khi gọi API hoàn thành:", err);
50
- document.getElementById("completedRequests").textContent = "Lỗi";
51
- }
52
- }
53
-
54
-
55
- // Gọi API /tong_doanh_thu_pyc
56
- async function hienThiDoanhThuPYC() {
57
- try {
58
- const res = await fetch("/tong_doanh_thu_pyc");
59
- const data = await res.json();
60
- if (res.ok && data.tong_doanh_thu !== undefined) {
61
- const formatted = Number(data.tong_doanh_thu).toLocaleString("vi-VN") + " VND";
62
- document.getElementById("requestRevenue").textContent = formatted;
63
- } else {
64
- document.getElementById("requestRevenue").textContent = "Không tải được";
65
- }
66
- } catch (err) {
67
- console.error("Lỗi khi gọi API doanh thu:", err);
68
- document.getElementById("requestRevenue").textContent = "Lỗi";
69
- }
70
- }
71
-
72
- function chonMuc(muc) {
73
- const pycload = document.getElementById("pycload");
74
- const bang = document.getElementById("bangChiTiet");
75
- const tieuDe = document.getElementById("tieuDeBang");
76
- const noiDung = document.getElementById("noiDungBang");
77
- const tongQuan = document.getElementById("tongQuan");
78
-
79
- tongQuan.style.display = "none";
80
- bang.style.display = "none";
81
- document.getElementById("doanhThuTheoDichVu").style.display = "none";
82
-
83
- if (muc === "tongquan") {
84
- tongQuan.style.display = "flex";
85
- hienThiTongQuan();
86
-
87
- } else if (muc === "pyc") {
88
- if (pycload) pycload.style.display = "flex";
89
- hienThiDanhSachPYC();
90
- hienThiSoPYCHoanThanh();
91
- hienThiDoanhThuPYC();
92
- bang.style.display = "block";
93
- tieuDe.textContent = "Phiếu yêu cầu chưa hoàn thành";
94
- hienThiBangTuAPI("/pyc_chua_hoan_thanh", noiDung);
95
-
96
- } else if (muc === "dt") {
97
- bang.style.display = "block";
98
- tieuDe.textContent = "Doanh thu theo dịch vụ";
99
- noiDung.innerHTML = "";
100
- document.getElementById("doanhThuTheoDichVu").style.display = "block";
101
-
102
- setTimeout(() => {
103
- veBieuDoDichVu();
104
- hienThiBangTuAPI("/so_luong_dich_vu", document.getElementById("bangSoLuongDichVu"));
105
- hienThiBangTuAPI("/khach_hang_theo_dich_vu", document.getElementById("bangKhachHangTheoDichVu"));
106
- }, 100);
107
-
108
- } else if (muc === "dt_thang") {
109
- bang.style.display = "block";
110
- tieuDe.textContent = "Doanh thu theo tháng";
111
- noiDung.innerHTML = `<canvas id="doanhThuThangChart" height="100"></canvas>`;
112
- setTimeout(() => veBieuDoDoanhThuThang(), 0);
113
-
114
- } else if (muc === "nb") {
115
- bang.style.display = "block";
116
- tieuDe.textContent = "Doanh thu nội bộ";
117
- noiDung.innerHTML = `<canvas id="chartTongHopDoanhThu" height="100"></canvas>`;
118
- setTimeout(() => veBieuDoTongHopDoanhThu(), 0);
119
-
120
- } else {
121
- bang.style.display = "block";
122
- tieuDe.textContent = "🚧 Tính năng đang phát triển";
123
- noiDung.innerHTML = "Vui lòng quay lại sau.";
124
- }
125
- }
126
-
127
-
128
- // Hàm render bảng động
129
- async function hienThiBangTuAPI(api, noiDung) {
130
- noiDung.innerHTML = "Đang tải dữ liệu...";
131
- try {
132
- const res = await fetch(api);
133
- const data = await res.json();
134
-
135
- if (!Array.isArray(data) || data.length === 0) {
136
- noiDung.innerHTML = "Không có dữ liệu.";
137
- return;
138
- }
139
-
140
- let html = "<table class='display' id='tableAuto'><thead><tr>";
141
- for (let key in data[0]) {
142
- html += `<th>${key}</th>`;
143
- }
144
- html += "</tr></thead><tbody>";
145
-
146
- for (let row of data) {
147
- html += "<tr>";
148
- for (let key in row) {
149
- html += `<td>${row[key]}</td>`;
150
- }
151
- html += "</tr>";
152
- }
153
-
154
- html += "</tbody></table>";
155
- noiDung.innerHTML = html;
156
-
157
- $(document).ready(function () {
158
- $('#tableAuto').DataTable();
159
- });
160
- } catch (err) {
161
- console.error("Lỗi khi tải bảng:", err);
162
- noiDung.innerHTML = "Lỗi khi tải dữ liệu.";
163
- }
164
- }
165
- async function veBieuDoDoanhThuThang() {
166
- try {
167
- const response = await fetch("https://doluong6-qlht.hf.space/doanh_thu_theo_thang"); // Đổi URL nếu backend khác
168
- const data = await response.json();
169
-
170
- if (data.error) {
171
- console.error("Lỗi từ API:", data.error);
172
- return;
173
- }
174
-
175
- const ctx = document.getElementById("doanhThuThangChart").getContext("2d");
176
-
177
- new Chart(ctx, {
178
- type: "bar",
179
- data: {
180
- labels: data.labels,
181
- datasets: [{
182
- label: "Doanh thu (VNĐ)",
183
- data: data.values,
184
- backgroundColor: "rgba(54, 162, 235, 0.7)",
185
- borderColor: "rgba(54, 162, 235, 1)",
186
- borderWidth: 1
187
- }]
188
- },
189
- options: {
190
- responsive: true,
191
- scales: {
192
- y: {
193
- beginAtZero: true,
194
- ticks: {
195
- callback: function(value) {
196
- return value.toLocaleString("vi-VN") + " VNĐ";
197
- }
198
- }
199
- }
200
- },
201
- plugins: {
202
- legend: {
203
- display: false
204
- },
205
- tooltip: {
206
- callbacks: {
207
- label: function(context) {
208
- return context.raw.toLocaleString("vi-VN") + " VNĐ";
209
- }
210
- }
211
- }
212
- }
213
- }
214
- });
215
-
216
- } catch (error) {
217
- console.error("Lỗi khi gọi API hoặc vẽ biểu đồ:", error);
218
- }
219
- }
220
-
221
-
222
- async function veBieuDoDichVu() {
223
- const canvas = document.getElementById("chartDichVu");
224
- if (!canvas) {
225
- console.error("Không tìm thấy canvas chartDichVu");
226
- return;
227
- }
228
-
229
- const ctx = canvas.getContext("2d");
230
-
231
- try {
232
- const res = await fetch("/ty_le_dich_vu");
233
- const data = await res.json();
234
-
235
- const chartData = {
236
- labels: ["Kiểm định", "Hiệu chuẩn", "Đo thử nghiệm"],
237
- datasets: [{
238
- label: "Tỷ lệ dịch vụ",
239
- data: [
240
- data.Kiem_dinh || 0,
241
- data.Hieu_chuan || 0,
242
- data.Do_thu_nghiem || 0
243
- ],
244
- backgroundColor: [
245
- "#4CAF50", "#2196F3", "#FFC107"
246
- ],
247
- hoverOffset: 10
248
- }]
249
- };
250
-
251
- new Chart(ctx, {
252
- type: 'doughnut',
253
- data: chartData,
254
- options: {
255
- responsive: true,
256
- plugins: {
257
- legend: { position: 'bottom' },
258
- tooltip: {
259
- callbacks: {
260
- label: (context) => `${context.label}: ${context.raw.toFixed(2)}%`
261
- }
262
- }
263
- }
264
- }
265
- });
266
-
267
- } catch (error) {
268
- console.error("Lỗi API /ty_le_dich_vu:", error);
269
- }
270
- }
271
- function toggleSubmenu(id) {
272
- const submenu = document.getElementById(id);
273
- const parent = submenu.parentElement;
274
- parent.classList.toggle("open");
275
- }
276
-