feat: лимитированные в Excel, НДС 20%, КС-2/КС-3, update-fgis, +11 расценок
Excel-футер: - Лимитированные затраты (врем. здания, зимнее, резерв) - НДС 20% - ВСЕГО с НДС Новые CLI-команды: - smeta ks2 — генерация КС-2 (Акт о приёмке выполненных работ) - smeta ks3 — генерация КС-3 (Справка о стоимости работ) - smeta update-fgis — пересборка pickle-кеша ФГИС ЦС Доп. ресурсы: +11 норм с cs.smetnoedelo.ru (итого 41) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+1045
File diff suppressed because it is too large
Load Diff
@@ -105,6 +105,34 @@ def fetch_resources(
|
||||
do_fetch(output_path, force=force)
|
||||
|
||||
|
||||
@app.command()
|
||||
def update_fgis(
|
||||
project_yaml: Path = typer.Argument(..., help="Path to project YAML config"),
|
||||
):
|
||||
"""Rebuild FGIS pickle cache from xlsx (faster subsequent loads)."""
|
||||
from smeta_railway.config import ProjectConfig
|
||||
from smeta_railway.data.fgis import load_fgis
|
||||
|
||||
config = ProjectConfig.from_yaml(project_yaml)
|
||||
project_dir = project_yaml.parent
|
||||
fgis_xlsx = _resolve_path(config.fgis.xlsx_path, project_dir)
|
||||
fgis_cache = _resolve_path(config.fgis.cache_path, project_dir)
|
||||
|
||||
if not fgis_xlsx.exists():
|
||||
typer.echo(f"Error: {fgis_xlsx} not found", err=True)
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Force rebuild by removing old cache
|
||||
if fgis_cache.exists():
|
||||
fgis_cache.unlink()
|
||||
typer.echo(f"Old cache removed: {fgis_cache}")
|
||||
|
||||
fgis = load_fgis(str(fgis_xlsx), str(fgis_cache))
|
||||
typer.echo(f"Cache rebuilt: {fgis_cache}")
|
||||
typer.echo(f" {len(fgis.index_map)} indices, "
|
||||
f"{len(fgis.current_price_map)} current prices")
|
||||
|
||||
|
||||
@app.command()
|
||||
def validate(
|
||||
project_yaml: Path = typer.Argument(..., help="Path to project YAML config"),
|
||||
@@ -131,6 +159,79 @@ def validate(
|
||||
typer.echo(f"Coefficients: {len(config.coefficients.definitions)}")
|
||||
|
||||
|
||||
@app.command()
|
||||
def ks2(
|
||||
project_yaml: Path = typer.Argument(..., help="Path to project YAML config"),
|
||||
output: str | None = typer.Option(None, "--output", "-o"),
|
||||
number: str = typer.Option("1", "--number", "-n"),
|
||||
date: str = typer.Option("", "--date"),
|
||||
period_from: str = typer.Option("", "--from"),
|
||||
period_to: str = typer.Option("", "--to"),
|
||||
):
|
||||
"""Generate КС-2 (Акт о приёмке выполненных работ)."""
|
||||
from smeta_railway.calc.estimate import EstimateCalculator
|
||||
from smeta_railway.config import ProjectConfig
|
||||
from smeta_railway.data.fgis import load_fgis
|
||||
from smeta_railway.data.gesn import load_resources
|
||||
from smeta_railway.output.ks_forms import generate_ks2
|
||||
|
||||
config = ProjectConfig.from_yaml(project_yaml)
|
||||
project_dir = project_yaml.parent
|
||||
fgis = load_fgis(
|
||||
str(_resolve_path(config.fgis.xlsx_path, project_dir)),
|
||||
str(_resolve_path(config.fgis.cache_path, project_dir)),
|
||||
)
|
||||
resources = load_resources(_resolve_path(config.resources_json, project_dir))
|
||||
calculator = EstimateCalculator(
|
||||
fgis=fgis, resources=resources,
|
||||
coeff_config=config.coefficients,
|
||||
overhead_config=config.overhead,
|
||||
limited_costs_config=config.limited_costs,
|
||||
)
|
||||
estimate = calculator.calculate(config.sections)
|
||||
out = output or "ks2.xlsx"
|
||||
out = str(_resolve_path(out, project_dir))
|
||||
generate_ks2(config, estimate, out, number, date, period_from, period_to)
|
||||
typer.echo(f"КС-2 saved: {out}")
|
||||
|
||||
|
||||
@app.command()
|
||||
def ks3(
|
||||
project_yaml: Path = typer.Argument(..., help="Path to project YAML config"),
|
||||
output: str | None = typer.Option(None, "--output", "-o"),
|
||||
number: str = typer.Option("1", "--number", "-n"),
|
||||
date: str = typer.Option("", "--date"),
|
||||
period_from: str = typer.Option("", "--from"),
|
||||
period_to: str = typer.Option("", "--to"),
|
||||
prev_total: float = typer.Option(0.0, "--prev-total"),
|
||||
):
|
||||
"""Generate КС-3 (Справка о стоимости выполненных работ)."""
|
||||
from smeta_railway.calc.estimate import EstimateCalculator
|
||||
from smeta_railway.config import ProjectConfig
|
||||
from smeta_railway.data.fgis import load_fgis
|
||||
from smeta_railway.data.gesn import load_resources
|
||||
from smeta_railway.output.ks_forms import generate_ks3
|
||||
|
||||
config = ProjectConfig.from_yaml(project_yaml)
|
||||
project_dir = project_yaml.parent
|
||||
fgis = load_fgis(
|
||||
str(_resolve_path(config.fgis.xlsx_path, project_dir)),
|
||||
str(_resolve_path(config.fgis.cache_path, project_dir)),
|
||||
)
|
||||
resources = load_resources(_resolve_path(config.resources_json, project_dir))
|
||||
calculator = EstimateCalculator(
|
||||
fgis=fgis, resources=resources,
|
||||
coeff_config=config.coefficients,
|
||||
overhead_config=config.overhead,
|
||||
limited_costs_config=config.limited_costs,
|
||||
)
|
||||
estimate = calculator.calculate(config.sections)
|
||||
out = output or "ks3.xlsx"
|
||||
out = str(_resolve_path(out, project_dir))
|
||||
generate_ks3(config, estimate, out, number, date, period_from, period_to, prev_total)
|
||||
typer.echo(f"КС-3 saved: {out}")
|
||||
|
||||
|
||||
def _resolve_path(path_str: str, base_dir: Path) -> Path:
|
||||
"""Resolve path relative to base_dir if not absolute."""
|
||||
p = Path(path_str)
|
||||
|
||||
@@ -742,7 +742,51 @@ def generate_excel(
|
||||
font=f, bold_27=bold)
|
||||
r += 1
|
||||
|
||||
# ========== ЛИМИТИРОВАННЫЕ ЗАТРАТЫ ==========
|
||||
r += 1
|
||||
write_data_row(ws, r, col8="ЛИМИТИРОВАННЫЕ ЗАТРАТЫ",
|
||||
font=FONT_BOLD, bold_27=True)
|
||||
r += 1
|
||||
|
||||
write_data_row(ws, r,
|
||||
col8=f"Временные здания и сооружения "
|
||||
f"(ГСН 81-05-01-2001, {grand.temp_buildings_pct}% от СМР)",
|
||||
col27=grand.temp_buildings, font=FONT)
|
||||
r += 1
|
||||
|
||||
write_data_row(ws, r,
|
||||
col8=f"Удорожание работ в зимнее время "
|
||||
f"(ГСН 81-05-02-2007, зона {config.limited_costs.winter_zone}, "
|
||||
f"{grand.winter_cost_pct}% от СМР)",
|
||||
col27=grand.winter_cost, font=FONT)
|
||||
r += 1
|
||||
|
||||
write_data_row(ws, r,
|
||||
col8=f"Резерв средств на непредвиденные работы и затраты "
|
||||
f"({grand.contingency_pct}%)",
|
||||
col27=grand.contingency, font=FONT)
|
||||
r += 1
|
||||
|
||||
r += 1
|
||||
write_data_row(ws, r, col8="ИТОГО с лимитированными затратами",
|
||||
col27=grand.grand_total_with_limits,
|
||||
font=FONT_BOLD, bold_27=True)
|
||||
r += 1
|
||||
|
||||
# НДС 20%
|
||||
nds = round(grand.grand_total_with_limits * 0.20, 2)
|
||||
write_data_row(ws, r, col8="НДС 20%", col27=nds, font=FONT)
|
||||
r += 1
|
||||
|
||||
# ВСЕГО с НДС
|
||||
vsego_with_nds = round(grand.grand_total_with_limits + nds, 2)
|
||||
write_data_row(ws, r, col8="ВСЕГО с НДС",
|
||||
col27=vsego_with_nds,
|
||||
font=FONT_BOLD, bold_27=True)
|
||||
r += 1
|
||||
|
||||
# Spravochno
|
||||
r += 1
|
||||
write_data_row(ws, r, col8="Справочно", font=FONT)
|
||||
r += 1
|
||||
write_data_row(ws, r, col8=" материальные ресурсы, отсутствующие в ФРСН ",
|
||||
@@ -759,6 +803,7 @@ def generate_excel(
|
||||
r += 1
|
||||
|
||||
# ========== Fill summary header cells ==========
|
||||
total_with_limits_thousands = round(grand.grand_total_with_limits / 1000, 2)
|
||||
total_thousands = round(grand.grand_total / 1000, 2)
|
||||
ws.cell(total_cost_cell_row, 6).value = f"{total_thousands:.2f}"
|
||||
ws.cell(total_cost_cell_row, 6).font = FONT
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
"""
|
||||
КС-2 and КС-3 forms generator.
|
||||
|
||||
КС-2 (form ОКУД 0322005): Акт о приёмке выполненных работ
|
||||
КС-3 (form ОКУД 0322001): Справка о стоимости выполненных работ и затрат
|
||||
|
||||
Based on Постановление Госкомстата РФ от 11.11.1999 №100.
|
||||
"""
|
||||
|
||||
import openpyxl
|
||||
from openpyxl.styles import Alignment, Border, Font, Side
|
||||
from openpyxl.worksheet.properties import PageSetupProperties
|
||||
|
||||
from smeta_railway.config import ProjectConfig, Section
|
||||
from smeta_railway.models import EstimateResult
|
||||
|
||||
FONT = Font(name="Times New Roman", size=10)
|
||||
FONT_BOLD = Font(name="Times New Roman", size=10, bold=True)
|
||||
FONT_SMALL = Font(name="Times New Roman", size=8)
|
||||
THIN = Side(style="thin")
|
||||
BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
||||
ALIGN_C = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
||||
ALIGN_L = Alignment(horizontal="left", vertical="top", wrap_text=True)
|
||||
ALIGN_R = Alignment(horizontal="right", vertical="top")
|
||||
|
||||
|
||||
def _cell(ws, row, col, value, font=FONT, align=None, border=True):
|
||||
c = ws.cell(row=row, column=col, value=value)
|
||||
c.font = font
|
||||
if align:
|
||||
c.alignment = align
|
||||
if border:
|
||||
c.border = BORDER
|
||||
return c
|
||||
|
||||
|
||||
def generate_ks2(
|
||||
config: ProjectConfig,
|
||||
estimate: EstimateResult,
|
||||
output_path: str,
|
||||
report_number: str = "1",
|
||||
report_date: str = "",
|
||||
period_from: str = "",
|
||||
period_to: str = "",
|
||||
) -> str:
|
||||
"""Generate КС-2 (Акт о приёмке выполненных работ)."""
|
||||
wb = openpyxl.Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "КС-2"
|
||||
|
||||
ws.column_dimensions["A"].width = 6
|
||||
ws.column_dimensions["B"].width = 20
|
||||
ws.column_dimensions["C"].width = 45
|
||||
ws.column_dimensions["D"].width = 10
|
||||
ws.column_dimensions["E"].width = 14
|
||||
ws.column_dimensions["F"].width = 16
|
||||
ws.column_dimensions["G"].width = 18
|
||||
|
||||
r = 1
|
||||
# Header
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, "Унифицированная форма №КС-2", FONT_SMALL, ALIGN_R, False)
|
||||
r += 1
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, "Утверждена постановлением Госкомстата РФ от 11.11.1999 №100",
|
||||
FONT_SMALL, ALIGN_R, False)
|
||||
r += 2
|
||||
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, "АКТ", FONT_BOLD, ALIGN_C, False)
|
||||
r += 1
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, "О ПРИЁМКЕ ВЫПОЛНЕННЫХ РАБОТ", FONT_BOLD, ALIGN_C, False)
|
||||
r += 2
|
||||
|
||||
# Meta info
|
||||
for label, value in [
|
||||
("Номер документа:", report_number),
|
||||
("Дата составления:", report_date),
|
||||
("Отчётный период с:", f"{period_from} по {period_to}"),
|
||||
("Объект:", config.project.object_name),
|
||||
("Смета №:", config.project.number),
|
||||
]:
|
||||
_cell(ws, r, 1, label, FONT_BOLD, ALIGN_L, False)
|
||||
ws.merge_cells(f"B{r}:G{r}")
|
||||
_cell(ws, r, 2, value, FONT, ALIGN_L, False)
|
||||
r += 1
|
||||
|
||||
r += 1
|
||||
|
||||
# Table header
|
||||
headers = ["№ п/п", "Обоснование", "Наименование работ",
|
||||
"Ед. изм.", "Кол-во", "Цена, руб.", "Стоимость, руб."]
|
||||
for i, h in enumerate(headers, 1):
|
||||
_cell(ws, r, i, h, FONT_BOLD, ALIGN_C)
|
||||
r += 1
|
||||
|
||||
# Data rows — from estimate positions
|
||||
item_num = 0
|
||||
total_cost = 0.0
|
||||
|
||||
for section in config.sections:
|
||||
# Section header
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, section.name, FONT_BOLD, ALIGN_L)
|
||||
r += 1
|
||||
|
||||
for subsection in section.subsections:
|
||||
if subsection.name:
|
||||
ws.merge_cells(f"A{r}:G{r}")
|
||||
_cell(ws, r, 1, subsection.name, Font(name="Times New Roman", size=10, italic=True), ALIGN_L)
|
||||
r += 1
|
||||
|
||||
for item in subsection.items:
|
||||
if item.code == "Материал":
|
||||
continue # skip material info lines in KS-2
|
||||
|
||||
item_num += 1
|
||||
# Find matching position in estimate
|
||||
pos = None
|
||||
for p in estimate.positions:
|
||||
if p.gesn_code == item.code and p.qty == item.qty and p.name == item.name:
|
||||
pos = p
|
||||
break
|
||||
|
||||
cost = pos.total if pos else 0.0
|
||||
price = round(cost / item.qty, 2) if item.qty else 0.0
|
||||
total_cost += cost
|
||||
|
||||
_cell(ws, r, 1, item_num, FONT, ALIGN_C)
|
||||
_cell(ws, r, 2, item.code, FONT_SMALL, ALIGN_L)
|
||||
_cell(ws, r, 3, item.name, FONT, ALIGN_L)
|
||||
_cell(ws, r, 4, item.unit, FONT, ALIGN_C)
|
||||
_cell(ws, r, 5, item.qty, FONT, ALIGN_R)
|
||||
ws.cell(r, 5).number_format = "#,##0.000"
|
||||
_cell(ws, r, 6, price, FONT, ALIGN_R)
|
||||
ws.cell(r, 6).number_format = "#,##0.00"
|
||||
_cell(ws, r, 7, cost, FONT, ALIGN_R)
|
||||
ws.cell(r, 7).number_format = "#,##0.00"
|
||||
r += 1
|
||||
|
||||
# Totals
|
||||
r += 1
|
||||
ws.merge_cells(f"A{r}:F{r}")
|
||||
_cell(ws, r, 1, "ИТОГО по акту", FONT_BOLD, ALIGN_R)
|
||||
_cell(ws, r, 7, total_cost, FONT_BOLD, ALIGN_R)
|
||||
ws.cell(r, 7).number_format = "#,##0.00"
|
||||
r += 2
|
||||
|
||||
# Signatures
|
||||
for role in ["Сдал:", "Принял:"]:
|
||||
_cell(ws, r, 1, role, FONT_BOLD, ALIGN_L, False)
|
||||
ws.merge_cells(f"C{r}:D{r}")
|
||||
_cell(ws, r, 3, "_______________", FONT, ALIGN_C, False)
|
||||
ws.merge_cells(f"E{r}:G{r}")
|
||||
_cell(ws, r, 5, "_______________", FONT, ALIGN_C, False)
|
||||
r += 1
|
||||
|
||||
ws.sheet_properties.pageSetUpPr = PageSetupProperties(fitToPage=True)
|
||||
ws.page_setup.orientation = "landscape"
|
||||
ws.page_setup.fitToWidth = 1
|
||||
ws.page_setup.fitToHeight = 0
|
||||
|
||||
wb.save(output_path)
|
||||
return output_path
|
||||
|
||||
|
||||
def generate_ks3(
|
||||
config: ProjectConfig,
|
||||
estimate: EstimateResult,
|
||||
output_path: str,
|
||||
report_number: str = "1",
|
||||
report_date: str = "",
|
||||
period_from: str = "",
|
||||
period_to: str = "",
|
||||
prev_periods_total: float = 0.0,
|
||||
) -> str:
|
||||
"""Generate КС-3 (Справка о стоимости выполненных работ и затрат)."""
|
||||
wb = openpyxl.Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "КС-3"
|
||||
|
||||
ws.column_dimensions["A"].width = 6
|
||||
ws.column_dimensions["B"].width = 40
|
||||
ws.column_dimensions["C"].width = 20
|
||||
ws.column_dimensions["D"].width = 20
|
||||
ws.column_dimensions["E"].width = 20
|
||||
ws.column_dimensions["F"].width = 20
|
||||
|
||||
r = 1
|
||||
ws.merge_cells(f"A{r}:F{r}")
|
||||
_cell(ws, r, 1, "Унифицированная форма №КС-3", FONT_SMALL, ALIGN_R, False)
|
||||
r += 1
|
||||
ws.merge_cells(f"A{r}:F{r}")
|
||||
_cell(ws, r, 1, "Утверждена постановлением Госкомстата РФ от 11.11.1999 №100",
|
||||
FONT_SMALL, ALIGN_R, False)
|
||||
r += 2
|
||||
|
||||
ws.merge_cells(f"A{r}:F{r}")
|
||||
_cell(ws, r, 1, "СПРАВКА", FONT_BOLD, ALIGN_C, False)
|
||||
r += 1
|
||||
ws.merge_cells(f"A{r}:F{r}")
|
||||
_cell(ws, r, 1, "О СТОИМОСТИ ВЫПОЛНЕННЫХ РАБОТ И ЗАТРАТ",
|
||||
FONT_BOLD, ALIGN_C, False)
|
||||
r += 2
|
||||
|
||||
for label, value in [
|
||||
("Номер:", report_number),
|
||||
("Дата:", report_date),
|
||||
("Отчётный период:", f"{period_from} — {period_to}"),
|
||||
("Объект:", config.project.object_name),
|
||||
("Договор подряда:", ""),
|
||||
]:
|
||||
_cell(ws, r, 1, label, FONT_BOLD, ALIGN_L, False)
|
||||
ws.merge_cells(f"B{r}:F{r}")
|
||||
_cell(ws, r, 2, value, FONT, ALIGN_L, False)
|
||||
r += 1
|
||||
|
||||
r += 1
|
||||
|
||||
# Table header
|
||||
headers = [
|
||||
"№\nп/п",
|
||||
"Наименование пусковых комплексов,\nэтапов, объектов, видов работ",
|
||||
"Стоимость выполненных\nработ и затрат\nс начала строительства,\nруб.",
|
||||
"Стоимость выполненных\nработ и затрат\nза предыдущие периоды,\nруб.",
|
||||
"Стоимость выполненных\nработ и затрат\nв отчётном периоде,\nруб.",
|
||||
"в том числе\nНДС 20%,\nруб.",
|
||||
]
|
||||
for i, h in enumerate(headers, 1):
|
||||
_cell(ws, r, i, h, FONT_BOLD, ALIGN_C)
|
||||
r += 1
|
||||
|
||||
# Column numbers
|
||||
for i in range(1, 7):
|
||||
_cell(ws, r, i, str(i), FONT, ALIGN_C)
|
||||
r += 1
|
||||
|
||||
# Data row: СМР
|
||||
current_period = estimate.grand_total_with_limits
|
||||
from_start = prev_periods_total + current_period
|
||||
nds = round(current_period * 0.20, 2)
|
||||
|
||||
_cell(ws, r, 1, "1", FONT, ALIGN_C)
|
||||
_cell(ws, r, 2, "Строительно-монтажные работы", FONT, ALIGN_L)
|
||||
_cell(ws, r, 3, from_start, FONT, ALIGN_R)
|
||||
ws.cell(r, 3).number_format = "#,##0.00"
|
||||
_cell(ws, r, 4, prev_periods_total, FONT, ALIGN_R)
|
||||
ws.cell(r, 4).number_format = "#,##0.00"
|
||||
_cell(ws, r, 5, current_period, FONT, ALIGN_R)
|
||||
ws.cell(r, 5).number_format = "#,##0.00"
|
||||
_cell(ws, r, 6, nds, FONT, ALIGN_R)
|
||||
ws.cell(r, 6).number_format = "#,##0.00"
|
||||
r += 1
|
||||
|
||||
# Total
|
||||
r += 1
|
||||
_cell(ws, r, 1, "", FONT, ALIGN_C)
|
||||
_cell(ws, r, 2, "ИТОГО", FONT_BOLD, ALIGN_R)
|
||||
_cell(ws, r, 3, from_start, FONT_BOLD, ALIGN_R)
|
||||
ws.cell(r, 3).number_format = "#,##0.00"
|
||||
_cell(ws, r, 4, prev_periods_total, FONT_BOLD, ALIGN_R)
|
||||
ws.cell(r, 4).number_format = "#,##0.00"
|
||||
_cell(ws, r, 5, current_period, FONT_BOLD, ALIGN_R)
|
||||
ws.cell(r, 5).number_format = "#,##0.00"
|
||||
_cell(ws, r, 6, nds, FONT_BOLD, ALIGN_R)
|
||||
ws.cell(r, 6).number_format = "#,##0.00"
|
||||
r += 2
|
||||
|
||||
# Signatures
|
||||
for role in ["Заказчик:", "Подрядчик:"]:
|
||||
_cell(ws, r, 1, role, FONT_BOLD, ALIGN_L, False)
|
||||
ws.merge_cells(f"C{r}:D{r}")
|
||||
_cell(ws, r, 3, "_______________", FONT, ALIGN_C, False)
|
||||
ws.merge_cells(f"E{r}:F{r}")
|
||||
_cell(ws, r, 5, "_______________", FONT, ALIGN_C, False)
|
||||
r += 1
|
||||
|
||||
ws.sheet_properties.pageSetUpPr = PageSetupProperties(fitToPage=True)
|
||||
ws.page_setup.orientation = "landscape"
|
||||
ws.page_setup.fitToWidth = 1
|
||||
ws.page_setup.fitToHeight = 0
|
||||
|
||||
wb.save(output_path)
|
||||
return output_path
|
||||
Reference in New Issue
Block a user