This commit is contained in:
@@ -9,6 +9,8 @@ using Swarmops.Basic.Types.Financial;
|
||||
|
||||
// This is the first part of Database to fully use MySql.
|
||||
|
||||
// TODO: This was written with several classes in one file. Break out to one class per file.
|
||||
|
||||
namespace Swarmops.Database
|
||||
{
|
||||
public partial class SwarmDb
|
||||
@@ -319,16 +321,27 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
public BasicFinancialAccountRow[] GetFinancialAccountRows (int financialAccountId, DateTime startDateTime,
|
||||
DateTime endDateTime)
|
||||
DateTime endDateTime, bool selectFar)
|
||||
{
|
||||
return GetFinancialAccountRows(new int[] {financialAccountId}, startDateTime, endDateTime);
|
||||
return GetFinancialAccountRows(new int[] {financialAccountId}, startDateTime, endDateTime, selectFar);
|
||||
}
|
||||
|
||||
public BasicFinancialAccountRow[] GetFinancialAccountRows(int[] financialAccountIds, DateTime startDateTime,
|
||||
DateTime endDateTime)
|
||||
DateTime endDateTime, bool selectFar)
|
||||
{
|
||||
var result = new List<BasicFinancialAccountRow>();
|
||||
|
||||
// initialize to near selector (equal sign by the lower bound
|
||||
|
||||
string selectorLower = ">=";
|
||||
string selectorUpper = "<";
|
||||
|
||||
if (selectFar) // equal sign by the upper bound
|
||||
{
|
||||
selectorLower = ">";
|
||||
selectorUpper = "<=";
|
||||
}
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
@@ -336,9 +349,9 @@ namespace Swarmops.Database
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"select FinancialTransactionRows.FinancialAccountId,FinancialTransactionRows.FinancialTransactionId,FinancialTransactions.DateTime,FinancialTransactions.Comment,FinancialTransactionRows.AmountCents,FinancialTransactionRows.CreatedDateTime,FinancialTransactionRows.CreatedByPersonId FROM FinancialTransactions,FinancialTransactionRows WHERE FinancialTransactionRows.Deleted=0 AND FinancialTransactions.FinancialTransactionId=FinancialTransactionRows.FinancialTransactionId AND FinancialTransactionRows.FinancialAccountId IN (" +
|
||||
JoinIds(financialAccountIds) + ") AND DateTime >= '" +
|
||||
JoinIds(financialAccountIds) + ") AND DateTime " + selectorLower + " '" +
|
||||
startDateTime.ToString("yyyy-MM-dd HH:mm:ss") +
|
||||
"' AND DateTime < '" + endDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "' ORDER BY DateTime,FinancialTransactions.FinancialTransactionId,FinancialTransactionRows.CreatedDateTime;",
|
||||
"' AND DateTime " + selectorUpper + " '" + endDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "' ORDER BY DateTime,FinancialTransactions.FinancialTransactionId,FinancialTransactionRows.CreatedDateTime;",
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
@@ -444,8 +457,6 @@ namespace Swarmops.Database
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
// TODO: Must limit this to dimension 1
|
||||
|
||||
string commandString = "select FinancialTransactions.FinancialTransactionId, " +
|
||||
"FinancialTransactions.OrganizationId, FinancialTransactions.DateTime, " +
|
||||
"FinancialTransactions.Comment, FinancialTransactions.ImportHash, " +
|
||||
|
||||
@@ -219,6 +219,15 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
public class ExternalBankMismatchingRecordDescription
|
||||
{
|
||||
public ExternalBankMismatchingRecordDescription()
|
||||
{
|
||||
this.Description = string.Empty;
|
||||
this.MasterCents = new long[0];
|
||||
this.SwarmopsCents = new long[0];
|
||||
this.TransactionDependencies = new object[0];
|
||||
this.ResyncAction = ExternalBankMismatchResyncAction.Unknown;
|
||||
}
|
||||
|
||||
public string Description;
|
||||
public long[] MasterCents; // may have multiple txs with this description
|
||||
public long[] SwarmopsCents; // may have multiple txs with this description
|
||||
@@ -226,21 +235,21 @@ namespace Swarmops.Logic.Financial
|
||||
public object[] TransactionDependencies; // matching the Swarmops array
|
||||
}
|
||||
|
||||
public class ExternalBankMismatchHelper
|
||||
public class ExternalBankMismatchConstruction
|
||||
{
|
||||
public ExternalBankMismatchHelper()
|
||||
public ExternalBankMismatchConstruction()
|
||||
{
|
||||
Master = new List<ExternalBankMismatchingRecordHelper>();
|
||||
Swarmops = new List<ExternalBankMismatchingRecordHelper>();
|
||||
Master = new Dictionary<string, ExternalBankMismatchingRecordConstruction>();
|
||||
Swarmops = new Dictionary<string, ExternalBankMismatchingRecordConstruction>();
|
||||
}
|
||||
|
||||
public List<ExternalBankMismatchingRecordHelper> Master;
|
||||
public List<ExternalBankMismatchingRecordHelper> Swarmops;
|
||||
public Dictionary<string, ExternalBankMismatchingRecordConstruction> Master;
|
||||
public Dictionary<string, ExternalBankMismatchingRecordConstruction> Swarmops;
|
||||
}
|
||||
|
||||
public class ExternalBankMismatchingRecordHelper
|
||||
public class ExternalBankMismatchingRecordConstruction
|
||||
{
|
||||
public ExternalBankMismatchingRecordHelper()
|
||||
public ExternalBankMismatchingRecordConstruction()
|
||||
{
|
||||
Cents = new List<long>();
|
||||
Dependencies = new List<object>();
|
||||
@@ -262,6 +271,10 @@ namespace Swarmops.Logic.Financial
|
||||
/// </summary>
|
||||
DeleteSwarmops,
|
||||
/// <summary>
|
||||
/// Create a Swarmops transaction (master exists, not in Swarmops)
|
||||
/// </summary>
|
||||
CreateSwarmops,
|
||||
/// <summary>
|
||||
/// No resync possible - manual action required
|
||||
/// </summary>
|
||||
ManualAction
|
||||
|
||||
@@ -62,7 +62,13 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
public FinancialAccountRows GetRows(DateTime start, DateTime end)
|
||||
{
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identity, start, end);
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identity, start, end, false);
|
||||
return FinancialAccountRows.FromArray(basicRows);
|
||||
}
|
||||
|
||||
public FinancialAccountRows GetRowsFar(DateTime start, DateTime end) // selects lowerbound < x <= upperbound
|
||||
{
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identity, start, end, true);
|
||||
return FinancialAccountRows.FromArray(basicRows);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,5 +23,10 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public FinancialTransaction Transaction
|
||||
{
|
||||
get { return FinancialTransaction.FromIdentity(this.FinancialTransactionId); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,15 @@ namespace Swarmops.Logic.Financial
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialAccounts(financialAccountIds));
|
||||
}
|
||||
|
||||
public FinancialAccountRows GetRows (DateTime start, DateTime end)
|
||||
public FinancialAccountRows GetRows(DateTime start, DateTime end)
|
||||
{
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identities, start, end);
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identities, start, end, false);
|
||||
return FinancialAccountRows.FromArray(basicRows);
|
||||
}
|
||||
|
||||
public FinancialAccountRows GetRowsFar(DateTime start, DateTime end)
|
||||
{
|
||||
BasicFinancialAccountRow[] basicRows = SwarmDb.GetDatabaseForReading().GetFinancialAccountRows(Identities, start, end, true);
|
||||
return FinancialAccountRows.FromArray(basicRows);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,4 +395,12 @@
|
||||
<value>- - Select one - -</value>
|
||||
<comment>Shown in dropdowns when selection required</comment>
|
||||
</data>
|
||||
<data name="Global_Missing" xml:space="preserve">
|
||||
<value>- missing -</value>
|
||||
<comment>When a record or similar is missing. Used in grids.</comment>
|
||||
</data>
|
||||
<data name="Global_Multiple" xml:space="preserve">
|
||||
<value>- multiple -</value>
|
||||
<comment>When there are multiple candidates for something. Synonym: "several". Used in grids.</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -42,9 +42,21 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
|
||||
foreach (ExternalBankMismatchingDateTime mismatch in mismatchArray)
|
||||
{
|
||||
string childrenString = string.Empty; // Room for next step here
|
||||
|
||||
string rowId = mismatch.DateTime.ToString("yyyyMMddHHmmss");
|
||||
|
||||
List<string> childItems = new List<string>();
|
||||
|
||||
foreach (ExternalBankMismatchingRecordDescription mismatchingRecord in mismatch.MismatchingRecords)
|
||||
{
|
||||
childItems.Add("{\"id\":\"" + rowId + childItems.Count.ToString("##0") + "\",\"rowName\":\"" +
|
||||
JsonSanitize(mismatchingRecord.Description) + "\",\"swarmopsData\":\"" +
|
||||
PrintCentsArray(mismatchingRecord.SwarmopsCents) + "\",\"masterData\":\"" +
|
||||
PrintCentsArray(mismatchingRecord.MasterCents) + "\",\"notes\":\"" +
|
||||
JsonSanitize("-todo-") + "\"}");
|
||||
}
|
||||
|
||||
string childrenString = String.Join(",", childItems.ToArray());
|
||||
|
||||
string rowName = mismatch.DateTime.ToString(profile.DateTimeFormatString);
|
||||
|
||||
string swarmopsData = ((double) mismatch.SwarmopsDeltaCents/100.0).ToString("N2") + " " +
|
||||
@@ -68,6 +80,28 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
private Dictionary<int, FinancialAccounts> _hashedAccounts;
|
||||
|
||||
|
||||
private string PrintCents (long cents)
|
||||
{
|
||||
return (((double) cents) / 100.0).ToString("N2"); // TODO: Verify that culture is applied
|
||||
}
|
||||
|
||||
private string PrintCentsArray (long[] cents)
|
||||
{
|
||||
if (cents.Length == 1)
|
||||
{
|
||||
return PrintCents(cents[0]);
|
||||
}
|
||||
else if (cents.Length == 0)
|
||||
{
|
||||
return Resources.Global.Global_Missing;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Resources.Global.Global_Multiple;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string GetAccountGroup (FinancialAccountType type, string localizedGroupName)
|
||||
{
|
||||
string childrenString = GetAccountsRecurse(type, 0);
|
||||
|
||||
@@ -247,6 +247,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
// "AddSeconds" because DeltaCents operates on ">= lowbound, < highbound"
|
||||
long masterDeltaCents = externalData.Records[currentRecordIndex++].TransactionNetCents;
|
||||
int masterTransactionCount = 1;
|
||||
int timestampStartIndex = currentRecordIndex;
|
||||
|
||||
while (currentRecordIndex < externalData.Records.Length &&
|
||||
externalData.Records[currentRecordIndex].DateTime == timeWalker)
|
||||
@@ -266,9 +267,74 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
newMismatch.SwarmopsDeltaCents = swarmopsDeltaCents;
|
||||
newMismatch.SwarmopsTransactionCount = 0; // TODO
|
||||
|
||||
// Load transactions from both sources
|
||||
// Load transactions from both sources. First, create the interim construction object.
|
||||
|
||||
// Analyze actions
|
||||
ExternalBankMismatchConstruction mismatchConstruction = new ExternalBankMismatchConstruction();
|
||||
|
||||
// Load from Master
|
||||
|
||||
for (int innerRecordIndex = timestampStartIndex; innerRecordIndex < currentRecordIndex; innerRecordIndex++)
|
||||
{
|
||||
if (!mismatchConstruction.Master.ContainsKey(externalData.Records[innerRecordIndex].Description))
|
||||
{
|
||||
mismatchConstruction.Master[externalData.Records[innerRecordIndex].Description] =
|
||||
new ExternalBankMismatchingRecordConstruction();
|
||||
}
|
||||
|
||||
mismatchConstruction.Master[externalData.Records[innerRecordIndex].Description].Cents.Add(externalData.Records[innerRecordIndex].TransactionNetCents);
|
||||
mismatchConstruction.Master[externalData.Records[innerRecordIndex].Description].Dependencies.Add(null); // no dependencies on the master side, only on swarmops side
|
||||
}
|
||||
|
||||
// Load from Swarmops
|
||||
|
||||
FinancialAccountRows swarmopsTransactionRows =
|
||||
account.GetRowsFar(lastTimestamp, timeWalker); // the "select far" is a boundary < x <= boundary selector. Default is boundary <= x < boundary.
|
||||
|
||||
foreach (FinancialAccountRow swarmopsTransactionRow in swarmopsTransactionRows)
|
||||
{
|
||||
FinancialTransaction swarmopsTransaction = swarmopsTransactionRow.Transaction;
|
||||
|
||||
if (!mismatchConstruction.Swarmops.ContainsKey(swarmopsTransaction.Description))
|
||||
{
|
||||
mismatchConstruction.Swarmops[swarmopsTransaction.Description] =
|
||||
new ExternalBankMismatchingRecordConstruction();
|
||||
}
|
||||
|
||||
mismatchConstruction.Swarmops[swarmopsTransaction.Description].Cents.Add(swarmopsTransactionRow.AmountCents);
|
||||
mismatchConstruction.Swarmops[swarmopsTransaction.Description].Dependencies.Add(swarmopsTransaction.Dependency);
|
||||
}
|
||||
|
||||
// Then, parse the construction object to the presentation object.
|
||||
|
||||
Dictionary <string,ExternalBankMismatchingRecordDescription> mismatchingRecordList = new Dictionary<string, ExternalBankMismatchingRecordDescription>();
|
||||
|
||||
foreach (string masterKey in mismatchConstruction.Master.Keys)
|
||||
{
|
||||
ExternalBankMismatchingRecordDescription newRecord =
|
||||
new ExternalBankMismatchingRecordDescription();
|
||||
newRecord.Description = masterKey;
|
||||
newRecord.MasterCents = mismatchConstruction.Master[masterKey].Cents.ToArray();
|
||||
|
||||
mismatchingRecordList[masterKey] = newRecord;
|
||||
}
|
||||
|
||||
foreach (string swarmopsKey in mismatchConstruction.Swarmops.Keys)
|
||||
{
|
||||
if (!mismatchingRecordList.ContainsKey(swarmopsKey))
|
||||
{
|
||||
mismatchingRecordList[swarmopsKey] = new ExternalBankMismatchingRecordDescription();
|
||||
mismatchingRecordList[swarmopsKey].Description = swarmopsKey;
|
||||
}
|
||||
|
||||
mismatchingRecordList[swarmopsKey].SwarmopsCents =
|
||||
mismatchConstruction.Swarmops[swarmopsKey].Cents.ToArray();
|
||||
mismatchingRecordList[swarmopsKey].TransactionDependencies =
|
||||
mismatchConstruction.Swarmops[swarmopsKey].Dependencies.ToArray();
|
||||
}
|
||||
|
||||
newMismatch.MismatchingRecords = mismatchingRecordList.Values.ToArray();
|
||||
|
||||
// TODO: Analyze actions
|
||||
|
||||
|
||||
mismatchList.Add(newMismatch);
|
||||
|
||||
Reference in New Issue
Block a user