In The craft
A General Ledger: A Simple C# Implementation
If you don’t have a basic understanding of general ledgers and double-entry bookkeeping read my post explaining the basics of these concepts.
Over the years I’ve worked on a systems with financial transactions. To have integrity with financial transactions using a general ledger is a must. If not, you can’t account for revenue and accounts payable. Believe me you, when your client wants detailed reports on their cash flow you better be able to generate it. Not to mention any legal issues you might encounter.
Early in my career, I had a discussion with a C-Level executive, I explained the importance of a general ledger. I was getting push back because it pushed out the timeline a bit to implement the general ledger. Eventually we won out and implemented a ledger and thankfully so. Just as we predicted the requests for reports started rolling in.
A basic schema for a general ledger.
CREATE TABLE [Accounting].[GeneralLedger] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Account_Id] INT NOT NULL,
[Debit] DECIMAL (19, 4) NULL,
[Credit] DECIMAL (19, 4) NULL,
[Transaction_Id] INT NOT NULL,
[EntryDateTime] DATETIME NOT NULL,
);
The C# class.
public class GeneralLedger
{
public int Id { get; set; }
public Account Account { get; set; }
public decimal Debit { get; set; }
public decimal Credit { get; set; }
public Transaction Transaction { get; set; }
public DateTime EntryDateTime { get; set; }
}
In my system I track all the transactions in and out of the system. For example, if a customer pays an invoice. I track the total payment in the general ledger. The credit account is called “Revenue” and the debit account is my company. Remember for each financial transaction two records are entered into the general ledger: a credit and a debit.
In my system I wanted higher fidelity so I added Transaction to the ledger. The transaction tracks the details of the entry. Only the transaction total is recorded in the general ledger. The transaction details(taxes, per item costs, etc) tells the story of how we arrived at the total.
Lets look at some data. Find an account with some credits and debits. Sum all the debit rows and sum all the credit rows. Subtract the debit from the credits. If the number is positive, the account finished in the black (has a profit), if it’s negative, then the account finished in the red (has a loss).
Your CEO wants to know how much money a client spent with your company. No problem. Again just sum the debits and credits and subtract them from each other for the clients account.
I hope this has helped you understand the power of the ledger and why it’s important when dealing with financial transactions.