<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_APPROVE_SALARY_AJUSTMENTS';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$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/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/payroll/includes/db/approve_salary_adjustments_db.inc");

simple_page_mode(true);

page(_($help_context = "Approve Salary Adjustments"));

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

start_form();


br();

function approve_salary_adjustments($id, $status_code)
{
    $type = substr($id,0,1);
    $row_id = substr($id,1);
    
    if($type == "A"){
        approve_salary_addition($row_id, $status_code);
    }
    elseif($type == "D"){
        approve_salary_deduction($row_id, $status_code);
    }
    elseif($type == "V"){
        approve_salary_advance($row_id, $status_code);
    }
    
}

$Ajax->activate('leaves');

div_start('leaves');

display_heading('Salary Additions');

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

$th = array(_("Id"),_("Employee Code"),_("Employee Name"), 
            _("Created On"),_("Type"),
            _("Amount"), _("Due Date"),
            _("Comment"),_("Action"),"Select");
table_header($th);

$j = 1;
$k=0; //row colour counter


if (isset($_POST['UpdateData']))
{
    $a_result = get_unapproved_salary_adjustments();
    
    while ($a_row = db_fetch($a_result))
    {

        if((isset($_POST["selected_".$a_row["rec_id"]])) &&
                ($_POST["selected_".$a_row["rec_id"]] == true))
        {
            $temp_name = 'leave_approval_status'.$a_row["rec_id"];

            approve_salary_adjustments($a_row["rec_id"], $_POST[$temp_name]);
        }
        display_notification(_("Salary adjustments have been approved."));
    }
}



$result_salary_additions=get_unapproved_salary_additions();
$result_salary_deductions=get_unapproved_salary_deductions();
$result_salary_advances=get_unapproved_salary_advances();

while ($myrow = db_fetch($result_salary_additions))
{

	alt_table_row_color($k);

        label_cell($myrow["id"],"align=center");
        label_cells('',$myrow["employee_code"]);
        label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
        
        
        label_cell(sql2date($myrow["created_on"]),"align=center");
        label_cells('',$myrow["type_name"],"align=center");
        //label_cells('',$myrow["amount"]);
        qty_cell($myrow["amount"], false, 2);
        label_cell(sql2date($myrow["due_date"]),"align=center");
        label_cells('',$myrow["comments"]);
        value_list_code_cells(null, 'leave_approval_status'.$myrow["rec_id"], "RECORD_APPROVAL_STATUS", $myrow["status_code"]);
        //label_cells('',$myrow["status_name"]);

        check_cells('', 'selected_'.$myrow["rec_id"],0, false, false, "align=center");

	end_row();
	$j++;
//	If ($j == 12)
//	{
//		$j = 1;
//		table_header($th);
//	}
}

end_table(1);

br();

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

display_heading('Salary Deductions');

$th = array(_("Id"),_("Employee Code"),_("Employee Name"), 
            _("Created On"),_("Type"),
            _("Amount"), _("Due Date"),
            _("Comment"),_("Action"),"Select");
table_header($th);

$j = 1;
$k=0; //row colour counter

while ($myrow = db_fetch($result_salary_deductions))
{

	alt_table_row_color($k);

        label_cell($myrow["id"],"align=center");
        label_cells('',$myrow["employee_code"]);
        label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
        
        
        label_cell(sql2date($myrow["created_on"]),"align=center");
        label_cells('',$myrow["type_name"],"align=center");
        //label_cells('',$myrow["amount"]);
        qty_cell($myrow["amount"], false, 2);
        label_cell(sql2date($myrow["due_date"]),"align=center");
        label_cells('',$myrow["comments"]);
        value_list_code_cells(null, 'leave_approval_status'.$myrow["rec_id"], "RECORD_APPROVAL_STATUS", $myrow["status_code"]);
        //label_cells('',$myrow["status_name"]);

        check_cells('', 'selected_'.$myrow["rec_id"],0, false, false, "align=center");
	end_row();
	$j++;
//	If ($j == 12)
//	{
//		$j = 1;
//		table_header($th);
//	}
}

end_table(1);

br();

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

display_heading('Salary Advances');

$th = array(_("Id"),_("Employee Code"),_("Employee Name"), 
            _("Created On"),_("Type"),
            _("Amount"), _("Date Date"),
            _("Comment"),_("Action"),"Select");
table_header($th);

$j = 1;
$k=0; //row colour counter

while ($myrow = db_fetch($result_salary_advances))
{

	alt_table_row_color($k);

        label_cell($myrow["id"],"align=center");
        label_cells('',$myrow["employee_code"]);
        label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
        
        
        label_cell(sql2date($myrow["created_on"]),"align=center");
        label_cells('',$myrow["type_name"],"align=center");
        //label_cells('',$myrow["amount"]);
        qty_cell($myrow["amount"], false, 2);
        label_cell(sql2date($myrow["due_date"]),"align=center");
        label_cells('',$myrow["comments"]);
        value_list_code_cells(null, 'leave_approval_status'.$myrow["rec_id"], "RECORD_APPROVAL_STATUS", $myrow["status_code"]);
        //label_cells('',$myrow["status_name"]);

        check_cells('', 'selected_'.$myrow["rec_id"],0, false, false, "align=center");

	end_row();
	$j++;
//	If ($j == 12)
//	{
//		$j = 1;
//		table_header($th);
//	}
}

end_table(1);




div_end();
submit_center('UpdateData', _("Update"), true, false, 'default');

br();

if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}
?>
