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

//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');

$date_created = new input();
$date_created->type("hidden");
$date_created->name("date_created");
$date_created->id("date_created");
$date_created->placeholder("DATE CREATED");
$date_created->value($current_date);

$product_name_label = new label();
$product_name_label->for("product_name");
$product_name_label->value("PRODUCT NAME");

$product_name = new input();
$product_name->type("text");
$product_name->name("product_name");
$product_name->id("product_name");
$product_name->placeholder("PRODUCT NAME");
$product_name->style("width: 95%;margin:1vw auto;");

$cultivar_label = new label();
$cultivar_label->for("cultivar");
$cultivar_label->value("CULTIVAR");

$cultivar = new input();
$cultivar->type("text");
$cultivar->name("cultivar");
$cultivar->id("cultivar");
$cultivar->placeholder("CULTIVAR");
$cultivar->style("width: 95%;margin:1vw auto;");

$supplier_name_label = new label();
$supplier_name_label->for("supplier_name");
$supplier_name_label->value("SUPPLIER NAME");

$supplier_name = new input();
$supplier_name->type("text");
$supplier_name->name("supplier_name");
$supplier_name->id("supplier_name");
$supplier_name->placeholder("SUPPLIER NAME");
$supplier_name->onchange("createsupplierID()");
$supplier_name->style("width: 95%;margin:1vw auto;");

$supplier_batch_id_label = new label();
$supplier_batch_id_label->for("supplier_batch_id_label");
$supplier_batch_id_label->value("SUPPLIER BATCH ID");

$supplier_batch_no = new input();
$supplier_batch_no->type("text");
$supplier_batch_no->name("supplier_batch_no");
$supplier_batch_no->id("supplier_batch_no");
$supplier_batch_no->placeholder("SUPPLIER BATCH ID");
$supplier_batch_no->style("width: 95%;margin:1vw auto;");
$supplier_batch_no->readonly();


$farm_name = new input();
$farm_name->type("text");
$farm_name->name("farm_name");
$farm_name->id("farm_name");
$farm_name->placeholder("FARM NAME");
$farm_name->style("width: 95%;margin:1vw auto;");

$farm_name_label = new label();
$farm_name_label->for("farm_name");
$farm_name_label->value("FARM NAME");


$crop_year_label = new label();
$crop_year_label->for("crop_year");
$crop_year_label->value("CROP YEAR");

$crop_year = new input();
$crop_year->type("text");
$crop_year->name("crop_year");
$crop_year->id("crop_year");
$crop_year->placeholder("CROP YEAR");
$crop_year->style("width: 95%;margin:1vw auto;");

$delivery_date_label = new label();
$delivery_date_label->for("delivery_date");
$delivery_date_label->value("DELIVERY DATE");

$delivery_date = new input();
$delivery_date->type("datetime-local");
$delivery_date->name("delivery_date");
$delivery_date->id("delivery_date");
$delivery_date->placeholder("DELIVERY DATE");
$delivery_date->style("width: 95%;margin:1vw auto;");

$country_of_origin_label = new label();
$country_of_origin_label->for("country_of_origin");
$country_of_origin_label->value("COUNTRY OF ORIGIN");

$country_of_origin = new input();
$country_of_origin->type("text");
$country_of_origin->name("country_of_origin");
$country_of_origin->id("country_of_origin");
$country_of_origin->placeholder("COUNTRY OF ORIGIN");
$country_of_origin->style("width: 95%;margin:1vw auto;");

$purchase_order_no_label = new label();
$purchase_order_no_label->for("purchase_order_no");
$purchase_order_no_label->value("PURCHASE ORDER NO");

$purchase_order_no = new input();
$purchase_order_no->type("text");
$purchase_order_no->name("purchase_order_no");
$purchase_order_no->id("purchase_order_no");
$purchase_order_no->placeholder("PURCHASE ORDER NO");
$purchase_order_no->style("width: 95%;margin:1vw auto;");

$description_of_package_label = new label();
$description_of_package_label->for("description_of_package");
$description_of_package_label->value("DESCRIPTION OF PACKAGING");

$description_of_package = new input();
$description_of_package->type("text");
$description_of_package->name("description_of_package");
$description_of_package->id("description_of_package");
$description_of_package->placeholder("DESCRIPTION OF PACKAGING");
$description_of_package->style("width: 95%;margin:1vw auto;");

$box_no_label = new label();
$box_no_label->for("box_no");
$box_no_label->value("NUMBER OF BOXES/CONTAINERS");

$box_no = new input();
$box_no->type("number");
$box_no->name("boxes_no");
$box_no->id("boxes_no");
$box_no->placeholder("NUMBER OF BOXES/CONTAINERS");
$box_no->style("width: 95%;margin:1vw auto;");

$box_tracking_no_label = new label();
$box_tracking_no_label->for("box_tracking_no");
$box_tracking_no_label->value("BOX/CONTAINER TRACKING NO");

$box_tracking_no = new input();
$box_tracking_no->type("text");
$box_tracking_no->name("box_tracking_no");
$box_tracking_no->id("box_tracking_no");
$box_tracking_no->placeholder("BOX/CONTAINER TRACKING NO");
$box_tracking_no->style("width: 95%;margin:1vw auto;");

$sampled_box_no_label = new label();
$sampled_box_no_label->for("sampled_box_no");
$sampled_box_no_label->value("NUMBER OF SAMPLED BOXES/CONTAINERS");

$sampled_box_no = new input();
$sampled_box_no->type("number");
$sampled_box_no->name("sampled_box_no");
$sampled_box_no->id("sampled_box_no");
$sampled_box_no->placeholder("NUMBER OF SAMPLED BOXES/CONTAINERS");
$sampled_box_no->style("width: 95%;margin:1vw auto;");

$total_weight_label = new label();
$total_weight_label->for("total_weight");
$total_weight_label->value("TOTAL WEIGHT(Kg)");

$total_weight = new input();
$total_weight->type("number");
$total_weight->name("total_weight");
$total_weight->id("total_weight");
$total_weight->placeholder("TOTAL WEIGHT(Kg)");
$total_weight->style("width: 95%;margin:1vw auto;");

$total_dnis_delivered_label = new label();
$total_dnis_delivered_label->for("total_dnis_delivered");
$total_dnis_delivered_label->value("TOTAL DNIS DELIVERED @ 1.5% k.m (kg)");

$total_dnis_delivered = new input();
$total_dnis_delivered->type("number");
$total_dnis_delivered->name("total_dnis_delivered");
$total_dnis_delivered->id("total_dnis_delivered");
$total_dnis_delivered->placeholder("TOTAL DNIS DELIVERED (Kg)");
$total_dnis_delivered->style("width:95%;margin:1vw auto;");

$total_wnis_delivered_label = new label();
$total_wnis_delivered_label->for("total_wnis_delivered");
$total_wnis_delivered_label->value("TOTAL WINS DELIVERED EXCLUDING SMALLS (kg)");

$total_wnis_delivered = new input();
$total_wnis_delivered->type("number");
$total_wnis_delivered->name("total_wnis_delivered");
$total_wnis_delivered->id("total_wnis_delivered");
$total_wnis_delivered->placeholder("TOTAL WINS DELIVERED (Kg)");
$total_wnis_delivered->style("width:95%;margin:1vw auto;");

$damaged_boxes_label = new label();
$damaged_boxes_label->for("damaged_boxes");
$damaged_boxes_label->value("NUMBER OF DAMAGED BOXES/SPILLAGE");

$damaged_boxes = new select();
$damaged_boxes->name("damaged_boxes");
$damaged_boxes->id("damaged_boxes");
$damaged_boxes->class("inputs");
$damaged_boxes->add_option("", "damaged_boxes");
$damaged_boxes->add_option("Yes", "Yes");
$damaged_boxes->add_option("No", "No");
$damaged_boxes->style("width: 95%;margin:1vw auto;");

$damages_no = new input();
$damages_no->type("number");
$damages_no->name("damages_no");
$damages_no->id("damages_no");
$damages_no->placeholder("NUMBER OF DAMAGED BOXES");
$damages_no->style("width: 95%;margin:1vw auto;");

$comments_label = new label();
$comments_label->for("comments");
$comments_label->value("COMMENTS");

$damages_comment = new input();
$damages_comment->type("text");
$damages_comment->name("comments");
$damages_comment->id("comments");
$damages_comment->placeholder("COMMENTS");
$damages_comment->style("width: 95%;margin:1vw auto;");

$documents_received_confimation_label = new label();
$documents_received_confimation_label->for("documents_received_confimation");
$documents_received_confimation_label->value("DOCUMENTS CONFIRMED TO GOODS RECEIVED");

$documents_received_confimation = new select();
$documents_received_confimation->name("documents_received_confimation");
$documents_received_confimation->id("documents_received_confimation");
$documents_received_confimation->class("inputs");
$documents_received_confimation->add_option("", "documents received confimation");
$documents_received_confimation->add_option("Yes", "Yes");
$documents_received_confimation->add_option("No", "No");
$documents_received_confimation->style("width: 95%;margin:1vw auto;");

$documents_comment = new input();
$documents_comment->type("text");
$documents_comment->name("documents_comment");
$documents_comment->id("documents_comment");
$documents_comment->placeholder("COMMENTS");
$documents_comment->style("width: 95%;margin:1vw auto;");

$purchase_order_option = new select();
$purchase_order_option->name("purchase_order_option");
$purchase_order_option->id("purchase_order_option");
$purchase_order_option->class("inputs");
$purchase_order_option->add_option("", "purchase order");
$purchase_order_option->add_option("Yes", "Yes");
$purchase_order_option->add_option("No", "No");

$submit_btn = new button();
$submit_btn->class("submit_btn");
$submit_btn->value("Submit");
$submit_btn->onclick("oder_details()");

?>

<div class="form_down">
    <h1>ORDER INFORMATION</h1><br>
    <style>
        table,
        th,
        td {
            border: 2px solid black;
            border-collapse: collapse;
            padding: 5px;
        }
    </style>

    <table id="order_details_table" style="width: 95%;">
        <tr style="background-color:#004aad80;">
            <th colspan="3">
                <h3>ORDER DETAILS</h3>
            </th>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $product_name_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $product_name->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $cultivar_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $cultivar->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $supplier_name_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $supplier_name->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $supplier_batch_id_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $supplier_batch_no->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $farm_name_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $farm_name->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $crop_year_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $crop_year->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $delivery_date_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $delivery_date->add();
                ?>
            </td>
        </tr>
        <tr>
            <td width="50%">
                <?php
                $country_of_origin_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $country_of_origin->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $purchase_order_no_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $purchase_order_no->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $description_of_package_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $description_of_package->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $box_no_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $box_no->add()
                    ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $box_tracking_no_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $box_tracking_no->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $sampled_box_no_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $sampled_box_no->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $total_weight_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $total_weight->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $total_dnis_delivered_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $total_dnis_delivered->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $total_wnis_delivered_label->add();
                ?>
            </td>
            <td colspan="2">
                <?php
                $total_wnis_delivered->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $damaged_boxes_label->add();
                ?>
            </td>
            <td>
                <?php
                $damaged_boxes->add();
                ?>
            </td>
            <td>
                <?php
                $damages_no->add();
                $damages_comment->add();
                ?>
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                <?php
                $documents_received_confimation_label->add();
                ?>
            </td>
            <td>
                <?php
                $documents_received_confimation->add();
                ?>
            </td>
            <td>
                <?php
                
                $documents_comment->add();
                ?>
            </td>
        </tr>
    </table>
    
    <?php
    $submit_btn->add(); 
    ?>
</div>

<?php

$oder_details_ajax = new js_ajax();
$oder_details_ajax->function_name("oder_details");
$oder_details_ajax->insert("");
$oder_details_ajax->on_success("");
$oder_details_ajax->redirect("");