会计数据库 - 存储交易 [英] Accounting Database - storing a transaction

查看:182
本文介绍了会计数据库 - 存储交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您做一个游戏网站,用户可以购买游戏积分和资金存入/贷记到用户的虚拟账户玩一些游戏等等......等等。

You make a gaming website where the user can buy gaming credits and the funds are deposited/credited into the user's virtual account to play some game etc...etc..

如果你有一个会计记录事务,将它记录是这样的(也许有点复杂,但你明白了吧)

If you got an accountant to record the transaction, it would be recorded like this (maybe a bit more complex but you get the point)

TRANSACTION
PK_ID1 Cash      - $10 (System)
PK_ID2 Deposit        $10 (System)

TRANSACTION
PK_ID3 Bank Account      - $10 (John)
PK_ID4 Deposit        $10 (John)

2

作为一个开发者,你真的需要浪费2个额外的记录?为什么不只是记录它像这样......(那么你可以存储在那里的​​资金,地位排在其他列在同一存款记录下信息)

2

As a developer, do you really need to waste 2 extra records? why not just record it like this…(then you might store information where the funds came from, status in other columns under the same deposit record)

TRANSACTION
PK_ID1 Cash      - $10 (system)
PK_ID2 Deposit        $10 (John)

时的有选择#1选项以上#2和副签证任何真正的优势在哪里?

Is there any real advantage of option #1 over option #2 and vice visa?

编辑:改性问题,删除CR,DR,并与一个标志换成

modified question, removed CR, DR and replaced with a sign.

推荐答案

(回答你的问题,而且在应对paxdiablo的回答提出的一些要点。)

(Answering your question, but also responding some points raised in paxdiablo's answer.)

这是无关的会计师找你的数据库中。随着复式,错误很容易跟踪;这是一个会计 IRS要求,所以真的,你没有选择,你需要与公共资金涉及任何系统双项。

It is nothing to do with the accountant looking inside your database. With Double entry, errors are easy to trace; it is an Accounting and IRS requirement, so really, you do not have a choice, you need double entry for any system that deals with public funds.


  • (请不要试图告诉我什么是双项是,我已经写了复式系统银行,审计要求)复式是一种核算方法的基础上,一组帐户。每一个金融交易的日记帐分录;如果从一开始就重新应用的所有事务,所有帐户将在他们的确切相同的平衡,因为它们是今天。

  • (Please do not try to tell me what "double entry" is; I have written double entry systems for banks, to Audit requirements.) Double entry is an accounting method, based on a set of accounts. Every financial transaction is Journal Entry; if all the transactions were re-applied from the beginning, all the accounts would at their exact same balance as they are today.

双项意味着每笔交易都有一个收件人和发件人账户;钱从未离开系统或进入系统。每一笔都有附加了借记卡。

Double Entry means every transaction has a "To" and a "From" account; money never leaves the system or enters the system. Every Credit has a Debit attached to it.

因此​​(1)不是(2),它们不能容易地比较双条目的版本。约翰的交易的双项版本(一个金融交易),在逻辑会计的角度来看:

Therefore (1) is not the "double entry" version of (2), they cannot be readily compared. The double entry version of John's transaction is (one financial transaction), in logical accounting terms:


  • 从: JohnAccount 键: SystemAccount 金额: 10.00 (美元)

这很可能是一个表中的两行,一个信用和其他借记,两个插入件包裹在一个SQL事务。

That may well be two rows in a table, one a credit and the other a debit, the two inserts wrapped in an SQL Transaction.

这是它的会计制度,这是内部的,与权钱交易。我们正在做的。

That is it for the Accounting system, which is internal, and deals with money. We are done.

但你是会计系统还娶了购买/销售系统(而无需显式声明它)。当然,你从约翰拿了十块钱,你需要给他他所购买它,并记录。约翰买了十块钱值得游戏学分,如果你追踪,那么,您还需要:

But you are additionally marrying the accounting system to a purchase/sale system (without having explicitly declared it). Of course for the ten bucks you took from John, you need to give him whatever he purchased for it, and record that. John bought ten bucks worth of gaming credits, if you are tracking that, then yes, you also need:


  • 从: SystemGamingAccount 键: JohnGamingAccount 金额: 100 (学分)结果
    或者,前$ P $以美元pssed:

  • 从: SystemGamingAccount 键: JohnGamingAccount 金额: 10.00 (美元)

  • From: SystemGamingAccount To: JohnGamingAccount Amount: 100 (credits)
    or,expressed in dollars:
  • From: SystemGamingAccount To: JohnGamingAccount Amount: 10.00 (dollars)

这也可能是在一个表中两行,一个是信贷和其他借记,四个刀片包装在一个SQL事务。

That, too, may well be two rows in a table, one a credit and the other a debit, the four inserts wrapped in an SQL Transaction.

需要明确的是,如果你是卖小部件,而不是游戏学分,第二个(小窗口跟踪)的交易将是:

To be clear, if you were selling widgets instead of gaming credits, the second (widget tracking) transaction would be:


  • 从:仓库键: PublicSale 金额: 1 (小工具)

和因为你是跟踪单位的仓库,但没有多少小部件迫在眉梢公众在他的口袋里,这是两个插入加一个更新(更新零件SET QtInStock = QtyInStock - 1 WHERE部分code =部件),所有包裹在一个SQL事务。

and since you are tracking Units in the warehouse but not how many widgets John Q Public has in his pocket, that is two inserts plus one update (UPDATE Part SET QtInStock = QtyInStock - 1 WHERE PartCode = "Widget"), all wrapped in a SQL transaction.

并没有为每个用户帐户,对吧。虚拟的,深奥的或物理的,这是一个法律实体,针对其交易的。所以我们不要pretend它不存在,因为它是虚拟的。对于游戏,一块钱的帐户加上一个游戏(信贷)帐户。

And there IS an Account for each user, right. Virtual, esoteric or physical, it is a Legal Entity, against which transactions are made. So let's not pretend it does not exist because it is virtual. For gaming, one dollar Account plus one gaming (credit) Account.

信用卡/借记

我会把CR / DB回来;不CHAR(2),但布尔值。它会帮助你后,当表很大,

I would put the CR/DB back in; not CHAR (2), but boolean. It will help you later when the table is large,

    WHERE IsCredit = 1  

    WHERE Amount >= 0.

请注意,与> =你必须确保每个code段为codeD以同样的方式,而不是>有时。布尔或字符不存在这样的问题。

Note that with ">=" you have to ensure that every code segment is coded the same way, not ">" sometimes. Boolean or char does not have that problem.

这篇关于会计数据库 - 存储交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆