<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();

$user_record_id = new input();
$user_record_id->type("hidden");
$user_record_id->name("record_id");
$user_record_id->id("record_id");
$user_record_id->value($_SESSION['user_id']);
// HTML FORM ELEMENTS
$username = new input();
$username->class("inputs");
$username->type("text");
$username->placeholder("username");
$username->name("username");
$username->required();
$username->id("username");
$username->value_from_db("users", "username", "record_id = {$_SESSION['user_id']}");

$password = new input();
$password->class("inputs");
$password->type("text");
$password->placeholder("password");
$password->name("user_password");
$password->id("user_password");

$hourly_rate = new input();
$hourly_rate->class("inputs");
$hourly_rate->type("text");
$hourly_rate->placeholder("HOURLY RATE");
$hourly_rate->name("hourly_rate");
$hourly_rate->required();
$hourly_rate->readonly();
$hourly_rate->id("hourly_rate");
$hourly_rate->value_from_db("users", "hourly_rate", "record_id = {$_SESSION['user_id']}");


$leave_days_rate = new input();
$leave_days_rate->class("inputs");
$leave_days_rate->type("text");
$leave_days_rate->placeholder("Leave Days Per Month");
$leave_days_rate->name("leave_days_rate");
$leave_days_rate->required();
$leave_days_rate->readonly();
$leave_days_rate->id("leave_days_rate");
$leave_days_rate->value_from_db("users", "leave_days_rate", "record_id = {$_SESSION['user_id']}");

$work_days = new input();
$work_days->class("inputs");
$work_days->type("text");
$work_days->placeholder("Work Days Per Month");
$work_days->name("work_days");
$work_days->required();
$work_days->readonly();
$work_days->id("work_days");
$work_days->value_from_db("users", "work_days", "record_id = {$_SESSION['user_id']}");


$over_time_multiplier = new input();
$over_time_multiplier->class("inputs");
$over_time_multiplier->type("text");
$over_time_multiplier->placeholder("Over Time @");
$over_time_multiplier->name("over_time_multiplier");
$over_time_multiplier->required();
$over_time_multiplier->readonly();
$over_time_multiplier->id("over_time_multiplier");
$over_time_multiplier->value_from_db("users", "over_time_multiplier", "record_id = {$_SESSION['user_id']}");

$id_number = new input();
$id_number->class("inputs");
$id_number->type("text");
$id_number->placeholder("ID Number");
$id_number->name("id_number");
$id_number->required();
$id_number->id("id_number");
$id_number->value_from_db("users", "id_number", "record_id = {$_SESSION['user_id']}");

$bank_name = new input();
$bank_name->class("inputs");
$bank_name->type("text");
$bank_name->placeholder("BANK NAME");
$bank_name->name("bank_name");
$bank_name->required();
$bank_name->id("bank_name");
$bank_name->value_from_db("users", "bank_name", "record_id = {$_SESSION['user_id']}");

$branch_code = new input();
$branch_code->class("inputs");
$branch_code->type("text");
$branch_code->placeholder("BRANCH CODE");
$branch_code->name("branch_code");
$branch_code->required();
$branch_code->id("branch_code");
$branch_code->value_from_db("users", "branch_code", "record_id = {$_SESSION['user_id']}");

$account_number = new input();
$account_number->class("inputs");
$account_number->type("text");
$account_number->placeholder("ACCOUNT NUMBER");
$account_number->name("account_number");
$account_number->required();
$account_number->id("account_number");
$account_number->value_from_db("users", "account_number", "record_id = {$_SESSION['user_id']}");

$address = new input();
$address->class("inputs");
$address->type("text");
$address->placeholder("Address");
$address->name("address");
$address->required();
$address->id("address");
$address->value_from_db("users", "address", "record_id = {$_SESSION['user_id']}");

$travel_allowance_amount = new input();
$travel_allowance_amount->class("inputs");
$travel_allowance_amount->type("text");
$travel_allowance_amount->placeholder("Travel Allowance Rate");
$travel_allowance_amount->name("travel_allowance_amount");
$travel_allowance_amount->required();
$travel_allowance_amount->readonly();
$travel_allowance_amount->id("travel_allowance_amount");
$travel_allowance_amount->value_from_db("users", "travel_allowance_amount", "record_id = {$_SESSION['user_id']}");

$user_type_label = new label();
$user_type_label->for("user_type");
$user_type_label->value("User Type");

$submit_btn = new button();
$submit_btn->value("UPDATE");
$submit_btn->onclick("edit_user()");

$id_doc_label = new label();
$id_doc_label->class();
$id_doc_label->value("ID DOCUMENT");

$id_doc_pdf = new input();
$id_doc_pdf->type("submit");
$id_doc_pdf->class();
$id_doc_pdf->onclick("open_pdf(this.value)");
$id_doc_pdf->value_from_db("users", "id_doc", "record_id = {$_SESSION['user_id']}");

$id_file = new file_upload();
$id_file->id("id_doc");
$id_file->name("id_doc");
$id_file->file_save_path("app/users/documents/");
$id_file->class();
$id_file->style("width:90%;max-width:100%;");

$proof_of_address_label = new label();
$proof_of_address_label->class();
$proof_of_address_label->value("PROOF OF ADDRESS");

$proof_of_address = new file_upload();
$proof_of_address->id("proof_of_address");
$proof_of_address->name("proof_of_address");
$proof_of_address->file_save_path("app/users/documents/");
$proof_of_address->class();
$proof_of_address->style("width:90%;max-width:100%;");

$proof_of_address_pdf = new input();
$proof_of_address_pdf->type("submit");
$proof_of_address_pdf->class();
$proof_of_address_pdf->onclick("open_pdf(this.value)");
$proof_of_address_pdf->value_from_db("users", "proof_of_address", "record_id = {$_SESSION['user_id']}");

$proof_of_account_label = new label();
$proof_of_account_label->class();
$proof_of_account_label->value("PROOF OF BANK ACCOUNT");



$email = new input();
$email->class("inputs");
$email->type("text");
$email->placeholder("Email");
$email->name("email");
$email->required();
$email->id("email");
$email->value_from_db("users", "email", "record_id = {$_SESSION['user_id']}");

$proof_of_account = new file_upload();
$proof_of_account->id("proof_of_account");
$proof_of_account->name("proof_of_account");
$proof_of_account->file_save_path("app/users/documents/");
$proof_of_account->class();
$proof_of_account->style("width:90%;max-width:100%;");

$proof_of_account_pdf = new input();
$proof_of_account_pdf->type("submit");
$proof_of_account_pdf->class();
$proof_of_account_pdf->onclick("open_pdf(this.value)");
$proof_of_account_pdf->value_from_db("users", "proof_of_account", "record_id = {$_SESSION['user_id']}");

$db = new db_safeguard();
$leave_days_res = $db->query("leavedays_trans", "SELECT SUM(amount) as total FROM leavedays_trans WHERE user_id = '{$_SESSION['user_id']}' AND `status` = 1");
$leave_days = $leave_days_res->fetch_assoc()['total'];

$curent_leave_days = new input();
$curent_leave_days->value($leave_days);
$curent_leave_days->class();
$curent_leave_days->type('text');

// ajax
?>

<div class="form_down">
    <h1>MY ACCOUNT</h1>
    <?php
    $user_record_id->add();
    $username->add();
    $password->add();
    $email->add();
    $hourly_rate->add();
    $leave_days_rate->add();
    $work_days->add();
    $over_time_multiplier->add();
    $id_number->add();
    $address->add();
    $travel_allowance_amount->add();
    $id_doc_label->add();
    $id_doc_pdf->add();
    $id_file->add();
    $proof_of_address_label->add();
    $proof_of_address_pdf->add();
    $proof_of_address->add();
    $proof_of_account_label->add();
    $proof_of_account_pdf->add();
    $proof_of_account->add();
    $bank_name->add();
    $branch_code->add();
    $account_number->add();
    $submit_btn->add();
    ?>
    <div>
        <h1>LEAVE DAYS</h1>

        <?php $curent_leave_days->add();
        ?>
        <div class='row'>
            <div class='inputs'>STATUS</div>
            <div class='inputs'>DATE</div>
            <div class='inputs'>AMOUNT</div>
            <div class='inputs'>FROM</div>
            <div class='inputs'>TO</div>
        </div>

        <?php
        $leave_days_res = $db->query("leavedays_trans", "SELECT * FROM leavedays_trans WHERE user_id = '{$_SESSION['user_id']}' ORDER BY record_id DESC");
        function status($status_id)
        {
            if ($status_id == 0) {
                return "WAITING";
            }
            if ($status_id == 1) {
                return "APPROVED";
            }
            if ($status_id == 2) {
                return "DENIED";
            }
        }
        while ($leave = $leave_days_res->fetch_array()) {
            echo "<div class='row'><div class='inputs'>" . status($leave['status']) . "</div><div class='inputs'>{$leave['date']}</div><div class='inputs'>{$leave['amount']}</div><div class='inputs'>{$leave['start_date']}</div><div class='inputs'>{$leave['to_date']}</div></div>";
        }

        ?>
    </div>
</div>



<?php
$ajax = new js_ajax();
$ajax->function_name("edit_user");
$ajax->submit_btn_id("submit");
$ajax->update("users");
$ajax->on_success("SUCCESSFULLY UPDATED THE USER");
?>

<script>function open_pdf(value) { window.open("documents/" + value, "_blank"); }</script>