I'm trying to create a script that checks if the fine for late payment is due.
The conditions are as follows:
1 - If notice is indemnified or waived (select), and payment was made within 10 days (date), the fine is not due.
2 - If the notice was worked or discounted, and payment was made after 1 day after the dismissal, the fine is due.
3 - In other cases it is not due.
This is the code:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="_css/form2.css"/>
<title></title>
</head>
<body>
<form method="post" id="Tform" action="multaqss.php">
<label for="Cavis"><b>Aviso prévio</b><br>Como deve ser considerado o aviso prévio?</label><br>
<select name="Tavis" id="Cavis">
<option></option>
<option value="indenizado">indenizado</option>
<option value="dispensado">dispensado</option>
<option value="trabalhado">trabalhado</option>
<option value="descontado">descontado</option>
</select>
<br>
<label id="pagtss"><b>Desligamento</b></label><br>
<label for="Cdesl22">Qual a data do desligamento?</label><br>
<input type="date" name="Tdesl" id="Cdesl22" size="6"><br>
<label id="datapagto"><b>Data do pagamento</b></label><br>
<label for="Cdatapgtos">Qual a data em que foi realizado o pagamento?</label><br>
<input type="date" id="Cdatapgtos" name="Tdatapagtos"><br>
<input type="submit" value="enviar">
</form>
</body>
</html>
<?php
$tavis = $_POST ["Tavis"];
$fimcon = $_POST ["Tdesl"];
$pagtos = $_POST ["Tdatapagtos"];
$multaqss = false;
$prazo = date_diff(date_create($pagtos), date_create($fimcon))->format('%d');
if ($tavis == "indenizado" || "dispensado" && $prazo > 10){
$multaqss = true;
}
elseif ($tavis == "trabalhado" || "descontado" && $prazo > 1) {
$multaqss = true;
}
print "A data de desligamento foi $fimcon" . "<br>";
print "A data de pagamento foi $pagtos" . "<br>";
print "A diferença entre o desligamento e o pagamento é de $prazo dia(s)" . "<br>";
print "O aviso prévio foi $tavis" . "<br>";
if ($multaqss == false) {
echo "A multa não é devida" . "<br>";
}
else {
echo "A multa é devida." . "<br>";
}
?>
The problem is that no matter what I do, it always feels it's due, even if the date does not match.
An example of output (wrong):
The disconnection date was 2015-04-01
Payment date was 2015-04-05
The difference between shutdown and payment is 4 day (s)
Previous notice has been indemnified
The fine is due.