Relational Data Model for Double-Entry Accounting

Question: Assume there is a bank, a large shop, etc, that wants the accounting to be done correctly, for both internal accounts, and keeping track of customer accounts.  Rather than implementing that which satisfies the current simple and narrow requirement, which would a 'home brew': those turn out to be a temporary crutch for the current simple requirement, and difficult or impossible to extend when new requirements come it.
As I understand it, Double-Entry Accounting is a method that is well-established, and serves all Accounting and Audit requirements, including those that are not contemplated at the current moment.  If that is implemented, it would:

eliminate the incremental enhancements that would occur over time, and the expense,
there will not be a need for future enhancement.

I have studied this Answer to another question: Derived account balance vs stored account balance for a simple bank account?, it provides good information, for internal Accounts.  A data model is required, so that one can understand the entities; their interaction; their relations, and @PerformanceDBA has given that.  This model is taken from that Answer:

Whereas that is satisfactory for simple internal accounts, I need to see a data model that provides the full Double-Entry Accounting method.
The articles are need to be added are Journal; internal vs external Transactions; etc..
Ideally I would like to see what those double entry rows look like in database terms, what the whole process will look like in SQL, which entities are affected in each case, etc.  Cases like:

A Client deposits cash to his account
The Bank charges fees once a month to all Clients accounts (sample batch job),
A Client does some operation over the counter, and the Bank charges a fee (cash withdrawal + withdrawal fee),
Mary sends some money from her account, to John's account, which is in the same bank

Let's just call it System instead of Bank, Bank may be  too complex to model, and let the question be about imaginary system which operates with accounts and assets. Customers perform a set of operations with system (deposits, withdrawals, fee for latter, batch fees), and with each other (transfer).
Comment: This guy wanted to leave a comment but didn't have enough rep: https://stackoverflow.com/q/59521817/6456163
Comment: Great edit, thank you. There was `Batch` mentioned, I don't know if it makes sense to bring it back, perhaps it only exist in my current understanding that it must be a special table.
Comment: 1) `Batch` does not need a data table for anything regarding the data content that the batch is processing.  2) Separately, one may have a `Batch` table for the purpose of administering the batch queue; controlling restart points; parallel processing (Threads); etc.  All of which I have.  But that is an Utility table, with no data content from the database proper.  3) Check my Answer to see if the batch issue is covered to your satisfaction.  If not, please comment, and I will edit the Answer.
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/204693/discussion-on-question-by-alex-relational-model-for-double-entry-accounting).
Answer: A. Preliminary
Your Approach
First and foremost, I must commend your attitude. It is rare to find someone who not only thinks and works from a solid grounding, and who wishes to understand and implement a Double-Entry Accounting system, instead of:

either not implementing DEA, thus suffering multiple re-writes, and pain at each increment, each new requirement,

or implementing DEA, but re-inventing the wheel from scratch, by figuring it out for oneself, and suffering the pain at each exposure of error, and the demanded bug fixes, a sequence that never ends.

To avoid all that, and to seek the standard Method, is highly commended.
Further, you want that in the form of a Relational data model, you are not enslaved by the Date; Darwen; Fagin; et al views that prescribes a Record ID based Record Filing Systems, that cripples both the modelling exercise and the resulting "database".  These days, some people are obsessed with primitive RFS and suppress Dr E F Codd's Relational Model.
1. Approach for the Answer
If you do not mind, I will explain things from the top, in logical order, so that I can avoid repeats, rather than just answering your particular requests.  I apologise if you have complete knowledge of any of these points.
Obstacle

Ideally I would like to see what those double entry rows look like in database terms

That is an obstacle to the proper approach that is required for modelling or defining anything.

In the same way that stamping an ID field on every file, and making it the "key", cripples the modelling exercise, because it prevents analysis of the data (what the thing that the data represents actually is), expecting two rows for a Credit/Debit pair at the start will cripple the understanding of what the thing is; what the accounting actions are; what effect those actions have; and most important, how the data will be modelled.  Particularly when one is learning.

Aristotle teaches us that:

the least initial deviation from the truth is multiplied later a thousandfold ...
a principle is great, rather in power, than in extent; hence that which was small [mistake] at the start turns out a giant [mistake] at the end.

Paraphrased as, a small mistake at the beginning (eg. principles; definitions) turns out to be a large mistake at the end.
Therefore the intellectual requirement, the first thing, is to clear your mind regarding what it will be at the end of the modelling exercise.  Of course, that is also required when one is learning what it is, in accounting terms.
2. Scope for the Answer

Assume there is a bank, a large shop, etc, that wants the accounting to be done correctly, for both internal accounts, and keeping track of customer accounts.
Let's just call it System instead of Bank, Bank may be too complex to model ...
Customers perform a set of operations with system (deposits, withdrawals, fee for latter, batch fees), and with each other (transfer).

To be clear, I have determined the scope to be as follows.  Please correct me if it is not:

Not a small business with a General Ledger only, with no Customer Accounts
But a small community Bank, with no branches (the head office is the branch)
You want both the internal Accounts, which consists of:
a simple General Ledger,
as well as external Accounts, one for each Customer
The best concept that I have in mind is a small community Bank, or a business that operates like one.  An agricultural cooperative, where each farmer has an Account that he purchases against, and is billed and paid monthly, and the cooperative operates like a small bank, with a full General Ledger, and offers some simple bank facilities.
A single Casino (not a chain) has the same requirement.
Not a large Bank with multiple branches; various financial products; etc.
Instead of System or Bank, I will call it House.  The relevance of that will be clear later.

Anyone seeking the Double-Entry method for just the Ledger, without the external Customer Account, can glean that easily from this Answer.
In the same vein, the data model given here is easy to expand, the Ledger can be larger than the simple one given.

B. Solution
1. Double-Entry Accounting
1.1. Concept
To know what that it is by name; that it has great value; that it is better than a roll-your-own system, is one thing, knowing what it is deeply enough to implement it, is another.

First, one needs to have a decent understanding of a General Ledger, and general Accounting principles.

Second, understand the concept that money represents value.  Value cannot be created or destroyed, it can only be moved.  From one bucket in the accounts to another bucket, otherwise known as Debit (the from-account) and Credit (the to-account).

While it is true that the SUM( all Credits ) = SUM( all Debits ), and one can obtain such a report from a DEA system, that is not the understanding required for implementation, that is just one end result.  There is more to it.

While it is true that every transaction consists of a pair: one Credit and one Debit for the same amount, there is more to that as well.

Each leg of the pair; the Credit and Debit, is not in the same Account or Ledger, they are in different Accounts, or Ledgers, or Accounts-and-Ledgers.

The SUM( all Credits ) is not simple, because they are in those different places (sets).  They are not in two rows in the same table (they could be, more later).  Likewise, the SUM( all Debits ).

Thus each of the two SUM()s cover quite different sets (Relational Sets), and have to be obtained first, before the two SUM()s can be compared.

1.2. Understanding Double-Entry Accounting
Before attempting a DEA implementation, we need to understand the thing that we are implementing, properly.  I advise the following:

You are right, the first principle is to hold the perspective of the Credit/Debit Pair, when dealing with anything in the books, the General Ledger; the Customer Accounts; the bank Accounts; etc.

This is the overarching mindset to hold, separate to whatever needs to be done in this or that Account or Ledger.

I have positioned it at the top; left, in the data model, such that the subordination of all articles to it is rendered visually.

The purpose or goal of a Double-Entry Accounting system is:

Eliminate (not just reduce) what is known as:

"lost" money

"lost" Transactions (one or the other side of the Credit/Debit pair)

and the time wasted in chasing it down.

Not only can money be found easily, but exactly what happened to it, and where it is now, can be determined quickly.

Full Audit functionality
It is not good enough to keep good Accounts, it is imperative for a business that accounts for other people's money, to be readily audit-able.  That is, any accountant or auditor must be able to examine the books without let or hindrance.

This is why the first thing an outsider, eg. an auditor, wants to know is, does the SUM( all Credits ) = SUM( all Debits ).  This also explains why the DEA concept is above any Accounts or accounting system that the company may be keeping.

The great benefit, although tertiary, is that the everyday or month end tasks, such as a Trial Balance or closing the books, can be closed easily and quickly.  All reports; Statements; Balance Sheets; etc, can be obtained simply (and with a single SELECT if the database is Relation).

Then ready the Wikipedia entry for Double-Entry Bookkeeping.

The internet has plenty of misleading information, and Wikipedia is particularly awful that is forever changing (truth does not change, falsity changes with the weather), but sorry, that is all we have.  Use it only to obtain an overview, it has no structural or logical descriptions, despite its length.  Follow the links for better info.

I do not entirely agree with the terminology in the Wikipedia article.  Nevertheless, in order to avoid avoidable confusion, I will use those terms.

There are tutorials available on the web, some better than others.  These are recommended for anyone who is implementing a proper Accounting system, with or without DEA.  That takes time, it is not relevant to an answer such as this, and that is why I have linked the Wikipedia article.

2. Business Transaction

Ideally I would like to see what those double entry rows looks like in database terms, what the whole process will look like in SQL, which entities are affected in each case, etc.

Ok.  Let's go with the Transactions first, then build up to understanding the data model that supports them, then inspect the example rows.  Any other order would be counter-productive, and cause unnecessary back-and-forth.
Your numbering.  Green is House in the General Ledger, blue is external Customer Account, black is neutral.

This is the first increment of Treatment, how a thing is treated, in different scenarios (your concern, and your request for specific examples, is precisely correct).

Credit/Debit Pairs
This is the first principle of DEA, understand the pair, as the pair, and nothing but the pair.

Do not worry about how the General Ledger or the Account is set up, or what the data model looks like.  Think in terms of an accountant (what has to be done in the books), not in terms of a developer (what has to be done in the system).
Notice that the each leg of the pair is in the one set (the Ledger), or in two sets (one leg in the Ledger, the other leg in Account).  There are no pairs in which both legs are in Account.

Because DEA is implemented, each Business Transaction (as distinct from a database Transaction), consists of two actions, one for each Credit/Debit leg.  The two actions are two entries in a paper-based account book.

A Client deposits cash to his account

During the DayEnd procedure, among other tasks, all cash is accounted for and checked.  The day is closed.  All cash sitting in HouseCash that is beyond whatever the bank deems necessary for everyday cash Transactions, is moved to HouseReserve.

The Bank charges fees once a month to all Clients accounts (sample batch job)

This charges each Account with the Fee
Fee is dependent on AccountType_Ext
This is the simple case.  If the Fee is dependent on something else, such as the number of transactions in the Account; or the CurrentBalance being below or above some limit; etc, that is not shown.  I am sure you can figure that out.

A Client does some operation over the counter, and the Bank charges a fee (cash withdrawal + withdrawal fee),

Simple Transactions do not incur fees, and Deposit/Withdrawal has already been given.  Let's examine a business Transaction that actually attracts a fee.

Mary sends $500 USD to her son Fred, who is travelling overseas looking for whales to save, and has run out of money.  The bank charges $30 for an Overseas Bank Transfer.  Fred can collect the funds (in local currency equivalent of $500 USD) at any partner bank branch.
To actually transfer the money to the foreign bank, the House has to interact with a local big bank that provides international settlement and currency exchange services.  That is not relevant to us, and not shown.  In any case, all those types of Interbank transactions are batched and dealt with once per day, not once per AccountTransaction.
In this simple DEA system, the House does not have currency accounts in the Ledger.  That is easy enough to implement.

Mary sends some money from her account, to John's account, which is in the same bank

The money is currently in Mary's account (deposited on a day prior to today), that is why it is in HouseReserve, not HouseCash
The money is moved from HouseReserve into HouseCash because John may come into the bank today and withdraw it.
As described in example [1.3] above, at the DayEnd procedure, any money sitting in HouseCash in all Accounts will be moved to HouseReserve.  Not shown.

3. Relational Data Model • Initial
Now let's see what the data modeller has done, to support the accountant's needs, the business Transactions.

This is of course, the second increment of Treatment, what the modeller has understood the real world business Transactions to be, expressed in Relational terms (FOPC; RM; Logic; Normalisation)

This is not the simplest data model that is required to satisfy the restated scope.

There are simpler models (more later), but they have problems that this one does not have, problems that are desirable, if not imperative, to avoid.

The image is too large for in-line viewing.  Open the image in a new tab, to appreciate it in full size.

3.1. Notation

All my data models are rendered in IDEF1X, the Standard for modelling Relational databases since 1993.

My IDEF1X Introduction is essential reading for those who are new to the Relational Model, or its modelling method.  Note that IDEF1X models are rich in detail and precision, showing all required details, whereas home-grown models, being unaware of the imperatives of the Standard, have far less definition.  Which means, the notation needs to be fully understood.

3.2. Content

The main difference between a genuine Relational data model produced by someone else, and mine, is:
a business Transaction (always two actions; two legs, one per Credit/Debit) is affected by a single row with two sides, one per Credit/Debit,
in AccountTransaction or LedgerTransaction.

Most modellers will model two rows for the Credit/Debit pair, one for each leg or side (hey, one leg is a Credit, and the other leg is a Debit, if I Normalise that, I get two rows).

Wrong.  If I tell you that Fred is Sally's father, you know, from that single Fact, that Sally is Fred's daughter.

A FOREIGN KEY needs to be declared just once, not once for each side.

Likewise, the Credit/Debit pair is a single Business Transaction,
a single Atomic article, that can be perceived from either Side, like two sides of one coin.  Modelled as such.

All manner of preventable bugs are prevented, the search for the "missing" leg is eliminated.

Even for those with sub-standard OLTP code, which causes quite preventable concurrency problems, if this method is implemented, this is one article wherein those problems will not arise.

Further, the number of rows in the %Transaction tables is halved.

I have arranged the articles such that the
External Account
Internal Ledger and LedgerTransaction
Internal-External AccountTransaction
are clear.

Along with a nugget of definition from the Wikipedia entry.

Having familiarised yourself with the DEA Credit/Debit pairs, now study the Treatment of the pair.  Notice that the Treatment is different, it is based on a number of criteria (three account types; six Ledger types; etc), which in turn is based on the complexity of the General Ledger.

This Ledger is simple, with Asset/Liability accounts only.  Of course, you are free to expand that.

The eagle-eyed will notice that AccountStatement.ClosingBalance and LedgerStatement.ClosingBalance can actually be derived, and thus (on the face of it), should not be stored.  However, these are published figures, eg. the Monthly Bank Statement for each Account, and thus subject to Audit, and therefore it must be stored.

For a full treatment of that issue, including considerations; definition; treatment, refer to this Q & A:

Derived account balance vs stored account balance for a simple bank account?

3.3. Summary
In closing this section, we should have reached this understanding:

The overarching principle of DEA, the Credit/Debit pairs, purely intellectual

The typical business Transactions, always a Credit/Debit pair, two legs, two entries in the accounting books

A deeper understanding of the Treatment of said Transactions

The environment that the House (small bank; cooperative; casino) manages (internal Ledger and external customer Account)

A first look at a data model that is proposed to handle all that.

4. Relational Data Model • Full
Here it is again, with a full set of sample data.

Re the Primary Keys:

Note that LedgerNo and AccountNo are not surrogates, they have meaning for the organisation, in ordering and structuring the Ledger, etc.  They are stable numbers, not an AUTOINCREMENT or IDENTITY or anything of the sort.

The Primary Keys for LedgerTransaction and AccountTransaction are pure, composite Relational Keys.

It is not a Transaction Number of some kind that is beloved of paper-based accountants.

It is not a crippling Record ID either.

The Alternate Keys are more meaningful to humans, hence I have used them in the examples (Business Transactions, above [2], and below [5]).  This Answer is already layered, it would be a nightmare trying to relate hundreds of 1's, 2's and 3's to each other.

If we wish to understand what something means, we need to hold onto the meaning that exists in the thing, rather than excising the meaning by giving it a number.

In the example data, the Primary Keys are bold.

5. Business Transaction with Row

Ideally I would like to see what those double entry rows looks like in database terms, what the whole process will look like in SQL, which entities are affected in each case, etc.

Now that we understand the Business Transactions, and the data model that services the requirement, we can examine the Business Transactions along with affected rows.

Each Business Transaction, in DEA terms, has two legs, two entries in the paper-based account books, for each of the Credit/Debit pair,
is yet a single Business Transaction, and now:
it is affected by a single row with two sides, for each of the Credit/Debit pair.

This is the third increment in understanding Treatment: the business Transactions; data model to implement them; and now, the affected rows

The example database rows are prefixed with the table name in short form.
Plus means INSERT
Minus means DELETE
Equal means UPDATE.

A Client deposits cash to his account

The Bank charges fees once a month to all Clients accounts (sample batch job)

This, too, is a batch job, just one task in the MonthEnd procedure.
Notice the date is the first day of the month.

A Client does some operation over the counter, and the Bank charges a fee (cash withdrawal + withdrawal fee),

To be clear, that is three Business Transactions; two entries each, one for each side of the Credit/Debit pair; affected by one database row each.

Mary sends some money from her account, to John's account, which is in the same bank

6. SQL Code
There are usually several ways to skin a cat (code), but very few if the cat is alive (code for a high concurrency system).

The Relational Model is founded on First Order Predicate Calculus (aka First Order Logic), all definitions (DDL) and thus all queries (DML) are entirely Logical.

A data model that conforms to that understanding, is therefore entirely Logical.

The queries against such a data model are dead easy: Logical and straight-forward.  They have none of the convoluted code that is required for Record ID based filing systems.

Therefore, out of the several methods that are possible for the SQL code requests, I give the most direct and logical.

The code examples are that which is appropriate for SO, it is imperative that you trap and recover from errors; that you do not attempt anything that will fail (check the validity of the action before using a verb), and follow OLTP Standards for ACID Transactions, etc.  The example code given here are the relevant snippets only.

6.1. SQL View • Account Current Balance
Since this code segment gets used in many places, let's do the right thing and create a View.

Note that on genuine SQL platforms, source code is compiled and run when it is submitted, Stored Procs and Views are stored in their compiled form, thus eliminating the compilation on every execution.  Unlike the mickey mouse NONsql suites.

High-end commercial SQL platforms do a lot more, such as caching the Query Plans for Views, and the queries in Stored Procs.

CREATE VIEW Account_Current_V
    AS
SELECT  AccountNo,
    Date = DATEADD( DD, -1, GETDATE() ),     -- show /as of/ previous day
    ASS.ClosingBalance,                      -- 1st of this month
    TotalCredit = (
        SELECT SUM( Amount )
            FROM AccountTransaction  ATT
            WHERE ATT.AccountNo = ASS.AccountNo
                AND XactTypeCode_Ext IN ( "AC", "Dp" )
                -- >= 1st day of this month yy.mm.01  /AND <= current date/
                AND DateTime >= CONVERT( CHAR(6), GETDATE(), 2 ) + "01"
            ),
    TotalDebit = (
        SELECT SUM( Amount )
            FROM AccountTransaction ATT
            WHERE ATT.AccountNo = ASS.AccountNo
                AND XactTypeCode_Ext NOT IN ( "AC", "Dp" )
                AND DateTime >= CONVERT( CHAR(6), GETDATE(), 2 ) + "01"
                ),
    CurrentBalance = ClosingBalance +
        <TotalCredit> -   -- subquery above
        <TotalDebit>      -- subquery above
    FROM AccountStatement  ASS
                                             -- 1st day of this month
    WHERE ASS.Date = CONVERT( CHAR(6), GETDATE(), 2 ) + "01"

6.2. SQL Transaction • [1.2] Withdraw from [External] Account
A proc for another DEA business Transaction.
CREATE PROC Account_Withdraw_tr (
    @AccountNo,
    @Amount
    ) AS
    IF EXISTS ( SELECT 1                       -- validate before verb
            FROM AccountCurrent_V
            WHERE AccountNo = @AccountNo
                AND CurrentBalance >= @Amount  -- withdrawal is possible
            )
        BEGIN
        SELECT @LedgerNo = LedgerNo
            FROM Ledger
            WHERE Name = "HouseCash"
        BEGIN TRAN
        INSERT AccountTransaction
            VALUES ( @LedgerNo, GETDATE(), "Cr", "Wd", @AccountNo, @Amount )
        COMMIT TRAN
        END

6.3. SQL Transaction • [1.1] Deposit to [External] Account
A proc, set up as an SQL Transaction, to execute a DEA business  Transaction.
CREATE PROC Account_Deposit_tr (
    @AccountNo,
    @Amount
    ) AS
    ... IF EXISTS, etc ...                   -- validate before verb
        BEGIN
        SELECT @LedgerNo ...
        BEGIN TRAN
        INSERT AccountTransaction
            VALUES ( @LedgerNo, GETDATE(), "Dr", "Dp", @AccountNo, @Amount )
        COMMIT TRAN
        END

6.4. SQL Transaction • [Internal] Ledger Account Transfer
A proc to add any business Transaction to LedgerAccount.  It is always:

one LedgerTransaction.LedgerNo, which is the Credit leg
one LedgerTransaction.LedgerNo_Dr, which is the Debit leg.
given by the caller.

CREATE PROC Ledger_Xact_tr (
    @LedgerNo,    -- Credit Ledger Account
    @LedgerNo_Dr, -- Debit  Ledger Account
    @Amount
    ) AS
    ... IF EXISTS, etc ...
        BEGIN
        SELECT @LedgerNo ...
        BEGIN TRAN
        INSERT LedgerTransaction
            VALUES ( @LedgerNo, GETDATE(), @LedgerNo_Dr, @Amount )
        COMMIT TRAN
        END

6.5. SQL Batch Task • Account Month End
This uses a View that is similar to [6.1 Account Current Balance], for any month (views are generic), with the values constrained to the month.  The caller selects the previous month.

This Answer now exceeds the SO limit, thus it is provided in a link Account_Month_V.

Just one Task, in a stored proc, to process the Month End for AccountStatement, which is executed as a batch job.  Again, just the essential code, the infrastructure needs to be added.
CREATE PROC Account_MonthEnd_btr ( ... )
    AS
... begin loop
... batch transaction control (eg. 500 rows per xact), etc ...
INSERT AccountStatement
    SELECT  ACT.AccountNo,
            CONVERT( CHAR(6), GETDATE(), 2 ) + "01",  -- 1st day THIS month
            AMV.ClosingBalance,                       -- for PREVIOUS month
            AMV.TotalCredit,
            AMV.TotalDebit
        FROM Account ACT
            JOIN Account_Month_V AMV               -- follow link for code
                ON ACT.AccountNo = AMV.AccountNo
                                                   -- 1st day PREVIOUS month
        WHERE AMV.OpeningDate = DATEADD( MM, -1, ACT.Date )
... end loop
... batch transaction control, etc ...

6.6. SQL Report • SUM( Credit ) vs SUM( Debit )

While it is true that the SUM( all Credits ) = SUM( all Debits ), and one can obtain such a report from a DEA system, that is not the understanding. There is more to it.

Hopefully, I have given the Method and details, and covered the understanding and the more, such that you can now write the required SELECT to produce the required report with ease.
Or perhaps the Monthly Statement for external Accounts, with a running total AccountBalance column.  Think: a Bank Statement.

One of the many, great efficiencies of a genuine Relational database is, any report can be serviced via a single SELECT command.

One PDF
Last but not least, it is desirable to have the Data Model; the example Transactions; the code snippets, all organised in a single PDF, in A3 (11x17 for my American friends).  For studying and annotation, print in A2 (17x22).
Comment: This answer is remarkable for two things (apart from its length): a) there are no citations to established practice/textbooks; b) the design of "a business Transaction is a single row" is not used by any ERP or accounting package, and for a good reason: it is inadequate. It's true that many transactions (especially in banking) consist of only two legs, debit and credit (equal and opposite). But in general there might be several legs -- typically with tax and/or charges, multiple distributions from one account to several others.
Comment: @Alex. 1) I did not state that (please do not follow the comments of those who are confused).  A Business Transaction is **two entries** in paper-based accounts; one entry for each Credit/Debit leg.  That is **affected by** a single row in my database. 2) `OTC_Transfer` is three business Transactions in the DEA sense, not one. As long as that is understood, it can be viewed as one *large* Business Transaction.  3) Nevertheless, I have added a few words of clarity throughout.  And one additional code segment.  Happy New Year.
Comment: @Edward My experience in banking is that complex transactions like you mention are common.  The important thing is that the Ledger is in balance not that each transaction has a matching credit and debit.  Payroll, Credit Card Bills,Settlements, all have large credits and debits that may offset to more than one ledger account.  Even Quick Books has a Split function for this same purpose.  If I deposit 1,000 (credit) and need to assign that to two invoices (debit) I don't create two credit transactions - it is one credit with two debits that balance.
Comment: @RexBloom  QuickBooks is not DEA.  QuickBooks cannot be used in Banking (which demands DEA).  You are performing a process (balancing) which is **manual, outside the system**, before entering your non-DEA 'transactions".  You don't need to do that under DEA, because the system is always balanced, because each Transaction is balanced.  No manual control required.  It is not "two credit transactions", it is two DEA Transactions, each a Credit **and** a Debit.
Comment: thank you @taffer, and well done for persisting. Typically a receivables-invoice transaction (entered to a Double-Entry Accounting system) uses at least three accounts _within the one transaction_: Customer (receivable total); tax (for transfer to the government); product sold (revenue for us). In American jurisdictions, we must account separately for Federal vs State vs City/local taxes -- so at least 5 account entries _within the one transaction_. Legally we must not represent the tax as 'our' revenue -- because we're merely collecting it on behalf of the government.
Comment: A single Debit (e.g. Payroll Expenses) can balance with two or more Credits (e.g. Salaries, Taxes).  There is not a one to one match between debit and credit entries but rather a constraint that all debits and credits balance.  I would model  LedgerTransaction with LedgerNo, Date, Type (Cr,Dr), and Amount.
Comment: @borN_free.  1) This is a template for the accounting side (the status is `accounted`).  Other statuses; etc (your list) are beyond Accounting, which may be deployed in a separate table, which is a queue, not submitted to Accounting.  2) The balance is **in** Accounting, the `Ledger` cluster.  There can be no balance *outside* accounting (if there is, it is fiction).  3) You could set up a `Suspense` account in `Account`, read up on it.
Comment: @Jon  1) Yes.  It is two real (physical) accounting transactions, each with different parties (one at the shop; one at the bank)  2) Who would the Invoice be sent to, your child ? Ok, one Invoice with two invoice line items.  3) Tax has to be managed correctly: open one external Account for each State, and one for Federal.  Any taxable item therefore has two accounting transactions. Then the Invoice Line item is easy.
Comment: So 'single-entry' bookkeeping is a naieve approach which simply won't scale. The claim "Further, the number of rows is halved." is bogus. (And as if anybody these days worries about saving disk space.) You need to index both the credit account and the debit account (and declare both with Foreign Key references to the 'Account master'). Seems to me Derek has made up this whole thing out of thin air. I'd be interested to know any example of a database design using 'single-entry' bookkeeping like this. Nobody should follow this example.
Comment: Oh, I should add: a typical requirement in a fully-featured account system is to hold 'pending' or 'registered not complete' transactions (sometimes called an 'inbox'). For example we've received an invoice for $100; we know the vendor's account (and we want to show the $100 against that vendor in an enquiry/balance owing); but we don't know our account coding for the line items/expenses (not all of them). So we post a 'one-sided' transaction, at a pending status to distinguish it from fully-posted/balancing transactions. 'Single-entry' bookkeeping is inadequate to meet this requirement.
Comment: Perhaps `a business Transaction is a single row` is a bit wrong since `OTC transfer` consist of 3 rows. I guess you mean `a doubly entry is a single row`, and there are many double-entries per business transaction.
Comment: @Alex. This Answer is of course complete for the purpose.  However, someone else asked for an expansion of the **Ledger**, which I provided [here](https://stackoverflow.com/a/59857806/484814).  You may be interested.
Comment: Does this model support complex ("compound") transactions that involve more than two accounts? E.g. "Purchase land for $15,000 by giving $5,000 cash and promising to pay the rest in 90 days". This would be a debit to Land for $15,000, credit to Cash for $5,000 and credit to Notes Payable for $10,000. If so, what would the DB rows look like?
Comment: @Edward  The question then remains in the Accounting sense, nothing to do with this model, which implements DEA.  There is no such thing as a "compound" or "complex" Transaction.  There is only a DEA Transaction or a non-DEA (mickey mouse) Transaction.  You can't do what you describe because it is anti-DEA.  You have to execute two DEA Transactions: Land/Cash $5,000 [DR, CR]; Land/NotePayable $10,000 [DR, CR] .. and a prior Transaction to get the Cash into the Cash Account.
Comment: Ok, thanks for clearing that up. I now understand where you're coming from. The textbook doesn't treat it that way - they do Land $15,000 [DR]; Notes Payable $10,000 [CR]; Cash $5,000 [CR]. Perhaps the "double" in DEA refers to there being balanced amounts in CR and DR sides, as opposed to a single DR, CR pair? In any event, you've answered my question - I see how your model works now.
Comment: The price of the software is not relevant.  In many systems there is someone you must answer to.  So you do need to figure that out and comply.  The Auditor of any system is the one who can say how that system must be designed.  Rest assured apart from that there is more than one way to balance a GL.  @PerformanceDBA says as much when they acknowledge above that there is a "main difference between models others design and mine".
Comment: @taffer.  1) I have not said that *DEA transactions allow more than two accounts*, thus I cannot defend it.  If it is more than two accounts, it is **not DEA**.  2) the cesspool article says *at least two accounts*, you need to chase them (not me) for a reference.  And a method.
Comment: There you go, now I've done your homework: *Dauber, Shim, Siegel (2012). The Complete CPA Reference. Wiley.* There is a compound entry on page 42, another one on page 46, and another one on page 111.
Comment: @PerformanceDBA Two questions that are not clarified here: 1) What if we have statuses for transactions (like scheduled, pending, rejected) - should we store them in accounting system and AccountTransaction table or should it be stored outside of accounting tool? 2) What if we need to calculate different balances based on different statuses (e.g. pending transaction influence available balance) - what is your recommendation here?
Comment: @だらんぎんじょん  1) I do not make a distinction between DE Accounting and DE Bookkeeping (Bookkeeping is merely the clerical side of Accounting).  2) For defns you need to identify and use an authority, the internet is a cesspool, there are very few. Try this defn **[What is the Double Entry System](https://www.accountingcoach.com/blog/what-is-the-double-entry-system)**.  3) Now for the rows. It is usually implemented as two rows, which demands proper ACID Transactions (no freeware), and becomes problematic when many references are required.
Comment: Ohh wow. Thanks a lot for such a detailed explanation.
Comment: @lowercase00 Thanks. I provided a Relational database Answer on SO, it is not an Accounting tutorial. For the Accounting side, feel free to use the Accounting authority of your choice ... obviously, I used a different authority, which is a bit less confused.
Comment: Please correct if I am wrong: The `[661] FeeRegular` (also `[662] FeeTransaction`) are `RR` (aka revenue), 'Cr' increases it, so we apply `Cr`. The '[990] HouseCash` is `AA` (Asset) so we have to increase it when deposit happens, we apply `Dr` because it increases `Asset`. But why it's an `Asset`? House owes that money to ext. account holders. I could treat [990] vice versa: it's `AL` and we decrease it by applying `Dr`. So what is it then?
Comment: @Alex. 1) Money represents value, it cannot be created or destroyed, only moved.  I do not use "increase/decrease" due to the implication.  A DEA `Cr` leg is credit, `Dr` leg is debit.  2) `661,662` is `RR` **√**. 3) `990` is `AL` Liability because that money needs to be paid to the Ext Acct holder on demand.  4) As detailed in § 5.1.1, a `Dp` deposit is an AccountTransaction that `Dr` debits `LedgerNo 990` (Income=`Dr`) and `Cr` credits external `AccountNo 123` (Giver=`Cr`).  In a naïve sense only, both are "increased", because money moved into the system.
Comment: @Edward. In the Accounting sense, that would be two ordinary Transactions, as per the examples, there is no need for your suggested "complex" Transaction.  The "cash" Account would be an External Account.  The whole point of DEA is to keep the Transactions simple and Double Entry.  Not quadruple or octuple entry.
Comment: @RexBloom.  No.  1) Read the notes in the DM.  LedgerTransaction is a single Transaction with two sides.  `LedgerNo` is the `CR` side, `LedgerNo_Dr` is the `DR` side.  2) If you do not understand that there **is** a 1-to-1 match of the Credit side vs the Debit side in every Accounting Transaction, you have missed the point of DEA completely.  Especially for payroll, when there is a discrepancy between the total Credit vs total Debit, in your model you would not find it.
Comment: @Edward. I found this helpful: https://github.com/apache/fineract.  If you dig into the fineract codebase you will see how they handle a GL account and Journal Entry (https://github.com/apache/fineract/blob/develop/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntry.java). They have some FK relationships I would not use but as we see in this thread to each his own and there is more than one way to create a balanced GL.
Comment: @Edward.  1) Re *there is more than one way to create a balanced GL*.  If you want your db to pass an IT Audit, or your Accounts to pass an Accounting Audit, no there is not.  There is one correct way, and all others are incorrect.  I did not write the standard, the CPA did, I merely comply.  2) You cannot compare freeware (which has no compliance with standards) against fee-paid software that complies with standards.  My fault is providing this Answer in a freeware platform, where it is perceived as just another freeware method.  Only the seeker can appreciate what he asked for.
Comment: @PerformanceDBA _There is no such thing as a "compound" or "complex" Transaction._ Do you have a reliable source for this claim? The Wikipedia article just says: _In double-entry bookkeeping, a transaction always affects **at least** two accounts_
Comment: @taffer  1) I say so, based on Standards & knowledge.  2) For the Accounting side, refer to any textbook for Chartered Practising Account (wiki is not a textbook).  3) For both the CPA side and the database side, anyone who reads & understands the Answer and the Data Model, will realise that anything other than two sides (two accounts, one account for each side) fails the definition of **D**ouble **E**ntry **A**ccounting.  4) I have already explained: if multiple purchases/sales are required, that should be in the External Account, with a single DEA AccountTransaction.
Comment: I have asked you several times to support your claims with sources, but you have been unable to do so. Instead, you just pointend to CPA textbooks. These, in turn, refute your interpretation that a journal entry in double-entry accounting can only contain two accounts. And no, double-entry accounting simply means that there must be a *debt* and a *credit* in each journal entry, which cancel each other out. It does not mean that only one account can be debited and only one account can be credited. It is called double-entry bookkeeping, not bookkeeping with at most two accounts.
Comment: @taffer. 1) You keep changing, but thank God, your understanding of DEA has progressed, finally we agree on the definition of DEA. You did not quote a CPA textbook, just a book.  2) What other implementations say they can do. is irrelevant, I have answered the original Q (not yours).  3) I have not changed my Answer, nothing is "refuted".  4) Now try and understand **Transactions** *within DEA*. Since you cannot read & understand the explicit transactions I have given in §5, & apply them to your "compound" or "composite" or 3 or 42 accounts, I cannot help you. Hint: [4] has **four Accounts**.
Comment: @taffer  *it is called double-entry bookkeeping, not bookkeeping with at most two accounts.*  Oh good.  Actually it is DEA not DEB.  Now in that DEA, which you say consists of two matching CR/DB entries, what is the no of accounts that can be referenced in those two entries (min; max) ???  If your answer is anything other than 2, you have totally missed the point of DEA, and you seek to pervert it, due to your misunderstanding of another context (the Transaction at the business & database level).  You are unable to separate the two contexts, you have them nicely confused.
Comment: @PerformanceDBA re "multi-line" transactions. Say I did a transaction where I bought a piggy bank for my child for $5 (which attracts sales tax of 10%) as well as paid a setup fee for a savings account of $10. Are you saying these would all be separate transactions? What if I wanted to issue an invoice/receipt to a customer that had both items on it, as well as the tax?
Comment: @PerformanceDBA thank you for this in-depth answer! A couple questions: 1) RE month end: Is your SQL meant to be run on the 1st of the month or the very end of the month? If the former, won't `Account_Current_V` return nothing since there's no statement for the new month yet? And, if the latter, wouldn't the date being inserted into `AccountStatement` be wrong (since the current balance calcs in the new month need a statement dated for that month)? 2) Can you explain more the purpose of the WHERE clause in the ACV/ASS join for the month end SQL? Thank you again!
Comment: @BtySgtMajor  1) You are most welcome.  2) I have added `Account_Month_V` to provide more explicit code, and changed `Account_MonthEnd_btr` to suit.  Month End procedure is now explicit.  Please check.
Comment: I had a first look and it looks good and makes total sense. Thank you one more time!
Comment: @Optimae  1) You can't pollute the DEA core, same as any standard, you can only comply xor fail.  2) What you are describing is Distribution or Allocation of some incoming (payable) or outgoing (receivable) that is one DEA transaction on the Ledger & Account structure, but multiple "business events" (your term, not mine) externally.  So, yes, you need a separate set of tables for that.  3) "Online" is a cesspool, the notion of referring to 2 or more things as 1 thing is hysterical, I cannot respond to that.  I wrote this answer for people who want the alternative; the standard; sanity.
Comment: @Arjun  Most resources especially on the web, are confused or incorrect, hence my Answer.  There are no resources for this level of implementation detail.  For DEA on Inventory movements, refer to the *Inventory model* in **[this Answer](https://stackoverflow.com/a/29713230/484814)**.
Comment: @PerformanceDBA First of all, thank you very much for the detailed and thoughtful answer. Database-wise, everything checks out and I am 100% sold on the answer on a technical/engineering level. What I'm absolutely perplexed about is the your definition of double entry accounting vs double entry bookkeeping, because I can't find a single reference anywhere that says that there should only be 1 debit and 1 credit per transaction. Everywhere else says a compound transaction is possible where in there are more than 2 rows in a given transaction. Could you provide any references to your definition?
Comment: 3) AFAIK, only I give a solution that uses one row, which is simple, unlimited references, and allows a freeware "sql" implementation.  4) If *everywhere else* has some value, please go there.  "Compound transactions" is insanity. I do not accept the cancer in the first place, and I do not need the medication is the second place, I simply reject insanity.  You should place whatever is "compound" is a separate cluster of tables: refer my comment to Optimae above re Distribution or Allocation.
Comment: @lowercase00  First, you have to dismiss your mindset re Cr-L & Dr-A.  Second, it is not about logic, it is the Accounting Method & terminology.  That $50 cash was not previously in the bank, it walked into the bank.  Therefore the Bank-Asset-Cash was Credited (cash increased).  Now we owe Alex $50.  That is Bank-Liability to Alex.  The other side of the DEA Transaction[ Bank-Asset-Cash-**Cr** ] is of course a Dr [ Bank-Liability-Account[ Alex ] **Dr** ].
Another way of stating that, from bank pov, is, Alex' account was debited $50, and the bank-cash was credited $50.
Comment: I've spent a month in full-time work, diving deep into @PerformanceDBA's answers and diagrams, as well as other related posts. I've also read numerous comments from others. There were times when I felt desperate, thinking that I was approaching everything the wrong way. But. Result was worth it. I now have the most robust and beautifully structured accounting system that operates solely by INSERT. There are no updates at all. This is what I call a high level of architecture. You have my utmost respect and gratitude. I want to express my sincere appreciation for sharing this knowledge with us.
Comment: @warmwhisky There is no LHS/RHS, I have not said "*ledger_no is on the left side and ledger_no_dr is on the right side*". **CR/DR** is explicitly named.
Comment: @PerformanceDBA Furthermore, it is important for me to mention that I possess a certain degree of inexperience when it comes to accounting concepts, although I do possess a notable level of proficiency in the realm of software architecture. I wish to convey my sincere appreciation for your explanations, which I have diligently and devotedly studied over the course of the past four weeks.
Comment: @PerformanceDBA I appreciate your clarification. It's reassuring to know that column order doesn't imply a strict left/right significance in our model. Your explanation about the flexibility and lack of a definitive "Left" or "Right" orientation is enlightening. Thanks for sharing your expertise.
Comment: @PerformanceDBA thanks for this very detailed and extensive answer. I totally agree that 1 row should represent 1 transaction for both sides of an entry if you want DEA. Would the ERD that you present here work for a small service business that does not have branches, and works with multiple clients (who would be in the account table and get invoiced)?

Would the data model change if the house became multi-branch?
Comment: @PerformanceDBA I learned a lot reading your example, while I was implementing a personal small ledger for myself. As I don't have an internal/external structure I do not have HouseCash etc. and my ledger is transfering between accounts.
But I have a question regarding your transactions: I assume in your transfer example you left out a transfer id because this is an example. Else I don't really get how you track money in a larger context where transaction with the same amount, may occur in the same time. Am I right with this assumption?
Comment: @Alex. For errors and specific questions, please leave comments here, so that there is a record with the Answer.  For discussion, the mods have opened a [chat](https://chat.stackoverflow.com/rooms/204693/discussion-on-question-by-alex-relational-model-for-double-entry-accounting), which has less restrictions than the comments.  They delete the comments.
Comment: @user806. 1) Yes.  In [5 [1.1] ] the customer `AccountNo` **`123`** `Alex` is Credited, the `Ledger[Account]No` **`990`** `HouseCash` is Debited.  The customer `Account` is external, `HouseCash` is external. 2) It is no problem at all to expand the simple Ledger I have given, by adding whatever `Ledger.Ledger[Account]Nos` to suit your needs.
Comment: @Alex.  I have upgraded all the graphics to show that further level of detail, and the PDF.  Note that it is not an error to move money from one Liability/Expense Ledger Account to another Liability/Expense, or to an Asset/Revenue.
Comment: Sounds reasonable, but it's kinda contradicts with `TransactionLedger_IsValid_ck
CHECK ( TransactionLedger_IsValid_fn( LedgerNo, LedgerNo_Dr ) = 1 )
-- check one is Asset and the other is Liability` from another answer?
Comment: Also, the comment from @AntC is interesting, usually in a more complex system you not only have `pending`,
but I would call it long running transactions with several states, where one large transaction affects many ledgers and ext. accounts,
where you can "rollback" (+ add new) all the multi ext. account/ledgers transactions when
state changes. You have to keep references to `Transactions`. (Here I am already referring to extended ledger model where `Transaction` is further normalised). It's obviously a material for another referred Q which is in progress ATM.
Comment: and **in** to another Account, via a **single** business transaction.  Therefore there never is one transaction that affects many Ext Accounts (or other Ledger Accounts): each is a separate business transaction.  There is no rollback, no need to keep "references".
Comment: I am guessing your point is to create a `LedgerAccount` per instance of such operation. So if one of dozens operations in a system is to `Sell a building` to a group of people (ext. accounts) there will be a `LedgerAccount` per each building. Building could be in process of construction and if something goes wrong you refund participants, pay penalty, etc. That trade could be cancelled one day due to some reason, you move funds back, penalty, etc. `Transaction` table accumulates track of transfers/buyers by current design.
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206862/discussion-between-performancedba-and-alex).
Comment: Thanks for your reply. My example was "in the accounting sense" from an accounting course - they refer to it as a 'complex' or 'compound' transaction.  I was just trying to match it up with your model. I'm still not sure how this looks in your model... which examples are you referring to?
Comment: @RexBloom Thanks, Rex, I think I understand that part, I just wanted to see the table entries in this model because it looks like each table row has the 2 parts in it (Dr and Cr) and assumes the amount for each is equal, so I'm just getting confused somewhere. How many rows would I need to insert and do I leave the Cr part null in some of them if it's multiple rows? A simple table image like the many in this answer would quickly clear it up.
Comment: in my model I do not store both ledgers together.  I always insert two records (minimum).  In your complex example you would insert 3.  I use a transaction and check that debits and credits balance before inserting.  With this I never insert data that unbalances the GL.
Comment: @RexBloom That makes sense, thanks. Do you have details of your model somewhere? Sounds like it's what I'm looking for.
Comment: @RexBloom  1) You get what you pay for.  Whether it is freeware "DBMS" or Accounting.  2) Auditor: ok, see if your CPA accredited Auditor approves your multi-transaction non-DEA method, that is supposed to balance the GL.
Comment: @taffer  1) I did not say that, I said *There is no such thing as a "compound" or "complex" Transaction. **There is only a DEA Transaction** or a non-DEA (mickey mouse) Transaction.*  If you read my Answer, you may find that it goes way beyond wiki, it clarifies *two sides* vs *two accounts*.  2) Wiki is a cesspool, guaranteed to confuse.  When I warn against it, SO censors my Answers.  I can't argue against a cesspool.
Comment: So, do DEA transactions allow more than two accounts or not and who says that?
Comment: *If it is more than two accounts, it is not DEA.* Who says so? I don't see any reliable source for your claim.
Comment: @BtySgtMajor  Great.  If your `Ledger` is a tree structure, you may be interested in [this answer](https://stackoverflow.com/questions/59847325/how-to-design-a-relational-model-for-double-entry-accounting-with-job-costing/59857806#59857806)
Comment: Hi. Thanks for writing this comprehensive answer. I am currently building an online marketplace and wondering if using a DEA type system would make sense. I have to track purchases, payments to sellers, payments in and out of paypal, payments VAT in different countries and all in multiple currencies.

Would implementing a DEA make sense?
How does one tie the DAE tables to the orders and products typically. Do you just transfer the payment amounts after the orders are complete?
Thanks!
Comment: Additionally, a couple of questions regarding the examples in the answer.
1) What is the difference between ledger and account - why are the ledgers not just represented as accounts.
2) When transferring from user account to user account, why the need for the transfer to the ledger first? If ledgers were just accounts (as in my first question), could it not just be represented as account -> account?

Thanks!
Comment: @Tom  The Answer is for the Seeker, (0) who understands accounting basics, re (1) how to implement DEA on top of that, and (2) a Relational db for DEA.  Your questions are about (0) the basics of accounting, they are outside the scope of (1) (2).  You are best advised to learn (0) accounting basics, before trying to understand (1) (2).  Sorry I can't help you.
Comment: @PerformanceDBA thank you for this answer. I can see the merits in this approach as you're eliminating accounting ambiguity for complex "business events". As a follow-up, are there specific textbooks/sources you would recommend for an authoritative definition of a "DEA business transaction"? When there's say a "business event" (what online is referred to as a "compound/split/complex transaction"), where we want to reference 2 or more DEA transactions and call them X, is my understanding correct that you'd handle this through a new set of tables to avoid "polluting" the core DEA functionality?
Comment: @PerformanceDBA how can this be modelled to Inventory Management? Are there any resources available that you reccommend? Thanks in advance
Comment: When Alex deposits $50, for a bank (or bank-like sort of business) you're crediting a Liability (Customer Deposits) and debiting an Asset (whichever asset it was - cash etc). I don't understand the logic for a deposit to be Cr Asset / Dr Liability.
Comment: There are a few ways that I like to think about this. The first is mechanical, you look into the nature of the accounts (Asset has a Debit nature / Liability a Credit nature), and just figure what should increase (we need to increase both the asset and the liabilities), hence you Credit 50 Liability and Debit 50 Asset. The second is more "logical", if "credit" is "source", then money came from Alex (for whom we owe), hence you Credit Liability and Debit Asset. This *is* the correct entry for this specific transaction in this specific case. Actually, AccountingCoach even has this exact example.
Comment: Linking a third party article that does a great job of explaining this specific transaction: https://www.accountingcoach.com/debits-and-credits/explanation/4. It would be worth to edit the answer so other folks that read this are not confused by the accounting logic / what sort of transaction this actually is. At last, when using account number for examples, it's always a good practice to use standard logic (Assets are 1xxx and Liabilities are 2xxx). Using 9xxx as a number for a liability account is confusing.
Comment: I apologize if I am misunderstanding you, but I am confused by your statement that ledger_no is credit and ledger_no_dr is debit. In accounting, debits are typically recorded on the left side of a ledger account, and credits are recorded on the right side. So, if ledger_no is a credit, then it should be on the right side of the ledger account, and ledger_no_dr should be on the left side. However, you are saying that ledger_no is on the left side and ledger_no_dr is on the right side. Can you please clarify what you mean?
Comment: @PerformanceDBA I apologize for any confusion. My reference was directed towards the `LedgerTransaction` table, where the columns are arranged in the subsequent order: `LedgerNo, DateTime, LedgerNo_Dr, Amount`. It is important to note that the provided description clarifies the roles of these columns as follows: `LedgerNo` signifies a credit (Cr), while `LedgerNo_Dr` signifies a debit (Dr). You may verify this information in the document located at the following URL:https://www.softwaregems.com.au/Documents/Student_Resolutions/Alex/Alex%20Account%20TA.pdf
Comment: @warmwhisky  Thanks.  Column order is not relevant, it does not signify Left/Right.  I could have, just as easily and legitimately, declared `LedgerNo_Dr, DateTime, LedgerNo, Amount` with the `PK` & `AK` switched.  I could have drawn `AccountTransaction` on the left of `Ledger` and `LedgerTransaction` on the right.  There is no Left and Right in this model.
Comment: @Alan  0) it is not an ERD, it is an IDEF1X Data Model.  1) *Small service business, multiple clients, no branches*: Yes, it works as is.  2) *Multiple branches*: (Most accounting systems I have corrected have poor Ledger definition, which is the source of many problems, but Accountants are unaware.) I would implement each branch as a separate Tree in the Ledger (notice the indented sample data). Therefore yes, it works but not as is.  To implement a full-blown Ledger that supports Trees, use my **[Hierarchy](http://www.softwaregems.com.au/Documents/Student%20Resolutions/Hierarchy.pdf)**.
Answer: Here is my schema (using sqlite as an example) with 2 tables:
Tables
-- This is a list of your chart of accounts
CREATE TABLE "accounts" (
    "name"      TEXT,
    "number"    INTEGER,
    "normal"    INTEGER
)

-- This is a table of each transaction
CREATE TABLE "transactions"
  (
     "id"        INTEGER,
     "date"      TEXT,
     "amount"    REAL,
     "account"   INTEGER,
     "direction" INTEGER
  )

With this convention, the accounts.normal and transaction.direction fields are set to 1 for debit and -1 for credit. The end user never sees this but it makes arithmetic easy.
When you create a journal entry, it will have at least 2 rows in the transactions table - a debit and a credit. They should share the same id.
To see your balances, you can run this query:
select
  (account) as a,
  name,
  sum(amount * direction * normal) as balance
from
  transactions
  left join accounts on a = accounts.number
group by
  name
order by
  a,
  name;

To view the ledger, you can run this:
select
  id,
  date,
  name,
  case when direction == 1 then amount end as DR,
  case when direction == -1 then amount end as CR
from
  transactions
  left join accounts on account = accounts.number
order by
  id,
  date,
  CR,
  DR;

I have a much more detailed post of different queries you can run, along with example data. But, with the above two tables, you can create a working double-entry system.
Comment: In this scenario, your `Transaction` table does not have a primary key?
Comment: In this example, each row does not have a unique ID. However, you could add one.


java.lang.NoClassDefFoundError: groovy/lang/Script but class is loaded...?

Question: I have a problem with trying to make a shell in groovy. I am using groovy 3.0.9 and am compiling it with my jar.
The code in question:
public class GrPlayerShell extends PlayerShell {
    private final Groovysh groovysh;
    private final PrintStream out;
    private final PrintStream err;
    protected GrPlayerShell(UUID uuid) {
        super(uuid, GrShell.getInstance());
        out = new PrintStream(new PlayerStream(uuid, false));
        err = new PrintStream(new PlayerStream(uuid, true));
        this.groovysh = new Groovysh(new IO(
                new InputStream() {
                    @Override
                    public int read() throws IOException {
                        throw new IOException("Not implemented");
                    }
                },
                out,
                err));
    }

    @Override
    public void doExecute(String command) {
        execute(command);
    }

    @Override
    public Result execute(String command) {
        if (command == null || command.isEmpty()) {
            return Result.EMPTY;
        }
        Object result = groovysh.execute(command); // FIXME: 12/26/21 NoClassDefFoundError: groovy.lang.Script
        return new Result(String.valueOf(result));
    }
}

(also here)
The doExecute and execute are running in a different thread to prevent the shell from pausing everything if the shell takes a while to execute (for example a while (true) {}).
This jar also gets loaded dynamically in runtime.
I have tested with java 8 and 17, yet both give exactly the same result.
Just encase the error message is of any importance:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during instruction selection: java.lang.NoClassDefFoundError: groovy/lang/Script

java.lang.RuntimeException: java.lang.NoClassDefFoundError: groovy/lang/Script
    at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:976)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
    at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
    at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
    at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:526)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:538)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:570)
    at groovy.lang.GroovyShell$parse$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
    at org.apache.groovy.groovysh.Interpreter.evaluate(Interpreter.groovy:76)
    at org.apache.groovy.groovysh.Evaluator$evaluate.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.apache.groovy.groovysh.Groovysh.execute(Groovysh.groovy:204)
    at uwu.smsgamer.serverscripter.groovy.shell.GrPlayerShell.execute(GrPlayerShell.java:67)
    at uwu.smsgamer.serverscripter.groovy.shell.GrPlayerShell.doExecute(GrPlayerShell.java:58)
    at uwu.smsgamer.serverscripter.shell.PlayerShell$1.run(PlayerShell.java:86)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.NoClassDefFoundError: groovy/lang/Script
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at groovy.lang.GroovyClassLoader.access$400(GroovyClassLoader.java:90)
    at groovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:700)
    at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:717)
    at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:721)
    at org.codehaus.groovy.control.CompilationUnit$3.lambda$call$0(CompilationUnit.java:806)
    at java.util.Optional.ifPresent(Optional.java:159)
    at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:806)
    at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: groovy.lang.Script
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:869)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:979)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:967)
    at groovy.lang.GroovyClassLoader$InnerLoader.loadClass(GroovyClassLoader.java:607)
    ... 36 more

1 error

[09:49:47 WARN]:    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:295)
[09:49:47 WARN]:    at org.codehaus.groovy.control.ErrorCollector.addException(ErrorCollector.java:143)
[09:49:47 WARN]:    at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:976)
[09:49:47 WARN]:    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
[09:49:47 WARN]:    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
[09:49:47 WARN]:    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
[09:49:47 WARN]:    at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
[09:49:47 WARN]:    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
[09:49:47 WARN]:    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:526)
[09:49:47 WARN]:    at groovy.lang.GroovyShell.parse(GroovyShell.java:538)
[09:49:47 WARN]:    at groovy.lang.GroovyShell.parse(GroovyShell.java:570)
[09:49:47 WARN]:    at groovy.lang.GroovyShell$parse$0.call(Unknown Source)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
[09:49:47 WARN]:    at org.apache.groovy.groovysh.Interpreter.evaluate(Interpreter.groovy:76)
[09:49:47 WARN]:    at org.apache.groovy.groovysh.Evaluator$evaluate.call(Unknown Source)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
[09:49:47 WARN]:    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
[09:49:47 WARN]:    at org.apache.groovy.groovysh.Groovysh.execute(Groovysh.groovy:204)
[09:49:47 WARN]:    at uwu.smsgamer.serverscripter.groovy.shell.GrPlayerShell.execute(GrPlayerShell.java:67)
[09:49:47 WARN]:    at uwu.smsgamer.serverscripter.groovy.shell.GrPlayerShell.doExecute(GrPlayerShell.java:58)
[09:49:47 WARN]:    at uwu.smsgamer.serverscripter.shell.PlayerShell$1.run(PlayerShell.java:86)
[09:49:47 WARN]:    at java.util.TimerThread.mainLoop(Timer.java:555)
[09:49:47 WARN]:    at java.util.TimerThread.run(Timer.java:505)

I have no idea why this might be happening because I put a Class.forName("groovy.lang.Script") before and even made my own class that extends that script class and they both work just fine. Why groovy is complaining that its own script class don't exist, I have 0 idea why.
Pliz help
Answer: just a guess.
if you are not specifying class loader for groovysh by default it takes Thread.currentThread().contextClassLoader
https://github.com/groovy/groovy-core/blob/master/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy#L122
so, at the moment of execution currentThread().contextClassLoader differs from classloader where it's successful for your test Class.forName("groovy.lang.Script")
check that groovy libraries accessible for thread context classloader or change classloader when creating groovish object.
check that you have all groovy dependencies for runtime


python code runs in standalone function but not as part of class

Question: In Python 3.3.5 I am building a class out of some code that works as standalone functions, but it aborts without an error message when the class version is run. It relies on a 3rd party package pcFastDB, distributed as a pyd.
unit1.py
import sys
import pcFastDB as p3

def get_context():
    return p3.pcContext.create()

def get_DB(ctx, dbName):
    return p3.pcDB.open(ctx, dbName)
.. more..

can be used as:
ctx = get_context()
db = get_DB(ctx, 'tester')
..do things with db

but
Unit2.py
import pcFastDB as p3
class DBOperation(object):
    def __init__(self, DB_name):
        '''
        Get the context, open the database and fill a channel list
        '''
        self.ctx = p3.pcContext.create()
        print('Context ' + str(self.ctx ))
        print(' - opening ' + DB_name)
        self.db = p3.pcDB.open(self.ctx, DB_name)  #aborts here
        print('DB opened successfully...' +str(self.db))

aborts silently when I try to open the DB.
db = DBOperation('tester')

The tester db exists and is in the project folder where I am running it.
There is no exception, no error, it just stops executing. PyDev doesn't like the pyd file very well. I don't get any code insight so debugging is kind of mysterious, but in IPython3 I can see all of the functions and class members, so I know its ok. Unfortunately debugging in IPython3 is an unfathomable mystery to me.
Anyway, I know that I am calling the right functions and I know the functions work, because it all works fine in Unit1, it just doesn't work as a class member. Is this even possible?
I've broken the DB lines out of the init and called them separately, and I've broken ctx out of the class and passed it into the functions but that doesn't work either. It behaves identically when run from within PyDev, IPython3 or the command line.
Any ideas?
Comment: How does class GeoDBOperation relate to the class DBOperation ?
Comment: show code where u make `DBOperation` Object.
Comment: @AbhishekBansal I've added the code into the question
Comment: @PaulMitchell Same thing,sorry, I've fixed it. I've obfuscated the code (badly) because of a  restrictive NDA
Comment: I assume you just did copy and paste operations between the working part and the class part - so no chance of typo ?
Comment: @SergeBallesta, yes that's right, and I've checked a dozen times!
Comment: Could it be a problem of not properly closing a previous instance ? What do you mean by "stop executing" ? If under command line python the interpreter ends and you are back in shell ?
Comment: @SergeBallesta yes exactly that.
Comment: Then I think you should try to see (or ask) what could generate such a crash in `pcFastDB.pcDB.open` ... no cleverer idea.
Answer: Thanks everyone, I've gotten it working by basically rewriting the identical code into a new module. There seems to have been something weird with the file itself. I'm blaming PyDev.
Marc


Custom url is not working with drealty listing

Question: I am using Drealty module in Drupal 7. I have created custom url for properties.
I am getting path using;
<a href="<?php print drupal_get_path_alias("drealty_listing/$id"); ?>"><?php print t('More Detail'); ?>
This code is not working for me properly. For some properties it gives page not found but Property exists.
Answer: Using the url() function should give you what you need:
<a href="<?php print url("drealty_listing/$id"); ?>"><?php print t('More Detail'); ?>
The url will be converted automatically to the alias.
Comment: Its working as well my code that I mention above.. still getting same issue for some listings.
Comment: Do you have a link to the pages with the problem?
Comment: Yes I have a link.
Comment: I mean a link to where you are having the problem to clarify what the issue is?
Comment: Issue is link is showing page not found. But when i click on edit . Property is available.


A simple field to hold date value

Question: For a content type, I need a field holding the value of a certain date in history. The content type will be used to hold some historic events and when the current date matches (September 17th, for example) the node will be displayed.
I know that the date module can handle such things but it is quite comprehensive and I will not be using calendars or event content types. All I need is to hold a date value and compare its day and month part with the current date's.
Is there a simple solution?
Comment: The simple solution _is_ the Date module...if you don't need the sub-modules you can just leave them disabled
Comment: Thank you @Clive. I go on with the date module If you gather your comments into an answer I will accept it.
Answer: The Date module will store date time in this format: "2012-05-25 hh:mm:ss" . Using PHP's date_parse function you can extract all those values. What easier thing do you need?
Answer: I think another solution is to create a long text type field and change Text processing to Filtered text (user selects text format) and give Default value (write your logic in PHP (include  tags)). And save it. Then edit it one more time and change Text format to PHP code.
Comment: Thank you for your downvoting .. I knew it was a bad method (but it works), but there is another solution? If there is then please explain ..
Comment: Not my downvote but yes, the date module is the easier solution. OP has a mis-conception that Date is overkill for what he needs (as it has a lot of optional extension modules included), but it's exactly what he needs. The wheel don't need re-inventing :)

A simple field to hold date value


Delayed email, server side using dovecot/postfix

Question: Alternative title:  How to delay a mail queue in postfix for a certain user.
I am planning to build a solution.  At first it would be I would create a separate email address for queuing.  Use a client to send the email from that address.  The queue on that email would be paused (not processing) and then create a job/script or something(separate question) to relay a sendmail -q to postfix to release the queue.
How do I make the queue stay in a delayed state so this is possible.  I do not wish to stop the service and restart it at certain times since that would disable all other email.
Comment: This sounds like mail delivery. What does it have to do with dovecot? Shouldn't this be a Postfix/sendmail/exim/qmail question?
Comment: Very quite possibly.  I am still a little confused on this structure.  I am afraid I am still at the follow the instructions closely stage of my linux email delivery structures.  I am using Postfix.  I will update the question
Comment: Forget dovecot, it doesn't matter here. Why do you want to do this anyway?
Comment: All typical delayed email solution require the client to be active.  Since I am between different OS/computers I can't rely on the client.  I am trying to get a better solution for delayed send.  I am aware I can use squirrelmail, but I would prefer a solution that doesn't require an active web server.  If there is an available add-in/project that would be wonderful.  I don't mean to re-invent the wheel.  Reason 2:  I might learn something
Comment: Why do you want to delay mail in the first place? Mail servers are designed to get rid of the mail as soon as possible.
Comment: What is the purpose and goal of what you are trying to achieve?  Your question is not clear. Are you trying to schedule email delivery? If so, that is a task for the mailing manger and not for the MTA.  Are you trying to prevent users from getting email asap?  If so, then you may have to set your MTA to only run the queue every so often.  If you clarify your goal, I am sure someone here can help you.
Comment: Oh.  I am just forgetful and somethings I do are time sensitive.  My email needs to be out a 5pm and I am emailing it to A.  I email B and say do you have any revisions for this email I am sending to A.  B will send corrections or sometimes forget to respond or not bother (sometimes the case in mass forwards).  Unless I stop it I want that email going out at 5pm.  If B responds then I log in and kill the email.
Comment: All of these are use cases of MUAs, not MTAs.
Comment: MUAs/MTAs.  No idea what they are, but I am sure google does.  I appreciate the terms.  Often you just need to know where to start
Answer: You could instruct postfix via  header_checks to hold emails with specific subjects or headers and then have a cron job that would release those emails at specific intervals/time.
So you would put this in your postfix configuration:
header_checks = regexp:/etc/postfix/header_checks

and then create the header_checks file an put:
/^From: "snailmail/ HOLD

then a cronjob would have to scan the mails that are on hold and release them.


Let $P$ be prime and contain $IJ$, the product ideal. Then $I \subset P$ or $J \subset P$

Question: So I already witness the solution. It is this: Assume $I \not\subset P$, then there is $i \not\in P$. Then the product $ij \in IJ \subset P$, but since $P$ is prime, $i \in P$ or $j \in P$, so $J \subset P$.
here is what I don't get. Doesn't this only show a finite truncation belongs to $P$? Don't we have to show that for any finite sum $i_1j_1 + \dots + i_nj_n \in P$, $i_n \in P$ for every $n$ (assuming $|J| = |I| = n$ for ease of argument)
Comment: What is your definition of prime ideal? This definition is the one that works in non-commutative settings.
Comment: @Math_QED $ab \in P$, then $a \in P$ or $b \in P.$
Comment: What does $|I|$ mean? At any rate, while it is true that such finite sums belong to $IJ$, you don't need to use that fact - it surely is true that $ij\in IJ$ and this is enough.
Comment: @Hawk If you are working with commutative rings, always be sure to use the [commutative-algebra] tag and/or mention commutativity in the post.
Answer: The proof as written is phrased a little awkwardly and missing important details.  Here is a correct proof (with everything spelled out):
Suppose $IJ \subset P$ and $I \subsetneq P$. We wish to show that for all $j \in J$, we have $j \in P$. Fix $j \in J$ $i \in I \setminus P$ and note that $ij \in IJ$. Since $IJ \subset P$, we have that $ij \in P$ but $P$ is prime, so we must have that either $i \in P$ or $j \in P$. Since $i \notin P$ (remember, $i \in I \setminus P$), we conclude that $j \in J$. This shows that $J \subset P$.
As far as the finite sums go, they belong to $IJ$ and thus to $P$ by assumption.
Answer: Well, suppose $I\not\subset P$. Then there is $i\in I$ such that $i\not\in P$. For EACH $j\in J$, $ij\in IJ\subseteq P$ by hypothesis. But $P$ is prime and so $j\in P$. Hence $J\subseteq P$.


One device for routing/firewall/ISP balancing/gateway

Question: Here are my three choices:

Right now I have a cisco ASA that I'm using for a firewall, vlan router, gateway, and ISP failover. There isn't enough control in the ASA for what I need and the license to do it gets very expensive. So upgrading that license is my least favorite option. My cisco also only has 100Mb interfaces, so file transfers between my two vlans would be really slow.
I am thinking about getting a dell poweredge R210 II to handle all of these tasks. Its dells lowest spec rack server. I would just add a 4 port gigabit nic. I would use that to setup routing between my two vlans, a firewall, and the ISP failover all using IPTables.
It's been suggested to me to just include this server into my virtual server which is one big 4u server with an identical physical backup, but it seems like a bad idea to have the domain controller and application servers on the same physical device as the firewall and the DMZ servers.

I would like to go with the second option because it separates out the connectivity server from the rest of my servers. It's also a lot cheaper and I would have full control with IPTables. We have about 200 devices in our network which seems easy to handle on such a low end server. Am I missing something to this or should I go ahead with the separate linux server with IPTables?
Comment: I'd go with #2 but use PfSense.
Comment: PFSense works quite well.  I and friend run it on low-power hardware at home plus at various branch offices and even on a small network at one of our datacenters.
Comment: Which Cisco ASA unit are you referring to?
Comment: It's the ASA 5505.
Comment: @KeithStokes, nice, didn't know there was a BSD distro specific to this. I'll look into that as well. Though I'm more comfortable with IPTables just for familiarity sake
Comment: Consider also m0n0wall, which pfsense forked from.  m0n0 is focussed on running embedded on hardware so may more closely meet your needs.  pfsense is more flexible, but that increases the burden of configuration and the potential security surface.
Answer: The Cisco ASA is quite capable of what you've listed. I tend to use an external load balancer for internet connectivity, though.
What is the shortcoming of the Cisco ASA in this case?
You're missing supportability, and creating a slightly more complex solution by going with a server versus purpose-built hardware. That's really a business decision, though.
Comment: Look for an ASA 5510 if you need the GigE ports. Even a used unit is a good deal and would be more solid than going the server route.
Comment: I'de like to use an external load balancer, but that'd be another $1500 minimum. The linux machine definitely has a cost benefit, I'm wondering if there is a reason not to do it basically. Security, longevity, etc
Comment: @justausr, If you want to keep your boss out of trouble, then buy an appliance firewall
Comment: Linux/bsd machines can be made to be as fault tolerant as cisco devices. You can boot from usb/flash/cdrom to avoid hard disk crashes. You'll get more bang for your buck. But you will have to know what your doing. Cisco is for people that want a solution, not exactly know what it's doing.
Comment: It can do it, but I would need a new license that would allow more vlans. My current license only allows a DMZ, an internal lan, and an external network. I need a DMZ, two lans, and two external networks. The ASA is also limited to 100Mb on each interface, which I need a gigabit between the two lans.
Comment: I'd say supportability. It's definitely do-able on Linux, but understand the tradeoff going into it. If I went with Linux hardware, I'd at least spec redundant power supplies. That's the only change I'd suggest.
Comment: I tend to do really niche things on this network. +1 for suggesting to do otherwise, I need to try to keep my boss out of trouble when I move on.
Comment: Why don't you ask a reseller for a sonicwall demo box?
Comment: "Cisco is for people that want a solution, not exactly know what it's doing." - that is generally the business perspective for every decision.
Answer: Some points to consider...

Anything with a rotating disk (Dell server) is less reliable than something that runs from flash (like a Cisco ASA).  You should go for SAS disks if you go this route (i.e. no SATA).
Dell support tends to get fussy unless you put genuine Dell parts in the system (then again, same story with Cisco).
Someone else already mentioned redundant power supplies, which you certainly should get if you went with the Dell server
I would buy real Intel NICs if you decide to go down the server path; I have not had good experiences with Broadcom's drivers (see this question involving deadlocks on Broadcom when I changed MTUs)
Support is a big issue with this plan.  Some people would argue that you can get paid linux support through RedHat; however, most people with companies your size aren't so happy with RedHat's level of support.
This linux plan will get really messy if you start to need dynamic IP routing protocols in linux.  There are some options (bird / quagga), but you're really getting specialized when you do this.
Comment: I thought SAS disks rotated too? Did you mean SSD? or is SAS just more reliable.
Comment: SAS disks are more reliable than SATA.  I personally think SSDs are too much of a new technology at this point.  We have over 40 years of OS optimizations around rotating disks... therefore SSDs do a lot of things under the hood to pretend they are a rotating disk
Comment: are you suggesting that you run a full routing protocol on a firewall device? Think again. This is terrible security practise. If your firewall need more than static routes, then it's not in the right place.
Comment: No it's not always terrible security practice; there are some situations where using BGP is required to announce reachability for B2B VPNs.  Furthermore, you are assuming that this device will use all interfaces as firewall interfaces, and not for general L3 routing...  Finally, if routing protocols are so terrible on a firewall ask yourself why both Cisco and Juniper support them
Comment: FYI the ASA does not run BGP.
Comment: This [ios firewall](http://cisco.com/go/iosfirewall) does...
Answer: Are you trying to firewall your two subnets from one another?  If not, why not just get a switch with L3 capability for the internal subnets and just use the existing firewall for external connectivity.  100M is generally plenty for that kind of thing and there would be no VLAN limitation.  Such a switch would likely end up being cheaper than either the FW license or the server and would certainly scale better than either.
Comment: We move 3 gig files between the two vlans constantly, but there's a physical and logical separation between the two vlans so we keep them separate. We're not firewalling them, but we do need WAN balancing, I figured one appliance that does it all would be cheaper than buying a L3 switch and a firewall and a balancer, PFSense is looking really promising
Comment: A simple L3 switch with ACL's might provide sufficient separation.  Like I said, adding that into the mix lets you run as many VLAN's as you'd like with no performance impact while maintaining your existing firewall, et al.  No disks, minimal power consumption, little or no OS to patch, etc.


installed python opencv 2.4.11 but only in the system it says I installed only 2.4.8

Question: I followed this link and installed opencv 2.4.11. However when I printed the current opencv version it says it is 2.4.8. Could anyone tell me what went wrong please? Thanks.
https://gist.github.com/dynamicguy/3d1fce8dae65e765f7c4
P.s. I am using Ubuntu 14.04.2 LTS. The command to check the current version of opencv is
import cv2
print cv2.__version__
As kindly suggested by   PraveenPalanisamy I am posting my result of running the command
ls -l /usr/local/lib | grep opencv
-rw-r--r-- 1 root root  1483006 Jul 26 21:33 libopencv_calib3d.a
-rw-r--r-- 1 root root  1850138 Jul 26 21:45 libopencv_contrib.a
-rw-r--r-- 1 root root  4811636 Jul 26 21:26 libopencv_core.a
-rw-r--r-- 1 root root  1420516 Jul 26 21:29 libopencv_features2d.a
-rw-r--r-- 1 root root  1100238 Jul 26 21:26 libopencv_flann.a
-rw-r--r-- 1 root root   863666 Jul 26 21:39 libopencv_gpu.a
-rw-r--r-- 1 root root  1258032 Jul 26 21:28 libopencv_highgui.a
-rw-r--r-- 1 root root  4363758 Jul 26 21:28 libopencv_imgproc.a
-rw-r--r-- 1 root root  2400896 Jul 26 21:37 libopencv_legacy.a
-rw-r--r-- 1 root root  1051714 Jul 26 21:35 libopencv_ml.a
-rw-r--r-- 1 root root   411916 Jul 26 21:44 libopencv_nonfree.a
-rw-r--r-- 1 root root   954904 Jul 26 21:38 libopencv_objdetect.a
-rw-r--r-- 1 root root  3269948 Jul 26 21:41 libopencv_ocl.a
-rw-r--r-- 1 root root   187250 Jul 26 21:38 libopencv_photo.a
-rw-r--r-- 1 root root   960120 Jul 26 21:46 libopencv_stitching.a
-rw-r--r-- 1 root root   543080 Jul 26 21:47 libopencv_superres.a
-rw-r--r-- 1 root root  1779168 Jul 26 21:29 libopencv_ts.a
-rw-r--r-- 1 root root   625806 Jul 26 21:29 libopencv_video.a
-rw-r--r-- 1 root root   508350 Jul 26 21:47 libopencv_videostab.a
Comment: how did you install?
Comment: I installed following the instruction here

https://gist.github.com/dynamicguy/3d1fce8dae65e765f7c4
Comment: Did you run `sudo make install` at the end?
Comment: yes I did, it took 30 mins to execute the command so I think it is done "properly"
Comment: Can you please paste the output of `ls -l /usr/local/lib | grep opencv`
Comment: Hi sorry I could not post pictures as I need more reputations but I have copied the text of the output in my original question. Thanks
Comment: Thanks for posting the output. I have updated my answer to address your issue specifically.
Answer: UPDATE:
From the output of your ls -l /usr/local/lib | grep opencv seems like static OpenCV libraries were built. Due to the -D BUILD_SHARED_LIBS=OFF flag on line 21 in the instructions. You could just remove -D BUILD_SHARED_LIBS=OFF from that line and go over the installation process again for a clean install or simply run the following 3 lines with your current status:
cmake -G "Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/g++ CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_FAT_JAVA_LIB=ON -D INSTALL_TO_MANGLED_PATHS=ON -D INSTALL_CREATE_DISTRIB=ON -D INSTALL_TESTS=ON -D ENABLE_FAST_MATH=ON -D WITH_IMAGEIO=ON -D WITH_GSTREAMER=ON ..
make all -j4 # 4 cores
sudo make install

.That should build shared OpenCV libraries and hopefully it'll solve your problem. If for some reason you still get the same error, then use the remaining of my answer (below) to fix the problem:
For some reason, the python module cv2 that you are importing is from OpenCV 2.4.8 which got installed when you ran the 11th line from the instructions that you followed ( Specifically this command: sudo apt-get install libopencv-dev).
The 23rd line in the instructions that you followed (sudo make install) should have installed the OpenCV2.4.11 as the default OpenCV library. Which can be verified by looking at the output of ls -l /usr/local/lib | grep opencv.
Instead of looking at many lines of the output, you can make it simpler by looking at the output of ls -l /usr/local/lib | grep opencv_core.
You should see something like:
libopencv_core.so -> libopencv_core.so.2.4
libopencv_core.so.2.4 -> libopencv_core.so.2.4.11
libopencv_core.so.2.4.11
libopencv_core.so.2.4.8

Case 1:
If you see the above lines exactly as they are, then it means your sudo make install worked and so, the default OpenCV library version (pointed by pkg-config --libs opencv) is 2.4.11. Then you need to look into the python modules path to see why your cv2 python module is from OpenCV 2.4.8 and not the one from OpenCV2.4.11. To do this, you can run ls -l /usr/local/lib/python2.7/dist-packages/ | grep cv to make sure you see cv2 and cv listed (see the lines below for example)
$ ls -l /usr/local/lib/python2.7/dist-packages/ | grep cv
-rw-r--r--  1 root staff  1638779 Jul 13 18:29 cv2.so
-rw-r--r--  1 root staff       21 Feb 25 07:10 cv.py

and then,look at the output of ldd /usr/local/lib/python2.7/dist-packages/cv2.so | grep opencv it should look something like :
libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f0df24e2000)
libopencv_flann.so.2.4 => /usr/local/lib/libopencv_flann.so.2.4 (0x00007f0df226e000)
libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f0df1d7f000)
libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f0df1ad2000)

Look at the first line of your output carefully: (for example)
libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4. This the library that the python module/wrapper uses. This should be pointing to libopencv_core.so.2.4.11 and not libopencv_core.so.2.4.8. You can verify where libopencv_core.so.2.4 is pointing to with the same command used before (ls -l /usr/local/lib | grep opencv).
Case 2:
The output of ls -l /usr/local/lib | grep opencv_core is something like:
libopencv_core.so -> libopencv_core.so.2.4
libopencv_core.so.2.4 -> libopencv_core.so.2.4.8

Which means the sudo make install that you ran while building OpenCV2.4.11 didn't work for some reason. Then you can two choices:
Choice 1:
Run make && sudo make install from opencv-2.4.11/release directory. Then follow the steps above to see if you see this line libopencv_core.so.2.4 -> libopencv_core.so.2.4.11. If you see it then, import cv2 print cv2.version should print 2.4.11.
Choice 2
If you see the file libopencv_core.so.2.4.11 existing in your /usr/local/lib directory, then you can just create a symlink to make the default OpenCV library files point to version 2.4.11 (which is automatically done when you run sudo make install from the OpenCV build directory)
Comment: omg thx for solving my problem! It was solved using the three lines of code give by you at the very beginning of the answer lol but thanks for your effort for producing such a detailed explanation.  I just started ubuntu yesterday and honestly I have no idea how you have fixed the problem but thanks again for your effort!
Comment: Glad that I could help you fix the problem.


Multiplicar e Somar de acordo com o Dropdown

Question: Nesse codigo a baixo ele faz o calculo de acordo com o checkbox mais eu não sei como fazer o terceiro campo funcionar. Esse terceiro campo só tem que multiplicar um valor pelo numero escolhido no dropdown,  mexendo o menos possível nesse código já existente

Exemplo $Valor = 50;
$valor  x numero no dropdown e soma no valor total

$(document).ready(function() {
    $(".valores1").change(function() {
        var total = 1000;
        total += $('input[class="valores1"]:checked').get().reduce(function(tot, el) {
            return tot + Number(el.value);
        }, 0);
        $('#total1').val(total.toFixed(2));
    });
});

500,00 Ida e Volta?
<input type="checkbox" class="valores1" name="choice" value="500" />

200,00 Adcional?
<input type="checkbox" class="valores1" name="choice" value="200" />

50,00 Cadeira  X
<select  class="valores1" name="cadeira" >
 <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>  //Fazer esse função funcionar

<input type="text" size="6"  readonly="" name="total" id="total1" value="1000" />

Answer: Pegue o valor do item selecionado pelo id do select.
A propriedade  ..selectedIndex].value - obtém o value do item selecionado no momento
var e = document.getElementById("valores2");
 var itemSelecionado = e.options[e.selectedIndex].value;

$(document).ready(function() {
  $(".valores1").change(function() {
    var total = 1000;
    total += $('input[class="valores1"]:checked').get().reduce(function(tot, el) {
      return tot + Number(el.value);
    }, 0);

    var e = document.getElementById("valores2");
    var itemSelecionado = e.options[e.selectedIndex].value;
    total=total+(itemSelecionado*50);
    $('#total1').val(total.toFixed(2));
  });
});

500,00 Ida e Volta?
<input type="checkbox" class="valores1" name="choice" value="500" />

200,00 Adcional?
<input type="checkbox" class="valores1" name="choice" value="200" />

50,00 Cadeira  X
<select id="valores2"  class="valores1" name="cadeira" >
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>  //Fazer esse função funcionar

<input type="text" size="6"  readonly="" name="total" id="total1" value="1000" />


Proving that $\sum_{i=1}^{n} \left(a\check{q}_{i}^{\frac{1}{\alpha}}+\left(1-a\right)\hat{q}_{i}^{\frac{1}{\alpha}}\right)^{\alpha}\geq 1$

Question: I'd like to show that
$$
\sum_{i=1}^{n} \tilde q_{i}=\sum_{i=1}^{n} \left(a\check{q}_{i}^{\frac{1}{\alpha}}+\left(1-a\right)\hat{q}_{i}^{\frac{1}{\alpha}}\right)^{\alpha}\geq 1,
$$
given that $a,\alpha,\check{q}_i,\hat{q}_i\in\left[0,1\right]$ and that $\sum_{i=1}^n\check q=\sum_{i=1}^n\hat q=1$.
If $\alpha=1$, $\sum_{i=1}^n\tilde q=1$, and I believe that this sum is decreasing in $\alpha$. However, I'm not able to establish the sign of the derivative. This derivative is
$$
\frac{d \sum_{i=1}^{n} \tilde q_{i}}{d \alpha}=\sum_{i=1}^{n}\tilde q_{i}\frac{1}{\alpha}\left(-\frac{a \check{q}_{i}^{\frac{1}{\alpha}}\ln \check{q}_{i}+\left(1-a\right) \hat{q}_{i}^{\frac{1}{\alpha}}\ln \hat{q}_{i}}{\tilde{q}_i^{\frac{1}{\alpha}}}+\ln \tilde{q}_{i}\right),
$$
and, as $\check{q}_i,\hat{q}_i\in\left[0,1\right]$ (and, therefore, $\tilde q_i\in\left[0,1\right])$, the first summand in the parenthesis is positive and the second is negative.
Answer: The derivative can be written as
$$
\frac{d \sum_{i=1}^{n} \tilde q_{i}}{d \alpha}=\sum_{i=1}^{n}\tilde q_{i}^{\frac{\alpha-1}{\alpha}}\left(-a \check{q}_{i}^{\frac{1}{\alpha}}\ln \check{q}_{i}^{\frac{1}{\alpha}}-\left(1-a\right) \hat{q}_{i}^{\frac{1}{\alpha}}\ln \hat{q}_{i}^{\frac{1}{\alpha}}+\tilde{q}_i^{\frac{1}{\alpha}}\ln \tilde{q}_{i}^{\frac{1}{\alpha}}\right)<0,
$$
where the inequality follows from $f(x)=x\ln x$ being a convex function.