Beispiel #1
0
        protected void btPrint_Click(object sender, EventArgs e)
        {
            bool    bParcUnica = false;
            bool    bParcNormal = false;
            bool    bAnoAtual = false;
            bool    bAnoAnterior = false;
            bool    bFind = false;
            bool    bEnvProt = false;
            decimal _valor_ajuizado = 0, _valor_Honorario = 0;

            divModal.Visible = false;
            Tributario_bll tributario_Class = new Tributario_bll("GTIconnection");

            bRefis       = tributario_Class.IsRefis();
            nPlano       = Convert.ToInt32(PlanoLabel.Text);
            lblmsg.Text  = "";
            lblMsg2.Text = "";
            if (bGerado)
            {
                ShowResult(false);
                Response.Write("<script>alert('A guia já foi gerada!');</script>");
                return;
            }

            if (TableResumo.Rows[0].Cells[1].Text == "0,00")
            {
                lblMsg2.Text = "Selecione os débitos que deseja pagar.";
            }
            else
            {
                foreach (GridViewRow row in grdMain.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        if ((row.FindControl("chkRow") as CheckBox).Checked)
                        {
                            if (Convert.ToInt16(row.Cells[4].Text) == 0)
                            {
                                bParcUnica = true;
                            }
                            if (Convert.ToInt16(row.Cells[4].Text) != 0)
                            {
                                bParcNormal = true;
                            }

                            if (Convert.ToDateTime(row.Cells[6].Text) <= Convert.ToDateTime("30/06/2019"))
                            {
                                bAnoAnterior = true;
                            }
                            if (Convert.ToDateTime(row.Cells[6].Text) > Convert.ToDateTime("30/06/2019"))
                            {
                                bAnoAtual = true;
                            }

                            if (Convert.ToInt16(row.Cells[2].Text.Substring(0, 3)) == 5)
                            {
                                if (Convert.ToDateTime(row.Cells[6].Text) > Convert.ToDateTime("05/01/2015") && !bRefis)
                                {
                                    bGerado      = false;
                                    lblMsg2.Text = "ISS Variável com vencimento após 01/05/2015 não pode ser pago por DAM.";
                                    return;
                                }
                            }
                            else
                            {
                                //if (row.Cells[12].Text == "SIM" && row.Cells[13].Text.Substring(0, 1) == "N") {
                                if (row.Cells[12].Text == "SIM")
                                {
                                    bFind            = true;
                                    _valor_ajuizado += Convert.ToDecimal(row.Cells[11].Text);
                                }
                            }
                            if (row.Cells[14].Text == "SIM")
                            {
                                bEnvProt = true;
                            }
                        }
                    }
                }
            }

            if (bEnvProt)
            {
                lblMsg2.Text = "Débitos enviados para protesto não podem ser pagos através de DAM";
                return;
            }


            if (bFind)
            {
                _valor_Honorario = (_valor_ajuizado * (decimal)0.1);
            }

            if (bRefis)
            {
                if (bAnoAnterior && bAnoAtual)
                {
                    bGerado = false;
                    nPlano  = 0;
                    //lblMsg2.Text = "Não é possível pagar débitos de 2017 com outros anos pelo Refis.";
                    lblMsg2.Text  = "Não é possível pagar débitos anteriores a 30/06/2019 com débitos posteriores durante Refis. ";
                    lblMsg2.Text += "Será necessário emitir dois boletos um contendo apenas os débitos com vencimento anterior à 30/06/2018 e depois outro com débitos posteriores as esta data.";
                    return;
                }
                if (!bAnoAnterior && bAnoAtual)
                {
                    nPlano = 0;
                }
            }

            if (bParcUnica && bParcNormal)
            {
                lblMsg2.Text = "Parcela ùnica não pode ser paga junto com outras parcelas.";
            }
            else
            {
                GeraGuia(_valor_Honorario);
            }
        }
Beispiel #2
0
        protected void btConsultar_Click(object sender, ImageClickEventArgs e)
        {
            bool     isNum          = false;
            int      Num            = 0;
            decimal  nSomaPrincipal = 0;
            decimal  nSomaJuros     = 0;
            decimal  nSomaMulta     = 0;
            decimal  nSomaCorrecao  = 0;
            decimal  nSomaTotal     = 0;
            string   num_cpf_cnpj   = "";
            DateTime DataDAM;

            bGerado = false;
            String sTextoImagem = txtimgcode.Text;

            txtimgcode.Text = "";

            lblmsg.Text      = "";
            lblMsg2.Text     = "";
            lblNome.Text     = "";
            lblDoc.Text      = "";
            lblEndereco.Text = "";
            lblValidate.Text = "";


            if (optCPF.Checked && gtiCore.RetornaNumero(txtCPF.Text).Length < 11)
            {
                lblmsg.Text = "CPF inválido!";
                ShowResult(false);
                return;
            }
            if (optCNPJ.Checked && gtiCore.RetornaNumero(txtCNPJ.Text).Length < 14)
            {
                lblmsg.Text = "CNPJ inválido!";
                ShowResult(false);
                return;
            }

            if (optCPF.Checked)
            {
                num_cpf_cnpj = gtiCore.RetornaNumero(txtCPF.Text);
                if (!gtiCore.ValidaCpf(num_cpf_cnpj))
                {
                    lblmsg.Text = "CPF inválido!";
                    ShowResult(false);
                    return;
                }
            }
            else
            {
                num_cpf_cnpj = gtiCore.RetornaNumero(txtCNPJ.Text);
                if (!gtiCore.ValidaCNPJ(num_cpf_cnpj))
                {
                    lblmsg.Text = "CNPJ inválido!";
                    ShowResult(false);
                    return;
                }
            }


            if (optList.Items[0].Selected == true)
            {
                isNum = int.TryParse(txtCod.Text, out Num);
                if (!isNum)
                {
                    lblmsg.Text = "Código do imóvel inválido!";
                    ShowResult(false);
                    return;
                }
                else
                {
                    Imovel_bll imovel_Class = new Imovel_bll("GTIconnection");
                    bool       bFind        = imovel_Class.Existe_Imovel(Num);
                    if (bFind)
                    {
                        ImovelStruct reg = imovel_Class.Dados_Imovel(Num);
                        List <ProprietarioStruct> regProp = imovel_Class.Lista_Proprietario(Num, true);

                        lblEndereco.Text = reg.NomeLogradouro + ", " + reg.Numero + " " + reg.Complemento;
                        lblDoc.Text      = reg.NomeBairro;
                        lblNome.Text     = regProp[0].Nome;
                        if (optCPF.Checked)
                        {
                            if (Convert.ToInt64(gtiCore.RetornaNumero(regProp[0].CPF)).ToString("00000000000") != num_cpf_cnpj)
                            {
                                lblmsg.Text = "CPF não pertence ao proprietário deste imóvel!";
                                ShowResult(false);
                                return;
                            }
                        }
                        else
                        {
                            if (Convert.ToInt64(gtiCore.RetornaNumero(regProp[0].CPF)).ToString("00000000000000") != num_cpf_cnpj)
                            {
                                lblmsg.Text = "CNPJ não pertence ao proprietário deste imóvel!";
                                ShowResult(false);
                                return;
                            }
                        }
                    }
                    else
                    {
                        lblmsg.Text = "Código do imóvel não cadastrado!";
                        ShowResult(false);
                        return;
                    }
                }
            }
            else
            {
                if (optList.Items[1].Selected == true)
                {
                    isNum = int.TryParse(txtCod.Text, out Num);
                    if (!isNum)
                    {
                        lblmsg.Text = "Código da empresa inválido!";
                        ShowResult(false);
                        return;
                    }
                    else
                    {
                        Empresa_bll empresa_Class = new Empresa_bll("GTIconnection");
                        bool        bFind         = empresa_Class.Existe_Empresa(Num);
                        if (bFind)
                        {
                            EmpresaStruct reg = empresa_Class.Retorna_Empresa(Num);
                            lblEndereco.Text = reg.Endereco_nome + ", " + reg.Numero + " " + reg.Complemento;
                            lblDoc.Text      = reg.Bairro_nome;
                            lblNome.Text     = reg.Razao_social;

                            if (optCPF.Checked)
                            {
                                if (Convert.ToInt64(gtiCore.RetornaNumero(reg.Cpf_cnpj)).ToString("00000000000") != num_cpf_cnpj)
                                {
                                    lblmsg.Text = "CPF não pertence ao proprietário deste imóvel!";
                                    ShowResult(false);
                                    return;
                                }
                            }
                            else
                            {
                                if (Convert.ToInt64(gtiCore.RetornaNumero(reg.Cpf_cnpj)).ToString("00000000000000") != num_cpf_cnpj)
                                {
                                    lblmsg.Text = "CNPJ não pertence ao proprietário deste imóvel!";
                                    ShowResult(false);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            lblmsg.Text = "Inscrição Municipal não cadastrada!";
                            ShowResult(false);
                            return;
                        }
                    }
                }
                else
                {
                    if (optList.Items[2].Selected == true)
                    {
                        isNum = Int32.TryParse(txtCod.Text, out Num);
                        if (!isNum)
                        {
                            lblmsg.Text = "Código de contribuinte inválido!";
                            ShowResult(false);
                            return;
                        }
                        else
                        {
                            if (Num < 500000 || Num > 700000)
                            {
                                lblmsg.Text = "Código de contribuinte inválido!";
                                ShowResult(false);
                                return;
                            }
                            else
                            {
                                Cidadao_bll cidadao_Class = new Cidadao_bll("GTIconnection");
                                bool        bFind         = cidadao_Class.ExisteCidadao(Num);
                                if (bFind)
                                {
                                    CidadaoStruct reg = cidadao_Class.LoadReg(Num);
                                    if (reg.EtiquetaR != null && reg.EtiquetaR == "S")
                                    {
                                        lblEndereco.Text = reg.EnderecoR + ", " + reg.NumeroR + " " + reg.ComplementoR;
                                        lblDoc.Text      = reg.NomeBairroR;
                                    }
                                    else
                                    {
                                        lblEndereco.Text = reg.EnderecoC + ", " + reg.NumeroC + " " + reg.ComplementoC;
                                        lblDoc.Text      = reg.NomeBairroC;
                                    }
                                    lblNome.Text = reg.Nome;

                                    if (optCPF.Checked)
                                    {
                                        if (Convert.ToInt64(gtiCore.RetornaNumero(reg.Cpf)).ToString("00000000000") != num_cpf_cnpj)
                                        {
                                            lblmsg.Text = "CPF não pertence ao proprietário deste imóvel!";
                                            ShowResult(false);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        if (Convert.ToInt64(gtiCore.RetornaNumero(reg.Cnpj)).ToString("00000000000000") != num_cpf_cnpj)
                                        {
                                            lblmsg.Text = "CNPJ não pertence ao proprietário deste imóvel!";
                                            ShowResult(false);
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    lblmsg.Text = "Contribuinte não cadastrado!";
                                    ShowResult(false);
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            if (!DateTime.TryParse(lblVenctoDam.Text, out DataDAM))
            {
                lblmsg.Text = "Data de vencimento inválida.";
                ShowResult(false);
                return;
            }
            else
            {
                String sDataVencto = lblVenctoDam.Text;
                String sDataNow    = DateTime.Now.ToString("dd/MM/yyyy");
                if (DateTime.ParseExact(sDataVencto, "dd/MM/yyyy", null) < DateTime.ParseExact(sDataNow, "dd/MM/yyyy", null))
                {
                    lblmsg.Text = "Vencimento menor que a data atual.";
                    ShowResult(false);
                    return;
                }
                else
                {
                    Int32 DifDias = ((TimeSpan)(DataDAM - DateTime.Now)).Days;
                    if (DifDias > 30)
                    {
                        lblmsg.Text = "Vencimento máximo de 30 dias.";
                        ShowResult(false);
                        return;
                    }
                }
            }

            if (txtimgcode.Text == Session["randomStr"].ToString())
            {
                lblmsg.Text = "Código da imagem inválido.";
                ShowResult(false);
                return;
            }
            else
            {
                ShowResult(true);
                lblmsg.Text  = "";
                lblMsg2.Text = "";
            }

            this.txtimgcode.Text = "";

            String         sDataDAM         = DataDAM.ToString("dd/MM/yyyy");
            Tributario_bll tributario_Class = new Tributario_bll("GTIconnection");

            bRefis = tributario_Class.IsRefis();
            List <SpExtrato>       ListaTributo = tributario_Class.Lista_Extrato_Tributo(Num, 1980, 2050, 0, 99, 0, 99, 0, 999, 0, 99, 0, 99, DateTime.ParseExact(sDataDAM, "dd/MM/yyyy", null), "Web");
            List <SpExtrato>       ListaParcela = tributario_Class.Lista_Extrato_Parcela(ListaTributo);
            List <DebitoStructure> debitos2     = new List <DebitoStructure>();

            Decimal nPerc = 0;

            int nIndex = 0;

            if (bRefis)
            {
                foreach (var item in ListaParcela)
                {
                    if (Convert.ToDateTime(item.Datavencimento) <= Convert.ToDateTime("30/06/2019"))
                    {
                        Int16 CodLanc = item.Codlancamento;
                        if (CodLanc != 48 || CodLanc != 69 || CodLanc != 78)
                        {
                            if (Convert.ToDateTime(sDataDAM) <= Convert.ToDateTime("18/10/2019"))
                            {
                                nPerc  = 1M;
                                nPlano = 33;
                            }
                            else if (Convert.ToDateTime(sDataDAM) > Convert.ToDateTime("18/10/2019") && Convert.ToDateTime(sDataDAM) <= Convert.ToDateTime("29/11/2019"))
                            {
                                nPerc  = 0.9M;
                                nPlano = 34;
                            }
                            else if (Convert.ToDateTime(sDataDAM) > Convert.ToDateTime("29/11/2019") && Convert.ToDateTime(sDataDAM) <= Convert.ToDateTime("20/12/2019"))
                            {
                                nPerc  = 0.8M;
                                nPlano = 35;
                            }
                            if (nPlano > 0)
                            {
                                item.Valorjuros = Convert.ToDecimal(item.Valorjuros) - (Convert.ToDecimal(item.Valorjuros) * nPerc);
                                item.Valormulta = Convert.ToDecimal(item.Valormulta) - (Convert.ToDecimal(item.Valormulta) * nPerc);
                                item.Valortotal = item.Valortributo + item.Valorjuros + item.Valormulta + item.Valorcorrecao;
                            }
                            ListaParcela[nIndex].Valorjuros = item.Valorjuros;
                            ListaParcela[nIndex].Valormulta = item.Valormulta;
                            ListaParcela[nIndex].Valortotal = item.Valortotal;
                        }
                    }
                    nIndex++;
                }
            }

            PlanoLabel.Text = nPlano.ToString();
            foreach (var item in ListaParcela)
            {
                if (item.Statuslanc == 3 || item.Statuslanc == 19 || item.Statuslanc == 38 || item.Statuslanc == 39 || item.Statuslanc == 42 || item.Statuslanc == 43)
                {
                    //if (item.Codlancamento != 16 && item.Codlancamento != 38) {
                    DebitoStructure reg = new DebitoStructure();
                    reg.Codigo_Reduzido      = item.Codreduzido;
                    reg.Ano_Exercicio        = item.Anoexercicio;
                    reg.Codigo_Lancamento    = Convert.ToInt16(item.Codlancamento);
                    reg.Descricao_Lancamento = item.Desclancamento;
                    reg.Sequencia_Lancamento = Convert.ToInt16(item.Seqlancamento);
                    reg.Numero_Parcela       = Convert.ToInt16(item.Numparcela);
                    reg.Complemento          = item.Codcomplemento;
                    reg.Data_Vencimento      = Convert.ToDateTime(item.Datavencimento);
                    reg.Codigo_Situacao      = Convert.ToInt16(item.Statuslanc);
                    reg.Soma_Principal       = item.Valortributo;
                    reg.Soma_Juros           = item.Valorjuros;
                    reg.Soma_Multa           = item.Valormulta;
                    reg.Soma_Correcao        = item.Valorcorrecao;
                    reg.Soma_Total           = item.Valortotal;
                    reg.Data_Ajuizamento     = item.Dataajuiza;
                    debitos2.Add(reg);
                    //  }
                }
            }

            if (debitos2.Count == 0)
            {
                lblDoc.Text = "";
                lblmsg.Text = "Não existem débitos.";
                ShowResult(false);
                return;
            }

            DataTable dt = new DataTable();

            dt.Columns.AddRange(new DataColumn[14] {
                new DataColumn("Exercicio"), new DataColumn("Lancamento"), new DataColumn("Sequencia"),
                new DataColumn("Parcela"), new DataColumn("Complemento"), new DataColumn("DtVencimento"), new DataColumn("VlPrincipal"),
                new DataColumn("VlJuros"), new DataColumn("VlMulta"), new DataColumn("VlCorrecao"), new DataColumn("VlTotal"), new DataColumn("DtAjuiza"),
                new DataColumn("Protesto"), new DataColumn("EnvProt")
            });

            foreach (var item in debitos2)
            {
                dt.Rows.Add(item.Ano_Exercicio.ToString(), item.Codigo_Lancamento.ToString("000") + "-" + item.Descricao_Lancamento.ToString(), item.Sequencia_Lancamento.ToString(),
                            item.Numero_Parcela.ToString(), item.Complemento.ToString(), Convert.ToDateTime(item.Data_Vencimento).ToString("dd/MM/yyyy"),
                            item.Soma_Principal.ToString("#0.00"), item.Soma_Juros.ToString("#0.00"), item.Soma_Multa.ToString("#0.00"),
                            item.Soma_Correcao.ToString("#0.00"), item.Soma_Total.ToString("#0.00"), item.Data_Ajuizamento == DateTime.MinValue || item.Data_Ajuizamento == null? "NÃO" : "SIM",
                            item.Codigo_Situacao == 38 ? "SIM" : "NÃO", item.Codigo_Situacao == 39 ? "SIM" : "NÃO");
                nSomaPrincipal += item.Soma_Principal;
                nSomaJuros     += item.Soma_Juros;
                nSomaMulta     += item.Soma_Multa;
                nSomaCorrecao  += item.Soma_Correcao;
                nSomaTotal     += item.Soma_Total;
            }

            grdMain.DataSource = dt;
            grdMain.DataBind();

            TableTotal.Rows[1].Cells[2].Text = nSomaPrincipal.ToString("#0.00");
            TableTotal.Rows[1].Cells[3].Text = nSomaMulta.ToString("#0.00");
            TableTotal.Rows[1].Cells[4].Text = nSomaJuros.ToString("#0.00");
            TableTotal.Rows[1].Cells[5].Text = nSomaCorrecao.ToString("#0.00");
            TableTotal.Rows[1].Cells[6].Text = nSomaTotal.ToString("#0.00");

            TableTotal.Rows[2].Cells[2].Text  = "0,00";
            TableTotal.Rows[2].Cells[3].Text  = "0,00";
            TableTotal.Rows[2].Cells[4].Text  = "0,00";
            TableTotal.Rows[2].Cells[5].Text  = "0,00";
            TableTotal.Rows[2].Cells[6].Text  = "0,00";
            TableResumo.Rows[0].Cells[1].Text = "0,00";
            TableResumo.Rows[1].Cells[1].Text = lblVenctoDam.Text;
        }