Пример #1
0
        decimal SaldoCliente(EntidadeDTO dto)
        {
            var ExtractList = FaturaClienteRN.GetInstance().GetCustomerExtractList(new FaturaDTO
            {
                Entidade = dto.Codigo
            });

            return(ExtractList.Sum(t => t.Saldo));
        }
Пример #2
0
        public void GenerateInvoicesHash(AuditFileBilling saftfile, string PrivateKeyFileName)
        {
            if (saftfile == null || saftfile.SourceDocuments == null || saftfile.SourceDocuments.SalesInvoices == null || saftfile.SourceDocuments.SalesInvoices.Invoice == null)
            {
                return;
            }

                #pragma warning disable IDE0068 // Usar o padrão de descarte recomendado
            object hasher = SHA1.Create();
                #pragma warning restore IDE0068 // Usar o padrão de descarte recomendado

            using (RSACryptoServiceProvider rsaCryptokey = new RSACryptoServiceProvider(1024))
            {
                rsaCryptokey.FromXmlString(GetRSAPrivateKey(PrivateKeyFileName));

                StringBuilder toHash = new StringBuilder();


                for (int i = 0; i < saftfile.SourceDocuments.SalesInvoices.Invoice.Count; i++)
                {
                    var invoice = saftfile.SourceDocuments.SalesInvoices.Invoice[i];

                    bool usaHashAnterior = true;
                    if (i == 0 || invoice.InvoiceType != saftfile.SourceDocuments.SalesInvoices.Invoice[i - 1].InvoiceType || Convert.ToInt32(invoice.InvoiceNo.Split('/')[1]) != Convert.ToInt32(saftfile.SourceDocuments.SalesInvoices.Invoice[i - 1].InvoiceNo.Split('/')[1]) + 1)
                    {
                        usaHashAnterior = false;
                    }


                    FormatinvoicesStringToHash(ref toHash, invoice, usaHashAnterior ? saftfile.SourceDocuments.SalesInvoices.Invoice[i - 1].Hash : "");

                    byte[] stringToHashBuffer = Encoding.UTF8.GetBytes(toHash.ToString());
                    byte[] r = rsaCryptokey.SignData(stringToHashBuffer, hasher);

                    invoice.Hash        = Convert.ToBase64String(r);
                    invoice.HashControl = invoice.Hash[0].ToString() + invoice.Hash[10].ToString() + invoice.Hash[20].ToString() + invoice.Hash[30].ToString();
                    string PriorHash = usaHashAnterior ? saftfile.SourceDocuments.SalesInvoices.Invoice[i - 1].Hash : "";
                    FaturaClienteRN.GetInstance().SaveHash(new FaturaDTO {
                        Hash      = invoice.Hash,
                        PriorHash = PriorHash,
                        Codigo    = invoice.InvoiceID
                    });
                }
            }
        }