How to schedule events in PHP - php

I am creating a processing system in PHP, I read tons of tutorials over the internet but nothing
seems to satisfy what I need for my system.
I have table SCHEDULE in SQL..
+----+------+---------------------+
| ID | Name | Description |
+----+------+---------------------+
| | | |
| 1 | D | Daily |
| 2 | W | Weekends |
| 3 | EOM | End Of the month |
| 4 | 11d | 11 day of the month |
| 5 | M | Monday |
+----+------+---------------------+
And Table PROCESS..
+----+---------------+-----------+
| ID | Schedule_id | Name |
+----+---------------+-----------+
| 1 | 1 | Process 1 |
| 2 | 2 | Process 2 |
| 3 | 3 | Process 3 |
+----+---------------+-----------+
What I want is to automatically show the process on each days base on their schedule.
Meaning:
if Process1 = D RUN Process1 everyday
if Process2 = W RUN ONLY Process2 on weekends
if Process3 = 11d RUN ONLY Process3 on the 11th day of the month
I also want them to store on my calendar and also how about holidays?
All answers will be appreciated thanks.

I understand that activities don't have an associated schedule, so you can be at any given time. Taking that as a starting point, you can run a cronjob, every day, through a script in PHP which being entrusted to compare the tasks that the day should be made and there using shell_exec() php function to run the process in bash or in what you have defined.
That is:
For each record in "sheduled" you compare the date (If today, tomorrow or the weekend) and if there is a match, run the associated process.

Related

Select all rows where dates fall between start column and end column in table 1 AND where the session user has eventID's that match from table 2

I don't know if this is too complicated for a SELECT alone or if it should be done in PHP.
I have two tables: EventDetail and EventPersonnel. I need to return the events for a specific date range and user.
EventDetail
EventId | EventName | Start | End
------: | :-------- | :--------- | :---------
1 | Event A | 2022-03-09 | 2022-03-11
2 | Event B | 2022-03-09 | 2022-03-15
3 | Event C | 2022-03-10 | 2022-03-21
EventPersonnel
EventID | UserID
------: | -----:
1 | 1
1 | 3
2 | 2
3 | 1
3 | 2
3 | 3
Expected Results:
If today were March 10, 2022 and current userId = 1, the expected results are:
EventId | EventName | StartDate | EndDate
------: | :-------- | :--------- | :---------
1 | Event A | 2022-03-09 | 2022-03-11
3 | Event C | 2022-03-10 | 2022-03-21
db<>fiddle here
I solved the first part returning all of the rows in where the current date falls between the start date and end date in my eventDetails table as below:
$currentEvent = new WA_MySQLi_RS("currentEvent",$stapleton,1);
$currentEvent->setQuery("SELECT * FROM eventDetails WHERE CURDATE() BETWEEN start AND end");
$currentEvent->execute();
I can also return all of the records of the logged in user via the session:
$userEvent = new WA_MySQLi_RS("userEvent",$stapleton,0);
$userEvent->setQuery("SELECT eventID FROM eventPersonnel WHERE userID = ?");
$userEvent->bindParam("i", "".($_SESSION['UserID']) ."", "-1"); //colname
$userEvent->execute();
Both of these work as i need them. However there is one more piece I need and that is to combine them so that I am only returning the events for the logged in user. I have tried several subqueries and cannot come up with anything that is not a illegal SQL error.
I don't know if I am explaining it well enough. I don't believe this would be hard for someone knowing what they are doing. But I don't know where to start.
I am very new to Php and can echo the queries and can create repeat regions to show my results but I do not know where to begin to write proper code. I'd appreciate it if someone could show me the proper code AND if they could please tell me what I need to learn so I can understand this myself. There's SO MUCH out there that for a noob like myself I have no clue even where to start. Thanks in advance!

Add due_payment table to the existing database and alter some features

I have a table called payment which holds records for student payment,Student details are saved in another table.
|payment_id | stuid | stu_name | recipt_no | descr | grade | scl_fees |sec_fees | fac_fees | sport_fees | pay_comp | paymentdate | record_status | is_reverse | reverese_date_time | reverese_user | created_at | updated_at | full_amount | pay_com_month |
| 001111 | 23214 | Jhon |2017cc12 | Nov,Dec | 4A | 500 | 200 | 200 | 300 |200 | 1300 | 2017-12-10 | paid |0 | | |2017-12-10 |6500 | Oct
System is up and running without issues,Student were supposed to complete their payments within the year,as per 1300 * 12.If so System reset all the values and prepare for the next year payment,
But in real scenario,some student didn't complete the payment as they supposed.So they need to move those due payments to next year.
Unfortunately my system was designed around the above table,in order for the new year i have to move those values for a new table,
but those due payments,I am kind a lost there.any idea guys !
My Solution is to create a another table called due_payments and hold those record.Because after completing those records for the last year,The payment table has to truncate and start from the beginning.But what will happen in next years to come.
i used laravel platform
Can anyone give me a Soultion,
Thank You.

Select MySQL return table header as well table body in one query

Hello I am facing hard time trying to realized this task. The problem is that I am not sure in which way this have to be proceeded and couldn't find tutorials or information about realizing this type of task.
The question is I have 2 tables and one connecting table between the two of them. With regular query usually what is displayed is the table header which is known value and them then data. In My case I have to display the table horizontally and vertically since the header value is unknown value.
Here is example of the DB
Clients:
+--------+------ +
| ID | client|
+--------+------ +
| 1 | Sony |
| 2 | Dell |
+--------+------ +
Users:
+--------+---------+------------+
| ID | name | department |
+--------+--------+-------------+
| 1 | John | 1|
| 2 | Dave | 2|
| 3 | Michael| 1|
| 4 | Rich | 3|
+--------+--------+-------------+
Time:
+--------+------+---------------------+------------+
| ID | user | clientid | time | date |
+--------+------+---------------------+------------+
| 1 | 1 | 1 | 01:00:00 | 2017-01-02 |
| 2 | 2 | 2 | 02:00:00 | 2017-01-02 |
| 3 | 1 | 2 | 04:00:00 | 2017-02-02 | -> Result Not Selected since date is different
| 4 | 4 | 1 | 02:00:00 | 2017-01-02 |
| 5 | 1 | 1 | 02:00:00 | 2017-01-02 |
+--------+------+---------------------+------------+
Result Table
+------------+--------+-----------+---------+----------+
| Client | John | Michael | Rich | Dave |
+------------+--------+-----------+---------+----------+
| Sony |3:00:00 | 0 | 2:00:00 | 0 |
+------------+--------+-----------+---------+----------+
| Dell | 0 | 0 | 0 | 2:00:00 |
+------------+--------+-----------+---------+----------+
First table Clients Contains information about clients.
Second table Users Contains information about users
Third Table Time contains rows of time for each users dedicated to different clients from the clients table.
So my goal is to make a SQL Query which will show the Result table. In other words it will select sum of hours which every user have completed for certain client. The number of clients and users is unknown. So first thing that have to be done is Select all users, no matter if they have hours completed or not. After that have to select each client and the sum of hours for each client which was realized for individual user.
The problem is I don't know how to approach this situation. Do I have first to make one query slecting all users then foreach them in the table header and then realize second query selecting the hours and foreaching the body conent, or this can be made with single query which will render the whole table.
The filters for select command are:
WHERE MONTH(`date`) = '$month'
AND YEAR(`date`) ='$year'
AND u.department = '$department'
Selecting single row for tume SUM is:
(SELECT SUM( TIME_TO_SEC( `time` ) ) FROM Time tm
WHERE tm.clientid = c.id AND MONTH(`date`) = '$month' AND YEAR(`date`) ='$year'
This is the query to select the times for a user , here by my logic this might be transformed with GROUP BY c.id (client id), and the problem is that it have to contains another WHERE clause which will specify the USER which is unknown. If the users was known value was for example 5, there is no problem to make 5 subsequent for each user WHERE u.id = 1, 2, 3 etc.
So here are the 2 major problems how to display in same query The users header and them select the sum of hours for each client corresponding the user.
Check out the result table hope to make the things clear.
Any suggestion or answer which can come to resolve this situation will be very helpful.
Thank you!

PHP reminders from API and local database

i am contacting an API in PHP that returns a loop of items with this information:
[domain_name] => domain.co.uk
[expiry_date] => 2016-06-18T02:27:04
i then have a table that contains columns for domain, reminder1, reminder2, reminder3
i am going to poll this URL throughout the day, every day and i want to send 'renewal reminders' for 30, 7 and 1 days before the expiry_date - each reminder will be stored in my database (reminder1, reminder2 and reminder3)
What is the best way to check if the reminders have already been sent?
I suggest you to change the database structure a bit to fit with this solution.
So for example you have the following tables:
Table domains:
+----+----------------------+
| id | domain_name |
+----+----------------------+
| 1 | domain1.com |
+----+----------------------+
| 2 | domain2.com |
+----+----------------------+
| 3 | domain3.com |
+----+----------------------+
Table domain_expiry
+----+--------------+----------------------+
| id | domain_id | expiry_date |
+----+--------------+----------------------+
| 1 | 1 | 2016-07-01 11:22:24 |
+----+--------------+----------------------+
| 2 | 1 | 2017-07-01 11:22:24 |
+----+--------------+----------------------+
| 3 | 2 | 2016-08-01 11:22:24 |
+----+--------------+----------------------+
Table reminders:
+----+-----------+---------------+------------+--------+
| id | expiry_id | reminder_type | date_sent | status |
+----+-----------+---------------+------------+--------+
| 1 | 1 | 1 | 2016-06-01 | 1 |
+----+-----------+---------------+---------------------+
| 2 | 1 | 2 | 2016-06-23 | 1 |
+----+-----------+---------------+---------------------+
| 3 | 2 | 1 | 2016-08-01 | 0 |
+----+-----------+---------------+---------------------+
Now, you should have a cron which runs daily/nightly ( say at 12:00 AM ), this cron shall do:
1- Pulls the domains and their latest expiry_date
2- Checks if the expiry_date of the domain matches the record in domain_expiry table, if matches do nothing, if doesn't match add a new records with domain_id and new expiry_date
3- Sends reminder according to domain latest expiry_date
4- Inserts the result of reminder sending process into reminders table
expiry_id,
reminder_type (1, 2, or 3),
the date when that reminder was sent, date_sent
and status (1 = success and 0 = failure)
Update
I updated my answer to allow the solution to keep history logs.

PHP Laravel view table design

I've been working on a project where I have 3 tables of dates, times and usernames and when I join them the last view is:
same date - same time - diff username
same date - same time - diff username
diff date - diff time - diff username
An example with real data would be:
2014-01-03 | 10.08 | alexrussell
2014-01-05 | 11.15 | geartz
2014-01-05 | 14.23 | geartz
2014-02-02 | 13.44 | alexrussell
2014-02-02 | 13.44 | geartz
2014-02-02 | 18.21 | alexrussell
What I'm trying is to create a table where the data that's the same from row to row is grouped:
-----------------------------------
| Date | Time | Username |
|------------|-------|--------------|
| 2014-01-03 | 10.08 | alexrussell |
|------------|-------|--------------|
| | 11.15 | geartz |
| 2014-01-15 |-------|--------------|
| | 14.23 | geartz |
|------------|-------|--------------|
| | | alexrussell |
| | 13.44 |--------------|
| 2014-02-02 | | geartz |
| |-------|--------------|
| | 18.21 | alexrussell |
-----------------------------------
I have 1 object and I'm using foreach to parse it. I tried several selects with distinct but that way, I can't include other objects in table so code gives error like 1 select with distinct for date and 1 for the rest which have "where" statement. I tried 1 object with several arrays in it but again since I'm using foreach, I can only fill 1 column and next column requires other object.
I also tried giving a rowspan per object count but It didn't work since I can't exactly get the user count.
There must be a way and I'm totally stuck on this. Probably I'm not the first one encountering a problem like this.

Categories