223 lines
10 KiB
C#
223 lines
10 KiB
C#
using CPM;
|
|
using MLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI.Dashboards.Cadastro
|
|
{
|
|
public class VendasPanel : FormularioModelo
|
|
{
|
|
// Container de abas para as 27 propriedades do modelo
|
|
private TabControl? tabVendas;
|
|
|
|
// --- ABA 1: RESUMO DO PEDIDO & CLIENTE ---
|
|
private LV_TEXTBOX1? txtIdVendas, txtCodigo, txtCliente, txtOperador, txtOperador2, txtDia, txtSituacaoV;
|
|
|
|
// --- ABA 2: FINANCEIRO E VALORES DE VENDA ---
|
|
private LV_TEXTBOX1? txtTotal, txtDesconto, txtTotalGeral, txtTotalServicos, txtTotalPecas, txtComissao, txtComissaoFixar;
|
|
|
|
// --- ABA 3: EXPEDIÇÃO, LOGÍSTICA & INTEGRAÇÃO ---
|
|
private LV_TEXTBOX1? txtTotalFrete, txtTransportadora, txtRastreio, txtGerouConta;
|
|
|
|
// --- ABA 4: FATURAMENTO FISCAL E OBSERVAÇÕES ---
|
|
private LV_TEXTBOX1? txtNfTipo, txtNfNumero, txtNfcNumero, txtNfsNumero, txtCupomNum, txtCancelada, txtObsVenda, txtObsVendaInterna;
|
|
|
|
public VendasPanel()
|
|
{
|
|
this.Titulo = "PDV - CENTRALIZADOR DE VENDAS E FATURAMENTO";
|
|
MontarInterfaceCompleta();
|
|
}
|
|
|
|
private void MontarInterfaceCompleta()
|
|
{
|
|
tabVendas = new TabControl
|
|
{
|
|
Location = new Point(10, 10),
|
|
Size = new Size(1060, 520),
|
|
Font = new Font("Segoe UI", 9.5f)
|
|
};
|
|
|
|
var tpGeral = new TabPage("1. Cabeçalho da Venda");
|
|
var tpValores = new TabPage("2. Totais e Precificação");
|
|
var tpLogistica = new TabPage("3. Despacho e Logística");
|
|
var tpFiscal = new TabPage("4. Fiscal & Observações");
|
|
|
|
tabVendas.TabPages.AddRange([tpGeral, tpValores, tpLogistica, tpFiscal]);
|
|
content.Controls.Add(tabVendas);
|
|
|
|
ConfigurarAbaGeral(tpGeral);
|
|
ConfigurarAbaValores(tpValores);
|
|
ConfigurarAbaLogistica(tpLogistica);
|
|
ConfigurarAbaFiscal(tpFiscal);
|
|
}
|
|
|
|
private void ConfigurarAbaGeral(TabPage tp)
|
|
{
|
|
tp.Controls.Add(CreateSectionHeader("Identificação Básica do Fluxo Comercial", 15));
|
|
txtIdVendas = AddInput(tp, "ID VENDA (SISTEMA)", 20, 50, 130, 28, true);
|
|
txtCodigo = AddInput(tp, "CÓDIGO PEDIDO / ORÇAMENTO", 165, 50, 180, 28);
|
|
txtDia = AddInput(tp, "DATA DA VENDA", 360, 50, 160, 28);
|
|
txtSituacaoV = AddInput(tp, "SITUAÇÃO / STATUS", 535, 50, 150, 28);
|
|
|
|
tp.Controls.Add(CreateSectionHeader("Operadores e Cliente Vinculado", 115));
|
|
txtCliente = AddInput(tp, "CLIENTE (NOME / RAZÃO SOCIAL)", 20, 150, 665, 28);
|
|
txtOperador = AddInput(tp, "OPERADOR PRINCIPAL (CAIXA / VENDEDOR)", 20, 210, 325, 28);
|
|
txtOperador2 = AddInput(tp, "OPERADOR 2 (ASSISTENTE / GERENTE)", 360, 210, 325, 28);
|
|
}
|
|
|
|
private void ConfigurarAbaValores(TabPage tp)
|
|
{
|
|
tp.Controls.Add(CreateSectionHeader("Divisão de Subtotais do Cupom / Pedido", 15));
|
|
txtTotalPecas = AddInput(tp, "TOTAL PRODUTOS / PEÇAS (+)", 20, 50, 210, 28);
|
|
txtTotalServicos = AddInput(tp, "TOTAL SERVIÇOS (+)", 245, 50, 210, 28);
|
|
txtDesconto = AddInput(tp, "DESCONTO APLICADO (-)", 470, 50, 215, 28);
|
|
|
|
tp.Controls.Add(CreateSectionHeader("Fechamento Líquido e Comissionamento", 115));
|
|
txtTotal = AddInput(tp, "SUBTOTAL BRUTO (R$)", 20, 150, 210, 28);
|
|
txtTotalGeral = AddInput(tp, "TOTAL GERAL LÍQUIDO (R$)", 245, 150, 210, 28);
|
|
|
|
txtComissao = AddInput(tp, "COMISSÃO OPERADOR (R$ ou %)", 20, 210, 210, 28);
|
|
txtComissaoFixar = AddInput(tp, "VALOR COMISSÃO FIXA (R$)", 245, 210, 210, 28);
|
|
}
|
|
|
|
private void ConfigurarAbaLogistica(TabPage tp)
|
|
{
|
|
tp.Controls.Add(CreateSectionHeader("Custos e Vinculações de Despacho", 15));
|
|
txtTotalFrete = AddInput(tp, "VALOR DO FRETE (R$)", 20, 50, 180, 28);
|
|
txtTransportadora = AddInput(tp, "TRANSPORTADORA PARCEIRA", 215, 50, 465, 28);
|
|
txtRastreio = AddInput(tp, "CÓDIGO DE RASTREAMENTO DO OBJETO", 20, 115, 660, 28);
|
|
|
|
tp.Controls.Add(CreateSectionHeader("Status Financeiro no Contas a Receber", 185));
|
|
txtGerouConta = AddInput(tp, "GEROU CONTA FINANCEIRA? (S/N)", 20, 220, 250, 28);
|
|
}
|
|
|
|
private void ConfigurarAbaFiscal(TabPage tp)
|
|
{
|
|
tp.Controls.Add(CreateSectionHeader("Documentação Fiscal Emitida (NF-e / NFC-e / NFS-e)", 15));
|
|
txtNfTipo = AddInput(tp, "TIPO DA NOTA (E/S)", 20, 50, 130, 28);
|
|
txtNfNumero = AddInput(tp, "NÚMERO NF-E", 165, 50, 160, 28);
|
|
txtNfcNumero = AddInput(tp, "NÚMERO NFC-E (CUPOM)", 340, 50, 160, 28);
|
|
txtNfsNumero = AddInput(tp, "NÚMERO NFS-E (SERVIÇO)", 515, 50, 160, 28);
|
|
|
|
txtCupomNum = AddInput(tp, "NÚMERO CONTROLE INTEGRAL / CUPOM", 20, 115, 225, 28);
|
|
txtCancelada = AddInput(tp, "VENDA CANCELADA? (S/N)", 260, 115, 215, 28);
|
|
|
|
tp.Controls.Add(CreateSectionHeader("Observações do Pedido", 185));
|
|
txtObsVenda = AddInput(tp, "OBSERVAÇÕES PÚBLICAS (SAÍDA NA NOTA/IMPRESSÃO)", 20, 220, 660, 28);
|
|
txtObsVendaInterna = AddInput(tp, "OBSERVAÇÕES INTERNAS (RESTRITO AO SISTEMA)", 20, 280, 660, 28);
|
|
}
|
|
|
|
// --- MÉTODOS OBRIGATÓRIOS DO FORMULÁRIO MODELO ---
|
|
|
|
protected override void OnNovo()
|
|
{
|
|
void LimparCamposFormulario(Control.ControlCollection controls)
|
|
{
|
|
foreach (Control c in controls)
|
|
{
|
|
if (c is LV_TEXTBOX1 txt && !txt.ReadOnly) txt.Text = string.Empty;
|
|
if (c.HasChildren) LimparCamposFormulario(c.Controls);
|
|
}
|
|
}
|
|
|
|
if (tabVendas != null)
|
|
{
|
|
LimparCamposFormulario(tabVendas.Controls);
|
|
tabVendas.SelectedIndex = 0;
|
|
}
|
|
|
|
if (txtIdVendas != null) txtIdVendas.Text = "0";
|
|
if (txtDia != null) txtDia.Text = DateTime.Today.ToString("dd/MM/yyyy");
|
|
if (txtSituacaoV != null) txtSituacaoV.Text = "ABERTA";
|
|
if (txtGerouConta != null) txtGerouConta.Text = "N";
|
|
if (txtCancelada != null) txtCancelada.Text = "N";
|
|
|
|
// Seta valores string como padrões limpos para evitar nulos visuais
|
|
if (txtTotal != null) txtTotal.Text = "0,00";
|
|
if (txtDesconto != null) txtDesconto.Text = "0,00";
|
|
if (txtTotalGeral != null) txtTotalGeral.Text = "0,00";
|
|
if (txtTotalServicos != null) txtTotalServicos.Text = "0,00";
|
|
if (txtTotalPecas != null) txtTotalPecas.Text = "0,00";
|
|
if (txtTotalFrete != null) txtTotalFrete.Text = "0,00";
|
|
if (txtComissao != null) txtComissao.Text = "0,00";
|
|
if (txtComissaoFixar != null) txtComissaoFixar.Text = "0,00";
|
|
|
|
txtCodigo?.Focus();
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtCliente?.Text))
|
|
{
|
|
MessageBox.Show("A definição do cliente é mandatória para faturar a venda.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
if (tabVendas != null) tabVendas.SelectedIndex = 0;
|
|
txtCliente?.Focus();
|
|
return;
|
|
}
|
|
|
|
int idVenda = string.IsNullOrEmpty(txtIdVendas?.Text) ? 0 : Convert.ToInt32(txtIdVendas.Text);
|
|
|
|
// Mapeamento absoluto de todas as 27 propriedades da classe ModeloVendas
|
|
// Como suas propriedades são todas string, passamos o fallback 'string.Empty' ou '0,00'
|
|
var venda = new ModeloVendas
|
|
{
|
|
ID_VENDAS = idVenda,
|
|
CODIGO = txtCodigo?.Text ?? string.Empty,
|
|
OPERADOR = txtOperador?.Text ?? string.Empty,
|
|
TOTAL = txtTotal?.Text ?? "0,00",
|
|
DIA = txtDia?.Text ?? string.Empty,
|
|
COMISSAO = txtComissao?.Text ?? "0,00",
|
|
CLIENTE = txtCliente.Text,
|
|
DESCONTO = txtDesconto?.Text ?? "0,00",
|
|
TOTAL_GERAL = txtTotalGeral?.Text ?? "0,00",
|
|
TOTAL_SERVICOS = txtTotalServicos?.Text ?? "0,00",
|
|
TOTAL_PECAS = txtTotalPecas?.Text ?? "0,00",
|
|
TOTAL_IMPOSTOS = "0,00", // Fallback padrão de tributos
|
|
TOTAL_FRETE = txtTotalFrete?.Text ?? "0,00",
|
|
TRANSPORTADORA = txtTransportadora?.Text ?? string.Empty,
|
|
NF_TIPO = txtNfTipo?.Text ?? string.Empty,
|
|
SITUACAO_V = txtSituacaoV?.Text ?? string.Empty,
|
|
NF_NUMERO = txtNfNumero?.Text ?? string.Empty,
|
|
OBS_VENDA = txtObsVenda?.Text ?? string.Empty,
|
|
GEROU_CONTA = txtGerouConta?.Text ?? "N",
|
|
CUPOM_NUM = txtCupomNum?.Text ?? string.Empty,
|
|
OPERADOR2 = txtOperador2?.Text ?? string.Empty,
|
|
COMISSAO_FIXA = txtComissaoFixar?.Text ?? "0,00",
|
|
RASTREIO = txtRastreio?.Text ?? string.Empty,
|
|
OBS_VENDA_INTERNA = txtObsVendaInterna?.Text ?? string.Empty,
|
|
CANCELADA = txtCancelada?.Text ?? "N",
|
|
NFC_NUMERO = txtNfcNumero?.Text ?? string.Empty,
|
|
NFS_NUMERO = txtNfsNumero?.Text ?? string.Empty
|
|
};
|
|
|
|
// Objeto completo pronto para a BLL gerenciar validações fiscais e dar o INSERT/UPDATE
|
|
MessageBox.Show($"Venda sob o código '{venda.CODIGO}' processada!", "LevelOS - PDV", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
if (tabVendas != null) tabVendas.SelectedIndex = 0;
|
|
txtCodigo?.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (MessageBox.Show("Excluir uma venda pode comprometer a escrituração fiscal e os saldos de estoque. Deseja cancelar a venda em vez disso?", "LevelOS - Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
|
|
{
|
|
if (txtCancelada != null) txtCancelada.Text = "S";
|
|
OnSalvar();
|
|
}
|
|
}
|
|
|
|
protected override void OnLocalizar()
|
|
{
|
|
// Aciona o grid de histórico geral de cupons e faturamentos
|
|
}
|
|
|
|
protected override void OnCancelar()
|
|
{
|
|
OnNovo();
|
|
}
|
|
}
|
|
} |