Exemplo n.º 1
0
        private void ShowCompany()
        {
            var companyManager = new CompanyManager(this);
            var company = companyManager.GetCompany(Convert.ToInt32(Page.ViewState["CompanyId"]));

            txtCompanyName.Text = company.LegalEntityProfile.CompanyName;
            txtCompanyPlan.Text = company.Plan.Name;

            if (company.User != null)
                txtLastActivityDate.Text = company.User.LastActivityDate.ToString();

            txtUserQuantity.Text = companyManager.GetCompanyUsersCount(company.CompanyId).ToString();
            txtStartDate.Text = company.StartDate.ToShortDateString();

            var responsableForCompany = companyManager.GetResponsableForCompany(company.CompanyId);

            if (responsableForCompany != null)
                txtEmail.Text = responsableForCompany.Email;
        }
        private Boletos ConvertInvoiceParcelsInBoleto(Int32 companyId, Int32 accountId, DateTime beginDate,
                                                      DateTime endDate)
        {
            var customerManager = new CustomerManager(this);
            var profileManager = new ProfileManager(this);
            var companyManager = new CompanyManager(this);
            var accountManager = new AccountManager(this);
            Boleto boleto;
            Sacado sacado;
            Endereco endereco;
            var address = new Address();
            Company company = companyManager.GetCompany(companyId);
            Account account = accountManager.GetAccount(accountId, companyId);
            var boletos = new Boletos();

            var cedente = new Cedente(company.LegalEntityProfile.CNPJ, company.LegalEntityProfile.CompanyName,
                                      account.Agency, Convert.ToString(account.AgencyDigit), account.AccountNumber,
                                      Convert.ToString(account.AccountNumberDigit));


            foreach (Parcel parcel in GetOpenInvoiceParcelInPeriodByAccount(companyId, accountId, beginDate, endDate))
            {
                endereco = new Endereco();

                if (parcel.Invoice.Customer.LegalEntityProfileId.HasValue)
                {
                    //Address
                    address = parcel.Invoice.Customer.LegalEntityProfile.Address;

                    endereco.Numero = parcel.Invoice.Customer.LegalEntityProfile.AddressNumber;
                    endereco.Complemento = parcel.Invoice.Customer.LegalEntityProfile.AddressComp;

                    //sacado
                    sacado = new Sacado(parcel.Invoice.Customer.LegalEntityProfile.CNPJ,
                                        parcel.Invoice.Customer.LegalEntityProfile.CompanyName);
                }
                else
                {
                    //Address
                    address = parcel.Invoice.Customer.Profile.Address;

                    endereco.Numero = parcel.Invoice.Customer.Profile.AddressNumber;
                    endereco.Complemento = parcel.Invoice.Customer.Profile.AddressComp;

                    //sacado
                    sacado = new Sacado(parcel.Invoice.Customer.Profile.CPF, parcel.Invoice.Customer.Profile.Name);
                }

                //Address
                endereco.Bairro = address.Neighborhood;
                endereco.CEP = address.PostalCode;
                endereco.Cidade = address.City ?? String.Empty;
                endereco.Logradouro = address.Name;
                endereco.UF = address.State;

                //boleto
                boleto = new Boleto(parcel.DueDate, Convert.ToDouble(parcel.Amount), String.Empty, String.Empty, cedente);

                sacado.Endereco = endereco;

                boleto.Sacado = sacado;

                var instrucao = new Instrucao(Convert.ToInt32(account.Bank.BankNumber));

                var banco = new Banco(Convert.ToInt32(account.Bank.BankNumber));

                instrucao.Banco = banco;
                instrucao.QuantidadeDias = 0;
                instrucao.Descricao = String.Empty;
                instrucao.Codigo = 0;

                boleto.CodigoBarra.LinhaDigitavel = String.Empty;
                boleto.DataDocumento = DateTime.Now;
                boleto.DataVencimento = parcel.DueDate;
                boleto.ValorDesconto = 0;

                boleto.Instrucoes = new List<IInstrucao>();
                boleto.Instrucoes.Add(instrucao);
                boletos.Add(boleto);
            }
            return boletos;
        }
        public void GerarArquivoRemessa(Int32 companyId, Int32 accountId, DateTime beginDate, DateTime endDate,
                                        Stream stream)
        {
            var accountManager = new AccountManager(this);
            var companyManager = new CompanyManager(this);

            Company company = companyManager.GetCompany(companyId);
            FinancierOperation operation = accountManager.GetFinancierOperationBoleto(companyId);
            Boletos boletos = ConvertInvoiceParcelsInBoleto(companyId, accountId, beginDate, endDate);
            var exportFile = new ArquivoRemessa(TipoArquivo.CNAB400);
            var cedente = new Cedente(company.LegalEntityProfile.CNPJ, company.LegalEntityProfile.CompanyName,
                                      operation.Account.Agency, Convert.ToString(operation.Account.AgencyDigit), operation.Account.AccountNumber,
                                      Convert.ToString(operation.Account.AccountNumberDigit));


            exportFile.GerarArquivoRemessa(String.Empty,
                                           new Banco(Convert.ToInt32(operation.Account.Bank.BankNumber)), cedente, boletos, stream,
                                           1);
        }