1
I am trying to create a script that ascertains whether the fine for late payment of the termination is due.
The conditions are as follows::
1 - If the prior notice is indemnified or waived (select), and payment was made within 10 days (date), the fine is not due.
2 - If the prior notice was worked or deducted, and the payment was made after 1 day of 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, he always considers it due, even if the date doesn’t match.
An output example (wrong):
The shutdown date was 2015-04-01
Payment date was 2015-04-05
The difference between disconnection and payment is 4 day(s)
Notice has been indemnified
The fine is due.
I don’t know much about php, but you shouldn’t separate operators using parentheses, for example, in this expression ?
($tavis == "indenizado" || "dispensado" && $prazo > 10)
– Carlos
Aside from having some less visible problem of date format, it seems to be just this.
– Maniero
It would be nice to @Carlos reply.
– Maniero
In a
if
you put"true"
(string) and the othertrue
(Boolean). This is not the problem but it is good to be careful with these details– Lucas
Thanks Lucas, that was a mistake really, I was trying to switch to string to see if it worked, and I had changed all, then when I returned to true/false I forgot these quotes. I already fixed here, and made the changes that indicated below (parentheses) but not yet solved.
– gustavox
@bigown What may have gone wrong with the date format?
– gustavox
I don’t know, it’s always a possibility for whoever’s looking at the code but there’s no way to test it. Could be something else, this was just an example, not everything gives p/ identify just by looking at the code. The code has a lot of small problems but here in the commentary it is difficult to cite all. Even if they are not causing actual errors, it shows that there may be other things wrong without being visible.
– Maniero
I put the script in the codepad (http://codepad.org/Lz3IWpUm) and gave this error: Fatal error: Call to Undefined Function date_diff() on line 7. As this was the only thing of the code I got ready (right here in Sopt), I believe the error is there (not that the code is wrong, perhaps the use I gave it...). He gives the right exit from the days of difference, but somehow does not consider it in the condition...
– gustavox
Friend just a hint, use
isset(...)
– Guilherme Nascimento