I have a table of products. The products can be rented. I have another table validity_periods. Here is the structure of tables.
http://sqlfiddle.com/#!2/c97e3
validity_periods
id description
1 7 Days
2 14 Days
3 21 Days
4 1 Month
products
id : 1
title : Car
description : None
validaity_id : 1
category_id : 1
rent_count : 0
current_status : available
start_date : 0000-00-00 00:00:00
end_date : 0000-00-00 00:00:00
Now i am doing the folliwing.
When user creates this product i provide a dropdown to select maximum validaity period for this product.
The drop down contains validity periods. And save the validity_id with product.
When someone rents this product i update the current_status from available to rented.
Takes the id find the current date and generate start_date and end_date and update the product.
Here i need two things
First : is there a simple solution that insted of doing a lot of work i simply do something to generate start_date and end_date? i can change the schema of validity_periods if required.
Second : When i display the product i display the status and the remaining days(after product will be available again to be rented).
So how can i achieve these two tasks.
Let suppose the product Car has been rented and now
id : 1
title : Car
description : None
validaity_id : 1
category_id : 1
rent_count : 1
current_status : rented
start_date : 2012-12-10 01:30:00
end_date : 2012-12-17 06:50:00
Now i need to display this information.
Item : Car
Status : Rented
Rent Count : 1
Remaining : 3 Days 23 Hours