diff --git "a/app.py" "b/app.py" new file mode 100644--- /dev/null +++ "b/app.py" @@ -0,0 +1,4358 @@ + +# Импортируем необходимые библиотеки +from flask import Flask, render_template_string, request, redirect, url_for, jsonify, flash, send_from_directory + +ORDERS_TEMPLATE = ''' + + +
+| ID | +Клиент | +Изделие | +Кол-во | +Статус | +Предоплата | +Дата | +
|---|---|---|---|---|---|---|
| {{ order.id[:8] }} | +{{ order.customer_name }} | +{{ order.product_name }} | +{{ order.quantity }} | +{{ order.status }} | +{{ format_currency_py(order.prepayment) }} | +{{ order.timestamp_created[:10] }} | +
| Сотрудник | +Должность | +Сумма | +Дата | +Статус | +
|---|---|---|---|---|
| {{ advance.employee_name }} | +{{ advance.role }} | +{{ format_currency_py(advance.amount) }} | +{{ advance.timestamp[:10] }} | +{{ advance.status }} | +
| ID | +Имя / Организация | +Телефон | +Адрес | +Действия | +
|---|---|---|---|---|
| {{ client.id[:8] }}... | +{{ client.name }} | +{{ client.phone }} | +{{ client.address | default('-') | safe }} | ++ + | +
| Клиенты еще не добавлены. | +||||
Обзор состояния производства и настройки
+ + +{{ materials_count }}
{{ pending_cutting_count }}
{{ pending_qc_count }}
{{ format_integer_py(total_packed_count) }}
{{ format_integer_py(items_ready_ship_qty) }}
Ткань: {{ total_defect_fabric_m }} м
Фурнитура: {{ total_defect_fittings_pcs }} шт.
Готовые изд.: {{ total_defect_finished_pcs }} шт.
Стоимость: {{ total_defect_cost }} сом
Нет категорий для удаления.
{% endif %}Нет категорий.
{% endif %} +| ID | Описание | Сумма (сом) | Дата |
|---|---|---|---|
| {{ expense.id[:8] }}... | +{{ expense.description }} | +{{ format_currency_py(expense.amount) }} | +{{ expense.timestamp[:16]|replace('T',' ') if expense.timestamp else 'N/A' }} | +
| Дополнительные расходы еще не добавлялись. | |||
| ID | +Название | +Категория | +Тип | +Кол-во | +Ед.изм. | +Цена/ед | +На ед. | +Добавлен | +Обновлен | +
|---|---|---|---|---|---|---|---|---|---|
| {{ m.id[:8] }}... | {{ m.name }} | +{{ m.category | default('Без категории') }} | +{{ 'Ткань' if m.type == 'fabric' else 'Фурнитура' }} | +{{ format_currency_py(m.quantity) if m.type == 'fabric' else format_integer_py(m.quantity) }} | {{ m.unit }} | +{{ format_currency_py(m.price_per_unit) }} | +{{ format_integer_py(m.items_per_unit) }} | +{{ m.timestamp_added[:16] | replace('T', ' ') if m.timestamp_added else 'N/A' }} | +{{ m.timestamp_last_updated[:16] | replace('T', ' ') if m.timestamp_last_updated else 'N/A' }} | +
| Нет материалов в наличии. | |||||||||
| ID | Ткань | Кол-во | Расход | Ст��тус | Создано | Завершено | +
|---|---|---|---|---|---|---|
| {{ task.id[:8] }}... | +{{ task.fabric_name }}({{ task.fabric_id[:6] }}...) | +{{ format_integer_py(task.cut_items_quantity) }} | +{{ format_currency_py(task.fabric_used) }} {{ task.fabric_unit }} | +{{ getStatusText(task.status) }} | +{{ task.timestamp_created[:16] | replace('T', ' ') if task.timestamp_created else 'N/A' }} | +{{ task.timestamp_completed[:16] | replace('T', ' ') if task.timestamp_completed else '-' }} | +
| Нет заданий на раскрой. | ||||||
| ID | Изделие | Сшито | + {# --- ИЗМЕНЕНО: Добавлен столбец для фурнитуры --- #} +Исп. фурн. | + {# --- КОНЕЦ ИЗМЕНЕНИЯ --- #} +Брак пошива | Статус | Упак./Брак ОТК | Создано | Завершено | Раскрой ID | +
|---|---|---|---|---|---|---|---|---|---|
| {{ task.id[:8] }}... | +{{ task.product_name }} | {{ format_integer_py(task.sewn_quantity) }} | + {# --- ИЗМЕНЕНО: Вывод данных фурнитуры --- #} +
+ {% if task.fittings_consumed is iterable and task.fittings_consumed is not string %} {# Доп. проверка #}
+
|
+ {# --- КОНЕЦ ИЗМЕНЕНИЯ --- #}
+
+ {% if task.defects_reported is iterable and task.defects_reported is not string %} {# Доп. проверка #}
+
|
+ {{ getStatusText(task.status) }} | +{{ format_integer_py(task.qc_packed_quantity) }} / {{ format_integer_py(task.qc_defective_quantity) }} | +{{ task.timestamp_created[:16] | replace('T', ' ') if task.timestamp_created else 'N/A' }} | +{{ task.timestamp_completed[:16] | replace('T', ' ') if task.timestamp_completed else '-' }} | +{{ task.cutting_task_id[:8] }}... | +
| Нет заданий на пошив. | |||||||||
| ID | Название | Кол-во | Себест. (ед.) | Цена (ед.) | Общая себест. | Общая цена | Статус | Дата упак. | Детали отправки | Пошив ID | +
|---|---|---|---|---|---|---|---|---|---|---|
| {{ item.id[:8] }}... | {{ item.product_name }} | {{ format_integer_py(item.quantity) }} | +{{ format_currency_py(cost_per_item) }} | +{{ format_currency_py(price_per_item) }} | +{{ format_currency_py(item.packed_total_cost) }} | +{{ format_currency_py(item.packed_final_price) }} | +{{ getStatusText(item.status) }} | +{{ item.timestamp_packed[:16] | replace('T', ' ') if item.timestamp_packed else 'N/A' }} | +
+ {% set details = item.shipment_details %}
+ {% if details is mapping %} {# Проверка что details это словарь #}
+
+ {{ details.get('timestamp')[:16] | replace('T',' ') if details.get('timestamp') else '' }}
+ {% if details.get('type') == 'client' %}
+ Клиент: {{ details.get('client_name', 'N/A')}} + {% elif details.get('type') == 'dor_doi_point' %} + Назначение: {{ details.get('destination', 'Дордой') }} + {% endif %} + + {% else %} {# ИЗМЕНЕНО: Показываем историю частичных отправок #} + {# Логика отображения истории частичных отправок, если она будет храниться здесь #} + {# Например, если добавить поле `partial_shipments`: #} + {# {% if item.partial_shipments %}
|
+ {{ item.sewing_task_id[:8] }}... | +
| Нет упакованных изделий. | ||||||||||
| ID | Изделие | В наличии | Себест.(общ) | Цена (общ) | Дата упак. | Дейст��ия | +
|---|---|---|---|---|---|---|
| {{ item.id[:8] }}... | +{{ item.product_name }} | +{{ format_integer_py(item.quantity) }} | +{{ format_currency_py(item.packed_total_cost) }} | +{{ format_currency_py(item.packed_final_price) }} | +{{ item.timestamp_packed[:16] | replace('T', ' ') if item.timestamp_packed else 'N/A' }} | ++ {# --- ИЗМЕНЕНО: Добавлено поле количества, изменена структура формы --- #} + + {# --- КОНЕЦ ИЗМЕНЕНИЯ --- #} + | +
| ID Отправки | Дата | Товары | Исходный ID уп. | +
|---|---|---|---|
| {{ shipment.shipment_id[:8] }}... | +{{ shipment.timestamp_dt.strftime('%Y-%m-%d %H:%M') if shipment.timestamp_dt else shipment.timestamp[:16]|replace('T',' ') }} | +
+ {% if shipment.items is iterable and shipment.items is not string and shipment.items %}
+
|
+ {{ shipment.packed_item_id[:8] }}... | +
| ID | Материал/Изделие | Тип | Кол-во | Ед. | Стоимость | Этап | Причина | Дата | Пошив ID | +
|---|---|---|---|---|---|---|---|---|---|
| {{ defect.log_id[:8] }}... | +{{ defect.material_name }} {% if defect.material_id %}({{ defect.material_id[:6] }}...){% endif %} | +{{ defect.type|replace('_', ' ')|title }} | +{{ defect.quantity_view }} | {# Используем поле _view #} +{{ defect.unit }} | +{{ format_currency_py(defect.cost_dec) }} | {# Используем поле _dec #} +{{ defect.stage|replace('_', ' ')|title }} | +{{ defect.reason | default('-') }} | +{{ defect.timestamp[:16] | replace('T', ' ') if defect.timestamp else 'N/A' }} | +{{ defect.sewing_task_id[:8] if defect.sewing_task_id else 'N/A' }}... | +
| Записи о браке отсутствуют. | |||||||||
{{ format_currency_py(report.total_revenue) }}
+ сом ({{ format_integer_py(report.total_packed_qty) }} шт. упаковано в период) +{{ format_currency_py(report.total_profit) }}
+ сом (Выручка - Затраты) +{{ format_currency_py(report.total_overall_cost) }}
+ сом (Себест.Упак.+Брак+Доп.) (Нажмите для деталей) +{{ format_currency_py(report.total_defect_cost) }}
+ сом ({{ report.filtered_defects|length }} записей) +Материалы: {{ format_currency_py(report.total_material_cost) }} сом
+Зарплаты: {{ format_currency_py(report.total_salary_cost) }} сом
+Итого себестоимость: {{ format_currency_py(report.total_cost_packed) }} сом
+ За {{ format_integer_py(report.total_packed_qty) }} шт. (Нажмите для деталей ЗП) +{{ format_currency_py(report.total_expenses) }}
+ сом ({{ report.filtered_expenses|length }} записей) +| Продукт | Упаковано (шт) | Выручка (сом) | Себестоимость (со��) | Прибыль (сом) | Средняя прибыль/шт | +
|---|---|---|---|---|---|
| {{ name }} | {{ format_integer_py(summary.quantity) }} | +{{ format_currency_py(summary.revenue) }} | +{{ format_currency_py(summary.cost) }} | +{{ format_currency_py(summary.profit) }} | +{{ format_currency_py(avg_profit) }} | +
| Нет данных об упакованных товарах за этот период. | |||||
| ID | Название | Кол-во | Себест. (ед.) | Цена (ед.) | Общ. себест. | Общ. цена | Дата упак. | Статус | Детали отправки | Пошив ID | +
|---|---|---|---|---|---|---|---|---|---|---|
| {{ item.id[:8] }}... | {{ item.product_name }} | {{ format_integer_py(item.quantity) }} | +{{ format_currency_py(cost_per_item) }} | +{{ format_currency_py(price_per_item) }} | +{{ format_currency_py(item.packed_total_cost) }} | +{{ format_currency_py(item.packed_final_price) }} | +{{ item.timestamp_packed[:16] | replace('T', ' ') if item.timestamp_packed else 'N/A' }} | +{{ getStatusText(item.status) }} | +
+ {% set details = item.shipment_details %}
+ {% if details is mapping %} {# Проверка что details это словарь #}
+
+ {# Используем поле _dt для форматированной даты отправки #}
+ {{ item.shipment_time_dt.strftime('%Y-%m-%d %H:%M') if item.shipment_time_dt else details.get('timestamp', '')[:16]|replace('T',' ') }}
+ {% if details.get('type') == 'client' %}
+ Клиент: {{ details.get('client_name', 'N/A')}} + {% elif details.get('type') == 'dor_doi_point' %} + Назначение: {{ details.get('destination', 'Дордой') }} + {% endif %} + + {% elif item.status == 'packed_ready_to_ship' %} - {# Готово, но не отправлено #} + {% else %} - {# Другой статус или нет данных #} {% endif %} + |
+ {{ item.sewing_task_id[:8] }}... | +
| Нет упакованных изделий за этот период. | ||||||||||
| ID | Материал/Изделие | Тип | Кол-во | Ед. | Стоимость | Этап | Причина | Дата | Пошив ID | +
|---|---|---|---|---|---|---|---|---|---|
| {{ defect.log_id[:8] }}... | +{{ defect.material_name }} {% if defect.material_id %}({{ defect.material_id[:6] }}...){% endif %} | +{{ defect.type|replace('_', ' ')|title }} | +{{ defect.quantity_view }} | {{ defect.unit }} | +{{ format_currency_py(defect.cost_dec) }} | +{{ defect.stage|replace('_', ' ')|title }} | +{{ defect.reason | default('-') }} | +{{ defect.timestamp[:16] | replace('T', ' ') if defect.timestamp else 'N/A' }} | +{{ defect.sewing_task_id[:8] if defect.sewing_task_id else 'N/A' }}... | +
| Нет записей о браке за этот период. | |||||||||
| ID | Описание | Сумма (сом) | Дата | +
|---|---|---|---|
| {{ expense.id[:8] }}... | {{ expense.description }} | +{{ format_currency_py(expense.amount) }} | +{{ expense.timestamp[:16]|replace('T',' ') if expense.timestamp else 'N/A' }} | +
| Нет доп. расходов за этот период. | |||
{{ file.description }}
+ {% endif %} +Размер: {{ (file.size/1024)|round(1) }} КБ
+Загружен: {{ file.timestamp[:10] }}
+