feat: add KS-2 UI, reporting period, and table layout fixes

- 004: KS-2 UI (list, create, edit, view, issue) with integration tests
- 005: navigation buttons, financial column alignment, button layout
- 006: reporting_period_from/to fields with migration, validation, display
- 007: fixed table layout with colgroup, quantity2 filter, stable column widths
This commit is contained in:
Арсентьев Александр
2026-09-26 21:36:43 +03:00
parent 1f5eed2064
commit 6c608a8779
20 changed files with 1407 additions and 96 deletions
+95 -32
View File
@@ -1,12 +1,16 @@
{% extends "base.html" %}
{% block title %}Создание КС-2{% endblock %}
{% block title %}{{ 'Редактирование' if document else 'Создание' }} КС-2{% endblock %}
{% block content %}
<div class="container mt-4">
<nav class="mb-3">
<a href="/projects/{{ project.id }}" class="btn btn-outline-secondary btn-sm">&larr; К проекту</a>
</nav>
<div class="row">
<div class="col-12">
<h2>Создание КС-2</h2>
<h2>{{ 'Редактирование КС-2' if document else 'Создание КС-2' }}</h2>
{% if error %}
<div class="alert alert-danger" role="alert">
@@ -14,85 +18,144 @@
</div>
{% endif %}
<form method="post" action="/projects/{{ project.id }}/ks2">
<form method="post" action="/projects/{{ project.id }}/ks2{% if document %}/{{ document.id }}/edit{% endif %}">
<div class="row mb-3">
<div class="col-md-6">
<div class="col-md-3">
<label for="number" class="form-label">Номер КС-2</label>
<input type="text" class="form-control" id="number" name="number" required>
<input type="text" class="form-control" id="number" name="number" required
value="{{ document.number if document else '' }}">
</div>
<div class="col-md-6">
<div class="col-md-3">
<label for="document_date" class="form-label">Дата</label>
<input type="date" class="form-control" id="document_date" name="document_date" required>
<input type="date" class="form-control" id="document_date" name="document_date" required
value="{{ document.date.isoformat() if document else '' }}">
</div>
<div class="col-md-3">
<label for="reporting_period_from" class="form-label">Период с</label>
<input type="date" class="form-control" id="reporting_period_from" name="reporting_period_from" required
value="{{ document.reporting_period_from.isoformat() if document and document.reporting_period_from else '' }}">
</div>
<div class="col-md-3">
<label for="reporting_period_to" class="form-label">Период по</label>
<input type="date" class="form-control" id="reporting_period_to" name="reporting_period_to" required
value="{{ document.reporting_period_to.isoformat() if document and document.reporting_period_to else '' }}">
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<label for="comment" class="form-label">Комментарий</label>
<input type="text" class="form-control" id="comment" name="comment"
value="{{ document.comment if document and document.comment else '' }}">
</div>
</div>
<div class="mb-3">
<label for="comment" class="form-label">Комментарий</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
<h4>Выберите позиции</h4>
<h4>Выберите позиции для закрытия</h4>
<div class="table-responsive">
<table class="table table-striped">
<table class="table table-striped table-sm" style="table-layout: fixed;">
<colgroup>
<col style="width: 50px">
<col>
<col style="width: 40px">
<col style="width: 72px">
<col style="width: 72px">
<col style="width: 72px">
<col style="width: 72px">
<col style="width: 96px">
<col style="width: 90px">
<col style="width: 100px">
</colgroup>
<thead>
<tr>
<th>№ поз.</th>
<th>Наименование</th>
<th>План</th>
<th>Факт</th>
<th>Закрыто</th>
<th>Доступно</th>
<th>Количество</th>
<th>Ед.</th>
<th class="text-end text-nowrap">План</th>
<th class="text-end text-nowrap">Факт</th>
<th class="text-end text-nowrap">Закрыто</th>
<th class="text-end text-nowrap">Доступно</th>
<th class="text-end text-nowrap">Цена</th>
<th class="text-nowrap">Кол-во</th>
<th class="text-end text-nowrap">Сумма</th>
</tr>
</thead>
<tbody>
{% for balance in balances %}
<tr>
<td>{{ balance.item.name }}</td>
<td>{{ balance.planned_quantity }}</td>
<td>{{ balance.actual_quantity }}</td>
<td>{{ balance.closed_quantity }}</td>
<td>{{ balance.available_quantity }}</td>
<td>{{ balance.item.source_number or '' }}</td>
<td style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">{{ balance.item.name }}</td>
<td>{{ balance.item.unit or '' }}</td>
<td class="text-end text-nowrap">{{ balance.planned_quantity|quantity2 }}</td>
<td class="text-end text-nowrap">{{ balance.actual_quantity|quantity2 }}</td>
<td class="text-end text-nowrap">{{ balance.closed_quantity|quantity2 }}</td>
<td class="text-end text-nowrap">{{ balance.available_quantity|quantity2 }}</td>
<td class="text-end text-nowrap" data-price="{{ balance.item.unit_price or 0 }}">{{ balance.item.unit_price|money }}</td>
<td>
<input type="checkbox" class="form-check-input" id="include_{{ balance.item.id }}"
name="include_{{ balance.item.id }}" value="1"
{% if balance.item.id in selected %}checked{% endif %}>
<input type="number" class="form-control form-control-sm"
<input type="number" class="form-control form-control-sm mt-1"
name="quantity_{{ balance.item.id }}"
value="{{ selected.get(balance.item.id, '') }}"
min="0" step="0.0001"
min="0" step="0.01"
{% if balance.item.id not in selected %}disabled{% endif %}
placeholder="Количество">
placeholder="0.00"
style="width: 100%; box-sizing: border-box;"
data-item-id="{{ balance.item.id }}">
</td>
<td class="text-end text-nowrap" id="amount_{{ balance.item.id }}">—</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<button type="submit" class="btn btn-primary">Создать</button>
<a href="/projects/{{ project.id }}/ks2" class="btn btn-secondary">Отмена</a>
<button type="submit" class="btn btn-primary">{{ 'Сохранить' if document else 'Создать' }}</button>
<a href="/projects/{{ project.id }}/ks2{% if document %}/{{ document.id }}{% endif %}" class="btn btn-secondary">Отмена</a>
</form>
</div>
</div>
</div>
<script>
// Обработчик изменения чекбокса
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', function() {
const quantityInput = document.querySelector(`input[name="quantity_${this.id.split('_')[1]}"]`);
const itemId = this.id.split('_')[1];
const quantityInput = document.querySelector(`input[name="quantity_${itemId}"]`);
if (this.checked) {
quantityInput.disabled = false;
quantityInput.focus();
} else {
quantityInput.disabled = true;
quantityInput.value = '';
updateAmount(itemId, quantityInput);
}
});
});
document.querySelectorAll('input[type="number"][data-item-id]').forEach(input => {
input.addEventListener('input', function() {
updateAmount(this.dataset.itemId, this);
});
});
// Инициализация сумм при редактировании
document.querySelectorAll('input[type="number"][data-item-id]').forEach(input => {
if (input.value) {
updateAmount(input.dataset.itemId, input);
}
});
function updateAmount(itemId, quantityInput) {
const amountCell = document.getElementById('amount_' + itemId);
const priceCell = quantityInput.closest('tr').querySelector('[data-price]');
const price = parseFloat(priceCell.dataset.price) || 0;
const qty = parseFloat(quantityInput.value) || 0;
const amount = price * qty;
amountCell.textContent = amount > 0 ? amount.toLocaleString('ru-RU', {minimumFractionDigits: 2, maximumFractionDigits: 2}) + ' \u20BD' : '—';
}
});
</script>
{% endblock %}
{% endblock %}