demo2/templates/add_sale.html
2026-01-30 11:53:18 +05:00

182 lines
9.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h2 class="card-title mb-0">
<i class="fas fa-cart-plus"></i> Добавление продажи
</h2>
</div>
<div class="card-body">
<!-- Информация о партнере -->
<div class="partner-info mb-4 p-3 bg-light rounded">
<h5>Партнер: {{ partner.name }}</h5>
<p class="mb-1"><strong>Тип:</strong> {{ partner.partner_type_name }}</p>
<p class="mb-1"><strong>Email:</strong> {{ partner.email }}</p>
<p class="mb-0"><strong>Телефон:</strong> {{ partner.phone or 'Не указан' }}</p>
</div>
<!-- Flash сообщения -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ 'danger' if category == 'error' else 'success' }} alert-dismissible fade show">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<form method="POST" id="saleForm">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="product_id" class="form-label">Товар *</label>
<select class="form-select" id="product_id" name="product_id" required>
<option value="">Выберите товар</option>
{% for product in products %}
<option value="{{ product.id }}"
data-price="{{ product.min_partner_price }}"
data-name="{{ product.product_name }}">
{{ product.product_name }} ({{ product.article }}) - {{ product.min_partner_price }} руб.
</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="quantity" class="form-label">Количество *</label>
<input type="number" class="form-control" id="quantity" name="quantity"
min="1" required value="1">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="sale_price" class="form-label">Цена продажи *</label>
<input type="number" class="form-control" id="sale_price" name="sale_price"
step="0.01" min="0.01" required>
<div class="form-text">Минимальная цена: <span id="minPrice">0</span> руб.</div>
</div>
<div class="mb-3">
<label for="sale_date" class="form-label">Дата продажи *</label>
<input type="date" class="form-control" id="sale_date" name="sale_date"
required value="{{ today }}">
</div>
</div>
</div>
<!-- Автоматический расчет суммы -->
<div class="row mt-3">
<div class="col-12">
<div class="calculation-section p-3 bg-light rounded">
<div class="row">
<div class="col-md-4">
<strong>Количество:</strong>
<span id="displayQuantity">1</span> ед.
</div>
<div class="col-md-4">
<strong>Цена за единицу:</strong>
<span id="displayPrice">0</span> руб.
</div>
<div class="col-md-4">
<strong class="text-primary">Итоговая сумма:</strong>
<span id="totalAmount" class="fs-5 text-success">0</span> руб.
</div>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-12">
<div class="d-flex justify-content-between">
<a href="{{ url_for('sales_history', partner_id=partner.id) }}"
class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Назад к истории
</a>
<button type="submit" class="btn btn-success">
<i class="fas fa-save"></i> Сохранить продажу
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
console.log('Script loaded!');
const productSelect = document.getElementById('product_id');
const quantityInput = document.getElementById('quantity');
const priceInput = document.getElementById('sale_price');
const minPriceSpan = document.getElementById('minPrice');
const totalAmountSpan = document.getElementById('totalAmount');
const displayQuantitySpan = document.getElementById('displayQuantity');
const displayPriceSpan = document.getElementById('displayPrice');
// Устанавливаем сегодняшнюю дату по умолчанию
const today = new Date().toISOString().split('T')[0];
document.getElementById('sale_date').value = today;
// Обновление цены при выборе товара
productSelect.addEventListener('change', function() {
console.log('Product changed');
const selectedOption = this.options[this.selectedIndex];
const minPrice = selectedOption.getAttribute('data-price');
console.log('Min price:', minPrice);
if (minPrice) {
minPriceSpan.textContent = minPrice;
priceInput.value = minPrice;
priceInput.min = minPrice;
displayPriceSpan.textContent = parseFloat(minPrice).toFixed(2);
calculateTotal();
}
});
// Расчет общей суммы
function calculateTotal() {
const quantity = parseInt(quantityInput.value) || 0;
const price = parseFloat(priceInput.value) || 0;
const total = quantity * price;
displayQuantitySpan.textContent = quantity;
displayPriceSpan.textContent = price.toFixed(2);
totalAmountSpan.textContent = total.toFixed(2);
}
// Слушатели изменений
quantityInput.addEventListener('input', calculateTotal);
priceInput.addEventListener('input', function() {
displayPriceSpan.textContent = parseFloat(this.value || 0).toFixed(2);
calculateTotal();
});
// Валидация формы
document.getElementById('saleForm').addEventListener('submit', function(e) {
const minPrice = parseFloat(minPriceSpan.textContent) || 0;
const salePrice = parseFloat(priceInput.value) || 0;
if (salePrice < minPrice) {
e.preventDefault();
alert(`Цена продажи не может быть ниже минимальной цены (${minPrice} руб.)`);
return false;
}
});
// Инициализация расчета
calculateTotal();
});
</script>
{% endblock %}