<?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 . "/includes/data_checks.inc");


include_once($path_to_root . "/projects/includes/db/project_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.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);

$task_group_id = 0;

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


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

function display_task_group_header($myrow)
{

//    $myrow = view_task_group_header($task_group_id);
    
    display_heading("Budget Group ".$myrow['code']." - ".$myrow['description']);
    
    br();
    
    

    start_table(TABLESTYLE2, "width=50%");

    start_row();

//    $iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $myrow['iou_id']);
//    label_cells(_("I Owe You No"), $iou_link, "class='tableheader2'");
//    end_row();
    label_cells(_("Type"), $myrow['type_name'], "class='tableheader2'");
    end_row();
    label_cells(_("Code"), $myrow['code'], "class='tableheader2'");
    end_row();
    label_cells(_("Description"), $myrow['description'], "class='tableheader2'");
    end_row();
    

    label_cells(_("Start Date"), sql2date($myrow['start_date']), "class='tableheader2'");
    end_row();
    label_cells(_("End Date"), sql2date($myrow['end_date']), "class='tableheader2'");
    end_row();
    label_cells(_("Long Description"), $myrow['long_description'], "class='tableheader2'");
    end_row();
    
    if($myrow['boq_group_id'] > 0){
        $s = get_project_trans_view_str(ST_PROJECT_BOQ_ITEM_GROUP, $myrow['project_id']."|".$myrow['boq_group_id'], $myrow['boq_group_code']." - ".$myrow['boq_group_description']);
    }
    else{
        $s = get_project_trans_view_str(ST_PROJECT_BOQ_ITEM_GROUP, $myrow['project_id']."|0", "No BOQ item group");
    }
    label_cells(_("BOQ Item Group"), $s, "class='tableheader2'");
    end_row();
    
    end_table();
    
}

function display_task_group_tasks($project_id, $task_group_id)
{
     br();
    
    display_heading2("Budgets");
    
    start_table(TABLESTYLE, "width=90%");

    $th = array(_("Detail Type"),_("Category"), 
                "Budget Id", //_("Budget Code"), _("Budget Description"), 
                _("Budget"), _("Budget Used"), _("Budget Allocated"), "Budget Available");

    table_header($th);

    $k = 0;
    
    $tasks_list = get_task_group_tasks($project_id, $task_group_id);
    while ($myrow = db_fetch($tasks_list))
    {
        alt_table_row_color($k);

//        label_cell($myrow["detail_type_id"]);
        
        label_cell($myrow["detail_type_name"]);
        label_cell($myrow["category_name"]);
        
        label_cell($myrow["task_id"]);
        
        
//        label_cell($myrow["task_code"]);
//        label_cell($myrow["description"]);
        if(isset($myrow["task_id"]) && $myrow["task_id"] > 0){
            amount_decimal_cell($myrow["budget"]);
            $task_cost_link = get_task_cost_details_view_str($myrow['task_id'], number_format($myrow['budget_used'],2));
            label_cell($task_cost_link, "align=right");
            //amount_cell($myrow["budget_used"]);
            $task_allocation_link = get_task_cost_allocation_details_view_str($myrow['task_id'], number_format($myrow['budget_allocated'],2));
            label_cell($task_allocation_link, "align=right");
//            amount_cell($myrow["budget_allocated"]);
            amount_cell($myrow["budget"] - ($myrow["budget_used"] + $myrow["budget_allocated"]));
        }
        else{
            label_cell('');label_cell('');label_cell('');label_cell('');
        }
        
        end_row();

    }

    end_table();
}

start_form();

$task_group = view_task_group_header($task_group_id);

display_task_group_header($task_group);

display_task_group_tasks($task_group['project_id'], $task_group_id);

end_form();


end_page();
