Files
watersurf-erp/app/templates/documents/supplier_order_form.html

61 lines
2.3 KiB
HTML

{% extends "base.html" %}
{% block title %}{{ title }} — ERP WaterSurf{% endblock %}
{% block content %}
<div class="ws-card">
<h2 class="ws-page-title">{% if object %}Редактировать{% else %}Создать{% endif %} {{ title }}</h2>
<form method="post" class="ws-form-card">
{% csrf_token %}
{% for field in form %}
<div class="ws-form-group">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% if field.errors %}<small class="ws-text-danger">{{ field.errors.0 }}</small>{% endif %}
</div>
{% endfor %}
<div class="ws-form-section">
<h3 class="ws-form-section-title">Товары</h3>
{{ formset.management_form }}
<div class="ws-table-wrap">
<table class="ws-table" id="supplier-order-items">
<thead>
<tr>
<th>Товар</th>
<th>Цена</th>
<th>Валюта</th>
<th>Количество</th>
<th class="ws-num">Стоимость</th>
<th>Удалить</th>
</tr>
</thead>
<tbody>
{% for f in formset %}
<tr class="item-row">
<td>{{ f.id }}{{ f.product }}</td>
<td>{{ f.price }}</td>
<td>{{ f.currency }}</td>
<td>{{ f.quantity }}</td>
<td class="row-amount ws-num"></td>
<td>{% if f.DELETE %}{{ f.DELETE }}{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="ws-btn-group" style="margin-top: 1.25rem;">
<button type="submit" class="btn btn-ws-primary">Сохранить</button>
<a href="{% url 'documents:supplier_order_list' %}" class="btn btn-ws-secondary">Отмена</a>
</div>
</form>
</div>
<script>
document.querySelector('.ws-form-card').addEventListener('input', function() {
document.querySelectorAll('#supplier-order-items .item-row').forEach(function(row) {
var price = parseFloat(row.querySelector('input[name$="-price"]')?.value) || 0;
var qty = parseFloat(row.querySelector('input[name$="-quantity"]')?.value) || 0;
row.querySelector('.row-amount').textContent = (price * qty).toFixed(2);
});
});
</script>
{% endblock %}