<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
ini_set ("display_errors", "0");
error_reporting(E_ALL);
require("../connect.php");

$stmtVKP = mysqli_query($conn, "SELECT id, SUBSTRING(SEC_TO_TIME(field_1130), 4) AS timeharvest 
FROM app_entity_61 WHERE FROM_UNIXTIME(field_875, '%Y-%m-%d') = '".$_GET['harvestdate']."';");

while ($rowVKP = mysqli_fetch_assoc($stmtVKP)) {
    
    $timeharvest = new DateTime($rowVKP['timeharvest']);
    
    if ($timeharvest >= new DateTime('06:00') && $timeharvest <= new DateTime('07:00')) {
        mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 840 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 840);");
    } else if ($timeharvest > new DateTime('07:00') && $timeharvest <= new DateTime('08:00')) {
        mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 841 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 841);");
    } else if ($timeharvest > new DateTime('08:00') && $timeharvest <= new DateTime('09:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 842 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 842);");
    } else if ($timeharvest > new DateTime('09:00') && $timeharvest <= new DateTime('10:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 843 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 843);");
    } else if ($timeharvest > new DateTime('10:00') && $timeharvest <= new DateTime('11:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 844 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 844);");
    } else if ($timeharvest > new DateTime('11:00') && $timeharvest <= new DateTime('12:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 845 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 845);");
    } else if ($timeharvest > new DateTime('12:00') && $timeharvest <= new DateTime('13:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 846 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 846);");
    } else if ($timeharvest > new DateTime('13:00') && $timeharvest <= new DateTime('14:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 847 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 847);");
    } else if ($timeharvest > new DateTime('14:00') && $timeharvest <= new DateTime('15:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 848 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 848);");
    } else if ($timeharvest > new DateTime('15:00') && $timeharvest <= new DateTime('16:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 849 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 849);");
    } else if ($timeharvest >= new DateTime('16:00') && $timeharvest <= new DateTime('17:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 850 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 850);");
    } else if ($timeharvest > new DateTime('17:00') && $timeharvest <= new DateTime('18:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 851 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 851);");
    } else if ($timeharvest > new DateTime('18:00') && $timeharvest <= new DateTime('19:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 852 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 852);");
    } else if ($timeharvest > new DateTime('19:00') && $timeharvest <= new DateTime('20:00')) {
    	mysqli_query($conn, "UPDATE app_entity_61 SET field_3027 = 853 WHERE id = ".$rowVKP['id'].";");
    	mysqli_query($conn, "INSERT INTO app_entity_61_values (items_id, fields_id, value) VALUES (".$rowVKP['id'].", 3027, 853);");
    }
}

?>