diff --git a/Database/Database-Documents.cs b/Database/Database-Documents.cs index e4f7d3db..893b7aa0 100644 --- a/Database/Database-Documents.cs +++ b/Database/Database-Documents.cs @@ -74,7 +74,8 @@ namespace Swarmops.Database string sqlQuery = "SELECT Documents.DocumentId,Documents.ServerFileName,Documents.ClientFileName,Documents.Description,DocumentTypes.Name AS DocumentType,Documents.ForeignId,Documents.FileSize,Documents.UploadedByPersonId,Documents.UploadedDateTime From Documents,DocumentTypes " + - "WHERE Documents.Description = '" + description.Replace ("'", "''") + "' AND " + + "WHERE Documents.DocumentTypeId=DocumentTypes.DocumentTypeId AND " + + "Documents.Description = '" + description.Replace("'", "''") + "' AND " + "Documents.UploadedDateTime > '" + DateTime.UtcNow.AddDays (-1).ToString ("yyyy-MM-dd HH:mm") + "'"; DbCommand command = GetDbCommand(sqlQuery, connection); diff --git a/Logic/Financial/ExternalBankData.cs b/Logic/Financial/ExternalBankData.cs new file mode 100644 index 00000000..8e88f71a --- /dev/null +++ b/Logic/Financial/ExternalBankData.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using Swarmops.Logic.Structure; + +namespace Swarmops.Logic.Financial +{ + public class ExternalBankData + { + 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) + { + string data = reader.ReadToEnd(); + LoadData(data, organization); + } + + public void LoadData(string data, Organization organization) + { + List recordList = new List(); + + if (Profile == null) + { + throw new InvalidOperationException("Cannot call LoadData before a profile has been set"); + } + + string organizationCurrencyCode = organization.Currency.Code; + + int crlfIndex = data.IndexOfAny(new char[] {'\n', '\r'}); + + string fieldKeyLine = data.Substring(0, crlfIndex); + + string[] dataKeyFields = fieldKeyLine.Split('\t'); + + Dictionary fieldNameLookup = + new Dictionary(); + + // below is an N^2 loop but doesn't matter in such a small context + + foreach (ExternalBankDataFieldName fieldName in Profile.FieldNames.Keys) + { + for (int index = 0; index < dataKeyFields.Length; index++) + { + if (dataKeyFields[index].Trim() == Profile.FieldNames[fieldName]) + { + fieldNameLookup[fieldName] = index; + break; + } + } + + if (!fieldNameLookup.ContainsKey(fieldName)) // wasn't found + { + throw new ArgumentException("Field key \"" + fieldName + "\" was not supplied or found in data file"); + } + } + + + data = data.Substring(crlfIndex).Trim(); + + string[] lines = data.Split(new char[] {'\r', '\n'}); + + foreach (string lineData in lines) + { + string line = lineData.Trim(); + + if (line.Length < 1) + { + continue; // empty lines may exist due to split on either CR or LF + } + + string[] lineFields = line.Split('\t'); + + // If wrong currency, ignore + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.Currency)) + { + string currency = lineFields[fieldNameLookup[ExternalBankDataFieldName.Currency]]; + + if (currency != organizationCurrencyCode) + { + continue; // ignore this record + } + } + + + ExternalBankDataRecord newRecord = new ExternalBankDataRecord(); + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.Description)) + { + newRecord.Description = lineFields[fieldNameLookup[ExternalBankDataFieldName.Description]]; + } + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.AccountBalance)) + { + // Dividing up to step-by-step statements instead of one long statement assists debugging + // of culture and other error sources + + string balanceString = lineFields[fieldNameLookup[ExternalBankDataFieldName.AccountBalance]]; + double parsedBalance = Double.Parse(balanceString, NumberStyles.Currency, new CultureInfo(Profile.Culture)); + newRecord.AccountBalanceCents = (long) Math.Floor(parsedBalance*100.0); + } + + if (!fieldNameLookup.ContainsKey(ExternalBankDataFieldName.Date) && !fieldNameLookup.ContainsKey(ExternalBankDataFieldName.DateTime)) + { + throw new InvalidOperationException("Cannot parse transactions file without at least a date field"); + } + + DateTime dateTime = DateTime.MinValue; + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.Date)) + { + string dateString = lineFields[fieldNameLookup[ExternalBankDataFieldName.Date]]; + dateTime = DateTime.Parse(dateString, new CultureInfo(Profile.Culture)); + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.Time)) + { + string timeString = lineFields[fieldNameLookup[ExternalBankDataFieldName.Time]]; + TimeSpan timeOfDay = TimeSpan.Parse(timeString); + + dateTime += timeOfDay; + } + else + { + // move transaction to like mid-day of the organization's time zone. For now, all orgs are in Europe, so add 12 hours + // this is a HACK HACK HACK + + dateTime = dateTime.AddHours(12); + } + } + else // no Date field, so by earlier logic, must have a DateTime field + { + dateTime = DateTime.Parse(lineFields[fieldNameLookup[ExternalBankDataFieldName.DateTime]], new CultureInfo(Profile.Culture)); + } + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.TimeZone)) + { + // Valid time zone formats are "XXX+hh:mm". The XXX are ignored. + + // Throws exception if this doesn't parse, which is what we want + + TimeSpan timeZone = + TimeSpan.Parse(lineFields[fieldNameLookup[ExternalBankDataFieldName.TimeZone]].Substring(4)); + + dateTime -= timeZone; // minus, to bring the time to UTC. If time 13:00 is in tz +01:00, the UTC time is 12:00 + } + + newRecord.DateTime = dateTime; + + if (!fieldNameLookup.ContainsKey(ExternalBankDataFieldName.TransactionNet)) + { + throw new ArgumentException("There must be a transaction amount field in the bank data profile"); + } + + string amountNetString = lineFields[fieldNameLookup[ExternalBankDataFieldName.TransactionNet]]; + double amountNetDouble = Double.Parse(amountNetString, NumberStyles.Currency, + new CultureInfo(Profile.Culture)); + + newRecord.TransactionNetCents = (long) (amountNetDouble*100.0); + + // TODO: Net, fee + + if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.UniqueId)) + { + newRecord.UniqueId = lineFields[fieldNameLookup[ExternalBankDataFieldName.UniqueId]]; + } + else if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.NotUniqueId)) + { + newRecord.NotUniqueId = lineFields[fieldNameLookup[ExternalBankDataFieldName.NotUniqueId]]; + } + + recordList.Add(newRecord); + } + + recordList.Sort(new ExternalBankDataRecord()); + + this.Records = recordList.ToArray(); + } + + public ExternalBankDataProfile Profile { get; set; } + public ExternalBankDataRecord[] Records { get; private set; } + } +} diff --git a/Logic/Financial/ExternalBankDataProfile.cs b/Logic/Financial/ExternalBankDataProfile.cs new file mode 100644 index 00000000..3de98daf --- /dev/null +++ b/Logic/Financial/ExternalBankDataProfile.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Structure; + +namespace Swarmops.Logic.Financial +{ + public class ExternalBankDataProfile + { + private ExternalBankDataProfile() + { + this.FieldNames = new Dictionary(); + } + + static public ExternalBankDataProfile FromIdentity (int externalBankDataProfileId) + { + ExternalBankDataProfile result = new ExternalBankDataProfile(); + + // Ugly hack for now + + if (externalBankDataProfileId == SESebId) + { + result.Name = "SEB"; + result.Country = Country.FromCode("SE"); + result.Culture = "sv-SE"; + + result.FieldNames[ExternalBankDataFieldName.Date] = "Bokföringsdatum"; + result.FieldNames[ExternalBankDataFieldName.Description] = "Text/mottagare"; + result.FieldNames[ExternalBankDataFieldName.TransactionNet] = "Belopp"; + result.FieldNames[ExternalBankDataFieldName.AccountBalance] = "Saldo"; + result.FieldNames[ExternalBankDataFieldName.NotUniqueId] = "Verifikationsnummer"; + + return result; + } + + if (externalBankDataProfileId == PaypalId) + { + result.Name = "Paypal"; + result.Country = null; + result.Culture = "sv-SE"; // what the actual fuck? Paypal's giving me sv-SE culture + + result.FieldNames[ExternalBankDataFieldName.Date] = "Date"; + result.FieldNames[ExternalBankDataFieldName.Time] = "Time"; + result.FieldNames[ExternalBankDataFieldName.TimeZone] = "Time Zone"; + result.FieldNames[ExternalBankDataFieldName.Description] = "Name"; + result.FieldNames[ExternalBankDataFieldName.Currency] = "Currency"; + result.FieldNames[ExternalBankDataFieldName.TransactionGross] = "Gross"; + result.FieldNames[ExternalBankDataFieldName.TransactionFee] = "Fee"; + result.FieldNames[ExternalBankDataFieldName.TransactionNet] = "Net"; + result.FieldNames[ExternalBankDataFieldName.AccountBalance] = "Balance"; + result.FieldNames[ExternalBankDataFieldName.UniqueId] = "Transaction ID"; + + return result; + } + + throw new ArgumentException("Unrecognized profile Id"); + } + + static public int SESebId { get { return 1; } } // Ugly pre-db hacks + static public int PaypalId { get { return 2; } } + + public string Name { get; set; } + public Country Country { get; set; } + public string Culture { get; set; } + public string Currency { get; set; } + + public Dictionary FieldNames { get; private set; } + } + + public enum ExternalBankDataFieldName + { + Unknown = 0, + AccountBalance, + TransactionGross, + TransactionFee, + TransactionNet, + Description, + UniqueId, + NotUniqueId, + Date, + Time, + DateTime, + TimeZone, + Currency + } +} diff --git a/Logic/Financial/ExternalBankDataRecord.cs b/Logic/Financial/ExternalBankDataRecord.cs new file mode 100644 index 00000000..1585d30b --- /dev/null +++ b/Logic/Financial/ExternalBankDataRecord.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Swarmops.Logic.Financial +{ + public class ExternalBankDataRecord: IComparer + { + public long AccountBalanceCents; + public long TransactionGrossCents; + public long TransactionNetCents; + public long FeeCents; + public string Description; + public DateTime DateTime; // UTC! + public string UniqueId; + public string NotUniqueId; // As it says, but something that still assists in creating a hash together w/ other fields + + #region Implementation of IComparer + + public int Compare(ExternalBankDataRecord x, ExternalBankDataRecord y) + { + // Use only DateTime to compare + + return x.DateTime.CompareTo(y.DateTime); + } + + #endregion + } +} diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index cbca441c..840151da 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -97,6 +97,9 @@ + + + diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index d2105b7d..6954ca52 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -391,4 +391,8 @@ Revenue + + - - Select one - - + Shown in dropdowns when selection required + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Menu5.resx b/Site5/App_GlobalResources/Menu5.resx index 6bc1f0e7..37f0ca5e 100644 --- a/Site5/App_GlobalResources/Menu5.resx +++ b/Site5/App_GlobalResources/Menu5.resx @@ -270,6 +270,9 @@ Profit & Loss Statement + + Resync Bank Account + Set Budget Amounts diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index d6d1f032..9d32d4b4 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -218,6 +218,12 @@ YTD Year To Date + + If your bookkeeping in Swarmops has gotten out of sync with your bank records for whatever technical or human reason, you can resynchronize them here by uploading a master file that covers the time frame you need to resync.<br/><br/><strong>Warning:</strong> this is a time-consuming process that may do a <em>lot</em> of changes to your bookkeeping. Do not use unless you have discovered a mismatch in the records vs. your bank.<br/><br/>(You will get a chance to review proposed changes before they are committed to your financial records.) + + + Resynchronize Bank Account + Budget, Owner Displayed above editables diff --git a/Site5/Automation/UploadFileHandler.ashx b/Site5/Automation/UploadFileHandler.ashx index d895611d..35d1047e 100644 --- a/Site5/Automation/UploadFileHandler.ashx +++ b/Site5/Automation/UploadFileHandler.ashx @@ -182,28 +182,34 @@ namespace Swarmops.Frontend.Automation ms.Write(fileData, 0, file.ContentLength); ms.Position = 0;*/ - // Try to load as image. If fails, not an acceptable file + string filterType = context.Request.QueryString["Filter"]; - try + if (filterType != "NoFilter") { - Image image = Image.FromStream (file.InputStream); - image.Dispose(); - } - catch (Exception) - { - // TODO: If general files accepted, then ok, otherwise fuck off - // TODO: Accept general files + // Try to load as image. If fails, not an acceptable file - var errorStatus = new FilesStatus (fullName, file.ContentLength); - errorStatus.error = "ERR_NOT_IMAGE"; - errorStatus.url = string.Empty; - errorStatus.delete_url = string.Empty; - errorStatus.thumbnail_url = string.Empty; + try + { + Image image = Image.FromStream(file.InputStream); + image.Dispose(); + } + catch (Exception) + { + // TODO: If general files accepted, then ok, otherwise fuck off - statuses.Add (errorStatus); - // -1 for length means the file was NOT saved, and that it could not be parsed as image. - return; + // TODO: Accept general files + + var errorStatus = new FilesStatus(fullName, file.ContentLength); + errorStatus.error = "ERR_NOT_IMAGE"; + errorStatus.url = string.Empty; + errorStatus.delete_url = string.Empty; + errorStatus.thumbnail_url = string.Empty; + + statuses.Add(errorStatus); + // -1 for length means the file was NOT saved, and that it could not be parsed as image. + return; + } } } diff --git a/Site5/Controls/v5/Base/FileUpload.ascx b/Site5/Controls/v5/Base/FileUpload.ascx index 67325572..a7e28c16 100644 --- a/Site5/Controls/v5/Base/FileUpload.ascx +++ b/Site5/Controls/v5/Base/FileUpload.ascx @@ -9,16 +9,24 @@ var imageFileEnd = "' /\x3E"; // needs to be separate var rather than inline because of mono-server optimization bug var imageUploadSuccess = imageFileStart + imageFileSuccess + imageFileEnd; var imageUploadFail = imageFileStart + imageFileFail + imageFileEnd; - + $(document).ready(function() { $('#<%=this.ClientID %>_ButtonUploadHidden').fileupload({ - url: '/Automation/UploadFileHandler.ashx?Guid=<%= GuidString %>', + url: '/Automation/UploadFileHandler.ashx?Guid=<%= GuidString %>&Filter=<%=Filter %>', dataType: 'json', done: function(e, data) { $.each(data.result, function(index, file) { if (file.error == null || file.error.length < 1) { $('#<%=this.ClientID %>_DivUploadCount').append(imageUploadSuccess); + + <% if (this.ClientUploadCompleteCallback.Length > 0) + { %> + + <%= this.ClientUploadCompleteCallback %>(); + + <% } %> + } else { $('#<%=this.ClientID %>_DivUploadCount').append(imageUploadFail); // Assume ERR_NOT_IMAGE alertify.error('File "' + file.name + '" could not be uploaded. Is it really an image?'); @@ -56,5 +64,5 @@ -
 
+
/>
​
diff --git a/Site5/Controls/v5/Base/FileUpload.ascx.cs b/Site5/Controls/v5/Base/FileUpload.ascx.cs index 8ec00c0d..88778eee 100644 --- a/Site5/Controls/v5/Base/FileUpload.ascx.cs +++ b/Site5/Controls/v5/Base/FileUpload.ascx.cs @@ -21,6 +21,14 @@ namespace Swarmops.Controls.Base { Filter = UploadFilter.NoFilter; } + if (this.DisplayCount == 0) // if not set + { + this.DisplayCount = 16; + } + if (this.ClientUploadCompleteCallback == null) + { + this.ClientUploadCompleteCallback = string.Empty; + } } else { @@ -30,6 +38,9 @@ namespace Swarmops.Controls.Base public string GuidString; public UploadFilter Filter { get; set; } + public int DisplayCount { get; set; } + public bool HideTrigger { get; set; } + public string ClientUploadCompleteCallback { get; set; } public enum UploadFilter diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 015642a7..f0d04f32 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -190,6 +190,7 @@ + diff --git a/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx b/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx new file mode 100644 index 00000000..3ac3ad0c --- /dev/null +++ b/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx @@ -0,0 +1,222 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ResyncExternalAccount.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.ResyncExternalAccount" %> +<%@ Register src="~/Controls/v5/UI/ExternalScripts.ascx" tagname="ExternalScripts" tagprefix="Swarmops5" %> +<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %> + + + + + + + + + + + + + + + +
+

Step 1/4: Upload Master File

+
+ +
+   +
+ + +
+ +
+
+ + + +

Step 3/4: Comparison results - Resync?

+ +

Step 4/4: Resynchronizing with master...

+ +

Resynchronization complete

+ + + + + + + + + + + + + +
——————
+
+ + + + + diff --git a/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx.cs b/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx.cs new file mode 100644 index 00000000..b01856d0 --- /dev/null +++ b/Site5/Pages/v5/Ledgers/ResyncExternalAccount.aspx.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Web; +using System.Web.Services; +using System.Web.UI; +using System.Web.UI.WebControls; +using System.Globalization; +using Swarmops.Basic.Enums; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; + +namespace Swarmops.Frontend.Pages.v5.Ledgers +{ + public partial class ResyncExternalAccount : PageV5Base + { + static ResyncExternalAccount() + { + _staticDataLookup = new Dictionary(); // This does not work at all for webfarms, which may be a problem down the road + } + + public static string StorageRoot + { + get + { + if (Debugger.IsAttached) + { + return @"C:\Windows\Temp\\Swarmops-Debug\\"; // Windows debugging environment + } + else + { + return "/opt/swarmops/upload/"; // production location on Debian installation TODO: config file + } + } + } + + protected void Page_Load(object sender, EventArgs e) + { + if (!this.CurrentOrganization.IsEconomyEnabled) + { + Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true); + return; + } + + this.PageIcon = "iconshock-treasure"; + this.PageTitle = Resources.Pages.Ledgers.ResyncExternalAccount_PageTitle; + this.InfoBoxLiteral = Resources.Pages.Ledgers.ResyncExternalAccount_Info; + + if (!Page.IsPostBack) + { + this.DropAccounts.Items.Add(new ListItem(Resources.Global.Global_SelectOne, "0")); + + FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization, + FinancialAccountType.Asset); + + foreach (FinancialAccount account in accounts) + { + // TODO: COnstruct import settings for accounts + + if (this.CurrentOrganization.Name == "Piratpartiet SE" && account.Identity == 1) + { + this.DropAccounts.Items.Add(new ListItem(account.Name + " (SE/SEB)", account.Identity.ToString(CultureInfo.InvariantCulture))); + } + } + + + Localize(); + } + } + + + private void Localize() + { + } + + + + [WebMethod(true)] + public static int GetProcessingProgress(string guid) + { + // Get data from static variables + + string key = guid + "PercentRead"; + + if (!_staticDataLookup.ContainsKey(key)) + { + return 0; + } + + return (int)_staticDataLookup[key]; + } + + [WebMethod(true)] + public static ExternalBankDataStatistics GetProcessingStatistics(string guid) + { + // Get data from static variables + + string key = guid + "PercentRead"; + + if (!_staticDataLookup.ContainsKey(key)) + { + return null; + } + + ExternalBankDataStatistics result = new ExternalBankDataStatistics(); + + result.FirstTransaction = (string)_staticDataLookup[guid + "FirstTx"]; + result.LastTransaction = (string)_staticDataLookup[guid + "LastTx"]; + result.TransactionCount = (string)_staticDataLookup[guid + "TxCount"]; + + return result; + } + + + + + + [WebMethod(true)] + public static void InitializeProcessing(string guid) + { + // Start an async thread that does all the work, then return + + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + Thread initThread = new Thread(ProcessUploadThread); + + ProcessThreadArguments args = new ProcessThreadArguments + {Guid = guid, Organization = authData.CurrentOrganization}; + + initThread.Start(args); + } + + + public class ExternalBankDataStatistics + { + public string FirstTransaction { get; set; } + public string LastTransaction { get; set; } + public string TransactionCount { get; set; } + } + + + private class ProcessThreadArguments + { + public string Guid { get; set; } + public Organization Organization { get; set; } + } + + + private static void ProcessUploadThread(object args) + { + string guid = ((ProcessThreadArguments) args).Guid; + + Documents documents = Documents.RecentFromDescription(guid); + + if (documents.Count != 1) + { + return; // abort + } + + Document uploadedDoc = documents[0]; + + ExternalBankData externalData = new ExternalBankData(); + externalData.Profile = ExternalBankDataProfile.FromIdentity(ExternalBankDataProfile.SESebId); // HACK HACK HACK + + using (StreamReader reader = new StreamReader(StorageRoot + uploadedDoc.ServerFileName, Encoding.GetEncoding(1252))) + { + externalData.LoadData(reader, ((ProcessThreadArguments) args).Organization); + } + + _staticDataLookup[guid + "FirstTx"] = externalData.Records[0].DateTime.ToLongDateString(); + _staticDataLookup[guid + "LastTx"] = + externalData.Records[externalData.Records.Length - 1].DateTime.ToLongDateString(); + _staticDataLookup[guid + "TxCount"] = externalData.Records.Length.ToString("N0"); + + _staticDataLookup[guid + "PercentRead"] = 1; + + int accountId = 1; // TODO: HACK HACK HACK HACK + + FinancialAccount account = FinancialAccount.FromIdentity(accountId); + + DateTime timeWalker = externalData.Records[0].DateTime; + int currentRecordIndex = 0; + + // Walk past the first identical time records, and verify that we have at least one balance record that matches + // our own for this timestamp. There may be several transactions in the master file, but at least one should have + // a post-transaction balance that matches our records, or something is much more broken. + + long swarmopsCentsStart = account.GetDeltaCents(DateTime.MinValue, timeWalker.AddSeconds(1)); + + // At least one of the transactions for this timestamp should match. + + bool foundMatch = false; + + while (externalData.Records [currentRecordIndex].DateTime == timeWalker) + { + if (externalData.Records[currentRecordIndex].AccountBalanceCents == swarmopsCentsStart) + { + foundMatch = true; + + // continue loop until on first record past initial conditions + } + currentRecordIndex++; // no test for array overrun in while + } + + if (!foundMatch) + { + throw new InvalidOperationException("Unable to locate stable initial conditions for resynchronization"); + } + + // From here on out, every new timestamp should have the exact same delta in Swarmops as it has in the master file. + + DateTime lastTimestamp = timeWalker; + + timeWalker = externalData.Records[currentRecordIndex].DateTime; + + long swarmopsDeltaCents = account.GetDeltaCents(lastTimestamp.AddSeconds(1), timeWalker.AddSeconds(1)); // "AddSeconds" because DeltaCents operates on ">= lowbound, < highbound" + long masterDeltaCents = externalData.Records[currentRecordIndex].TransactionNetCents; + + + } + + private static Dictionary _staticDataLookup; + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs index 8a2cf337..0766a123 100644 --- a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs +++ b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs @@ -282,7 +282,7 @@ namespace Swarmops.Site.Pages.Ledgers this.LabelImportResultsHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_FileImportedHeader_ErrorBalance; } } - catch (Exception exception) + catch (InvalidOperationException exception) { this.LiteralDownloadInstructionsModal.Text = exception.ToString(); // For debug purposes -- will not be shown to user this.PanelErrorImage.Visible = true; @@ -883,8 +883,13 @@ namespace Swarmops.Site.Pages.Ledgers row.Comment = StripQuotes(parts[4]); row.DateTime = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]), CultureInfo.InvariantCulture); row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", "").Replace(",", "").Replace(" ", "")); - row.FeeCents = Int64.Parse(StripQuotes(parts[8]).Replace(".", "").Replace(",", "").Replace(" ", ""), CultureInfo.InvariantCulture); row.AmountCentsNet = Int64.Parse(StripQuotes(parts[9]).Replace(".", "").Replace(",", "").Replace(" ", "")); + row.FeeCents = 0; + if (parts[8] != "\"...\"") // used as fee field for payments held/cleared + { + row.FeeCents = Int64.Parse(StripQuotes(parts[8]).Replace(".", "").Replace(",", "").Replace(" ", ""), CultureInfo.InvariantCulture); + } + // Adjust for timezone -- necessary for Paypal and other int'l services