<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

//GET THE NUMBER OF ROWS IN THE JOBCARDS TABLE AND ADD 1
$jobcard_res = $db->query("jobcards", "SELECT * FROM jobcards WHERE record_id = '" . $_GET['record_id'] . "' ORDER BY record_id DESC");
$jobcard_data = $jobcard_res->fetch_assoc();


//get today's date and add 2 hours to the time
$today = new DateTime();
$today->modify('+2 hours');
$current_date = $today->format('Y-m-d' . ' ' . 'H:i');

//get the seeion user id
$user_id = $_SESSION['user_id'];

$date = new input();
$date->class("inputs");
$date->type("hidden");
$date->name("date_created");
$date->style("display: none;");
$date->value($current_date);
$date->id("date_created");

$record_id = new input();
$record_id->name("record_id");
$record_id->id("record_id");
$record_id->value($_GET['record_id']);
$record_id->type("hidden");

$jobcard_number = new input();
$jobcard_number->class("inputs");
$jobcard_number->type("text");
$jobcard_number->placeholder("JOBCARD NO");
$jobcard_number->name("jc_no");
$jobcard_number->id("jc_no");
$jobcard_number->value($jobcard_data['jc_no']);
$jobcard_number->required();
$jobcard_number->readonly();

$jobcard_number_label = new label();
$jobcard_number_label->for("jc_no_label");
$jobcard_number_label->value("JOBCARD NO");

$phone = new input();
$phone->class("inputs");
$phone->type("text");
$phone->placeholder("PHONE NUMBER");
$phone->name("contact_number");
$phone->required();
$phone->id("contact_number");
$phone->value_from_db("jobcards", "contact_number", "record_id = {$_GET['record_id']}");

$other_number = new input();
$other_number->class("inputs");
$other_number->type("text");
$other_number->placeholder("OTHER NUMBER");
$other_number->name("other_number");
$other_number->id("other_number");
$other_number->value_from_db("jobcards", "other_number", "record_id = {$_GET['record_id']}");

$alternate_number = new input();
$alternate_number->class("inputs");
$alternate_number->type("text");
$alternate_number->placeholder("ALTERNATE NUMBER");
$alternate_number->name("alternate_number");
$alternate_number->id("alternate_number");
$alternate_number->value_from_db("jobcards", "alternate_number", "record_id = {$_GET['record_id']}");

$contact_number_label = new label();
$contact_number_label->for("contact_number");
$contact_number_label->value("CONTACT NUMBER");

$other_number_label = new label();
$other_number_label->for("other_number");
$other_number_label->value("OTHER NUMBER");

$alternate_number_label = new label();
$alternate_number_label->for("alternate_number");
$alternate_number_label->value("ALTERNATE NUMBER");







//////////////////////////////////////////////////////////////////////////////////////////////////////

$date_created_label = new label();
$date_created_label->for("date_created");
$date_created_label->value("DATE CREATED");

$date_created = new input();
$date_created->class("inputs");
$date_created->type("text");
$date_created->placeholder("DATE CREATED");
$date_created->name("date_created");
$date_created->style("font-size:1em;");
$date_created->readonly();
$date_created->id("date_created");
$date_created->value_from_db("jobcards", "date_created", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////

$action_date_label = new label();
$action_date_label->for("action_date");
$action_date_label->value("ACTION DATE");

$action_date = new input();
$action_date->class("inputs");
$action_date->type("text");
$action_date->placeholder("ACTION DATE");
$action_date->name("action_date");
$action_date->style("font-size:1em;");
$action_date->id("action_date");
$action_date->value_from_db("jobcards", "action_date", "record_id = {$_GET['record_id']}");


//////////////////////////////////////////////////////////////////////////////////////////////////////

$date_closed_label = new label();
$date_closed_label->for("date_time_closed");
$date_closed_label->value("DATE CLOSED");

$date_closed = new input();
$date_closed->class("inputs");
$date_closed->type("text");
$date_closed->placeholder("DATE CLOSED");
$date_closed->name("date_time_closed");
$date_closed->required();
$date_closed->style("font-size:1em;");
$date_closed->id("date_time_closed");
$date_closed->value_from_db("jobcards", "date_time_closed", "record_id = {$_GET['record_id']}");


//////////////////////////////////////////////////////////////////////////////////////////////////////

$user_opened_label = new label();
$user_opened_label->for("user_id");
$user_opened_label->value("USER CREATED");

$user_id = new select();
$user_id->class("inputs");
$user_id->name("user_id");
$user_id->style("font-size:1em;");
$user_id->id("user_id");
$user_id->value_from_db("jobcards", "user_id", "record_id = {$_GET['record_id']}");
$user_id->fill_from_db("users", "record_id", "username");

//////////////////////////////////////////////////////////////////////////////////////////////////////

$user_assigned_label = new label();
$user_assigned_label->for("user_assigned");
$user_assigned_label->value("USER ASSINGED");

$user_assigned = new select();
$user_assigned->class("inputs");
$user_assigned->name("user_assigned");
$user_assigned->style("font-size:1em;");
$user_assigned->id("user_assigned");
$user_assigned->value_from_db("jobcards", "user_assigned", "record_id = {$_GET['record_id']}");
$user_assigned->fill_from_db("users", "record_id", "username");



//////////////////////////////////////////////////////////////////////////////////////////////////////

$client_label = new label();
$client_label->for("client_id");
$client_label->value("Client");

$client_id = new select();
$client_id->class("inputs");
$client_id->name("client_id");
$client_id->style("font-size:1em;");
$client_id->id("client_id");
$client_id->value_from_db("jobcards", "client_id", "record_id = {$_GET['record_id']}");
$client_id->fill_from_db("clients", "record_id", "name");



//////////////////////////////////////////////////////////////////////////////////////////////////////

$drill_co_ordinates_label = new label();
$drill_co_ordinates_label->for("drill_co_ordinates");
$drill_co_ordinates_label->value("CO-ORDINATES");

$drill_co_ordinates = new input();
$drill_co_ordinates->class("inputs");
$drill_co_ordinates->name("drill_co_ordinates");
$drill_co_ordinates->readonly();
$drill_co_ordinates->style("font-size:1em;");
$drill_co_ordinates->id("drill_co_ordinates");
$drill_co_ordinates->value_from_db("jobcards", "drill_co_ordinates", "record_id = {$_GET['record_id']}");


//////////////////////////////////////////////////////////////////////////////////////////////////////

$contact_name_label = new label();
$contact_name_label->for("contact_name");
$contact_name_label->value("CONTACT NAME");

$contact_name = new input();
$contact_name->class("inputs");
$contact_name->name("contact_name");
$contact_name->style("font-size:1em;");
$contact_name->id("contact_name");
$contact_name->value_from_db("jobcards", "contact_name", "record_id = {$_GET['record_id']}");



//////////////////////////////////////////////////////////////////////////////////////////////////////

$payment_method_label = new label();
$payment_method_label->for("payment_method");
$payment_method_label->value("PAYMENT METHOD");

$payment_method = new select();
$payment_method->class("inputs");
$payment_method->name("payment_method");
$payment_method->style("font-size:1em;");
$payment_method->id("payment_method");
$payment_method->add_option("Cash", "Cash");
$payment_method->add_option("0", "N/A");
$payment_method->add_option("EFT", "EFT");
$payment_method->value_from_db("jobcards", "payment_method", "record_id = {$_GET['record_id']}");


//////////////////////////////////////////////////////////////////////////////////////////////////////

$cash_amount_label = new label();
$cash_amount_label->for("cash_amount");
$cash_amount_label->value("CASH AMOUNT");

$cash_amount = new input();
$cash_amount->class("inputs");
$cash_amount->name("cash_amount");
$cash_amount->style("font-size:1em;");
$cash_amount->id("cash_amount");
$cash_amount->value_from_db("jobcards", "cash_amount", "record_id = {$_GET['record_id']}");


//////////////////////////////////////////////////////////////////////////////////////////////////////

$deposit_amount_label = new label();
$deposit_amount_label->for("deposite_amount");
$deposit_amount_label->value("DEPOSIT AMOUNT");

$deposit_amount = new input();
$deposit_amount->class("inputs");
$deposit_amount->name("deposite_amount");
$deposit_amount->style("font-size:1em;");
$deposit_amount->id("deposite_amount");
$deposit_amount->value_from_db("jobcards", "deposite_amount", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////


$estimated_liters_label = new label();
$estimated_liters_label->for("estimated_liters");
$estimated_liters_label->value("ESTIMATED LITERS");

$estimated_liters = new input();
$estimated_liters->class("inputs");
$estimated_liters->name("estimated_liters");
$estimated_liters->style("font-size:1em;");
$estimated_liters->id("estimated_liters");
$estimated_liters->value_from_db("jobcards", "estimated_liters", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////



$break_found_on_label = new label();
$break_found_on_label->for("break_found_on");
$break_found_on_label->value("BREAK FOUND ON");

$break_found_on = new input();
$break_found_on->class("inputs");
$break_found_on->name("break_found_on");
$break_found_on->style("font-size:1em;");
$break_found_on->id("break_found_on");
$break_found_on->value_from_db("jobcards", "break_found_on", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////


$diesel_start_label = new label();
$diesel_start_label->for("diesel_start");
$diesel_start_label->value("DIESEL START");

$diesel_start = new input();
$diesel_start->class("inputs");
$diesel_start->name("diesel_start");
$diesel_start->style("font-size:1em;");
$diesel_start->id("diesel_start");
$diesel_start->value_from_db("jobcards", "diesel_start", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////


$diesel_stop_label = new label();
$diesel_stop_label->for("diesel_stop");
$diesel_stop_label->value("DIESEL STOP");

$diesel_stop = new input();
$diesel_stop->class("inputs");
$diesel_stop->name("diesel_stop");
$diesel_stop->style("font-size:1em;");
$diesel_stop->id("diesel_stop");
$diesel_stop->value_from_db("jobcards", "diesel_stop", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////


$interested_in_pump_label = new label();
$interested_in_pump_label->for("interested_in_pump");
$interested_in_pump_label->value("INTERESTED IN PUMP");

$interested_in_pump = new select();
$interested_in_pump->class("inputs");
$interested_in_pump->name("interested_in_pump");
$interested_in_pump->style("font-size:1em;");
$interested_in_pump->id("interested_in_pump");
$interested_in_pump->add_option("NO", "NO");
$interested_in_pump->add_option("YES", "YES");
$interested_in_pump->value_from_db("jobcards", "interested_in_pump", "record_id = {$_GET['record_id']}");

//////////////////////////////////////////////////////////////////////////////////////////////////////

if (strlen($jobcard_data['slip_file']) > 1)
{



}



$team_assigned = new select();
$team_assigned->class("inputs");
$team_assigned->name("team_assigned_id");
$team_assigned->required();
$team_assigned->id("team_assigned_id");
$team_assigned->fill_from_db("teams", "record_id", "name");
$team_assigned->value_from_db("jobcards", "team_assigned_id", "record_id = {$_GET['record_id']}");

$team_assigned_label = new label();
$team_assigned_label->for("team_assigned");
$team_assigned_label->value("TEAM ASSIGNED");

$submit_btn = new button();
$submit_btn->value("UPDATE JOBCARD");
$submit_btn->onclick("update_jobcard()");

$other_number = new input();
$other_number->class("inputs");
$other_number->type("text");
$other_number->placeholder("OTHER NUMBER");
$other_number->name("other_number");
$other_number->required();
$other_number->id("other_number");
$other_number->value_from_db("jobcards", "other_number", "record_id = {$_GET['record_id']}");



$area_label = new label();
$area_label->for("area");
$area_label->value("AREA");

$area = new input();
$area->class("inputs");
$area->type("text");
$area->placeholder("AREA");
$area->name("address");
$area->required();
$area->id("address");
$area->value_from_db("jobcards", "address", "record_id = {$_GET['record_id']}");

?>
<style>

</style>
<div class="form_down">
    <h1>EDIT JOBCRD</h1>

    <?php
    $record_id->add();
    $jobcard_number_label->add();
    $jobcard_number->add();
    $date->add();
    $date->add();
    ?>

    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $date_created_label->add();
        $action_date_label->add();
        $date_closed_label->add();
        ?>
    </div>

    <div>
        <?php
        $date_created->add();
        $action_date->add();
        $date_closed->add();
        ?>
    </div>

    <h1>USER DETIALS</h1>


    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $user_opened_label->add();
        $team_assigned_label->add();

        $user_assigned_label->add();
        ?>
    </div>

    <div>
        <?php
        $user_id->add();
        $team_assigned->add();
        $user_assigned->add();

        ?>
    </div>

    <h1>CLIENT DETIALS</h1>

    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $client_label->add();
        $drill_co_ordinates_label->add();
        $area_label->add();
        ?>
    </div>
    <div>
        <?php
        $client_id->add();
        $drill_co_ordinates->add();
        $area->add();
        ?>
    </div>
    <?php
    $interested_in_pump_label->add();

    $interested_in_pump->add();

    $contact_name_label->add();
    $contact_name->add();
    ?>
    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $contact_number_label->add();
        $other_number_label->add();
        $alternate_number_label->add();
        ?>
    </div>
    <div>
        <?php
        $phone->add();
        $other_number->add();
        $alternate_number->add();
        ?>
    </div>
    <h1>FINANCES</h1>
    <?php
    $payment_method_label->add();
    $payment_method->add();
    ?>
    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $cash_amount_label->add();
        $deposit_amount_label->add();
        ?>
    </div>
    <div>
        <?php
        $cash_amount->add();
        $deposit_amount->add();
        ?>
    </div>

    <h1>OPERATIONS</h1>

    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $estimated_liters_label->add();
        $break_found_on_label->add();
        $diesel_start_label->add();
        ?>
    </div>
    <div>
        <?php
        $estimated_liters->add();
        $break_found_on->add();
        $diesel_start->add();

        ?>
    </div>

    <h1>DIESEL</h1>


    <div style="display: flex; width: 45%; justify-content: space-between;">
        <?php
        $diesel_start_label->add();
        $diesel_stop_label->add();
        ?>
    </div>
    <div>
        <?php
        $diesel_start->add();
        $diesel_stop->add();
        ?>
    </div>

    <?php









    $submit_btn->add();

    ?>
</div>

<?php

$ajax = new js_ajax();
$ajax->function_name("update_jobcard");
$ajax->submit_btn_id("submit_btn");
$ajax->update("jobcards");
$ajax->on_success("JOBCARD CREATED SUCCESSFULLY");
$ajax->redirect("../jobcards/home.php");

?>