{% extends "base.html" %} {% block title %}Vendas{% endblock %} {% block content %}

Vendas

Nova Venda
{# Busca e Filtros #}
{% set empresas_filtro = empresas if empresas is defined and empresas else app_empresa_empresas_disponiveis if app_empresa_empresas_disponiveis is defined else [] %}
{# Tabela de vendas #}
{% if vendas %}
{% if current_user.nivel_acesso in ['gerente', 'admin'] %} {% endif %} {% for venda in vendas %} {% if current_user.nivel_acesso in ['gerente', 'admin'] %} {% endif %} {% endfor %}
Nº Pedido Nº Documento Data Cliente EmpresaCusto DescontoValor Total Pagamento Online Status Ações
{{ venda.numero_pedido }} {% if venda.desconto_excecao %} Exceção {% endif %} {% if venda.tipo_documento and venda.numero_documento %} {% if venda.tipo_documento == 55 %} NF-e {% elif venda.tipo_documento == 65 %} NFC-e {% else %} {{ venda.tipo_documento }} {% endif %} {{ venda.numero_documento }} {% else %} - {% endif %} {{ venda.data_venda.strftime('%d/%m/%Y') if venda.data_venda else 'N/A' }} {{ venda.get_cliente_nome() }} {{ venda.empresa.nome_fantasia or venda.empresa.razao_social if venda.empresa else 'N/A' }} {% set custo_total = namespace(valor=0) %} {% for item in venda.itens %} {% if item.produto %} {# Buscar custo médio do produto (ProdutoEstoque) ou usar custo_operacao #} {% set custo_unitario = 0 %} {% if item.produto.estoques and item.produto.estoques|length > 0 %} {% set custo_unitario = item.produto.estoques[0].custo_medio or 0 %} {% endif %} {% if custo_unitario == 0 %} {% set custo_unitario = item.produto.custo_operacao or 0 %} {% endif %} {% set custo_total.valor = custo_total.valor + custo_unitario * item.quantidade %} {% endif %} {% endfor %} R$ {{ "%.2f"|format(custo_total.valor) }} {% if venda.desconto and venda.desconto > 0 %} R$ {{ "%.2f"|format(venda.desconto) }} {% if venda.desconto_excecao %}
Extra autorizado
{% endif %} {% else %} - {% endif %}
R$ {{ "%.2f"|format(venda.valor_total if venda.valor_total else 0) }} {% set online_label = venda.pagamento_online_label or 'Sem online' %} {% set online_badge = venda.pagamento_online_badge or 'secondary' %} {{ online_label }}
{{ venda.pagamento_online_detail or 'Venda local / balcão' }}
{% if venda.operacao_online_atual and venda.operacao_online_atual.referencia_externa %}
Ref. {{ venda.operacao_online_atual.referencia_externa }}
{% endif %}
{% if venda.status == 'aberto' %} Aberto {% elif venda.status == 'fechado' %} Fechado {% elif venda.status == 'faturado' %} Faturado {% elif venda.status == 'recebido' %} Recebido {% elif venda.status == 'entregue' %} Entregue {% elif venda.status == 'cancelado' %} Cancelado {% else %} {{ venda.status|default('Desconhecido')|replace('_', ' ')|title }} {% endif %} {% if venda.pagamento_online_status == 'pendente' and venda.status not in ['recebido', 'cancelado'] %}
A confirmar pgto.
{% endif %}
{% else %}
Nenhuma venda encontrada.
{% if status_filter == 'todos' and guardadas_finalizadas_count and guardadas_finalizadas_count > 0 %} {% endif %} {% endif %}
{# Modais de Timeline #} {% for venda in vendas %} {% endfor %} {% endblock %}