public static LedgerEntry Decode(IByteReader stream) {
   LedgerEntry decodedLedgerEntry = new LedgerEntry();
   decodedLedgerEntry.LastModifiedLedgerSeq = Uint32.Decode(stream);
   decodedLedgerEntry.Data = LedgerEntryData.Decode(stream);
   decodedLedgerEntry.Ext = LedgerEntryExt.Decode(stream);
   return decodedLedgerEntry;
 }
        public static void Encode(XdrDataOutputStream stream, BucketEntry encodedBucketEntry)
        {
            stream.WriteInt((int)encodedBucketEntry.Discriminant.InnerValue);
            switch (encodedBucketEntry.Discriminant.InnerValue)
            {
            case BucketEntryType.BucketEntryTypeEnum.LIVEENTRY:
            case BucketEntryType.BucketEntryTypeEnum.INITENTRY:
                LedgerEntry.Encode(stream, encodedBucketEntry.LiveEntry);
                break;

            case BucketEntryType.BucketEntryTypeEnum.DEADENTRY:
                LedgerKey.Encode(stream, encodedBucketEntry.DeadEntry);
                break;

            case BucketEntryType.BucketEntryTypeEnum.METAENTRY:
                BucketMetadata.Encode(stream, encodedBucketEntry.MetaEntry);
                break;
            }
        }
Beispiel #3
0
        public static BucketEntry Decode(XdrDataInputStream stream)
        {
            BucketEntry     decodedBucketEntry = new BucketEntry();
            BucketEntryType discriminant       = BucketEntryType.Decode(stream);

            decodedBucketEntry.Discriminant = discriminant;

            switch (decodedBucketEntry.Discriminant.InnerValue)
            {
            case BucketEntryType.BucketEntryTypeEnum.LIVEENTRY:
                decodedBucketEntry.LiveEntry = LedgerEntry.Decode(stream);
                break;

            case BucketEntryType.BucketEntryTypeEnum.DEADENTRY:
                decodedBucketEntry.DeadEntry = LedgerKey.Decode(stream);
                break;
            }

            return(decodedBucketEntry);
        }
Beispiel #4
0
    void addOrUpdate(LedgerEntry le)
    {
        int index = -1;

        for (int i = 0; i < les.Count; ++i)
        {
            if (les[i].playerData.netID == le.playerData.netID)
            {
                index = i;
                break;
            }
        }
        if (index >= 0)
        {
            les[index] = le;
        }
        else
        {
            les.Add(le);
        }
    }
Beispiel #5
0
    public void UpdateDisplay(LedgerEntry le)
    {
        addOrUpdate(le);
        //TODO: les should be a dictionary
        les = les.OrderByDescending(a => a.score).ToList();

        for (int i = 0; i < entries.Length; ++i)
        {
            string row   = "";
            string score = "";
            if (i < les.Count)
            {
                LedgerEntry l = les[i];
                row   = string.Format("({0}) {1}", i, l.playerData.displayName);
                score = string.Format("{0}", l.score);
                entries[i].setColors(l.playerData.color);
            }
            entries[i].left.text  = row;
            entries[i].right.text = score;
        }
    }
Beispiel #6
0
        public async Task <IEnumerable <LedgerEntry> > Subtract(string sessionId, double priceToSubtract)
        {
            var session = await _dbContext.Sessions.FindAsync(sessionId);

            var inserted = await GetAddedCollectionBySession(sessionId);

            var ledgerEntries   = inserted.ToList();
            var insertedOrdered = ledgerEntries.OrderBy(p => p.Token.Value).ToList();

            var currentPrice = priceToSubtract;

            IList <LedgerEntry> subtracted = new List <LedgerEntry>();

            var enumerator = insertedOrdered.GetEnumerator();

            while (currentPrice <= priceToSubtract && enumerator.MoveNext())
            {
                var currentLedgerEntry = enumerator.Current;
                if (currentLedgerEntry == null)
                {
                    continue;
                }
                currentPrice -= currentLedgerEntry.Token.Value;
                var newOutLedger = new LedgerEntry
                {
                    Operation = "O",
                    Related   = currentLedgerEntry,
                    Session   = session,
                    Token     = currentLedgerEntry.Token
                };
                await _dbContext.LedgerEntries.AddAsync(newOutLedger);

                subtracted.Add(newOutLedger);
            }

            enumerator.Dispose();
            await _dbContext.SaveChangesAsync();

            return(subtracted);
        }
Beispiel #7
0
        public static void Encode(IByteWriter stream, LedgerEntryChange encodedLedgerEntryChange)
        {
            XdrEncoding.EncodeInt32((int)encodedLedgerEntryChange.Discriminant.InnerValue, stream);
            switch (encodedLedgerEntryChange.Discriminant.InnerValue)
            {
            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_CREATED:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.Created);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_UPDATED:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.Updated);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_REMOVED:
                LedgerKey.Encode(stream, encodedLedgerEntryChange.Removed);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_STATE:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.State);
                break;
            }
        }
        public static void Encode(XdrDataOutputStream stream, LedgerEntryChange encodedLedgerEntryChange)
        {
            stream.WriteInt((int)encodedLedgerEntryChange.Discriminant.InnerValue);
            switch (encodedLedgerEntryChange.Discriminant.InnerValue)
            {
            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_CREATED:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.Created);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_UPDATED:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.Updated);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_REMOVED:
                LedgerKey.Encode(stream, encodedLedgerEntryChange.Removed);
                break;

            case LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_STATE:
                LedgerEntry.Encode(stream, encodedLedgerEntryChange.State);
                break;
            }
        }
        private static IEnumerable <LedgerTransaction> IncludeStatementTransactions(LedgerEntry newEntry, ICollection <Transaction> filteredStatementTransactions)
        {
            if (filteredStatementTransactions.None())
            {
                return(new List <LedgerTransaction>());
            }

            List <Transaction> transactions = filteredStatementTransactions.Where(t => t.BudgetBucket == newEntry.LedgerBucket.BudgetBucket).ToList();

            if (transactions.Any())
            {
                IEnumerable <LedgerTransaction> newLedgerTransactions = transactions.Select(
                    t =>
                {
                    if (t.Amount < 0)
                    {
                        return(new CreditLedgerTransaction(t.Id)
                        {
                            Amount = t.Amount,
                            Narrative = ExtractNarrative(t),
                            Date = t.Date
                        });
                    }

                    return(new CreditLedgerTransaction(t.Id)
                    {
                        Amount = t.Amount,
                        Narrative = ExtractNarrative(t),
                        Date = t.Date
                    });
                });

                return(newLedgerTransactions.ToList());
            }

            return(new List <LedgerTransaction>());
        }
 private bool ContainsRoundValue(LedgerEntry line, int magnitude)
 {
     return(IsRound(line.Amount, magnitude) ||
            IsRound(line.Amount, magnitude) ||
            IsRound(line.Amount, magnitude));
 }
Beispiel #11
0
 public Task <SQLResult> Delete(LedgerEntry pModel)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
        public async Task <SQLResult> Create(LedgerEntry pModel)
        {
            SQLResult result = new SQLResult();

            _Context.Database.BeginTransaction();
            try
            {
                string csql = @" EXEC spmLedgerInsert
                    @pi_LedgerCode
                    , @pi_Ledger
                    , @pi_LedgerGroupFlag
                    , @pi_LedgerGroupId
                    , @pi_MainLedgerGroupId
                    , @pi_LedgerTypeId
                    , @pi_ControlAccountId
                    , @pi_NoJVPosting
                    , @pi_AutomaticPostingId
                    , @pi_mCurrencyId
                    , @pi_LevelNo
                    , @pi_EffectiveFrom
                    , @pi_EffectiveTo
                    , @pi_AnalysisCodeApplicableFlag
                    , @pi_CostCenterApplication
                    , @pi_VersionNo
                    , @pi_Active
                    , @pi_mMyParentId
                    , @pi_UserId
                    , @pi_HostName
                    , @pi_IPAddress
                    , @pi_DeviceType
                    , @pi_MACAddress";
                List <SqlParameter> sqlparam = new List <SqlParameter>()
                {
                    new SqlParameter("@pi_LedgerCode", pModel.LedgerCode),
                    new SqlParameter("@pi_Ledger", pModel.Ledger),
                    new SqlParameter("@pi_LedgerGroupFlag", pModel.LedgerGroupFlag),
                    new SqlParameter("@pi_LedgerGroupId", pModel.LedgerGroupId),
                    new SqlParameter("@pi_MainLedgerGroupId", pModel.MainLedgerGroupId),
                    new SqlParameter("@pi_LedgerTypeId", pModel.LedgerTypeId),
                    new SqlParameter("@pi_ControlAccountId", pModel.ControlAccountId),
                    new SqlParameter("@pi_NoJVPosting", pModel.NoJVPosting),
                    new SqlParameter("@pi_AutomaticPostingId", pModel.AutomaticPostingId),
                    new SqlParameter("@pi_mCurrencyId", pModel.CurrencyId),
                    new SqlParameter("@pi_LevelNo", pModel.LevelNo),
                    new SqlParameter("@pi_EffectiveFrom", pModel.EffectiveFrom),
                    new SqlParameter("@pi_EffectiveTo", pModel.EffectiveTo),
                    new SqlParameter("@pi_AnalysisCodeApplicableFlag", pModel.AnalysisCodeApplicableFlag),
                    new SqlParameter("@pi_CostCenterApplication", pModel.CostCenterApplication),
                    new SqlParameter("@pi_Active", pModel.Active),
                    new SqlParameter("@pi_UserId", pModel.AuditColumns.UserId),
                    new SqlParameter("@pi_HostName", pModel.AuditColumns.HostName),
                    new SqlParameter("@pi_IPAddress", pModel.AuditColumns.IPAddress),
                    new SqlParameter("@pi_DeviceType", pModel.AuditColumns.DeviceType),
                    new SqlParameter("@pi_MACAddress", pModel.AuditColumns.MACAddress),
                };
                result = await _Context.DBResult.FromSql(csql, sqlparam.ToArray()).SingleOrDefaultAsync();

                if (result.ErrorNo != 0)
                {
                    _Context.Database.RollbackTransaction();
                }
                else
                {
                    _Context.Database.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                _Context.Database.RollbackTransaction();
                result.ErrorNo         = 9999999999;
                result.ErrorMessage    = ex.Message.ToString();
                result.SQLErrorNumber  = ex.HResult;
                result.SQLErrorMessage = ex.Source.ToString();
            }
            return(result);
        }
Beispiel #13
0
 private static string FormatEntry(IFormatProvider culture, LedgerEntry entry) =>
 $"{FormatDate(culture, entry.Date)} | {(entry.Desc.Length > 25 ? FormatDescription(entry.Desc) : entry.Desc),-25} | {FormatChange(culture, entry.Chg),13}";
Beispiel #14
0
        public bool VerifySignature <TrsanctioneeIdType>(LedgerEntry <TrsanctioneeIdType> ledgerEntry, string signature)
        {
            var calculatedHash = GetSignature(ledgerEntry);

            return(string.Compare(calculatedHash, signature) == 0);
        }
Beispiel #15
0
        private bool Validate(LedgerEntry pModel, Boolean UpdateFlag)
        {
            if (UpdateFlag == true)
            {
                if (pModel.LedgerId <= 1)
                {
                    ModelState.AddModelError("", Messages.Blank("Ledger"));
                    return(false);
                }
            }
            if (pModel.LedgerCode.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("Ledger Code"));
                return(false);
            }
            if (pModel.Ledger.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("Ledger"));
                return(false);
            }
            if (pModel.LedgerGroupId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Ledger Group"));
                return(false);
            }


            if (pModel.MainLedgerGroupId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Main ledger group"));
                return(false);
            }
            if (pModel.LedgerTypeId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Ledger type"));
                return(false);
            }
            if (pModel.ControlAccountId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Control account"));
                return(false);
            }
            if (pModel.AutomaticPostingId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Automatic posting"));
                return(false);
            }
            if (pModel.CurrencyId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("Currency"));
                return(false);
            }
            if (pModel.AuditColumns.CompanyId <= 1)
            {
                ModelState.AddModelError("", Messages.Blank("Company"));
                return(false);
            }
            if (pModel.AuditColumns.UserId <= 0)
            {
                ModelState.AddModelError("", Messages.Blank("User Id"));
                return(false);
            }
            if (pModel.AuditColumns.MACAddress.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("MAC Address"));
                return(false);
            }
            if (pModel.AuditColumns.HostName.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("Host Name"));
                return(false);
            }
            if (pModel.AuditColumns.IPAddress.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("IP Address"));
                return(false);
            }
            if (pModel.AuditColumns.DeviceType.Trim().Length == 0)
            {
                ModelState.AddModelError("", Messages.Blank("Device Type"));
                return(false);
            }
            return(true);
        }
 public static void Encode(IByteWriter stream, LedgerEntry encodedLedgerEntry)
 {
     Uint32.Encode(stream, encodedLedgerEntry.LastModifiedLedgerSeq);
     LedgerEntryData.Encode(stream, encodedLedgerEntry.Data);
     LedgerEntryExt.Encode(stream, encodedLedgerEntry.Ext);
 }
        /// <summary>
        ///     A Test LedgerBook with data populated for June July and August 2013.  Also includes some debit transactions.
        ///     There are multiple Bank Balances for the latest entry, and the Home Insurance bucket in a different account.
        /// </summary>
        public static LedgerBook TestData5(Func <LedgerBook> ctor = null)
        {
            LedgerBook book;

            if (ctor != null)
            {
                book = ctor();
            }
            else
            {
                book = new LedgerBook(new ReconciliationBuilder(new FakeLogger()));
            }
            book.Name       = "Test Data 5 Book";
            book.Modified   = new DateTime(2013, 12, 16);
            book.StorageKey = "C:\\Folder\\book5.xml";

            var list = new List <LedgerEntryLine>
            {
                CreateLine(
                    new DateTime(2013, 06, 15),
                    new[] { new BankBalance(ChequeAccount, 2800), new BankBalance(SavingsAccount, 300) },
                    "Lorem ipsum")
                .SetEntriesForTesting(
                    new List <LedgerEntry>
                {
                    CreateLedgerEntry(HouseInsLedgerSavingsAccount).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 300M, Narrative = "Budgeted amount", AutoMatchingReference = "IbEMWG7"
                        }
                    }),
                    CreateLedgerEntry(HairLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 55M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -45M, Narrative = "Hair cut"
                        }
                    }),
                    CreateLedgerEntry(PowerLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 140M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -123.56M, Narrative = "Power bill"
                        }
                    }),
                    CreateLedgerEntry(PhoneLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 95M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -86.43M, Narrative = "Pay phones"
                        }
                    })
                })
            };

            LedgerEntry previousHairEntry  = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.HairBucketCode);
            LedgerEntry previousPowerEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PowerBucketCode);
            LedgerEntry previousPhoneEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PhoneBucketCode);
            LedgerEntry previousInsEntry   = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.InsuranceHomeBucketCode);

            list.Add(
                CreateLine(
                    new DateTime(2013, 07, 15),
                    new[] { new BankBalance(ChequeAccount, 4000), new BankBalance(SavingsAccount, 600) },
                    "dolor amet set").SetEntriesForTesting(
                    new List <LedgerEntry>
            {
                CreateLedgerEntry(HouseInsLedgerSavingsAccount, previousInsEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 300M, Narrative = "Budgeted amount", AutoMatchingReference = "9+1R06x"
                    }
                }),
                CreateLedgerEntry(HairLedger, previousHairEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 55M, Narrative = "Budgeted amount"
                    }
                }),
                CreateLedgerEntry(PowerLedger, previousPowerEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 140M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -145.56M, Narrative = "Power bill"
                    }
                }),
                CreateLedgerEntry(PhoneLedger, previousPhoneEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 95M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -66.43M, Narrative = "Pay phones"
                    }
                })
            }));

            previousHairEntry  = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.HairBucketCode);
            previousPowerEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PowerBucketCode);
            previousPhoneEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PhoneBucketCode);
            previousInsEntry   = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.InsuranceHomeBucketCode);

            LedgerEntryLine line = CreateLine(
                new DateTime(2013, 08, 15),
                new[] { new BankBalance(ChequeAccount, 3050), new BankBalance(SavingsAccount, 1000) },
                "The quick brown fox jumped over the lazy dog").SetEntriesForTesting(
                new List <LedgerEntry>
            {
                CreateLedgerEntry(HouseInsLedgerSavingsAccount, previousInsEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 300M, Narrative = "Budgeted amount", AutoMatchingReference = "agkT9kC"
                    }
                }),
                CreateLedgerEntry(HairLedger, previousHairEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 55M, Narrative = "Budgeted amount"
                    }
                }),
                CreateLedgerEntry(PowerLedger, previousPowerEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 140M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -98.56M, Narrative = "Power bill"
                    }
                }),
                CreateLedgerEntry(PhoneLedger, previousPhoneEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 95M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -67.43M, Narrative = "Pay phones"
                    }
                })
            });

            line.BalanceAdjustment(-550, "Credit card payment yet to go out.", ChequeAccount);
            list.Add(line);

            book.SetReconciliations(list);

            Finalise(book);
            return(book);
        }
        private void AddLedgerEntryLinesVertically(Grid grid, int numberOfMonthsToShow)
        {
            var gridColumn  = 2; //because the first two columns are headings
            var monthNumber = 0;

            // Loop thru all Reconciliations from most recent to oldest adding cells to the grid vertically.
            foreach (LedgerEntryLine line in this.ledgerBook.Reconciliations)
            {
                var gridRow = 0;
                if (++monthNumber > numberOfMonthsToShow)
                {
                    break;
                }

                // Date
                gridRow = AddDateCellToLedgerEntryLine(grid, gridRow, ref gridColumn, line);

                // Remarks
                TextBlock remarksHyperlink = AddHyperlinkToGrid(grid, "...", ref gridRow, gridColumn, NormalStyle, line.Remarks, line);
                var       hyperlink        = (Hyperlink)remarksHyperlink.Inlines.FirstInline;
                hyperlink.Command = this.showRemarksCommand;

                // Bank Balance
                AddBorderToGridCell(grid, BankBalanceBackground, false, gridRow, gridColumn);
                TextBlock bankBalanceText = AddHyperlinkToGrid(
                    grid,
                    line.LedgerBalance.ToString("N", CultureInfo.CurrentCulture),
                    ref gridRow,
                    gridColumn,
                    ImportantNumberStyle,
                    BuildToolTipForBankBalance(line),
                    line);
                hyperlink                  = (Hyperlink)bankBalanceText.Inlines.FirstInline;
                hyperlink.Command          = this.showBankBalancesCommand;
                bankBalanceText.Foreground = (Brush)FindResource(BankBalanceTextBrush);

                // Balance Adjustments
                AddHyperlinkToGrid(
                    grid,
                    line.TotalBalanceAdjustments.ToString("N", CultureInfo.CurrentCulture),
                    ref gridRow,
                    gridColumn,
                    ImportantNumberStyle,
                    parameter: line);

                // Surplus
                gridRow = AddSurplusCell(grid, gridRow, gridColumn, line);

                // Ledgers
                Account currentBankAccount = null;
                foreach (LedgerBucket ledger in this.sortedLedgers)
                {
                    if (currentBankAccount != ledger.StoredInAccount)
                    {
                        gridRow++;
                        currentBankAccount = ledger.StoredInAccount;
                    }

                    LedgerEntry entry = line.Entries.FirstOrDefault(e => e.LedgerBucket.BudgetBucket == ledger.BudgetBucket);
                    decimal     balance, netAmount;

                    var movedBankAccounts = false;
                    if (entry == null)
                    {
                        // New ledger added that older entries do not have.
                        balance   = 0;
                        netAmount = 0;
                    }
                    else if (entry.LedgerBucket != ledger)
                    {
                        // This means the ledger has change bank accounts and should not be included in this bank account's group. Leave blank cells in this case.
                        movedBankAccounts = true;
                        balance           = 0;
                        netAmount         = 0;
                    }
                    else
                    {
                        balance   = entry.Balance;
                        netAmount = entry.NetAmount;
                    }

                    if (ledger.BudgetBucket is SpentMonthlyExpenseBucket)
                    {
                        Border border = AddBorderToGridCell(grid, false, true, gridRow, gridColumn);
                        border.ToolTip = "This ledger has moved to another bank account.";
                        if (movedBankAccounts)
                        {
                            gridRow++;
                        }
                        else
                        {
                            AddHyperlinkToGrid(grid, balance.ToString("N", CultureInfo.CurrentCulture), ref gridRow, gridColumn, NumberStyle, parameter: entry);
                        }
                    }
                    else
                    {
                        Border border1 = AddBorderToGridCell(grid, true, false, gridRow, gridColumn);
                        Border border2 = AddBorderToGridCell(grid, false, true, gridRow + 1, gridColumn);
                        if (movedBankAccounts)
                        {
                            border1.ToolTip = "This ledger has moved to another bank account.";
                            border2.ToolTip = "This ledger has moved to another bank account.";
                            gridRow        += 2;
                            continue;
                        }

                        AddHyperlinkToGrid(grid, netAmount.ToString("N", CultureInfo.CurrentCulture), ref gridRow, gridColumn, NumberStyle, parameter: entry);
                        AddHyperlinkToGrid(grid, balance.ToString("N", CultureInfo.CurrentCulture), ref gridRow, gridColumn, NumberStyle, parameter: entry);
                    }
                }

                gridColumn++;
            }
        }
Beispiel #19
0
 private LedgerEntry GetPreviousLedgerEntry(LedgerEntry ledgerEntry)
 {
     return(LedgerEntries.FirstOrDefault(t => t.TransactionTimestamp.CompareTo(ledgerEntry.TransactionTimestamp) < 0 &&
                                         t.BlockTimestamp.CompareTo(ledgerEntry.BlockTimestamp) < 0));
 }
Beispiel #20
0
 public LedgerEntryMessage(LedgerEntry ledgerEntry, LedgerEntryMessageAction action)
 {
     LedgerEntry = ledgerEntry;
     Action      = action;
 }
Beispiel #21
0
 public bool Add(LedgerEntry entry)
 {
     return AddItem(entry.Index(), entry);
 }
Beispiel #22
0
 public static void Encode(IByteWriter stream, LedgerEntry encodedLedgerEntry)
 {
     Uint32.Encode(stream, encodedLedgerEntry.LastModifiedLedgerSeq);
     LedgerEntryData.Encode(stream, encodedLedgerEntry.Data);
     LedgerEntryExt.Encode(stream, encodedLedgerEntry.Ext);
 }
 partial void ToModelPreprocessing(LedgerEntryDto dto, LedgerEntry model)
 {
     // Transactions must be done first otherwise balance will be changed by adding transactions and the balance should be read from the Dto.
     var transactionMapper = new Mapper_LedgerTransactionDto_LedgerTransaction(this.transactionFactory, this.accountTypeRepo);
     foreach (var txn in dto.Transactions)
     {
         model.AddTransaction(transactionMapper.ToModel(txn));
     }
 }
 partial void ToModelPostprocessing(LedgerEntryDto dto, ref LedgerEntry model)
 {
     model.LedgerBucket = this.bucketFactory.Build(dto.BucketCode, dto.StoredInAccount);
 }
 partial void ToDtoPostprocessing(ref LedgerEntryDto dto, LedgerEntry model)
 {
     dto.BucketCode = model.LedgerBucket.BudgetBucket.Code;
     dto.StoredInAccount = model.LedgerBucket.StoredInAccount.Name;
 }
        /// <summary>
        ///     Same as Test Data 2, but with multiple Bank Balances for the latest entry.
        ///     A Test LedgerBook with data populated for June July and August 2013.  Also includes some debit transactions.
        ///     August transactions include some balance adjustments.
        /// </summary>
        public static LedgerBook TestData4()
        {
            var book = new LedgerBook(new ReconciliationBuilder(new FakeLogger()))
            {
                Name       = "Test Data 4 Book",
                Modified   = new DateTime(2013, 12, 16),
                StorageKey = "C:\\Folder\\book1.xml"
            };

            var list = new List <LedgerEntryLine>
            {
                CreateLine(new DateTime(2013, 06, 15), new[] { new BankBalance(StatementModelTestData.ChequeAccount, 2500) }, "Lorem ipsum").SetEntriesForTesting(
                    new List
                    <LedgerEntry>
                {
                    CreateLedgerEntry(HairLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 55M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -45M, Narrative = "Hair cut"
                        }
                    }),
                    CreateLedgerEntry(PowerLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 140M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -123.56M, Narrative = "Power bill"
                        }
                    }),
                    CreateLedgerEntry(PhoneLedger).SetTransactionsForTesting(
                        new List <LedgerTransaction>
                    {
                        new BudgetCreditLedgerTransaction {
                            Amount = 95M, Narrative = "Budgeted amount"
                        },
                        new CreditLedgerTransaction {
                            Amount = -86.43M, Narrative = "Pay phones"
                        }
                    })
                })
            };

            LedgerEntry previousHairEntry  = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.HairBucketCode);
            LedgerEntry previousPowerEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PowerBucketCode);
            LedgerEntry previousPhoneEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PhoneBucketCode);

            list.Add(
                CreateLine(new DateTime(2013, 07, 15), new[] { new BankBalance(StatementModelTestData.ChequeAccount, 3700) }, "dolor amet set").SetEntriesForTesting(
                    new List
                    <LedgerEntry>
            {
                CreateLedgerEntry(HairLedger, previousHairEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 55M, Narrative = "Budgeted amount"
                    }
                }),
                CreateLedgerEntry(PowerLedger, previousPowerEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 140M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -145.56M, Narrative = "Power bill"
                    }
                }),
                CreateLedgerEntry(PhoneLedger, previousPhoneEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 95M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -66.43M, Narrative = "Pay phones"
                    }
                })
            }));

            previousHairEntry  = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.HairBucketCode);
            previousPowerEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PowerBucketCode);
            previousPhoneEntry = list.Last().Entries.Single(e => e.LedgerBucket.BudgetBucket.Code == TestDataConstants.PhoneBucketCode);

            LedgerEntryLine line = CreateLine(
                new DateTime(2013, 08, 15),
                new[] { new BankBalance(StatementModelTestData.ChequeAccount, 2750), new BankBalance(StatementModelTestData.SavingsAccount, 200) },
                "The quick brown fox jumped over the lazy dog").SetEntriesForTesting(
                new List <LedgerEntry>
            {
                CreateLedgerEntry(HairLedger, previousHairEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 55M, Narrative = "Budgeted amount"
                    }
                }),
                CreateLedgerEntry(PowerLedger, previousPowerEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 140M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -98.56M, Narrative = "Power bill"
                    }
                }),
                CreateLedgerEntry(PhoneLedger, previousPhoneEntry.Balance).SetTransactionsForTesting(
                    new List <LedgerTransaction>
                {
                    new BudgetCreditLedgerTransaction {
                        Amount = 95M, Narrative = "Budgeted amount"
                    },
                    new CreditLedgerTransaction {
                        Amount = -67.43M, Narrative = "Pay phones"
                    }
                })
            });

            line.BalanceAdjustment(-550, "Credit card payment yet to go out.", StatementModelTestData.ChequeAccount);
            list.Add(line);

            book.SetReconciliations(list);

            Finalise(book);
            return(book);
        }
        /// <summary>
        ///     This is effectively stage 2 of the Reconciliation process.
        ///     Called by <see cref="ReconciliationBuilder.CreateNewMonthlyReconciliation" />. It builds the contents of the new
        ///     ledger line based on budget and statement input.
        /// </summary>
        /// <param name="budget">The current applicable budget</param>
        /// <param name="statement">The current period statement.</param>
        /// <param name="startDateIncl">
        ///     The date of the previous ledger line. This is used to include transactions from the
        ///     Statement starting from this date and including this date.
        /// </param>
        private void AddNew(
            BudgetModel budget,
            StatementModel statement,
            DateTime startDateIncl)
        {
            if (!this.newReconciliationLine.IsNew)
            {
                throw new InvalidOperationException("Cannot add a new entry to an existing Ledger Line, only new Ledger Lines can have new entries added.");
            }

            var reconciliationDate = this.newReconciliationLine.Date;
            // Date filter must include the start date, which goes back to and includes the previous ledger date up to the date of this ledger line, but excludes this ledger date.
            // For example if this is a reconciliation for the 20/Feb then the start date is 20/Jan and the finish date is 20/Feb. So transactions pulled from statement are between
            // 20/Jan (inclusive) and 19/Feb (inclusive) but not including anything for the 20th of Feb.
            List <Transaction> filteredStatementTransactions = statement?.AllTransactions.Where(t => t.Date >= startDateIncl && t.Date < reconciliationDate).ToList() ?? new List <Transaction>();

            IEnumerable <LedgerEntry> previousLedgerBalances = CompileLedgersAndBalances(LedgerBook);

            var entries = new List <LedgerEntry>();

            foreach (var previousLedgerEntry in previousLedgerBalances)
            {
                LedgerBucket ledgerBucket;
                var          openingBalance = previousLedgerEntry.Balance;
                var          currentLedger  = LedgerBook.Ledgers.Single(l => l.BudgetBucket == previousLedgerEntry.LedgerBucket.BudgetBucket);
                if (previousLedgerEntry.LedgerBucket.StoredInAccount != currentLedger.StoredInAccount)
                {
                    // Check to see if a ledger has been moved into a new default account since last reconciliation.
                    ledgerBucket = currentLedger;
                }
                else
                {
                    ledgerBucket = previousLedgerEntry.LedgerBucket;
                }

                var newEntry = new LedgerEntry(true)
                {
                    Balance = openingBalance, LedgerBucket = ledgerBucket
                };

                // Start by adding the budgeted amount to a list of transactions.
                List <LedgerTransaction> transactions = IncludeBudgetedAmount(budget, ledgerBucket, reconciliationDate);

                // Append all other transactions for this bucket, if any, to the transaction list.
                transactions.AddRange(IncludeStatementTransactions(newEntry, filteredStatementTransactions));

                AutoMatchTransactionsAlreadyInPreviousPeriod(filteredStatementTransactions, previousLedgerEntry, transactions);
                newEntry.SetTransactionsForReconciliation(transactions);

                entries.Add(newEntry);
            }

            this.newReconciliationLine.SetNewLedgerEntries(entries);

            foreach (var behaviour in ReconciliationBehaviourFactory.ListAllBehaviours())
            {
                behaviour.Initialise(filteredStatementTransactions,
                                     this.newReconciliationLine,
                                     this.toDoList,
                                     this.logger,
                                     statement);
                behaviour.ApplyBehaviour();
            }

            // At this point each ledger balance is still set to the opening balance, it hasn't ben updated yet. This should always be done last.
            foreach (var ledger in this.newReconciliationLine.Entries)
            {
                ledger.Balance += ledger.Transactions.Sum(t => t.Amount);
            }
        }
Beispiel #28
0
 public bool Update(LedgerEntry readLedgerEntry)
 {
     return UpdateItem(readLedgerEntry.Index(), readLedgerEntry);
 }
 public Task AddLedgerEntryAsync(LedgerEntry ledgerEntry)
 {
     return(Task.CompletedTask);
 }
Beispiel #30
0
        private int?GetPreviousLedgerEntryIndex(LedgerEntry ledgerEntry)
        {
            var previousLedgerEntry = GetPreviousLedgerEntry(ledgerEntry);

            return(previousLedgerEntry == null ? null : (int?)LedgerEntries.IndexOf(previousLedgerEntry));
        }
 public static void Encode(XdrDataOutputStream stream, LedgerEntry encodedLedgerEntry)
 {
     Uint32.Encode(stream, encodedLedgerEntry.LastModifiedLedgerSeq);
     LedgerEntryData.Encode(stream, encodedLedgerEntry.Data);
     LedgerEntryExt.Encode(stream, encodedLedgerEntry.Ext);
 }
Beispiel #32
0
 public static LedgerEntryTypes.General CreateAndAddToGroup(ApplicationDbContext db, LedgerEntry GroupAction, string SubmitterUserId, string Description)
 {
     return((LedgerEntryTypes.General)CreateAndAddToGroup(db, GroupAction, SubmitterUserId, LEDGER_ACTION_TYPE.General, Description));
 }
Beispiel #33
0
 partial void ToDtoPostprocessing(ref LedgerEntryDto dto, LedgerEntry model)
 {
     dto.BucketCode      = model.LedgerBucket.BudgetBucket.Code;
     dto.StoredInAccount = model.LedgerBucket.StoredInAccount.Name;
 }
        /// <summary>
        ///     Match statement transaction with special automatching references to Ledger transactions.
        ///     Configures hyperlinking ids and marks then as matched. Also checks to ensure they are matched for data integrity.
        /// </summary>
        private void AutoMatchTransactionsAlreadyInPreviousPeriod(
            List <Transaction> transactions,
            LedgerEntry previousLedgerEntry,
            List <LedgerTransaction> newLedgerTransactions)
        {
            List <LedgerTransaction> ledgerAutoMatchTransactions = FindAutoMatchingTransactions(previousLedgerEntry).ToList();
            var checkMatchedTxns = new List <LedgerTransaction>();
            var checkMatchCount  = 0;

            foreach (var lastMonthLedgerTransaction in ledgerAutoMatchTransactions)
            {
                this.logger.LogInfo(l => l.Format("Ledger Reconciliation - AutoMatching - Found {0} {1} ledger transaction that require matching.", ledgerAutoMatchTransactions.Count(),
                                                  previousLedgerEntry.LedgerBucket.BudgetBucket.Code));

                var ledgerTxn = lastMonthLedgerTransaction;
                foreach (var matchingStatementTransaction in TransactionsToAutoMatch(transactions, lastMonthLedgerTransaction.AutoMatchingReference))
                {
                    this.logger.LogInfo(l => l.Format("Ledger Reconciliation - AutoMatching - Matched {0} ==> {1}", ledgerTxn, matchingStatementTransaction));

                    ledgerTxn.Id = matchingStatementTransaction.Id; // Allows user to click and link back to statement transaction.

                    // Don't automatch if it has already been auto-matched
                    if (!ledgerTxn.AutoMatchingReference.StartsWith(MatchedPrefix, StringComparison.Ordinal))
                    {
                        // There will be two statement transactions but only one ledger transaction to match to.
                        checkMatchCount++;
                        ledgerTxn.AutoMatchingReference = $"{MatchedPrefix}{ledgerTxn.AutoMatchingReference}";
                        checkMatchedTxns.Add(ledgerTxn);
                    }

                    // Remove automatched transactions from the new recon
                    var duplicateTransaction = newLedgerTransactions.FirstOrDefault(t => t.Id == matchingStatementTransaction.Id);
                    if (duplicateTransaction != null)
                    {
                        this.logger.LogInfo(l => l.Format("Ledger Reconciliation - Removing Duplicate Ledger transaction after auto-matching: {0}", duplicateTransaction));

                        newLedgerTransactions.Remove(duplicateTransaction);
                    }
                }
            }

            // Check for any orphaned transactions that should have been auto-matched. This is for data integrity, it shouldn't happen.
            if (ledgerAutoMatchTransactions.Any() && ledgerAutoMatchTransactions.Count() != checkMatchCount)
            {
                this.logger.LogWarning(
                    l =>
                    l.Format(
                        "Ledger Reconciliation - WARNING {0} ledger transactions appear to be waiting to be automatched, but no statement transactions were found. {1}",
                        ledgerAutoMatchTransactions.Count(),
                        ledgerAutoMatchTransactions.First().AutoMatchingReference));
                IEnumerable <LedgerTransaction> unmatchedTxns = ledgerAutoMatchTransactions.Except(checkMatchedTxns);
                foreach (var txn in unmatchedTxns)
                {
                    this.toDoList.Add(
                        new ToDoTask(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                "WARNING: Missing auto-match transaction. Transfer {0:C} with reference {1} Dated {2:d} to {3}. See log for more details.",
                                txn.Amount,
                                txn.AutoMatchingReference,
                                this.newReconciliationLine.Date.AddDays(-1),
                                previousLedgerEntry.LedgerBucket.StoredInAccount),
                            true));
                }
            }
        }
Beispiel #35
0
 partial void ToModelPostprocessing(LedgerEntryDto dto, ref LedgerEntry model)
 {
     model.LedgerBucket = this.bucketFactory.Build(dto.BucketCode, dto.StoredInAccount);
 }
Beispiel #36
0
 public void AddSLE(LedgerEntry sle)
 {
     this.AddLeaf(sle.Index, new LedgerEntryLeafNode(sle));
 }
Beispiel #37
0
 private static string PrintEntry(IFormatProvider culture, LedgerEntry entry)
 {
     return(Date(culture, entry.Date)
            + " | " + string.Format("{0,-25}", Description(entry.Desc))
            + " | " + string.Format("{0,13}", Change(culture, entry.Chg)));
 }