Beispiel #1
0
        private bool CreateExpenseForTransaction(string propertyCode, double amount, DateTime transactionDate, string category)
        {
            var     provider = new ExpenseProvider(_dbContext);
            Expense expense  = provider.GetRebalanceExpenseByKey(propertyCode, category, transactionDate);

            if (expense == null)
            {
                amount = -Math.Round(amount, 2);

                expense = new Expense
                {
                    ExpenseDate      = transactionDate,
                    Category         = category,
                    ExpenseAmount    = (float)amount,
                    PropertyCode     = propertyCode,
                    ParentId         = 0,
                    ApprovalStatus   = RevenueApprovalStatus.Approved,
                    ApprovedNote     = "Rebalance",
                    ConfirmationCode = string.Empty,
                };

                provider.Create(expense);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private void CreateExpenseGroupsForTransactions(SummaryRebalanceTransactionModel model, DateTime transactionDate)
        {
            var provider = new ExpenseProvider(_dbContext);

            foreach (RebalanceTransactionModel transaction in model.Transactions)
            {
                // From property
                var     debitCategory = MakeCategory(DebitCategoryPrefix, transaction.ToAddress);
                Expense debitExpense  = provider.GetRebalanceExpenseByKey(transaction.FromProperty, debitCategory, transactionDate);
                if (debitExpense != null)
                {
                    debitExpense.ParentId = debitExpense.ExpenseId;
                    provider.Update(debitExpense.ExpenseId, debitExpense);
                }

                // To Property
                var creditCategory = MakeCategory(CreditCategoryPrefix, transaction.FromAddress);
                var creditExpense  = provider.GetRebalanceExpenseByKey(transaction.ToProperty, creditCategory, transactionDate);
                if (creditExpense != null)
                {
                    creditExpense.ParentId = creditExpense.ExpenseId;
                    provider.Update(creditExpense.ExpenseId, creditExpense);
                }
            }
            CommitChanges();
        }
Beispiel #3
0
        // Replaced by stored precedure version MoveWorkflowAll above due to performance issue using Entity Framework for bulk db operation
        public RevenueApprovalStatus?BacktrackWorkflowAll(DateTime month, string propertyCode, RevenueApprovalStatus state)
        {
            try
            {
                var provider = new ExpenseProvider(_context);

                DateTime startDate = new DateTime(month.Year, month.Month, 1);
                DateTime endDate   = new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month));
                var      expenses  = provider.RetrieveCombinedExpenses(startDate, endDate, propertyCode);
                var      prevState = PrevState(state);
                if (expenses != null && prevState != null)
                {
                    foreach (var expense in expenses)
                    {
                        if (expense.ApprovalStatus >= prevState)
                        {
                            expense.ApprovalStatus = prevState.Value;
                            RetrackWorkflowSignature(expense, state);
                            provider.Update(expense.ExpenseId, expense);
                        }
                    }
                    provider.Commit();
                    return(prevState);
                }
            }
            catch
            {
                throw;
            }
            return(null);
        }
Beispiel #4
0
 public bool SetFieldStatus(int expenseId, string fieldname, bool included)
 {
     try
     {
         var provider = new ExpenseProvider(_context);
         var entity   = provider.Retrieve(expenseId);
         if (entity != null)
         {
             if (fieldname == "IncludeOnStatement")
             {
                 entity.IncludeOnStatement = included;
                 provider.Update(entity.ExpenseId, entity);
                 provider.Commit();
                 return(true);
             }
             else // not supported field; just ignore for now...
             {
                 return(true);
             }
         }
     }
     catch
     {
         throw;
     }
     return(false);
 }
Beispiel #5
0
        public void CreateExpenseGroup(Expense entity)
        {
            try
            {
                var dataProvider = new ExpenseProvider(_context);
                dataProvider.Create(entity);
                dataProvider.Commit();

                if (entity.ExpenseId == 0)
                {
                    entity.ExpenseId = dataProvider.GetGroupByKey(entity.PropertyCode, entity.Category, entity.ExpenseDate.Value);
                }

                if (entity.ExpenseId > 0)
                {
                    entity.ParentId = entity.ExpenseId;
                    dataProvider.Update(entity.ExpenseId, entity);
                    dataProvider.Commit();
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #6
0
 public override void Update(int id, ExpenseRevenueModel model)
 {
     try
     {
         var dataProvider = new ExpenseProvider(_context);
         var entity       = dataProvider.Retrieve(model.ExpenseId);
         MapData(model, entity);
         dataProvider.Update(id, entity);
     }
     catch
     {
         throw;
     }
 }
Beispiel #7
0
 public override void Create(ExpenseRevenueModel model)
 {
     try
     {
         var entity = new Expense();
         MapData(model, entity);
         var dataProvider = new ExpenseProvider(_context);
         dataProvider.Create(entity);
     }
     catch
     {
         throw;
     }
 }
Beispiel #8
0
 public override void Delete(int id)
 {
     try
     {
         // entity deletion does not physically delete the record; it marks [IsDeletd] = true
         var dataProvider = new ExpenseProvider(_context);
         var entity       = dataProvider.Retrieve(id);
         entity.IsDeleted = true;
         dataProvider.Update(id, entity);
     }
     catch
     {
         throw;
     }
 }
Beispiel #9
0
        public int UpdateCombinedExpense(int sourceId, int targetId)
        {
            try
            {
                var   dataProvider     = new ExpenseProvider(_context);
                var   entity           = _context.Expenses.Where(x => x.ExpenseId == sourceId).FirstOrDefault();
                int   originalParentId = entity.ParentId;
                float originalAmount   = entity.ExpenseAmount;
                entity.ParentId = targetId;
                dataProvider.Update(sourceId, entity);
                dataProvider.Commit();

                // update original expense total
                if (originalParentId != sourceId)
                {
                    var totalAmount = _context.Expenses.Where(x => x.ParentId == originalParentId && x.ExpenseId != originalParentId)
                                      .Select(x => x.ExpenseAmount)
                                      .Sum();
                    var sourceEntity = _context.Expenses.Where(x => x.ExpenseId == originalParentId).FirstOrDefault();
                    if (sourceEntity != null)
                    {
                        sourceEntity.ExpenseAmount = totalAmount;
                        dataProvider.Update(originalParentId, sourceEntity);
                    }
                }

                if (sourceId != targetId)
                {
                    var totalAmount = _context.Expenses.Where(x => x.ParentId == targetId && x.ExpenseId != targetId)
                                      .Select(x => x.ExpenseAmount)
                                      .Sum();
                    var targetEntity = _context.Expenses.Where(x => x.ExpenseId == targetId).FirstOrDefault();
                    if (targetEntity != null)
                    {
                        targetEntity.ExpenseAmount = totalAmount;
                        dataProvider.Update(targetId, targetEntity);
                    }
                }

                dataProvider.Commit();

                return(sourceId);
            }
            catch
            {
                return(-1);
            }
        }
Beispiel #10
0
        private void CreateExpenseGroupAsNeeded(SummaryRebalanceTransactionModel model, DateTime transactionDate)
        {
            const string RebalanceApprovalNote = "Rebalance";

            var provider = new ExpenseProvider(_dbContext);

            foreach (RebalanceTransactionModel t in model.Transactions)
            {
                int id = provider.GetGroupByKey(t.FromProperty, DebitGroupCategory, transactionDate);
                if (id == 0)
                {
                    var expense = new Expense
                    {
                        ExpenseDate      = transactionDate,
                        Category         = DebitGroupCategory,
                        ExpenseAmount    = 0,
                        PropertyCode     = t.FromProperty,
                        ApprovalStatus   = RevenueApprovalStatus.Approved,
                        ApprovedNote     = RebalanceApprovalNote,
                        ConfirmationCode = string.Empty,
                    };
                    provider.CreateExpenseGroup(expense);
                }

                id = provider.GetGroupByKey(t.ToProperty, CreditGroupCategory, transactionDate);
                if (id == 0)
                {
                    var expense = new Expense
                    {
                        ExpenseDate      = transactionDate,
                        Category         = CreditGroupCategory,
                        ExpenseAmount    = 0,
                        PropertyCode     = t.ToProperty,
                        ApprovalStatus   = RevenueApprovalStatus.Approved,
                        ApprovedNote     = RebalanceApprovalNote,
                        ConfirmationCode = string.Empty,
                    };
                    provider.CreateExpenseGroup(expense);
                }
            }
        }
Beispiel #11
0
 public RevenueApprovalStatus?BacktrackWorkflow(int expenseId, RevenueApprovalStatus state)
 {
     try
     {
         var dataProvider = new ExpenseProvider(_context);
         var entity       = dataProvider.Retrieve(expenseId);
         var prevState    = PrevState(state);
         if (entity != null && prevState != null)
         {
             entity.ApprovalStatus = prevState.Value;
             RetrackWorkflowSignature(entity, state);
             dataProvider.Update(expenseId, entity);
             dataProvider.Commit();
             return(prevState);
         }
     }
     catch
     {
         throw;
     }
     return(null);
 }
Beispiel #12
0
 public RevenueApprovalStatus?MoveWorkflow(int expenseId, RevenueApprovalStatus state)
 {
     try
     {
         var dataProvider = new ExpenseProvider(_context);
         var entity       = dataProvider.Retrieve(expenseId);
         var nextState    = NextState(state);
         if (entity != null && nextState != null)
         {
             entity.ApprovalStatus = state;
             SetWorkflowSignature(entity, state);
             dataProvider.Update(expenseId, entity);
             dataProvider.Commit();
             return(nextState);
         }
     }
     catch
     {
         throw;
     }
     return(null);
 }
Beispiel #13
0
        private bool CreateExpenseForTransaction(string propertyCode, double amount, DateTime transactionDate, string groupCategory, string category)
        {
            var provider = new ExpenseProvider(_dbContext);
            int groupId  = provider.GetGroupByKey(propertyCode, groupCategory, transactionDate);

            if (groupId > 0)
            {
                amount = -Math.Round(amount, 2);

                var expense = new Expense
                {
                    ExpenseDate      = transactionDate,
                    Category         = category,
                    ExpenseAmount    = (float)amount,
                    PropertyCode     = propertyCode,
                    ParentId         = groupId,
                    ApprovalStatus   = RevenueApprovalStatus.Approved,
                    ApprovedNote     = string.Empty,
                    ConfirmationCode = string.Empty,
                };

                provider.Create(expense);

                var entity = provider.Retrieve(groupId);
                if (entity != null)
                {
                    entity.ExpenseAmount += (float)amount;
                    provider.Update(entity.ExpenseId, entity);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }