forked from vladimir-aubrecht/StatementParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TaxReporterCLI simplified and it can print xlsx now.
- Loading branch information
Vladimír Aubrecht
authored and
Vladimír Aubrecht
committed
Feb 4, 2020
1 parent
35de7df
commit e4d43b7
Showing
12 changed files
with
185 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System; | ||
namespace StatementParser.Models | ||
{ | ||
public enum Currency { USD, EUR, JPY } | ||
public enum Currency { CZK, USD, EUR, JPY } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using NPOI.SS.UserModel; | ||
using NPOI.XSSF.UserModel; | ||
using StatementParser.Models; | ||
|
||
namespace TaxReporterCLI | ||
{ | ||
public class Output | ||
{ | ||
private Dictionary<string, List<Transaction>> GroupTransactions(IList<Transaction> transactions) | ||
{ | ||
return transactions.GroupBy(i => i.GetType()).ToDictionary(k => k.Key.Name, i => i.Select(a => a).ToList()); | ||
} | ||
|
||
public void PrintAsJson(IList<Transaction> transactions) | ||
{ | ||
var groupedTransactions = GroupTransactions(transactions); | ||
|
||
Console.WriteLine(JsonConvert.SerializeObject(groupedTransactions)); | ||
} | ||
|
||
public void SaveAsExcelSheet(string filePath, IList<Transaction> transactions) | ||
{ | ||
var groupedTransactions = GroupTransactions(transactions); | ||
|
||
using (FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
var wb1 = new XSSFWorkbook(); | ||
|
||
foreach (var group in groupedTransactions) | ||
{ | ||
var sheet = wb1.CreateSheet(group.Key); | ||
|
||
var headerRow = sheet.CreateRow(0); | ||
var headerProperties = GetPublicProperties(group.Value[0]); | ||
SetRowValues(headerRow, headerProperties.Keys); | ||
|
||
for (int rowIndex = 1; rowIndex < group.Value.Count() + 1; rowIndex++) | ||
{ | ||
var row = sheet.CreateRow(rowIndex); | ||
var properties = GetPublicProperties(group.Value[rowIndex - 1]); | ||
|
||
SetRowValues(row, properties.Values); | ||
} | ||
wb1.Add(sheet); | ||
} | ||
|
||
wb1.Write(file); | ||
} | ||
} | ||
|
||
public void PrintAsPlainText(IList<Transaction> transactions) | ||
{ | ||
var groupedTransactions = GroupTransactions(transactions); | ||
|
||
foreach (var group in groupedTransactions) | ||
{ | ||
Console.WriteLine(); | ||
Console.WriteLine(group.Key); | ||
Console.WriteLine(String.Join("\r\n", group.Value)); | ||
} | ||
} | ||
|
||
private void SetRowValues(IRow row, ICollection<string> rowValues) | ||
{ | ||
var columnIndex = 0; | ||
foreach (var rowValue in rowValues) | ||
{ | ||
var cell = row.CreateCell(columnIndex); | ||
|
||
cell.SetCellValue(rowValue); | ||
|
||
columnIndex++; | ||
} | ||
} | ||
|
||
private IDictionary<string, string> GetPublicProperties(Transaction transaction) | ||
{ | ||
var properties = transaction.GetType().GetProperties(); | ||
return properties.Reverse().ToDictionary(k => k.Name, i => i.GetValue(transaction).ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters