Beispiel #1
0
        public void DictionaryTest()
        {
            LedgerBucket instance1 = LedgerBookTestData.HairLedger;

            var dictionary = new Dictionary <LedgerBucket, LedgerBucket>
            {
                { instance1, instance1 }
            };

            LedgerBucket instance2 = new SavedUpForLedger
            {
                BudgetBucket    = StatementModelTestData.HairBucket,
                StoredInAccount = LedgerBookTestData.ChequeAccount
            };

            // Should already contain this, its the same code.
            Assert.IsTrue(dictionary.ContainsKey(instance2));

            LedgerBucket instance3 = new SavedUpForLedger
            {
                BudgetBucket    = new SavedUpForExpenseBucket("HAIRCUT", "Foo bar"),
                StoredInAccount = LedgerBookTestData.ChequeAccount
            };

            Assert.IsTrue(dictionary.ContainsKey(instance3));
        }
 private void Reset()
 {
     this.ledger         = null;
     MonthlyBudgetAmount = 0;
     BankAccounts.Clear();
     StoredInAccount = null;
 }
        public void MoveLedgerToAccount(LedgerBucket ledger, Account storedInAccount)
        {
            if (ledger == null)
            {
                throw new ArgumentNullException(nameof(ledger));
            }
            if (storedInAccount == null)
            {
                throw new ArgumentNullException(nameof(storedInAccount));
            }

            LedgerBook.SetLedgerAccount(ledger, storedInAccount);
        }
        // ReSharper disable once UnusedParameter.Local - This argument is used to optionally detect elements not in array.
        private LedgerBucket GetOrAddFromCache(LedgerBucket ledger, bool throwIfNotFound = false)
        {
            if (this.cachedLedgers.ContainsKey(ledger.BudgetBucket.Code))
            {
                return this.cachedLedgers[ledger.BudgetBucket.Code];
            }

            if (throwIfNotFound)
            {
                throw new ArgumentException($"Ledger Bucket {ledger.BudgetBucket.Code} not found in cache.");
            }

            this.cachedLedgers.Add(ledger.BudgetBucket.Code, ledger);
            return ledger;
        }
Beispiel #5
0
        // ReSharper disable once UnusedParameter.Local - This argument is used to optionally detect elements not in array.
        private LedgerBucket GetOrAddFromCache(LedgerBucket ledger, bool throwIfNotFound = false)
        {
            if (this.cachedLedgers.ContainsKey(ledger.BudgetBucket.Code))
            {
                return(this.cachedLedgers[ledger.BudgetBucket.Code]);
            }

            if (throwIfNotFound)
            {
                throw new ArgumentException($"Ledger Bucket {ledger.BudgetBucket.Code} not found in cache.");
            }

            this.cachedLedgers.Add(ledger.BudgetBucket.Code, ledger);
            return(ledger);
        }
Beispiel #6
0
        public LedgerBookBuilder IncludeLedger(LedgerBucket ledger, decimal openingBalance = 0)
        {
            if (this.ledgerBuckets.Any(b => b.BudgetBucket.Code == ledger.BudgetBucket.Code))
            {
                throw new DuplicateNameException("Ledger Bucket already exists in collection.");
            }

            if (ledger.StoredInAccount == null)
            {
                ledger.StoredInAccount = StatementModelTestData.ChequeAccount;
            }

            this.ledgerBuckets.Add(ledger);
            this.openingBalances.Add(ledger, openingBalance);

            return(this);
        }
Beispiel #7
0
        public void TestIntialise()
        {
            this.mockBucketRepo  = new Mock <IBudgetBucketRepository>();
            this.mockRuleService = new Mock <ITransactionRuleService>();
            this.mockReconciliationConsistency = new Mock <IReconciliationConsistency>();
            this.subject = new ReconciliationCreationManager(this.mockRuleService.Object, this.mockReconciliationConsistency.Object, new FakeLogger());

            this.testDataLedgerBook = LedgerBookTestData.TestData5(() => new LedgerBookTestHarness(new Mock <IReconciliationBuilder>().Object));
            this.testDataEntryLine  = this.testDataLedgerBook.Reconciliations.First();
            this.testDataEntryLine.Unlock();

            this.surplusChqLedger = new SurplusLedger {
                StoredInAccount = StatementModelTestData.ChequeAccount
            };
            this.insHomeSavLedger = this.testDataLedgerBook.Ledgers.Single(l => l.BudgetBucket == StatementModelTestData.InsHomeBucket);
            this.phNetChqLedger   = this.testDataLedgerBook.Ledgers.Single(l => l.BudgetBucket == StatementModelTestData.PhoneBucket);
        }
        private static Brush StripColour(LedgerBucket ledger)
        {
            if (ledger.BudgetBucket is SpentMonthlyExpenseBucket)
            {
                return(ConverterHelper.SpentMonthlyBucketBrush);
            }

            if (ledger.BudgetBucket is SavedUpForExpenseBucket)
            {
                return(ConverterHelper.AccumulatedBucketBrush);
            }

            if (ledger.BudgetBucket is SavingsCommitmentBucket)
            {
                return(ConverterHelper.SavingsCommitmentBucketBrush);
            }

            return(ConverterHelper.TileBackgroundBrush);
        }
        public void ShowDialog([NotNull] Engine.Ledger.LedgerBook parentLedgerBook, [NotNull] LedgerBucket ledgerBucket, [NotNull] BudgetModel budgetModel)
        {
            if (parentLedgerBook == null)
            {
                throw new ArgumentNullException(nameof(parentLedgerBook));
            }

            if (ledgerBucket == null)
            {
                throw new ArgumentNullException(nameof(ledgerBucket));
            }

            if (budgetModel == null)
            {
                throw new ArgumentNullException(nameof(budgetModel));
            }

            if (LedgerBucketHistoryAnalysis == null)
            {
                LedgerBucketHistoryAnalysis = CreateBucketHistoryAnalyser();
            }
            LedgerBucketHistoryAnalysis.Analyse(ledgerBucket, parentLedgerBook);
            this.ledger         = ledgerBucket;
            BankAccounts        = new ObservableCollection <Account>(this.accountRepo.ListCurrentlyUsedAccountTypes());
            BucketBeingTracked  = ledgerBucket.BudgetBucket;
            StoredInAccount     = ledgerBucket.StoredInAccount;
            MonthlyBudgetAmount = budgetModel.Expenses.Single(e => e.Bucket == BucketBeingTracked).Amount;
            this.correlationId  = Guid.NewGuid();

            var dialogRequest = new ShellDialogRequestMessage(BudgetAnalyserFeature.LedgerBook, this, ShellDialogType.OkCancel)
            {
                CorrelationId = this.correlationId,
                Title         = "Ledger - " + BucketBeingTracked,
                HelpAvailable = true
            };

            MessengerInstance.Send(dialogRequest);
        }
Beispiel #10
0
        /// <summary>
        ///     Analyses the specified ledger and assigns graph data
        /// </summary>
        public void Analyse([NotNull] LedgerBucket ledger, [NotNull] LedgerBook book)
        {
            if (ledger == null)
            {
                throw new ArgumentNullException(nameof(ledger));
            }

            if (book == null)
            {
                throw new ArgumentNullException(nameof(book));
            }

            GraphData = new GraphData
            {
                GraphName = "Bucket Balance History"
            };

            var series = new SeriesData
            {
                Description = "The actual bank balance of the Ledger Bucket over time.",
                SeriesName  = "Balance"
            };

            GraphData.SeriesList.Add(series);

            foreach (var reconciliation in book.Reconciliations.Take(24).Reverse())
            {
                var entry = reconciliation.Entries.FirstOrDefault(e => e.LedgerBucket == ledger);
                var plot  = new DatedGraphPlot
                {
                    Date   = reconciliation.Date,
                    Amount = entry?.Balance ?? 0
                };
                series.PlotsList.Add(plot);
            }
        }
Beispiel #11
0
 private void OnShowLedgerBucketDetailsCommand(LedgerBucket ledgerBucket)
 {
     this.uiContext.LedgerBucketViewController.Updated += OnLedgerBucketUpdated;
     this.uiContext.LedgerBucketViewController.ShowDialog(ViewModel.LedgerBook, ledgerBucket, ViewModel.CurrentBudget.Model);
 }
 private static LedgerEntry CreateLedgerEntry(LedgerBucket ledger, decimal balance = 0)
 {
     return(new LedgerEntry {
         LedgerBucket = ledger, Balance = balance
     });
 }
Beispiel #13
0
 partial void ToModelPostprocessing(LedgerBucketDto dto, ref LedgerBucket model)
 {
     model.BudgetBucket    = this.bucketRepo.GetByCode(dto.BucketCode);
     model.StoredInAccount = this.accountTypeRepo.GetByKey(dto.StoredInAccount);
 }
Beispiel #14
0
 partial void ToDtoPostprocessing(ref LedgerBucketDto dto, LedgerBucket model)
 {
     dto.BucketCode      = model.BudgetBucket.Code;
     dto.StoredInAccount = model.StoredInAccount.Name;
 }
Beispiel #15
0
 public SpecificLedgerEntryTestDataBuilder WithLedger(LedgerBucket ledger)
 {
     return(this.ledgers[ledger]);
 }
 partial void ToModelPostprocessing(LedgerBucketDto dto, ref LedgerBucket model)
 {
     model.BudgetBucket = this.bucketRepo.GetByCode(dto.BucketCode);
     model.StoredInAccount = this.accountTypeRepo.GetByKey(dto.StoredInAccount);
 }
 partial void ToDtoPostprocessing(ref LedgerBucketDto dto, LedgerBucket model)
 {
     dto.BucketCode = model.BudgetBucket.Code;
     dto.StoredInAccount = model.StoredInAccount.Name;
 }
 // ReSharper disable once RedundantAssignment
 partial void ModelFactory(LedgerBucketDto dto, ref LedgerBucket model)
 {
     model = this.bucketFactory.Build(dto.BucketCode, dto.StoredInAccount);
 }
        private List <LedgerTransaction> IncludeBudgetedAmount(BudgetModel currentBudget, LedgerBucket ledgerBucket, DateTime reconciliationDate)
        {
            var budgetedExpense = currentBudget.Expenses.FirstOrDefault(e => e.Bucket.Code == ledgerBucket.BudgetBucket.Code);
            var transactions    = new List <LedgerTransaction>();

            if (budgetedExpense != null)
            {
                BudgetCreditLedgerTransaction budgetedAmount;
                if (ledgerBucket.StoredInAccount.IsSalaryAccount)
                {
                    budgetedAmount = new BudgetCreditLedgerTransaction
                    {
                        Amount    = budgetedExpense.Bucket.Active ? budgetedExpense.Amount : 0,
                        Narrative = budgetedExpense.Bucket.Active ? "Budgeted Amount" : "Warning! Bucket has been disabled."
                    };
                }
                else
                {
                    budgetedAmount = new BudgetCreditLedgerTransaction
                    {
                        Amount    = budgetedExpense.Bucket.Active ? budgetedExpense.Amount : 0,
                        Narrative = budgetedExpense.Bucket.Active
                            ? "Budget amount must be transferred into this account with a bank transfer, use the reference number for the transfer."
                            : "Warning! Bucket has been disabled.",
                        AutoMatchingReference = ReferenceNumberGenerator.IssueTransactionReferenceNumber()
                    };
                    // TODO Maybe the budget should know which account the incomes go into, perhaps mapped against each income?
                    var salaryAccount = this.newReconciliationLine.BankBalances.Single(b => b.Account.IsSalaryAccount).Account;
                    this.toDoList.Add(
                        new TransferTask(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                "Budgeted Amount for {0} transfer {1:C} from Salary Account to {2} with auto-matching reference: {3}",
                                budgetedExpense.Bucket.Code,
                                budgetedAmount.Amount,
                                ledgerBucket.StoredInAccount,
                                budgetedAmount.AutoMatchingReference),
                            true)
                    {
                        Amount             = budgetedAmount.Amount,
                        SourceAccount      = salaryAccount,
                        DestinationAccount = ledgerBucket.StoredInAccount,
                        BucketCode         = budgetedExpense.Bucket.Code,
                        Reference          = budgetedAmount.AutoMatchingReference
                    });
                }

                budgetedAmount.Date = reconciliationDate;
                transactions.Add(budgetedAmount);
            }

            return(transactions);
        }
Beispiel #20
0
 // ReSharper disable once RedundantAssignment
 partial void ModelFactory(LedgerBucketDto dto, ref LedgerBucket model)
 {
     model = this.bucketFactory.Build(dto.BucketCode, dto.StoredInAccount);
 }