This commit is contained in:
Rick Falkvinge
2019-01-10 12:03:49 +01:00
33 changed files with 1377 additions and 71 deletions
+1
View File
@@ -57,6 +57,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DbColumnAwareBase.cs" />
<Compile Include="Types\Common\BlockchainHash.cs" />
<Compile Include="Types\Financial\BasicExpenseClaimGroup.cs" />
<Compile Include="Types\Financial\BasicFinancialAccountDocument.cs" />
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
/* 2018-Dec-22: This is a started refactoring of the Database namespace into separate derived classes
* from a generic that contains most of the gruntwork. It is not nearly complete and
* the code is still experimental, not taken into production yet.
*/
namespace Swarmops.Basic
{
public class DbColumnAwareBase
{
static DbColumnAwareBase()
{
if (_classColumnOrdinalLookup == null)
{
_classColumnOrdinalLookup = new Dictionary<string, Dictionary<string, int>>();
_classColumnSequenceLookup = new Dictionary<string, string>();
}
}
public DbColumnAwareBase()
{
// ReSharper disable once DoNotCallOverridableMethodsInConstructor
VerifyLookupInitialized();
}
private static Dictionary<string, Dictionary<string, int>> _classColumnOrdinalLookup;
private static Dictionary<string, string> _classColumnSequenceLookup;
public virtual void VerifyLookupInitialized()
{
string className = this.GetType().Name;
if (_classColumnOrdinalLookup.ContainsKey(className))
{
return;
}
// The key of the instantiated class is not in the dictionary, so initialize dictionary
// This is done with reflection, so is very expensive, which is why we only do it once for
// every class that derives from DbColumnAwareBase
;
}
/*
*
* sample SELECT sequence:
* private const string financialAccountDocumentFieldSequence =
" FinancialAccountDocumentId,FinancialAccountId,FinancialAccountDocumentTypes.Name,UploadedDateTime,UploadedByPersonId, " + // 0-4
" ConcernsPeriodStart,ConcernsPeriodEnd,RawDocumentText " + // 5-7
" FROM FinancialAccountDocuments JOIN FinancialAccountDocumentTypes USING (FinancialAccountDocumentTypeId) ";
*/
}
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Common.Attributes;
using Swarmops.Common.Enums;
using Swarmops.Common.Interfaces;
@@ -38,14 +39,25 @@ namespace Swarmops.Basic.Types.Financial
// empty copy ctor
}
// Identity field
[DbColumnName] [DbIdentity]
public int FinancialAccountDocumentId { get; private set; }
public int FinancialAccountId { get; private set; }
// Name-identical dbcolumns / properties
[DbColumnName] public int FinancialAccountId { get; private set; }
[DbColumnName] public DateTime UploadedDateTime { get; private set; }
[DbColumnName] public int UploadedByPersonId { get; private set; }
[DbColumnName] public DateTime ConcernsPeriodStart { get; private set; }
[DbColumnName] public DateTime ConcernsPeriodEnd { get; private set; }
[DbColumnName] public string RawDocumentText { get; private set; }
// Complex or renamed dbcolumns / properties
[DbColumnForeignTypeName("FinancialAccountDocumentTypes", "FinancialAccountDocumentTypeId", "Name")]
public FinancialAccountDocumentType Type { get; private set; }
public DateTime UploadedDateTime { get; private set; }
public int UploadedByPersonId { get; private set; }
public DateTime ConcernsPeriodStart { get; private set; }
public DateTime ConcernsPeriodEnd { get; private set; }
public string RawDocumentText { get; private set; }
public int Identity { get { return this.FinancialAccountDocumentId; } }
}
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* 2018-Dec-22: This is a started refactoring of the Database namespace into separate derived classes
* from a generic that contains most of the gruntwork. It is not nearly complete and
* the code is still experimental, not taken into production yet.
*/
namespace Swarmops.Common.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class DbColumnName: Attribute
{
public DbColumnName()
{
// empty attr means the column name is the same as the property name that houses the attribute
this.ColumnName = string.Empty;
}
public DbColumnName(string columnName)
{
this.ColumnName = columnName;
}
public string ColumnName { get; private set; }
}
}
+24
View File
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Swarmops.Common.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class DbColumnForeignTypeName: Attribute
{
public DbColumnForeignTypeName(string foreignTableName, string commonIdColumnName, string foreignTypeColumnName)
{
this.ForeignTableName = foreignTableName;
this.CommonIdColumnName = commonIdColumnName;
this.ForeignTypeColumnName = foreignTypeColumnName;
}
public string ForeignTableName { get; private set; }
public string CommonIdColumnName { get; private set; }
public string ForeignTypeColumnName { get; private set; }
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Swarmops.Common.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class DbIdentity: Attribute
{
public DbIdentity() { }
}
}
+4
View File
@@ -40,7 +40,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes\DbColumnTypeName.cs" />
<Compile Include="Attributes\DbEnumField.cs" />
<Compile Include="Attributes\DbColumnName.cs" />
<Compile Include="Attributes\DbIdentity.cs" />
<Compile Include="Attributes\DbRecordType.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Enums\AddressValidationResult.cs" />
@@ -82,6 +85,7 @@
<Compile Include="ExtensionMethods\Color.cs" />
<Compile Include="ExtensionMethods\DateTime.cs" />
<Compile Include="Generics\Tree.cs" />
<Compile Include="Interfaces\IDatabaseColumnAware.cs" />
<Compile Include="Interfaces\IEmailPerson.cs" />
<Compile Include="Interfaces\IHandleProvider.cs" />
<Compile Include="Interfaces\IHasIdentities.cs" />
+6 -1
View File
@@ -77,6 +77,11 @@ namespace Swarmops.Common.Enums
/// <summary>
/// Nor this
/// </summary>
Salary
Salary,
/// <summary>
/// Documentation related to a financial account, usually an external one
/// </summary>
FinancialAccountDocument
}
}
+2 -1
View File
@@ -10,6 +10,7 @@ namespace Swarmops.Common.Enums
{
Unknown = 0,
BankStatement,
BankTransactionData
BankTransactionData,
BankPaymentData
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* 2018-Dec-22: This is a started refactoring of the Database namespace into separate derived classes
* from a generic that contains most of the gruntwork. It is not nearly complete and
* the code is still experimental, not taken into production yet.
*/
namespace Swarmops.Common.Interfaces
{
[SuppressMessage("ReSharper", "TypeParameterCanBeVariant")]
public interface IDatabaseColumnAware<TBasic>
{
// these could all be static but C# doesn't allow static methods in interfaces
string DbTableName { get; }
string[] DbColumnSequence { get; }
string DbIdentityColumn { get; }
TBasic FromDataReader (IDataReader reader);
}
}
@@ -0,0 +1,464 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common.Enums;
namespace Swarmops.Database
{
public partial class SwarmDb
{
#region Database field reading
private const string financialAccountDocumentFieldSequence =
" FinancialAccountDocumentId,FinancialAccountId,FinancialAccountDocumentTypes.Name,UploadedDateTime,UploadedByPersonId, " + // 0-4
" ConcernsPeriodStart,ConcernsPeriodEnd,RawDocumentText " + // 5-7
" FROM FinancialAccountDocuments JOIN FinancialAccountDocumentTypes USING (FinancialAccountDocumentTypeId) ";
private static BasicFinancialAccountDocument ReadFinancialAccountDocumentFromDataReader(IDataRecord reader)
{
int financialAccountDocumentId = reader.GetInt32(0);
int financialAccountId = reader.GetInt32(1);
string financialAccountDocumentTypeString = reader.GetString(2);
DateTime uploadedDateTime = reader.GetDateTime(3);
int uploadedByPersonId = reader.GetInt32(4);
DateTime concernsPeriodStart = reader.GetDateTime(5);
DateTime concernsPeriodEnd = reader.GetDateTime(6);
string rawText = reader.GetString(7);
FinancialAccountDocumentType docType = (FinancialAccountDocumentType) Enum.Parse(typeof (FinancialAccountDocumentType), financialAccountDocumentTypeString);
return new BasicFinancialAccountDocument(financialAccountDocumentId, financialAccountId, docType, uploadedDateTime, uploadedByPersonId, concernsPeriodStart,
concernsPeriodEnd, rawText);
}
#endregion
#region Database record reading -- SELECT clauses
public BasicFinancialAccountDocument GetFinancialAccountDocument(int financialAccountDocumentId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand("SELECT" + financialAccountDocumentFieldSequence +
"WHERE FinancialAccountDocumentId=" + financialAccountDocumentId,
connection);
using (DbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return ReadFinancialAccountDocumentFromDataReader(reader);
}
throw new ArgumentException("No such FinancialAccountDocumentId:" + financialAccountDocumentId);
}
}
}
public BasicFinancialAccountDocument[] GetFinancialAccountDocuments(params object[] conditions)
{
List<BasicFinancialAccountDocument> result = new List<BasicFinancialAccountDocument>();
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand(
"SELECT" + financialAccountDocumentFieldSequence + ConstructWhereClause("Payments", conditions), connection);
using (DbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(ReadFinancialAccountDocumentFromDataReader(reader));
}
return result.ToArray();
}
}
}
#endregion
#region Creation and manipulation -- stored procedures
public int CreateFinancialAccountDocument(int financialAccountId, FinancialAccountDocumentType type, int uploadedByPersonId,
DateTime concernsPeriodStart, DateTime concernsPeriodEnd, string rawText)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("CreateFinancialAccountDocument", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "financialAccountId", financialAccountId);
AddParameterWithName(command, "financialAccountDocumentType", type.ToString());
AddParameterWithName(command, "uploadedDateTime", DateTime.UtcNow);
AddParameterWithName(command, "uploadedByPersonId", uploadedByPersonId);
AddParameterWithName(command, "concernsPeriodStart", concernsPeriodStart); // inclusive endpoint
AddParameterWithName(command, "concernsPeriodEnd", concernsPeriodEnd); // exclusive endpoint
AddParameterWithName(command, "rawDocumentText", rawText);
return Convert.ToInt32(command.ExecuteScalar());
}
}
#endregion
#region Dead template code
/*
public BasicExpenseClaim GetExpenseClaim(int expenseClaimId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
"FROM ExpenseClaims WHERE ExpenseClaimId=" + expenseClaimId.ToString(),
connection);
using (DbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return ReadExpenseFromDataReader(reader);
}
throw new ArgumentException("Unknown ExpenseClaim Id");
}
}
}
public BasicExpenseClaim[] GetExpenseClaimsByClaimer(int claimingPersonId)
{
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
"FROM ExpenseClaims WHERE ClaimingPersonId=" + claimingPersonId.ToString(),
connection);
using (DbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(ReadExpenseFromDataReader(reader));
}
return result.ToArray();
}
}
}
public BasicExpenseClaim[] GetExpenseClaimsByBudgetAndYear(int budgetId, int budgetYear)
{
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
"FROM ExpenseClaims WHERE BudgetId=" + budgetId.ToString() + " AND BudgetYear=" + budgetYear.ToString(),
connection);
using (DbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(ReadExpenseFromDataReader(reader));
}
return result.ToArray();
}
}
}
public BasicExpenseClaim[] GetExpenseClaimsByOrganization(int organizationId)
{
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
"FROM ExpenseClaims WHERE OrganizationId=" + organizationId.ToString(),
connection);
using (DbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(ReadExpenseFromDataReader(reader));
}
return result.ToArray();
}
}
}
private BasicExpenseClaim ReadExpenseFromDataReader(DbDataReader reader)
{
int expenseClaimId = reader.GetInt32(0);
int claimingPersonId = reader.GetInt32(1);
DateTime createdDateTime = reader.GetDateTime(2);
bool open = reader.GetBoolean(3);
bool attested = reader.GetBoolean(4);
bool documented = reader.GetBoolean(5);
bool claimed = reader.GetBoolean(6);
int organizationId = reader.GetInt32(7);
int geographyId = reader.GetInt32(8); // obsolete field
int budgetId = reader.GetInt32(9);
int budgetYear = reader.GetInt32(10);
DateTime expenseDate = reader.GetDateTime(11);
string description = reader.GetString(12);
double preApprovedAmount = reader.GetDouble(13);
double amount = reader.GetDouble(14);
bool repaid = reader.GetBoolean(15);
return new BasicExpenseClaim(expenseClaimId, claimingPersonId, createdDateTime,
open, attested, documented, claimed, organizationId, geographyId,
budgetId, budgetYear, expenseDate, description, preApprovedAmount,
amount, repaid);
}
public int CreateExpenseClaim(int claimingPersonId, int organizationId, int budgetId, int budgetYear,
DateTime expenseDate, string description, double amount)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("CreateExpenseClaim", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "claimingPersonId", claimingPersonId);
AddParameterWithName(command, "createdDateTime", DateTime.Now);
AddParameterWithName(command, "organizationId", organizationId);
AddParameterWithName(command, "budgetId", budgetId);
AddParameterWithName(command, "budgetYear", budgetYear);
AddParameterWithName(command, "expenseDate", expenseDate);
AddParameterWithName(command, "description", description);
AddParameterWithName(command, "amount", amount);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimDescription(int expenseClaimId, string description)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimDescription", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "description", description);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimBudget(int expenseClaimId, int budgetId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimBudget", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "budgetId", budgetId);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimBudgetYear(int expenseClaimId, int budgetYear)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimBudgetYear", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "budgetYear", budgetYear);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimDate(int expenseClaimId, DateTime expenseDate)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimDate", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "expenseDate", expenseDate);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimAmount(int expenseClaimId, double amount)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimAmount", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "amount", amount);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimAttested(int expenseClaimId, bool attested)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimAttested", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "attested", attested);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimValidated(int expenseClaimId, bool validated)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimValidated", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "validated", validated);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimOpen(int expenseClaimId, bool open)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimOpen", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "open", open);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int SetExpenseClaimRepaid(int expenseClaimId, bool repaid)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimRepaid", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "repaid", repaid);
return Convert.ToInt32(command.ExecuteScalar());
}
}
public int CreateExpenseEvent(int expenseId, ExpenseEventType eventType, int personId)
{
// WARNING: NOT CONVERTED TO V4 YET
using (DbConnection connection = GetSqlServerDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("CreateExpenseEvent", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseId", expenseId);
AddParameterWithName(command, "dateTime", DateTime.Now);
AddParameterWithName(command, "eventPersonId", personId);
AddParameterWithName(command, "eventType", eventType.ToString());
return Convert.ToInt32(command.ExecuteScalar());
}
}
*/
#endregion
}
}
+2
View File
@@ -62,6 +62,7 @@
<Compile Include="Database-BackendServiceOrders.cs" />
<Compile Include="Database-ExchangeRates.cs" />
<Compile Include="Database-ExpenseGroups.cs" />
<Compile Include="Database-FinancialAccountDocuments.cs" />
<Compile Include="Database-GeographyUpdates.cs" />
<Compile Include="Database-CashAdvances.cs" />
<Compile Include="Database-Currencies.cs" />
@@ -141,6 +142,7 @@
<Compile Include="Database-Constructors.cs" />
<Compile Include="Database-Newsletters.cs" />
<Compile Include="RecordLimit.cs" />
<Compile Include="TableBase.cs" />
<None Include="app.config">
<SubType>Designer</SubType>
</None>
+56
View File
@@ -0,0 +1,56 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Common.Interfaces;
/* 2018-Dec-22: This is a started refactoring of the Database namespace into separate derived classes
* from a generic that contains most of the gruntwork. It is not nearly complete and
* the code is still experimental, not taken into production yet.
*/
namespace Swarmops.Database
{
public class TableBase<TBasic> where TBasic: IDatabaseColumnAware<TBasic>, new()
{
public TBasic GetRecordByIdentity(int identity, bool aggressive = false)
{
throw new NotImplementedException();
/*
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand("SELECT" + paymentFieldSequence +
"WHERE PaymentId=" + paymentId,
connection);
using (DbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return new TBasic().FromDataReader(reader);
}
throw new ArgumentException("No such PaymentId:" + paymentId);
}
}*/
}
public TBasic[] GetRecordsByIdentity(int[] identities)
{
throw new NotImplementedException();
}
public TBasic[] GetRecords(params object[] conditions)
{
throw new NotImplementedException();
}
}
}
+8 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common;
@@ -171,7 +172,13 @@ namespace Swarmops.Logic.Financial
public FinancialAccountDocument GetMostRecentDocument(FinancialAccountDocumentType documentType)
{
// TODO: Continue here
FinancialAccountDocuments documents = FinancialAccountDocuments.ForAccount(this, documentType);
if (documents.Count() > 0)
{
return documents.Last();
}
return null;
}
@@ -4,6 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common.Enums;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Financial
{
@@ -14,5 +17,38 @@ namespace Swarmops.Logic.Financial
public FinancialAccountDocument()
{
}
private FinancialAccountDocument(BasicFinancialAccountDocument basic) : base(basic)
{
// private ctor
}
public static FinancialAccountDocument FromBasic(BasicFinancialAccountDocument basic)
{
return new FinancialAccountDocument(basic);
}
public static FinancialAccountDocument FromIdentity(int financialAccountDocumentId)
{
return FromBasic(SwarmDb.GetDatabaseForReading().GetFinancialAccountDocument(financialAccountDocumentId));
}
internal static FinancialAccountDocument FromIdentityAggressive(int financialAccountDocumentId)
{
return FromBasic(SwarmDb.GetDatabaseForWriting().GetFinancialAccountDocument(financialAccountDocumentId));
}
public static FinancialAccountDocument Create(FinancialAccount account, FinancialAccountDocumentType documentType, Person uploader, DateTime concernsStart, DateTime concernsEnd, string rawText)
{
return FromIdentityAggressive(
SwarmDb.GetDatabaseForWriting().CreateFinancialAccountDocument(
account.Identity,
documentType,
uploader == null? 0: uploader.Identity,
concernsStart,
concernsEnd,
rawText
));
}
}
}
@@ -4,11 +4,49 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common.Enums;
using Swarmops.Database;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Financial
{
public class FinancialAccountDocuments: PluralBase<FinancialAccountDocuments,FinancialAccountDocument,BasicFinancialAccountDocument>
{
public static FinancialAccountDocuments ForAccount(FinancialAccount account, FinancialAccountDocumentType typeRequested = FinancialAccountDocumentType.Unknown)
{
FinancialAccountDocuments result = FromArray(SwarmDb.GetDatabaseForReading().GetFinancialAccountDocuments(account));
result.Sort(new FinancialAccountDocumentsSorterByTypeThenDate());
if (typeRequested != FinancialAccountDocumentType.Unknown)
{
FinancialAccountDocuments subset = new FinancialAccountDocuments();
foreach (FinancialAccountDocument document in result)
{
if (document.Type == typeRequested)
{
subset.Add(document);
}
}
return subset;
}
return result;
}
}
internal class FinancialAccountDocumentsSorterByTypeThenDate : IComparer<FinancialAccountDocument>
{
public int Compare(FinancialAccountDocument a, FinancialAccountDocument b)
{
if (a.Type != b.Type)
{
return a.Type.CompareTo(b.Type);
}
return (a.ConcernsPeriodStart.CompareTo(b.ConcernsPeriodStart));
}
}
}
+4
View File
@@ -249,6 +249,10 @@ namespace Swarmops.Logic.Support
{
return DocumentType.Salary;
}
else if (foreignObject is FinancialAccountDocument)
{
return DocumentType.FinancialAccountDocument;
}
else
{
throw new ArgumentException ("Unrecognized foreign object type:" + foreignObject.GetType().ToString());
+3 -3
View File
@@ -39,7 +39,7 @@ wget -qO- https://packages.swarmops.com/swarmops-packages.gpg.key | apt-key add
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
```
Then, add the Swarmops repository to your list of software sources, where [your_distro] is `debian` or `ubuntu`, and [your_distro_version] below is `xenial` or `bionic` (Ubuntu) or `stretch` (Debian):
Then, add the Swarmops and Mono repositories to your list of software sources, where [your_distro] is `debian` or `ubuntu`, and [your_distro_version] below is `xenial` or `bionic` (Ubuntu) or `stretch` (Debian):
```
echo "deb https://packages.swarmops.com/ [your_distro_version] contrib" > /etc/apt/sources.list.d/swarmops.list
@@ -100,7 +100,7 @@ That also means that any code _you_ commit to Swarmops, whether by checking in c
Beta-6 features progress
------------------------
Beta-6 will be released on January or February 5, 2019, with string freeze three days earlier. Its focus is to increase multicurrency functionality for payouts and bank imports.
Beta-6 will be released on February 5, 2019, with string freeze three days earlier. Its focus is to increase multicurrency functionality for payouts and bank imports.
- [x] Parameterize the bank file import procedure (big feature!)
- [x] Make it possible to import bank files in non-presentation currency
@@ -112,7 +112,7 @@ Beta-6 will be released on January or February 5, 2019, with string freeze three
Beta-7 features progress
------------------------
Beta-7 will be released on March 5, 2019, with string freeze on March 2. Its tentative focus will be Fairshift integration and possibly an open API exposure.
Beta-7 will be released on April 5, 2019, with string freeze on April 2. Its tentative focus will be Fairshift integration and possibly an open API exposure.
- [ ] Rewrite Bitcoin Cold Storage detection to handle forks, current and future
- [ ] Add blockchain-upgrade code that properly splits Core, Cash txs, hashes, accounts
+18
View File
@@ -411,6 +411,24 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Earnings before Interest, Taxes, Depreciation, and Amortization.
/// </summary>
internal static string Financial_Ebitda_Long {
get {
return ResourceManager.GetString("Financial_Ebitda_Long", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to EBITDA.
/// </summary>
internal static string Financial_Ebitda_Short {
get {
return ResourceManager.GetString("Financial_Ebitda_Short", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Expense.
/// </summary>
+7
View File
@@ -1004,4 +1004,11 @@
<value>Skip</value>
<comment>The "yes" option on the "Skip? Yes/no" dialog</comment>
</data>
<data name="Financial_Ebitda_Long" xml:space="preserve">
<value>Earnings before Interest, Taxes, Depreciation, and Amortization</value>
</data>
<data name="Financial_Ebitda_Short" xml:space="preserve">
<value>EBITDA</value>
<comment>Earnings before Interest, Taxes, Depreciation, and Amortization - a financial term</comment>
</data>
</root>
+92 -2
View File
@@ -159,6 +159,33 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Set up Connected Accounts.
/// </summary>
internal static string Menu5_Admin_SetupConnectedAccounts {
get {
return ResourceManager.GetString("Menu5_Admin_SetupConnectedAccounts", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Set up Ledger Account Structure.
/// </summary>
internal static string Menu5_Admin_SetupLedgerAccountStructure {
get {
return ResourceManager.GetString("Menu5_Admin_SetupLedgerAccountStructure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Set up Payroll.
/// </summary>
internal static string Menu5_Admin_SetupPayroll {
get {
return ResourceManager.GetString("Menu5_Admin_SetupPayroll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Built on {0:MMM d, yyyy}.
/// </summary>
@@ -465,6 +492,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to My Salary.
/// </summary>
internal static string Menu5_Financial_Salary {
get {
return ResourceManager.GetString("Menu5_Financial_Salary", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Send New Invoice.
/// </summary>
@@ -672,6 +708,24 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Deprecating &amp; Amortized Assets.
/// </summary>
internal static string Menu5_Ledgers_DeprecatingAmortizedAssets {
get {
return ResourceManager.GetString("Menu5_Ledgers_DeprecatingAmortizedAssets", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Depreciations and Amortizations.
/// </summary>
internal static string Menu5_Ledgers_DepreciationsAmortizations {
get {
return ResourceManager.GetString("Menu5_Ledgers_DepreciationsAmortizations", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Import Bank Data.
/// </summary>
@@ -708,6 +762,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Make Payroll Adjustments.
/// </summary>
internal static string Menu5_Ledgers_PayrollAdjustments {
get {
return ResourceManager.GetString("Menu5_Ledgers_PayrollAdjustments", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Profit &amp; Loss Statement.
/// </summary>
@@ -718,7 +781,7 @@ namespace Resources {
}
/// <summary>
/// Looks up a localized string similar to Resync Bank Account.
/// Looks up a localized string similar to Resync Connected Account.
/// </summary>
internal static string Menu5_Ledgers_ResyncExternalAccount {
get {
@@ -727,7 +790,7 @@ namespace Resources {
}
/// <summary>
/// Looks up a localized string similar to Set Budget Amounts.
/// Looks up a localized string similar to Set up Budgets.
/// </summary>
internal static string Menu5_Ledgers_SetBudgets {
get {
@@ -753,6 +816,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Tracked Transactions.
/// </summary>
internal static string Menu5_Ledgers_TrackedTransactions {
get {
return ResourceManager.GetString("Menu5_Ledgers_TrackedTransactions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Upload Bank Files.
/// </summary>
@@ -942,6 +1014,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Distributed Assets.
/// </summary>
internal static string Menu5_People_DistributedAssets {
get {
return ResourceManager.GetString("Menu5_People_DistributedAssets", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to List/Find People.
/// </summary>
@@ -1032,6 +1113,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Reports.
/// </summary>
internal static string Menu5_Reports {
get {
return ResourceManager.GetString("Menu5_Reports", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This is a temporary menu. Yes it&apos;s ugly now..
/// </summary>
+40 -2
View File
@@ -304,10 +304,11 @@
<value>Profit &amp; Loss Statement</value>
</data>
<data name="Menu5_Ledgers_ResyncExternalAccount" xml:space="preserve">
<value>Resync Bank Account</value>
<value>Resync Connected Account</value>
</data>
<data name="Menu5_Ledgers_SetBudgets" xml:space="preserve">
<value>Set Budget Amounts</value>
<value>Set up Budgets</value>
<comment>"Budget" as in "Cost allowed for a particular purpose" or "Revenue expected from a source".</comment>
</data>
<data name="Menu5_Ledgers_UploadBankFiles" xml:space="preserve">
<value>Upload Bank Files</value>
@@ -446,4 +447,41 @@
<data name="Menu5_Administration_Debug_BitcoinEchoTest" xml:space="preserve">
<value>Bitcoin Hotwallet Echo Test</value>
</data>
<data name="Menu5_Admin_SetupConnectedAccounts" xml:space="preserve">
<value>Set up Connected Accounts</value>
<comment>The connected accounts are those where transactions are read from an external source, like a bank account, a blockchain address, etc.</comment>
</data>
<data name="Menu5_Admin_SetupLedgerAccountStructure" xml:space="preserve">
<value>Set up Ledger Account Structure</value>
<comment>This is sometimes called an "account plan" but this term has many overloaded meanings in the context of operations software.</comment>
</data>
<data name="Menu5_Admin_SetupPayroll" xml:space="preserve">
<value>Set up Payroll</value>
</data>
<data name="Menu5_Financial_Salary" xml:space="preserve">
<value>My Salary</value>
<comment>This lists salary payments for the logged on individual</comment>
</data>
<data name="Menu5_Ledgers_DeprecatingAmortizedAssets" xml:space="preserve">
<value>Deprecating &amp; Amortized Assets</value>
</data>
<data name="Menu5_Ledgers_DepreciationsAmortizations" xml:space="preserve">
<value>Depreciations and Amortizations</value>
</data>
<data name="Menu5_Ledgers_PayrollAdjustments" xml:space="preserve">
<value>Make Payroll Adjustments</value>
<comment>As in bonuses, sick leave, lunch extras, whatever. Before or after tax.</comment>
</data>
<data name="Menu5_Ledgers_TrackedTransactions" xml:space="preserve">
<value>Tracked Transactions</value>
<comment>Tracking of special transactions</comment>
</data>
<data name="Menu5_People_DistributedAssets" xml:space="preserve">
<value>Distributed Assets</value>
<comment>Distributed as in "out among activists"; this tracks who has what equipment</comment>
</data>
<data name="Menu5_Reports" xml:space="preserve">
<value>Reports</value>
<comment>This is financial analysis reports. "Analysis" would also work as translation.</comment>
</data>
</root>
+20 -2
View File
@@ -115,7 +115,7 @@ namespace Resources.Pages {
}
/// <summary>
/// Looks up a localized string similar to Are transactions here excluded from 2-D reports?.
/// Looks up a localized string similar to Is this an account after the EBITDA line?.
/// </summary>
internal static string AccountPlan_Edit_AdministrativeLong {
get {
@@ -1141,7 +1141,7 @@ namespace Resources.Pages {
}
/// <summary>
/// Looks up a localized string similar to Resolve all unmatched accounts.
/// Looks up a localized string similar to Resolve all unmatched ledger transactions.
/// </summary>
internal static string EndOfMonth_MatchAccounts {
get {
@@ -1149,6 +1149,15 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to Payroll: No payroll defined.
/// </summary>
internal static string EndOfMonth_PayrollInactive {
get {
return ResourceManager.GetString("EndOfMonth_PayrollInactive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;strong&gt;SKIP BANK STATEMENT?&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;Bank statements are typically needed for audit verification of the internal records. The only valid reason to skip a month&apos;s statement is that the account wasn&apos;t opened yet, in which case you skip the months before the account was opened and no statements therefore exist.&lt;br/&gt;&lt;br/&gt;You won&apos;t be asked again to upload this particular statement if you skip it now..
/// </summary>
@@ -1158,6 +1167,15 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to &lt;strong&gt;SKIP DOCUMENT UPLOAD?&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;This document is typically needed for operation records. The only valid reason to skip a document is that it doesn&apos;t exist because the operations weren&apos;t running yet, like when an operation started in June of a year won&apos;t have documents for January of that year.&lt;br/&gt;&lt;br/&gt;You won&apos;t be asked again to upload this document if you skip it now..
/// </summary>
internal static string EndOfMonth_SkipDocumentDialogGeneric {
get {
return ResourceManager.GetString("EndOfMonth_SkipDocumentDialogGeneric", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to End-of-Month Routine: {0:MMMM yyyy}.
/// </summary>
+10 -2
View File
@@ -402,7 +402,8 @@
<value>Active</value>
</data>
<data name="AccountPlan_Edit_AdministrativeLong" xml:space="preserve">
<value>Are transactions here excluded from 2-D reports?</value>
<value>Is this an account after the EBITDA line?</value>
<comment>Earnings before interest, tax, depreciation and amortization (EBITDA) is a measure of a company's operating performance.</comment>
</data>
<data name="AccountPlan_Edit_AdministrativeShort" xml:space="preserve">
<value>Admin</value>
@@ -1010,7 +1011,7 @@
<value>This is a checklist of things to do to close the previous month and begin the new one with respect to accounting.</value>
</data>
<data name="EndOfMonth_MatchAccounts" xml:space="preserve">
<value>Resolve all unmatched accounts</value>
<value>Resolve all unmatched ledger transactions</value>
<comment>This means to match bank transactions with incoming/outgoing expected payments (invoices, expense reports, etc) where it couldn't be done automatically</comment>
</data>
<data name="EndOfMonth_Title" xml:space="preserve">
@@ -1028,4 +1029,11 @@
<data name="EndOfMonth_SkipBankStatementDialog" xml:space="preserve">
<value>&lt;strong&gt;SKIP BANK STATEMENT?&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;Bank statements are typically needed for audit verification of the internal records. The only valid reason to skip a month's statement is that the account wasn't opened yet, in which case you skip the months before the account was opened and no statements therefore exist.&lt;br/&gt;&lt;br/&gt;You won't be asked again to upload this particular statement if you skip it now.</value>
</data>
<data name="EndOfMonth_SkipDocumentDialogGeneric" xml:space="preserve">
<value>&lt;strong&gt;SKIP DOCUMENT UPLOAD?&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;This document is typically needed for operation records. The only valid reason to skip a document is that it doesn't exist because the operations weren't running yet, like when an operation started in June of a year won't have documents for January of that year.&lt;br/&gt;&lt;br/&gt;You won't be asked again to upload this document if you skip it now.</value>
</data>
<data name="EndOfMonth_PayrollInactive" xml:space="preserve">
<value>Payroll: No payroll defined</value>
<comment>This is shown as a disabled action item when there's no active payroll</comment>
</data>
</root>
+18
View File
@@ -75,8 +75,22 @@
<%= this.ClientUploadStartedCallback %>("<%= GuidString%>", "<%= Cookie%>");
<% } %>
},
send: function(e, data) {
// call when upload actually begins -- for notify
},
fail: function(e, data) {
// called on upload fail or upload abort -- for notify
<% if (!String.IsNullOrEmpty(this.ClientUploadFailedCallback))
{ %>
<%= this.ClientUploadFailedCallback %>("<%= GuidString%>", "<%= Cookie%>");
<% } %>
}
});
@@ -102,6 +116,10 @@
}
function <%=this.ClientID%>_triggerUpload() {
$('#<%=this.ClientID %>_ButtonUploadHidden').click();
}
function <%=this.ClientID%>_clear() {
// Note that this only clears the UI -- the uploaded docs must be disassociated elsewhere
$('#<%=this.ClientID%>_DivUploadCount').empty();
+1
View File
@@ -36,6 +36,7 @@ namespace Swarmops.Controls.Base
public bool HideTrigger { get; set; }
public string ClientUploadCompleteCallback { get; set; }
public string ClientUploadStartedCallback { get; set; }
public string ClientUploadFailedCallback { get; set; }
public string Cookie { get; set; }
public string GuidToken
@@ -20,7 +20,7 @@
alertify.set({
labels: {
ok: SwarmopsJS.unescape('<%=this.Localized_ConfirmDialog_Proceed%>'),
ok: SwarmopsJS.unescape('<%=this.Localized_Impersonate%>'),
cancel: SwarmopsJS.unescape('<%=this.Localized_ConfirmDialog_Cancel%>')
},
buttonFocus: 'cancel'
@@ -85,6 +85,13 @@ namespace Swarmops.Frontend.Pages.v5.Admin
get { return JavascriptEscape(Resources.Pages.Admin.CommenceImpersonation_Confirm); }
}
public string Localized_Impersonate
{
get { return JavascriptEscape(Resources.Pages.Admin.CommenceImpersonation_Impersonate); }
}
/*
public string Localized_ValidationError_BankAccount
{
+190 -25
View File
@@ -14,6 +14,7 @@
// set action icons to their respective initial icons
$('img.eomitem-wrench').attr('src', '/Images/Icons/iconshock-balloon-wrench-128x96px.png');
$('img.eomitem-document').attr('src', '/Images/Icons/iconshock-balloon-invoice-128x96px.png');
$('img.eomitem-upload').attr('src', '/Images/Icons/iconshock-upload-128x96px.png');
@@ -131,45 +132,204 @@
var itemId = $(this).attr('data-item');
var callbackFunction = $(this).attr('data-callback');
$('img.action-icon[data-item="' + itemId + '"]').hide();
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').show();
if ($(this).hasClass('is-upload')) {
SwarmopsJS.ajaxCall(
"/Pages/v5/Ledgers/EndOfMonth.aspx/" + callbackFunction,
{},
$.proxy(function() {
var groupId = $(this).attr('data-group');
var itemId = $(this).attr('data-item');
// Trigger upload, then trigger ajax call on complete
$('span.action-list-item[data-item="' + itemId + '"]').addClass('action-list-item-completed');
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').hide();
$('img.status-icon-completed[data-item="' + itemId + '"]').fadeIn();
if (activeUpload != null) {
// upload is already in progress; don't allow two concurrent uploads since we're using one control
// todo: error message or some UX to explain this?
var selector = ".action-list-item:not(.action-list-item-completed):not(.action-list-item-disabled)[data-group='" + groupId + "']";
if ($(selector).length == 0) // no further actions in this group enabled
{
// mark the group as completed
$(".group-status-icon[data-group='" + groupId + "']").fadeIn();
}
}, this)
);
return;
}
triggeredUpload = $(this).attr('data-item');
<%=this.UploadControl.ClientID%>_triggerUpload();
} else {
// Ajax call right away
$('img.action-icon[data-item="' + itemId + '"]').hide();
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').show();
SwarmopsJS.ajaxCall(
"/Pages/v5/Ledgers/EndOfMonth.aspx/" + callbackFunction,
{ itemId: itemId },
// Success function
$.proxy(function (result) {
var itemId = $(this).attr('data-item');
if (result.Success) {
markItemCompleted(itemId);
} else {
// Restore action icons.
// Todo: display DisplayMessage in dialog or error notice.
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').hide();
$('img.action-icon[data-item="' + itemId + '"]').show();
}
}, this),
// Failure (exception) function
$.proxy(function () {
var itemId = $(this).attr('data-item');
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').hide();
$('img.action-icon[data-item="' + itemId + '"]').show();
}, this)
);
}
});
$('.action-skip > a').click(function () {
var itemId = $(this).parent().parent().attr("data-item");
var dependentItemId = $('span.action-list-item[data-dependson="' + itemId + '"]').attr("data-item");
$('img.action-icon[data-item="' + itemId + '"]').hide();
$('img.status-icon-completed[data-item="' + itemId + '"]').attr("src", "/Images/Icons/iconshock-red-cross-128x96px.png").fadeIn();
var prompt = localized_skipPromptGeneric;
if (itemId.startsWith('BankStatement')) {
prompt = localized_skipPromptBankStatement;
}
$('span.action-list-item[data-item="' + itemId + '"]').addClass('action-list-item-completed');
$('span.action-list-item[data-item="' + dependentItemId + '"]').removeClass('action-list-item-disabled');
$('img.action-icon[data-item="' + dependentItemId + '"]').removeClass('action-icon-disabled');
alertify.set({
labels: {
ok: localized_skipYesResponse,
cancel: localized_skipNoResponse
},
buttonFocus: 'cancel'
});
alertify.confirm(prompt,
$.proxy(function(response) {
if (response) {
var itemId = $(this).parent().parent().attr("data-item");
var dependentItemId = $('span.action-list-item[data-dependson="' + itemId + '"]').attr("data-item");
$('img.action-icon[data-item="' + itemId + '"]').hide();
$('img.status-icon-completed[data-item="' + itemId + '"]').attr("src", "/Images/Icons/iconshock-red-cross-128x96px.png").fadeIn();
$('span.action-list-item[data-item="' + itemId + '"]').addClass('action-list-item-completed');
$('span.action-list-item[data-item="' + dependentItemId + '"]').removeClass('action-list-item-disabled');
$('img.action-icon[data-item="' + dependentItemId + '"]').removeClass('action-icon-disabled');
}
}, this));
});
});
function markItemCompleted(itemId) {
var groupId = $('span.action-list-item[data-item="' + itemId + '"]').attr('data-group');
console.log("GroupId is " + groupId);
$('span.action-list-item[data-item="' + itemId + '"]').addClass('action-list-item-completed');
$('img.status-icon-pleasewait[data-item="' + itemId + '"]').hide();
$('img.status-icon-completed[data-item="' + itemId + '"]').fadeIn();
// If any items depended on this one, enable them now
var dependentItemId = $('span.action-list-item[data-dependson="' + itemId + '"]').attr("data-item");
$('span.action-list-item[data-item="' + dependentItemId + '"]').removeClass('action-list-item-disabled');
$('img.action-icon[data-item="' + dependentItemId + '"]').removeClass('action-icon-disabled');
// Check if group is complete
var selector = ".action-list-item:not(.action-list-item-completed):not(.action-list-item-disabled)[data-group='" + groupId + "']";
if ($(selector).length == 0) // no further actions in this group enabled
{
// mark the group as completed
$(".group-status-icon[data-group='" + groupId + "']").fadeIn();
}
}
function clientStartedUpload() {
if (triggeredUpload == null) {
// invalid state
return;
}
activeUpload = triggeredUpload;
triggeredUpload = null;
// switch action icon upload to status icon waiting
$('img.action-icon[data-item="' + activeUpload + '"]').hide();
$('img.status-icon-pleasewait[data-item="' + activeUpload + '"]').show();
// If there's a skip option, disable it at this time
$('span.action-list-item[data-item="' + activeUpload + '"] span.action-skip').addClass('action-skip-disabled');
}
function clientFailedUpload() {
console.log("Client aborted or failed upload");
if (activeUpload == null) {
// invalid state
return;
}
$('img.status-icon-pleasewait[data-item="' + activeUpload + '"]').hide();
$('img.action-icon[data-item="' + activeUpload + '"]').show();
activeUpload = null;
}
function clientFinishedUpload() {
if (activeUpload == null) {
// invalid state
return;
}
var itemType = activeUpload.substring(0, activeUpload.indexOf('-'));
// Note that the function to call is selected dynamically!
SwarmopsJS.ajaxCall(
"/Pages/v5/Ledgers/EndOfMonth.aspx/Upload" + itemType,
{ guid: uploadGuid, itemId: activeUpload },
function(result) {
if (result.Success) {
markItemCompleted(activeUpload);
// If there are items that depend on this one,
// disable their "skip" option now (because there's
// a first document in the series)
var itemIterator = $('.action-list-item[data-dependson="' + activeUpload + '"]');
while (itemIterator.length > 0) {
// We're only supporting a 1:1 chain at this time, no 1:n dependencies
var itemId = $(itemIterator).attr('data-item');
$('span.action-list-item[data-item="' + itemId + '"] span.action-skip').addClass('action-skip-disabled');
itemIterator = $('.action-list-item[data-dependson="' + itemId + '"]');
}
activeUpload = null;
} else {
// Todo: add more error handling later, maybe
clientFailedUpload();
}
},
function(error) {
clientFailedUpload();
});
}
var uploadGuid = '<%=this.UploadControl.GuidString%>';
var triggeredUpload = null;
var activeUpload = null;
var localized_skipNoResponse = SwarmopsJS.unescape('<%=this.Localized_SkipNo%>');
var localized_skipYesResponse = SwarmopsJS.unescape('<%=this.Localized_SkipYes%>');
var localized_skipPromptBankStatement = SwarmopsJS.unescape('<%=this.Localized_SkipPrompt_BankStatement%>');
var localized_skipPromptGeneric = SwarmopsJS.unescape('<%=this.Localized_SkipPrompt_Generic%>');
var uploadGuid = '<%=this.UploadControl.GuidString%>';
// Function: Match all mismatched transactions
// Function: Upload bank statement PDF for accountId x
@@ -219,6 +379,10 @@
transition: all 0.50s;*/
}
.action-list-item .action-skip-disabled {
display: none !important;
}
.action-list-item-disabled .action-skip, .action-list-item-completed .action-skip {
-webkit-transition: all 0.50s;
transition: all 0.50s;
@@ -255,6 +419,7 @@
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h2><asp:Label runat="server" ID="LabelHeader"></asp:Label></h2>
<div style="display: none"><Swarmops5:FileUpload ID="UploadControl" ClientUploadFailedCallback="clientFailedUpload" ClientUploadStartedCallback="clientStartedUpload" ClientUploadCompleteCallback="clientFinishedUpload" runat="server"/></div>
<table id="TableEomItems" class="easyui-datagrid" style="width:680px;height:500px"
data-options="rownumbers:false,singleSelect:false,nowrap:false,fit:false,loading:false,selectOnCheck:false,checkOnSelect:false"
+149 -19
View File
@@ -24,8 +24,8 @@ namespace Swarmops.Frontend.Pages.Ledgers
this.PageTitle =
this.Title =
this.LabelHeader.Text =
String.Format(Resources.Pages.Ledgers.EndOfMonth_Title, DateTime.UtcNow.AddMonths(-1));
this.LabelHeader.Text =
String.Format(Resources.Pages.Ledgers.EndOfMonth_Title, DateTime.UtcNow.AddMonths(-1));
this.InfoBoxLiteral = Resources.Pages.Ledgers.EndOfMonth_Info;
@@ -37,6 +37,9 @@ namespace Swarmops.Frontend.Pages.Ledgers
EomItemGroup group1 = new EomItemGroup();
group1.Header = Resources.Pages.Ledgers.EndOfMonth_Header_ExternalData;
group1.Id = "ExternalData";
string lastUploadItemId = string.Empty;
// Iterate over all Balance accounts and check for automation;
// if so, add it to an upload sequence
@@ -55,13 +58,15 @@ namespace Swarmops.Frontend.Pages.Ledgers
// This account has automation
// If automation has Bank Account Statement enabled (assume true for now):
FinancialAccountDocument lastBankStatement = assetAccount.GetMostRecentDocument(FinancialAccountDocumentType.BankStatement);
int lastStatementMonth = (this.CurrentOrganization.FirstFiscalYear-1) *100 + 12; // December of the year before
FinancialAccountDocument lastBankStatement =
assetAccount.GetMostRecentDocument(FinancialAccountDocumentType.BankStatement);
int lastStatementMonth = (this.CurrentOrganization.FirstFiscalYear - 1)*100 + 12;
// December of the year before
if (lastBankStatement != null)
{
lastStatementMonth = lastBankStatement.ConcernsPeriodStart.Year*100 +
lastBankStatement.ConcernsPeriodStart.Month;
lastBankStatement.ConcernsPeriodStart.Month;
skippable = false;
}
@@ -79,9 +84,11 @@ namespace Swarmops.Frontend.Pages.Ledgers
EomItem bankStatement = new EomItem();
bankStatement.DependsOn = lastId; // empty for first record
bankStatement.Id = lastId = "BankStatement-" +
assetAccount.Identity.ToString(CultureInfo.InvariantCulture) + monthIterator;
assetAccount.Identity.ToString(CultureInfo.InvariantCulture) + '-' +
monthIterator;
bankStatement.Name = string.Format(Resources.Pages.Ledgers.EndOfMonth_UploadBankStatementFor,
assetAccount.Name, "PDF", new DateTime(monthIterator / 100, monthIterator % 100, 15).ToString("MMMM yyyy"));
assetAccount.Name, "PDF",
new DateTime(monthIterator/100, monthIterator%100, 15).ToString("MMMM yyyy"));
bankStatement.Completed = false; // TODO
bankStatement.Icon = "upload";
bankStatement.Skippable = skippable;
@@ -89,9 +96,38 @@ namespace Swarmops.Frontend.Pages.Ledgers
group1.Items.Add(bankStatement);
}
// Add data upload item
// TODO: Check if the last data upload was into the current month
EomItem dataUploadItem = new EomItem();
dataUploadItem.Id = "BankDataUpload-" + assetAccount.Identity.ToString(CultureInfo.InvariantCulture);
dataUploadItem.Icon = "upload";
dataUploadItem.Completed = false; // todo
dataUploadItem.Name = String.Format(Resources.Pages.Ledgers.EndOfMonth_UploadTransactionDataFor,
assetAccount.Name, "CSV");
dataUploadItem.Skippable = false;
group1.Items.Add(dataUploadItem);
}
}
// If there are any items in Group 1, OR if an account matching is necessary, then
// add that as an action item
if (group1.Items.Count() > 0 || FinancialTransactions.GetUnbalanced(this.CurrentOrganization).Count() > 0)
{
EomItem matchAccounts = new EomItem();
matchAccounts.DependsOn = lastUploadItemId; // may be empty if there's nothing to upload and that's ok
matchAccounts.Id = "MatchAccounts";
matchAccounts.Completed = false; // we already know there's at least one unbalanced
matchAccounts.Icon = "wrench";
matchAccounts.Skippable = false;
matchAccounts.Name = Resources.Pages.Ledgers.EndOfMonth_MatchAccounts;
group1.Items.Add(matchAccounts);
}
if (group1.Items.Count > 0)
{
ItemGroups.Add(group1);
@@ -118,6 +154,23 @@ namespace Swarmops.Frontend.Pages.Ledgers
group2.Items.Add(vatReport);
}
Payroll payroll = Payroll.ForOrganization(this.CurrentOrganization);
if (payroll.Any())
{
// There is active payroll
// TODO: Taxes for last month and processing for this month
}
else
{
EomItem payrollInactive = new EomItem();
payrollInactive.Id = "PayrollInactive";
payrollInactive.Completed = true;
payrollInactive.Name = Resources.Pages.Ledgers.EndOfMonth_PayrollInactive;
payrollInactive.Icon = "document";
group2.Items.Add(payrollInactive);
}
if (group2.Items.Count > 0)
{
@@ -157,8 +210,12 @@ namespace Swarmops.Frontend.Pages.Ledgers
builder.Append(@"
$('#TableEomItems').datagrid('appendRow', {
itemGroupName: '<span class=""itemGroupHeader""" + previousGroupIdData + @">" + group.Header.Replace(" ", "&nbsp;").Replace("'", "''") + @"</span>',
action: ""<img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" + group.Id + "'" + previousGroupIdData + @" class='group-status-icon status-completed' style='display:" + (groupReady? "inline" : "none") + @"' />"",
itemGroupName: ""<span class='itemGroupHeader'" + previousGroupIdData + @">" +
group.Header.Replace(" ", "&nbsp;") + @"</span>"",
action: ""<img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" +
group.Id + "'" + previousGroupIdData +
@" class='group-status-icon status-completed' style='display:" +
(groupReady ? "inline" : "none") + @"' />"",
itemId: '" + group.Id + @"'
});
@@ -172,7 +229,7 @@ namespace Swarmops.Frontend.Pages.Ledgers
});
");
foreach (EomItem item in group.Items)
{
if (!item.Completed)
@@ -180,8 +237,9 @@ namespace Swarmops.Frontend.Pages.Ledgers
string itemName = Server.HtmlEncode(item.Name);
string itemDisabledClass = string.Empty;
string iconDisabledClass = string.Empty;
string iconIsUploadClass = string.Empty;
if (item.DependsOn.Length > 0)
if (!string.IsNullOrEmpty(item.DependsOn))
{
// add as disabled
itemDisabledClass = " action-list-item-disabled";
@@ -194,10 +252,26 @@ namespace Swarmops.Frontend.Pages.Ledgers
Server.HtmlEncode(Resources.Global.Global_SkipThis) + "</a>)</span>";
}
if (item.Icon == "upload")
{
iconIsUploadClass = " is-upload";
}
builder.Append(@"
$('#TableEomItems').datagrid('appendRow', {
itemName: ""<span class='action-list-item" + itemDisabledClass + @"' data-item='" + item.Id + @"' data-dependson='" + item.DependsOn + @"' data-group='" + group.Id + @"'>" + itemName + @"</span>"",
action: ""<img src='/Images/Icons/transparency-16px.png' data-item='" + item.Id + @"' data-group='" + group.Id + @"' class='action action-icon eomitem-" + item.Icon + iconDisabledClass + @"' data-callback='" + item.Callback + @"' data-dependson='" + item.DependsOn + @"' /><img src='/Images/Abstract/ajaxloader-48x36px.gif' data-group='" + group.Id + @"' class='status-icon status-icon-pleasewait' data-item='" + item.Id + @"' style='display:none' /><img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" + group.Id + @"' class='status-icon status-icon-completed' data-item='" + item.Id + @"' style='display:none' />""
itemName: ""<span class='action-list-item" + itemDisabledClass + @"' data-item='" +
item.Id + @"' data-dependson='" + item.DependsOn + @"' data-group='" +
group.Id + @"'>" + itemName + @"</span>"",
action: ""<img src='/Images/Icons/transparency-16px.png' data-item='" + item.Id +
@"' data-group='" + group.Id + @"' class='action action-icon eomitem-" +
item.Icon + iconIsUploadClass + iconDisabledClass + @"' data-callback='" +
item.Callback + @"' data-dependson='" + item.DependsOn +
@"' /><img src='/Images/Abstract/ajaxloader-48x36px.gif' data-group='" +
group.Id + @"' class='status-icon status-icon-pleasewait' data-item='" +
item.Id +
@"' style='display:none' /><img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" +
group.Id + @"' class='status-icon status-icon-completed' data-item='" +
item.Id + @"' style='display:none' />""
});
");
}
@@ -205,27 +279,29 @@ namespace Swarmops.Frontend.Pages.Ledgers
{
builder.Append(@"
$('#TableEomItems').datagrid('appendRow', {
itemName: ""<span class='action-list-item action-list-item-completed' data-item='" + item.Id + @"' data-group='" + group.Id + @"'>" + item.Name + @"</span>"",
action: ""<img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" + group.Id + @"' class='status-icon status-icon-completed' data-item='" + item.Id + @"' style='display:inline' />""
itemName: ""<span class='action-list-item action-list-item-completed' data-item='" +
item.Id + @"' data-group='" + group.Id + @"'>" + item.Name + @"</span>"",
action: ""<img src='/Images/Icons/iconshock-green-tick-128x96px.png' data-group='" +
group.Id + @"' class='status-icon status-icon-completed' data-item='" +
item.Id + @"' style='display:inline' />""
});
");
}
}
previousGroupId = group.Id; // only set if group has items
previousGroupId = group.Id; // only set if group has items
}
}
return builder.ToString();
}
}
[WebMethod]
public static AjaxCallResult CreateVatReport()
public static AjaxCallResult CreateVatReport(string itemId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
if (!authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.BookkeepingDetails)))
{
throw new UnauthorizedAccessException();
@@ -237,6 +313,39 @@ namespace Swarmops.Frontend.Pages.Ledgers
}
[WebMethod]
public static AjaxCallResult UploadBankStatement(string guid, string itemId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
if (!authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.BookkeepingDetails)))
{
throw new UnauthorizedAccessException();
}
string[] parts = itemId.Split('-');
FinancialAccount account = FinancialAccount.FromIdentity(Int32.Parse(parts[1]));
int yearMonth = Int32.Parse(parts[2]);
DateTime statementStart = new DateTime(yearMonth/100, yearMonth%100, 1);
if (account.OrganizationId != authData.CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException();
}
Documents documents = Documents.RecentFromDescription(guid);
FinancialAccountDocument accountDoc = FinancialAccountDocument.Create(account, FinancialAccountDocumentType.BankStatement, authData.CurrentUser,
statementStart, statementStart.AddMonths(1), string.Empty);
documents.SetForeignObjectForAll(accountDoc);
return new AjaxCallResult {Success = true};
}
private class EomItem
{
public string Id { get; set; }
@@ -261,5 +370,26 @@ namespace Swarmops.Frontend.Pages.Ledgers
}
private List<EomItemGroup> ItemGroups { get; set; }
public string Localized_SkipPrompt_BankStatement
{
get { return CommonV5.JavascriptEscape(Resources.Pages.Ledgers.EndOfMonth_SkipBankStatementDialog); }
}
public string Localized_SkipPrompt_Generic
{
get { return CommonV5.JavascriptEscape(Resources.Pages.Ledgers.EndOfMonth_SkipDocumentDialogGeneric); }
}
public string Localized_SkipYes
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_SkipYes); }
}
public string Localized_SkipNo
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_SkipNo); }
}
}
}
+9
View File
@@ -20,5 +20,14 @@ namespace Swarmops.Frontend.Pages.Ledgers {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelHeader;
/// <summary>
/// UploadControl control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Controls.Base.FileUpload UploadControl;
}
}
+6
View File
@@ -75,6 +75,9 @@
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime">
<HintPath>..\..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
@@ -5310,6 +5313,9 @@
<LastGenOutput>Pages.Swarm.yo-NG.designer.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Frames\v5\" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+10 -6
View File
@@ -3,7 +3,7 @@ NOV2018
OVERALL:
[ ] Fix basic flows
[ ] Focus on new SKU Backoffice.Cash
[ ] Focus on new SKU op.Cash
[ ] Make work on Bionic and Stretch
@@ -14,7 +14,7 @@ PRIO 1
[ ] End-of-month routine
[ ] - incl EOY
[ ] - with todo field
[ ] Fix generic block explorer interfaces'
[ ] Fix generic block explorer interfaces
[ ] Fix & redo bank file upload completely
[ ] - with interface to Github repo of XML definitions
[ ] Fix Bionic build
@@ -25,25 +25,29 @@ PRIO 1
PRIO 2
------
[ ] Recurring expenses
[ ] Todo box JSON
[ ] Expense reject malfunction
[ ] Backoffice.Cash SKU
[ ] Expense reject malfunction (what's this? -RF)
[ ] op.Cash SKU
[ ] Submit invoice
[ ] Control messages for invoice progress
[ ] Pay invoice
[ ] Payment points for invoices, expense reports
[ ] Upload bank statements
[ ] External people notifications
[ ] Currency inventory tracking
[ ] Cost centers and 2-D reports
[ ] Monthly reports (not just quarterly)
PRIO 3
------
[ ] Recurring expenses
[ ] HTML/Markdown mail
[ ] Org texts self-signup
[ ] Load hotwallet from cold
[ ] Database discrepancy
[ ] Icons for Validation
[ ] Backoffice.Cash OOBE
[ ] op.Cash OOBE
[ ] Assign role geolock