forked from zakaria/zenai-apc-ngoro
fix batch bug and enhance ux
This commit is contained in:
1 parent
85e3e07153
commit
f051392739
4 files changed
+577
-285
No files matched your search
+65
-38
@@ -130,36 +130,18 @@ class BatchStore:
|
||||
'Finalizing before fresh start.'
|
||||
)
|
||||
st_count = state.get('count', 0)
|
||||
if st_count >= self.min_object_per_batch:
|
||||
is_main = st_count >= self.main_batch_min_count
|
||||
if is_main:
|
||||
bn = str(self.get_next_main_batch_number(state['counting_date']))
|
||||
else:
|
||||
prev_main = self.get_last_main_batch_number(state['counting_date']) or 1
|
||||
letter = self.get_next_sub_batch_letter(state['counting_date'], prev_main)
|
||||
bn = f"{prev_main}{letter}"
|
||||
if st_count >= 1:
|
||||
bn, is_main = self.assign_batch_number(state['counting_date'], st_count)
|
||||
status = 'VALID' if st_count >= self.min_object_per_batch else 'PARTIAL'
|
||||
self._insert_batch(
|
||||
state['counting_date'],
|
||||
bn,
|
||||
st_count,
|
||||
state['start_time'],
|
||||
datetime.now().isoformat(),
|
||||
status='VALID',
|
||||
status=status,
|
||||
is_main=is_main,
|
||||
)
|
||||
elif st_count >= 1:
|
||||
prev_main = self.get_last_main_batch_number(state['counting_date']) or 1
|
||||
letter = self.get_next_sub_batch_letter(state['counting_date'], prev_main)
|
||||
bn = f"{prev_main}{letter}"
|
||||
self._insert_batch(
|
||||
state['counting_date'],
|
||||
bn,
|
||||
st_count,
|
||||
state['start_time'],
|
||||
datetime.now().isoformat(),
|
||||
status='PARTIAL',
|
||||
is_main=False,
|
||||
)
|
||||
self.state_file.unlink(missing_ok=True)
|
||||
return None
|
||||
self.log(
|
||||
@@ -179,6 +161,29 @@ class BatchStore:
|
||||
with open(self.state_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.current_state, f, indent=2, ensure_ascii=False)
|
||||
|
||||
def assign_batch_number(self, counting_date, count):
|
||||
cur = self.db.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM batches
|
||||
WHERE counting_date = ? AND camera_name = ? AND object_label = ?
|
||||
""",
|
||||
(counting_date, self.camera_name, self.object_label),
|
||||
)
|
||||
total_existing = cur.fetchone()[0]
|
||||
|
||||
# Rule: Sub-batch does not apply to the first batch of the day
|
||||
if total_existing == 0:
|
||||
return "1", True
|
||||
|
||||
if count >= self.main_batch_min_count:
|
||||
return str(self.get_next_main_batch_number(counting_date)), True
|
||||
else:
|
||||
prev_main = self.get_last_main_batch_number(counting_date) or 1
|
||||
letter = self.get_next_sub_batch_letter(counting_date, prev_main)
|
||||
return f"{prev_main}{letter}", False
|
||||
|
||||
def get_last_main_batch_number(self, counting_date):
|
||||
cur = self.db.cursor()
|
||||
cur.execute(
|
||||
@@ -186,11 +191,10 @@ class BatchStore:
|
||||
SELECT batch_number
|
||||
FROM batches
|
||||
WHERE counting_date = ? AND camera_name = ? AND object_label = ?
|
||||
AND count >= ?
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
""",
|
||||
(counting_date, self.camera_name, self.object_label, self.main_batch_min_count),
|
||||
(counting_date, self.camera_name, self.object_label),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if row:
|
||||
@@ -205,9 +209,8 @@ class BatchStore:
|
||||
SELECT COALESCE(MAX(CAST(batch_number AS INTEGER)), 0)
|
||||
FROM batches
|
||||
WHERE counting_date = ? AND camera_name = ? AND object_label = ?
|
||||
AND count >= ?
|
||||
""",
|
||||
(counting_date, self.camera_name, self.object_label, self.main_batch_min_count),
|
||||
(counting_date, self.camera_name, self.object_label),
|
||||
)
|
||||
val = cur.fetchone()[0]
|
||||
return val + 1
|
||||
@@ -240,6 +243,17 @@ class BatchStore:
|
||||
return chr(ord(last) + 1)
|
||||
|
||||
def get_next_batch_number(self, counting_date):
|
||||
cur = self.db.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM batches
|
||||
WHERE counting_date = ? AND camera_name = ? AND object_label = ?
|
||||
""",
|
||||
(counting_date, self.camera_name, self.object_label),
|
||||
)
|
||||
if cur.fetchone()[0] == 0:
|
||||
return 1
|
||||
return self.get_next_main_batch_number(counting_date)
|
||||
|
||||
def start_new_batch(self, counting_date):
|
||||
@@ -400,19 +414,26 @@ class BatchStore:
|
||||
return False
|
||||
|
||||
# Determine standalone main batch vs sub batch merged into preceding main batch
|
||||
prev_main = self.get_last_main_batch_number(state['counting_date'])
|
||||
final_batch_number, is_main = self.assign_batch_number(state['counting_date'], state['count'])
|
||||
|
||||
# Rule: Sub-batch does not apply to the first batch of the day
|
||||
if prev_main is None:
|
||||
is_main = True
|
||||
final_batch_number = "1"
|
||||
elif state['count'] >= self.main_batch_min_count:
|
||||
is_main = True
|
||||
final_batch_number = str(self.get_next_main_batch_number(state['counting_date']))
|
||||
else:
|
||||
is_main = False
|
||||
letter = self.get_next_sub_batch_letter(state['counting_date'], prev_main)
|
||||
final_batch_number = f"{prev_main}{letter}"
|
||||
# Safety guard against UNIQUE constraint collisions
|
||||
cur = self.db.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT 1 FROM batches
|
||||
WHERE counting_date = ? AND batch_number = ?
|
||||
AND camera_name = ? AND object_label = ?
|
||||
""",
|
||||
(state['counting_date'], str(final_batch_number), self.camera_name, self.object_label),
|
||||
)
|
||||
if cur.fetchone():
|
||||
self.log(f"WARNING: Batch #{final_batch_number} already exists! Resolving collision...")
|
||||
if is_main:
|
||||
final_batch_number = str(self.get_next_main_batch_number(state['counting_date']))
|
||||
else:
|
||||
prev_main = self.get_last_main_batch_number(state['counting_date']) or 1
|
||||
letter = self.get_next_sub_batch_letter(state['counting_date'], prev_main)
|
||||
final_batch_number = f"{prev_main}{letter}"
|
||||
|
||||
state['batch_number'] = final_batch_number
|
||||
batch_id = f"{state['counting_date']}-{final_batch_number}"
|
||||
@@ -443,6 +464,12 @@ class BatchStore:
|
||||
)
|
||||
except Exception as exc:
|
||||
self.log(f'Failed to persist batch: {exc}')
|
||||
# CRITICAL: Always clean up in-memory state and timer so the counter never gets permanently stuck!
|
||||
self.current_state = None
|
||||
self.save_state()
|
||||
if self.batch_timer:
|
||||
self.batch_timer.cancel()
|
||||
self.batch_timer = None
|
||||
return False
|
||||
|
||||
self.current_state = None
|
||||
|
||||
+370
-206
@@ -18,6 +18,7 @@ from pathlib import Path
|
||||
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
from flask import Flask, render_template, jsonify, request, Response
|
||||
from werkzeug.serving import WSGIRequestHandler
|
||||
@@ -784,40 +785,52 @@ def _excel_response(wb, filename):
|
||||
)
|
||||
|
||||
|
||||
def _style_header(ws, cols):
|
||||
def _style_header(ws, cols, row_idx=1):
|
||||
header_font = Font(bold=True, color="FFFFFF", size=11)
|
||||
header_fill = PatternFill(start_color="0F4C75", end_color="0F4C75", fill_type="solid")
|
||||
thin_border = Border(
|
||||
left=Side(style="thin"), right=Side(style="thin"),
|
||||
top=Side(style="thin"), bottom=Side(style="thin"),
|
||||
left=Side(style="thin", color="CBD5E1"), right=Side(style="thin", color="CBD5E1"),
|
||||
top=Side(style="thin", color="CBD5E1"), bottom=Side(style="thin", color="CBD5E1"),
|
||||
)
|
||||
for col_idx, (_, text) in enumerate(cols, 1):
|
||||
cell = ws.cell(row=1, column=col_idx, value=text)
|
||||
cell = ws.cell(row=row_idx, column=col_idx, value=text)
|
||||
cell.font = header_font
|
||||
cell.fill = header_fill
|
||||
cell.alignment = Alignment(horizontal="center")
|
||||
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||
cell.border = thin_border
|
||||
ws.freeze_panes = "A2"
|
||||
ws.row_dimensions[row_idx].height = 24
|
||||
|
||||
|
||||
def _style_section_banner(ws, text, row_idx, num_cols):
|
||||
banner_font = Font(bold=True, color="FFFFFF", size=11)
|
||||
banner_fill = PatternFill(start_color="1B2A4A", end_color="1B2A4A", fill_type="solid")
|
||||
for col_idx in range(1, num_cols + 1):
|
||||
c = ws.cell(row=row_idx, column=col_idx)
|
||||
c.fill = banner_fill
|
||||
ws.merge_cells(start_row=row_idx, start_column=1, end_row=row_idx, end_column=num_cols)
|
||||
cell = ws.cell(row=row_idx, column=1, value=text)
|
||||
cell.font = banner_font
|
||||
cell.alignment = Alignment(horizontal="left", vertical="center", indent=1)
|
||||
ws.row_dimensions[row_idx].height = 24
|
||||
|
||||
|
||||
def _auto_width(ws):
|
||||
for col in ws.columns:
|
||||
for col_idx, col in enumerate(ws.columns, 1):
|
||||
max_len = 0
|
||||
col_letter = col[0].column_letter
|
||||
col_letter = get_column_letter(col_idx)
|
||||
for cell in col:
|
||||
if cell.value is not None:
|
||||
max_len = max(max_len, len(str(cell.value)))
|
||||
ws.column_dimensions[col_letter].width = max_len + 4
|
||||
if cell.value is not None and type(cell).__name__ != 'MergedCell':
|
||||
val_str = str(cell.value)
|
||||
if len(val_str) <= 45:
|
||||
max_len = max(max_len, len(val_str))
|
||||
ws.column_dimensions[col_letter].width = max(max_len + 4, 12)
|
||||
|
||||
|
||||
def _prepare_batches_for_export(rows):
|
||||
"""
|
||||
Builds explicit rows for export, retaining every batch run (never omitting rows).
|
||||
Adds dedicated columns:
|
||||
- 'before_count': Raw individual batch count.
|
||||
- 'after_count': Consolidated total on Main batch, 0 on Child batch.
|
||||
- 'batch_type': 'Main' vs 'Sub'.
|
||||
- 'notes': 'Main (termasuk 15a)' / 'Digabung ke Batch 15' / '-'.
|
||||
Builds explicit rows for export, returning:
|
||||
1. raw_rows: All batch runs as counted (Main and Sub), raw counts.
|
||||
2. fixed_rows: Only the consolidated fixed batches (after adjustments), excluding batches with 0 chickens.
|
||||
"""
|
||||
main_min = MAIN_BATCH_MIN_COUNT
|
||||
groups = []
|
||||
@@ -865,14 +878,15 @@ def _prepare_batches_for_export(rows):
|
||||
}
|
||||
groups.append(current_group)
|
||||
else:
|
||||
# Assign explicit letter suffix (a, b, c...) if child does not have one
|
||||
if not has_letter:
|
||||
sub_idx = len(current_group["children"])
|
||||
letter = chr(ord('a') + sub_idx) if sub_idx < 26 else f"a{sub_idx}"
|
||||
row["batch_number"] = f"{current_group['main_id']}{letter}"
|
||||
current_group["children"].append(row)
|
||||
|
||||
export_rows = []
|
||||
raw_rows = []
|
||||
fixed_rows = []
|
||||
|
||||
for grp in groups:
|
||||
main_r = grp["main_row"]
|
||||
children = grp["children"]
|
||||
@@ -882,14 +896,12 @@ def _prepare_batches_for_export(rows):
|
||||
child_labels = [str(c["batch_number"]) for c in children]
|
||||
|
||||
main_notes = f"Main (termasuk {', '.join(child_labels)})" if children else "-"
|
||||
export_rows.append(
|
||||
raw_rows.append(
|
||||
{
|
||||
"counting_date": main_r.get("counting_date"),
|
||||
"batch_number": main_r["batch_number"],
|
||||
"batch_type": "Main",
|
||||
"before_count": main_raw,
|
||||
"after_count": consolidated_total,
|
||||
"status": main_r.get("status") or "VALID",
|
||||
"count": main_raw,
|
||||
"notes": main_notes,
|
||||
"start_time": main_r.get("start_time"),
|
||||
"end_time": main_r.get("end_time"),
|
||||
@@ -899,14 +911,12 @@ def _prepare_batches_for_export(rows):
|
||||
|
||||
for c in children:
|
||||
parent_id = grp["main_id"]
|
||||
export_rows.append(
|
||||
raw_rows.append(
|
||||
{
|
||||
"counting_date": c.get("counting_date"),
|
||||
"batch_number": c["batch_number"],
|
||||
"batch_type": "Sub",
|
||||
"before_count": c.get("count") or 0,
|
||||
"after_count": 0,
|
||||
"status": c.get("status") or "PARTIAL",
|
||||
"count": c.get("count") or 0,
|
||||
"notes": f"Digabung ke Batch {parent_id}",
|
||||
"start_time": c.get("start_time"),
|
||||
"end_time": c.get("end_time"),
|
||||
@@ -914,7 +924,25 @@ def _prepare_batches_for_export(rows):
|
||||
}
|
||||
)
|
||||
|
||||
return export_rows
|
||||
# Standalone fixed batch (NO 0-chicken batches!)
|
||||
if consolidated_total > 0:
|
||||
fixed_end = children[-1].get("end_time") if children and children[-1].get("end_time") else main_r.get("end_time")
|
||||
combined_dur = round((main_r.get("duration_minutes") or 0) + sum(c.get("duration_minutes") or 0 for c in children), 1)
|
||||
fixed_notes = f"Termasuk {', '.join(child_labels)}" if children else "-"
|
||||
fixed_rows.append(
|
||||
{
|
||||
"counting_date": main_r.get("counting_date"),
|
||||
"batch_number": grp["main_id"],
|
||||
"batch_type": "Main",
|
||||
"count": consolidated_total,
|
||||
"notes": fixed_notes,
|
||||
"start_time": main_r.get("start_time"),
|
||||
"end_time": fixed_end,
|
||||
"duration_minutes": combined_dur,
|
||||
}
|
||||
)
|
||||
|
||||
return raw_rows, fixed_rows
|
||||
|
||||
|
||||
@app.route("/api/export-daily-csv")
|
||||
@@ -942,31 +970,14 @@ def export_daily_xlsx():
|
||||
except Exception as e:
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
export_rows = _prepare_batches_for_export(rows)
|
||||
raw_rows, fixed_rows = _prepare_batches_for_export(rows)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Laporan Harian"
|
||||
_style_header(
|
||||
ws,
|
||||
[
|
||||
("A", "Tanggal"),
|
||||
("B", "Batch #"),
|
||||
("C", "Tipe Batch"),
|
||||
("D", "Hitung Ayam Potong (Before)"),
|
||||
("E", "Batch Disesuaikan (After)"),
|
||||
("F", "Status"),
|
||||
("G", "Catatan"),
|
||||
("H", "Mulai"),
|
||||
("I", "Selesai"),
|
||||
("J", "Durasi (menit)"),
|
||||
],
|
||||
)
|
||||
|
||||
child_font = Font(color="B45309", bold=True)
|
||||
child_fill = PatternFill(start_color="FEF3C7", end_color="FEF3C7", fill_type="solid")
|
||||
warn_font = Font(color="DC2626", bold=True)
|
||||
warn_fill = PatternFill(start_color="FEE2E2", end_color="FEE2E2", fill_type="solid")
|
||||
|
||||
total_font = Font(bold=True, color="0F172A", size=11)
|
||||
total_fill = PatternFill(start_color="F1F5F9", end_color="F1F5F9", fill_type="solid")
|
||||
@@ -977,97 +988,184 @@ def export_daily_xlsx():
|
||||
right=Side(style="thin", color="CBD5E1"),
|
||||
)
|
||||
|
||||
for r_idx, row in enumerate(export_rows, 2):
|
||||
ws.cell(row=r_idx, column=1, value=row["counting_date"])
|
||||
ws.cell(row=r_idx, column=2, value=str(row["batch_number"]))
|
||||
type_cell = ws.cell(row=r_idx, column=3, value=row["batch_type"])
|
||||
avg_font = Font(bold=True, italic=True, color="334155", size=10)
|
||||
avg_fill = PatternFill(start_color="F8FAFC", end_color="F8FAFC", fill_type="solid")
|
||||
avg_border = Border(
|
||||
top=Side(style="thin", color="E2E8F0"),
|
||||
bottom=Side(style="thin", color="94A3B8"),
|
||||
left=Side(style="thin", color="E2E8F0"),
|
||||
right=Side(style="thin", color="E2E8F0"),
|
||||
)
|
||||
|
||||
cur_row = 1
|
||||
|
||||
# ── TABEL 1: HITUNG AYAM POTONG (RINCIAN SELURUH BATCH) ──
|
||||
_style_section_banner(ws, "1. HITUNG AYAM POTONG (RINCIAN SELURUH BATCH)", cur_row, 8)
|
||||
cur_row += 1
|
||||
|
||||
t1_headers = [
|
||||
("A", "Tanggal"),
|
||||
("B", "Batch #"),
|
||||
("C", "Tipe Batch"),
|
||||
("D", "Hitung Ayam Potong"),
|
||||
("E", "Catatan"),
|
||||
("F", "Mulai"),
|
||||
("G", "Selesai"),
|
||||
("H", "Durasi (menit)"),
|
||||
]
|
||||
_style_header(ws, t1_headers, cur_row)
|
||||
cur_row += 1
|
||||
|
||||
for row in raw_rows:
|
||||
ws.cell(row=cur_row, column=1, value=row["counting_date"])
|
||||
ws.cell(row=cur_row, column=2, value=str(row["batch_number"]))
|
||||
type_cell = ws.cell(row=cur_row, column=3, value=row["batch_type"])
|
||||
if row["batch_type"] == "Sub":
|
||||
type_cell.font = child_font
|
||||
type_cell.fill = child_fill
|
||||
ws.cell(row=r_idx, column=4, value=row["before_count"]).number_format = '#,##0'
|
||||
ws.cell(row=r_idx, column=5, value=row["after_count"]).number_format = '#,##0'
|
||||
status_val = row["status"] or "VALID"
|
||||
status_cell = ws.cell(row=r_idx, column=6, value=status_val)
|
||||
if status_val in ("PARSIAL", "PARTIAL"):
|
||||
status_cell.font = warn_font
|
||||
status_cell.fill = warn_fill
|
||||
ws.cell(row=r_idx, column=7, value=row["notes"])
|
||||
ws.cell(row=r_idx, column=8, value=row["start_time"])
|
||||
ws.cell(row=r_idx, column=9, value=row["end_time"])
|
||||
ws.cell(row=r_idx, column=10, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
ws.cell(row=cur_row, column=4, value=row["count"]).number_format = '#,##0'
|
||||
ws.cell(row=cur_row, column=5, value=row["notes"])
|
||||
ws.cell(row=cur_row, column=6, value=row["start_time"])
|
||||
ws.cell(row=cur_row, column=7, value=row["end_time"])
|
||||
ws.cell(row=cur_row, column=8, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
cur_row += 1
|
||||
|
||||
if export_rows:
|
||||
total_row_idx = len(export_rows) + 2
|
||||
avg_row_idx = total_row_idx + 1
|
||||
last_data_row = total_row_idx - 1
|
||||
if raw_rows:
|
||||
total_raw = sum(r["count"] for r in raw_rows)
|
||||
total_raw_dur = round(sum(r.get("duration_minutes") or 0 for r in raw_rows), 1)
|
||||
main_count = sum(1 for r in raw_rows if r["batch_type"] == "Main")
|
||||
sub_count = sum(1 for r in raw_rows if r["batch_type"] == "Sub")
|
||||
earliest_start = raw_rows[0]["start_time"]
|
||||
latest_end = raw_rows[-1]["end_time"]
|
||||
avg_raw = round(total_raw / len(raw_rows), 1)
|
||||
avg_raw_dur = round(total_raw_dur / len(raw_rows), 1)
|
||||
|
||||
total_before = sum(r["before_count"] for r in export_rows)
|
||||
total_after = sum(r["after_count"] for r in export_rows)
|
||||
total_dur = round(sum(r.get("duration_minutes") or 0 for r in export_rows), 1)
|
||||
# TOTAL ROW Table 1
|
||||
ws.cell(row=cur_row, column=1, value="TOTAL")
|
||||
ws.cell(row=cur_row, column=2, value=f"{len(raw_rows)} Batch")
|
||||
ws.cell(row=cur_row, column=3, value=f"{main_count} Main, {sub_count} Sub")
|
||||
ws.cell(row=cur_row, column=4, value=total_raw)
|
||||
ws.cell(row=cur_row, column=5, value="Semua batch terhitung")
|
||||
ws.cell(row=cur_row, column=6, value=earliest_start)
|
||||
ws.cell(row=cur_row, column=7, value=latest_end)
|
||||
ws.cell(row=cur_row, column=8, value=total_raw_dur)
|
||||
|
||||
main_count = sum(1 for r in export_rows if r["batch_type"] == "Main")
|
||||
sub_count = sum(1 for r in export_rows if r["batch_type"] == "Sub")
|
||||
valid_count = sum(1 for r in export_rows if (r["status"] or "VALID") in ("VALID", "Valid"))
|
||||
partial_count = len(export_rows) - valid_count
|
||||
earliest_start = export_rows[0]["start_time"]
|
||||
latest_end = export_rows[-1]["end_time"]
|
||||
|
||||
avg_before = round(total_before / len(export_rows), 1) if export_rows else 0
|
||||
avg_after = round(total_after / (main_count or 1), 1) if main_count else 0
|
||||
avg_dur = round(total_dur / len(export_rows), 1) if export_rows else 0
|
||||
|
||||
# --- TOTAL ROW ---
|
||||
ws.cell(row=total_row_idx, column=1, value="TOTAL")
|
||||
ws.cell(row=total_row_idx, column=2, value=f"{len(export_rows)} Batch")
|
||||
ws.cell(row=total_row_idx, column=3, value=f"{main_count} Main, {sub_count} Sub")
|
||||
ws.cell(row=total_row_idx, column=4, value=total_before)
|
||||
ws.cell(row=total_row_idx, column=5, value=total_after)
|
||||
ws.cell(row=total_row_idx, column=6, value=f"{valid_count} Valid, {partial_count} Parsial")
|
||||
ws.cell(row=total_row_idx, column=7, value="Semua batch terhitung")
|
||||
ws.cell(row=total_row_idx, column=8, value=earliest_start)
|
||||
ws.cell(row=total_row_idx, column=9, value=latest_end)
|
||||
ws.cell(row=total_row_idx, column=10, value=total_dur)
|
||||
|
||||
for col_idx in range(1, 11):
|
||||
c = ws.cell(row=total_row_idx, column=col_idx)
|
||||
for col_idx in range(1, 9):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = total_font
|
||||
c.fill = total_fill
|
||||
c.border = total_border
|
||||
if col_idx in (4, 5):
|
||||
if col_idx == 4:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 10:
|
||||
elif col_idx == 8:
|
||||
c.number_format = '#,##0.0'
|
||||
elif col_idx in (1, 2, 3, 6):
|
||||
elif col_idx in (1, 2, 3, 5):
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# --- AVERAGE ROW ---
|
||||
avg_font = Font(bold=True, italic=True, color="334155", size=10)
|
||||
avg_fill = PatternFill(start_color="F8FAFC", end_color="F8FAFC", fill_type="solid")
|
||||
avg_border = Border(
|
||||
top=Side(style="thin", color="E2E8F0"),
|
||||
bottom=Side(style="thin", color="94A3B8"),
|
||||
left=Side(style="thin", color="E2E8F0"),
|
||||
right=Side(style="thin", color="E2E8F0"),
|
||||
)
|
||||
ws.cell(row=avg_row_idx, column=1, value="RATA-RATA")
|
||||
ws.cell(row=avg_row_idx, column=2, value="-")
|
||||
ws.cell(row=avg_row_idx, column=3, value="-")
|
||||
ws.cell(row=avg_row_idx, column=4, value=avg_before)
|
||||
ws.cell(row=avg_row_idx, column=5, value=avg_after)
|
||||
ws.cell(row=avg_row_idx, column=6, value="-")
|
||||
ws.cell(row=avg_row_idx, column=7, value="-")
|
||||
ws.cell(row=avg_row_idx, column=8, value="-")
|
||||
ws.cell(row=avg_row_idx, column=9, value="-")
|
||||
ws.cell(row=avg_row_idx, column=10, value=avg_dur)
|
||||
# AVERAGE ROW Table 1
|
||||
ws.cell(row=cur_row, column=1, value="RATA-RATA")
|
||||
ws.cell(row=cur_row, column=2, value="-")
|
||||
ws.cell(row=cur_row, column=3, value="-")
|
||||
ws.cell(row=cur_row, column=4, value=avg_raw)
|
||||
ws.cell(row=cur_row, column=5, value="-")
|
||||
ws.cell(row=cur_row, column=6, value="-")
|
||||
ws.cell(row=cur_row, column=7, value="-")
|
||||
ws.cell(row=cur_row, column=8, value=avg_raw_dur)
|
||||
|
||||
for col_idx in range(1, 11):
|
||||
c = ws.cell(row=avg_row_idx, column=col_idx)
|
||||
for col_idx in range(1, 9):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = avg_font
|
||||
c.fill = avg_fill
|
||||
c.border = avg_border
|
||||
if col_idx in (4, 5):
|
||||
if col_idx == 4:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 10:
|
||||
elif col_idx == 8:
|
||||
c.number_format = '#,##0.0'
|
||||
else:
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# 2 Empty Rows
|
||||
cur_row += 2
|
||||
|
||||
# ── TABEL 2: BATCH DISESUAIKAN (SETELAH PENYESUAIAN) ──
|
||||
_style_section_banner(ws, "2. BATCH DISESUAIKAN (SETELAH PENYESUAIAN) - HANYA BATCH TETAP", cur_row, 8)
|
||||
cur_row += 1
|
||||
|
||||
t2_headers = [
|
||||
("A", "Tanggal"),
|
||||
("B", "Batch #"),
|
||||
("C", "Tipe Batch"),
|
||||
("D", "Batch Disesuaikan"),
|
||||
("E", "Catatan"),
|
||||
("F", "Mulai"),
|
||||
("G", "Selesai"),
|
||||
("H", "Durasi (menit)"),
|
||||
]
|
||||
_style_header(ws, t2_headers, cur_row)
|
||||
cur_row += 1
|
||||
|
||||
for row in fixed_rows:
|
||||
ws.cell(row=cur_row, column=1, value=row["counting_date"])
|
||||
ws.cell(row=cur_row, column=2, value=str(row["batch_number"]))
|
||||
ws.cell(row=cur_row, column=3, value=row["batch_type"])
|
||||
ws.cell(row=cur_row, column=4, value=row["count"]).number_format = '#,##0'
|
||||
ws.cell(row=cur_row, column=5, value=row["notes"])
|
||||
ws.cell(row=cur_row, column=6, value=row["start_time"])
|
||||
ws.cell(row=cur_row, column=7, value=row["end_time"])
|
||||
ws.cell(row=cur_row, column=8, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
cur_row += 1
|
||||
|
||||
if fixed_rows:
|
||||
total_fixed = sum(r["count"] for r in fixed_rows)
|
||||
total_fixed_dur = round(sum(r.get("duration_minutes") or 0 for r in fixed_rows), 1)
|
||||
fixed_start = fixed_rows[0]["start_time"]
|
||||
fixed_end = fixed_rows[-1]["end_time"]
|
||||
avg_fixed = round(total_fixed / len(fixed_rows), 1)
|
||||
avg_fixed_dur = round(total_fixed_dur / len(fixed_rows), 1)
|
||||
|
||||
# TOTAL ROW Table 2
|
||||
ws.cell(row=cur_row, column=1, value="TOTAL")
|
||||
ws.cell(row=cur_row, column=2, value=f"{len(fixed_rows)} Batch")
|
||||
ws.cell(row=cur_row, column=3, value=f"{len(fixed_rows)} Main Batch")
|
||||
ws.cell(row=cur_row, column=4, value=total_fixed)
|
||||
ws.cell(row=cur_row, column=5, value="Semua batch tetap")
|
||||
ws.cell(row=cur_row, column=6, value=fixed_start)
|
||||
ws.cell(row=cur_row, column=7, value=fixed_end)
|
||||
ws.cell(row=cur_row, column=8, value=total_fixed_dur)
|
||||
|
||||
for col_idx in range(1, 9):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = total_font
|
||||
c.fill = total_fill
|
||||
c.border = total_border
|
||||
if col_idx == 4:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 8:
|
||||
c.number_format = '#,##0.0'
|
||||
elif col_idx in (1, 2, 3, 5):
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# AVERAGE ROW Table 2
|
||||
ws.cell(row=cur_row, column=1, value="RATA-RATA")
|
||||
ws.cell(row=cur_row, column=2, value="-")
|
||||
ws.cell(row=cur_row, column=3, value="-")
|
||||
ws.cell(row=cur_row, column=4, value=avg_fixed)
|
||||
ws.cell(row=cur_row, column=5, value="-")
|
||||
ws.cell(row=cur_row, column=6, value="-")
|
||||
ws.cell(row=cur_row, column=7, value="-")
|
||||
ws.cell(row=cur_row, column=8, value=avg_fixed_dur)
|
||||
|
||||
for col_idx in range(1, 9):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = avg_font
|
||||
c.fill = avg_fill
|
||||
c.border = avg_border
|
||||
if col_idx == 4:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 8:
|
||||
c.number_format = '#,##0.0'
|
||||
else:
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
@@ -1100,30 +1198,14 @@ def export_day_xlsx(date):
|
||||
except Exception as e:
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
export_rows = _prepare_batches_for_export(rows)
|
||||
raw_rows, fixed_rows = _prepare_batches_for_export(rows)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = f"Hari {date}"
|
||||
_style_header(
|
||||
ws,
|
||||
[
|
||||
("A", "Batch #"),
|
||||
("B", "Tipe Batch"),
|
||||
("C", "Hitung Ayam Potong (Before)"),
|
||||
("D", "Batch Disesuaikan (After)"),
|
||||
("E", "Status"),
|
||||
("F", "Catatan"),
|
||||
("G", "Mulai"),
|
||||
("H", "Selesai"),
|
||||
("I", "Durasi (menit)"),
|
||||
],
|
||||
)
|
||||
|
||||
child_font = Font(color="B45309", bold=True)
|
||||
child_fill = PatternFill(start_color="FEF3C7", end_color="FEF3C7", fill_type="solid")
|
||||
warn_font = Font(color="DC2626", bold=True)
|
||||
warn_fill = PatternFill(start_color="FEE2E2", end_color="FEE2E2", fill_type="solid")
|
||||
|
||||
total_font = Font(bold=True, color="0F172A", size=11)
|
||||
total_fill = PatternFill(start_color="F1F5F9", end_color="F1F5F9", fill_type="solid")
|
||||
@@ -1134,94 +1216,176 @@ def export_day_xlsx(date):
|
||||
right=Side(style="thin", color="CBD5E1"),
|
||||
)
|
||||
|
||||
for r_idx, row in enumerate(export_rows, 2):
|
||||
ws.cell(row=r_idx, column=1, value=str(row["batch_number"]))
|
||||
type_cell = ws.cell(row=r_idx, column=2, value=row["batch_type"])
|
||||
avg_font = Font(bold=True, italic=True, color="334155", size=10)
|
||||
avg_fill = PatternFill(start_color="F8FAFC", end_color="F8FAFC", fill_type="solid")
|
||||
avg_border = Border(
|
||||
top=Side(style="thin", color="E2E8F0"),
|
||||
bottom=Side(style="thin", color="94A3B8"),
|
||||
left=Side(style="thin", color="E2E8F0"),
|
||||
right=Side(style="thin", color="E2E8F0"),
|
||||
)
|
||||
|
||||
cur_row = 1
|
||||
|
||||
# ── TABEL 1: HITUNG AYAM POTONG (RINCIAN SELURUH BATCH) ──
|
||||
_style_section_banner(ws, f"1. HITUNG AYAM POTONG (RINCIAN SELURUH BATCH) - TANGGAL {date}", cur_row, 7)
|
||||
cur_row += 1
|
||||
|
||||
t1_headers = [
|
||||
("A", "Batch #"),
|
||||
("B", "Tipe Batch"),
|
||||
("C", "Hitung Ayam Potong"),
|
||||
("D", "Catatan"),
|
||||
("E", "Mulai"),
|
||||
("F", "Selesai"),
|
||||
("G", "Durasi (menit)"),
|
||||
]
|
||||
_style_header(ws, t1_headers, cur_row)
|
||||
cur_row += 1
|
||||
|
||||
for row in raw_rows:
|
||||
ws.cell(row=cur_row, column=1, value=str(row["batch_number"]))
|
||||
type_cell = ws.cell(row=cur_row, column=2, value=row["batch_type"])
|
||||
if row["batch_type"] == "Sub":
|
||||
type_cell.font = child_font
|
||||
type_cell.fill = child_fill
|
||||
ws.cell(row=r_idx, column=3, value=row["before_count"]).number_format = '#,##0'
|
||||
ws.cell(row=r_idx, column=4, value=row["after_count"]).number_format = '#,##0'
|
||||
status_val = row["status"] or "VALID"
|
||||
status_cell = ws.cell(row=r_idx, column=5, value=status_val)
|
||||
if status_val in ("PARSIAL", "PARTIAL"):
|
||||
status_cell.font = warn_font
|
||||
status_cell.fill = warn_fill
|
||||
ws.cell(row=r_idx, column=6, value=row["notes"])
|
||||
ws.cell(row=r_idx, column=7, value=row["start_time"])
|
||||
ws.cell(row=r_idx, column=8, value=row["end_time"])
|
||||
ws.cell(row=r_idx, column=9, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
ws.cell(row=cur_row, column=3, value=row["count"]).number_format = '#,##0'
|
||||
ws.cell(row=cur_row, column=4, value=row["notes"])
|
||||
ws.cell(row=cur_row, column=5, value=row["start_time"])
|
||||
ws.cell(row=cur_row, column=6, value=row["end_time"])
|
||||
ws.cell(row=cur_row, column=7, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
cur_row += 1
|
||||
|
||||
if export_rows:
|
||||
total_row_idx = len(export_rows) + 2
|
||||
avg_row_idx = total_row_idx + 1
|
||||
last_data_row = total_row_idx - 1
|
||||
if raw_rows:
|
||||
total_raw = sum(r["count"] for r in raw_rows)
|
||||
total_raw_dur = round(sum(r.get("duration_minutes") or 0 for r in raw_rows), 1)
|
||||
main_count = sum(1 for r in raw_rows if r["batch_type"] == "Main")
|
||||
sub_count = sum(1 for r in raw_rows if r["batch_type"] == "Sub")
|
||||
earliest_start = raw_rows[0]["start_time"]
|
||||
latest_end = raw_rows[-1]["end_time"]
|
||||
avg_raw = round(total_raw / len(raw_rows), 1)
|
||||
avg_raw_dur = round(total_raw_dur / len(raw_rows), 1)
|
||||
|
||||
total_before = sum(r["before_count"] for r in export_rows)
|
||||
total_after = sum(r["after_count"] for r in export_rows)
|
||||
total_dur = round(sum(r.get("duration_minutes") or 0 for r in export_rows), 1)
|
||||
# TOTAL ROW Table 1
|
||||
ws.cell(row=cur_row, column=1, value="TOTAL")
|
||||
ws.cell(row=cur_row, column=2, value=f"{main_count} Main, {sub_count} Sub")
|
||||
ws.cell(row=cur_row, column=3, value=total_raw)
|
||||
ws.cell(row=cur_row, column=4, value=f"{len(raw_rows)} Batch Total")
|
||||
ws.cell(row=cur_row, column=5, value=earliest_start)
|
||||
ws.cell(row=cur_row, column=6, value=latest_end)
|
||||
ws.cell(row=cur_row, column=7, value=total_raw_dur)
|
||||
|
||||
main_count = sum(1 for r in export_rows if r["batch_type"] == "Main")
|
||||
sub_count = sum(1 for r in export_rows if r["batch_type"] == "Sub")
|
||||
valid_count = sum(1 for r in export_rows if (r["status"] or "VALID") in ("VALID", "Valid"))
|
||||
partial_count = len(export_rows) - valid_count
|
||||
earliest_start = export_rows[0]["start_time"]
|
||||
latest_end = export_rows[-1]["end_time"]
|
||||
|
||||
avg_before = round(total_before / len(export_rows), 1) if export_rows else 0
|
||||
avg_after = round(total_after / (main_count or 1), 1) if main_count else 0
|
||||
avg_dur = round(total_dur / len(export_rows), 1) if export_rows else 0
|
||||
|
||||
# --- TOTAL ROW ---
|
||||
ws.cell(row=total_row_idx, column=1, value="TOTAL")
|
||||
ws.cell(row=total_row_idx, column=2, value=f"{main_count} Main, {sub_count} Sub")
|
||||
ws.cell(row=total_row_idx, column=3, value=total_before)
|
||||
ws.cell(row=total_row_idx, column=4, value=total_after)
|
||||
ws.cell(row=total_row_idx, column=5, value=f"{valid_count} Valid, {partial_count} Parsial")
|
||||
ws.cell(row=total_row_idx, column=6, value=f"{len(export_rows)} Batch Total")
|
||||
ws.cell(row=total_row_idx, column=7, value=earliest_start)
|
||||
ws.cell(row=total_row_idx, column=8, value=latest_end)
|
||||
ws.cell(row=total_row_idx, column=9, value=total_dur)
|
||||
|
||||
for col_idx in range(1, 10):
|
||||
c = ws.cell(row=total_row_idx, column=col_idx)
|
||||
for col_idx in range(1, 8):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = total_font
|
||||
c.fill = total_fill
|
||||
c.border = total_border
|
||||
if col_idx in (3, 4):
|
||||
if col_idx == 3:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 9:
|
||||
elif col_idx == 7:
|
||||
c.number_format = '#,##0.0'
|
||||
elif col_idx in (1, 2, 5, 6):
|
||||
elif col_idx in (1, 2, 4):
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# --- AVERAGE ROW ---
|
||||
avg_font = Font(bold=True, italic=True, color="334155", size=10)
|
||||
avg_fill = PatternFill(start_color="F8FAFC", end_color="F8FAFC", fill_type="solid")
|
||||
avg_border = Border(
|
||||
top=Side(style="thin", color="E2E8F0"),
|
||||
bottom=Side(style="thin", color="94A3B8"),
|
||||
left=Side(style="thin", color="E2E8F0"),
|
||||
right=Side(style="thin", color="E2E8F0"),
|
||||
)
|
||||
ws.cell(row=avg_row_idx, column=1, value="RATA-RATA")
|
||||
ws.cell(row=avg_row_idx, column=2, value="-")
|
||||
ws.cell(row=avg_row_idx, column=3, value=avg_before)
|
||||
ws.cell(row=avg_row_idx, column=4, value=avg_after)
|
||||
ws.cell(row=avg_row_idx, column=5, value="-")
|
||||
ws.cell(row=avg_row_idx, column=6, value="-")
|
||||
ws.cell(row=avg_row_idx, column=7, value="-")
|
||||
ws.cell(row=avg_row_idx, column=8, value="-")
|
||||
ws.cell(row=avg_row_idx, column=9, value=avg_dur)
|
||||
# AVERAGE ROW Table 1
|
||||
ws.cell(row=cur_row, column=1, value="RATA-RATA")
|
||||
ws.cell(row=cur_row, column=2, value="-")
|
||||
ws.cell(row=cur_row, column=3, value=avg_raw)
|
||||
ws.cell(row=cur_row, column=4, value="-")
|
||||
ws.cell(row=cur_row, column=5, value="-")
|
||||
ws.cell(row=cur_row, column=6, value="-")
|
||||
ws.cell(row=cur_row, column=7, value=avg_raw_dur)
|
||||
|
||||
for col_idx in range(1, 10):
|
||||
c = ws.cell(row=avg_row_idx, column=col_idx)
|
||||
for col_idx in range(1, 8):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = avg_font
|
||||
c.fill = avg_fill
|
||||
c.border = avg_border
|
||||
if col_idx in (3, 4):
|
||||
if col_idx == 3:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 9:
|
||||
elif col_idx == 7:
|
||||
c.number_format = '#,##0.0'
|
||||
else:
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# 2 Empty Rows
|
||||
cur_row += 2
|
||||
|
||||
# ── TABEL 2: BATCH DISESUAIKAN (SETELAH PENYESUAIAN) ──
|
||||
_style_section_banner(ws, "2. BATCH DISESUAIKAN (SETELAH PENYESUAIAN) - HANYA BATCH TETAP", cur_row, 7)
|
||||
cur_row += 1
|
||||
|
||||
t2_headers = [
|
||||
("A", "Batch #"),
|
||||
("B", "Tipe Batch"),
|
||||
("C", "Batch Disesuaikan"),
|
||||
("D", "Catatan"),
|
||||
("E", "Mulai"),
|
||||
("F", "Selesai"),
|
||||
("G", "Durasi (menit)"),
|
||||
]
|
||||
_style_header(ws, t2_headers, cur_row)
|
||||
cur_row += 1
|
||||
|
||||
for row in fixed_rows:
|
||||
ws.cell(row=cur_row, column=1, value=str(row["batch_number"]))
|
||||
ws.cell(row=cur_row, column=2, value=row["batch_type"])
|
||||
ws.cell(row=cur_row, column=3, value=row["count"]).number_format = '#,##0'
|
||||
ws.cell(row=cur_row, column=4, value=row["notes"])
|
||||
ws.cell(row=cur_row, column=5, value=row["start_time"])
|
||||
ws.cell(row=cur_row, column=6, value=row["end_time"])
|
||||
ws.cell(row=cur_row, column=7, value=row["duration_minutes"] or 0).number_format = '#,##0.0'
|
||||
cur_row += 1
|
||||
|
||||
if fixed_rows:
|
||||
total_fixed = sum(r["count"] for r in fixed_rows)
|
||||
total_fixed_dur = round(sum(r.get("duration_minutes") or 0 for r in fixed_rows), 1)
|
||||
fixed_start = fixed_rows[0]["start_time"]
|
||||
fixed_end = fixed_rows[-1]["end_time"]
|
||||
avg_fixed = round(total_fixed / len(fixed_rows), 1)
|
||||
avg_fixed_dur = round(total_fixed_dur / len(fixed_rows), 1)
|
||||
|
||||
# TOTAL ROW Table 2
|
||||
ws.cell(row=cur_row, column=1, value="TOTAL")
|
||||
ws.cell(row=cur_row, column=2, value=f"{len(fixed_rows)} Main Batch")
|
||||
ws.cell(row=cur_row, column=3, value=total_fixed)
|
||||
ws.cell(row=cur_row, column=4, value="Semua batch tetap")
|
||||
ws.cell(row=cur_row, column=5, value=fixed_start)
|
||||
ws.cell(row=cur_row, column=6, value=fixed_end)
|
||||
ws.cell(row=cur_row, column=7, value=total_fixed_dur)
|
||||
|
||||
for col_idx in range(1, 8):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = total_font
|
||||
c.fill = total_fill
|
||||
c.border = total_border
|
||||
if col_idx == 3:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 7:
|
||||
c.number_format = '#,##0.0'
|
||||
elif col_idx in (1, 2, 4):
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
cur_row += 1
|
||||
|
||||
# AVERAGE ROW Table 2
|
||||
ws.cell(row=cur_row, column=1, value="RATA-RATA")
|
||||
ws.cell(row=cur_row, column=2, value="-")
|
||||
ws.cell(row=cur_row, column=3, value=avg_fixed)
|
||||
ws.cell(row=cur_row, column=4, value="-")
|
||||
ws.cell(row=cur_row, column=5, value="-")
|
||||
ws.cell(row=cur_row, column=6, value="-")
|
||||
ws.cell(row=cur_row, column=7, value=avg_fixed_dur)
|
||||
|
||||
for col_idx in range(1, 8):
|
||||
c = ws.cell(row=cur_row, column=col_idx)
|
||||
c.font = avg_font
|
||||
c.fill = avg_fill
|
||||
c.border = avg_border
|
||||
if col_idx == 3:
|
||||
c.number_format = '#,##0'
|
||||
elif col_idx == 7:
|
||||
c.number_format = '#,##0.0'
|
||||
else:
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
|
||||
@@ -524,6 +524,44 @@
|
||||
.status-badge.info {
|
||||
background: var(--blue-bg); border-color: var(--blue); color: var(--blue-btn);
|
||||
}
|
||||
.total-type-badge {
|
||||
white-space: normal !important;
|
||||
word-break: break-word;
|
||||
line-height: 1.25;
|
||||
display: inline-block;
|
||||
padding: 3px 6px;
|
||||
text-align: center;
|
||||
}
|
||||
.tbtn.tbtn-active {
|
||||
background: rgba(56, 189, 248, 0.15) !important;
|
||||
border-color: #38bdf8 !important;
|
||||
color: #38bdf8 !important;
|
||||
font-weight: 700;
|
||||
}
|
||||
.active-date-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 10px;
|
||||
border-radius: 999px;
|
||||
background: rgba(56, 189, 248, 0.12);
|
||||
border: 1px solid rgba(56, 189, 248, 0.3);
|
||||
color: #38bdf8;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.chip-clear-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: inherit;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
padding: 0 2px;
|
||||
}
|
||||
.chip-clear-btn:hover {
|
||||
color: #ef4444;
|
||||
}
|
||||
.link-detail {
|
||||
color: var(--text); font-size: 11px; font-weight: 600; cursor: pointer;
|
||||
min-height: var(--touch-min); display: inline-flex; align-items: center;
|
||||
@@ -609,10 +647,8 @@
|
||||
.ms-val { font-family: var(--mono); font-size: clamp(1rem, 0.8rem + 1vw, 1.375rem); font-weight: 700; }
|
||||
.ms-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; }
|
||||
.modal-body {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.55fr) minmax(220px, 1fr);
|
||||
gap: 16px;
|
||||
align-items: start;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.modal-table-wrap {
|
||||
width: 100%;
|
||||
@@ -640,13 +676,13 @@
|
||||
letter-spacing: 0.02em;
|
||||
background: rgba(0,0,0,0.18);
|
||||
}
|
||||
.modal-table th:nth-child(1), .modal-table td:nth-child(1) { width: 13%; }
|
||||
.modal-table th:nth-child(2), .modal-table td:nth-child(2) { width: 13%; }
|
||||
.modal-table th:nth-child(3), .modal-table td:nth-child(3) { width: 14%; }
|
||||
.modal-table th:nth-child(1), .modal-table td:nth-child(1) { width: 12%; }
|
||||
.modal-table th:nth-child(2), .modal-table td:nth-child(2) { width: 18%; }
|
||||
.modal-table th:nth-child(3), .modal-table td:nth-child(3) { width: 15%; }
|
||||
.modal-table th:nth-child(4), .modal-table td:nth-child(4),
|
||||
.modal-table th:nth-child(5), .modal-table td:nth-child(5) { width: 16%; }
|
||||
.modal-table th:nth-child(6), .modal-table td:nth-child(6) { width: 14%; }
|
||||
.modal-table th:nth-child(7), .modal-table td:nth-child(7) { width: 14%; }
|
||||
.modal-table th:nth-child(5), .modal-table td:nth-child(5) { width: 15%; }
|
||||
.modal-table th:nth-child(6), .modal-table td:nth-child(6) { width: 13%; }
|
||||
.modal-table th:nth-child(7), .modal-table td:nth-child(7) { width: 12%; }
|
||||
.modal-table .mono { font-family: var(--mono); font-weight: 600; }
|
||||
.modal-aside {
|
||||
border: 1px solid var(--border);
|
||||
@@ -921,9 +957,13 @@
|
||||
<rect x="2" y="2.5" width="12" height="11.5" rx="2" stroke="currentColor" stroke-width="1"/>
|
||||
<path d="M2 6h12M5.5 1.5v2M10.5 1.5v2" stroke="currentColor" stroke-width="1"/>
|
||||
</svg>
|
||||
<span>Pilih Tanggal</span>
|
||||
<span id="btn-pick-date-label">Pilih Tanggal</span>
|
||||
</button>
|
||||
<input type="date" id="date-filter" class="date-filter-input" tabindex="-1" aria-hidden="true">
|
||||
<div id="active-date-chip" class="active-date-chip" style="display: none;">
|
||||
<span id="active-date-chip-text"></span>
|
||||
<button type="button" class="chip-clear-btn" onclick="resetFilter()" title="Hapus filter tanggal">×</button>
|
||||
</div>
|
||||
<button class="tbtn tbtn-primary" type="button" onclick="filterByDate()">
|
||||
Filter
|
||||
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||
@@ -996,12 +1036,6 @@
|
||||
<tbody id="modal-table-body"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<aside class="modal-aside">
|
||||
<div class="modal-aside-title">Distribusi per batch</div>
|
||||
<div class="modal-share-list" id="modal-share-list">
|
||||
<div class="modal-empty">Tidak ada data batch</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1326,6 +1360,26 @@ async function loadAllDates() {
|
||||
renderDailyTable();
|
||||
}
|
||||
|
||||
function updateDateSelectionDisplay(dateStr) {
|
||||
const btnLabel = document.getElementById('btn-pick-date-label');
|
||||
const pickBtn = document.getElementById('btn-pick-date');
|
||||
const chip = document.getElementById('active-date-chip');
|
||||
const chipText = document.getElementById('active-date-chip-text');
|
||||
if (!dateStr) {
|
||||
if (btnLabel) btnLabel.textContent = 'Pilih Tanggal';
|
||||
if (pickBtn) pickBtn.classList.remove('tbtn-active');
|
||||
if (chip) chip.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
const formatted = formatDateID(dateStr);
|
||||
if (btnLabel) btnLabel.textContent = formatted;
|
||||
if (pickBtn) pickBtn.classList.add('tbtn-active');
|
||||
if (chip && chipText) {
|
||||
chipText.textContent = `📅 ${formatted}`;
|
||||
chip.style.display = 'inline-flex';
|
||||
}
|
||||
}
|
||||
|
||||
function openDatePicker() {
|
||||
const el = document.getElementById('date-filter');
|
||||
if (!el) return;
|
||||
@@ -1338,14 +1392,30 @@ function openDatePicker() {
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const dateInput = document.getElementById('date-filter');
|
||||
if (dateInput) {
|
||||
dateInput.addEventListener('change', function() {
|
||||
if (this.value) {
|
||||
filterByDate();
|
||||
} else {
|
||||
resetFilter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function resetFilter() {
|
||||
document.getElementById('date-filter').value = '';
|
||||
const el = document.getElementById('date-filter');
|
||||
if (el) el.value = '';
|
||||
updateDateSelectionDisplay(null);
|
||||
loadAllDates();
|
||||
}
|
||||
|
||||
function filterByDate() {
|
||||
const val = document.getElementById('date-filter').value;
|
||||
if (!val) { resetFilter(); return; }
|
||||
updateDateSelectionDisplay(val);
|
||||
fetch('/api/available-dates').then(r => r.json()).then(dates => {
|
||||
allDailyDates = dates.filter(d => d.date === val);
|
||||
dailyPage = 1;
|
||||
@@ -1501,7 +1571,7 @@ async function showDayDetail(date) {
|
||||
tableHtml += `
|
||||
<tr style="background: rgba(22,130,178,0.12); font-weight: 700; border-top: 2px solid var(--border-accent);">
|
||||
<td class="mono" style="font-weight:700;">TOTAL</td>
|
||||
<td><span class="status-badge info" style="font-size: 10px; padding: 2px 6px;">${mainCount} Main, ${subCount} Sub</span></td>
|
||||
<td><span class="status-badge info total-type-badge">${mainCount} Main, ${subCount} Sub</span></td>
|
||||
<td class="mono" style="font-weight:700; color: #38bdf8;">${total.toLocaleString('id-ID')}</td>
|
||||
<td style="font-size:10px; color:var(--text-muted);">${batches[0] ? formatTime(batches[0].start_time) : '--'}</td>
|
||||
<td style="font-size:10px; color:var(--text-muted);">${batches[batches.length - 1] ? formatTime(batches[batches.length - 1].end_time) : '--'}</td>
|
||||
@@ -1513,19 +1583,8 @@ async function showDayDetail(date) {
|
||||
}
|
||||
document.getElementById('modal-table-body').innerHTML = tableHtml;
|
||||
|
||||
document.getElementById('modal-share-list').innerHTML = batches.length
|
||||
? batches.map(b => {
|
||||
const pct = total > 0 ? (b.count / total) * 100 : 0;
|
||||
return `
|
||||
<div class="modal-share-row">
|
||||
<div class="modal-share-meta">
|
||||
<span class="label">Batch #${b.batch_number}${b.is_child ? ' (Sub)' : ''}</span>
|
||||
<span class="pct">${b.count.toLocaleString('id-ID')} · ${pct.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div class="modal-share-bar"><div class="modal-share-fill" style="width:${pct.toFixed(1)}%"></div></div>
|
||||
</div>`;
|
||||
}).join('')
|
||||
: `<div class="modal-empty">Tidak ada data batch</div>`;
|
||||
const shareList = document.getElementById('modal-share-list');
|
||||
if (shareList) shareList.innerHTML = '';
|
||||
|
||||
document.getElementById('detail-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
@@ -863,27 +863,69 @@
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.acc-day + .acc-day {
|
||||
margin-top: 20px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
html[data-theme="light"] .acc-day + .acc-day {
|
||||
border-top-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.acc-day-head {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
min-height: 36px;
|
||||
padding: 6px 4px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-muted);
|
||||
min-height: 40px;
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 10px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.09);
|
||||
border-radius: 6px;
|
||||
color: #F1F5F9;
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-align: left;
|
||||
text-transform: uppercase;
|
||||
transition: background 0.15s ease, border-color 0.15s ease;
|
||||
}
|
||||
|
||||
.acc-day-head:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-color: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
html[data-theme="light"] .acc-day-head {
|
||||
background: #F1F5F9;
|
||||
border-color: #E2E8F0;
|
||||
color: #0F172A;
|
||||
}
|
||||
|
||||
html[data-theme="light"] .acc-day-head:hover {
|
||||
background: #E2E8F0;
|
||||
}
|
||||
|
||||
.acc-day-head .count-pill {
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
font-size: 10.5px;
|
||||
font-weight: 700;
|
||||
color: #38bdf8;
|
||||
background: rgba(56, 189, 248, 0.14);
|
||||
border: 1px solid rgba(56, 189, 248, 0.3);
|
||||
border-radius: 999px;
|
||||
padding: 3px 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.partial-card .acc-day-head .count-pill {
|
||||
color: #fbbf24;
|
||||
background: rgba(245, 158, 11, 0.14);
|
||||
border-color: rgba(245, 158, 11, 0.3);
|
||||
}
|
||||
|
||||
.acc-day-body {
|
||||
|
||||
Reference in new issue
Block a user