<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_SALARY_COMP_GROUPING';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/db/sales_types_db.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/salary_component_grouping_db.inc");

if (!@$_GET['popup'])
	page(_($help_context = "Salary Component Grouping"));

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

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------
$input_error = 0;

if (isset($_GET['payroll_id']))
{
	$_POST['payroll_id'] = $_GET['payroll_id'];
}

if (!isset($_POST['payroll_id']))
	$_POST['payroll_id'] = get_global_payroll_id();


br();


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

function check_data($id)
{
        if (!check_num("print_seq".$id, 0))
        {
            display_error( _("Salary Component Grouping Id entered was not numeric or positive."));
            set_focus('seq_no');
            return false;
        }
        
        return true;

}

if(isset($_POST['UPDATE_SEQ']))
{
        $msg = "";
        
        $result = get_salary_component_grouping_details();
        
        delete_salary_component_grouping_details();
        
        while ($myrow = db_fetch($result)){

            if(check_data($myrow["id"])){
                    //$seq_no = input_num("seq_no".$myrow["id"]);
                    $print_ref = get_post("print_ref".$myrow["id"]);
                    $print_seq = get_post("print_seq".$myrow["id"]);
            }
            else{
                    $seq_no = 0;
                    $print_ref = 0;
                    $print_seq = 0;
            }
            
            add_salary_component_grouping_details($myrow["id"],
                            $print_ref, $print_seq);

                
        }
        
        $msg = _("Salary Grouping details has been updated.");
        display_notification($msg);
        $Mode = 'RESET';

}

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


if ($Mode == 'RESET')
{
	$selected_id = -1;
}


$Ajax->activate('price_table');

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

$heading_text = "Salary Component Grouping";


display_heading($heading_text);

$result = get_salary_component_grouping_details();
start_form();
div_start('price_table');

br();

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

$th = array(
      _("Component Type"), _("Component Code"), _("Component Name"), _("Component Group"), _("Print Seq."));

table_header($th);
$k = 0; 
$calculated = false;

$previous_rec_status = 0;

while ($myrow = db_fetch($result))
{
        $_POST["seq_no".$myrow["id"]] = 0;
                
        
        
        if($myrow["salary_group_id"] == null){
            $print_ref = '';
        }
        else{
            $print_ref = $myrow["salary_group_id"];
        }
        
        if($myrow["print_seq"] == null){
            $print_seq = '';
        }
        else{
            $print_seq = $myrow["print_seq"];
        }


	alt_table_row_color($k);

       
        hidden("list_value_id".$myrow["id"], $myrow["id"]);
        label_cell($myrow["list_name"]);
        label_cell($myrow["value_code"]);
        label_cell($myrow["comp_name"]);
        value_list_cells(null, 'print_ref'.$myrow["id"], "SALARY_COMPONENT_GROUPS",$myrow["salary_group_id"]," ");
        amount_cells_ex(null,"print_seq".$myrow["id"], 6, 10, $print_seq, null, null, 0);
       
        
        end_row();
        
       //$previous_rec_status = $myrow["active"];

}

end_table();

div_end();
//------------------------------------------------------------------------------------------------

br(2);


end_table();

submit_center('UPDATE_SEQ', _("Update"), true, '', 'default');

br();
end_form();
div_end();

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