コード例 #1
0
        public Companys Put(Companys companys)
        {
            try
            {
                Validate(companys);

                if (companys.CompanyId <= 0)
                {
                    throw new Exception("Informe o código da empresa!");
                }

                SQL.AppendLine(" Update Companys Set ");
                SQL.AppendLine("    UserId = " + companys.UserId + ",");
                SQL.AppendLine("    CNPJ = '" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.CNPJ)) + "',");
                SQL.AppendLine("    IM = " + (string.IsNullOrEmpty(companys.IM) ? "Null," : "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.IM)) + "',"));
                SQL.AppendLine("    IE = " + (string.IsNullOrEmpty(companys.IE) ? "Null," : "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.IE)) + "',"));
                SQL.AppendLine("    Name = '" + Functions.NoQuote(companys.Name) + "',");
                SQL.AppendLine("    NameFantasy = '" + Functions.NoQuote(companys.NameFantasy) + "',");
                SQL.AppendLine("    CEP = '" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.CEP)) + "',");
                SQL.AppendLine("    Street = '" + Functions.NoQuote(companys.Street) + "',");
                SQL.AppendLine("    Neighborhood = '" + Functions.NoQuote(companys.Neighborhood) + "',");
                SQL.AppendLine("    City = '" + Functions.NoQuote(companys.City) + "', ");
                SQL.AppendLine("    State = '" + Functions.NoQuote(companys.State) + "',");
                SQL.AppendLine("    Telephone =  " + (string.IsNullOrEmpty(companys.Telephone) ? "Null," : "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.Telephone)) + "',"));
                SQL.AppendLine("    Email = " + (string.IsNullOrEmpty(companys.Email) ? "Null," : "'" + Functions.RemoveCharSpecialEmail(Functions.NoQuote(companys.Email)) + "',"));
                SQL.AppendLine("    Logo = '" + (companys.Logo == null ? string.Empty : Functions.NoQuote(companys.Logo)) + "',");
                SQL.AppendLine("    IRRF = " + Functions.FormatNumber(companys.IRRF) + ",");
                SQL.AppendLine("    PIS = " + Functions.FormatNumber(companys.PIS) + ",");
                SQL.AppendLine("    COFINS = " + Functions.FormatNumber(companys.COFINS) + ",");
                SQL.AppendLine("    CSLL = " + Functions.FormatNumber(companys.CSLL) + ",");
                SQL.AppendLine("    INSS = " + Functions.FormatNumber(companys.INSS) + ",");
                SQL.AppendLine("    DateUpdate = GetDate() ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And CompanyId = " + companys.CompanyId);

                if (Functions.Conn.Update(SQL.ToString()))
                {
                    TaxpayerActivitiesDomain taxpayerActivitiesDomain = new TaxpayerActivitiesDomain();
                    taxpayerActivitiesDomain.Reload(Homologation.CPF, Homologation.Password, Homologation.IM, int.Parse(Homologation.CityCod), companys.CompanyId);

                    return(companys);
                }
                throw new InternalProgramException("Houve um problema ao atualizar a empresa.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public NFeSRequestPreview Issue(NFeSRequest NFeS)
        {
            try
            {
                ValidateIssue(NFeS);

                //Objetos da Nota Fiscal:
                var Taker              = new TakerDomain().Get <Takers>(NFeS.TakerId);
                var Company            = new CompanyDomain().Get <Companys>(CompanyDomain.Type.Company, NFeS.CompanyId);
                var CFPS               = new CFPSDomain().Get <CFPS>(NFeS.CFPSId);
                var TaxpayerActivities = new TaxpayerActivitiesDomain().Get(NFeS.TaxpayerActivitiesId);
                var ShippingCompany    = new ShippingCompany();
                if (NFeS.ShippingCompanyId > 0)
                {
                    ShippingCompany = new ShippingCompanyDomain().Get <ShippingCompany>(NFeS.ShippingCompanyId);
                }

                //Nota Fiscal:
                var NFeSRequest = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfd();
                var NotaFiscal  = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfd()
                {
                    numeronfd                 = Homologation.NumberNF,
                    codseriedocumento         = Homologation.Serie,
                    codnaturezaoperacao       = CFPS.CFPSCod,
                    codigocidade              = Homologation.CityCod,
                    inscricaomunicipalemissor = Homologation.IM,
                    dataemissao               = Functions.DateTimeBr().ToString("dd/MM/yyyy"),
                    razaotomador              = Taker.Name,
                    nomefantasiatomador       = Taker.NameFantasy,
                    enderecotomador           = Taker.Street,
                    numeroendereco            = Taker.Number,
                    cidadetomador             = Taker.City,
                    estadotomador             = Taker.State,
                    paistomador               = Homologation.Country,
                    fonetomador               = Taker.Telephone,
                    faxtomador                = Taker.Telephone,
                    ceptomador                = Taker.CEP,
                    bairrotomador             = Taker.Neighborhood,
                    emailtomador              = Taker.Email,
                    tppessoa                  = Taker.TypePerson,
                    cpfcnpjtomador            = Taker.CPF_CNPJ,
                    inscricaoestadualtomador  = Taker.RG_IE,
                    inscricaomunicipaltomador = Taker.IM,
                    observacao                = NFeS.Note,
                    razaotransportadora       = Functions.IIf(ShippingCompany.Name),
                    cpfcnpjtransportadora     = Functions.IIf(ShippingCompany.CPF_CNPJ),
                    pis    = Homologation.PIS,
                    cofins = Homologation.COFINS,
                    csll   = Homologation.CSLL,
                    irrf   = Homologation.IRRF,
                    inss   = Homologation.INSS,
                    descdeducoesconstrucao  = string.Empty,
                    totaldeducoesconstrucao = string.Empty,
                    tributadonomunicipio    = string.Empty,
                    vlroutros              = string.Empty,
                    numerort               = string.Empty,
                    codigoseriert          = string.Empty,
                    dataemissaort          = string.Empty,
                    fatorgerador           = Functions.DateTimeBr().Month + "/" + Functions.DateTimeBr().Year,
                    enderecotransportadora =
                        Functions.IIf(ShippingCompany.Street) + ","
                        + Functions.IIf(ShippingCompany.Neighborhood) + ","
                        + Functions.IIf(ShippingCompany.City) + ","
                        + Functions.IIf(ShippingCompany.State),
                };

                //Faturas:
                NotaFiscal.tbfatura = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdFatura[NFeS.Invoices.Count];
                for (int X = 0; X < NFeS.Invoices.Count; X++)
                {
                    NFeSRequestInvoices Invoice = NFeS.Invoices[X];
                    NotaFiscal.tbfatura[X] = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdFatura
                    {
                        numfatura        = Invoice.Number.ToString(),
                        vencimentofatura = DateTime.Parse(Invoice.Maturity).ToString("dd/MM/yyyy"),
                        valorfatura      = Invoice.Value.ToString()
                    };
                }

                //Serviços:
                NotaFiscal.tbservico = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdServico[NFeS.Itens.Count];
                for (int X = 0; X < NFeS.Itens.Count; X++)
                {
                    NFeSRequestItens Item     = NFeS.Itens[X];
                    Services         Services = new ServiceDomain().Get <Services>(Item.ServicesId);

                    NotaFiscal.tbservico[X] = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdServico
                    {
                        quantidade    = Item.Amount.ToString(),
                        descricao     = Services.Description,
                        codatividade  = TaxpayerActivities.CNAE,
                        valorunitario = Item.Value.ToString(),
                        aliquota      = TaxpayerActivities.Aliquot.ToString(),
                        impostoretido = CFPS.TaxWithheld
                    };
                }

                NFeSRequest.nfd = NotaFiscal;

                string XmlRPS = API.Send(API.GetCity(Company.City), Homologation.CPF, Homologation.Password, int.Parse(Homologation.CityCod), this.Assign(NFeSRequest));

                if (Functions.XmlFunctions.IsXml(XmlRPS))
                {
                    //Enviando o RPS para receber a NFSe(5 tentativas)//
                    int    Cont          = 0;
                    string XmlAuthorized = string.Empty;

                    //Primeira tentativa
                    XmlAuthorized = API.Receive(API.GetCity(Company.City),
                                                Homologation.CPF,
                                                Homologation.Password,
                                                Homologation.IM,
                                                XmlRPS);

                    bool Auth = Functions.XmlFunctions.IsXml(XmlAuthorized);

                    while (!Auth & Cont <= 5)
                    {
                        XmlAuthorized = API.Receive(API.GetCity(Company.City),
                                                    Homologation.CPF,
                                                    Homologation.Password,
                                                    Homologation.IM,
                                                    XmlRPS);

                        Auth = Functions.XmlFunctions.IsXml(XmlAuthorized);
                        Cont++;
                        System.Threading.Thread.Sleep(5000);
                    }


                    if (Functions.XmlFunctions.IsXml(XmlAuthorized))
                    {
                        var    NFeSAuthorized = Functions.XmlFunctions.StringXmlForClass <Models.Models.NFeSStructure.NFeSProcessingResult.tbnfd>(XmlAuthorized);
                        string XmlUrl         = API.GetUrl(API.City.Serra,
                                                           int.Parse(Homologation.CityCod),
                                                           int.Parse(NFeSAuthorized.nfdok.NewDataSet.NOTA_FISCAL.NumeroNota),
                                                           int.Parse(NFeSAuthorized.nfdok.NewDataSet.NOTA_FISCAL.CodigoSerie),
                                                           Homologation.IM);

                        if (Functions.XmlFunctions.IsXml(XmlUrl))
                        {
                            var    NFeSUrl = Functions.XmlFunctions.StringXmlForClass <Models.Models.NFeSStructure.NFeSPreview.util>(XmlUrl);
                            string PDF     = Download(NFeSUrl.urlNfd);

                            //Salvando no banco os dados da nota fiscal
                            Save(Taker,
                                 Company,
                                 CFPS,
                                 ShippingCompany,
                                 NFeSAuthorized,
                                 NFeSUrl,
                                 XmlAuthorized,
                                 PDF);

                            //Enviando email para o tomador
                            SendEmail(Taker, Company, NFeSAuthorized, NFeSUrl);

                            return(new NFeSRequestPreview(NFeSUrl.urlNfd, PDF));
                        }
                        else
                        {
                            throw new InternalProgramException(XmlUrl);
                        }
                    }
                    else
                    {
                        throw new InternalProgramException(XmlAuthorized);
                    }
                }
                else
                {
                    throw new InternalProgramException(XmlRPS);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public Companys Post(Companys companys)
        {
            try
            {
                Validate(companys);

                if (Functions.ExistsRegister(companys.CNPJ, TypeInput.Texto, "CNPJ", "Companys"))
                {
                    throw new InternalProgramException("Empresa já existe!");
                }

                SQL.AppendLine(" Insert Into Companys ");
                SQL.AppendLine("    (UserId, ");
                SQL.AppendLine("    CNPJ, ");
                SQL.AppendLine("    IM, ");
                SQL.AppendLine("    IE, ");
                SQL.AppendLine("    Name, ");
                SQL.AppendLine("    NameFantasy, ");
                SQL.AppendLine("    CEP, ");
                SQL.AppendLine("    Street, ");
                SQL.AppendLine("    Neighborhood, ");
                SQL.AppendLine("    City, ");
                SQL.AppendLine("    State, ");
                SQL.AppendLine("    Telephone, ");
                SQL.AppendLine("    Email, ");
                SQL.AppendLine("    Logo, ");
                SQL.AppendLine("    IRRF, ");
                SQL.AppendLine("    PIS, ");
                SQL.AppendLine("    COFINS, ");
                SQL.AppendLine("    CSLL, ");
                SQL.AppendLine("    INSS, ");
                SQL.AppendLine("    Active, ");
                SQL.AppendLine("    DateInsert, ");
                SQL.AppendLine("    DateUpdate) ");
                SQL.AppendLine(" Values ");
                SQL.AppendLine("    ( " + companys.UserId + ",");
                SQL.AppendLine("     '" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.CNPJ)) + "',");
                SQL.AppendLine("     " + (companys.IM == null ? "Null," : "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.IM.ToString())) + "',"));
                SQL.AppendLine("     " + (companys.IE == null ? "Null,": "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.IE.ToString())) + "',"));
                SQL.AppendLine("     '" + Functions.NoQuote(companys.Name) + "',");
                SQL.AppendLine("     '" + Functions.NoQuote(companys.NameFantasy) + "',");
                SQL.AppendLine("     '" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.CEP)) + "',");
                SQL.AppendLine("     '" + Functions.NoQuote(companys.Street) + "',");
                SQL.AppendLine("     '" + Functions.NoQuote(companys.Neighborhood) + "',");
                SQL.AppendLine("     '" + Functions.NoQuote(companys.City) + "',");
                SQL.AppendLine("     '" + Functions.NoQuote(companys.State) + "',");
                SQL.AppendLine("      " + (companys.Telephone == null ? "Null," : "'" + Functions.RemoveCharSpecial(Functions.NoQuote(companys.Telephone.ToString())) + "',"));
                SQL.AppendLine("      " + (companys.Email == null ? "Null," : "'" + Functions.RemoveCharSpecialEmail(Functions.NoQuote(companys.Email.ToString())) + "',"));
                SQL.AppendLine("     '" + (companys.Logo == null ? string.Empty:Functions.NoQuote(companys.Logo)) + "',");
                SQL.AppendLine("     " + Functions.FormatNumber(companys.IRRF) + ",");
                SQL.AppendLine("     " + Functions.FormatNumber(companys.PIS) + ",");
                SQL.AppendLine("     " + Functions.FormatNumber(companys.COFINS) + ",");
                SQL.AppendLine("     " + Functions.FormatNumber(companys.CSLL) + ",");
                SQL.AppendLine("     " + Functions.FormatNumber(companys.INSS) + ",");
                SQL.AppendLine("     1 ,");
                SQL.AppendLine("     GetDate(), ");
                SQL.AppendLine("     GetDate() ");
                SQL.AppendLine("    ) ");

                companys.CompanyId = Functions.Conn.Insert(SQL.ToString());
                if (companys.CompanyId > 0)
                {
                    TaxpayerActivitiesDomain taxpayerActivitiesDomain = new TaxpayerActivitiesDomain();
                    taxpayerActivitiesDomain.Reload(Homologation.CPF, Homologation.Password, Homologation.IM, int.Parse(Homologation.CityCod), companys.CompanyId);
                    companys.Active     = true;
                    companys.DateInsert = DateTime.Now.ToString("yyyy-MM-dd");
                    companys.DateUpdate = DateTime.Now.ToString("yyyy-MM-dd");
                    return(companys);
                }
                throw new InternalProgramException("Houve um problema ao cadastrar a empresa!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }