public BasicFinancialValidation (int financialValidationId, FinancialValidationType validationType, int personId, DateTime dateTime, FinancialDependencyType dependencyType, int foreignId)
 {
     this.FinancialValidationId = financialValidationId;
     this.ValidationType = validationType;
     this.PersonId = personId;
     this.DateTime = dateTime;
     this.DependencyType = dependencyType;
     this.ForeignId = foreignId;
 }
Пример #2
0
 public BasicFinancialValidation(int financialValidationId, FinancialValidationType validationType, int personId,
                                 DateTime dateTime, FinancialDependencyType dependencyType, int foreignId)
 {
     FinancialValidationId = financialValidationId;
     ValidationType        = validationType;
     PersonId       = personId;
     DateTime       = dateTime;
     DependencyType = dependencyType;
     ForeignId      = foreignId;
 }
Пример #3
0
        // Normal ctor

        public BasicVatReportItem(int vatReportItemId, int vatReportId, int financialTransactionId, int foreignId,
                                  FinancialDependencyType dependencyType, Int64 turnoverCents, Int64 vatInboundCents, Int64 vatOutboundCents)
        {
            this.VatReportItemId        = vatReportItemId;
            this.VatReportId            = VatReportId;
            this.FinancialTransactionId = financialTransactionId;
            this.ForeignId        = foreignId;
            this.DependencyType   = dependencyType;
            this.TurnoverCents    = turnoverCents;
            this.VatInboundCents  = vatInboundCents;
            this.VatOutboundCents = vatOutboundCents;
        }
Пример #4
0
        private static BasicFinancialValidation ReadFinancialValidationFromDataReader(IDataRecord reader)
        {
            int financialValidationId = reader.GetInt32(0);
            FinancialValidationType validationType =
                (FinancialValidationType)(Enum.Parse(typeof(FinancialValidationType), reader.GetString(1)));
            FinancialDependencyType dependencyType =
                (FinancialDependencyType)(Enum.Parse(typeof(FinancialDependencyType), reader.GetString(2)));
            int      foreignId = reader.GetInt32(3);
            DateTime dateTime  = reader.GetDateTime(4);
            int      personId  = reader.GetInt32(5);
            double   amount    = reader.GetDouble(6); // not yet used

            return(new BasicFinancialValidation(financialValidationId, validationType, personId, dateTime, dependencyType, foreignId));
        }
Пример #5
0
        private static BasicVatReportItem ReadVatReportItemFromDataReader(IDataRecord reader)
        {
            int vatReportItemId        = reader.GetInt32(0);
            int vatReportId            = reader.GetInt32(1);
            int financialTransactionId = reader.GetInt32(2);
            int foreignId = reader.GetInt32(3);
            FinancialDependencyType dependencyType =
                (FinancialDependencyType)Enum.Parse(typeof(FinancialDependencyType), reader.GetString(4));

            Int64 turnoverCents    = reader.GetInt64(5);
            Int64 vatInboundCents  = reader.GetInt64(6);
            Int64 vatOutboundCents = reader.GetInt64(7);

            return(new BasicVatReportItem(vatReportItemId, vatReportId, financialTransactionId, foreignId,
                                          dependencyType, turnoverCents, vatInboundCents, vatOutboundCents));
        }
Пример #6
0
        public void CreatePayoutDependency(int payoutId, FinancialDependencyType dependencyType, int foreignId)
        {
            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command = GetDbCommand("CreatePayoutDependency", connection);
                command.CommandType = CommandType.StoredProcedure;

                AddParameterWithName(command, "payoutId", payoutId);
                AddParameterWithName(command, "financialDependencyType", dependencyType.ToString());
                AddParameterWithName(command, "foreignId", foreignId);

                command.ExecuteNonQuery();
            }
        }
Пример #7
0
        public static Payout FromDependency(IHasIdentity dependency, FinancialDependencyType dependencyType = FinancialDependencyType.Unknown)
        {
            int payoutId = 0;

            if (dependencyType == FinancialDependencyType.Unknown)
            {
                payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency);
            }
            else
            {
                payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency, dependencyType);
            }

            if (payoutId == 0)
            {
                throw new ArgumentException("Supplied item does not have an associated payout");
            }

            return(Payout.FromIdentity(payoutId));
        }
Пример #8
0
        public static VatReportItem Create(VatReport report, FinancialTransaction transaction, Int64 turnoverCents,
                                           Int64 vatInboundCents, Int64 vatOutboundCents)
        {
            // Assumes there's a dependency of some sort

            IHasIdentity            foreignObject  = transaction.Dependency;
            FinancialDependencyType dependencyType =
                (foreignObject != null
                ? FinancialTransaction.GetFinancialDependencyType(transaction.Dependency)
                : FinancialDependencyType.Unknown);

            // The transaction dependency is stored for quick lookup; it duplicates information in the database
            // to save an expensive query as a mere optimization.

            int newVatReportItemId = SwarmDb.GetDatabaseForWriting()
                                     .CreateVatReportItem(report.Identity, transaction.Identity, foreignObject?.Identity ?? 0,
                                                          dependencyType, turnoverCents, vatInboundCents, vatOutboundCents);

            return(FromIdentityAggressive(newVatReportItemId));
        }
        public BasicFinancialValidation[] GetFinancialValidations(FinancialDependencyType dependencyType, int foreignId)
        {
            List<BasicFinancialValidation> result = new List<BasicFinancialValidation>();

            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command =
                    GetDbCommand(
                        "SELECT " + financialValidationFieldSequence + " WHERE FinancialDependencyTypes.Name='" + dependencyType.ToString() + "' AND ForeignId=" + foreignId.ToString() + " " + financialValidationOrder, connection);

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        result.Add(ReadFinancialValidationFromDataReader(reader));
                    }

                    return result.ToArray();
                }
            }
        }
Пример #10
0
        public BasicFinancialValidation[] GetFinancialValidations(FinancialDependencyType dependencyType, int foreignId)
        {
            List <BasicFinancialValidation> result = new List <BasicFinancialValidation>();

            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command =
                    GetDbCommand(
                        "SELECT " + financialValidationFieldSequence + " WHERE FinancialDependencyTypes.Name='" + dependencyType.ToString() + "' AND ForeignId=" + foreignId.ToString() + " " + financialValidationOrder, connection);

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        result.Add(ReadFinancialValidationFromDataReader(reader));
                    }

                    return(result.ToArray());
                }
            }
        }
Пример #11
0
 public BasicFinancialDependency(int objectId, FinancialDependencyType dependencyType, int foreignId)
 {
     ObjectId       = objectId;
     DependencyType = dependencyType;
     ForeignId      = foreignId;
 }
Пример #12
0
 public int GetPayoutIdFromDependency(IHasIdentity foreignObject, FinancialDependencyType typeName)
 {
     return GetPayoutIdFromDependency(foreignObject.Identity, typeName.ToString());
 }
Пример #13
0
 public int GetPayoutIdFromDependency(IHasIdentity foreignObject, FinancialDependencyType typeName)
 {
     return(GetPayoutIdFromDependency(foreignObject.Identity, typeName.ToString()));
 }
Пример #14
0
 public BasicFinancialDependency(int objectId, FinancialDependencyType dependencyType, int foreignId)
 {
     this.ObjectId       = objectId;
     this.DependencyType = dependencyType;
     this.ForeignId      = foreignId;
 }
Пример #15
0
        // TODO: Return BasicFinancialValidation object

        public void CreateFinancialValidation (FinancialValidationType validationType, FinancialDependencyType dependencyType, int foreignId,
            DateTime validatedDateTime, int personId, double amount)
        {
            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command = GetDbCommand("CreateFinancialValidation", connection);
                command.CommandType = CommandType.StoredProcedure;

                AddParameterWithName(command, "validationType", validationType.ToString());
                AddParameterWithName(command, "dependencyType", dependencyType.ToString());
                AddParameterWithName(command, "foreignId", foreignId);
                AddParameterWithName(command, "validatedDateTime", validatedDateTime);
                AddParameterWithName(command, "personId", personId);
                AddParameterWithName(command, "amount", amount);

                command.ExecuteNonQuery();
            }
        }
Пример #16
0
 public BasicFinancialValidation(int financialValidationId, FinancialValidationType validationType, int personId, DateTime dateTime, FinancialDependencyType dependencyType, int foreignId)
 {
     this.FinancialValidationId = financialValidationId;
     this.ValidationType        = validationType;
     this.PersonId       = personId;
     this.DateTime       = dateTime;
     this.DependencyType = dependencyType;
     this.ForeignId      = foreignId;
 }
Пример #17
0
        // The function below uses OUT parameters, which is a no-go according to .Net Design Guidelines.
        // Fix this by introducing the BasicFinancialDependency type in the semi-near future, and
        // using it as a return type.

        public void GetFinancialTransactionDependency (int financialTransactionId, out FinancialDependencyType dependencyType, out int foreignId)
        {
            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command =
                    GetDbCommand(
                        "SELECT FinancialDependencyTypes.Name,FinancialTransactionDependencies.ForeignId " +
                        "FROM FinancialTransactionDependencies,FinancialDependencyTypes " +
                        "WHERE FinancialDependencyTypes.FinancialDependencyTypeId=FinancialTransactionDependencies.FinancialDependencyTypeId " +
                        "AND FinancialTransactionDependencies.FinancialTransactionId=" + financialTransactionId.ToString(), connection);

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        // Set OUT parameters

                        dependencyType = (FinancialDependencyType) Enum.Parse(typeof (FinancialDependencyType), reader.GetString(0));
                        foreignId = reader.GetInt32(1);
                    }
                    else
                    {
                        // Set OUT parameters

                        dependencyType = FinancialDependencyType.Unknown;
                        foreignId = 0;
                    }
                }
            }
            
        }
Пример #18
0
        public BasicFinancialTransaction[] GetDependentFinancialTransactions(FinancialDependencyType dependencyType, int foreignId)
        {
            List<int> transactionIds = new List<int>();

            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command =
                    GetDbCommand(
                        "SELECT FinancialTransactionId FROM FinancialTransactionDependencies,FinancialDependencyTypes " +
                        "WHERE FinancialDependencyTypes.Name='" + dependencyType.ToString() + "' AND " +
                        "FinancialDependencyTypes.FinancialDependencyTypeId=FinancialTransactionDependencies.FinancialDependencyTypeId AND " +
                        "FinancialTransactionDependencies.ForeignId=" + foreignId.ToString(), connection);

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        transactionIds.Add(reader.GetInt32(0));
                    }
                }
            }

            if (transactionIds.Count == 0)
            {
                return new BasicFinancialTransaction[0];
            }

            return GetFinancialTransactions(transactionIds.ToArray());
        }
Пример #19
0
        public void SetFinancialTransactionDependency(int financialTransactionId, FinancialDependencyType dependencyType, int foreignId)
        {
            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command = GetDbCommand("SetFinancialTransactionDependency", connection);
                command.CommandType = CommandType.StoredProcedure;

                AddParameterWithName(command, "financialTransactionId", financialTransactionId);
                AddParameterWithName(command, "financialDependencyType", dependencyType.ToString());
                AddParameterWithName(command, "foreignId", foreignId);

                command.ExecuteNonQuery();
            }
        }
Пример #20
0
 public BasicFinancialDependency (int objectId, FinancialDependencyType dependencyType, int foreignId)
 {
     this.ObjectId = objectId;
     this.DependencyType = dependencyType;
     this.ForeignId = foreignId;
 }
Пример #21
0
        public int CreateVatReportItem(int vatReportId, int financialTransactionId, int foreignObjectId, FinancialDependencyType financialDependencyType, Int64 turnoverCents, Int64 vatInboundCents, Int64 vatOutboundCents)
        {
            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command = GetDbCommand("CreateVatReportItem", connection);
                command.CommandType = CommandType.StoredProcedure;

                AddParameterWithName(command, "vatReportId", vatReportId);
                AddParameterWithName(command, "financialTransactionId", financialTransactionId);
                AddParameterWithName(command, "foreignId", foreignObjectId);
                AddParameterWithName(command, "financialDependencyType", financialDependencyType.ToString());
                AddParameterWithName(command, "turnoverCents", turnoverCents);
                AddParameterWithName(command, "vatInboundCents", vatInboundCents);
                AddParameterWithName(command, "vatOutboundCents", vatOutboundCents);

                return(Convert.ToInt32(command.ExecuteScalar()));

                // "Open" is set in the stored procedure to "NOT (TaxPaid AND NetPaid)".
                // So if both are paid, Open is set to false.
            }
        }