Monthly hours per shift

Asked

Viewed 419 times

5

I have to create a php button so when clicking generate a monthly turn time, but I don’t see how to do it. Can anyone suggest an idea?

What I’m thinking of is randomly choosing the contributions I need per day of each shift, but it’s making a mistake because of UNION and the ORDER BY.

This is the code I have:

SELECT * FROM centrodb.InfoColaboradores WHERE Turno = 'M' ORDER BY RAND() LIMIT 8
UNION
SELECT * FROM centrodb.InfoColaboradores WHERE Turno = 'T' ORDER BY RAND() LIMIT 4
UNION
SELECT * FROM centrodb.InfoColaboradores WHERE Turno = 'T2' ORDER BY RAND() LIMIT 3
UNION
SELECT * FROM centrodb.InfoColaboradores WHERE Turno = 'N' ORDER BY RAND() LIMIT 2;

This is my table structure:

1-Weekday table with fields: id, Days. In this table I put every day of the week as shown in the image:

inserir a descrição da imagem aqui

2-Table H_shift with the following fields: id, Shift, H_start, H_end. Table with the beginning and end of each turn as shown in the image:

inserir a descrição da imagem aqui

3- Table Infocontributors with the following fields: id, Contributor Name, Shift, Schedule. This indicates each employee’s turn and the hours they can do per day as shown in the image:

Do I have the structure of the tables well created?

The idea now is to create monthly random and automatically, where in the morning shift can only have 8 employees, the afternoon 4 employees, the afternoon 3 employees and the evening 2 employees.

Rules: If you work 4 days in a row 1 day off, if it’s 5 days 2 days off. Work a Sunday every 2 months

I used the code above with the Rand() I can create the first random selection of each turn.

This way I can start generating only automatically for the first day and only for the morning shift, but still no rules, code example:

SELECT NomeColaborador, centrodb.H_Turno.Turno, centrodb.H_Turno.H_inicio, centrodb.H_Turno.H_Fim, MONTH(NOW())
FROM centrodb.InfoColaboradores LEFT OUTER JOIN centrodb.H_Turno
ON centrodb.H_Turno.Turno = centrodb.InfoColaboradores.Turno
WHERE centrodb.H_Turno.Turno = 'M' ORDER BY RAND() LIMIT 8

How to generate this shift automatically for the month and not just for one day?

  • It is important that you make the excerpts more relevant than you have ever done.

  • I don’t have any code yet, because I’m not seeing a way to do it. Can’t you put an example? One of the rules is to create the monthly shift time, if the employee works 4 days in a row off one, if he works 5 days in a row off two and try to have everyone work at least one Sunday every two months.

  • This lacks the necessary rules to create this function. This is a classic computing problem called the backpack problem.

  • 3

    You see, from the moment you have exact control of the problem, you have control of the solution. Before you go into the code, scribble a lot and create scales in your hand. When you can do this on paper, it will be very easy to pass it to the code One tip I give you is to try to use simple solutions, such as scaling, where you create a "ladder" of gaps and variations. but as I said, take control of the problem and understand how to solve it first, as each case is a case A good starting point https://www.youtube.com/watch?v=T8dHReSgSQY

  • 2

    My dear, first of all, I recommend that you simplify your business rules, because of the following situations: (1) If it is difficult to understand and implement, it will be even more difficult to modify when new rules or future crossings arise; (2) If you need to implement a log of how the system generated the scale, to prevent against lawsuits, it will be almost impossible; (3) If someone needs to miss and you need to reschedule the scale, you will have serious problems; (4) You will waste a lot of time and development effort in a situation that delivers little value to the customer. Simplify.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.