------ Auto Leave Encashment Process.Start --------

SET DEFINE OFF

INSERT INTO ITM2MENU (APPLICATION,LEVEL_1,LEVEL_2,LEVEL_3,LEVEL_4,LEVEL_5,WIN_NAME,DESCR,COMMENTS,MENU_PATH,ICON_PATH,CLOSE_ICON,OPEN_ICON,OBJ_TYPE,CHG_DATE,CHG_TERM,CHG_USER,MOB_DEPLOY) 
VALUES 
('ADM',4,12,3,0,0,'w_auto_leave_encash','C. Auto leave encashment','Auto leave encashment','ADM.4.12.3.0.0',null,null,null,null,null,null,null,null);

UPDATE ITM2MENU SET OBJ_TYPE = 'P' , ICON_PATH =  'e12_logo.gif'  WHERE WIN_NAME = 'w_auto_leave_encash';

COMMIT;

INSERT INTO TRANSETUP (TRAN_WINDOW,SAVE_FLAG,VAL_FLAG,KEY_FLAG,KEY_STRING,UDF_1,UDF_2,UDF_3,UDF_4,UDF_5,REPEATE_ADD,CHG_DATE,CHG_USER,CHG_TERM,EDI_OPTION,SITE_ACC_COL,CONFIRM_COL,CONFIRM_VAL,REPEAT_ADD_DET,REPEATADDDET,LOAD_MODE,AUTO_CONFIRM,LEDG_POST_CONF,CHG_DATE_ON_CONF,TRAN_ID_COL,MAIL_OPTION,CONFIRM_MODE,GARBAGE_OPT,VAL_FLAG_EDI,VERIFY_PASSWORD,CUST_ACC_COL,SALES_PERS_ACC_COL,SUPP_ACC_COL,ITEM_SER_ACC_CODE,EMP_ACC_COL,ITEM_SER_ACC_COL,WORKFLOW_OPT,TABLE_NAME,APPLICATION,TABLE_DESC,TRAN_DATE_COL,TRAN_ID__FROM,TRAN_ID__TO,TABLE_NAME_DET1,TABLE_NAME_DET2,TABLE_NAME_DET3,MULTITIRE_OPT,REF_SER,VIEW_MODE,TAX_FORMS,SIGN_STATUS,USER_TRAN_WINDOW,CUSTOM_PREVIEW_OBJ,IGNOREERRLIST_ONLOAD,CHILDDATA_ARGOPT,EDIT_TMPLT,WRKFLW_INIT,EDITTAX,FORMAL_ARGS,AUDIT_TRAIL_OPT,EDIT_OPT,CACHE_OPT,OPTIMIZE_MODE,EDIT_EXPR,RATE_COL,QTY_COL,EDIT_EXPR_INP,RCP_CACHE_STATUS,PRINT_CONTROL,TRANSFER_MODE,PROFILE_ID__RES,TRAN_COMPL_MSG,PERIOD_OPTION,WRKFLW_PRIORITY,EXEC_TYPE,DISP_META_DATA,START_FORM,ISATTACHMENT,HEADER_FORM_NO,ALLOW_ATTACH,MSG_ONSAVE,CONFIRM_DATE_COL,CONFIRM_BY_COL,WF_STATUS,ISGWTINITIATED,RESTART_FORM) 
VALUES 
('w_auto_leave_encash','2','2','M','seq10',null,null,null,null,null,'N',FN_SYSDATE(),'BASE','BASE','0',null,null,null,'N','N',null,null,null,null,null,'0','0',null,null,null,null,null,null,null,null,null,'0',null,'ADM',null,null,null,null,null,null,null,'0',null,'F',null,null,null,null,null,null,null,null,null,null,'0',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

UPDATE TRANSETUP SET WORKFLOW_OPT = 0, APPLICATION='ADM', AUDIT_TRAIL_OPT = CASE WHEN AUDIT_TRAIL_OPT IS NULL THEN '0' ELSE AUDIT_TRAIL_OPT END WHERE TRAN_WINDOW = 'w_auto_leave_encash' ;

COMMIT;

INSERT INTO OBJ_FORMS (WIN_NAME,TITLE,OBJ_BROW_NAME,OBJ_EDIT_NAME,CROSS_UPDATE_EXPR,EXPR_FLD_INFO,TARGET_FLD_INFO,EXPR_COMMENT,FORM_NO,SCR_FLAG,AUTO_ACCEPT_SCAN,SCAN_FLAG,SCAN_METADATA,PROPERTY_INFO,EXT_COM,EXT_METADATA,EXT_SETUP,AFTER_SAVE,COLUMN_ON_SAVE,SCAN_DELIMITER,AUTO_ACCEPT_WEIGHDATA,RATE_COL,QTY_COL,FORM_TYPE,DISP_METADATA,PARENT_KEY_COL,ASSISTED_MODE,STORAGE_KEY_METADATA,SELECTION_MODE,DEFAULT_VIEW,AUTO_ADDON_ENTRY) 
VALUES 
('w_auto_leave_encash','Auto Leave Encash',null,null,null,null,null,null,'1',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

INSERT INTO OBJ_FORMS (WIN_NAME,TITLE,OBJ_BROW_NAME,OBJ_EDIT_NAME,CROSS_UPDATE_EXPR,EXPR_FLD_INFO,TARGET_FLD_INFO,EXPR_COMMENT,FORM_NO,SCR_FLAG,AUTO_ACCEPT_SCAN,SCAN_FLAG,SCAN_METADATA,PROPERTY_INFO,EXT_COM,EXT_METADATA,EXT_SETUP,AFTER_SAVE,COLUMN_ON_SAVE,SCAN_DELIMITER,AUTO_ACCEPT_WEIGHDATA,RATE_COL,QTY_COL,FORM_TYPE,DISP_METADATA,PARENT_KEY_COL,ASSISTED_MODE,STORAGE_KEY_METADATA,SELECTION_MODE,DEFAULT_VIEW,AUTO_ADDON_ENTRY) 
VALUES 
('w_auto_leave_encash','Auto Leave Encash',null,null,null,null,null,null,'2',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

UPDATE OBJ_FORMS SET TITLE = 'Auto Leave Encash' , OBJ_BROW_NAME = 'd_auto_leve_encash',OBJ_EDIT_NAME = 'd_auto_encash_display' 
WHERE WIN_NAME = 'w_auto_leave_encash' ;

COMMIT;

INSERT INTO OBJ_ACTIONS (OBJ_NAME,LINE_NO,IMAGE,DESCRIPTION,SERVICE_CODE,INTERACTIVE,RIGHTS_CHAR,TITLE,FORM_NO,SERVICE_HANDLER,PLACEMENT,ACTION_TYPE,TRAN_TYPE,CHG_DATE,CHG_TERM,CHG_USER,IS_CONFIRMATION_REQ) 
VALUES 
('auto_leave_encash',1,'vdata~normal.gif','Action to get data','get_data','a','V','View Data','1',null,null,'S',null,null,null,null,null);

INSERT INTO OBJ_ACTIONS (OBJ_NAME,LINE_NO,IMAGE,DESCRIPTION,SERVICE_CODE,INTERACTIVE,RIGHTS_CHAR,TITLE,FORM_NO,SERVICE_HANDLER,PLACEMENT,ACTION_TYPE,TRAN_TYPE,CHG_DATE,CHG_TERM,CHG_USER,IS_CONFIRMATION_REQ) 
VALUES 
('auto_leave_encash',2,null,'Action to process data','process','a','P','Process','1',null,null,'S',null,null,null,null,null);

COMMIT;

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','itm_default','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','emp_code__fr','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','emp_code__to','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','dept_code__fr','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','dept_code__to','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','site_code__fr','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','site_code__to','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','lve_code__fr','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','lve_code__to','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','proc_group__fr','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','proc_group__to','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','prd_code','Y');

INSERT INTO OBJ_ITEMCHANGE (OBJ_NAME,FORM_NO,FIELD_NAME,MANDATORY) 
VALUES 
('auto_leave_encash','1','payroll_or_voucher','Y');

UPDATE OBJ_ITEMCHANGE SET MANDATORY = 'Y' WHERE OBJ_NAME = 'auto_leave_encash';

COMMIT;



INSERT INTO SYSTEM_EVENTS (OBJ_NAME,EVENT_CODE,EVENT_CONTEXT,SERVICE_CODE,METHOD_RULE,OVERWRITE_CORE,CHG_DATE,CHG_USER,CHG_TERM,RESULT_HANDLE,COMP_NAME,COMP_TYPE,COMM_FORMAT) 
VALUES 
('auto_leave_encash','post_item_change','1','poic_adm_default_1',null,'0',FN_SYSDATE(),'BASE','BASE','2','nvo_bo_auto_leave_encash','WSR',null);

INSERT INTO SYSTEM_EVENTS (OBJ_NAME,EVENT_CODE,EVENT_CONTEXT,SERVICE_CODE,METHOD_RULE,OVERWRITE_CORE,CHG_DATE,CHG_USER,CHG_TERM,RESULT_HANDLE,COMP_NAME,COMP_TYPE,COMM_FORMAT) 
VALUES 
('auto_leave_encash','pre_validate','1','prv_adm_default_1',null,'0',FN_SYSDATE(),'BASE','BASE','2','nvo_bo_auto_leave_encash','WSR',null);

INSERT INTO SYSTEM_EVENTS (OBJ_NAME,EVENT_CODE,EVENT_CONTEXT,SERVICE_CODE,METHOD_RULE,OVERWRITE_CORE,CHG_DATE,CHG_USER,CHG_TERM,RESULT_HANDLE,COMP_NAME,COMP_TYPE,COMM_FORMAT) 
VALUES 
('auto_leave_encash','get_data','1','gd_adm_default_1',null,'0',fn_sysdate(),'BASE','BASE','2','nvo_bo_auto_leave_encash','WSR',null);

INSERT INTO SYSTEM_EVENTS (OBJ_NAME,EVENT_CODE,EVENT_CONTEXT,SERVICE_CODE,METHOD_RULE,OVERWRITE_CORE,CHG_DATE,CHG_USER,CHG_TERM,RESULT_HANDLE,COMP_NAME,COMP_TYPE,COMM_FORMAT) 
VALUES 
('auto_leave_encash','process','1','pr_adm_default_2',null,'0',FN_SYSDATE(),'BASE','BASE','2','nvo_bo_auto_leave_encash','WSR',null);

INSERT INTO system_events (
	OBJ_NAME,
	EVENT_CODE,
	EVENT_CONTEXT,
	SERVICE_CODE,
	METHOD_RULE,
	OVERWRITE_CORE,
	CHG_DATE,
	CHG_USER,
	CHG_TERM,
	RESULT_HANDLE,
	COMP_NAME,
	COMP_TYPE,
	COMM_FORMAT)
VALUES (
	'auto_leave_encash',
	'post_validate',
	'1',
	'post_gen_val',
	NULL,
	'0',
	fn_sysdate(),
	'BASE',
	'BASE',
	'2',
	'GenValidate',
	'EJB',
	NULL);

UPDATE SYSTEM_EVENTS SET COMP_NAME='nvo_bo_auto_leave_encash' , COMP_TYPE = 'WSR' , SERVICE_CODE = 'prv_adm_default_1' WHERE OBJ_NAME='auto_leave_encash' AND EVENT_CODE = 'pre_validate';

UPDATE SYSTEM_EVENTS SET COMP_NAME='nvo_bo_auto_leave_encash' , COMP_TYPE = 'WSR' , SERVICE_CODE = 'poic_adm_default_1' WHERE OBJ_NAME='auto_leave_encash' AND EVENT_CODE = 'post_item_change';

UPDATE SYSTEM_EVENTS SET COMP_NAME='nvo_bo_auto_leave_encash' , COMP_TYPE = 'WSR' , SERVICE_CODE = 'gd_adm_default_1' WHERE OBJ_NAME='auto_leave_encash' AND EVENT_CODE = 'get_data';

UPDATE SYSTEM_EVENTS SET COMP_NAME='nvo_bo_auto_leave_encash' , COMP_TYPE = 'WSR' , SERVICE_CODE = 'pr_adm_default_2' WHERE OBJ_NAME='auto_leave_encash' AND EVENT_CODE = 'process';

COMMIT;

create or replace function FN_GET_ENC_LVEBAL
(
	ls_emp_code char, 
	ls_lve_code char,
	ld_laps_on_date date, 
	ld_ench_date date, 
	ls_empsite char , 
	ls_worksite char, 
	ls_paysite char, 
	ls_grade char, 
	ls_cadre char, 
	ls_lve_tblno char
) 
Return Number Is Lc_Bal_Days Number(14,1);
Lc_Bal_Days1 Number(14,1);
lc_used_days1 Number(14,1);
begin
	lc_bal_days1 := 0.00;
	lc_used_days1 := 0.00;

	SELECT Sum(LEAVEBAL.BAL_DAYS) as bal_days into lc_bal_days1 
	FROM leavebal
	where leavebal.lve_code = ls_lve_code AND  
	leavebal.emp_code = ls_emp_code AND  
	Leavebal.Exp_Date >= Ld_Laps_On_Date;

	Select Sum(Emplve_Trace.Lves_Alloc) Into Lc_Used_Days1 From Emplve_Trace Where 
	Emplve_Trace.Emp_Code = Ls_Emp_Code 
	And Emplve_Trace.Lve_Code = Ls_Lve_Code 
	and emplve_trace.lve_date_fr > ld_laps_on_date ;

	If Lc_Bal_Days1 Is Null Then 
		Lc_Bal_Days1 := 0;
	end if;
	If Lc_Used_Days1 Is Null Then 
		Lc_Used_Days1 := 0;
	End If;
	lc_bal_days := lc_bal_days1 + lc_used_days1;
	return lc_bal_days;
end;
/

---------- Function to calculate leave bal days for auto encashment as per new logic.End ----------



------ Auto Leave Encashment Process.End --------

