<?php
    session_start();

    require("../includes/database_connect.php");

    $electrical_id = $_POST['electrical_id'];
    $date_start = $_POST['date_start'];
    $date_expiry = $_POST['date_expiry'];
    $location = $_POST['location'];
    $taken_by = $_POST['taken_by'];
    $used_by = $_POST['used_by'];
    $price_rental = $_POST['price_rental'];
    $price_by = $_POST['price_by'];
  
    $timestamp =date('Y-m-d H:i:s');

    //var_dump($_POST);
    //die();
   
    $sql = "insert into electrical_history (electrical_id, date_start, date_expiry, location, taken_by, used_by, price_rental, price_by, rented_at) values ('$electrical_id','$date_start','$date_expiry','$location','$taken_by','$used_by','$price_rental', '$price_by', '$timestamp')";
    $sql2 = "update electrical set status='rented' where id='$electrical_id'";

    if ($conn->query($sql)) {
        $conn->query($sql2);
        $_SESSION['success'] = "Stock Rent successfully";
    } else {
        $_SESSION['error'] = "Error updating record: " . $conn->error;
    }
    
    header('location: ../electrical_listing.php?type='.$_POST['type']);
?>