<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_COST_INQ';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");

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

include_once($path_to_root . "/projects/includes/db/project_cost_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/project_cost_allocation_inquiry_db.inc");
include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "Project Cost Allocations"), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;
if ($_GET['task_id'] != "")
{
	$task_id = $_GET['task_id'];
}



function display_project_task_details($task_id)
{
    $task = view_task_details($task_id);
    
    display_heading("Budget : ".$task['task_code']." - ".$task['description']);

    br();
    
    start_table(TABLESTYLE2, "width=90%");
    start_row();
    label_cells(_("Project"), $task['project_description'], "class='tableheader2'");
        label_cells(_("Total Budget"), number_format($task['budget'],2), "class='tableheader2'","align=right");
    
    end_row();

    start_row();
    label_cells(_("BOQ Item Group"), $task['boq_item_group_description'], "class='tableheader2'");
        $task_cost_link = get_task_cost_details_view_str($task['task_id'], number_format($task['budget_used'],2));
        label_cells(_("Budget Used"), $task_cost_link, "class='tableheader2'","align=right");
    end_row();
    
    start_row();
    label_cells(_("Budget"), $task['description'], "class='tableheader2'");
        label_cells(_("Budget Allocated"), number_format($task['budget_allocated'],2), "class='tableheader2'", "align=right");
    end_row();
    
    start_row();
    label_cells(_("Detail Type"), $task['detail_type_name'], "class='tableheader2'");
        $available =  + (float)$task['budget'] - (float)$task['budget_used'] - (float)$task['budget_allocated'] ;
//        $available =  - (float)$task['budget_used'] ;
        label_cells(_("Budget Available"), number_format($available,2), "class='tableheader2'", "align=right");
    end_row();

    end_table();
}

function display_project_cost_allocation_details($task_id)
{
    global $systypes_array;
    
    $th = array(("Id"),_("Tran Type"), _("Tran No"),
            _("Date"),_("Amount"), "Total Cost");
    
    start_table(TABLESTYLE2, "width=90%");

    table_header($th);
    
    start_row();

    $result = view_project_cost_allocation_details($task_id);
    while ($myrow = db_fetch($result)) {
        start_row();
        label_cell($myrow['id'], "align=center");
        label_cell($systypes_array[$myrow['tran_type']]);
        label_cell(get_trans_view_str($myrow['tran_type'], $myrow['tran_no']), "align=center");
        label_cell($myrow['updated_on'], "align=center");
        amount_cell($myrow['amount']);
        amount_cell($myrow['total_allocation']);
        end_row();

        
    }
    
    end_table();
}

display_project_task_details($task_id);
br(1);
display_project_cost_allocation_details($task_id);

end_page(true, false, false, ST_WORKORDER, $woid);

?>
