<?php
include "db.class.php";
$db = new db();
$results = $db->exec_query('reset_date', ['*'], '', '', '', '', "record_id = 1");
$data = $results->fetch_assoc();
$date = date("Y-m-d H:i");
if ($data['day'] == date('d')) {
    echo "this day has been reset";
    $results = $db->exec_query("water", ['*'], '', '', '', '', "unit_id = 1", "ORDER BY record_id DESC LIMIT 1");
    $data = $results->fetch_assoc();
    $db->insert("INSERT INTO water_history (`unit_id`,`date`,`pulses`) VALUES (1,'$date',{$data['count']})");
    $results = $db->exec_query("water", ['*'], '', '', '', '', "unit_id = 2", "ORDER BY record_id DESC LIMIT 1");
    $data = $results->fetch_assoc();
    $db->insert("INSERT INTO water_history (`unit_id`,`date`,`pulses`) VALUES (2,'$date',{$data['count']})");
    $results = $db->exec_query("water", ['*'], '', '', '', '', "unit_id = 3", "ORDER BY record_id DESC LIMIT 1");
    $data = $results->fetch_assoc();
    $db->insert("INSERT INTO water_history (`unit_id`,`date`,`pulses`) VALUES (3,'$date',{$data['count']})");

    $db->insert("DELETE FROM water WHERE 1");

    // $random_1 = rand(2908461, 3038461);
    // $random_2 = rand(3000000, 3038461);
    // $random_3 = rand(2899999, 3038461);

    $db->insert("UPDATE actions SET `reset` = 1 WHERE record_id = 1 OR record_id = 2");
    // $db->insert("UPDATE actions SET `threshold` = $random_1 WHERE record_id = 1 ");
    // $db->insert("UPDATE actions SET `threshold` = $random_2 WHERE record_id = 2 ");
    // $db->insert("UPDATE actions SET `threshold` = $random_3 WHERE record_id = 3 ");

}


