feat: add KS-3/payments, tech debt fixes, UI polish, and KS-2 Excel/Word export

Tasks 008-016: KS-6a journal, KS-3 documents, payments with allocations,
tech debt cleanup, financial privacy, document tree, storno mechanism,
row-click UI, BOQ collapse/sticky header, and KS-2 export to Excel/Word
via shared DTO architecture.
This commit is contained in:
Арсентьев Александр
2026-09-27 13:38:45 +03:00
parent 6c608a8779
commit 9cfb341774
57 changed files with 7163 additions and 50 deletions
+104
View File
@@ -0,0 +1,104 @@
from datetime import date
from decimal import Decimal
from pathlib import Path
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session, joinedload
from app.database.database import get_db
from app.models.boq import System, WorkItem
from app.models.daily_report import DailyReport, DailyReportItem
from app.models.project import Project
def _quantity2(value):
try:
return f"{Decimal(str(value if value is not None else 0)):.2f}"
except Exception:
return "0.00"
router = APIRouter()
templates = Jinja2Templates(directory=Path(__file__).resolve().parents[1] / "templates")
templates.env.filters["quantity2"] = _quantity2
def _project(db, project_id):
obj = db.query(Project).filter(Project.id == project_id).first()
if obj is None:
raise HTTPException(status_code=404, detail="Проект не найден")
return obj
@router.get("/{project_id}/ks6a")
async def ks6a_journal(
request: Request,
project_id: int,
date_from: str = "",
date_to: str = "",
system_id: str = "",
db: Session = Depends(get_db),
):
project = _project(db, project_id)
systems = db.query(System).filter(
System.project_id == project_id
).order_by(System.sort_order, System.id).all()
rows = []
total_count = 0
parsed_from = None
parsed_to = None
error = None
if date_from and date_to:
try:
parsed_from = date.fromisoformat(date_from)
parsed_to = date.fromisoformat(date_to)
except ValueError:
error = "Неверный формат даты"
else:
if parsed_to < parsed_from:
error = "Дата окончания не может быть раньше даты начала"
if parsed_from and parsed_to and not error:
query = db.query(DailyReportItem).join(
DailyReport, DailyReport.id == DailyReportItem.daily_report_id
).join(
WorkItem, WorkItem.id == DailyReportItem.work_item_id
).options(
joinedload(DailyReportItem.work_item),
joinedload(DailyReportItem.report),
).filter(
DailyReport.project_id == project_id,
DailyReport.report_date >= parsed_from,
DailyReport.report_date <= parsed_to,
)
if system_id and system_id != "all":
try:
sid = int(system_id)
except (ValueError, TypeError):
error = "Некорректный идентификатор системы"
else:
query = query.filter(WorkItem.system_id == sid)
if not error:
rows = query.order_by(
DailyReport.report_date,
DailyReport.id,
DailyReportItem.id,
).all()
total_count = len(rows)
return templates.TemplateResponse(name="ks6a/journal.html", context={
"request": request,
"project": project,
"systems": systems,
"rows": rows,
"total_count": total_count,
"date_from": date_from,
"date_to": date_to,
"system_id": system_id,
"error": error,
})