How to auto update account balance in database every 30 days - php

I have a customer table in my database. This table contains customer information including his/her balance.
Now I want to add his/her balance after every 30 days depends on what promo or plan he/she applied
example: he applied for a plan 1599 so after every 30 days his balance must add the price of the plan he applied.
current balance = 0
after 30 days balance = 1599
How will i do this?

You can create a cron job for the same. Check the date difference for every user and if its greater than 30 days add the balance to the respective user's account.

You can do this like
Store the Date when user choose plan by using date('Y-m-d') in a variable
Add 30 Days in it by using date('Y-m-d',strtotime("+7 day", $date)) and save this in database
Write a query to check that date of today is equal to that stored date or not if so then add points to that account.
For point 3 you may also need cron job depends on your requirement.
If still need help feel free to comment

Related

How to calculate total online time using laravel?

I want to calculate particular user's total online time for selected date. Below is MySQL table -
User Active Status Table
In status column I store values as 0 (Offline) and 1 (Online).
As you see user_id 33 is online at -
10:05:25
14:00:00
and offline at -
11:45:58
19:00:04
So, How to calculate total online time using Laravel?
Thanks in advance!
You can try to refactor a bit your database..
Add 3 columns date, logged_in_time, logged_out_time and you can make an event listener each time user logs in our out. Any time they will log in our out it will be stored in your table and you can filter easily by dates in your query.
If you want to calculate the amount of time they were logged in for a specific date you will just do 'logged_out_time - logged_in_time'

How to automatically update an entry daily in phpMyAdmin?

I have a database called ARTICLES. Inside Articles, I have a table called Users. Inside Users, there is an entry called Renewal, which is an Integer.
Once Renewal is set, it should decrease by 1 every 24 hours. For example, let's say Renewal is 30. In 24 hours, Renewal should be 29. I do not wish to go inside the entry, and update this field every 24 hours. There will be hundreds of rows with different values for Renewal.
Is there a way to automatically update this entry every 24 hours, so that the entry decreases by 1?
You're taking the wrong approach. Instead of counting down in a complicated manner you can simply set an 'expire' date. 30 days from now? Then expire at 19 juli 2016 at 12:00. No need for automatic updates.
You can create scheduled events in MySQL - CREATE EVENT
I would check renewal values programatically in you PHP script based on your record timestamp instead of you approach.

Laravel4 Date based actions

I have a Mysql Table with columns below
ID Amount Charge_Date
1 200 12-Apr-2015
2 300 10-May-2015
I am trying to write code so that when date reaches today, the amount is debited in a new table. eg lets say today is 12 Apr then Rs 200 is debited to account which is a new table.
Please help me with the idea. Should I set a Cron Job which will run everyday and check if date is today. Or is there a better way of calculating such things.
Also need help with setting recurring events like everyday I need to calculate outstanding from a table and send email to customers.
Cron seems to be the only way out. Just need to set cron from cpanel and it will run for any desired controller

Decrement days daily in membership site

I have a database for membership site where users has a column day .This is number of days left until users membership expire.
Right now I run cron job daily at 12 AM to decrement day column by 1.
Is this the better solution or any other ideas available ? using date of registration and current today date.
Much better approach is to store membership expiration date and just compare with the current date.

Programming logic - update the database only one time after specific time interval

I am developing ecommerce store in php and I have some problem in creating a logic. The problem is I have a store page where I am showing some products. all the products have some time interval,after interval passes the products will no longer be display there.
For example
Product: jeans
time left: 10 days.
after 10 days jeans product will no longer be there. in database I have a set a field with the name active_status which accepts Y or N..
I know that I can simply run the update query and set the status to "N" after time passes. here in this example after 10 days
BUT the question is WHEN DO I RUN THIS UPDATE QUERY ?
should I always check time and run again and again update query and set STATUS TO 'N'??? IS that is the only solution ?
I mean usually we do like for example if customer logins we set some status or any other event but here we are setting the status against checking the time. Hopefully you have understand my question
In the db I am saving the start time and number of days which user puts through the admin panel
My first shot would be cron, php script and properties table (if needed, because for simple uses you could just store expiration date inside business entity).
Cron runs php script periodically (e.g. once a day),
scripts checks if there is anything to delete, based on properties table, or entity properties.
If there is anything to delete, script performs deletion of selected content.
That's all and it is in fact very popular scenario.
More on cron: http://www.pantz.org/software/cron/croninfo.html
Here is my logic i hope it will helps i think
While Publishing the product we have to maintain the time interval of that product for example if you want to display the product for 10 days give 10 days and date of publish product.
By comparing with that date and number of days given for time interval with the present date i.e today's date
Can you check with this

Categories