13. februar 2012 - 18:24 Der er 10 kommentarer og
1 løsning

Review of database for microloans

I am writing this in English, because I have a 'partner in crime' who prefers this language.

I am as volunteer helping an organisation with the purpose to organise 'microloans' to entrepeneurs that cannot get commercial loans, because they cannot provide any collateral.  (I do not seek comments about this purpose - I know it is controversial.) 

The loans will initially be provioded in Uganda.  The organisation has a bank balance there.  When a loangiver in Dennmark transfers an amount to the organisation this amount will remain in Denmark, and the organisation authorises by email the contact person in Uganda to make a withdrawal and pay it out to the loantaker.  The installments the loantaker pays are deposited in the bank, and the contact person reports the installments by email to the organisation in Denmark who then reimburses the loangiver.  International transfers are thereby avoided to reduce costs. 

The platform is Joomla using mysql for database.  The organisation has chosen paypal for money transfers.  I envisage using the following tables.  Here is a picture of the tables and their relationships: http://christianjorgensen.be/Billeder/tables.jpg?_cache=1329153452

A. loancase (lånesag) where loancases are established with id, title, goal (mål), start- and end date.  The loancase will have an B.installmentplan (afdragsplan), for example a loan of 1200kr started 1 February expects installments of 430kr at the end of February, March, and April (the excess of 3x30kr goes to cover expenses and expected exchange rate losses.)  A loancase includes more data that falls outside the scope of this question.

C. lender (långiver) where individuals are established as lenders first time they provide a loan.

D. bid, an amount one lender provides for one loancase.  A loancase for 1200kr can be funded, for example, by three bids, 200kr, 600kr, and 400kr from three different lenders.  A lender can provide bids for several loancases.  Bids are established when lenders from their paypal accounts transfer amounts to the paypal account of the organisation.  Paypal identifies payers and payees with email accounts, and because one lender can use different paypal accounts with different email addresses for the bids, the bid record must include the email address used.

So far so good.  The loantakers hopefully pay the installments, and when they do, the organisation receives reports from the Ugandian contact person.  The organisation shall then, manually in the beginning, create an entry in the table E.installment (afdrag).  Each installment relates to one loancase.  (Queries on the tables installmentplan and installment can give reports on which loancases have installments overdue.)

There are no direct relationship between installments and bids.  A loan of 1200 kr can for example have been funded by three bids of 200, 600, and 400 kr and have three installments of 400 each.  The organisation will manually (for a start) monitor the flow of installments, and when enough installments have been received for a loancase to reimburse a bid the organisation will create an entry in the table  F. return (retur).  Normally there will be one return for each bid, but it must be possible to have one bid covered by the sum of several returns.  The loangiver will by email be informed and may request to be  reimbursed or may donate the installment to the organisation. The return therefore go through varies status' such as created, lender informed, lender reimbursed, donated.  If the lender asks for reimbursement the amount will be transferred from the organisation's paypal account to the same paypal account from where it came.

If you are still with me, here is what I ask:  A review of and comments to the proposed table and data structure.  One possible change could be, noting that the tables B. installmentplan (afdragsplan) and E. (afdrag) have the same structure, to drop one table and add a column 'type' to indicate whether an entry is plan or actual.  You may think of other changes.  I shall later add additional tables to include the financial transactions, so that it is becomes possible, among others, to verify if the balance on the paypal account agrees with the sum of bids and returns that have passed through it.
Avatar billede arne_v Ekspert
14. februar 2012 - 02:11 #1
If there is no flexibility in payments, then you can merge the payment_plan and payment tables to just have a field that say whether it is paid or not.

If there is flexibility (make extra payment etc.) then I would keep the two tables.
Avatar billede arne_v Ekspert
14. februar 2012 - 02:17 #2
But I don't like the rest of the table structure.

Or at least I don't like the names.

As I see it then you really have:

bid----inloan----outloan

where outloan has payment_plan and payment

and inloan has return_plan and return (drop return_plan if no plan exist)

and add current_balance to both inloan and outloan (too cumbersome to calculate every time you need it)
Avatar billede arne_v Ekspert
14. februar 2012 - 02:18 #3
And I take it for given that table and column names will be in English!
14. februar 2012 - 08:13 #4
arne_v, thanks for input.  I shall reflect on it (it requires some thought) and return, probably tomorrow.  In the meantime I hope for comments from others.
15. februar 2012 - 08:07 #5
Arne_v, yes, I made a mess of the naming.  The tables will be held in Danish, but for the purpose of this question I now use table names and column names in English.

And yes, it helps to think of the processes in terms of inloan and outloan.  The tables and the programming will handle the inloan cycle.  The outloan cycle shall for a start be handled manually.  I therefore for now suppress the tables for installments, planned and actual.  The overall accounting, such total inloans received by the organisation, total outloans given, total installments received and disbursed, also remains to be done and is outside the scope of this question.

The inloan cycle starts with defining a loancase, for example that Jost in Uganda needs 800 kr. to purchase a chainsaw to so that he can produce firewood from dead trees and sell it to local households.  Creating and displaying the loancase triggers an entry in the Loancase database table.

Someone, say Hans Jensen, sees the loancase and opens a lending form with the intention of lending 300 kr.  If Hans Jensen is not logged in he shall be registered as a lender when completing the lending form. 

When the lender submits the lending form it results in the internal action of making a draft record in the Inloan table.  At the same time, as an external action, the amount is transferred from the lender's paypal account to the organisation's paypal account.  If the transaction is successful paypal returns a message which is used to complete the inloan record.

This has all been programmed and the tables set up.  Now I need to move on: 

At some time (depending on events in the outloan cycle) the organisation decides to close an inloan, such as the 300 kr lent by Hans Jensen.  Using an adminfunction the organisation shall create a Return record and shall by email ask the lender whether the lender wants the money back (the default option) or wants to donate it to the organisation.  If the lender wants the money back the organisation shall start the external action of transferring the sum from its paypal account to the lender's paypal account.  The return message from paypal, if success, will update the inloan with datum closed.  If the lender will donate the amount no money changes hands, but the organisation creates a donation record and updates the inloan with datum closed.

If there is always a one-to-one relation between an inloan and a return (300 kr lent for a purpose and the 300 kr back) probably the separate return record and table could be dropped and the return could be recorded directly in the inloan record.  However, it must be possible to handle a situation where for example the loantaker fails to pay the full installments in time and either defaults entirely or pays back after a longer delay.

The return goes through a number of status', created, email to lender, response to lender, paid back, donation created.

The current balance of an inloan, the 300 kr from Hans Jensen, will either be the full amount or will be 0 (except in cases of default etc.) when either the amount has been reimbursed or donated.

This has clarified my own mind.  I welcome further comments, from you or elsewhere.
15. februar 2012 - 08:19 #6
..and a picture of the tables:

http://christianjorgensen.be/tables.php
15. februar 2012 - 08:27 #7
And arne_v, expanding my knowledge: you propose in #3, pragmatically, to deviate from strict normalisation by storing data that can be derived from other data, because the disadvantages of so doing are judged to be less than the added efficiency of having the balances ready at hand?  Because these balances can be expected to be needed very frequently.  Did I understand you correctly?
Avatar billede arne_v Ekspert
15. februar 2012 - 15:45 #8
Having to aggregate over multiple rows to get information tend to be cumbersome and impact performance.

Also consider whether data is really redundant. Let us say that the original balance was 1000. Then 4 payments of 100 are made. So the we have 4 rows in the payment table. And the current balance in the loan table says 600. Now a terrible accident deletes 2 of the row in the payment table. Do you consider the current balance to be 600 or 800? I am pretty sure that you would say 600. So the current balance in loan is not really a redundant value. It is a true independent value and one of the most significant in the system. The payment table just has historical information that hopefully explains why the current balance is as it is.
15. februar 2012 - 18:19 #9
I hear what you are saying.  I shall bear it in mind when in the next stage time comes to automate the accounting for the aggregate flow of money.  That is still outside of the scope of this question, where I am, for now, only dealing with the individual loaned amounts.
17. februar 2012 - 16:01 #10
arne_v, nobody else came with input, thank for yours.  Please submit an answer for closure and points.
Avatar billede arne_v Ekspert
17. februar 2012 - 16:08 #11
svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester