vendredi 16 août 2019

How to fix an IF Statement error in PHP where it get into the first one only?

I'm doing a program where inserting some dates (start and end of a contract work), it gaves you what to use for calculating payments. I've wrote this PHP code to do all the comparisons and then give only the answer, but, it isn't working correctly because it keeps taking only the first IF, or the last one.

Any date I enter, it always gives me the same output string. When in theory it should change.

I've already a similar program but in Excel, and I'm converting it in WebApp to be used from any platform without any problem.

HTML Page (very easy):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="AlterVista - Editor HTML"/>
<title></title>
</head>
<body>
<form action="provaAEC.php" method="POST">
Inizio Mandato: <input type="date" name="start"/><br><br>
Fine Mandato: <input type="date" name="end" /><br><br>
<input type="submit"/>
</form>
</body>
</html>

PHP Code:

<html>
<body>

<?php
$start = $_REQUEST['start'];
$end = $_REQUEST['end'];
$primacondizioneinizio = 12/31/2013;
$primacondizionefine = 03/31/2017;
$secondacondizionefine = 04/01/2017;
$terzacondizioneinizio = 01/1/2014;
$terzacondizionefine = 12/31/2015;
$quartacondizioneinizio = 9/01/2014;
$dateTimestamp1 = strtotime($start); 
$dateTimestamp2 = strtotime($end);
$dateTimestamp3 = strtotime($primacondizioneinizio); 
$dateTimestamp4 = strtotime($primacondizionefine); 
$dateTimestamp5 = strtotime($secondacondizionefine); 
$dateTimestamp6 = strtotime($terzacondizioneinizio); 
$dateTimestamp7 = strtotime($terzacondizionefine); 
$dateTimestamp8 = strtotime($quartacondizioneinizio);

if ($dateTimestamp1 <= $dateTimestamp3 and $dateTimestamp2 <= $dateTimestamp4)
{
   echo "Si applicano gli AEC 2002";
}
elseif ($dateTimestamp1 <= $dateTimestamp3 and $dateTimestamp2 >= $dateTimestamp5)
{
   echo "Si applicano gli AEC 2002 fino al 31/12/2015 e gli AEC 2014 a partire dal 01/01/2016";
}
elseif ($dateTimestamp1 >= $dateTimestamp6 and $dateTimestamp2 <= $dateTimestamp7)
{
    echo "Si applicano gli AEC 2002 per interpretazione logica";
}
elseif ($dateTimestamp1 >= $dateTimestamp8)
{
    echo "Si applicano gli AEC 2014";
}
?>

</body>
</html>

It should works like this: Contracts signed up to 31/12/2013 and terminated within the 31/03/2017 -> "Si applicano gli AEC 2002"

Contracts signed up to 31/12/2013 and terminated within the 01/04/2017 -> "Si applicano gli AEC 2002 fino al 31/12/2015 e gli AEC 2014 a partire dal 01/01/2016"

Contracts signed up from 01/01/2014 and terminated within the 31/12/2015 -> "Si applicano gli AEC 2002 per interpretazione logica"

Contracts signed up from 01/09/2014 -> "Si applicano gli AEC 2014"

but, it isn't at all...

If you want, you can see it here (my test platform): http://www.bilatogiulio.altervista.org/provaAEC.html

Aucun commentaire:

Enregistrer un commentaire