Example #1
0
        public void ConferePagamento(int idPedido)
        {
            var dataTitulo = new Model.Titulo().Query().SelectRaw("SUM(total) as total").Where("id_pedido", idPedido).Where("excluir", 0).FirstOrDefault();
            var dataPedido = new Model.Pedido().FindById(idPedido).Select("total").Where("excluir", 0).FirstOrDefault();

            if (dataTitulo.TOTAL > 0)
            {
                if (dataPedido.TOTAL > 0)
                {
                    if (dataTitulo.TOTAL != dataPedido.TOTAL)
                    {
                        //Model.Titulo _iTitulo = new Model.Titulo().Query().Where("pedido", idPedido).Where("excluir", "0").First<Model.Titulo>();
                        //Model.Titulo _iTitulo = new Model.Pedido().FindById(idPedido).Select("total").Where("excluir", 0).FirstOrDefault();

                        var _item = _titulo.Query().Where("id_pedido", idPedido).Where("excluir", "0").First <Model.Titulo>();

                        var diff = Validation.Round(Validation.ConvertToDouble(dataTitulo.TOTAL) - Validation.ConvertToDouble(dataPedido.TOTAL));
                        if (_item.Total > diff)
                        {
                            _item.Total    = Validation.Round(_item.Total - diff);
                            _item.Recebido = Validation.Round(_item.Recebido - diff);
                            _item.Save(_item, false);
                        }
                    }
                }
            }
        }
Example #2
0
        public IEnumerable <dynamic> GetDataPgtosLancados(int idPedido)
        {
            var data = new Model.Titulo().Query()
                       .LeftJoin("formapgto", "formapgto.id", "titulo.id_formapgto")
                       .Select("titulo.id", "titulo.total", "titulo.recebido", "titulo.vencimento",
                               "formapgto.nome as formapgto", "formapgto.id as formapgtoid")
                       .Where("titulo.excluir", 0)
                       .Where("titulo.id_pedido", idPedido)
                       .OrderByDesc("titulo.id");

            return(data.Get());
        }
Example #3
0
        public double GetLancados(int idPedido)
        {
            if (string.IsNullOrEmpty(idPedido.ToString()))
            {
                return(0);
            }

            var data = new Model.Titulo().Query().SelectRaw("SUM(recebido) as recebido").Where("id_pedido", idPedido)
                       .Where("excluir", 0).FirstOrDefault();

            return(Validation.ConvertToDouble(data.RECEBIDO ?? 0));
        }
Example #4
0
        public double GetTroco(int idPedido)
        {
            if (string.IsNullOrEmpty(idPedido.ToString()))
            {
                return(0);
            }

            var data = new Model.Titulo().Query().SelectRaw("SUM(recebido) as recebido, SUM(total) as total")
                       .Where("id_pedido", idPedido).Where("excluir", 0).FirstOrDefault();
            var total    = data.TOTAL ?? 0;
            var recebido = data.RECEBIDO ?? 0;

            return(Validation.ConvertToDouble(total - recebido));
        }
Example #5
0
        public IEnumerable <dynamic> GetDataTableTitulosGerados(string tela, string Search, int tipo, string dataInicial, string dataFinal)
        {
            var titulos = new Model.Titulo();

            var tipoPesquisa = tipo == 0 ? "titulo.vencimento" : "titulo.emissao";

            var search = "%" + Search + "%";
            var data   = titulos.Query()
                         .LeftJoin("formapgto", "formapgto.id", "titulo.id_formapgto")
                         .LeftJoin("pessoa", "pessoa.id", "titulo.id_pessoa")
                         .Select("titulo.id", "titulo.recebido", "titulo.vencimento", "titulo.emissao", "titulo.total",
                                 "titulo.id_pedido", "titulo.baixa_data", "titulo.baixa_total", "titulo.valor_liquido",
                                 "formapgto.nome as formapgto", "pessoa.nome", "pessoa.fantasia", "pessoa.rg", "pessoa.cpf")
                         .Where(tipoPesquisa, ">=", Validation.ConvertDateToSql(dataInicial))
                         .Where(tipoPesquisa, "<=", Validation.ConvertDateToSql(dataFinal))
                         .Where("titulo.excluir", 0)
                         .Where("titulo.tipo", tela)
                         .OrderByDesc("titulo.criado");

            switch (status)
            {
            case "Pendentes":
                data.Where
                (
                    q => q.Where("titulo.recebido", "=", 0)
                );
                break;

            case "Recebidos":
            case "Pagos":
                data.Where
                (
                    q => q.Where("titulo.recebido", "<>", 0)
                );
                break;
            }

            if (!string.IsNullOrEmpty(Search))
            {
                data.Where
                (
                    q => q.Where("pessoa.nome", "like", search)
                );
            }

            return(data.Get());
        }
Example #6
0
        public double GetRestante(int idPedido)
        {
            if (string.IsNullOrEmpty(idPedido.ToString()))
            {
                return(0);
            }

            var data = new Model.Titulo().Query().SelectRaw("SUM(total) as total").Where("id_pedido", idPedido)
                       .Where("excluir", 0).FirstOrDefault();
            var lancado = Validation.ConvertToDouble(data.TOTAL ?? 0);

            double restante = 0;

            if (lancado < GetTotalPedido(idPedido))
            {
                restante = lancado - GetTotalPedido(idPedido);
            }

            return(restante * -1);
        }
Example #7
0
        public void Imprimir(int idTitulo, string tipo = "Bobina 80mm", int modelo = 0)
        {
            if (IniFile.Read("Printer", "Comercial") == "Bobina 80mm" || tipo == "Bobina 80mm")
            {
                var printerModel = IniFile.Read("Model", "SAT");
                var printerPort  = IniFile.Read("Port", "SAT");

                if (printerModel == "Bematech")
                {
                    #region EMITENTE

                    var _emitente         = new Model.Pessoa();
                    var _emitenteEndereco = new PessoaEndereco();
                    var _emitenteContato  = new PessoaContato();

                    _emitente.RG  = Settings.Default.empresa_inscricao_estadual;
                    _emitente.CPF = Settings.Default.empresa_cnpj;

                    _emitente.Nome     = Settings.Default.empresa_razao_social;
                    _emitente.Fantasia = Settings.Default.empresa_nome_fantasia;

                    _emitenteEndereco.Rua    = Settings.Default.empresa_rua;
                    _emitenteEndereco.Nr     = Settings.Default.empresa_nr;
                    _emitenteEndereco.Bairro = Settings.Default.empresa_bairro;
                    _emitenteEndereco.Cidade = Settings.Default.empresa_cidade;
                    _emitenteEndereco.Cep    = Settings.Default.empresa_cep;
                    _emitenteEndereco.IBGE   = Settings.Default.empresa_ibge;
                    _emitenteEndereco.Estado = Settings.Default.empresa_estado;

                    #endregion EMITENTE

                    var _titulo       = new Model.Titulo().FindById(idTitulo).First <Model.Titulo>();
                    var _destinatario = new Model.Pessoa().FindById(_titulo.Id_Pessoa).FirstOrDefault <Model.Pessoa>();

                    int    iRetorno    = 0;
                    string linewithdot = "------------------------------------------------------------------";
                    string pLine       = "\r\n";

                    iRetorno = Bematech.ConfiguraModeloImpressora(7);
                    //iRetorno = Bematech.IniciaPorta(printerPort);
                    iRetorno = Bematech.IniciaPorta("USB");
                    iRetorno = Bematech.FormataTX(linewithdot + pLine, 1, 0, 0, 0, 0);

                    iRetorno = Bematech.ComandoTX(Validation.alignBematech(1), Validation.alignBematech(1).Length);
                    iRetorno = Bematech.FormataTX(Validation.CleanStringForFiscal(_emitente.Fantasia) + pLine, 3, 0, 0, 0, 1);
                    iRetorno = Bematech.FormataTX(Validation.CleanStringForFiscal(_emitenteEndereco.Rua) + ", " + Validation.CleanStringForFiscal(_emitenteEndereco.Nr) + " - " + Validation.CleanStringForFiscal(_emitenteEndereco.Bairro) + pLine, 1, 0, 0, 0, 0);
                    iRetorno = Bematech.FormataTX(Validation.CleanStringForFiscal(_emitenteEndereco.Cidade) + "/" + Validation.CleanStringForFiscal(_emitenteEndereco.Estado) + pLine, 1, 0, 0, 0, 0);

                    iRetorno = Bematech.FormataTX(linewithdot + pLine, 1, 0, 0, 0, 0);
                    iRetorno = Bematech.FormataTX("Extrato N." + _titulo.Id + pLine, 1, 0, 0, 0, 0);

                    if (_destinatario != null)
                    {
                        if (_titulo.Tipo == "Pagar")
                        {
                            iRetorno = Bematech.FormataTX("Fornecedor: " + _destinatario.Nome + pLine, 1, 0, 0, 0, 0);
                        }
                        else
                        {
                            iRetorno = Bematech.FormataTX("Cliente: " + _destinatario.Nome + pLine, 1, 0, 0, 0, 0);
                        }
                    }

                    iRetorno = Bematech.FormataTX("Vencimento: " + Validation.ConvertDateToForm(_titulo.Vencimento) + pLine, 1, 0, 0, 0, 0);

                    string formapgto = "";

                    switch (_titulo.Id_FormaPgto)
                    {
                    case 1:
                        formapgto = "Dinheiro";
                        break;

                    case 2:
                        formapgto = "Cheque";
                        break;

                    case 3:
                        formapgto = "Cartão de Débito";
                        break;

                    case 4:
                        formapgto = "Cartão de Crédito";
                        break;

                    case 5:
                        formapgto = "Crediário";
                        break;

                    case 6:
                        formapgto = "Boleto";
                        break;

                    default:
                        formapgto = "N/D";
                        break;
                    }

                    iRetorno = Bematech.FormataTX(AddSpaces("Tipo: " + Validation.CleanStringForFiscal(formapgto), "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Total)) + pLine), 1, 0, 0, 0, 0);
                    iRetorno = Bematech.FormataTX(linewithdot + pLine, 1, 0, 0, 0, 0);

                    if (_titulo.Recebido > 0)
                    {
                        try
                        {
                            iRetorno = Bematech.FormataTX(AddSpaces("Recebido: " + Validation.ConvertDateToForm(_titulo.Baixa_data), "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Recebido)) + pLine), 1, 0, 0, 0, 0);
                        }
                        catch (Exception)
                        {
                            iRetorno = Bematech.FormataTX(AddSpaces("Recebido: ", "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Recebido)) + pLine), 1, 0, 0, 0, 0);
                        }
                    }

                    iRetorno = Bematech.FormataTX(pLine, 1, 0, 0, 0, 0);
                    iRetorno = Bematech.FormataTX(pLine, 1, 0, 0, 0, 0);
                    iRetorno = Bematech.FormataTX(pLine, 1, 0, 0, 0, 0);

                    iRetorno = Bematech.AcionaGuilhotina(0);
                    iRetorno = Bematech.FechaPorta();
                }
                else
                {
                    #region EMITENTE

                    var _emitente         = new Model.Pessoa();
                    var _emitenteEndereco = new PessoaEndereco();
                    var _emitenteContato  = new PessoaContato();

                    _emitente.RG  = Settings.Default.empresa_inscricao_estadual;
                    _emitente.CPF = Settings.Default.empresa_cnpj;

                    _emitente.Nome     = Settings.Default.empresa_razao_social;
                    _emitente.Fantasia = Settings.Default.empresa_nome_fantasia;

                    _emitenteEndereco.Rua    = Settings.Default.empresa_rua;
                    _emitenteEndereco.Nr     = Settings.Default.empresa_nr;
                    _emitenteEndereco.Bairro = Settings.Default.empresa_bairro;
                    _emitenteEndereco.Cidade = Settings.Default.empresa_cidade;
                    _emitenteEndereco.Cep    = Settings.Default.empresa_cep;
                    _emitenteEndereco.IBGE   = Settings.Default.empresa_ibge;
                    _emitenteEndereco.Estado = Settings.Default.empresa_estado;

                    #endregion EMITENTE

                    var _titulo       = new Model.Titulo().FindById(idTitulo).First <Model.Titulo>();
                    var _destinatario = new Model.Pessoa().FindById(_titulo.Id_Pessoa).FirstOrDefault <Model.Pessoa>();

                    var printername = IniFile.Read("PrinterName", "Comercial");

                    if (printername == null)
                    {
                        return;
                    }

                    if (printername == "Selecione")
                    {
                        Alert.Message("Opps", "Você precisa configurar uma impressora.", Alert.AlertType.info);
                        return;
                    }

                    var printer = new Printer(printername);

                    printer.AlignCenter();
                    printer.BoldMode(_emitente.Fantasia);
                    printer.Append(_emitente.Nome);
                    printer.Append(_emitenteEndereco.Rua + ", " + _emitenteEndereco.Nr + " - " + _emitenteEndereco.Bairro);
                    printer.Append(_emitenteEndereco.Cidade + "/" + _emitenteEndereco.Estado);
                    printer.Append(_emitenteContato.Telefone);

                    printer.NewLines(2);
                    printer.Separator();

                    printer.BoldMode("Extrato N°" + _titulo.Id);

                    printer.Separator();

                    printer.AlignLeft();

                    if (_destinatario != null)
                    {
                        if (_titulo.Tipo == "Pagar")
                        {
                            printer.Append("Fornecedor: " + _destinatario.Nome);
                        }
                        else
                        {
                            printer.Append("Cliente: " + _destinatario.Nome);
                        }
                    }

                    printer.Append(("Vencimento: " + Validation.ConvertDateToForm(_titulo.Vencimento)));

                    string formapgto = "";

                    switch (_titulo.Id_FormaPgto)
                    {
                    case 1:
                        formapgto = "Dinheiro";
                        break;

                    case 2:
                        formapgto = "Cheque";
                        break;

                    case 3:
                        formapgto = "Cartão de Débito";
                        break;

                    case 4:
                        formapgto = "Cartão de Crédito";
                        break;

                    case 5:
                        formapgto = "Crediário";
                        break;

                    case 6:
                        formapgto = "Boleto";
                        break;

                    default:
                        formapgto = "N/D";
                        break;
                    }

                    printer.Append(AddSpaces("Tipo: " + Validation.CleanStringForFiscal(formapgto), "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Total))));
                    printer.Separator();

                    if (_titulo.Recebido > 0)
                    {
                        try
                        {
                            printer.Append(AddSpaces("Recebido: " + Validation.ConvertDateToForm(_titulo.Baixa_data), "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Recebido))));
                        }
                        catch (Exception)
                        {
                            printer.Append(AddSpaces("Recebido: ", "Total R$: " + Validation.FormatPrice(Validation.ConvertToDouble(_titulo.Recebido))));
                        }
                    }

                    printer.NewLines(5);

                    printer.FullPaperCut();
                    printer.PrintDocument();
                }
            }
        }
Example #8
0
        public bool AddPagamento(int idPedido, int formaPgto, string valorS, string inicio, string parcela = "1", int idTaxa = 0)
        {
            #region Variaveis

            var _mTaxa     = new Taxas();
            var data       = new Model.Titulo();
            var valor      = Validation.ConvertToDouble(valorS);
            var vencimento = DateTime.Now;

            if (Validation.ConvertToDouble(valorS) <= 0)
            {
                Alert.Message("Opss", "O valor informado é inválido!", Alert.AlertType.error);
                return(false);
            }

            if (idTaxa > 0)
            {
                _mTaxa = _mTaxa.FindById(idTaxa).FirstOrDefault <Taxas>();
            }

            if (idPedido > 0)
            {
                if (GetRestante(idPedido) <= 0)
                {
                    Alert.Message("Opss", "Valor total já recebido. Verifique os lançamentos!", Alert.AlertType.error);
                    return(false);
                }

                data.Id_Pedido = idPedido;

                var clienteId = new Model.Pedido().FindById(idPedido).Select("cliente").Where("excluir", 0)
                                .FirstOrDefault();
                data.Id_Pessoa = clienteId.CLIENTE ?? 0;
            }

            if (valor < 0)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(inicio))
            {
                vencimento = Validation.ConvertStringDateTime(inicio);
            }

            if (vencimento.ToString().Contains("01/01/0001"))
            {
                Alert.Message("Opss", "Data inválida", Alert.AlertType.error);
                return(false);
            }

            #endregion

            //2 CHEQUE 4 CARTÃO DE CRÉDITO 5 CREDIÁRIO 6 BOLETO
            if (parcela.IndexOf("+") > 0)
            {
                //15+20+30+50+70 / dias e parcelas

                var numeros = parcela.Split(new[] { "+" }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse)
                              .ToArray();

                var qtdDecimall = Validation.GetNumberOfDigits((decimal)valor);
                var qtdD        = qtdDecimall + 1;
                data.Total = Validation.Round(valor / Validation.ConvertToInt32(parcela), qtdD);

                for (var i = 0; i < numeros.Length; i++)
                {
                    vencimento = vencimento.AddDays(numeros[i]);

                    data.Id           = 0;
                    data.Id_FormaPgto = formaPgto;
                    data.Emissao      = Validation.DateNowToSql();
                    data.Vencimento   = Validation.ConvertDateToSql(vencimento);
                    data.Recebido     = data.Total;

                    double taxaAntecipacao = 0;
                    bool   parcelaJuros    = false;
                    if (formaPgto == 4)
                    {
                        if (_mTaxa.Antecipacao_Auto == 1)
                        {
                            taxaAntecipacao = _mTaxa.Taxa_Antecipacao;
                        }

                        var taxacredito            = valor / 100 * _mTaxa.Taxa_Credito;
                        var taxaparcelas           = valor / 100 * _mTaxa.Taxa_Parcela;
                        var taxaFixa               = _mTaxa.Taxa_Fixa / Validation.ConvertToInt32(parcela);
                        var taxaAntecipacaoParcela = taxaAntecipacao / Validation.ConvertToInt32(parcela);

                        if (_mTaxa.Parcela_Semjuros > 0)
                        {
                            if (i > _mTaxa.Parcela_Semjuros)
                            {
                                parcelaJuros       = true;
                                data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela - taxaparcelas) /
                                                     Validation.ConvertToInt32(parcela); // com juros
                            }
                            else
                            {
                                data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela) /
                                                     Validation.ConvertToInt32(parcela); // sem juros
                            }
                        }
                        else
                        {
                            data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela) /
                                                 Validation.ConvertToInt32(parcela);
                        }
                    }

                    data.Taxas    = $@"{_mTaxa.Taxa_Fixa}|{_mTaxa.Taxa_Credito}|{_mTaxa.Taxa_Parcela}|{taxaAntecipacao}|{_mTaxa.Dias_Receber}|{parcela}|{parcelaJuros}";
                    data.Id_Caixa = Home.idCaixa;
                    data.Tipo     = "Receber";

                    if (formaPgto == 1 || formaPgto == 3 || formaPgto == 4)
                    {
                        data.Baixa_data         = data.Vencimento;
                        data.Baixa_id_formapgto = formaPgto;
                        data.Baixa_total        = data.Total;
                    }

                    data.Save(data, false);
                }
            }
            else if (Validation.ConvertToInt32(parcela) > 0 && formaPgto != 1 && formaPgto != 3)
            {
                #region Validation.ConvertToInt32(parcela) > 0 && formaPgto != 1 && formaPgto != 3

                var qtdDecimall = Validation.GetNumberOfDigits((decimal)valor);
                var qtdD        = qtdDecimall + 1;
                data.Total = Validation.Round(valor / Validation.ConvertToInt32(parcela), 2);

                var count = 1;
                while (count <= Validation.ConvertToInt32(parcela))
                {
                    data.Id           = 0;
                    data.Id_FormaPgto = formaPgto;
                    data.Emissao      = Validation.DateNowToSql();
                    data.Vencimento   = Validation.ConvertDateToSql(vencimento.AddMonths(count));
                    data.Recebido     = data.Total;

                    double taxaAntecipacao = 0;
                    bool   parcelaJuros    = false;
                    if (formaPgto == 4)
                    {
                        if (_mTaxa.Antecipacao_Auto == 1)
                        {
                            taxaAntecipacao = _mTaxa.Taxa_Antecipacao;
                        }

                        // taxa de intermediação
                        var taxacredito            = valor / 100 * _mTaxa.Taxa_Credito;
                        var taxaparcelas           = valor / 100 * _mTaxa.Taxa_Parcela;
                        var taxaFixa               = _mTaxa.Taxa_Fixa / Validation.ConvertToInt32(parcela);
                        var taxaAntecipacaoParcela = taxaAntecipacao / Validation.ConvertToInt32(parcela);

                        if (_mTaxa.Parcela_Semjuros > 0)
                        {
                            if (count > _mTaxa.Parcela_Semjuros)
                            {
                                parcelaJuros       = true;
                                data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela - taxaparcelas) / Validation.ConvertToInt32(parcela); // com juros
                            }
                            else
                            {
                                data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela) / Validation.ConvertToInt32(parcela); // sem juros
                            }
                        }
                        else
                        {
                            data.Valor_Liquido = (valor - taxacredito - taxaFixa - taxaAntecipacaoParcela) / Validation.ConvertToInt32(parcela);
                        }
                    }

                    data.Taxas    = $@"{_mTaxa.Taxa_Fixa}|{_mTaxa.Taxa_Credito}|{_mTaxa.Taxa_Parcela}|{taxaAntecipacao}|{_mTaxa.Dias_Receber}|{parcela}|{parcelaJuros}";
                    data.Id_Caixa = Home.idCaixa;
                    data.Tipo     = "Receber";

                    if (formaPgto == 1 || formaPgto == 3 || formaPgto == 4)
                    {
                        data.Baixa_data         = data.Vencimento;
                        data.Baixa_id_formapgto = formaPgto;
                        data.Baixa_total        = data.Total;
                    }

                    data.Save(data, false);
                    count++;
                }

                #endregion

                ConferePagamento(idPedido);
            }
            else
            {
                //1 DINHEIRO 3 CARTÃO DE DÉBITO

                data.Id           = 0;
                data.Id_FormaPgto = formaPgto;
                data.Emissao      = Validation.DateNowToSql();
                data.Vencimento   = !string.IsNullOrEmpty(inicio)
                    ? Validation.ConvertDateToSql(inicio)
                    : Validation.DateNowToSql();

                double taxaAntecipacao = 0;
                if (formaPgto == 1 && valor > GetRestante(idPedido))
                {
                    data.Total    = GetRestante(idPedido);
                    data.Recebido = valor;
                }
                else
                {
                    data.Total    = valor;
                    data.Recebido = valor;

                    if (_mTaxa.Antecipacao_Auto == 1)
                    {
                        taxaAntecipacao = _mTaxa.Taxa_Antecipacao;
                    }

                    var taxadebito = valor / 100 * _mTaxa.Taxa_Debito;
                    data.Valor_Liquido = valor - taxadebito - _mTaxa.Taxa_Fixa - taxaAntecipacao;
                }

                data.Taxas    = $@"{_mTaxa.Taxa_Fixa}|{_mTaxa.Taxa_Debito}|{_mTaxa.Taxa_Parcela}|{taxaAntecipacao}|{_mTaxa.Dias_Receber}|{parcela}|{_mTaxa.Parcela_Semjuros}";
                data.Id_Caixa = Home.idCaixa;
                data.Tipo     = Home.pedidoPage == "Compras" ? "Pagar" : "Receber";

                if (formaPgto == 1 || formaPgto == 3 || formaPgto == 4)
                {
                    data.Baixa_data         = data.Vencimento;
                    data.Baixa_id_formapgto = formaPgto;
                    data.Baixa_total        = data.Total;
                }

                return(data.Save(data, false));
            }

            return(false);
        }
Example #9
0
        /// <summary>
        ///     Eventos do form
        /// </summary>
        public void Eventos()
        {
            Load += (s, e) =>
            {
                PayVerify = true;

                if (AddPedidos.PDV)
                {
                    // btn NF-e
                    btnNfe.Visible      = false;
                    button21.Visible    = false;
                    pictureBox6.Visible = false;
                }
            };

            Shown += (s, e) =>
            {
                Resolution.SetScreenMaximized(this);

                AddPedidos.BtnFinalizado = false;
                TelaReceber.Visible      = false;

                switch (Home.pedidoPage)
                {
                case "Orçamentos":
                    label13.Text = $@"Dados do Orçamento: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar um orçamento!";
                    break;

                case "Consignações":
                    label13.Text = $@"Dados da Consignação: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar uma consignãção!";
                    break;

                case "Devoluções":
                    label13.Text = $@"Dados da Devolução: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar uma devolução!";
                    break;

                case "Compras":
                    label13.Text = $@"Dados da Compra: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para adicionar uma compra!";

                    label15.Text = @"Á Pagar";
                    label1.Text  = @"Pagamentos";
                    //enviarEmail.Visible = false;
                    btnNfe.Visible    = false;
                    button21.Visible  = false;
                    btnCFeSat.Visible = false;
                    button22.Visible  = false;
                    break;

                default:
                    label13.Text = $@"Dados da Venda: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para adicionar uma venda!";
                    break;
                }

                if (HideFinalizar)
                {
                    btnCFeSat.Visible = false;
                    button22.Visible  = false;

                    btnNfe.Visible   = false;
                    button21.Visible = false;

                    btnConcluir.Visible = false;
                    button19.Visible    = false;

                    //btnImprimir.Left = 835;
                    //button20.Left = 830;
                    btnImprimir.Visible = false;
                    button20.Visible    = false;
                }

                if (IniFile.Read("Alimentacao", "Comercial") == "True")
                {
                    btnDividir.Visible = true;
                }

                mtxt.Visible  = false;
                mtxt2.Visible = false;

                GridListaFormaPgtos.Controls.Add(mtxt);
                GridListaFormaPgtos.Controls.Add(mtxt2);

                AtualizarDados();

                AddPedidos.BtnFinalizado = false;

                Dinheiro.Focus();
                Dinheiro.Select();

                var taxasSource = new ArrayList();
                var dataTaxa    = new Taxas().FindAll(new[] { "id", "nome" }).WhereFalse("excluir").Get <Taxas>();
                taxasSource.Add(new { Id = 0, Nome = "SELECIONE" });
                if (dataTaxa.Any())
                {
                    foreach (var item in dataTaxa)
                    {
                        taxasSource.Add(new { item.Id, item.Nome });
                    }
                }

                taxas.DataSource    = taxasSource;
                taxas.DisplayMember = "Nome";
                taxas.ValueMember   = "Id";
            };

            FormClosing += (s, e) =>
            {
                if (AddPedidos.BtnFinalizado)
                {
                    Application.OpenForms["AddPedidos"]?.Close();
                }
            };

            KeyDown                     += KeyDowns;
            Dinheiro.KeyDown            += KeyDowns;
            Cheque.KeyDown              += KeyDowns;
            Debito.KeyDown              += KeyDowns;
            Credito.KeyDown             += KeyDowns;
            Crediario.KeyDown           += KeyDowns;
            Boleto.KeyDown              += KeyDowns;
            Desconto.KeyDown            += KeyDowns;
            Acrescimo.KeyDown           += KeyDowns;
            GridListaFormaPgtos.KeyDown += KeyDowns;

            btnCFeSat.KeyDown += (s, e) =>
            {
                if (UserPermission.SetControl(btnCFeSat, pictureBox1, "fiscal_emissaocfe"))
                {
                    return;
                }

                KeyDowns(s, e);
            };

            btnNfe.KeyDown += (s, e) =>
            {
                if (!Support.CheckForInternetConnection())
                {
                    Alert.Message("Opps", "Você está sem conexão com a internet.", Alert.AlertType.warning);
                    return;
                }

                if (UserPermission.SetControl(btnNfe, pictureBox6, "fiscal_emissaonfe"))
                {
                    return;
                }

                KeyDowns(s, e);
            };

            btnImprimir.KeyDown += KeyDowns;
            btnConcluir.KeyDown += KeyDowns;
            btnSalvar.KeyDown   += KeyDowns;
            btnCancelar.KeyDown += KeyDowns;
            valor.KeyDown       += KeyDowns;
            parcelas.KeyDown    += KeyDowns;
            iniciar.KeyDown     += KeyDowns;

            btnImprimir.Click += (s, e) => { new Controller.Pedido().Imprimir(idPedido); };

            Debito.Click    += (s, e) => JanelasRecebimento("Cartão de Débito");
            Credito.Click   += (s, e) => JanelasRecebimento("Cartão de Crédito");
            Dinheiro.Click  += (s, e) => JanelasRecebimento("Dinheiro");
            Boleto.Click    += (s, e) => JanelasRecebimento("Boleto");
            Crediario.Click += (s, e) => JanelasRecebimento("Crediário");
            Cheque.Click    += (s, e) => JanelasRecebimento("Cheque");

            Desconto.Click  += (s, e) => JanelaDesconto();
            Acrescimo.Click += (s, e) => JanelaAcrescimo();
            Devolucao.Click += (s, e) => JanelaDevolucao();

            btnSalvar.Click   += (s, e) => BSalvar();
            btnCancelar.Click += (s, e) =>
            {
                PayVerify           = true;
                TelaReceber.Visible = false;
            };

            btnClose.Click += (s, e) =>
            {
                if (_controllerTitulo.GetLancados(idPedido) > 0)
                {
                    var text    = Home.pedidoPage == "Compras" ? "pagamentos" : "recebimentos";
                    var message = AlertOptions.Message("Atenção",
                                                       $"Os {text} lançados serão apagados,\n deseja continuar?", AlertBig.AlertType.warning,
                                                       AlertBig.AlertBtn.YesNo);
                    if (message)
                    {
                        foreach (DataGridViewRow row in GridListaFormaPgtos.Rows)
                        {
                            if (Convert.ToString(row.Cells[0].Value) != "")
                            {
                                _mTitulo.Remove(Validation.ConvertToInt32(row.Cells[0].Value), "ID", false);
                            }
                        }

                        AtualizarDados();

                        _mPedido        = _mPedido.FindById(idPedido).FirstOrDefault <Model.Pedido>();
                        _mPedido.status = 2;
                        _mPedido.Save(_mPedido);

                        Close();
                    }
                    else
                    {
                        return;
                    }
                }

                AddPedidos.BtnVoltar = true;
                Close();
            };

            btnDividir.Click += (s, e) =>
            {
                var itens = new ArrayList();
                if (PayVerify)
                {
                    var dataItens = _mPedidoItens.FindAll().Where("pedido", idPedido).WhereFalse("excluir")
                                    .Get <PedidoItem>();
                    if (dataItens.Any())
                    {
                        foreach (var item in dataItens)
                        {
                            itens.Add(new
                            {
                                item.Id,
                                item.Item,
                                item.xProd,
                                item.CEan,
                                item.CProd,
                                item.Quantidade,
                                item.Total
                            });
                        }
                    }

                    PedidoModalDividirConta.Itens = itens;
                }

                var form = new PedidoModalDividirConta {
                    TopMost = true
                };
                if (form.ShowDialog() == DialogResult.OK)
                {
                    valor.Text = Validation.FormatPrice(PedidoModalDividirConta.ValorDividido);
                }
            };

            btnConcluir.Click += (s, e) => { Concluir(); };

            iniciar.KeyPress += Masks.MaskBirthday;
            iniciar.KeyPress += Masks.MaskBirthday;
            valor.KeyPress   += (s, e) => Masks.MaskDouble(s, e);

            valor.TextChanged += (s, e) =>
            {
                var txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            mtxt2.TextChanged += (s, e) =>
            {
                var txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            GridListaFormaPgtos.CellDoubleClick += (s, e) =>
            {
                if (GridListaFormaPgtos.Columns[e.ColumnIndex].Name == "colExcluir")
                {
                    if (Convert.ToString(GridListaFormaPgtos.CurrentRow.Cells[4].Value) != "")
                    {
                        var id = Validation.ConvertToInt32(GridListaFormaPgtos.CurrentRow.Cells[0].Value);
                        _mTitulo.Remove(id);
                        AtualizarDados();
                    }
                }
            };

            GridListaFormaPgtos.CellBeginEdit += (s, e) =>
            {
                if (e.ColumnIndex == 2)
                {
                    //-----mtxt

                    mtxt.Mask = @"##/##/####";

                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt.Location = rec.Location;
                    mtxt.Size     = rec.Size;
                    mtxt.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt.Visible = true;
                }

                if (e.ColumnIndex == 3)
                {
                    //-----mtxt2

                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt2.Location = rec.Location;
                    mtxt2.Size     = rec.Size;
                    mtxt2.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt2.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt2.Visible = true;
                }
            };

            GridListaFormaPgtos.CellEndEdit += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt.Text;
                    mtxt.Visible = false;
                }

                if (mtxt2.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt2.Text;
                    mtxt2.Visible = false;
                }

                var ID = Validation.ConvertToInt32(GridListaFormaPgtos.Rows[e.RowIndex].Cells["colID"].Value);
                if (ID == 0)
                {
                    return;
                }

                var titulo = new Model.Titulo().FindById(ID).FirstOrDefault <Model.Titulo>();

                if (titulo == null)
                {
                    return;
                }

                DateTime parsed;
                if (DateTime.TryParse(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value.ToString(),
                                      out parsed))
                {
                    titulo.Vencimento =
                        Validation.ConvertDateToSql(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value);
                }
                else
                {
                    GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value =
                        Validation.ConvertDateToForm(titulo.Vencimento);
                }

                titulo.Total    = Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);
                titulo.Recebido =
                    Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);

                if (titulo.Save(titulo, false))
                {
                    //_controllerTitulo.GetDataTableTitulos(GridListaFormaPgtos, IdPedido);
                    Alert.Message("Pronto!", "Recebimento atualizado com sucesso.", Alert.AlertType.success);
                    AtualizarDados(false);
                }
                else
                {
                    Alert.Message("Opsss!", "Algo deu errado ao atualizar o recebimento.", Alert.AlertType.error);
                }
            };

            GridListaFormaPgtos.Scroll += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex,
                                                                          GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt.Location = rec.Location;
                }

                if (mtxt2.Visible)
                {
                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex,
                                                                          GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt2.Location = rec.Location;
                }
            };

            btnClearRecebimentos.Click += (s, e) =>
            {
                foreach (DataGridViewRow row in GridListaFormaPgtos.Rows)
                {
                    if (Convert.ToString(row.Cells[0].Value) != "")
                    {
                        _mTitulo.Remove(Validation.ConvertToInt32(row.Cells[0].Value), "ID", false);
                    }
                }

                AtualizarDados();

                _mPedido        = _mPedido.FindById(idPedido).FirstOrDefault <Model.Pedido>();
                _mPedido.status = 2;
                _mPedido.Save(_mPedido);
            };

            btnNfe.Click += (s, e) =>
            {
                if (!Support.CheckForInternetConnection())
                {
                    Alert.Message("Opps", "Você está sem conexão com a internet.", Alert.AlertType.warning);
                    return;
                }

                if (UserPermission.SetControl(btnNfe, pictureBox6, "fiscal_emissaonfe"))
                {
                    return;
                }

                Nfe();
            };

            btnCFeSat.Click += (s, e) =>
            {
                if (UserPermission.SetControl(btnCFeSat, pictureBox1, "fiscal_emissaocfe"))
                {
                    return;
                }

                Cfe();
            };
        }
Example #10
0
        /// <summary>
        /// Eventos do form
        /// </summary>
        public void Eventos()
        {
            KeyDown           += KeyDowns;
            Dinheiro.KeyDown  += KeyDowns;
            Cheque.KeyDown    += KeyDowns;
            Debito.KeyDown    += KeyDowns;
            Credito.KeyDown   += KeyDowns;
            Crediario.KeyDown += KeyDowns;
            Boleto.KeyDown    += KeyDowns;
            Desconto.KeyDown  += KeyDowns;
            Acrescimo.KeyDown += KeyDowns;

            btnSalvar.KeyDown   += KeyDowns;
            btnCancelar.KeyDown += KeyDowns;
            valor.KeyDown       += KeyDowns;
            parcelas.KeyDown    += KeyDowns;
            iniciar.KeyDown     += KeyDowns;

            Load += (s, e) =>
            {
                mtxt.Visible  = false;
                mtxt2.Visible = false;

                GridListaFormaPgtos.Controls.Add(mtxt);
                GridListaFormaPgtos.Controls.Add(mtxt2);

                AtualizarDados();

                if (_mNota.Status != "Pendente")
                {
                    progress5.Visible   = false;
                    pictureBox1.Visible = false;
                    label13.Visible     = false;
                    Next.Visible        = false;
                }
            };

            Debito.Click    += (s, e) => JanelasRecebimento("Cartão de Débito");
            Credito.Click   += (s, e) => JanelasRecebimento("Cartão de Crédito");
            Dinheiro.Click  += (s, e) => JanelasRecebimento("Dinheiro");
            Boleto.Click    += (s, e) => JanelasRecebimento("Boleto");
            Crediario.Click += (s, e) => JanelasRecebimento("Crediário");
            Cheque.Click    += (s, e) => JanelasRecebimento("Cheque");

            Desconto.Click  += (s, e) => JanelaDesconto();
            Acrescimo.Click += (s, e) => JanelaAcrescimo();

            btnSalvar.Click   += (s, e) => bSalvar();
            btnCancelar.Click += (s, e) => TelaReceber.Visible = false;

            iniciar.KeyPress += (s, e) => Masks.MaskBirthday(s, e);
            iniciar.KeyPress += (s, e) => Masks.MaskBirthday(s, e);
            valor.KeyPress   += (s, e) => Masks.MaskDouble(s, e);

            valor.TextChanged += (s, e) =>
            {
                TextBox txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            GridListaFormaPgtos.CellDoubleClick += (s, e) =>
            {
                if (GridListaFormaPgtos.Columns[e.ColumnIndex].Name == "colExcluir")
                {
                    Console.WriteLine(GridListaFormaPgtos.CurrentRow.Cells[4].Value);
                    if (Convert.ToString(GridListaFormaPgtos.CurrentRow.Cells[4].Value) != "")
                    {
                        int id = Validation.ConvertToInt32(GridListaFormaPgtos.CurrentRow.Cells[0].Value);
                        _mTitulo.Remove(id);
                        AtualizarDados();
                    }
                }
            };

            btnClearRecebimentos.Click += (s, e) =>
            {
                foreach (DataGridViewRow row in GridListaFormaPgtos.Rows)
                {
                    if (Convert.ToString(row.Cells[0].Value) != "")
                    {
                        _mTitulo.Remove(Validation.ConvertToInt32(row.Cells[0].Value), "ID", false);
                    }
                }

                AtualizarDados();
            };

            Next.Click += (s, e) => OpenForm.Show <TelaFinal>(this);

            Back.Click += (s, e) => Close();

            mtxt2.TextChanged += (s, e) =>
            {
                TextBox txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            GridListaFormaPgtos.CellBeginEdit += (s, e) =>
            {
                if (e.ColumnIndex == 2)
                {
                    //-----mtxt

                    mtxt.Mask = "##/##/####";

                    Rectangle rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt.Location = rec.Location;
                    mtxt.Size     = rec.Size;
                    mtxt.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt.Visible = true;
                }

                if (e.ColumnIndex == 3)
                {
                    //-----mtxt2

                    Rectangle rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt2.Location = rec.Location;
                    mtxt2.Size     = rec.Size;
                    mtxt2.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt2.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt2.Visible = true;
                }
            };

            GridListaFormaPgtos.CellEndEdit += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt.Text;
                    mtxt.Visible = false;
                }

                if (mtxt2.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt2.Text;
                    mtxt2.Visible = false;
                }

                int ID = Validation.ConvertToInt32(GridListaFormaPgtos.Rows[e.RowIndex].Cells["colID"].Value);

                if (ID == 0)
                {
                    return;
                }

                var titulo = new Model.Titulo().FindById(ID).FirstOrDefault <Model.Titulo>();

                if (titulo == null)
                {
                    return;
                }

                DateTime parsed;
                if (DateTime.TryParse(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value.ToString(), out parsed))
                {
                    titulo.Vencimento = Validation.ConvertDateToSql(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value);
                }
                else
                {
                    GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value = Validation.ConvertDateToForm(titulo.Vencimento);
                }

                titulo.Total    = Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);
                titulo.Recebido = Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);

                if (titulo.Save(titulo, false))
                {
                    //_controllerTitulo.GetDataTableTitulos(GridListaFormaPgtos, IdPedido);
                    Alert.Message("Pronto!", "Recebimento atualizado com sucesso.", Alert.AlertType.success);
                    AtualizarDados(false);
                }
                else
                {
                    Alert.Message("Opsss!", "Algo deu errado ao atualizar o recebimento.", Alert.AlertType.error);
                }
            };

            GridListaFormaPgtos.Scroll += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    Rectangle rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex, GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt.Location = rec.Location;
                }

                if (mtxt2.Visible)
                {
                    Rectangle rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex, GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt2.Location = rec.Location;
                }
            };
        }