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



function project_settings(&$project_id) 
{
	global $SysPrefs, $path_to_root, $new_item, $pic_height, $Refs, $Ajax;
        
        $Ajax->activate('customer_id');
        
        if(list_updated('project_id')){
            $_POST['_customer_id_edit'] = '';                        
            $_POST['customer_id'] = '';
        }

	start_outer_table(TABLESTYLE2);

	table_section(1);

	table_section_title(_("Projects"));
	//------------------------------------------------------------------------------------
	if ($new_item) 
	{
            if(isset($_POST['project_code_1'])){
                $project_code = $_POST['project_code_1'];
            }
            else{
                $project_code = '';
            }
            text_row("Code", "project_code", null, 25, 50);
            text_row(_("Description:"), 'description', null, 50, 200);
            textarea_row(_('Long Description:'), 'long_description', null, 31, 3);

            customer_list_row(_('Customer:'), 'customer_id', null, _('Select Customer') ,false);
            
            project_types_list_row(_("Type:"), 'type_id', null,"Select a project type");      
            value_list_row(_("Department:"), 'department_id', 'DEPARTMENTS', null,"Select a Department");      
            yesno_list_row("Purchase to Stock:", 'purchase_to_stock', null, 'Yes (No PR Issues)', 'No (PR Issues available)');
            
            
            date_row(_('Start date:'), 'project_start_date');
            date_row(_('End date:'), 'project_end_date');
            date_row(_('Frozen date:'), 'frozen_date');
            
            amount_row(_('Project Value:'), 'editing_project_value'); 
            amount_row(_('Estimated Project Cost:'), 'estimated_cost'); 
            amount_row(_('Minimum Overhead Percentage (over Project Value):'), 'overhead_percentage'); 
            
//            $budget_details = get_project_tasks_current_budgets_total($project_id);            
//            label_row("Department Approved Budgets Total:", number_format($budget_details['current_budgets_total'], 2));            
//            label_row("Unapproved Budget Total:", number_format($budget_details['unapproved_budgets_total'],2));
            
            yesno_list_row("Rate include taxes:", 'rate_include_taxes', null, 'Yes', 'No');
            
            
            user_list_row(_("Project Manager:"), 'project_manager_id', null, 'Select a project manager');
            text_row("Project Manager Name:", "project_manager_name", null, 50, 150);
            text_row("Contact Person:", "contact_person", null, 50, 150);

            value_list_row("Data Access Group:", 'data_access_group_id', 'DATA_ACCESS_GROUPS', null, 'Select a Data Access Group', false);
            
            label_row("Approval Status:", "");
            hidden('approved', 0);

            $fresh_item = !isset($_POST['NewProjectID']) || $new_item 
                || check_usage($_POST['project_id'],false);

            value_list_row("Project Status", 'project_status_id', "PROJECT_STATUS", null,'Select project status');
            record_status_list_row(_("Inactive:"), 'inactive');

            
//            table_section_title(_("Reference Structure"));
//                project_serial_category_list_row(_("Select a Company:"), 'company_category_code', null,
//                            _('Select a company'), true, 3,check_value('show_inactive')); 
//
//                ref_row(_("Group Serial No:"), 'group_serial_no', '', $Refs->get_next(103));
//
//                if($_POST['company_category_code'] != -1){
//                    $myrow = get_next_number($_POST['company_category_code']);
//                    $company_serial_no = $myrow["next_number"];
//                    label_row(_("Company Serial No:"), $company_serial_no);
//                    //text_row(_("Company Serial No:"), 'company_serial_no', $_POST['company_serial_no'], 20, 20);
//                }
//                else{
//                    label_row(_("Company Serial No:"), '');
//                }
//
//                value_list_code_row(_("Year:"), 'year', 'YEAR');
//
//                project_serial_category_list_row(_("Customer Category:"), 'customer_category_code', null,
//                            _('Select a customer'), true, 2,check_value('show_inactive'));
//
//                project_serial_category_list_row(_("Project Category:"), 'project_category_code', null,
//                            _('Select a project'), true, 1,check_value('show_inactive'));
//
//                if($_POST['project_category_code'] != -1){
//                    $result = get_next_number($_POST['project_category_code']);
//                    $project_category_code = $result["next_number"];
//
//                    label_row(_("Category Serial No:"), $project_category_code);
//                    //text_row(_("Category Serial No:"), 'project_category_code', $_POST['project_category_code'], 20, 20);
//                }
//                else{
//                    label_row(_("Category Serial No:"), '');
//                }
             //ref_row(_("Category Serial No:"), 'category_serial_no', '', $Refs->get_next(101));

            table_section(2);
            
            table_section_title(_("Accounts"));
                $company_record = get_company_prefs();
                if(!(isset($_POST['revenue_account']) && strlen($_POST['revenue_account']) > 1) || list_updated('project_id')){
                    $_POST['revenue_account']  = $company_record["default_proj_revenue_act"];
                }
                if(!(isset($_POST['cost_account']) && strlen($_POST['cost_account']) > 1) || list_updated('project_id')){
                    $_POST['cost_account']  = $company_record["default_proj_cost_act"];
                }
                gl_all_accounts_list_row(_("Revenue Account:"), 'revenue_account');
                gl_all_accounts_list_row(_("Cost Account:"), 'cost_account');
                gl_all_accounts_list_row(_("Employee Advances Account:"), 'employee_advances_account', null, true, false, "Select an account"); 


            end_outer_table(1);
                    
            $_POST['inactive'] = 0;
	} 
	else 
	{ // Must be modifying an existing item

                if (get_post('NewProjectID') != get_post('project_id') || get_post('addupdate')) { 
                // first item display
            
                        $_POST['NewProjectID'] = $_POST['project_id'];
			$myrow = get_project_details($_POST['NewProjectID']);
                        
                        set_post_not_set_string('project_code', $myrow["project_code"], 'project_id');
//			$_POST['project_code'] = $myrow["project_code"];
//                        $_POST['project_name'] = $myrow["project_name"];
//                        $_POST['long_description'] = $myrow["long_description"];
                        set_post_not_set_string('project_name', $myrow["project_name"], 'project_id');
                        set_post_not_set_string('long_description', $myrow["long_description"], 'project_id');
			set_post_not_set_string('description', $myrow["description"], 'project_id');
			set_post_not_set_numeric('project_manager_id', $myrow["project_manager_id"], 'project_id');
                        set_post_not_set_string('frozen_date', sql2date($myrow["budget_freeze_date"]), 'project_id');
                        
			$_POST['created_on']  = sql2date($myrow["created_on"]);
			$_POST['updated_on']  = sql2date($myrow["updated_on"]);
			$_POST['company_category_code']  = $myrow["company_category_code"];
                        $_POST['group_serial_no'] =  $myrow['group_serial_no'];
                        $_POST['customer_category_code'] =  $myrow['customer_category_code'];
			$_POST['year'] =  0;
			//$_POST['customer_category_code'] = $myrow['customer_category_code'];
			$_POST['project_category_code'] = "";
			$_POST['category_serial_no']	= 0;
			$_POST['company_serial_no']	= 0;	
                        
                        set_post_not_set_numeric('type_id', $myrow['type_id'], 'project_id');
                        set_post_not_set_numeric('department_id', $myrow['department_id'], 'project_id');
                        set_post_not_set_numeric('purchase_to_stock', $myrow['purchase_to_stock'], 'project_id');

                        if(!(isset($_POST['customer_id']) && $_POST['customer_id'] != '')){
//                            $_POST['_customer_id_edit'] = $myrow['customer_id'];                        
                            $_POST['customer_id'] = $myrow['customer_id'];
                        }

			set_post_not_set_string('project_manager_name', $myrow['project_manager_name'], 'project_id');
			set_post_not_set_string('contact_person', $myrow['contact_person'], 'project_id');
                        set_post_not_set_numeric('project_status_id', $myrow['project_status_id'], 'project_id');
                        
			set_post_not_set_numeric('inactive', $myrow['inactive'], 'project_id');
                        
                        set_post_not_set_string('project_start_date', sql2date($myrow['start_date']), 'project_id');
                        set_post_not_set_string('project_end_date', sql2date($myrow['end_date']), 'project_id');
                        
                        set_post_not_set_numeric('editing_project_value', $myrow['editing_project_value'], 'project_id');
                        set_post_not_set_numeric('estimated_cost', $myrow['estimated_cost'], 'project_id');
                        set_post_not_set_numeric('overhead_percentage', $myrow['overhead_percentage'], 'project_id');
                        set_post_not_set_numeric('rate_include_taxes', $myrow['rate_include_taxes'], 'project_id');

                        set_post_not_set_string('cost_account', $myrow['cost_account'], 'project_id');
                        set_post_not_set_string('revenue_account', $myrow['revenue_account'], 'project_id');
                        set_post_not_set_string('employee_advances_account', $myrow['employee_advances_account'], 'project_id');

                        set_post_not_set_numeric('data_access_group_id', $myrow['dag_id'], 'project_id');
                        
                        $_POST['approval_status'] = $myrow['approval_status'];
                        $_POST['approved_cost_budgets_total'] = $myrow['approved_cost_budgets_total'];
                        $_POST['approved_overhead_budgets_total'] = $myrow['approved_overhead_budgets_total'];
                        

                        /*
			$_POST['project_code'] = $myrow["project_code"];
                        $_POST['project_name'] = $myrow["project_name"];
                        $_POST['long_description'] = $myrow["long_description"];
			$_POST['description'] = $myrow["description"];
			$_POST['project_manager_id'] = $myrow["project_manager_id"];
                        $_POST['frozen_date'] = sql2date($myrow['budget_freeze_date']);
                        
			$_POST['created_on']  = sql2date($myrow["created_on"]);
			$_POST['updated_on']  = sql2date($myrow["updated_on"]);
			$_POST['company_category_code']  = $myrow["company_category_code"];
                        $_POST['group_serial_no'] =  $myrow['group_serial_no'];
                        $_POST['customer_category_code'] =  $myrow['customer_category_code'];
			$_POST['year'] =  $myrow['year_value'];
			//$_POST['customer_category_code'] = $myrow['customer_category_code'];
			$_POST['project_category_code'] = $myrow['project_category_code'];
			$_POST['category_serial_no']	= $myrow['category_serial_no'];
			$_POST['company_serial_no']	= $myrow['company_serial_no'];	
                        
                        $_POST['type_id'] = $myrow['type_id'];
                        $_POST['department_id'] = $myrow['department_id'];
                        $_POST['purchase_to_stock'] = $myrow['purchase_to_stock'];

                        if(!(isset($_POST['customer_id']) && $_POST['customer_id'] != '')){
//                            $_POST['_customer_id_edit'] = $myrow['customer_id'];                        
                            $_POST['customer_id'] = $myrow['customer_id'];
                        }

			$_POST['project_manager_name']	= $myrow['project_manager_name'];
			$_POST['contact_person']	= $myrow['contact_person'];
                        $_POST['project_status_id']	= $myrow['project_status_id'];
                        
                        
                        
			$_POST['inactive'] = $myrow['inactive'];
                        $_POST['project_start_date'] = sql2date($myrow['start_date']);
                        $_POST['project_end_date'] = sql2date($myrow['end_date']);
                        $_POST['editing_project_value'] = $myrow['editing_project_value'];
                        $_POST['estimated_cost'] = $myrow['estimated_cost'];
                        $_POST['overhead_percentage'] = $myrow['overhead_percentage'];
                        $_POST['rate_include_taxes'] = $myrow['rate_include_taxes'];

                        $_POST['cost_account'] = $myrow['cost_account'];
                        $_POST['revenue_account'] = $myrow['revenue_account'];

                        $_POST['data_access_group_id'] = $myrow['dag_id'];
                        
                        $_POST['approval_status'] = $myrow['approval_status'];
                        $_POST['approved_cost_budgets_total'] = $myrow['approved_cost_budgets_total'];
                        $_POST['approved_overhead_budgets_total'] = $myrow['approved_overhead_budgets_total'];
                         * /
                         */
                        
		}
                
//                        $Ajax->activate('_customer_id_edit');
        
        
                label_row("No:", $_POST['project_id']);

                text_row("Code", "project_code", null, 25, 50);

                text_row(_("Description:"), 'description', null, 50, 200);

                textarea_row(_('Long Description:'), 'long_description', null, 31, 3);
                //hidden('NewProjectID', $_POST['NewProjectID']);

                customer_list_row(_('Customer:'), 'customer_id', null,  _('Select Customer') ,false);
                
                project_types_list_row(_("Type:"), 'type_id', null,"Select a project type");  
                value_list_row(_("Department:"), 'department_id', 'DEPARTMENTS', null, "Select a department");
                yesno_list_row("Purchase to Stock:", 'purchase_to_stock', null, 'Yes (No PR Issues)', 'No (PR Issues available)');


                
        //        $customer = get_customer($_POST['customer_id']);
        //        label_row(_('Customer:'), $customer['debtor_ref'] . " - ". $customer['name']);
        //        hidden('customer_id', $_POST['customer_id']);
        
                date_row(_('Start date:'), 'project_start_date');
                date_row(_('End date:'), 'project_end_date');
                date_row(_('Frozen date:'), 'frozen_date');
                
                amount_row(_("Project Value:"), 'editing_project_value');
                amount_row(_("Estimated Project Cost:"), 'estimated_cost');
                amount_row(_('Minimum Overhead Percentage (over Project Value):'), 'overhead_percentage');

                

                yesno_list_row("Rate include taxes:", 'rate_include_taxes', null, 'Yes', 'No');
                
//                table_section_title(_("Reference Structure"));
                
                user_list_row(_("Project Manager:"), 'project_manager_id', null, 'Select a project manager');
                text_row("Project Manager Name:", "project_manager_name", null, 50, 150);
                text_row("Contact Person:", "contact_person",null, 50, 150);
        

        //            $fresh_item = !isset($_POST['NewProjectID']) || $new_item 
        //                    || check_usage($_POST['project_id'],false);

                value_list_row("Data Access Group:", 'data_access_group_id', 'DATA_ACCESS_GROUPS', null, 'Select a Data Access Group', false);

                global $approval_statuses;
                $s = get_project_trans_view_str(ST_APPROVAL_LOG, $_POST['project_id']."&source_type_id=".ST_APPROVE_PROJECT, "Approval Status");
                label_row($s,$approval_statuses[$_POST['approval_status']]);

        //        hidden('approved', $_POST['approved']);
                value_list_row("Project Status", 'project_status_id', "PROJECT_STATUS", null, 'Select project status');
                record_status_list_row(_("Inactive:"), 'inactive');
        
                table_section(2);
                table_section_title(_("Values"));
                label_row("Project Approved Cost Budgets Total:", number_format($_POST['approved_cost_budgets_total'],2));
                label_row("Project Approved Overhead Budgets Total:", number_format($_POST['approved_overhead_budgets_total'],2));

                $current_budgets_total = $unapproved_budgets_total = 0;
                $budget_details = get_project_tasks_current_budgets_total($_POST['project_id']);
                if(isset($budget_details['current_budgets_total']) && $budget_details['current_budgets_total'] > 0 ){
                    $current_budgets_total = $budget_details['current_budgets_total'];
                    $unapproved_budgets_total = $budget_details['unapproved_budgets_total'];
                }
                label_row("Department Approved All Budgets Total:", number_format($current_budgets_total,2));
                label_row("Unapproved All Budgets Total:", number_format($unapproved_budgets_total,2));
                
                
//                table_section_title(_("Reference Structure"));
//                label_row(_("Name:"),$_POST['project_name']);
//                label_row(_("Company Code:"),$_POST['company_category_code']);
//                label_row(_("Group Serial No:"),$_POST['group_serial_no']);
//                label_row(_("Company Serial No:"),$_POST['company_serial_no']);
//                label_row(_("Year:"),$_POST['year']);
//                label_row(_("Customer Category:"),$_POST['customer_category_code']);
//                label_row(_("Project Category:"),$_POST['project_category_code']);
//                label_row(_("Category Serial No:"),$_POST['category_serial_no']);

                table_section_title(_("Accounts"));
                gl_all_accounts_list_row(_("Revenue Account:"), 'revenue_account', $_POST['revenue_account']);
                gl_all_accounts_list_row(_("Cost Account:"), 'cost_account', $_POST['cost_account']);
                gl_all_accounts_list_row(_("Employee Advances Account:"), 'employee_advances_account', $_POST['employee_advances_account'], true, false, "Select an account"); 

                end_outer_table(1);
//                set_focus('description');

	}
        
    div_start('controls');
    if (!isset($_POST['NewProjectID']) || $new_item) 
    {
            submit_center('addupdate', _("Add New Project"), true, '', 'default');
    } 
    else 
    {
            submit_center_first('addupdate', _("Update Project"), '', @$_REQUEST['popup'] ? true : 'default');

//            submit_return('select', get_post('project_id'), _("Select this items and return to document entry."), 'default');
            //submit('clone', _("Clone This Item"), true, '', true);
            submit('delete', _("Delete This Project"), true, '', true);
            submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
            
            br();
            
            submit_center_first('Release_Project_For_Department_Users', "Release (To Department Users)", '', 'default');
    }

    div_end();
}




function check_project_require_approval($project_id)
{
    
    $old_project = get_project_record($project_id);
    
    if(date2sql($_POST['project_start_date']) != $old_project['start_date']){
        return true;
    }
    if(date2sql($_POST['project_end_date']) != $old_project['end_date']){
        return true;
    }
    if($_POST['revenue_account'] != $old_project['revenue_account']){
        return true;
    }
    if($_POST['cost_account'] != $old_project['cost_account']){
        return true;
    }

    if(input_num('editing_project_value') != $old_project['project_value']){
        return true;
    }
    
    return false;
}

    
function can_save_project($new_item){
    $input_error = 0;
 
    if (!(strlen($_POST['project_code']) > 1)){
        $input_error = 1;
        display_error( _("Code can not be empty"));
        set_focus('project_code');
        return false;
    }
    
    if (!(strlen($_POST['description']) > 1)){
        $input_error = 1;
        display_error( _("Description can not be empty"));
        set_focus('description');
        return false;
    }
    
    if(!($_POST['type_id'] > 0)) 
    {
        $input_error = 1;
        display_error( _('Please select a project type.'));
        set_focus('type_id');
        return false;
    }
    
    if(!($_POST['department_id'] > 0)) 
    {
        $input_error = 1;
        display_error( _('Please select a department.'));
        set_focus('department_id');
        return false;
    }
    
    if (is_date($_POST['project_start_date']) == FALSE){

        $input_error = 1;
        display_error( _("Incorrect start date"));
        set_focus('project_start_date');
        return false;
    }
    
    if (is_date($_POST['project_end_date']) == FALSE){

            $input_error = 1;
            display_error( _("Incorrect end date"));
            set_focus('project_end_date');
            return false;
    }
        
    if (date1_greater_date2($_POST['project_start_date'], $_POST['project_end_date']))
    {
            $input_error = 1;
            display_error( _("Project end date can not be greater than task start date"));
            set_focus('project_end_date');
            return false;
    }

        
    if (check_num('editing_project_value', 0) == false) 
    {
            $input_error = 1;
            display_error( _('Project value must be numeric and positive.'));
            set_focus('editing_project_value');
            return false;
    }  
         
    if (check_num('estimated_cost', 0) == false) 
    {
            $input_error = 1;
            display_error( _('Project estimated cost must be numeric and positive.'));
            set_focus('estimated_cost');
            return false;
    } 
        
    if (check_num('overhead_percentage', 0) == false) 
    {
            $input_error = 1;
            display_error( _('Minimum overhead percentage must be numeric and positive.'));
            set_focus('overhead_percentage');
            return false;
    } 
        

    if (is_date($_POST['frozen_date']) == false)
    {
            $input_error = 1;		
            display_error( _("Budget freeze date is not a valid date"));		
            set_focus('frozen_date');		
            return false;		
    }
            
    
    if(!($_POST['project_manager_id'] > 0)) 
    {
        $input_error = 1;
        display_error( _('Please select a project manager.'));
        set_focus('project_manager_id');
        return false;
    }
    
    if(!($_POST['data_access_group_id'] > 0)) 
    {
        $input_error = 1;
        display_error( _('Please select a Data Access Group.'));
        set_focus('data_access_group_id');
        return false;
    } 
    
    if(!($_POST['project_status_id'] > 0)) 
    {
        $input_error = 1;
        display_error( _('Please select a project status.'));
        set_focus('project_status_id');
        return false;
    }
    
    
    if($new_item)
    {
//        if ($_POST['company_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a company.'));
//                set_focus('company_category_code');
//                return false;
//        } 
//        if (strlen($_POST['group_serial_no']) == 0) 
//        {
//                $input_error = 1;
//                display_error( _('The group serial number must be entered.'));
//                set_focus('group_serial_no');
//                return false;
//        } 
//        if (check_num('group_serial_no', 0) == FALSE)
//        {
//                $input_error = 1;
//                display_error( _("Group serial number must be numeric."));
//                set_focus('group_serial_no');
//                return false;
//        }
//         if ($_POST['customer_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a customer category.'));
//                set_focus('customer_category_code');
//                return false;
//        } 
//        if ($_POST['project_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a project.'));
//                set_focus('project_category_code');
//                return false;
//        }
    }
        

    
    return true;
}


function save_project(&$new_item, $project_id)
{
    global $Ajax;
    
    if(can_save_project($new_item)){
        
        $project_manager_id = 0;
        if($_POST['project_manager_id'] > 0){
            $project_manager_id = $_POST['project_manager_id'];
        }

        
        
        if (!$new_item) 
        { /*so its an existing one */

            $approval_required = check_project_require_approval($project_id);

//            $current_budgets_total = get_project_tasks_current_budgets_total($project_id);
//            $approved_budgets_total = $current_budgets_total['current_budgets_total'];
            
            begin_transaction();
            update_project($project_id, $_POST['project_code'], $_POST['description'],
                    $_POST['long_description'], $project_manager_id, $_POST['customer_id'], $_POST['project_manager_name'],
                    $_POST['contact_person'],$_POST['inactive'],
                    $_POST['project_start_date'], $_POST['project_end_date'], 
                    input_num('editing_project_value'),input_num('estimated_cost'),
                    $_POST['rate_include_taxes'], $_POST['type_id'],
                    $_POST['department_id'], $_POST['purchase_to_stock'], $_POST['data_access_group_id'],
                    $_POST['revenue_account'], $_POST['cost_account'],
                    $_POST['frozen_date'], $_POST['project_status_id'], 
                    input_num('overhead_percentage'), $_POST['employee_advances_account']) ;

            if($approval_required){
                $project = get_project_record($project_id);
                
                $rap_msg = reopen_project($project);               
                if($rap_msg['success'] !== true){
                    cancel_transaction();
                    display_error($rap_msg["message"]);
                }
                else{
                    commit_transaction();
                    set_focus('description');
                    $Ajax->activate('description'); // in case of status change
                    display_notification(_("Project has been updated."));
                }
            }
            else{
                commit_transaction();
                set_focus('description');
                $Ajax->activate('description'); // in case of status change
                display_notification(_("Project has been updated."));
            }
        } 
        else 
        { //it is a NEW part                  
//            $myrow = get_next_number($_POST['company_category_code']);
//            $company_serial_no = $myrow["next_number"];
//            $result = get_next_number($_POST['project_category_code']);
//            $project_category_code = $result["next_number"];
//            $name = $_POST['company_category_code']. '/' .$_POST['group_serial_no']. '/' .$company_serial_no. '/' .$_POST['year']. '/' .$_POST['customer_category_code']. '/' .$_POST['project_category_code']
//                    . '/' .$project_category_code;

            $_POST['project_category_code'] = ""; 
            $_POST['company_category_code'] = "";
            $_POST['group_serial_no'] = 0;
            $_POST['year'] = 0;
            $_POST['customer_category_code'] = "";
            
            $category_serial_no = 0;
            $company_serial_no = 0;
            $name = "";

            begin_transaction();

            $approved = 0;
            $add_budgets = 1;

            add_project($_POST['description'], $_POST['long_description'], $_POST['inactive'],
                                $project_manager_id, $_POST['company_category_code'], $_POST['group_serial_no'], 
                                $company_serial_no, $_POST['year'], $_POST['customer_category_code'],
                                $_POST['project_category_code'], $category_serial_no, $_POST['project_start_date'], 
                                $_POST['project_end_date'],$_POST['customer_id'],$_POST['project_manager_name'],$_POST['contact_person'], 
                                input_num('editing_project_value'),input_num('estimated_cost'), $_POST['rate_include_taxes'], $_POST['project_code'], 
                                $name ,$_POST['type_id'], $_POST['department_id'], $_POST['purchase_to_stock'], $_POST['data_access_group_id'],
                                $_POST['revenue_account'], $_POST['cost_account'], AS_NEW, $add_budgets, $_POST['frozen_date'], 
                                $_POST['project_status_id'], input_num('overhead_percentage'), $_POST['employee_advances_account']) ;


            commit_transaction();

            clear_project_data();

            display_notification(_("A new Project has been added."));
                        set_focus('description');
        }
        
        
    }
    
}

function clear_project_data()
{
    unset($_POST['project_code']);
    unset($_POST['description']);
    unset($_POST['project_name']);
    unset($_POST['company_category_code']);
    unset($_POST['group_serial_no']);
    unset($_POST['company_serial_no']);
    unset($_POST['year']);
    unset($_POST['customer_category_code']);
    unset($_POST['project_category_code']);
    unset($_POST['category_serial_no']);
    unset($_POST['project_start_date']);
    unset($_POST['project_end_date']);
    unset($_POST['editing_project_value']);
    unset($_POST['estimated_cost']);
    unset($_POST['project_manager_id']);
    unset($_POST['long_description']);
    unset($_POST['inactive']); 
    unset($_POST['customer_id']);
    unset($_POST['project_manager_id']);
    unset($_POST['project_manager_name']);
    unset($_POST['contact_person']);
    unset($_POST['data_access_group_id']);
    unset($_POST['project_status_id']);
    unset($_POST['department_id']);
    unset($_POST['type_id']);
    unset($_POST['NewProjectID']);
	
}


function remove_project($project_id)
{
    global $path_to_root;
    
    include_once($path_to_root . "/projects/includes/db/tasks_db.inc");
    include_once($path_to_root . "/projects/includes/db/project_boq_item_groups_db.inc");
    include_once($path_to_root . "/projects/includes/db/project_boq_items_db.inc");
    
    $groups_list = get_project_boq_item_groups($project_id);
    if(db_num_rows($groups_list) > 0){
        display_error(_("Selected project can not be deleted.It has BOQ Item Groups"));
        return;
    }
    
    $tasks_list = get_tasks($project_id);
    if(db_num_rows($tasks_list) > 0){
        display_error(_("Selected project can not be deleted.It has budgets"));
        return;
    }
    
    $boq_list = get_project_boq_items($project_id);
    if(db_num_rows($boq_list) > 0){
        display_error(_("Selected project can not be deleted.It has BOQ items"));
        return;
    }

//        $project_id = $_POST['project_id'];
    delete_project($project_id);

    display_notification(_("Selected project has been deleted."));

    clear_project_data();
         
    
}