<?php
$page_security = 'SA_PROJECT_WORK_DONE';
$path_to_root = "../..";
include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");

include_once($path_to_root . "/projects/includes/db/work_done_entry_details_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_sites_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_items_db.inc");
include_once($path_to_root . "/projects/includes/ui/work_done_entry_ui.inc");

        
$js = '';

if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}


simple_page_mode(true);

$trans_no = 0;
if (isset($_GET["trans_no"]))
{
	$_POST["trans_no"] = $_GET["trans_no"];
}
if (isset($_POST["trans_no"]))
{
	$trans_no = $_POST["trans_no"];
}

$sep_pos = strpos($trans_no, "|");
$boq_item_id = substr($trans_no, 0, $sep_pos);

if(!(isset($_POST["project_site_id"]))){
    $_POST["project_site_id"] = substr($trans_no, $sep_pos+1);
}

//$site_id = 0;

page(_($help_context = "BOQ Item Workdone Details"), true, false, false, $js);

function display_project_boq_item_work_done($boq_item_id, $site_id)
{
    if(!($boq_item_id >= 0)){
        $boq_item_id = 0;
    }
    
    if(!($site_id >= 0)){
        $site_id = 0;
    }
    
    $result_a = view_boq_item_site_work_done_history($boq_item_id, $site_id);

    
    start_table(TABLESTYLE, "width=60%");

    $th = array(_("ID"),_("Date"), _("Unit"), 
                _("Quantity"), _("Comment"));
   
    table_header($th);

    while ($boq_item = db_fetch($result_a))
    {
        start_row();

        label_cell($boq_item["id"], "align=center");
        label_cell(sql2date($boq_item["tran_date"]), "align=center");
        label_cell($boq_item["unit"], "align=center");   
        amount_decimal_cell($boq_item["quantity"]);          
        label_cell($boq_item["comment"]);

    }
    
    end_table(1);

}

start_form();


$boq_item = get_project_boq_item_record($boq_item_id);
$project_id = $boq_item["project_id"];

display_heading2("Workdone Details of BOQ Item : "."[".$boq_item['code']."] - ".$boq_item['description']);

br();

start_table(TABLESTYLE, "width=30%");
    project_sites_list_row("Job :", "project_site_id", $project_id, null, "Select a job" , true);
    hidden('trans_no', $trans_no);
end_table();
        
br();

display_project_boq_item_work_done($boq_item_id, get_post('project_site_id'));

//submit_center_first('Recalculate_Poject_PA', _("Recalculate Payment Application Summaries"), '', 'default');

end_form();


end_page();
