public List <string> Convert(IQifMapping <string> inMapping, string csvfile, string acctType) { var outMapping = TranformMapping(inMapping as InvestmentAccountsMapping <string>); var headerColumns = new Dictionary <string, int> (); var qfiList = new List <string> (); using (var reader = new StreamReader(csvfile)) using (var csv = new CsvReader(reader)) { qfiList.Add(CsvToQifHelper.HeaderName(acctType)); csv.Read(); csv.ReadHeader(); while (csv.Read()) { qfiList.Add(CsvToQifHelper.QifValue(outMapping.DateField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.ActionField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.SecurityField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.PriceField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.QuantityField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.TransactionAmountField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.ClearedStatusField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.TextField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.MemoField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.CommisionField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.AccountForTransferField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.AmountTransferedField, csv)); qfiList.Add(QifContants.EndOfEnty); } } return(qfiList); }
public List <string> Convert(IQifMapping <string> inMapping, string csvfile, string acctType) { var outMapping = TranformMapping(inMapping as NonInvestmentAccountsMapping <string>); // var rowCnt = 1; var headerColumns = new Dictionary <string, int> (); var qfiList = new List <string> (); var splitIndicatorMapped = false; if (!string.IsNullOrEmpty(outMapping.SplitIndicatorField.FieldName)) { splitIndicatorMapped = true; } using (var reader = new StreamReader(csvfile)) using (var csv = new CsvReader(reader)) { qfiList.Add(CsvToQifHelper.HeaderName(acctType)); csv.Read(); csv.ReadHeader(); var readRecord = csv.Read(); while (readRecord) { bool split = false; if (splitIndicatorMapped) { // Initialize var saveDate = csv.GetField(outMapping.DateField.FieldName); var savedPayee = csv.GetField(outMapping.PayeeField.FieldName); var mainDate = CsvToQifHelper.QifValue(outMapping.DateField, csv); var mainPayee = CsvToQifHelper.QifValue(outMapping.PayeeField, csv); var mainCleared = CsvToQifHelper.QifValue(outMapping.ClearedField, csv); var mainRef = CsvToQifHelper.QifValue(outMapping.RefOrCheckNumberField, csv); var mainMemo = CsvToQifHelper.QifValue(outMapping.MemoField, csv); var mainCategory = CsvToQifHelper.QifValue(outMapping.CategoryField, csv); var mainAmount = CsvToQifHelper.QifValue(outMapping.AmountField, csv); double totalAmount = 0.00; var aggList = new List <string> (); split = csv.GetField(outMapping.SplitIndicatorField.FieldName) == outMapping.SplitIndicatorField.Prefix; if (split) { do { // split = csv.GetField (outMapping.SplitIndicatorField.FieldName) == outMapping.SplitIndicatorField.Prefix; // // Aggregate // if (split) { aggList.Add(CsvToQifHelper.QifValue(outMapping.SplitCategory, csv)); aggList.Add(CsvToQifHelper.QifValue(outMapping.SplitMemoField, csv)); aggList.Add(CsvToQifHelper.QifValue(outMapping.SplitAmountField, csv)); totalAmount = totalAmount + double.Parse(csv.GetField(outMapping.SplitAmountField.FieldName)); // } readRecord = csv.Read(); }while (readRecord && saveDate == csv.GetField(outMapping.DateField.FieldName) && savedPayee == csv.GetField(outMapping.PayeeField.FieldName) && csv.GetField(outMapping.SplitIndicatorField.FieldName) == outMapping.SplitIndicatorField.Prefix); } else { readRecord = csv.Read(); } qfiList.Add(mainDate); if (aggList.Count > 0) { qfiList.Add($"T{totalAmount}"); } else { qfiList.Add(mainAmount); } qfiList.Add(mainCleared); qfiList.Add(mainRef); qfiList.Add(mainPayee); qfiList.Add(mainMemo); qfiList.Add(mainCategory); qfiList.AddRange(aggList); } else { qfiList.Add(CsvToQifHelper.QifValue(outMapping.DateField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.AmountField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.ClearedField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.RefOrCheckNumberField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.PayeeField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.MemoField, csv)); qfiList.Add(CsvToQifHelper.QifValue(outMapping.CategoryField, csv)); readRecord = csv.Read(); } qfiList.Add(QifContants.EndOfEnty); } } return(qfiList); }