<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_PROJECT_STATUS_VIEW';
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/trace.php");
$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(900, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
	
page(_($help_context = "Project Status View"), @$_REQUEST['popup'], false, "", $js);

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 . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/projects/includes/db/approve_projects_db.inc");
include_once($path_to_root . "/projects/includes/db/project_sites_db.inc");
include_once($path_to_root . "/projects/includes/db/project_approval_path_db.inc");
include_once($path_to_root . "/projects/includes/db/project_serial_categories_db.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");

include_once($path_to_root . "/projects/includes/db/project_boq_item_groups_db.inc");
include_once($path_to_root . "/projects/includes/ui/project_boq_item_groups_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_task_detail_types_db.inc");

include_once($path_to_root . "/projects/includes/ui/project_status_view_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_status_view_db.inc");
include_once($path_to_root . "/projects/includes/db/approve_projects_db.inc");
include_once($path_to_root . "/projects/includes/db/unapproved_project_budgets_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_billing_schedule_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_expenses_schedule_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");

        
        
if(isset($_POST['Recalculate_BOQ_Item_Groups'])){
    
    recalculate_boq_item_groups(get_post('project_id'));
    display_note("BOQ Item Groups have been recalculated.");    
}


//-------------------------------------------------------------------------------------------- 

if (!isset($_POST['project_id'])){
//	$_POST['project_id'] = get_global_project_id();
}
else{
    $project_id = $_POST['project_id'];
}

start_form(true);

//start_table();
start_table(TABLESTYLE_NOBORDER);

    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('Select a project'), true);
        submit_cells('SearchOrders', _("Display"),'',_('Search'), '');
    end_row();
 
   
end_table(1);

//set_global_project_id($_POST['project_id']);

global $Ajax;

$Ajax->activate('proj_status_tbl');

$from_date = INFINITE_START_DATE;
$to_date = INFINITE_END_DATE;
        
div_start('proj_status_tbl');
if(isset($_POST['project_id']) && $_POST['project_id'] > 0){
    $dep_approved_all_budgets_total = display_project_details($_POST['project_id'], $from_date, $to_date); 
        
    
    br(2);
    start_outer_table(TABLESTYLE_NOBORDER, "width=80%");
    display_project_profit_and_loss($_POST['project_id'], $from_date, $to_date);
    
    $id_user = $_SESSION['wa_current_user']->user;
//    if($id_user == 1 || $id_user == 27){
        echo "</td><td valign=top>"; // outer table
        display_project_cost_allocations($_POST['project_id'], $from_date, $to_date);
        br(2);
        
//        $link = "<a href='$path_to_root/dashboard/project_gallery.php?project_id=".$_POST['project_id']."' target=_blank>" ." View Project Images" . "</a>";
//        display_note(text_bold($link));
//        br(2);
        
        display_project_petty_cash_expenses($_POST['project_id'], $from_date, $to_date);
        
        display_project_collections($_POST['project_id'], $from_date, $to_date);
        
        br(2);
        
        display_project_expenses_schedule_details($_POST['project_id'], 100);
//    }
    end_outer_table();

    
    br(2);
    submit_center_first('Recalculate_BOQ_Item_Groups', _("Recalculate BOQ Item Group Summaries"), '', 'default');
    echo(get_project_trans_view_str(ST_PROJECT_BOQ_ITEM_GROUPS_SUMMARY, $_POST['project_id'], "<b>View BOQ Item Group Details</b>"));

    br(2);
   
    display_task_category_summary($_POST['project_id'], $dep_approved_all_budgets_total);
    
    br(2);
    display_project_billing_details($_POST['project_id']);
    
            
}

br(1);


div_end();


hidden('popup', @$_REQUEST['popup']);

end_form();

//------------------------------------------------------------------------------------

end_page(@$_REQUEST['popup']);



?>
