Committing intermediate work

This commit is contained in:
Rick Falkvinge
2018-04-28 20:16:49 +02:00
parent b455f162b8
commit b12ef267bf
2 changed files with 30 additions and 37 deletions
+9 -16
View File
@@ -15,21 +15,13 @@ namespace Swarmops.Logic.Financial
public ExternalBankDataProfile Profile { get; set; }
public ExternalBankDataRecord[] Records { get; private set; }
public void LoadData (Stream dataStream, Organization organization)
{
using (TextReader reader = new StreamReader (dataStream)) // TODO: Is encoding necessary?
{
LoadData (reader, organization);
}
}
public void LoadData (TextReader reader, Organization organization)
public void LoadData (TextReader reader, Organization organization, Currency expectedCurrency)
{
string data = reader.ReadToEnd();
LoadData (data, organization);
LoadData (data, organization, expectedCurrency);
}
public void LoadData (string data, Organization organization)
public void LoadData (string data, Organization organization, Currency accountCurrency)
{
List<ExternalBankDataRecord> recordList = new List<ExternalBankDataRecord>();
@@ -45,8 +37,11 @@ namespace Swarmops.Logic.Financial
// TODO: Implement bank data reader factory here
string organizationCurrencyCode = organization.Currency.Code;
string accountCurrencyCode = string.Empty;
string expectedCurrencyCode = organization.Currency.Code;
if (accountCurrency != null)
{
expectedCurrencyCode = accountCurrency.Code;
}
// TODO: This function must be made aware of the expected currency code
@@ -128,10 +123,8 @@ namespace Swarmops.Logic.Financial
{
string currency = StripQuotes (lineFields[fieldNameLookup[ExternalBankDataFieldName.Currency]]);
if (currency != organizationCurrencyCode)
if (currency != expectedCurrencyCode)
{
// TODO: Implement nonpresentation currency import right here
continue; // ignore this record
}
}
+21 -21
View File
@@ -337,7 +337,8 @@ namespace Swarmops.Site.Pages.Ledgers
string guid = ((ProcessThreadArguments) args).Guid;
BankFileType fileType = ((ProcessThreadArguments) args).FileType;
Person currentUser = ((ProcessThreadArguments) args).CurrentUser;
Organization organization = ((ProcessThreadArguments) args).Organization;
Organization organization = ((ProcessThreadArguments)args).Organization;
FinancialAccount account = ((ProcessThreadArguments)args).Account;
Documents documents = Documents.RecentFromDescription (guid);
GuidCache.Set (guid + "-Progress", 1); // to make sure results aren't repeated from last file
@@ -349,35 +350,21 @@ namespace Swarmops.Site.Pages.Ledgers
}
Document uploadedDoc = documents[0];
Currency accountCurrency = account.ForeignCurrency;
Currency presentationCurrency = organization.Currency;
try
{
FinancialAccount account = ((ProcessThreadArguments) args).Account;
ExternalBankData externalData = new ExternalBankData();
externalData.Profile = account.ExternalBankDataProfile;
if (fileType == BankFileType.Unknown)
{
StreamReader reader;
switch (externalData.Profile.Encoding.ToUpperInvariant())
{
case "UTF-8":
case "UTF8":
reader = uploadedDoc.GetReader(Encoding.UTF8);
break;
default: // none specified
reader = uploadedDoc.GetReader(1252); // Windows western 1 as default
break;
}
using (reader) // Guarantees disposal of reader
using (StreamReader reader = CreateReader(uploadedDoc, externalData.Profile.Encoding)) // Guarantees disposal of reader
{
try
{
externalData.LoadData (reader, organization);
externalData.LoadData (reader, organization, accountCurrency);
// catch here and set result to BAD
ImportResults results = ProcessImportedData (externalData, (ProcessThreadArguments) args);
@@ -417,9 +404,9 @@ namespace Swarmops.Site.Pages.Ledgers
if (fileType == BankFileType.AccountStatement)
{
using (StreamReader reader = uploadedDoc.GetReader (1252))
using (StreamReader reader = CreateReader(uploadedDoc, externalData.Profile.Encoding)) // Guarantees disposal of reader
{
externalData.LoadData (reader, ((ProcessThreadArguments) args).Organization);
externalData.LoadData (reader, organization, accountCurrency);
// catch here and set result to BAD
ImportResults results = ProcessImportedData (externalData, (ProcessThreadArguments) args);
@@ -457,6 +444,19 @@ namespace Swarmops.Site.Pages.Ledgers
}
static private StreamReader CreateReader(Document document, string encoding = "")
{
switch (encoding)
{
case "UTF-8":
case "UTF8":
return document.GetReader(Encoding.UTF8);
default: // none specified
return document.GetReader(1252); // Windows western 1 as default
}
}
/*
private void Submit_Click(object sender, EventArgs e)
{