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


$page_security = 'SA_EMPLOYEES';
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/trace.php");
$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();
	
page(_($help_context = "Employees"), @$_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 . "/includes/data_checks.inc");

include_once($path_to_root . "/payroll/includes/payroll_db.inc");
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");
include_once($path_to_root . "/payroll/includes/db/salary_commitments_db.inc");

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

$user_comp = user_company();
$new_item = get_post('employee_code')=='' || get_post('cancel') || get_post('clone'); 

//------------------------------------------------------------------------------------
if (!isset($_POST['employee_code']))
{
    $_SESSION['previous_employee_for_resign'] = '';
    $_SESSION['current_employee_for_resign'] = '';
}
if (isset($_SESSION['current_employee_for_resign']) && $_SESSION['current_employee_for_resign'] != "")
{
	$_SESSION['previous_employee_for_resign'] = $_SESSION['current_employee_for_resign'];
}

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

    $employee_code = get_post('employee_code');
    $_SESSION['current_employee_for_resign'] = $employee_code;



if (list_updated('employee_code')) {
	$_POST['NewEmployeeCode'] = $employee_code = get_post('employee_code');
    clear_data();
	$Ajax->activate('details');
	$Ajax->activate('controls');
}

if (get_post('cancel')) {
	$_POST['NewEmployeeCode'] = $employee_code = $_POST['employee_code'] = '';
    clear_data();
	set_focus('employee_code');
	$Ajax->activate('_page_body');
}
if (list_updated('category_id') || list_updated('mb_flag')) {
	$Ajax->activate('details');
}
$upload_file = "";
if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') 
{      
        $employee_code = $_POST['NewEmployeeCode'];
	$result = $_FILES['pic']['error'];
 	$upload_file = 'Yes'; //Assume all is well to start off with
	$filename = company_path().'/images';
	if (!file_exists($filename))
	{
		mkdir($filename);
	}	
	$filename .= "/".item_img_name($employee_code).".jpg";
	
	//But check for the worst 
	if ((list($width, $height, $type, $attr) = getimagesize($_FILES['pic']['tmp_name'])) !== false)
		$imagetype = $type;
	else
		$imagetype = false;
	//$imagetype = exif_imagetype($_FILES['pic']['tmp_name']);
	if ($imagetype != IMAGETYPE_GIF && $imagetype != IMAGETYPE_JPEG && $imagetype != IMAGETYPE_PNG)
	{	//File type Check
		display_warning( _('Only graphics files can be uploaded'));
		$upload_file ='No';
	}
	elseif (!in_array(strtoupper(substr(trim($_FILES['pic']['name']), strlen($_FILES['pic']['name']) - 3)), array('JPG','PNG','GIF')))
	{
		display_warning(_('Only graphics files are supported - a file extension of .jpg, .png or .gif is expected'));
		$upload_file ='No';
	} 
	elseif ( $_FILES['pic']['size'] > ($max_image_size * 1024)) 
	{ //File Size Check
		display_warning(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $max_image_size);
		$upload_file ='No';
	} 
	elseif (file_exists($filename))
	{
		$result = unlink($filename);
		if (!$result) 
		{
			display_error(_('The existing image could not be removed'));
			$upload_file ='No';
		}
	}
	
	if ($upload_file == 'Yes')
	{
		$result  =  move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
	}
	$Ajax->activate('details');
 /* EOF Add Image upload for New Item  - by Ori */
}

function clear_data()
{
	//return;
        
        unset($_POST['employee_reference']);
	unset($_POST['epf_no']);
    unset($_POST['first_name']);
	unset($_POST['middle_name']);
	unset($_POST['last_name']);
	unset($_POST['NewEmployeeCode']);
    unset($_POST['date_of_birth']);
	unset($_POST['nic']);
	unset($_POST['passport']);
	unset($_POST['passport_expiry_date']);
	unset($_POST['dl_no']);
	unset($_POST['dl_expiry_date']);
	unset($_POST['gender']);
	unset($_POST['marital_status']);
	unset($_POST['nationality']);
	unset($_POST['address']);
	unset($_POST['work_telephone_no']);
	unset($_POST['home_telephone_no']);
	unset($_POST['mobile_no']);
	unset($_POST['emergency_contact_details']);
	unset($_POST['work_email_id']);
	unset($_POST['other_email_ids']);
	unset($_POST['bank_account_name']);
	unset($_POST['bank_account_no']);
	unset($_POST['bank_id']);
	unset($_POST['bank_branch_id']);
	unset($_POST['inactive']);
    unset($_POST['joined_date']);
	unset($_POST['resigned_date']);
	unset($_POST['resigned']);
	unset($_POST['office_mobile_no']);

}

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

if (isset($_POST['addupdate'])) 
{ 
	$input_error = 0;
    if ($upload_file == 'No')
        $input_error = 1;
    if (strlen($_POST['first_name']) == 0) 
    {
        $input_error = 1;
        display_error( _('First name must be entered.'));
        set_focus('first_name');
    }
    elseif (strlen($_POST['NewEmployeeCode']) == 0) 
    {
        $input_error = 1;
        display_error( _('The employee code cannot be empty'));
        set_focus('NewEmployeeCode');
    }
    elseif (strstr($_POST['NewEmployeeCode'], " ") || strstr($_POST['NewEmployeeCode'],"'") || 
        strstr($_POST['NewEmployeeCode'], "+") || strstr($_POST['NewEmployeeCode'], "\"") || 
        strstr($_POST['NewEmployeeCode'], "&") || strstr($_POST['NewEmployeeCode'], "\t")||
        strstr($_POST['NewEmployeeCode'], "%"))    
    {
        $input_error = 1;
        display_error( _('The employee code cannot contain any of the following characters -  & + % OR a space OR quotes'));
        set_focus('NewEmployeeCode');

    }
    
    $employee_id = 0;
    if ($new_item === false) {
        $row = get_employee($_POST['NewEmployeeCode']);
            if (is_array($row)) {
                $employee_id = $row['employee_id'];
            }
    }
        
    $dup_code_row = check_employee_code_already_used($_POST['NewEmployeeCode'], $employee_id);
        if (is_array($dup_code_row)) {
            $input_error = 1;
            display_error( _('The employee code cannot duplicate. It is already used to employee '). get_employee_formatted_long_name($dup_code_row['employee_code']));
            set_focus('NewEmployeeCode');
        }
    
    if(!is_date($_POST['date_of_birth']))
	{
		$input_error = 1;
		display_error( _('Date of birth is not a valid date'));
		set_focus('date_of_birth');
	}
  
    if(!is_date($_POST['joined_date']))
    {
            $input_error = 1;
            display_error( _('Date of joining is not a valid date'));
            set_focus('joined_date');
    }
    if($_POST['resigned'] == 1){     
        if(!is_date($_POST['resigned_date']))
        {
            $input_error = 1;
            display_error( _('Date of resignation is not a valid date'));
            set_focus('resigned_date');
        }
    }
    
    if($_POST['resigned'] == 1){     
        if(!is_date($_POST['resigned_date']))
        {
            $input_error = 1;
            display_error( _('Date of resignation is not a valid date'));
            set_focus('resigned_date');
        }
    }
    else{
        if(!(strlen($_POST['nic']) == 10 || strlen($_POST['nic']) == 12)){
            $input_error = 1;
            display_error( _('NIC number should be 10 or 12 characters'));
            set_focus('nic');
        }

        $check_nic = check_nic($_POST['nic']);
        if(isset($check_nic['employee_id']) && $check_nic['employee_id'] > 0 && $check_nic['employee_code'] == $_POST['employee_code']){
            
        }
        else{
            if($check_nic != ""){
            $input_error = 1;
            display_error( _("This NIC number is already attached to employee ". $check_nic['employee_code']." - ".
                    $check_nic['initials']."".$check_nic['last_name']." (".$check_nic['first_name'].")"));
            set_focus('nic');
            }
        }
        
        if($_POST['bank_account_no'] != ''){
            if($new_item){
                $check_bank_account_no = check_bank_account_no($_POST['bank_id'], $_POST['bank_account_no']);
            }
            else{
                $check_bank_account_no = check_bank_account_no($_POST['bank_id'], $_POST['bank_account_no'], $_POST['employee_code']);
            }

            if($check_bank_account_no){
                $input_error = 1;
                display_error( _("This Bank Account number is already attached to employee ". $check_bank_account_no['employee_code']." - ".
                        $check_bank_account_no['initials']."".$check_bank_account_no['last_name']." (".$check_bank_account_no['first_name'].")"));
                set_focus('bank_account_no');
            }
        }
    }
    
    if(!$new_item)
    {
        $row = get_employee($_POST['NewEmployeeCode']);
        if($_POST['bank_id'] != $row['bank_id'] || $_POST['bank_branch_id'] != $row['bank_branch_id'] 
                || $_POST['bank_account_no'] != $row['bank_account_no']){

            $cehsc = check_employee_has_salary_commitments($_POST['NewEmployeeCode'],$row['bank_id'],
                    $row['bank_branch_id'], $row['bank_account_no']);

            if($cehsc != "" && $_POST['bank_id'] != $row['bank_id'])
            {
                $input_error = 1;
                display_error( _('This employee has salary commitments.Therefore Bank Name can not be changed '));
                set_focus('bank_id');
            }

            if($cehsc != "" && $_POST['bank_branch_id'] != $row['bank_branch_id'])
            {
                $input_error = 1;
                display_error( _('This employee has salary commitments.Therefore Branch Name can not be changed '));
                set_focus('bank_branch_id');
            }

            if($cehsc != "" && $_POST['bank_account_no'] != $row['bank_account_no'])
            {
                $input_error = 1;
                display_error( _('This employee has salary commitments.Therefore Account No can not be changed '));
                set_focus('bank_account_no');
            }
        }
    }

	
	if ($input_error != 1)
	{
		if (check_value('del_image'))
		{
			$filename = company_path().'/images/'.item_img_name($_POST['NewEmployeeCode']).".jpg";
			if (file_exists($filename))
				unlink($filename);
		}
		
        $bank_id = $bank_branch_id = 0;
        if($_POST['bank_id'] > 0){
            $bank_id = $_POST['bank_id'];
            if($_POST['bank_branch_id'] > 0){
                $bank_branch_id = $_POST['bank_branch_id'];
            }
        }
        else{
            $bank_branch_id = 0;
        }
        
        $salary_group_id = 0;
        if(isset($_POST['salary_group_id']) && $_POST['salary_group_id'] > 0){
            $salary_group_id = $_POST['salary_group_id'];
        }
        
		if (!$new_item) 
		{ /*so its an existing one */
                    if(!isset($_POST['resigned_date']))
                    {
                        $_POST['resigned_date'] = sql2date(INFINITE_END_DATE);
                    }
			update_employee($_POST['NewEmployeeCode'], $_POST['first_name'],
				$_POST['middle_name'], $_POST['last_name'], 
                $_POST['initials'], 
				date2sql($_POST['date_of_birth']), $_POST['nic'],
				$_POST['passport'], date2sql($_POST['passport_expiry_date']), 
				$_POST['dl_no'], date2sql($_POST['dl_expiry_date']),
				$_POST['gender'], $_POST['marital_status'], 
				$_POST['nationality'], $_POST['employee_type_id'], $salary_group_id, $_POST['address'],
                                date2sql($_POST['joined_date']), date2sql($_POST['resigned_date']), $_POST['resigned'],
				$_POST['work_telephone_no'], $_POST['home_telephone_no'], 
				$_POST['mobile_no'], $_POST['office_mobile_no'], get_post('emergency_contact_details'),
				$_POST['work_email_id'], $_POST['other_email_ids'], 
				$_POST['bank_account_name'], $_POST['bank_account_no'],
				$bank_id, $bank_branch_id, 
				$_POST['epf_no'], $_POST['include_in_bank_file'],$_POST['bank_basic_salary'],$_POST['bank_incentive_salary'],
                                $_POST['inactive'], $_POST['employee_reference']);

            //clear_data();
			set_focus('employee_code');
			$Ajax->activate('employee_code'); // in case of status change
			display_notification(_("Employee has been updated."));
                        
		} 
		else 
		{ //it is a NEW part
                    $_POST['resigned_date'] = sql2date(INFINITE_END_DATE);
			add_employee($_POST['NewEmployeeCode'], $_POST['first_name'],
				$_POST['middle_name'], $_POST['last_name'], 
                $_POST['initials'], 
				date2sql($_POST['date_of_birth']), $_POST['nic'],
				$_POST['passport'], date2sql($_POST['passport_expiry_date']), 
				$_POST['dl_no'], date2sql($_POST['dl_expiry_date']),
				$_POST['gender'], $_POST['marital_status'], 
				$_POST['nationality'], $_POST['employee_type_id'], $salary_group_id, $_POST['address'],
                                date2sql($_POST['joined_date']), date2sql($_POST['resigned_date']), $_POST['resigned'],
				$_POST['work_telephone_no'], $_POST['home_telephone_no'], 
				$_POST['mobile_no'], $_POST['office_mobile_no'], get_post('emergency_contact_details'),
				$_POST['work_email_id'], $_POST['other_email_ids'], 
				$_POST['bank_account_name'], $_POST['bank_account_no'],
				$bank_id, $bank_branch_id, 
				$_POST['epf_no'], $_POST['include_in_bank_file'],$_POST['bank_basic_salary'],$_POST['bank_incentive_salary'],
                                $_POST['inactive'], $_POST['employee_reference']);

            clear_data();
			display_notification(_("A new employee has been added."));
			$_POST['employee_code'] = $_POST['NewEmployeeCode'] = 
			set_focus('NewEmployeeCode');
                        
		}
		$Ajax->activate('_page_body');
	}
}

if (get_post('clone')) {
	unset($_POST['employee_code']);
	$employee_code = '';
	unset($_POST['inactive']);
	set_focus('NewEmployeeCode');
	$Ajax->activate('_page_body');
    //l('224 inside get_post ');
}
//------------------------------------------------------------------------------------

function check_usage($employee_code, $dispmsg=true)
{
	$msg = item_in_foreign_codes($employee_code);

	if ($msg != '')	{
		if($dispmsg) display_error($msg);
		return false;
	}
	return true;
}

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

//if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) 
//{
//
//    retun;
//	if (check_usage($_POST['NewEmployeeCode'])) {
//
//		$employee_code = $_POST['NewEmployeeCode'];
//		//delete_item($employee_code);
//		$filename = company_path().'/images/'.item_img_name($employee_code).".jpg";
//		if (file_exists($filename))
//			unlink($filename);
//		display_notification(_("Selected item has been deleted."));
//		$_POST['employee_code'] = '';
//		clear_data();
//		set_focus('employee_code');
//		$new_item = true;
//		$Ajax->activate('_page_body');
//	}
//}



function item_settings(&$employee_code) 
{
	global $SysPrefs, $path_to_root, $new_item, $pic_height;

	start_outer_table(TABLESTYLE2);

	table_section(1);

	table_section_title(_("Personal Details"));
        
        

	//------------------------------------------------------------------------------------
	if ($new_item) 
	{
		text_row(_("Employee Code:"), 'NewEmployeeCode', null, 21, 20);

		$_POST['inactive'] = 0;
	} 
	else 
	{ // Must be modifying an existing item
                
                //if (get_post('NewEmployeeCode') != get_post('employee_code') || get_post('addupdate')) { // first item display
                if (get_post('employee_code') || get_post('addupdate')) { // first item display

			$_POST['NewEmployeeCode'] = $_POST['employee_code'];

			$myrow = get_employee($_POST['NewEmployeeCode']);

                        if(isset($_SESSION['previous_employee_for_resign']) 
                                && $_SESSION['previous_employee_for_resign'] == $_SESSION['current_employee_for_resign'])
                        {
//                            $Ajax->activate('_page_body');
                            if(isset($_POST['resigned'])){
                                $_POST['resigned'] = $_POST['resigned'];
                            }
                            else{
                                $_POST['resigned'] = $myrow['resigned'];
                            }
                            $_POST['resigned_date']	= sql2date($myrow['date_of_resignation']);
                            
                            if(isset($_POST['bank_id']) && $_POST['bank_id'] != $myrow['bank_id']){
                                $_POST['bank_id'] = $_POST['bank_id'];
                            }

                        }
                        else
                        {
                            $_POST['resigned_date']	= sql2date($myrow['date_of_resignation']);
                            $_POST['resigned']	= $myrow['resigned'];
                            $_POST['bank_id']	= $myrow['bank_id'];

                        }
                        
                        $_POST['employee_reference'] = $myrow["employee_reference"];
                        $_POST['first_name'] = $myrow["first_name"];
                        $_POST['middle_name'] = $myrow["middle_name"];
                        $_POST['last_name']  = $myrow["last_name"];
                        $_POST['initials']  = $myrow["initials"];
                        $_POST['date_of_birth']  = sql2date($myrow["date_of_birth"]);
                        $_POST['nic']  = $myrow["nic"];
                        $_POST['passport']  = $myrow["passport"];
                        $_POST['passport_expiry_date']  = sql2date($myrow["passport_expiry_date"]);
                        $_POST['dl_no'] =  $myrow['dl_no'];
                        $_POST['dl_expiry_date'] = sql2date($myrow['dl_expiry_date']);
                        $_POST['gender'] = $myrow['gender'];
                        $_POST['marital_status']	= $myrow['marital_status'];
                        $_POST['nationality']	= $myrow['nationality'];
                        $_POST['employee_type_id']	= $myrow['employee_type_id'];
                        $_POST['salary_group_id']	= $myrow['salary_group_id'];
                        $_POST['address']	= $myrow['address'];
                        $_POST['joined_date']	= sql2date($myrow['date_of_joining']);
//                        $_POST['resigned_date']	= sql2date($myrow['date_of_resignation']);
//                        $_POST['resigned']	= $myrow['resigned'];
                        $_POST['work_telephone_no']	= $myrow['work_telephone_no'];
                        $_POST['home_telephone_no']	= $myrow['home_telephone_no'];
                        $_POST['mobile_no']	= $myrow['mobile_no'];
                        $_POST['office_mobile_no']	= $myrow['office_mobile_no'];
                        $_POST['emergency_contact_details'] = $myrow["emergency_contact_details"];
                        $_POST['work_email_id']  = $myrow["work_email_id"];
                        $_POST['other_email_ids'] =  $myrow['other_email_ids'];
                        $_POST['bank_account_name'] = $myrow['bank_account_name'];
                        $_POST['bank_account_no'] = $myrow['bank_account_no'];
                        
                        if(!(isset($_POST['bank_id']) && $_POST['bank_id'] > 0)){
                            $_POST['bank_id']	= $myrow['bank_id'];
                        }
//                        $_POST['bank_id']	= $myrow['bank_id'];
                        if(!(isset($_POST['bank_branch_id']) && $_POST['bank_branch_id'] > 0)){
                            $_POST['bank_branch_id']	= $myrow['bank_branch_id'];
                        }
                        
//                        $_POST['bank_branch_id']	= $myrow['bank_branch_id'];
                        $_POST['epf_no']	= $myrow['epf_no'];
                        $_POST['include_in_bank_file']	= $myrow['include_in_bank_file'];
                        $_POST['bank_basic_salary']	= $myrow['bank_basic_salary'];
                        $_POST['bank_incentive_salary']	= $myrow['bank_incentive_salary'];
                        $_POST['inactive']	= $myrow['inactive'];

                        $_POST['del_image'] = 0;
                        
		}
		label_row(_("Employee Code:"),$_POST['NewEmployeeCode']);
		hidden('NewEmployeeCode', $_POST['NewEmployeeCode']);
		set_focus('first_name');
	}

        text_row(_('Employee Reference:'), 'employee_reference', null, 20, 20);

        text_row(_('EPF No:'), 'epf_no', null, 20, 20);
        
        text_row(_("Full Name:"), 'middle_name', null, 50, 500);
    
        text_row(_("Calling Name:"), 'first_name', null, 50, 200);
        
        text_row(_("Surname (Last Name):"), 'last_name', null, 50, 200);
        
        text_row(_("Initials:"), 'initials', null, 20, 20);
        
        date_row('Date of Birth:', ('date_of_birth'));

        text_row(_("NIC:"), 'nic', null, 20, 20);
        
        text_row(_("Passport:"), 'passport', null, 20, 20);
        	
        date_row('Passport Expiry Date:', ('passport_expiry_date'));
        
        text_row(_("Driving License No:"), 'dl_no', null, 20, 20);
        	
        date_row(_('DL Expiry Date:'), 'dl_expiry_date');
        
        two_value_list_row(_("Gender"), 'gender', null, "Female", "Male", "F", "M", false);
        
        two_value_list_row(_("Marital Status"), 'marital_status', null, "Single", "Married", "S", "M", false);
        
        text_row(_("Nationality:"), 'nationality', null, 50, 50);
        
        value_list_row(_("Employee Type:"), 'employee_type_id', "EMPLOYEE_TYPE");
        
        value_list_row(_("Salary Group:"), 'salary_group_id', "SALARY_GROUPS", null, '');
        
        record_status_list_row(_("Record Status:"), 'inactive');
        
                
        table_section_title(_("Bank Account Details"));

        text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 50);
        
        text_row(_("Bank Account No:"), 'bank_account_no', null, 50, 50);
        
        value_list_row(_("Bank Name:"), 'bank_id', "BANKS", null, '', true);
        
        bank_branch_list_row(_("Bank Branch Name:"), 'bank_branch_id', $_POST['bank_id']);
//        text_row(_("Bank Branch Name:"), 'bank_branch_id', null, 50, 50);
        
        
        table_section(2);

	table_section_title(_("Image"));

	// Add image upload for New Item  - by Joe
	file_row(_("Image File (.jpg)") . ":", 'pic', 'pic');
	// Add Image upload for New Item  - by Joe
	$stock_img_link = "";
	$check_remove_image = false;
	if (isset($_POST['NewEmployeeCode']) && file_exists(company_path().'/images/'
		.item_img_name($_POST['NewEmployeeCode']).".jpg")) 
	{
	 // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D.
		$stock_img_link .= "<img id='item_img' alt = '[".$_POST['NewEmployeeCode'].".jpg".
			"]' src='".company_path().'/images/'.item_img_name($_POST['NewEmployeeCode']).
			".jpg?nocache=".rand()."'"." height='$pic_height' border='0'>";
		$check_remove_image = true;
	} 
	else 
	{
		$stock_img_link .= _("No image");
	}

	label_row("&nbsp;", $stock_img_link);
	if ($check_remove_image)
		check_row(_("Delete Image:"), 'del_image');
        
        table_section_title(_("Employement Period"));
        
        date_row(_('Date of Joining:'), 'joined_date');
        
        yesno_list_row("Resigned:", 'resigned', null, "Yes", "No", true);
        
//        if($_SESSION['previous_employee_for_resign'] = $_SESSION['current_employee_for_resign'])
//        {
            if($_POST['resigned'] == 1)
            {
                if ($new_item) 
                {  
                    $_POST['resigned_date'] = sql2date(INFINITE_END_DATE);
                } 
                    date_row(_('Date of Resigning:'), 'resigned_date');
            }
//        }
	table_section_title(_("Contact Details"));
        
        textarea_row(_('Address:'), 'address', null, 25, 3);
        
        text_row(_("Work Telephone No:"), 'work_telephone_no', null, 20, 20);
        
        text_row(_("Home Telephone No:"), 'home_telephone_no', null, 20, 20);
        
        text_row(_("Mobile No:"), 'mobile_no', null, 20, 20);
        
        text_row(_("Emergency Contact Details:"), 'emergency_contact_details', null, 50, 200);
        
        text_row(_("Work Email Id:"), 'work_email_id', null, 50, 50);
        
        text_row(_("Other Email Ids:"), 'other_email_ids', null, 50, 200);
        
        
        table_section_title(_("Contact Details (Mobile Allowances)"));
        
        text_row(_("Office Mobile No:"), 'office_mobile_no', null, 20, 20);
        
        table_section_title(_("Other"));
        
        
        if(isset($_POST['include_in_bank_file'])){
            $include_in_bank_file = $_POST['include_in_bank_file'];
        }
        else{
            $include_in_bank_file = 0;
        }
        
        yesno_list_row("Bank Basic Salary:", 'bank_basic_salary', null, "Yes", "No", false);
        yesno_list_row("Bank Incentive Salary:", 'bank_incentive_salary', null, "Yes", "No", false);
        
        yesno_list_row("Include In Bank Upload File:", "include_in_bank_file",$include_in_bank_file,false,"");
        

	end_outer_table(1);

	div_start('controls');
	if (!isset($_POST['NewEmployeeCode']) || $new_item) 
	{
		submit_center('addupdate', _("Insert New Employee"), true, '', 'default');
	} 
	else 
	{
		submit_center_first('addupdate', _("Update Employee"), '', 
			@$_REQUEST['popup'] ? true : 'default');
                
		submit_return('select', get_post('employee_code'), 
			_("Select this employee and return to document entry."), 'default');
		submit('clone', _("Clone This Employee"), true, '', true);
//		submit('delete', _("Delete This Employee"), true, '', true);
		submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
	}

	div_end();
}

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

start_form(true);

//if (db_has_stock_items()) 
{
	start_table(TABLESTYLE_NOBORDER);
	start_row();
//    emoplyees_list_cells(_("Select an Employee:"), 'employee_code', null,
//	  _('New Employee'), true, check_value('show_inactive'));
  employee_search_list_cells(_("Select an Employee:"), 'employee_code', null,
	  _('New Employee'), true, check_value('show_inactive'));
    
	$new_item = get_post('employee_code')=='';
	check_cells(_("Show inactive:"), 'show_inactive', null, true);
	end_row();
	end_table();

	if (get_post('_show_inactive_update')) {
		$Ajax->activate('employee_code');
		set_focus('employee_code');
	}
}
//else
//{
//	hidden('employee_code', get_post('employee_code'));
//}



div_start('details');

$employee_code = get_post('employee_code');

if (!$employee_code)
	unset($_POST['_tabs_sel']); // force settings tab for new customer

tabbed_content_start('tabs', array(
		'settings' => array(_('&General settings'), $employee_code),
		'employment_details' => array(_('&Current Employment Details'), $employee_code),
		'employment_history' => array(_('&Employment History'), $employee_code),
		'qualifications' => array(_('&Qualifications'), $employee_code),
        'salary_commitments' => array(_('&Salary Commitments'), $employee_code),
        'employee_departments' => array(_('&Departments'), $employee_code),
        'hold_salary' => array(_('&Hold Salary'), $employee_code),
	));
	
	switch (get_post('_tabs_sel')) {
		default:
		case 'settings':
            item_settings($employee_code); 
			break;
		case 'employment_details':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/employment_details.php");
			break;
		case 'employment_history':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/employment_history.php");
			break;
		case 'qualifications':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/qualifications.php");
			break;
        case 'salary_commitments':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/salary_commitments.php");
			break;
        case 'employee_departments':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/employee_departments.php");
			break;
        case 'hold_salary':
			$_GET['employee_code'] = $employee_code;
			$_GET['popup'] = 1;
			include_once($path_to_root."/payroll/hold_salary.php");
			break;
	};
br();
tabbed_content_end();

div_end();


hidden('popup', @$_REQUEST['popup']);

end_form();

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

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