public void CanParseSantander() { var parser = new OfxDocumentParser(); var ofxDocument = parser.Import(new FileStream(@"santander.ofx", FileMode.Open)); Assert.IsNotNull(ofxDocument); }
public string UploadTransactionsToDatabase(Guid CustomerId, HttpPostedFileBase UploadedFile) { try { var Context = new Central(); var StreamToUpdate = UploadedFile.InputStream; var parser = new OfxDocumentParser(); string StreamString = StreamToString(StreamToUpdate); var ofxDocument = parser.Import(StreamString); foreach (var x in ofxDocument.Transactions) { if (!IsExistingTransaction(CustomerId, x)) { TransactionItem UserTransaction = new TransactionItem(); UserTransaction.TransactionItemId = Guid.NewGuid(); UserTransaction.CustomerId = CustomerId; UserTransaction.TransactionItemName = x.Name; UserTransaction.TransactionItemDate = DateTime.Parse(x.Date.ToShortDateString()); UserTransaction.TransactionItemAmount = x.Amount; UserTransaction.TransactionItemBudgetItem = Guid.Empty; UserTransaction.TransactionItemType = 1; UserTransaction.CreationDate = DateTime.Now; UserTransaction.UpdateDate = DateTime.Now; Context.TransactionItems.Add(UserTransaction); } } Context.SaveChanges(); string Status = "Success"; return(Status); } catch (Exception e) { return(e.ToString()); } }
public ActionResult Upar(HttpPostedFileBase file) { var lista = new List <LancamentoOFX>(); if (file != null && file.ContentLength > 0) { try { ViewBag.Message = "Arquivo carregado com sucesso."; var filename = file.FileName; var diretorio = Server.MapPath("~/"); var path = Path.Combine(diretorio, filename); file.SaveAs(path); var parser = new OfxDocumentParser(); var ofxDocument = parser.Import(new FileStream(path, FileMode.Open)); foreach (var item in ofxDocument.Transactions) { lista.Add(new LancamentoOFX(item.TransType.ToString(), item.Date, item.Name ?? item.Memo, Math.Abs((float)item.Amount) / 100)); } //XDocument xmlDoc = new XDocument(); //xmlDoc = XDocument.Load(path); //var lancamentos = from item in xmlDoc.Descendants("STMTTRN") // select new // { // tipo = item.Element("TRNTYPE").Value, // data = new DateTime( // int.Parse(item.Element("DTPOSTED").Value.Substring(0, 4)), // int.Parse(item.Element("DTPOSTED").Value.Substring(4, 2)), // int.Parse(item.Element("DTPOSTED").Value.Substring(6, 2))), // descricao = item.Element("NAME").Value, // qnt = (float)Math.Round(Math.Abs(float.Parse(item.Element("TRNAMT").Value)), 2) // }; //foreach (var item in lancamentos) //{ // lista.Add(new LancamentoOFX(item.tipo, item.data, item.descricao, item.qnt)); //} //ViewBag.Lancamentos = lista; return(View("Index", lista)); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "Nenhum arquivo selecionado."; } return(View("Index")); }
public void CanParseMemoryStream() { var parser = new OfxDocumentParser(); var bytes = File.ReadAllBytes(@"bb.ofx"); var stream = new MemoryStream(bytes); var ofxDocument = parser.Import(stream); Assert.AreEqual(3, ofxDocument.Transactions.Count()); }
public void CanParseItau() { var parser = new OfxDocumentParser(); var ofxDocument = parser.Import(new FileStream(@"itau.ofx", FileMode.Open)); Assert.AreEqual(ofxDocument.Account.AccountId, "9999 99999-9"); Assert.AreEqual(ofxDocument.Account.BankId, "0341"); Assert.AreEqual(3, ofxDocument.Transactions.Count()); CollectionAssert.AreEqual(ofxDocument.Transactions.Select(x => x.Memo.Trim()).ToList(), new[] { "RSHOP", "REND PAGO APLIC AUT MAIS", "SISDEB" }); }
public void Parse_Should_Parse() { //Given var extrato1OfxDocment = Path.Combine(Environment.CurrentDirectory, "extrato1.ofx"); var ofxDocumentStream = File.OpenRead(extrato1OfxDocment); //When var ofxDocument = OfxDocumentParser.Parse(ofxDocumentStream); //Then Assert.NotNull(ofxDocument); }
public void CanParseBancoDoBrasil() { var parser = new OfxDocumentParser(); var ofxDocument = parser.Import(new FileStream(@"bb.ofx", FileMode.Open), Encoding.GetEncoding("ISO-8859-1")); Assert.AreEqual(ofxDocument.Account.AccountId, "99999-9"); Assert.AreEqual(ofxDocument.Account.BranchId, "9999-9"); Assert.AreEqual(ofxDocument.Account.BankId, "1"); Assert.AreEqual(3, ofxDocument.Transactions.Count()); CollectionAssert.AreEqual(ofxDocument.Transactions.Select(x => x.Memo.Trim()).ToList(), new[] { "Transferência Agendada", "Compra com Cartão", "Saque" }); Assert.IsNotNull(ofxDocument); }
public OfxDocument GetStatement() { var fullUrl = new Uri(Options.Url); var baseUrl = string.Format("https://{0}", fullUrl.Host); var rightUrl = fullUrl.PathAndQuery; var client = new RestClient(baseUrl); var request = new RestRequest(rightUrl, Method.POST); request.AddParameter("application/x-ofx", Ofx.CreateRequest(Options), ParameterType.RequestBody); request.AddHeader("Accept", "application/ofx"); var response = client.Execute(request); var parser = new OfxDocumentParser(); return(parser.Import(response.Content)); }
public ActionResult Reconcile(IFormCollection formCollection) { try { //Should be tested. IFormFileCollection should be in Core Framework? var ofxDocuments = new List <OfxDocument>(); foreach (var file in formCollection.Files) { var stream = file.OpenReadStream(); var ofxDocument = OfxDocumentParser.Parse(stream); ofxDocuments.Add(ofxDocument); } var bankAccount = _bankReconciliationService.ReconcileAndAddTransactions(ofxDocuments); return(View(nameof(Reconcile), bankAccount)); } catch { return(View()); } }
public OfxService(OfxDocumentParser ofxDocumentParser) => _ofxDocumentParser = ofxDocumentParser;