diff --git a/Basic/Basic.csproj b/Basic/Basic.csproj
index 27cb55bc..1b61a3b0 100644
--- a/Basic/Basic.csproj
+++ b/Basic/Basic.csproj
@@ -57,6 +57,7 @@
+
diff --git a/Basic/DbColumnAwareBase.cs b/Basic/DbColumnAwareBase.cs
new file mode 100644
index 00000000..3d58ba96
--- /dev/null
+++ b/Basic/DbColumnAwareBase.cs
@@ -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>();
+ _classColumnSequenceLookup = new Dictionary();
+ }
+ }
+
+ public DbColumnAwareBase()
+ {
+ // ReSharper disable once DoNotCallOverridableMethodsInConstructor
+ VerifyLookupInitialized();
+ }
+
+ private static Dictionary> _classColumnOrdinalLookup;
+ private static Dictionary _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) ";
+
+ */
+ }
+}
diff --git a/Basic/Types/Financial/BasicFinancialAccountDocument.cs b/Basic/Types/Financial/BasicFinancialAccountDocument.cs
index 43191ccc..d0b329b8 100644
--- a/Basic/Types/Financial/BasicFinancialAccountDocument.cs
+++ b/Basic/Types/Financial/BasicFinancialAccountDocument.cs
@@ -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; } }
}
diff --git a/Common/Attributes/DbColumnName.cs b/Common/Attributes/DbColumnName.cs
new file mode 100644
index 00000000..5b04cb1e
--- /dev/null
+++ b/Common/Attributes/DbColumnName.cs
@@ -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; }
+ }
+}
diff --git a/Common/Attributes/DbColumnTypeName.cs b/Common/Attributes/DbColumnTypeName.cs
new file mode 100644
index 00000000..f4897130
--- /dev/null
+++ b/Common/Attributes/DbColumnTypeName.cs
@@ -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; }
+ }
+}
diff --git a/Common/Attributes/DbIdentity.cs b/Common/Attributes/DbIdentity.cs
new file mode 100644
index 00000000..9b64aac1
--- /dev/null
+++ b/Common/Attributes/DbIdentity.cs
@@ -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() { }
+ }
+}
diff --git a/Common/Common.csproj b/Common/Common.csproj
index 06194146..42a06436 100644
--- a/Common/Common.csproj
+++ b/Common/Common.csproj
@@ -40,7 +40,10 @@
+
+
+
@@ -82,6 +85,7 @@
+
diff --git a/Common/Enums/DocumentType.cs b/Common/Enums/DocumentType.cs
index e844d989..544d3b18 100644
--- a/Common/Enums/DocumentType.cs
+++ b/Common/Enums/DocumentType.cs
@@ -77,6 +77,11 @@ namespace Swarmops.Common.Enums
///
/// Nor this
///
- Salary
+ Salary,
+
+ ///
+ /// Documentation related to a financial account, usually an external one
+ ///
+ FinancialAccountDocument
}
}
\ No newline at end of file
diff --git a/Common/Enums/FinancialAccountDocumentType.cs b/Common/Enums/FinancialAccountDocumentType.cs
index ba80cb98..c76f95dc 100644
--- a/Common/Enums/FinancialAccountDocumentType.cs
+++ b/Common/Enums/FinancialAccountDocumentType.cs
@@ -10,6 +10,7 @@ namespace Swarmops.Common.Enums
{
Unknown = 0,
BankStatement,
- BankTransactionData
+ BankTransactionData,
+ BankPaymentData
}
}
diff --git a/Common/Interfaces/IDatabaseColumnAware.cs b/Common/Interfaces/IDatabaseColumnAware.cs
new file mode 100644
index 00000000..b17a7bba
--- /dev/null
+++ b/Common/Interfaces/IDatabaseColumnAware.cs
@@ -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
+ {
+ // 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);
+ }
+}
diff --git a/Database/Database-FinancialAccountDocuments.cs b/Database/Database-FinancialAccountDocuments.cs
new file mode 100644
index 00000000..9f85d435
--- /dev/null
+++ b/Database/Database-FinancialAccountDocuments.cs
@@ -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 result = new List();
+
+ 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 result = new List();
+
+ 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 result = new List();
+
+ 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 result = new List();
+
+ 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
+ }
+}
\ No newline at end of file
diff --git a/Database/Database.csproj b/Database/Database.csproj
index e1e0c0f1..7a981f39 100644
--- a/Database/Database.csproj
+++ b/Database/Database.csproj
@@ -62,6 +62,7 @@
+
@@ -141,6 +142,7 @@
+
Designer
diff --git a/Database/TableBase.cs b/Database/TableBase.cs
new file mode 100644
index 00000000..35744805
--- /dev/null
+++ b/Database/TableBase.cs
@@ -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 where TBasic: IDatabaseColumnAware, 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();
+ }
+ }
+}
diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs
index 04db0532..b4e445da 100644
--- a/Logic/Financial/FinancialAccount.cs
+++ b/Logic/Financial/FinancialAccount.cs
@@ -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;
}
diff --git a/Logic/Financial/FinancialAccountDocument.cs b/Logic/Financial/FinancialAccountDocument.cs
index 4e1e9bf4..5958a116 100644
--- a/Logic/Financial/FinancialAccountDocument.cs
+++ b/Logic/Financial/FinancialAccountDocument.cs
@@ -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
+ ));
+ }
}
}
diff --git a/Logic/Financial/FinancialAccountDocuments.cs b/Logic/Financial/FinancialAccountDocuments.cs
index a4d2bfeb..2665d78b 100644
--- a/Logic/Financial/FinancialAccountDocuments.cs
+++ b/Logic/Financial/FinancialAccountDocuments.cs
@@ -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
{
+ 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
+ {
+ public int Compare(FinancialAccountDocument a, FinancialAccountDocument b)
+ {
+ if (a.Type != b.Type)
+ {
+ return a.Type.CompareTo(b.Type);
+ }
+
+ return (a.ConcernsPeriodStart.CompareTo(b.ConcernsPeriodStart));
+ }
}
}
diff --git a/Logic/Support/Document.cs b/Logic/Support/Document.cs
index b209adf6..190cf730 100644
--- a/Logic/Support/Document.cs
+++ b/Logic/Support/Document.cs
@@ -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());
diff --git a/README.md b/README.md
index b2c610ae..99bd7db0 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/Site/App_GlobalResources/Global.designer.cs b/Site/App_GlobalResources/Global.designer.cs
index 52bf4e72..06290e0e 100644
--- a/Site/App_GlobalResources/Global.designer.cs
+++ b/Site/App_GlobalResources/Global.designer.cs
@@ -411,6 +411,24 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Earnings before Interest, Taxes, Depreciation, and Amortization.
+ ///
+ internal static string Financial_Ebitda_Long {
+ get {
+ return ResourceManager.GetString("Financial_Ebitda_Long", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to EBITDA.
+ ///
+ internal static string Financial_Ebitda_Short {
+ get {
+ return ResourceManager.GetString("Financial_Ebitda_Short", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Expense.
///
diff --git a/Site/App_GlobalResources/Global.resx b/Site/App_GlobalResources/Global.resx
index bb9c0fa0..0f9d826c 100644
--- a/Site/App_GlobalResources/Global.resx
+++ b/Site/App_GlobalResources/Global.resx
@@ -1004,4 +1004,11 @@
Skip
The "yes" option on the "Skip? Yes/no" dialog
+
+ Earnings before Interest, Taxes, Depreciation, and Amortization
+
+
+ EBITDA
+ Earnings before Interest, Taxes, Depreciation, and Amortization - a financial term
+
\ No newline at end of file
diff --git a/Site/App_GlobalResources/Menu5.designer.cs b/Site/App_GlobalResources/Menu5.designer.cs
index 38bfdb64..9c04998b 100644
--- a/Site/App_GlobalResources/Menu5.designer.cs
+++ b/Site/App_GlobalResources/Menu5.designer.cs
@@ -159,6 +159,33 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Set up Connected Accounts.
+ ///
+ internal static string Menu5_Admin_SetupConnectedAccounts {
+ get {
+ return ResourceManager.GetString("Menu5_Admin_SetupConnectedAccounts", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Set up Ledger Account Structure.
+ ///
+ internal static string Menu5_Admin_SetupLedgerAccountStructure {
+ get {
+ return ResourceManager.GetString("Menu5_Admin_SetupLedgerAccountStructure", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Set up Payroll.
+ ///
+ internal static string Menu5_Admin_SetupPayroll {
+ get {
+ return ResourceManager.GetString("Menu5_Admin_SetupPayroll", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Built on {0:MMM d, yyyy}.
///
@@ -465,6 +492,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to My Salary.
+ ///
+ internal static string Menu5_Financial_Salary {
+ get {
+ return ResourceManager.GetString("Menu5_Financial_Salary", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Send New Invoice.
///
@@ -672,6 +708,24 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Deprecating & Amortized Assets.
+ ///
+ internal static string Menu5_Ledgers_DeprecatingAmortizedAssets {
+ get {
+ return ResourceManager.GetString("Menu5_Ledgers_DeprecatingAmortizedAssets", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Depreciations and Amortizations.
+ ///
+ internal static string Menu5_Ledgers_DepreciationsAmortizations {
+ get {
+ return ResourceManager.GetString("Menu5_Ledgers_DepreciationsAmortizations", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Import Bank Data.
///
@@ -708,6 +762,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Make Payroll Adjustments.
+ ///
+ internal static string Menu5_Ledgers_PayrollAdjustments {
+ get {
+ return ResourceManager.GetString("Menu5_Ledgers_PayrollAdjustments", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Profit & Loss Statement.
///
@@ -718,7 +781,7 @@ namespace Resources {
}
///
- /// Looks up a localized string similar to Resync Bank Account.
+ /// Looks up a localized string similar to Resync Connected Account.
///
internal static string Menu5_Ledgers_ResyncExternalAccount {
get {
@@ -727,7 +790,7 @@ namespace Resources {
}
///
- /// Looks up a localized string similar to Set Budget Amounts.
+ /// Looks up a localized string similar to Set up Budgets.
///
internal static string Menu5_Ledgers_SetBudgets {
get {
@@ -753,6 +816,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Tracked Transactions.
+ ///
+ internal static string Menu5_Ledgers_TrackedTransactions {
+ get {
+ return ResourceManager.GetString("Menu5_Ledgers_TrackedTransactions", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Upload Bank Files.
///
@@ -942,6 +1014,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Distributed Assets.
+ ///
+ internal static string Menu5_People_DistributedAssets {
+ get {
+ return ResourceManager.GetString("Menu5_People_DistributedAssets", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to List/Find People.
///
@@ -1032,6 +1113,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Reports.
+ ///
+ internal static string Menu5_Reports {
+ get {
+ return ResourceManager.GetString("Menu5_Reports", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to This is a temporary menu. Yes it's ugly now..
///
diff --git a/Site/App_GlobalResources/Menu5.resx b/Site/App_GlobalResources/Menu5.resx
index 3914f133..99fc8b1f 100644
--- a/Site/App_GlobalResources/Menu5.resx
+++ b/Site/App_GlobalResources/Menu5.resx
@@ -304,10 +304,11 @@
Profit & Loss Statement
- Resync Bank Account
+ Resync Connected Account
- Set Budget Amounts
+ Set up Budgets
+ "Budget" as in "Cost allowed for a particular purpose" or "Revenue expected from a source".
Upload Bank Files
@@ -446,4 +447,41 @@
Bitcoin Hotwallet Echo Test
+
+ Set up Connected Accounts
+ The connected accounts are those where transactions are read from an external source, like a bank account, a blockchain address, etc.
+
+
+ Set up Ledger Account Structure
+ This is sometimes called an "account plan" but this term has many overloaded meanings in the context of operations software.
+
+
+ Set up Payroll
+
+
+ My Salary
+ This lists salary payments for the logged on individual
+
+
+ Deprecating & Amortized Assets
+
+
+ Depreciations and Amortizations
+
+
+ Make Payroll Adjustments
+ As in bonuses, sick leave, lunch extras, whatever. Before or after tax.
+
+
+ Tracked Transactions
+ Tracking of special transactions
+
+
+ Distributed Assets
+ Distributed as in "out among activists"; this tracks who has what equipment
+
+
+ Reports
+ This is financial analysis reports. "Analysis" would also work as translation.
+
\ No newline at end of file
diff --git a/Site/App_GlobalResources/Pages.Ledgers.designer.cs b/Site/App_GlobalResources/Pages.Ledgers.designer.cs
index e48a5512..4dfda495 100644
--- a/Site/App_GlobalResources/Pages.Ledgers.designer.cs
+++ b/Site/App_GlobalResources/Pages.Ledgers.designer.cs
@@ -115,7 +115,7 @@ namespace Resources.Pages {
}
///
- /// 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?.
///
internal static string AccountPlan_Edit_AdministrativeLong {
get {
@@ -1141,7 +1141,7 @@ namespace Resources.Pages {
}
///
- /// Looks up a localized string similar to Resolve all unmatched accounts.
+ /// Looks up a localized string similar to Resolve all unmatched ledger transactions.
///
internal static string EndOfMonth_MatchAccounts {
get {
@@ -1149,6 +1149,15 @@ namespace Resources.Pages {
}
}
+ ///
+ /// Looks up a localized string similar to Payroll: No payroll defined.
+ ///
+ internal static string EndOfMonth_PayrollInactive {
+ get {
+ return ResourceManager.GetString("EndOfMonth_PayrollInactive", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to <strong>SKIP BANK STATEMENT?</strong><br/><br/>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.<br/><br/>You won't be asked again to upload this particular statement if you skip it now..
///
@@ -1158,6 +1167,15 @@ namespace Resources.Pages {
}
}
+ ///
+ /// Looks up a localized string similar to <strong>SKIP DOCUMENT UPLOAD?</strong><br/><br/>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.<br/><br/>You won't be asked again to upload this document if you skip it now..
+ ///
+ internal static string EndOfMonth_SkipDocumentDialogGeneric {
+ get {
+ return ResourceManager.GetString("EndOfMonth_SkipDocumentDialogGeneric", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to End-of-Month Routine: {0:MMMM yyyy}.
///
diff --git a/Site/App_GlobalResources/Pages.Ledgers.resx b/Site/App_GlobalResources/Pages.Ledgers.resx
index 0343b66f..151b6b5b 100644
--- a/Site/App_GlobalResources/Pages.Ledgers.resx
+++ b/Site/App_GlobalResources/Pages.Ledgers.resx
@@ -402,7 +402,8 @@
Active
- Are transactions here excluded from 2-D reports?
+ Is this an account after the EBITDA line?
+ Earnings before interest, tax, depreciation and amortization (EBITDA) is a measure of a company's operating performance.
Admin
@@ -1010,7 +1011,7 @@
This is a checklist of things to do to close the previous month and begin the new one with respect to accounting.
- Resolve all unmatched accounts
+ Resolve all unmatched ledger transactions
This means to match bank transactions with incoming/outgoing expected payments (invoices, expense reports, etc) where it couldn't be done automatically
@@ -1028,4 +1029,11 @@
<strong>SKIP BANK STATEMENT?</strong><br/><br/>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.<br/><br/>You won't be asked again to upload this particular statement if you skip it now.
+
+ <strong>SKIP DOCUMENT UPLOAD?</strong><br/><br/>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.<br/><br/>You won't be asked again to upload this document if you skip it now.
+
+
+ Payroll: No payroll defined
+ This is shown as a disabled action item when there's no active payroll
+
\ No newline at end of file
diff --git a/Site/Controls/v5/Base/FileUpload.ascx b/Site/Controls/v5/Base/FileUpload.ascx
index 337dfc54..1c1ccc7c 100644
--- a/Site/Controls/v5/Base/FileUpload.ascx
+++ b/Site/Controls/v5/Base/FileUpload.ascx
@@ -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();
diff --git a/Site/Controls/v5/Base/FileUpload.ascx.cs b/Site/Controls/v5/Base/FileUpload.ascx.cs
index 4d1db30a..9506b1d1 100644
--- a/Site/Controls/v5/Base/FileUpload.ascx.cs
+++ b/Site/Controls/v5/Base/FileUpload.ascx.cs
@@ -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
diff --git a/Site/Pages/v5/Admin/CommenceImpersonation.aspx b/Site/Pages/v5/Admin/CommenceImpersonation.aspx
index 54ac871f..eb1ed37e 100644
--- a/Site/Pages/v5/Admin/CommenceImpersonation.aspx
+++ b/Site/Pages/v5/Admin/CommenceImpersonation.aspx
@@ -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'
diff --git a/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs b/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
index 858cf85a..8f6bae8b 100644
--- a/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
+++ b/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
@@ -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
{
diff --git a/Site/Pages/v5/Ledgers/EndOfMonth.aspx b/Site/Pages/v5/Ledgers/EndOfMonth.aspx
index 6c88694b..e5223e3c 100644
--- a/Site/Pages/v5/Ledgers/EndOfMonth.aspx
+++ b/Site/Pages/v5/Ledgers/EndOfMonth.aspx
@@ -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 @@
+
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: '" + group.Header.Replace(" ", " ").Replace("'", "''") + @"',
- action: ""
"",
+ itemGroupName: """",
+ action: ""
"",
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) + ")";
}
+ if (item.Icon == "upload")
+ {
+ iconIsUploadClass = " is-upload";
+ }
+
builder.Append(@"
$('#TableEomItems').datagrid('appendRow', {
- itemName: """ + itemName + @""",
- action: ""

""
+ itemName: """ + itemName + @""",
+ action: ""

""
});
");
}
@@ -205,27 +279,29 @@ namespace Swarmops.Frontend.Pages.Ledgers
{
builder.Append(@"
$('#TableEomItems').datagrid('appendRow', {
- itemName: """ + item.Name + @""",
- action: ""
""
+ itemName: """ + item.Name + @""",
+ action: ""
""
});
");
}
}
- 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 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); }
+ }
}
}
\ No newline at end of file
diff --git a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.designer.cs b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.designer.cs
index a7497d52..dfc5ac42 100644
--- a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.designer.cs
+++ b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.designer.cs
@@ -20,5 +20,14 @@ namespace Swarmops.Frontend.Pages.Ledgers {
/// To modify move field declaration from designer file to code-behind file.
///
protected global::System.Web.UI.WebControls.Label LabelHeader;
+
+ ///
+ /// UploadControl control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::Swarmops.Controls.Base.FileUpload UploadControl;
}
}
diff --git a/Site/Site.csproj b/Site/Site.csproj
index 5c92cee9..4cb30e16 100644
--- a/Site/Site.csproj
+++ b/Site/Site.csproj
@@ -75,6 +75,9 @@
+
+ ..\..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll
+
..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
True
@@ -5310,6 +5313,9 @@
Pages.Swarm.yo-NG.designer.cs
+
+
+
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
diff --git a/todo.txt b/todo.txt
index 003a6c93..2dca32e6 100644
--- a/todo.txt
+++ b/todo.txt
@@ -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