Scale of services by turns in php

3

I plan to create a monthly shift schedule. I have 4 turns:

  • T.M = Morning shift (11 helpers this shift, but each day    3)

  • T.T = Afternoon shift (there are 5 aids this shift, but each day       2)

  • T.I = Intermediate Shift (there are 4 assistants this turn, but each day       2)

  • T.N = Night Shift (there are 4 assistants this turn, but each day       2)

  • F = Gaps

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 spare 1, the following week work 3 nights and spare 1.

I wanted to create a table for each month that generated the schedule automatically by shift, but I have not found a way to do that yet.

At this point I thought of this logic that I will present, but it does not form the scale as I intend and I think 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 to this, I created 1 trab in mysql: Table with employee types:

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;
    
asked by anonymous 26.10.2018 / 10:02

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 calculates and returns the result, remember to put it in a loop to fill the table.

Obs2 : Remember to change the value of the flag in your loop every time you use the method.

    
03.11.2018 / 07:06