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

$page_security = 'SA_PROJECT_STATUS_VIEW';
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();
	
page(_($help_context = "Employee Projects 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 . "/projects/includes/db/employee_projects_db.inc"); 
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc"); 
include_once($path_to_root . "/payroll/includes/db/employees_db.inc"); 
include_once($path_to_root . "/projects/includes/db/projects_db.inc");

start_form(true);

function display_employee_project_view_selecting_parameters() {
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            employees_simple_list_cells(_("Employee:"), 'employee_code', null, '', true);
            project_list_cells("Project", 'project_id', null, 'Select a project', true);
            date_cells('From Date:', 'from_date', 'From Date', null, 0, -1);
            date_cells('To Date:', 'to_date', 'To Date');

            submit_cells('SearchOrders', _("Display"),'',_('Search'), '');
        end_row();
    end_table(1);
}

function display_employee_project_view_details($employee_code, $project_id, $from_date_, $to_date_) {
    if (! (strlen($employee_code) > 0)) {
//        display_note("Please select an employee."); br(1);
//        return;
    }
    
    start_table(TABLESTYLE, "width=98%");

        $th = array(_("Id"), _("Employee"), _("Project"), _("BOQ Item"), _("Start Date"), _("End Date"), _("Days Assigned"), _("Days Worked"));
        table_header($th);

        $k = 0; //row colour counter
        $result = get_employee_project_view_detail($employee_code, $project_id, date2sql($from_date_), date2sql($to_date_));
            while ($row = db_fetch($result)) {
                alt_table_row_color($k);
                    label_cell($row["id"], 'align=center');
                    label_cell(get_employee_formatted_long_name($row["employee_code"]));
                    label_cell(get_project_formatted_name($row["project_id"]));
                    label_cell($row["boq_item_code"]." - ".$row["boq_item_name"]);
                    label_cell(sql2date($row["start_date"]), 'align=center');
                    label_cell(sql2date($row["end_date"]), 'align=center');
                    label_cell($row["days_per_month"], 'align=right');
                    if ($row["days_worked"] > 0) {
                        label_cell(get_project_trans_view_str(DASH_VW_EMPLOYEE_PROJECT_BOQ_ITEM_WORK_DONE, $row["id"], $row['days_worked']), "align=right");
                    } else {
                        label_cell('');
                    }
                end_row();
            }
    
    end_table(2);
}

    global $Ajax;
    
    display_employee_project_view_selecting_parameters();
    
    $Ajax->activate('employee_project_view');
    div_start('employee_project_view');
        display_employee_project_view_details($_POST['employee_code'], $_POST['project_id'], $_POST['from_date'], $_POST['to_date']); 
    div_end();

end_form();

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

?>