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

$page_security = 'SA_PROJ_TASK_DETAIL_TYPES';
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 . "/projects/includes/db/project_task_detail_types_db.inc");



page(_($help_context = "Project Task Detail Types"));

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

simple_page_mode(true);

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


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

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

br();

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


if(isset($_POST['UPDATE_PTC']))
{
        $msg = "";
        
        $result = get_project_task_detail_types();
        
        delete_project_task_detail_types();
        
        while ($myrow = db_fetch($result)){
           
            $category_id = get_post("detail_type_category_".$myrow["id"]);
            $debit_account = get_post("debit_account_".$myrow["id"]);
            $credit_account = get_post("credit_account_".$myrow["id"]);
            
            add_project_task_detail_type($myrow["value_code"], $category_id, $debit_account, $credit_account);                        
                
        }
        
        $msg = ("Project Budget Detail Types has been updated.");
        display_notification($msg);
        $Mode = 'RESET';

}

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


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


$Ajax->activate('price_table');

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

$heading_text = "Project Task Detail Types";


display_heading($heading_text);

$dispaly_result = get_project_task_detail_types();
start_form();
div_start('price_table');

br();

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

$th = array(_("Detail Type Code"), _("Detail Type Name"), _("Catergory"), "Debit Account", "Credit Account");
     

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

$previous_rec_status = 0;

while ($myrow_a = db_fetch($dispaly_result))
{      
    alt_table_row_color($k);

    label_cell($myrow_a["value_code"]);
    label_cell($myrow_a["detail_type_name"]);
    if(!(isset($_POST['detail_type_category_'.$myrow_a["id"]]) && $_POST['detail_type_category_'.$myrow_a["id"]] > 0)){
        $_POST['detail_type_category_'.$myrow_a["id"]] = $myrow_a["detail_type_category_id"];
    }
    value_list_cells(null, 'detail_type_category_'.$myrow_a["id"], 'PROJECT_TASK_DETAIL_TYPE_CATEGORIES', null, false, false);
    
    gl_all_accounts_list_cells(null, 'debit_account_'.$myrow_a["id"], $myrow_a["debit_account"], false, false, 'Select an Account');
    gl_all_accounts_list_cells(null, 'credit_account_'.$myrow_a["id"], $myrow_a["credit_account"], false, false, 'Select an Account');
               
    end_row();
      
}

end_table();

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

br(2);

end_table();

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

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

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


?>
