Wow man you got a cheek to ask for source code! You want to ue open source tools, want to see the source code of softwares to design your own and then hide your software's source code. Please stop abusing open source softwares and their ideology.
Anyway to answer your query, you can check out some open source accounting packages, their source code will be available on their websites.You can decide which one matches your need and can use it to model your software. You can google around a bit for it.
Here's one I found
SQL-Ledger