I think this is a very good and common approach I would use, one thing you may want to consider is using foreign keys to link the tables together. For example, you could use the structure_id as a foreign key to link the movements to the structures table. This can help ensure data consistency and integrity.
Incomes and expenditures : best database structure ?
Hello,
I have to develop a very very simple accountability application, just to save what comes in and goes out, classified by categories, clients and expenditure items.
First time I develop an application with financial purposes and it's for a personal use to have a book with all movements. I could use an existing application (what I already do for a part of my activity), but it's always interesting to try to develop such an application.
How is the best database structure to save incomes and expenditures ?
I wonder if this structure is relevant or not.
activities : id, name
roles : id, name (creditors, debitors)
structures : id, name, role_id (or enum with creditor and debitor)
missions : id, name
movements : id, amount, invoice_date, payment_date, activity_id, structure_id, mission_id
But => the invoice_date, the activity_id and the mission_id can be null.
So I had the idea to separate the movement into two different tables.
incomes : id, amount, invoice_date, payment_date, activity_id, structure_id, mission_id (all fields are not null)
expenditures : id, amount, invoice_date, payment_date, activity_id, structure_id, mission_id (some fields can be null)
So I had another idea to structure the database : put the activity_id, structure_id, mission_id fields in another table named caracteristics.
movements : id, amount, invoice_date, payment_date, structure_id
caracteristics : id, activity_id, mission_id, movement_id
Like this when a movement isn't related to a specific activity and/or mission, I don't need to fill it.
What do you think about all this ?
Thanks a lot for your suggestions.
Vincent
@vincent15000 I usually just do standard bookkeeping, see: https://laracasts.com/discuss/channels/general-discussion/rental-management-db-schema
Please or to participate in this conversation.