{% macro br(val) %}R$ {{ '%.2f'|format((val or 0)|float) | replace('.', ',') }}{% endmacro %} {% set subtotal_venda = (venda.subtotal|default(venda.valor_bruto|default(0), true)|float) if venda.subtotal is defined or venda.valor_bruto is defined else (venda.itens | sum(attribute='valor_total')) %} {% set desconto_valor = (venda.desconto|default(venda.valor_desconto|default(0), true)|float) %} {% set acrescimo_valor = (venda.acrescimo|default(venda.valor_acrescimo|default(0), true)|float) %} {% set valor_total_calc = (valor_total|default(venda.valor_total|default(0), true)|float) %} {% set _nome_empresa = (empresa.nome_fantasia or empresa.nome or empresa.razao_social or 'CAPESYSTEM') if empresa else 'CAPESYSTEM' %} {% set _razao = (empresa.razao_social or empresa.nome or '') if empresa else '' %} {% set _status = (venda.status or '')|lower %} {% set _eh_fiscal = (venda.chave_documento and venda.chave_documento|length == 44) %} {% set _cliente_obj = venda.pessoa or venda.cliente %} {% set _cliente_nome = (_cliente_obj.nome if _cliente_obj else '') %} {% set _cliente_doc = (_cliente_obj.cpf_cnpj if _cliente_obj and _cliente_obj.cpf_cnpj is defined else (_cliente_obj.cnpj_cpf if _cliente_obj and _cliente_obj.cnpj_cpf is defined else (_cliente_obj.cpf if _cliente_obj and _cliente_obj.cpf is defined else (_cliente_obj.cnpj if _cliente_obj and _cliente_obj.cnpj is defined else '')))) %} {% set _cliente_fone = (_cliente_obj.telefone if _cliente_obj and _cliente_obj.telefone is defined and _cliente_obj.telefone else (_cliente_obj.celular if _cliente_obj and _cliente_obj.celular is defined else '')) %} {% set _data_ref = venda.data_venda or venda.data_criacao or venda.data_fechamento or venda.data_recebimento %} {% set _titulo_doc = 'DOCUMENTO AUXILIAR DE VENDA' %} {% set _faixa_status = '' %} {% if _status in ['aberto', 'digitacao', 'fechado'] %} {% set _titulo_doc = 'PEDIDO / ORÇAMENTO' %} {% set _faixa_status = '*** PEDIDO / ORÇAMENTO - NÃO FISCAL ***' %} {% elif _status == 'cancelado' %} {% set _titulo_doc = 'PEDIDO CANCELADO' %} {% set _faixa_status = '*** PEDIDO CANCELADO - SEM VALOR FISCAL ***' %} {% elif not _eh_fiscal %} {% set _faixa_status = '*** NÃO É DOCUMENTO FISCAL ***' %} {% endif %} {% if empresa and empresa.logo %}
{% if empresa.logo.startswith('data:') %} {% else %} {% endif %}
{% endif %}
{{ _nome_empresa.upper() }}
{% if _razao and _razao.upper() != _nome_empresa.upper() %}
{{ _razao }}
{% endif %} {% if empresa %} {% set _end = (empresa.logradouro or empresa.endereco or '') %} {% set _num = (empresa.numero or '') %} {% set _bairro = (empresa.bairro or '') %} {% set _cidade = (empresa.municipio or empresa.cidade or '') %} {% set _uf = (empresa.uf or '') %} {% set _cep_raw = (empresa.cep or '')|replace('.','')|replace('-','')|replace(' ','') %} {% if _end %}
{{ _end }}{% if _num %}, {{ _num }}{% endif %}
{% endif %} {% if _bairro %}
{{ _bairro }}
{% endif %} {% if _cidade %}
{{ _cidade }}{% if _uf %}/{{ _uf }}{% endif %}{% if _cep_raw|length == 8 %} - CEP: {{ _cep_raw[:5] }}-{{ _cep_raw[5:] }}{% endif %}
{% endif %} {% if empresa.cnpj %}
CNPJ: {{ empresa.cnpj }}
{% endif %} {% if empresa.telefone %}
Fone: {{ empresa.telefone }}
{% endif %} {% endif %}
{{ _titulo_doc }}
{% if _faixa_status %}
{{ _faixa_status }}
{% endif %}
Nº {{ venda.numero_pedido or venda.id }} {% if _data_ref %}{{ _data_ref.strftime('%d/%m/%Y %H:%M') }}{% else %}-{% endif %}
Status: {{ (_status or '---')|upper }} Operador: {{ venda.usuario.username if venda.usuario and venda.usuario.username else current_user.username }}
{% if venda.vendedor_nome or (venda.vendedor and venda.vendedor.nome) %}
Vendedor: {{ venda.vendedor_nome or venda.vendedor.nome }}
{% endif %} {% if venda.forma_pagamento %}
Pagamento: {{ venda.forma_pagamento }}
{% endif %} {% if venda.condicao_pagamento %}
Condição: {{ venda.condicao_pagamento }}
{% endif %}
{% if _cliente_nome and _cliente_nome not in ('Consumidor Final', 'CONSUMIDOR', '', 'Cliente não informado', 'Cliente nao informado') %}
CLIENTE:
  {{ _cliente_nome }}
{% if _cliente_doc %}
  CPF/CNPJ: {{ _cliente_doc }}
{% endif %} {% if _cliente_fone %}
  Fone: {{ _cliente_fone }}
{% endif %} {% else %}
CLIENTE: Consumidor Final
{% endif %}
{% for item in venda.itens %} {% endfor %}
COD DESCRIÇÃO QTD UNIT TOTAL
{{ (item.produto.codigo_produto if item.produto and item.produto.codigo_produto else '') or loop.index }} {{ item.descricao or (item.produto.nome if item.produto else 'Produto') }} {% if item.embalagem %}
{{ item.embalagem.nome }}
{% endif %}
{%- set _qtd = (item.quantidade or 0)|float -%} {%- if _qtd == (_qtd | int) -%} {{ _qtd | int }} {%- else -%} {{ '%.3f'|format(_qtd) | replace('.', ',') }} {%- endif -%} {{ '%.2f'|format((item.valor_unitario or 0)|float) | replace('.', ',') }} {{ '%.2f'|format((item.valor_total or 0)|float) | replace('.', ',') }}
{% set _total_un = venda.itens | sum(attribute='quantidade') %} QTD ITENS: {{ venda.itens | length }}  |   TOTAL UN: {%- if _total_un == (_total_un | int) -%} {{ _total_un | int }} {%- else -%} {{ '%.3f'|format(_total_un) | replace('.', ',') }} {%- endif -%}
{% if desconto_valor > 0 or acrescimo_valor > 0 %}
Subtotal:{{ br(subtotal_venda) }}
{% endif %} {% if desconto_valor > 0 %}
(-) Desconto:{{ br(desconto_valor) }}
{% endif %} {% if acrescimo_valor > 0 %}
(+) Acréscimo:{{ br(acrescimo_valor) }}
{% endif %}
TOTAL {{ br(valor_total_calc) }}
{% if pagamentos %}
PAGAMENTO DETALHADO
{% for pg in pagamentos %} {% set _forma = pg.get('forma_nome') or pg.get('forma') or pg.get('tipo') or 'Pagamento' %} {% set _valor = (pg.get('valor') if pg.get('valor') is not none else (pg.get('valor_recebido') if pg.get('valor_recebido') is not none else 0)) | float %} {% set _recebido = (pg.get('valor_recebido') if pg.get('valor_recebido') is not none else (pg.get('valor_pago') if pg.get('valor_pago') is not none else _valor)) | float %} {% set _troco = (pg.get('troco') or 0) | float %}
{{ loop.index }}. {{ _forma }}
  Valor:{{ br(_valor) }}
{% if (_recebido - _valor) | abs > 0.009 %}
  Recebido:{{ br(_recebido) }}
{% endif %} {% if _troco > 0 %}
  Troco:{{ br(_troco) }}
{% endif %}
{% endfor %} {% if total_troco and total_troco > 0 %}
TROCO {{ br(total_troco) }}
{% endif %}
{% elif venda.forma_pagamento or venda.condicao_pagamento %}
CONDIÇÕES COMERCIAIS
{% if venda.forma_pagamento %}
Pagamento:{{ venda.forma_pagamento }}
{% endif %} {% if venda.condicao_pagamento %}
Condição:{{ venda.condicao_pagamento }}
{% endif %}
{% endif %} {% if venda.observacoes or venda.observacoes_internas %}
OBSERVAÇÕES:
{{ venda.observacoes or venda.observacoes_internas }}
{% endif %} {% if _eh_fiscal %}
CHAVE DE ACESSO
{{ venda.chave_documento }}
{% elif _faixa_status and _status not in ['aberto', 'digitacao', 'fechado', 'cancelado'] %}
{{ _faixa_status }}
{% endif %}
Voltar