Jump to content

Setting up MySQL for 'Banking' Style Database


c4onastick

Recommended Posts

Hi,

I've had it with trying to keep track of what my roommates owe me for utilities, food, rent, etc. Sounds like a good opportunity to open the web-banking part of "C4onastick's Credit Union". I'm having a little trouble thinking out how this should work. Essentially I'd like it to parallel most online banking. Here's the layout I'm thinking:

Table: Roomate

Cols:
[list]
[*]transaction_id
[*]date
[*]description
[*]amount
[*]balance
[/list]

With one table for each roommate. How would I work the balance column? I'm thinking a MySQL function to calculate the value from the previous entry. How would I write that (I've never written a MySQL function)? Otherwise I could have a bunch of queries from the PHP side, and have PHP calculate the value and plop it in. Any thoughts? (Only my roommates and I will be using it, so I'm not terribly worried about security or using InnoDB)

Thanks in advance.
Link to comment
Share on other sites

Agreed. I'm thinking this out in my head, and it could become a mess of database calls.

- Select the previous balance
- Calculate the resulting transaction balance
- Insert the new transaction

I invisioned the transaction table to be more like a checkbook ledger. With the resulting balance of the transaction tracked/calculated for every transaction. Sure this would be doable, but it seems like there's an easier way... Or maybe not! That's why I'm posting! Thoughts?
Link to comment
Share on other sites

[quote author=fenway link=topic=116431.msg475607#msg475607 date=1164807977]
Well, the real question is why you need to keep storing the temporary balance.  If you just store the transactions, debits & credits, you can simply add them up, and there's your current balance.
[/quote] I think I'd like to be able it have it browseable by date, in which case I think I'd need the resulting balance stored so that you could see the resulting balance (what they owe me) as of when. I'm not sure how I'd do that if they were live calculated. Ideas?
Link to comment
Share on other sites

I see your point though, it would be much easier to just calculate them "on-the-fly". The only problem I have with that is that this record will be for years (I usually pay all the utilities, rent, etc. and have my roommates pay me for that all in total when rent's due). So I think it would be nice (read: smart) to have a hard copy of the balances after every transaction.

So I guess my question should really be: Is there a way to embed a 'Excel style' "=previous_balance + current_transaction" (please forgive the MySQL noobieness of this question) into the value for the balance column? Or do I need to do that the way I described earlier?

- Select the previous balance
- Calculate the resulting transaction balance
- Insert the new transaction

Thanks for all your help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.