Scale of shift services in php

Asked

Viewed 956 times

3

I intend to create a monthly shift schedule. I’ve got four shifts:

  • T.M = Morning shift (has 11 assistants this shift, but on each day break 3)

  • T.T = Afternoon shift (has 5 assistants this shift, but on each day break 2)

  • T.I = Intermediate shift (has 4 assistants this shift, but on each day break 2)

  • T.N = Night Shift (has 4 assistants this shift, but in each day break 2)

  • F = Leave

In the morning, afternoon and intermediate shift the cycle is work 4 days and play 1. In the night shift the cycle is in a week work 2 nights and take off 1, in the following week work 3 nights and take off 1.

I wanted to create a table for each month that would automatically generate the time scale per shift, but I haven’t found a way to do so yet.

At this moment I thought of this logic that I will present, but it does not shape the scale as I intend and I think that the error is in logic:

<?php
$diasDaSemana=array(
    "segunda-feira"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "terça-feira"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "quarta-feira"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "quinta-feira"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "sexta-feira"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "sábado"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    ),
    "domingo"=>array(
        "tm"=>array(
            "ativos"=>5,
            "folgas"=>3
        ),
        "tt"=>array(
            "ativos"=>4,
            "folgas"=>1
        ),
        "tt2"=>array(
            "ativos"=>2,
            "folgas"=>2
        ),
        "tn"=>array(
            "ativos"=>1,
            "folgas"=>0
        ),
        "tr"=>array(
            "ativos"=>3,
            "folgas"=>2
        )
    )
);

foreach ($diasDaSemana as $dias => $turnos) {
    foreach ($turnos as $turno => $value) {
        $limiteAtivo = $value["ativo"];
        $limiteFolga = $value["folga"];
        $selectAtivo="SELECT * FROM colaboradores WHERE turno='$turno' ORDER BY ultimaFolga ASC LIMIT $limiteAtivo";
        $selectAtivo="SELECT * FROM colaboradores WHERE turno='$turno' ORDER BY ultimaFolga DESC LIMIT $limiteFolga";
    }
}

In addition I created 1 work in mysql: Table with types of collaborators:

CREATE TABLE `Colaboradores` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `id_colaborador` int(11) DEFAULT NULL,
  `ultimaFolga` date DEFAULT NULL,
  `turno` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  • Friend, To make it a little clearer, the assistants can be registered in more than one shift? Or are exclusive of a certain shift?

  • @Irahe Kasprzykowski In all shifts they are auxiliary, and the rotary auxiliaries can also do any shift.

1 answer

3


You can solve this with a method to create the table. something like the code below can help you solve the problem:

function calculaFolga($turno, $ultimaFolga, $flagFolga){ //recebe como parâmetro a ultima folga, o turno e uma flag (booleana) para continuar calculando a folga do turno noturno 
  if($turno != 'tn'){ //caso não seja o turno noturno ele sempre vai adicionar 4 dias
    return $ultimaFolga + 4;
  }else{// sendo o turno noturno ele vai decidir com o valor da flag qual "punição" aplicar
    if($flagFolga){ // se for true ele trabalhou 2 dias, sua próxima folga será em mais três dias
      return $ultimaFolga + 3;
    }else{ // se for false ele trabalhou 3 dias e vai adicionar 4 dias para a próxima folga
      return $ultimaFolga + 4;
    }
  }
}

Obs1: note that the function works with return, so it only does the calculation and returns the result, remember to put it in a loop to fill the table.

Obs2: remember to change the flag value in your loop each time you use the method.

Browser other questions tagged

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