25 lines
26 KiB
HTML
25 lines
26 KiB
HTML
<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>ДС №{{ agreement.number }} — {{ project.name }}</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"><style>.numeric{font-variant-numeric:tabular-nums;white-space:nowrap}.item-name{min-width:16rem}</style></head><body class="bg-light"><main class="container-fluid container-xxl py-4">
|
||
<nav><ol class="breadcrumb"><li class="breadcrumb-item"><a href="/projects/">Проекты</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}">{{ project.name }}</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}/agreements">ДС</a></li><li class="breadcrumb-item active">№{{ agreement.number }}</li></ol></nav>
|
||
{% if error %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endif %}
|
||
<header class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4"><div><h1 class="h2 mb-1">ДС №{{ agreement.number }} — {{ agreement.title }}</h1><div class="text-muted">{{ agreement.date.strftime('%d.%m.%Y') }} · {{ scope_label }}</div></div><div class="d-flex gap-2"><a class="btn btn-outline-secondary" href="/projects/{{ project.id }}/agreements">К списку</a>{% if agreement.status == 'approved' %}<span class="badge text-bg-success align-self-center">Утверждено</span>{% else %}<span class="badge text-bg-secondary align-self-center">Черновик</span>{% endif %}</div></header>
|
||
{% if agreement.status == 'draft' %}
|
||
<section class="card border-0 shadow-sm mb-4"><div class="card-header bg-white"><h2 class="h5 mb-0">Реквизиты ДС</h2></div><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/update"><div class="card-body row g-3">
|
||
<div class="col-md-3"><label class="form-label">Номер</label><input class="form-control" name="number" value="{{ agreement.number }}" required></div><div class="col-md-3"><label class="form-label">Дата</label><input class="form-control" type="date" name="agreement_date" value="{{ agreement.date.isoformat() }}" required></div><div class="col-md-6"><label class="form-label">Наименование</label><input class="form-control" name="title" value="{{ agreement.title }}" required></div><div class="col-12"><label class="form-label">Описание</label><textarea class="form-control" name="description" rows="2">{{ agreement.description or '' }}</textarea></div>
|
||
<div class="col-md-7"><label class="form-label">Область применения</label><select class="form-select" name="scope" required><option value="project" {% if agreement.boq_document_id is none %}selected{% endif %}>Весь проект</option>{% for doc in boq_documents %}<option value="boq:{{ doc.id }}" {% if agreement.boq_document_id == doc.id %}selected{% endif %}>{{ doc.name }}</option>{% endfor %}</select></div></div><div class="card-footer bg-white"><button class="btn btn-outline-primary" type="submit">Сохранить реквизиты</button></div></form></section>
|
||
{% else %}<section class="card border-0 shadow-sm mb-4"><div class="card-body row g-3"><div class="col-md-3"><span class="text-muted">Номер:</span> <strong>{{ agreement.number }}</strong></div><div class="col-md-3"><span class="text-muted">Дата:</span> {{ agreement.date.strftime('%d.%m.%Y') }}</div><div class="col-md-6"><span class="text-muted">Область:</span> {{ scope_label }}</div><div class="col-12"><span class="text-muted">Описание:</span> {{ agreement.description or '—' }}</div></div></section>{% endif %}
|
||
<section class="card border-0 shadow-sm mb-4"><div class="card-header bg-white d-flex justify-content-between"><h2 class="h5 mb-0">Позиции ДС</h2><span>{{ line_rows|length }} поз.</span></div><div class="table-responsive"><table class="table table-hover align-middle mb-0"><thead><tr><th>Тип</th><th>№ / Позиция</th><th>Ед.</th><th class="text-end">Базовое / текущее</th><th class="text-end">Изменение</th><th class="text-end">После ДС</th><th class="text-end">Сумма изменения</th><th></th></tr></thead><tbody>
|
||
{% for row in line_rows %}<tr><td>{% if row.line.change_type == 'new_position' %}<span class="badge text-bg-info">Новая</span>{% elif row.line.change_type == 'decrease' %}<span class="badge text-bg-warning">Уменьшение</span>{% else %}<span class="badge text-bg-primary">Увеличение</span>{% endif %}</td><td class="item-name"><div class="fw-semibold">{{ row.item.source_number or '' }} {{ row.item.name }}</div><small class="text-muted">{{ row.item.model or '' }}{% if row.item.manufacturer %} · {{ row.item.manufacturer }}{% endif %}</small></td><td>{{ row.item.unit or '—' }}</td><td class="text-end numeric">{{ row.before_quantity }}</td><td class="text-end numeric">{{ row.line.quantity_delta }}</td><td class="text-end numeric">{{ row.after_quantity }}</td><td class="text-end numeric">{{ row.amount_delta|money(project.currency) }}</td><td class="text-end">{% if agreement.status == 'draft' %}<button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#edit-line-{{ row.line.id }}">Править</button><form class="d-inline" method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/items/{{ row.line.id }}/delete" onsubmit="return confirm('Удалить позицию из черновика?')"><button class="btn btn-sm btn-outline-danger">×</button></form>{% endif %}</td></tr>
|
||
{% if agreement.status == 'draft' %}<tr class="collapse" id="edit-line-{{ row.line.id }}"><td colspan="8"><form class="row g-2" method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/items/{{ row.line.id }}/edit"><div class="col-md-2"><label class="form-label">Δ кол-во</label><input class="form-control" type="number" step="0.0001" name="quantity_delta" value="{{ row.line.quantity_delta }}" required></div>{% if row.line.change_type == 'new_position' %}<div class="col-md-2"><label class="form-label">Имя</label><input class="form-control" name="name" value="{{ row.item.name }}" required></div><div class="col-md-2"><label class="form-label">Модель</label><input class="form-control" name="model" value="{{ row.item.model or '' }}"></div><div class="col-md-2"><label class="form-label">Произв.</label><input class="form-control" name="manufacturer" value="{{ row.item.manufacturer or '' }}"></div><div class="col-md-2"><label class="form-label">Ед.</label><input class="form-control" name="unit" value="{{ row.item.unit or '' }}"></div><div class="col-md-2"><label class="form-label">Цена</label><input class="form-control" type="number" step="0.000000000001" name="unit_price" value="{{ row.item.unit_price }}" required></div><div class="col-md-3"><label class="form-label">Система</label><select class="form-select system-select" name="system_id" required>{% for system in systems %}<option value="{{ system.id }}" {% if row.item.system_id == system.id %}selected{% endif %}>{{ system.name }}</option>{% endfor %}</select></div><div class="col-md-3"><label class="form-label">Раздел</label><select class="form-select section-select" name="section_id" required>{% for section in sections %}<option value="{{ section.id }}" data-system="{{ section.system_id }}" {% if row.item.section_id == section.id %}selected{% endif %}>{{ section.name }}</option>{% endfor %}</select></div>{% endif %}<div class="col-md-2 align-self-end"><button class="btn btn-primary">Сохранить</button></div></form></td></tr>{% endif %}
|
||
{% else %}<tr><td colspan="8" class="text-center text-muted py-4">Позиции ещё не добавлены.</td></tr>{% endfor %}</tbody></table></div><div class="card-footer bg-white d-flex justify-content-between"><span class="text-muted">Сумма изменения плана</span><strong>{{ change_amount|money(project.currency) }}</strong></div></section>
|
||
{% if agreement.status == 'draft' %}<div class="row g-4"><div class="col-xl-6"><section class="card border-0 shadow-sm h-100"><div class="card-header bg-white"><h2 class="h5 mb-0">Добавить существующую позицию</h2></div><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/items/existing"><div class="card-body"><div class="mb-3 position-relative" data-position-picker><label class="form-label" for="existing-position-search">Позиция проекта</label><div class="input-group"><input id="existing-position-search" class="form-control" type="search" autocomplete="off" placeholder="Поиск по номеру, наименованию, модели, системе..." aria-expanded="false" aria-controls="existing-position-results" required><button class="btn btn-outline-secondary" type="button" data-clear-position>Очистить</button></div><input type="hidden" name="work_item_id" data-work-item-id><div class="form-text" data-selected-position aria-live="polite">Позиция не выбрана</div><div id="existing-position-results" class="list-group position-absolute shadow bg-white" role="listbox" style="z-index:1050;max-height:18rem;overflow-y:auto;min-width:min(100%,40rem);display:none">{% for row in selectable_items %}<button type="button" class="list-group-item list-group-item-action autocomplete-position" role="option" data-id="{{ row.item.id }}" data-search="{{ row.item.source_number or '' }} {{ row.item.name }} {{ row.item.model or '' }} {{ row.item.manufacturer or '' }} {{ row.item.system.name if row.item.system else '' }} {{ row.item.section.name if row.item.section else '' }}" data-label="{{ row.item.system.name if row.item.system else '' }} ? {{ row.item.section.name if row.item.section else '' }} ? ?{{ row.item.source_number or '' }} ? {{ row.item.name }}{% if row.item.model %} ? {{ row.item.model }}{% endif %} ? {{ row.quantity }} {{ row.item.unit or '' }}"><span class="fw-semibold">{{ row.item.system.name if row.item.system else '' }} ? {{ row.item.section.name if row.item.section else '' }} ? ?{{ row.item.source_number or '?' }}</span><br>{{ row.item.name }}{% if row.item.model %} ? {{ row.item.model }}{% endif %}<small class="d-block text-muted">{{ row.item.manufacturer or '' }}{% if row.item.manufacturer %} ? {% endif %}{{ row.quantity }} {{ row.item.unit or '' }}</small></button>{% endfor %}<div class="list-group-item text-muted d-none" data-no-results>Ничего не найдено.</div><div class="list-group-item text-muted d-none" data-more-results>Показаны первые 20 результатов. Уточните поиск.</div></div></div><div class="mb-3"><label class="form-label">Δ количество (+ / −)</label><input class="form-control" type="number" step="0.0001" name="quantity_delta" required><div class="form-text">Для уменьшения укажите отрицательное число. Сумма рассчитается по цене позиции.</div></div>{% if not selectable_items %}<div class="text-muted small mb-3">В этой области нет недобавленных позиц.</div>{% endif %}</div><div class="card-footer bg-white"><button class="btn btn-outline-primary" {% if not selectable_items %}disabled{% endif %}>Добавить позицию</button></div></form></section></div>
|
||
<div class="col-xl-6"><section class="card border-0 shadow-sm h-100"><div class="card-header bg-white"><h2 class="h5 mb-0">Добавить новую позицию</h2></div><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/items/new" data-new-item-form data-system-url="/projects/{{ project.id }}/agreements/{{ agreement.id }}/systems" data-section-url="/projects/{{ project.id }}/agreements/{{ agreement.id }}/sections"><div class="card-body row g-3"><div class="col-12"><label class="form-label">Ведомость (необязательно)</label><select class="form-select" name="source_boq_document_id"><option value="">Без ведомости</option>{% for doc in boq_documents %}<option value="{{ doc.id }}" {% if agreement.boq_document_id == doc.id %}selected{% endif %}>{{ doc.name }}</option>{% endfor %}</select></div><div class="col-md-6"><label class="form-label">Наименование</label><input class="form-control" name="name" required></div><div class="col-md-6"><label class="form-label">Модель / артикул</label><input class="form-control" name="model"></div><div class="col-md-6"><label class="form-label">Производитель</label><input class="form-control" name="manufacturer"></div><div class="col-md-3"><label class="form-label">Единица</label><input class="form-control" name="unit"></div><div class="col-md-3"><label class="form-label">Δ кол-во</label><input class="form-control" type="number" min="0.0001" step="0.0001" name="quantity_delta" required></div><div class="col-md-6"><label class="form-label">Цена за единицу</label><input class="form-control" type="number" min="0" step="0.000000000001" name="unit_price" required></div><div class="col-md-6"><label class="form-label">Система</label><select class="form-select system-select" name="system_id" data-system-select><option value="">Без системы</option>{% for system in systems %}<option value="{{ system.id }}">{{ system.name }}</option>{% endfor %}<option value="__new__">+ Новая система...</option></select><div class="input-group mt-2 d-none" data-new-system-panel><input class="form-control" maxlength="255" placeholder="Название системы"><button type="button" class="btn btn-outline-primary" data-create-system>Создать</button></div></div><div class="col-md-6"><label class="form-label">Раздел</label><select class="form-select section-select" name="section_id" data-section-select><option value="">Без раздела</option>{% for section in sections %}<option value="{{ section.id }}" data-system="{{ section.system_id }}">{{ section.name }}</option>{% endfor %}<option value="__new__">+ Новый раздел...</option></select><div class="input-group mt-2 d-none" data-new-section-panel><input class="form-control" maxlength="255" placeholder="Название раздела"><button type="button" class="btn btn-outline-primary" data-create-section>Создать</button></div></div><div class="col-12 text-danger small" data-association-error role="alert"></div></div><div class="card-footer bg-white"><button class="btn btn-outline-primary">Добавить новую позицию</button></div></form></section></div></div>
|
||
<section class="d-flex justify-content-end mt-4"><button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#approveModal" {% if not line_rows %}disabled{% endif %}>Утвердить</button></section>
|
||
<div class="modal fade" id="approveModal" tabindex="-1"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h2 class="modal-title fs-5">Подтвердите утверждение</h2><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div><strong>ДС №{{ agreement.number }}</strong></div><div>Область: {{ scope_label }}</div><div>Количество позиций: {{ line_rows|length }}</div><p class="text-warning mt-3 mb-0">После утверждения изменения нельзя редактировать.</p></div><div class="modal-footer"><button class="btn btn-outline-secondary" data-bs-dismiss="modal">Отмена</button><form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/approve"><button class="btn btn-success">Утвердить ДС</button></form></div></div></div></div>
|
||
{% else %}<div class="alert alert-info">ДС утверждено. Изменения недоступны.</div>{% endif %}
|
||
</main><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script><script>
|
||
document.querySelectorAll('.system-select').forEach(systemSelect=>{const form=systemSelect.closest('form');const section=form.querySelector('.section-select');if(!section)return;const filter=()=>{const value=systemSelect.value;[...section.options].forEach(option=>{if(!option.dataset.system)return;option.hidden=!!value&&value!=='__new__'&&option.dataset.system!==value;});const selected=section.selectedOptions[0];if(selected&&selected.dataset.system&&selected.hidden)section.value='';};systemSelect.addEventListener('change',filter);filter();});
|
||
const makeOption=(select,id,name,attributes={})=>{const option=document.createElement('option');option.value=id;option.textContent=name;Object.entries(attributes).forEach(([key,value])=>option.dataset[key]=value);const createOption=[...select.options].find(item=>item.value==='__new__');select.insertBefore(option,createOption||null);select.value=String(id);};
|
||
document.querySelectorAll('[data-new-item-form]').forEach(form=>{const system=form.querySelector('[data-system-select]');const section=form.querySelector('[data-section-select]');const systemPanel=form.querySelector('[data-new-system-panel]');const sectionPanel=form.querySelector('[data-new-section-panel]');const error=form.querySelector('[data-association-error]');const showError=message=>{error.textContent=message||'';};const filterSections=()=>{const selected=system.value;[...section.options].forEach(option=>{if(option.dataset.system)option.hidden=!selected||selected==='__new__'||option.dataset.system!==selected;});};system.addEventListener('change',()=>{section.value='';sectionPanel.classList.add('d-none');systemPanel.classList.toggle('d-none',system.value!=='__new__');if(system.value==='__new__'){section.value='';section.disabled=true;}else{section.disabled=!system.value;filterSections();}});section.addEventListener('change',()=>sectionPanel.classList.toggle('d-none',section.value!=='__new__'));const createEntity=async(url,values)=>{showError('');const response=await fetch(url,{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams(values)});const payload=await response.json();if(!response.ok)throw new Error(payload.detail||'?? ??????? ???????');return payload;};form.querySelector('[data-create-system]').addEventListener('click',async()=>{const input=systemPanel.querySelector('input');try{const entity=await createEntity(form.dataset.systemUrl,{name:input.value});makeOption(system,entity.id,entity.name);systemPanel.classList.add('d-none');system.disabled=false;section.disabled=false;section.value='';filterSections();input.value='';}catch(errorValue){showError(errorValue.message);}});form.querySelector('[data-create-section]').addEventListener('click',async()=>{const input=sectionPanel.querySelector('input');if(!system.value||system.value==='__new__'){showError('??????? ???????? ??? ???????? ???????');return;}try{const entity=await createEntity(form.dataset.sectionUrl,{system_id:system.value,name:input.value});makeOption(section,entity.id,entity.name,{system:entity.system_id});sectionPanel.classList.add('d-none');input.value='';}catch(errorValue){showError(errorValue.message);}});form.addEventListener('submit',event=>{if(system.value==='__new__'||section.value==='__new__'){event.preventDefault();showError('??????? ????????? ????? ??????? ??? ??????');}});});
|
||
document.querySelectorAll('[data-position-picker]').forEach(picker=>{const input=picker.querySelector('input[type="search"]');const hidden=picker.querySelector('[data-work-item-id]');const menu=picker.querySelector('[role="listbox"]');const options=[...picker.querySelectorAll('.autocomplete-position')];const selected=picker.querySelector('[data-selected-position]');const noResults=picker.querySelector('[data-no-results]');const more=picker.querySelector('[data-more-results]');const normalize=value=>value.toLocaleLowerCase().trim().replace(/\s+/g,' ');const close=()=>{menu.style.display='none';input.setAttribute('aria-expanded','false');};const render=()=>{const query=normalize(input.value);let shown=0;let matches=0;options.forEach(option=>{const match=!query||normalize(option.dataset.search).includes(query);if(match){matches++;option.hidden=shown>=20;if(!option.hidden)shown++;}else option.hidden=true;});noResults.classList.toggle('d-none',matches!==0);more.classList.toggle('d-none',matches<=20);menu.style.display='block';input.setAttribute('aria-expanded','true');};input.addEventListener('focus',render);input.addEventListener('input',()=>{hidden.value='';selected.textContent='\u041f\u043e\u0437\u0438\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u0430';input.setCustomValidity('\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430');render();});options.forEach(option=>option.addEventListener('click',()=>{hidden.value=option.dataset.id;input.value=option.dataset.label;selected.textContent='\u0412\u044b\u0431\u0440\u0430\u043d\u043e: '+option.dataset.label;input.setCustomValidity('');close();}));picker.querySelector('[data-clear-position]').addEventListener('click',()=>{hidden.value='';input.value='';selected.textContent='\u041f\u043e\u0437\u0438\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u0430';input.setCustomValidity('\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430');input.focus();render();});picker.closest('form').addEventListener('submit',event=>{if(!hidden.value){input.setCustomValidity('\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430');input.reportValidity();event.preventDefault();}});document.addEventListener('click',event=>{if(!picker.contains(event.target))close();});});
|
||
</script></body></html>
|