Sunday 4 December 2011

Control File to upload element entry

-- File Name         : XXARJ_CREATE_ELEMENT_ENTRY.ctl
-- File Type         : SQL*Loader Control file.
-- RICEW Object id   :
-- Description       : This SQL*Loader file is used to load  data
--                     from flat file to the staging table XXARJ_CREATE_ELEMENT_ENTRY
-- Maintenance History:
LOAD DATA
INFILE '/genhor12app/hc12u/uat/apps/apps_st/appl/XXARJ/12.0.0/data/XXARJ_CREATE_ELEMENT_ENTRY.csv'
APPEND
INTO TABLE  XXARJ_CREATE_ELEMENT_ENTRY
TRUNCATE
FIELDS TERMINATED BY "," optionally enclosed by '"'
TRAILING NULLCOLS
( "ELEMENT_NAME" ,
    "BATCH_NAME" ,
    "ENTRY_TYPE" ,
    "CREATOR_TYPE",
    "EFFECTIVE_START_DATE" ,
    "BUSINESS_GROUP_ID"  ,
    "EMPLOYEE_NUMBER"    ,
    "NEW_EMPLOYEE_NUMBER" ,
    "INPUT_VALUE_1"       ,
    "ENTRY_VALUE_1"       ,
    "INPUT_VALUE_2"       ,
    "ENTRY_VALUE_2"       ,
    "INPUT_VALUE_3"       ,
    "ENTRY_VALUE_3"       ,
    "INPUT_VALUE_4"       ,
    "ENTRY_VALUE_4"       ,
    "INPUT_VALUE_5"       ,
    "ENTRY_VALUE_5"       ,
    "INPUT_VALUE_6"       ,
    "ENTRY_VALUE_6"       ,
    "INPUT_VALUE_7"       ,
    "ENTRY_VALUE_7"       ,
    "INPUT_VALUE_8"       ,
    "ENTRY_VALUE_8"       ,
    "INPUT_VALUE_9"       ,
    "ENTRY_VALUE_9"       ,
    "INPUT_VALUE_10"      ,
    "ENTRY_VALUE_10"      ,
    "INPUT_VALUE_11"      ,
    "ENTRY_VALUE_11"      ,
    "INPUT_VALUE_12"      ,
    "ENTRY_VALUE_12"      ,
    "INPUT_VALUE_13"      ,
    "ENTRY_VALUE_13"      ,
    "INPUT_VALUE_14"      ,
    "ENTRY_VALUE_14"      ,
    "INPUT_VALUE_15"      ,
    "ENTRY_VALUE_15"      ,
    "PROCESS_FLAG"  CONSTANT 'N',
    "ERROR_MESSAGE"       ,
    "ELEMENT_ENTRY_ID"    ,
    "OBJECT_VERSION_NUMBER",
    "CREATION_DATE" SYSDATE,
    "CREATED_BY" "FND_GLOBAL.USER_ID",
    "LAST_UPDATE_DATE" SYSDATE,
    "LAST_UPDATED_BY" "FND_GLOBAL.USER_ID" ,
    "LAST_UPDATE_LOGIN" "FND_GLOBAL.LOGIN_ID"
 )


 

Controll file to upload employee data

-- File Name         : XXARJ_HR_CNV_PEOPLE_TMP.ctl
-- File Type         : SQL*Loader Control file.
-- RICEW Object id   : HR_CNV_01
-- Description       : This SQL*Loader file is used to load  data
--                     from flat file to the staging table XXPLL_HR_CNV_PEOPLE_TMP
-- Maintenance History:
LOAD DATA
INFILE '/genhor12app/hc12u/uat/apps/apps_st/appl/XXARJ/12.0.0/data/XXARJ_HR_CNV_PEOPLE_TMP.csv'
APPEND
INTO TABLE  XXPLL_HR_CNV_PEOPLE_TMP
TRUNCATE
FIELDS TERMINATED BY "," optionally enclosed by '"'
TRAILING NULLCOLS
(  "EMPLOYEE_NUMBER",
    "GENDER",
    "TITLE",
    "FIRST_NAME",
    "MIDDLE_NAME",
    "LAST_NAME",
    "USER_PERSON_TYPE",
    "MARITAL_STATUS",
    "DATE_OF_BIRTH",
    "HIRE_DATE",
    "NATIONALITY",
    "COUNTRY_OF_BIRTH",
    "BLOOD_TYPE",
    "PAN_NUMBER",
    "PAN_APPLIED_FOR",
    "PAN_REFERENCE_NUMBER",
    "RESIDENTIAL_STATUS",
    "PF_NUMBER",
    "ESI_NUMBER",
    "SUPERANNUATION_NUMBER",
    "GROUP_INSURANCE_NUMBER",
    "NSSN",
    "PENSION_FUND_NUMBER",
    "BGC_CONDUCTED",
    "BGC_STATUS",
    "BGC_CONDUCTED_ON",
    "EMPLOYEMENT_STATUS",
    "DISABILTY",
    "CONTRACT_END_DATE",
    "ROLE_IF_ANY",
    "PRESENT_POSITION_TITLE",
    "SUPERVISOR_NUMBER",
    "FULL_NAME_SUPER",
    "EFFECTIVE_START_DATE",
    "EFFECTIVE_END_DATE",
    "EMAIL_ADDRESS",
    "LOCATION_CODE",
    "JOB_NAME",
    "GRADE",
    "ORGANIZATION_NAME_ORG",
    "LEGACY_EMPLOYEE_ID",
    "TOWN_OF_BIRTH",
    "REGION_OF_BIRTH",
    "GRATUITY_NUMBER",
    "ASSIGN_STATUS_TYPE",
    "PROBATION_PERIOD",
    "PROBATION_UNIT",
    "ASSIGNMENT_CATEGORY",
    "EMPLOYEE_CATEGORY",
    "GREORLEGALENTITY",
    "PFORGANIZATION",
    "PROFESSIONALTAXORGANISATION",
    "ESIORGANIZATION",
    "FACTORY",
    "ESTABLISHMENT",
    "COVERED_BY_GRATUITY_ACT",
    "HAVING_SUBSTANTIAL_INTEREST",
    "DIRECTOR",
    "SPECIFIED_EMPLOYEE",
    "PFEPSCONTRIBUTION",
    "LEGAL_NAME",
    "PASSPORT_NUMBER",
    "PASSPORT_COUNTRY_OF_ISSUE",
    "CPF_CATEOGRY",
    "RACE",
    "COMUNITY_FUND_CATEOGRY",
    "PAYESS_ID",
    "NRICFN",
    "PERMIT_TYPE",
    "PERMIT_NUMBER",
    "PERMIT_CATEGORY",
    "PERMIT_DATE_ISSUE",
    "PERMIT_EXPIRY_DATE",
    "INCOME_TAX_NUMBER",
    "CPFACCNUMBER",
    "CPF_CATEGORY",
    "INOME_TAX_NUMBER_SPOUSE",
    "PASSPORT_DATE_ISSUED",
    "PASSPORT_DATE_EXPIRY",
    "SYSTEM_PERSON_TYPE",
    "NEW_EMPLOYEE_NUMBER",
    "PAYROLL_NAME",
    "FUNCTIONAL_MGR",
    "EX_SERVICEMAN",
    "GROUP_NAME",
    "SUBGROUP_NAME",
    "PROCESS_FLAG" CONSTANT 'N',
    "ERROR_MESSAGE",
    "CREATION_DATE" SYSDATE,
    "CREATED_BY" "FND_GLOBAL.USER_ID",
    "LAST_UPDATE_DATE" SYSDATE,
    "LAST_UPDATED_BY" "FND_GLOBAL.USER_ID",
    "LAST_UPDATE_LOGIN" "FND_GLOBAL.LOGIN_ID",
    "REQUEST_ID"
 )


 

Core HR Reports 1 : Pesronal and assignment Details history Report

create or replace PACKAGE BODY XXARJ_PER_ASSG_DET_REP_PKG AS

    PROCEDURE XXARJ_PER_ASN_DET_IND_PROC(errbuf OUT VARCHAR2,
                                        retcode OUT NUMBER,
                                        P_EFFECTIVE_DATE       IN VARCHAR2,
                                        P_ORGANIZATION_ID      IN NUMBER,
                                        P_ROLL_UP              IN VARCHAR2,
                                        p_location_id          IN NUMBER,
                                        p_job_id               IN NUMBER,
                                        p_grade_id             IN NUMBER,
                                        p_user_person_type     IN VARCHAR2,
                                        P_EMPLOYEE_NUMBER      IN VARCHAR2,
                                        p_ass_attribute1       IN varchar2,
                                        p_NATIONALITY          IN VARCHAR2,
                                        p_sex                  IN VARCHAR2,
                                        p_DOJ                  IN DATE,
                                        P_PAN                  IN VARCHAR2,
                                        P_PAN_Applied_for      IN VARCHAR2,
                                        p_manager_number       IN VARCHAR2,
                                        p_Passport             IN VARCHAR2)
    AS
        l_date DATE;
        CURSOR XXARJ_emp_details_cur(l_date VARCHAR2) is
        SELECT papf.person_id person_id
              ,papf.business_group_id business_group_id
              ,papf.employee_number employee_number
              ,papf.attribute1 previous_employee_number
              ,papf.full_name full_name
              ,papf.original_date_of_hire doj
              ,papf.effective_start_date  latest_start_date    -- added on 18th nov 2011
              ,hr_general.decode_lookup('SEX', papf.sex) gender
              ,papf.date_of_birth birth_date
              ,Round((months_between(l_date, papf.date_of_birth) / 12),1) age
              ,hr_general.decode_lookup('PER_US_COUNTRY_CODE', papf.country_of_birth) country_of_birth
              ,hr_general.decode_lookup('MAR_STATUS', papf.Marital_Status) marital_status
              ,hr_general.decode_lookup('NATIONALITY',  papf.NATIONALITY) nationality
              ,hr_general.decode_lookup('IN_RESIDENTIAL_STATUS', papf.per_information7) residential_status
              ,hr_general.decode_lookup('REGISTERED_DISABLED', papf.registered_disabled_flag) registered_disabled
              ,papf.blood_type blood_type
              ,papf.per_information14 pan_reference_number
              ,papf.per_information4 pan
              ,hr_general.decode_lookup('YES_NO', papf.per_information5) pan_applied_for
              ,papf.per_information8 provident_fund_number
              ,papf.per_information9 esi_number
              ,papf.per_information10 superannuation_number
              ,papf.per_information11 group_insurance_number
              ,papf.per_information12 gratutity_number
              ,papf.per_information13 pension_fund_number
              ,rtrim(pa.address_line1 ||', '||
               pa.address_line2 ||', '||
               pa.address_line3 ||', '||
               pa.add_information14 ||', '||
               hr_general.decode_lookup('IN_STATES', pa.add_information15) ||', '||
               hr_general.decode_lookup('PER_US_COUNTRY_CODE', pa.country) ||', '||
               pa.postal_code, ', ') address
              ,papf.email_address email
              ,replace(rtrim((SELECT rtrim (xmlagg (xmlelement (e, phone_number || ', ')).extract ('//text()'), ',') phone_numbers
                FROM per_phones
                WHERE parent_id = papf.person_id
                AND phone_type = 'M'
                GROUP BY parent_id), ', '), chr(10)) mobile_number
              ,replace(rtrim((SELECT rtrim (xmlagg (xmlelement (e, phone_number || ', ')).extract ('//text()'), ',') phone_numbers
                FROM per_phones
                WHERE parent_id = papf.person_id
                AND phone_type = 'P'
                GROUP BY parent_id), ', '), chr(10)) emergency_number
              ,ppei.pei_information2 passport_number
              ,ppei.pei_information6 emigration_check_required
              ,TO_CHAR(to_date(substr(ppei.pei_information4,1,10),'YYYY-MM-DD'),'DD-Mon-YYYY') passport_issue_date
              ,TO_CHAR(to_date(substr(ppei.pei_information5,1,10),'YYYY-MM-DD'),'DD-Mon-YYYY') passport_expiry_date
              ,ppei.pei_information3 issue_place
              ,hr_general.decode_lookup('PER_US_COUNTRY_CODE',ppei.pei_information7) passport_issuing_country
              ,(select 'Licence Number: ' || pac.segment1 ||
                      ' Licence Type: ' || pac.segment2 ||
                      ' Issue Date: ' || TO_CHAR(to_date(substr(pac.segment3,1,10),'YYYY-MM-DD'),'DD-Mon-YYYY') ||
                      ' Licence Expiry Date: ' || TO_CHAR(to_date(substr(pac.segment4,1,10),'YYYY-MM-DD'),'DD-Mon-YYYY') ||
                      ' Place Of Issue:?' || pac.segment5 ||
                      ' Issuing Country:?' || hr_general.decode_lookup('PER_US_COUNTRY_CODE',pac.segment6)
                  from  fnd_id_flex_structures fifs
                        ,per_person_analyses ppa
                        ,per_analysis_criteria pac
                  where       fifs.id_flex_structure_code = 'XXARJ_DRIVING_LICENSE'
                        AND   ppa.person_id                  = papf.person_id
                        AND   ppa.id_flex_num                = fifs.id_flex_num
                        AND   ppa.business_group_id          = papf.business_group_id
                        AND   pac.analysis_criteria_id       = ppa.analysis_criteria_id
                        AND   pac.id_flex_num                = ppa.id_flex_num
                        AND   fifs.id_flex_num               = pac.id_flex_num
                        AND   ppa.date_from = (select max(ppa1.date_from) from per_person_analyses ppa1 where ppa1.person_id = papf.person_id)
                        AND   ROWNUM <= 1
              ) driving_licence
              ,(select 'Work Station: ' || pac.segment1 ||
                      ' Extension Number: ' || pac.segment2 ||
                      ' Floor: ' || pac.segment3 ||
                      ' Building Number: ' || pac.segment4
                  from  fnd_id_flex_structures fifs
                        ,per_person_analyses ppa
                        ,per_analysis_criteria pac
                  where       fifs.id_flex_structure_code = 'XXARJ_WORK_STATION'
                        AND   ppa.person_id                  = papf.person_id
                        AND   ppa.id_flex_num                = fifs.id_flex_num
                        AND   ppa.business_group_id          = papf.business_group_id
                        AND   pac.analysis_criteria_id       = ppa.analysis_criteria_id
                        AND   pac.id_flex_num                = ppa.id_flex_num
                        AND   fifs.id_flex_num               = pac.id_flex_num
                        AND   ppa.date_from = (select max(ppa1.date_from) from per_person_analyses ppa1 where ppa1.person_id = papf.person_id)
                        AND   ROWNUM <= 1
              ) work_station_details
              ,(select 'BGC Conducted: ' || pac.segment1 ||
                      ' BGC Status: ' || pac.segment2 ||
                      ' BGC Conducted On: ' || pac.segment3
                  from  fnd_id_flex_structures fifs
                        ,per_person_analyses ppa
                        ,per_analysis_criteria pac
                  where       fifs.id_flex_structure_code = 'XXARJ_BACKGROUND_CHECK'
                        AND   ppa.person_id                  = papf.person_id
                        AND   ppa.id_flex_num                = fifs.id_flex_num
                        AND   ppa.business_group_id          = papf.business_group_id
                        AND   pac.analysis_criteria_id       = ppa.analysis_criteria_id
                        AND   pac.id_flex_num                = ppa.id_flex_num
                        AND   fifs.id_flex_num               = pac.id_flex_num
                        AND   ppa.date_from = (select max(ppa1.date_from) from per_person_analyses ppa1 where ppa1.person_id = papf.person_id)
                        AND   ROWNUM <= 1
              ) bgc_details
              ,nvl(XXARJ_hr_general_pkg.get_organization_name(paaf.organization_id, 'Entity')
                  ,XXARJ_hr_general_pkg.get_organization_name(paaf.organization_id, 'Business Group')) entity
              ,hr_general.decode_lookup('ORG_TYPE',haou.type) organization_type
              ,hr_general.decode_organization(paaf.organization_id) organization_name
              ,hr_general.decode_location(paaf.location_id) location_name
              ,hr_general.decode_job(paaf.job_id) job_name
              ,hr_general.decode_grade(paaf.grade_id) grade_name
              ,ppt.user_person_type person_type
              ,initcap(paaf.employee_category) employee_category
              ,papf_sup.full_name manager_name
              ,papf_sup.employee_number manager_number
              ,flv.meaning employee_role
              ,papf_admin.full_name admin_name
              ,papf_admin.employee_number admin_number
        FROM   per_all_people_f papf
              ,per_all_assignments_f paaf
              ,per_addresses pa
              ,per_people_extra_info ppei
              ,hr_all_organization_units haou
              ,per_person_type_usages_f pptuf
              ,per_person_types ppt
              ,per_all_people_f papf_sup
              ,fnd_lookup_values flv
              ,per_all_people_f papf_admin
        WHERE papf.person_id = paaf.person_id
        AND   papf.current_employee_flag = 'Y'
        AND   paaf.primary_flag = 'Y'
        AND   paaf.assignment_type = 'E'
        AND   paaf.assignment_status_type_id in (1,3096)
        --AND   papf.business_group_id = 81
        AND   pa.person_id(+) = papf.person_id
        AND   pa.primary_flag(+) = 'Y'
        AND   pa.style(+) = 'IN'
        AND   l_date BETWEEN pa.date_from(+) AND nvl(pa.date_to(+), to_date('31-DEC-4712'))
        AND   l_date between papf.effective_start_date and papf.effective_end_date
        AND   l_date between paaf.effective_start_date and paaf.effective_end_date
        AND   (papf.employee_number LIKE 'P%' OR papf.employee_number LIKE 'C%')
        AND   ppei.person_id(+) = papf.person_id
        AND   ppei.information_type(+) = 'IN_PASSPORT_DETAILS'
        AND   paaf.organization_id = haou.organization_id
        AND   papf.person_id = pptuf.person_id
        AND   ppt.person_type_id = pptuf.person_type_id
        AND   l_date between pptuf.effective_start_date and pptuf.effective_end_date
        AND   ppt.system_person_type = 'EMP'
        AND   ppt.active_flag = 'Y'
        AND   paaf.supervisor_id = papf_sup.person_id(+)
        AND   l_date between papf_sup.effective_start_date(+) and papf_sup.effective_end_date(+)
        AND   paaf.ass_attribute1 = flv.lookup_code(+)
        AND   flv.lookup_type(+) = 'XXARJ_ROLE'
        AND   paaf.ASS_ATTRIBUTE3 = papf_admin.person_id(+)
        AND   l_date between papf_admin.effective_start_date(+) and papf_admin.effective_end_date(+)
        /*AND   (paaf.organization_id IN (SELECT OSE.organization_id_child
                                        FROM  PER_ORG_STRUCTURE_ELEMENTS_V OSE
                                        WHERE P_ROLL_UP = 'Y'
                                        and org_structure_version_id = XXHCM_HR_HOST.get_hierarchy_id()
                                        START WITH OSE.organization_id_Parent = P_ORGANIZATION_ID
                                        CONNECT BY OSE.organization_id_Parent = PRIOR OSE.organization_id_child)
                                        OR paaf.organization_id = P_ORGANIZATION_ID)*/
        /*AND ((PAAF.ORGANIZATION_ID       IN (SELECT  OSE.ORGANIZATION_ID_CHILD
                                         FROM  PER_ORG_STRUCTURE_ELEMENTS_V OSE
                                         WHERE P_ROLL_UP = 'Y'
                                         AND   ORG_STRUCTURE_VERSION_ID = 61
                                         START WITH OSE.ORGANIZATION_ID_PARENT = P_ORGANIZATION_ID
                                         CONNECT BY OSE.ORGANIZATION_ID_PARENT = PRIOR OSE.ORGANIZATION_ID_CHILD ))
          OR (PAAF.ORGANIZATION_ID=P_ORGANIZATION_ID))*/
        AND   ((paaf.organization_id IN (SELECT child_org_id
                                         FROM XXARJ_org_structure
                                         WHERE P_ROLL_UP = 'Y'
                                         AND parent_org_id = P_ORGANIZATION_ID))
              OR (PAAF.ORGANIZATION_ID=P_ORGANIZATION_ID))
        AND   nvl(paaf.location_id,-1) = nvl(nvl(p_location_id, paaf.location_id),-1)
        AND   nvl(paaf.job_id,-1) = nvl(nvl(p_job_id, paaf.job_id),-1)
        AND   nvl(paaf.grade_id,-1) = nvl(nvl(p_grade_id, paaf.grade_id),-1)
        AND   pptuf.person_type_id = nvl(p_user_person_type, pptuf.person_type_id)
        AND   papf.person_id = nvl(P_EMPLOYEE_NUMBER, papf.person_id)
        AND   nvl(paaf.ass_attribute1,-1) = nvl(p_ass_attribute1,nvl(paaf.ass_attribute1,-1))
        AND   nvl(papf.nationality,-1) = nvl(p_NATIONALITY,nvl(papf.nationality,-1))
        AND   papf.sex = nvl(p_sex,papf.sex)
        AND   nvl(papf.original_date_of_hire,to_date('01-Jan-1951')) = nvl(nvl(p_DOJ,papf.original_date_of_hire),to_date('01-Jan-1951'))
        AND   nvl(papf.per_information4,-1) = nvl(nvl(P_PAN, papf.per_information4),-1)
        AND   nvl(hr_general.decode_lookup('YES_NO',papf.per_information5),-1)=nvl(nvl(P_PAN_Applied_for,hr_general.decode_lookup('YES_NO',papf.per_information5)),-1)
        AND   nvl(paaf.supervisor_id,-1) = nvl(nvl(p_manager_number, paaf.supervisor_id),-1)
        AND   nvl2(ppei.pei_information2, 'Y', 'N') = nvl(p_Passport, nvl2(ppei.pei_information2, 'Y', 'N'));
        --order by papf.person_id;
        --and papf.employee_number = 'P1002030';

        cursor highest_qualification(p_person_id number) is
          select pqt.name Highest_Qualification
                ,pq.attribute1 Type_Specialisation
                ,pq.grade_attained Grade
                ,pe.name University
                ,DECODE(pea.full_time,'Y' , 'Full Time' , 'N' , 'Part Time' , pea.full_time) Full_Time_Part_Time
                ,pq.end_date year_of_completion
                ,pe.name School_College
          from  per_qualifications_v pq
               ,per_qualification_types pqt
               ,per_establishment_attendances  pea
               ,per_establishments pe
          where pq.person_id                                          = p_person_id
          AND pq.person_id                                            = pea.person_id(+)
          AND pq.business_group_id                                    = pea.business_group_id(+)
          AND pq.attendance_id                                        = pea.attendance_id(+)
          AND pea.establishment_id                                    = pe.establishment_id(+)
          AND pq.qualification_type_id                                = pqt.qualification_type_id(+)
          AND (nvl(pq.end_date,to_date('01-Jan-0001','DD-Mon-YYYY'))  IN (SELECT MAX(nvl(pq1.end_date,to_date('01-Jan-0001','DD-Mon-YYYY')))
                                                                            FROM per_qualifications_v pq1
                                                                            WHERE pq1.person_id = p_person_id)
              OR(pq.end_date IS NULL))
          AND (nvl(pea.attended_end_date,to_date('01-Jan-0001','DD-Mon-YYYY')) IN (SELECT MAX(nvl(pea1.attended_end_date,to_date('01-Jan-0001','DD-Mon-YYYY')))
                                                                                      FROM per_establishment_attendances pea1
                                                                                      WHERE pea1.person_id = pq.person_id
                                                                                      AND pea1.business_group_id = pq.business_group_id)
              OR( pea.attended_end_date IS NULL))
          AND ROWNUM <= 1;

        cursor previous_employment(p_person_id number,p_business_group_id number) is
          select ppe.employer_name Employer
            ,ppe.employer_address Emp_Address
            ,hr_general.decode_lookup('PER_US_COUNTRY_CODE',ppe.employer_country) Country
            ,hr_general.decode_lookup('PREV_EMP_TYPE',ppe.employer_type) Type
            ,hr_general.decode_lookup('PREV_EMP_SUBTYPE',ppe.employer_subtype) Sub_Type
            ,ppe.start_date Start_Date
            ,ppe.end_date End_Date
            ,ppj.job_name Last_Designation
            ,ROUND(MONTHS_BETWEEN(ppe.end_date,ppe.start_date) / 12,1) Prev_Experience
            ,(SELECT  ROUND(MONTHS_BETWEEN(l_date,Min(ppe.start_date)) / 12,1)
              FROM  per_previous_employers ppe
              WHERE ppe.person_id                                     = p_person_id
              )  Total_Experience
            ,(SELECT ROUND(MONTHS_BETWEEN(l_date,original_date_of_hire )/12,1)
              FROM per_all_people_f
              WHERE person_id = p_person_id
              AND l_date BETWEEN effective_start_date AND effective_end_date) EXP_IN_PLG
          from per_previous_employers ppe
              ,per_previous_jobs ppj
          where ppe.person_id                                         = p_person_id
          AND ppe.business_group_id                                   = nvl(p_business_group_id, ppe.business_group_id)
          AND ppj.previous_employer_id(+)                             = ppe.previous_employer_id
          AND (nvl(ppe.start_date,to_date('01-Jan-0001','DD-Mon-YYYY')))  IN (SELECT MAX(nvl(ppe.start_date,to_date('01-Jan-0001','DD-Mon-YYYY')))
                                                                              FROM per_previous_employers ppe
                                                                              WHERE ppe.person_id = p_person_id)
          AND ROWNUM <= 1;

        cursor language_prof(p_person_id number, p_business_group_id number) is
          select  pac.segment1
                ,pac.segment2
                ,pac.segment3
                ,pac.segment4
          from  fnd_id_flex_structures fifs
                ,per_person_analyses ppa
                ,per_analysis_criteria pac
          where       fifs.id_flex_structure_code    = 'XXARJ_WORK_STATION'
                AND   ppa.person_id                  = p_person_id
                AND   ppa.id_flex_num                = fifs.id_flex_num
                AND   ppa.business_group_id          = p_business_group_id
                AND   pac.analysis_criteria_id       = ppa.analysis_criteria_id
                AND   pac.id_flex_num                = ppa.id_flex_num
                AND   fifs.id_flex_num               = pac.id_flex_num;

        i           number:=1;
        --L_EMP       VARCHAR2(50);
        L_EXP_TOT   VARCHAR2(50);
        L_EXP_PLG   VARCHAR2(50);
        l_e_ph_no   VARCHAR2(50);
        l_mb_no     VARCHAR2(50);
        l_speak varchar2(1000):='Speak :';
        l_write varchar2(1000):='Write :';
        l_read varchar2(1000):='Read :';
        l_result  VARCHAR2(10000) :='';
        L_LATEST_START_DATE DATE;
        L_ENTITY VARCHAR2(10000);
    BEGIN
        l_date := fnd_date.canonical_to_date(P_EFFECTIVE_DATE);
        fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<?xml version="1.0" ?>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<PERSON_ASSIGNMENT_DETAIL>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<P_DATE><![CDATA['|| l_date ||']]></P_DATE>');

        FOR REEC_EMPLOYEE_DETAILS IN XXARJ_emp_details_cur(l_date)
        LOOP
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<G_PER_ASSG_DETAILS>');
           --fnd_file.put_line(fnd_file.LOG,   '1st:=> ' || REEC_EMPLOYEE_DETAILS.employee_number);
         /*  BEGIN
           SELECT MAX(EFFECTIVE_START_DATE) INTO L_LATEST_START_DATE FROM PER_ALL_PEOPLE_F
           WHERE EMPLOYEE_NUMBER =REEC_EMPLOYEE_DETAILS.employee_number
        
           EXCEPTION WHEN OTHERS THEN
           L_LATEST_START_DATE := REEC_EMPLOYEE_DETAILS.latest_start_date;
           END;*/ -- THIS IS NOT DONE BECAUSE WE NEED TO FETCH AS PER EFFECTIVE DATE PARAMETER
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Employee_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.employee_number || ']]></Employee_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Previous_Employee_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.previous_employee_number || ']]></Previous_Employee_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Full_Name><![CDATA[' || REEC_EMPLOYEE_DETAILS.full_name || ']]></Full_Name>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<DOJ><![CDATA[' || REEC_EMPLOYEE_DETAILS.doj || ']]></DOJ>');
          
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<latest_start_date><![CDATA[' || REEC_EMPLOYEE_DETAILS.latest_start_date|| ']]></latest_start_date>');--added on 18th nov
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Gender><![CDATA[' || REEC_EMPLOYEE_DETAILS.gender || ']]></Gender>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Birth_Date><![CDATA[' || REEC_EMPLOYEE_DETAILS.birth_date || ']]></Birth_Date>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Age><![CDATA[' || REEC_EMPLOYEE_DETAILS.age || ']]></Age>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Country_of_Birth><![CDATA[' || REEC_EMPLOYEE_DETAILS.country_of_birth || ']]></Country_of_Birth>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Marital_Status><![CDATA[' || REEC_EMPLOYEE_DETAILS.marital_status || ']]></Marital_Status>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Nationality><![CDATA[' || REEC_EMPLOYEE_DETAILS.nationality || ']]></Nationality>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Residential_Status><![CDATA[' || REEC_EMPLOYEE_DETAILS.residential_status || ']]></Residential_Status>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Registered_Disabled><![CDATA[' || REEC_EMPLOYEE_DETAILS.registered_disabled || ']]></Registered_Disabled>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Blood_Type><![CDATA[' || REEC_EMPLOYEE_DETAILS.blood_type || ']]></Blood_Type>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<PAN_Reference_Number><![CDATA['|| REEC_EMPLOYEE_DETAILS.pan_reference_number || ']]></PAN_Reference_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<PAN><![CDATA[' || REEC_EMPLOYEE_DETAILS.pan || ']]></PAN>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<PAN_Applied_For><![CDATA[' || REEC_EMPLOYEE_DETAILS.pan_applied_for || ']]></PAN_Applied_For>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Provident_Fund_Number><![CDATA['|| REEC_EMPLOYEE_DETAILS.provident_fund_number || ']]></Provident_Fund_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<ESI_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.esi_number || ']]></ESI_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Superannuation_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.superannuation_number || ']]></Superannuation_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Group_Insurance_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.group_insurance_number || ']]></Group_Insurance_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Gratutity_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.gratutity_number || ']]></Gratutity_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Pension_Fund_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.pension_fund_number || ']]></Pension_Fund_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Address><![CDATA[' || REEC_EMPLOYEE_DETAILS.address || ']]></Address>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Email><![CDATA[' || REEC_EMPLOYEE_DETAILS.email || ']]></Email>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Mobile_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.mobile_number || ']]></Mobile_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Emergency_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.emergency_number || ']]></Emergency_Number>');
        FOR REEC_EMPLOYEE_QUALIFICATION IN highest_qualification(REEC_EMPLOYEE_DETAILS.person_id)
        LOOP
           ---Highest Qualification
           --fnd_file.put_line(fnd_file.LOG,   '2nd');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Highest_Qualification><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.Highest_Qualification || ']]></Highest_Qualification>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Type_Specialisation><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.Type_Specialisation || ']]></Type_Specialisation>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Grade><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.Grade || ']]></Grade>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<University><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.University || ']]></University>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Full_Time_Part_Time><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.Full_Time_Part_Time || ']]></Full_Time_Part_Time>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<year_of_completion><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.year_of_completion || ']]></year_of_completion>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<School_College ><![CDATA[' || REEC_EMPLOYEE_QUALIFICATION.School_College || ']]></School_College >');
        END LOOP;
           ---------------------------------------------------------------------------------------------------------------------------------
        FOR REEC_EMPLOYER_DETAILS IN previous_employment(REEC_EMPLOYEE_DETAILS.person_id, REEC_EMPLOYEE_DETAILS.business_group_id)
        LOOP
           ----Previous Employment
           --fnd_file.put_line(fnd_file.LOG,   '3rd');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Employer><![CDATA[' || REEC_EMPLOYER_DETAILS.Employer || ']]></Employer>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Emp_Address><![CDATA[' || REEC_EMPLOYER_DETAILS.Emp_Address || ']]></Emp_Address>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Country><![CDATA[' || REEC_EMPLOYER_DETAILS.Country || ']]></Country>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Type><![CDATA[' || REEC_EMPLOYER_DETAILS.Type || ']]></Type>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Sub_Type><![CDATA[' || REEC_EMPLOYER_DETAILS.Sub_Type || ']]></Sub_Type>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Start_Date><![CDATA[' || REEC_EMPLOYER_DETAILS.Start_Date || ']]></Start_Date>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<End_Date><![CDATA[' || REEC_EMPLOYER_DETAILS.End_Date || ']]></End_Date>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Last_Designation><![CDATA[' || REEC_EMPLOYER_DETAILS.Last_Designation || ']]></Last_Designation>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Total_Experience><![CDATA[' || REEC_EMPLOYER_DETAILS.Total_Experience || ']]></Total_Experience>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Total_Exp_PLG><![CDATA[' || REEC_EMPLOYER_DETAILS.EXP_IN_PLG || ']]></Total_Exp_PLG>');
        END LOOP;
       ----------------------------------------------------------------------------------------------------------------------------------
           ---Passport Details
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Passport_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.passport_number || ']]></Passport_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<ECNR_Required><![CDATA[' || REEC_EMPLOYEE_DETAILS.emigration_check_required || ']]></ECNR_Required>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Passport_Issue_Date><![CDATA[' || REEC_EMPLOYEE_DETAILS.passport_issue_date || ']]></Passport_Issue_Date>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Passport_Expiry_Date><![CDATA[' || REEC_EMPLOYEE_DETAILS.passport_expiry_date || ']]></Passport_Expiry_Date>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Issue_Place><![CDATA[' || REEC_EMPLOYEE_DETAILS.issue_place || ']]></Issue_Place>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Passport_Issuing_Country><![CDATA[' || REEC_EMPLOYEE_DETAILS.passport_issuing_country || ']]></Passport_Issuing_Country>');
          ------------------------------------------------------------------------------------------------------------------------------------
           --fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Have_Passport><![CDATA['           || REEC_EMPLOYEE_DETAILS.Have_Passport                                 || ']]></Have_Passport>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<DRIVING_LICENCE_DETAILS><![CDATA[' || REEC_EMPLOYEE_DETAILS.driving_licence || ']]></DRIVING_LICENCE_DETAILS>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<WORK_STATION_DETAILS><![CDATA[' || REEC_EMPLOYEE_DETAILS.work_station_details || ']]></WORK_STATION_DETAILS>');
        l_speak :='Speak :';
        l_write :='Write :';
        l_read  :='Read :';
        l_result :='';
        for i in language_prof(REEC_EMPLOYEE_DETAILS.person_id, REEC_EMPLOYEE_DETAILS.business_group_id)
        loop
        --fnd_file.put_line(fnd_file.LOG,   '4th');
            if i.segment2 <> 'No' then
                l_speak:=l_speak||' '||i.segment1;
            end if;
    --
            if i.segment3 <> 'No' then
                l_read:=l_read||' '||i.segment1;
            end if;
    --
            if i.segment4 <> 'No' then
                l_write:=l_write||' '||i.segment1;
            end if;
            l_result:=l_speak||' :: '||l_read||' :: '||l_write;
            fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Language_Details><![CDATA[' || l_result || ']]></Language_Details>');
        end loop;
           --fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Language_Details><![CDATA['           || REEC_EMPLOYEE_DETAILS.Language_Details                                 || ']]></Language_Details>');
           ---------------------
           IF REEC_EMPLOYEE_DETAILS.organization_type ='Entity' THEN
           L_ENTITY := REEC_EMPLOYEE_DETAILS.organization_name;
           ELSE
           L_ENTITY := REEC_EMPLOYEE_DETAILS.entity;
           END IF;
          
          
           -------------------------
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Entity><![CDATA[' || L_ENTITY || ']]></Entity>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Organization_Type><![CDATA[' || REEC_EMPLOYEE_DETAILS.organization_type || ']]></Organization_Type>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Organization><![CDATA[' || REEC_EMPLOYEE_DETAILS.organization_name || ']]></Organization>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Location><![CDATA[' || REEC_EMPLOYEE_DETAILS.location_name || ']]></Location>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Job><![CDATA[' || REEC_EMPLOYEE_DETAILS.job_name || ']]></Job>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Assignment_Grade><![CDATA[' || REEC_EMPLOYEE_DETAILS.grade_name || ']]></Assignment_Grade>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<person_type><![CDATA[' || REEC_EMPLOYEE_DETAILS.person_type || ']]></person_type>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Employee_Category><![CDATA[' || REEC_EMPLOYEE_DETAILS.employee_category || ']]></Employee_Category>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Manager><![CDATA[' || REEC_EMPLOYEE_DETAILS.manager_name || ']]></Manager>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Manager_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.manager_number || ']]></Manager_Number>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<BGC_Details><![CDATA[' || REEC_EMPLOYEE_DETAILS.bgc_details || ']]></BGC_Details>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Employee_Role><![CDATA[' || REEC_EMPLOYEE_DETAILS.employee_role || ']]></Employee_Role>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Admin_Manager><![CDATA[' || REEC_EMPLOYEE_DETAILS.admin_name || ']]></Admin_Manager>');
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Admin_Manager_Number><![CDATA[' || REEC_EMPLOYEE_DETAILS.admin_number || ']]></Admin_Manager_Number>');
           --fnd_file.put_line(fnd_file.LOG,   '5th:=> ' || REEC_EMPLOYEE_DETAILS.employee_number);
           fnd_file.PUT_LINE(fnd_file.OUTPUT,   '</G_PER_ASSG_DETAILS>');
        END LOOP;
        fnd_file.PUT_LINE(fnd_file.OUTPUT,   '</PERSON_ASSIGNMENT_DETAIL>');
    END XXARJ_PER_ASN_DET_IND_PROC;
END XXARJ_PER_ASSG_DET_REP_PKG;

Payroll main Reports 2 : Pay Slip Report

create or replace PACKAGE BODY XXARJ_PAYSLIP_GENERATION_PKG AS
FUNCTION XXARJ_NET_SAL_FNC
  (
    P_ASG_ACTION_ID IN NUMBER ,
    P_BAL_NAME      IN VARCHAR2 ,
    P_DIM_NAME      IN VARCHAR2
  )
  RETURN NUMBER
AS
  P_NET_SALARY NUMBER:=0;
  P_DEF_BAL_ID NUMBER;
BEGIN
  P_DEF_BAL_ID := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id(P_BAL_NAME, P_DIM_NAME,81,'IN');
  P_NET_SALARY := pay_balance_pkg.get_value(P_DEF_BAL_ID, P_ASG_ACTION_ID);
  RETURN P_NET_SALARY;
EXCEPTION
WHEN OTHERS THEN
  RETURN P_NET_SALARY;
  fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function XXARJ_NET_SAL_FNC: '||SQLCODE||'   '||SQLERRM);
END XXARJ_NET_SAL_FNC;


--------
---
--First day of month
---
FUNCTION fday_ofmonth(value_in DATE)
RETURN DATE IS
 vMo VARCHAR2(2);
 vYr VARCHAR2(4);
BEGIN
  vMo := TO_CHAR(value_in, 'MM');
  vYr := TO_CHAR(value_in, 'YYYY');
  RETURN TO_DATE(vMo || '-01-' || vYr, 'MM-DD-YYYY');
EXCEPTION
  WHEN OTHERS THEN
    RETURN TO_DATE('01-01-1900', 'MM-DD-YYYY');
END fday_ofmonth;
---
--Number to word conversion
---
FUNCTION notoword(amt number
                 )return varchar2
AS
ntword varchar2(10000);
BEGIN
     select replace(replace(' ' ||
            decode(floor(amt/power(10,7)),0,'',
            initcap(to_char(to_date(floor(amt/power(10,7)),
            'J'),'JSP') || ' crore ')) ||
            decode(floor((amt-power(10,7)*floor(amt/power(10,7)))/power(10,5)),0,'',
            initcap(to_char(to_date(floor((amt-power(10,7)*floor(amt/power(10,7)))/power(10,5)),
            'J'),'JSP') || ' lac ')) ||
            decode(floor((amt-power(10,5)*floor(amt/power(10,5)))/power(10,3)),0,'',
            initcap(to_char(to_date(floor((amt-power(10,5)*floor(amt/power(10,5)))/power(10,3)),
            'J'),'JSP') || ' thousand ')) ||
            decode(floor((amt-power(10,3)*floor(amt/power(10,3)))/power(10,2)),0,'',
            initcap(to_char(to_date(floor((amt-power(10,3)*floor(amt/power(10,3)))/power(10,2)),
            'J'),'JSP') || ' hundred ')) ||
            decode(floor((amt-power(10,2)*floor(amt/power(10,2)))/power(10,0)),0,'',
            initcap(to_char(to_date(floor((amt-power(10,2)*floor(amt/power(10,2)))/power(10,0)),
            'J'),'JSP') || ' ')) ||
            'and ' ||
            decode(power(10,2)*(amt-floor(amt)),0,'Zero',
            initcap(to_char(to_date(power(10,2)*(amt-floor(amt)),
            'J'),'JSP') )) ||
            ' Paise ' ||
            'Only','-',' '),' and Zero Paise','')
    into    ntword
    from    dual;
    return ntword;
EXCEPTION
   WHEN OTHERS THEN
        fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function notoword: '||SQLCODE||'   '||SQLERRM);
END   notoword;

-------------
-- ||XXARJ_ELEMENT_VALUE_TILLDATE_FNC used to calculate sum of Arrears From RUN RESULT VALUE of an element
-------------
FUNCTION XXARJ_ELEMENT_VALUE_TILL_FNC
  (
    P_ASSIGNMENT_ID    NUMBER ,
    P_INPUT_VALUE_NAME VARCHAR2 ,
    P_ELEMENT_NAME     VARCHAR2 ,
    P_FIRST_DATE DATE,
    P_DATE DATE )
  RETURN NUMBER
AS
  L_ELEMENT_VALUE NUMBER:=0;
BEGIN
  SELECT SUM(fnd_number.canonical_to_number(NVL(PRRV.RESULT_VALUE,0)))
  INTO L_ELEMENT_VALUE
  FROM PAY_ELEMENT_TYPES_F PETF,
    PAY_RUN_RESULTS PRR,
    PAY_RUN_RESULT_VALUES PRRV,
    PAY_INPUT_VALUES_F PIVF,
    PAY_ASSIGNMENT_ACTIONS PAA,
    PAY_PAYROLL_ACTIONS PPA
  WHERE PPA.ACTION_TYPE       IN('R', 'Q', 'I', 'B')
  AND PPA.ACTION_STATUS        = 'C'
  AND PPA.PAYROLL_ACTION_ID    = PAA.PAYROLL_ACTION_ID
  AND PAA.ACTION_STATUS        = 'C'
  AND PRR.ASSIGNMENT_ACTION_ID = PAA.ASSIGNMENT_ACTION_ID
  AND PAA.ASSIGNMENT_ID        = P_ASSIGNMENT_ID
  AND PETF.ELEMENT_NAME        = P_ELEMENT_NAME
  AND (PETF.LEGISLATION_CODE   = 'IN'
  OR PETF.BUSINESS_GROUP_ID    = FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
  AND PETF.ELEMENT_TYPE_ID     = PRR.ELEMENT_TYPE_ID
  AND PRR.RUN_RESULT_ID        = PRRV.RUN_RESULT_ID
  AND PIVF.NAME                = P_INPUT_VALUE_NAME
  AND (PIVF.LEGISLATION_CODE   = 'IN'
  OR PIVF.BUSINESS_GROUP_ID    = FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
  AND PIVF.INPUT_VALUE_ID      = PRRV.INPUT_VALUE_ID
  AND PETF.ELEMENT_TYPE_ID     = PIVF.ELEMENT_TYPE_ID
  AND PPA.DATE_EARNED BETWEEN P_FIRST_DATE AND LAST_DAY(P_DATE)
  AND P_DATE BETWEEN PETF.EFFECTIVE_START_DATE AND PETF.EFFECTIVE_END_DATE
  AND P_DATE BETWEEN PIVF.EFFECTIVE_START_DATE AND PIVF.EFFECTIVE_END_DATE;
  RETURN L_ELEMENT_VALUE;
EXCEPTION
WHEN OTHERS THEN
  fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function XXARJ_ELEMENT_VALUE_TILLDATE_FNC:     '||SQLERRM);
  RETURN L_ELEMENT_VALUE;
END XXARJ_ELEMENT_VALUE_TILL_FNC;
-------------------------------------------------------------------------------------
---Function get_projection_value
---Purpose:Fetches all the elements with projected value
---        from first payroll run of the financial year
---        to till date(the date of this payslip generation)
---Parameter:IN parameter ->Employee Number
---                         Element Name
---                         Month
---                         Year
---                         Classification Name(Earnig or Allowance etc
---                         Processing Type(Recurring or Non recurring)
---          OUT Parameter->Non recurring value if the element is non recurring
---------------------------------------------------------------------------------------
FUNCTION get_projection_value(p_person_id           IN     NUMBER
                             ,p_element_name        IN     VARCHAR2
                             ,P_effective_month     IN     VARCHAR2
                             ,P_effective_year      IN     NUMBER
                             ,p_classification_name IN     VARCHAR2
                             ,p_processing_type     IN OUT VARCHAR2
                             ,p_non_rec             OUT    NUMBER
                         --   ,p_rem_flag            IN     VARCHAR2
                             ,p_context_value       IN     VARCHAR2
                             ,p_period_left         OUT    NUMBER
                             )RETURN NUMBER
AS
TYPE month_type IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER;
month_array month_type;
l_assignment_action_id      NUMBER        := 0;
l_assignment_id             NUMBER        := 0;
l_element_run_result_value  NUMBER        := 0;
l_standard_value            NUMBER        := 0;
l_taxable_value             NUMBER        := 0;
l_tot_non_rec               NUMBER        := 0;
l_pay_gen_date              DATE;
from_date                   NUMBER;
total_sum                   NUMBER:=0;
index_num                   NUMBER;
period_left                 NUMBER;
i                           NUMBER:=1;
p_hra_from_to_date          DATE;
value_till_date             NUMBER;
l_standard_taxable_value    NUMBER;
period_left_DATE            DATE;
l_ear_till_date             NUMBER;
l_first_fin_date            DATE;
l_end_fin_date              DATE;
TABLE_TILL_DATE             DATE;
l_first_tab_date            DATE;
l_element_till_date_value   NUMBER;
l_project_value             NUMBER;
l_total_projected_value     NUMBER;
--20-Aug-2011
l_act_ter_date date;
P_MON_LEVEL number;
l_standard_taxable_value_1 number;
l_element_run_result_value_1 number;
BEGIN
    month_array(1) :=  'APR';
    month_array(2) :=  'MAY';
    month_array(3) :=  'JUN';
    month_array(4) :=  'JUL';
    month_array(5) :=  'AUG';
    month_array(6) :=  'SEP';
    month_array(7) :=  'OCT';
    month_array(8) :=  'NOV';
    month_array(9) :=  'DEC';
    month_array(10):=  'JAN';
    month_array(11):=  'FEB';
    month_array(12):=  'MAR';
    fnd_file.PUT_LINE(fnd_file.LOG,'###########################################');
    fnd_file.PUT_LINE(fnd_file.LOG,'Element Name  :      '||p_element_name);

    FOR i IN 1 ..month_array.COUNT
    LOOP
    BEGIN
        IF month_array(i)=substr(P_effective_month,1,3) THEN
              index_num:=i;
        END IF;
    EXCEPTION
    WHEN OTHERS THEN
         fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Month Array: '||SQLCODE||'   '||SQLERRM);
    END;
    END LOOP;
---------------------------
---Date Formation
---------------------------
    IF UPPER(P_effective_month) IN('JAN','FEB','MAR') THEN
       from_date:=P_effective_year-1;
    ELSE
       from_date:=P_effective_year;
    END IF;
    l_pay_gen_date    :=fnd_conc_date.string_to_date('01' || P_effective_month || P_effective_year);
    l_first_fin_date  :=fnd_conc_date.string_to_date('01' || 'APR'             || from_date);
    l_end_fin_date    :=fnd_conc_date.string_to_date('01' || 'MAR'             || (from_date+1));
--
    l_assignment_action_id      := getAssignmentActionId(l_assignment_id,p_person_id,l_pay_gen_date);
    period_left:=12-index_num;
-----------------------------
---IF the element is earning
-----------------------------
        IF p_classification_name='Earnings'  THEN
        fnd_file.PUT_LINE(fnd_file.LOG,'This is a earning element');

            --  l_standard_value   := get_screen_entry_value(l_assignment_id,p_element_name,l_pay_gen_date);
-----------------------------------------------------------------------------------------
--- IF the payslip generation date is between 01-APR-2010 and 31-MAR-2011
--- then we have to fetch value till august from custom table named "XXARJ_EARNING_TILL_DATE"
--- and pay value from run results for rest of the month.
-------------------------------------------------------------------------------------------
              IF l_pay_gen_date BETWEEN TO_DATE('01-APR-2010') AND  TO_DATE('31-MAR-2011')  THEN
                     fnd_file.PUT_LINE(fnd_file.LOG,'Payslip generation date is between 01-apr-2011 and 31-mar-2012');
                    BEGIN
                       SELECT value,EFFECTIVE_ENDDATE
                       INTO l_ear_till_date , TABLE_TILL_DATE
                       FROM XXARJ_EARNING_TILL_DATE
                       WHERE assignment_id =l_assignment_id
                       AND element_type_id=(SELECT element_type_id
                                            from   pay_element_types_f  petf
                                            WHERE  element_name = p_element_name
                                            and   (petf.legislation_code = 'IN' OR petf.business_group_id =fnd_profile.value('PER_BUSINESS_GROUP_ID')));--fnd_profile.value('PER_BUSINESS_GROUP_ID')));-- )
                       fnd_file.PUT_LINE(fnd_file.LOG,'Value of this element from custom table :  '|| l_ear_till_date  ||'Till  month' || TABLE_TILL_DATE );
                       l_first_tab_date := FDAY_OFMONTH(ADD_MONTHS(TABLE_TILL_DATE,1));
                    EXCEPTION
                    WHEN NO_DATA_FOUND THEN
                          l_ear_till_date:=0;
                          l_first_tab_date:=l_pay_gen_date;
                          fnd_file.PUT_LINE(fnd_file.LOG,'Value is not present for this element from custom table :  '|| l_ear_till_date );
                    END;
                    WHILE l_first_tab_date <= l_pay_gen_date
                    LOOP
                          l_assignment_action_id      := getAssignmentActionId(l_assignment_id,p_person_id,l_first_tab_date);
                          l_element_run_result_value  := l_element_run_result_value   + XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(p_hra_from_to_date
                                                                                                                                        ,l_assignment_action_id
                                                                                                                                        ,p_element_name
                                                                                                                                        ,'Pay Value'
                                                                                                                                        ,l_first_tab_date
                                                                                                                                        ,'IP'
                                                                                                                                        );
                          fnd_file.PUT_LINE(fnd_file.LOG,'Value from run result for this element   :  '|| l_element_run_result_value ||'For the month of ' || l_first_tab_date);
                          l_first_tab_date:=add_months(l_first_tab_date,1);
                    END LOOP;
                    l_standard_value           :=get_screen_entry_value(l_assignment_id,p_element_name,l_pay_gen_date);
                    /*  SELECT months_between(l_end_fin_date,l_pay_gen_date )
                    INTO period_left
                    from dual;  */

                    l_project_value               :=  l_standard_value * period_left;
                    l_element_till_date_value     :=  l_element_run_result_value +  l_ear_till_date;
                    l_total_projected_value       :=  l_element_till_date_value  +  l_project_value;
                    fnd_file.PUT_LINE(fnd_file.LOG,'Standard value of the element :      '||l_standard_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'value till date = custom table value + run result value  :      '||l_element_till_date_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'Projected value = standard value * period left :                '||l_project_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'total projected value  :      '||l_total_projected_value);
              ELSE
                    fnd_file.PUT_LINE(fnd_file.LOG,'Payslip generation date is NOT  between 01-APR-2010 and 31-MAR-2010');
                    FOR i IN 1..index_num
                    LOOP
                        l_assignment_action_id      := getAssignmentActionId(l_assignment_id,p_person_id,l_first_fin_date);
                        l_element_run_result_value  := l_element_run_result_value   + get_run_result_value(p_hra_from_to_date
                                                                                    ,l_assignment_action_id
                                                                                    ,p_element_name
                                                                                    ,'Pay Value'
                                                                                    ,l_first_fin_date
                                                                                    ,'IP'
                                                                                    );
                        fnd_file.PUT_LINE(fnd_file.LOG,'Value from run result for this element   :  '|| l_element_run_result_value ||'For the month of ' || l_first_fin_date);
                        l_first_fin_date:=add_months(l_first_fin_date,1);
                    END LOOP;
                     l_first_fin_date  :=fnd_conc_date.string_to_date('01' || 'APR'             || from_date);
                    Begin
                         Select actual_termination_date
                         Into   l_act_ter_date
                         From per_periods_of_service
                         Where  person_id = p_person_id;
                    Exception
                    When Others Then
                         l_act_ter_date:= to_date('31-Dec-4712');
                    End;
                    If(l_act_ter_date between l_first_fin_date And l_end_fin_date)Then
                          Begin
                               SELECT  LEVEL INTO P_MON_LEVEL
                               FROM DUAL WHERE TO_CHAR(add_months(to_date('01-MAR-2000'),level),'MON') = TO_CHAR(l_act_ter_date,'MON') connect by level <= 12;
                          Exception
                          When Others Then
                            P_MON_LEVEL:=0;
                          End;
                          period_left:= P_MON_LEVEL - index_num;
                     Else
                     period_left                := 12-index_num;
                     End If;
                     ----------------------------updated on 01-nov-2011------
                    -- l_element_run_result_value_1 :=get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP');
                    -- fnd_file.PUT_LINE(fnd_file.LOG,'Value from run result for this element   :  '|| l_element_run_result_value ||'For the month of ' || l_pay_gen_date);
                    
                     ---------------------------------
                    l_standard_value           := get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Value',l_pay_gen_date,'IP'); --get_screen_entry_value(l_assignment_id,p_element_name,l_pay_gen_date);
                    l_element_till_date_value  := l_element_run_result_value;
                    l_project_value            := l_standard_value * period_left;
                    l_total_projected_value    := l_element_till_date_value +  l_project_value;
                    /*For Thailand Standard Value will be taken*/
                          if (p_element_name ='Thailand Allowance') then
                           fnd_file.PUT_LINE(fnd_file.LOG,'******************** Thai *************'||period_left);
                            --l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Value',l_pay_gen_date,'IP');
                            l_total_projected_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP');
                            --l_project_value           :=  l_standard_taxable_value * period_left;
                            --l_total_projected_value   :=  l_standard_taxable_value_1+l_project_value  ;--12*l_standard_taxable_value ;--value_till_date + l_project_value;
                         end if;
                    fnd_file.PUT_LINE(fnd_file.LOG,'Standard value of the element :      '||l_standard_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'value till date = total run result value from 1st financial year  :  '||l_element_till_date_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'Projected value = standard value * period left :                     '||l_project_value||' period_left '||period_left);
                    fnd_file.PUT_LINE(fnd_file.LOG,'total projected value  :                                             '||l_total_projected_value);
          END IF;
        END IF;
        IF  p_classification_name='Allowances'  THEN
        fnd_file.PUT_LINE(fnd_file.LOG,'If the element is allowance ');
            IF p_element_name='Site Allowance'
              OR p_element_name='Phone Subsidy' THEN
            fnd_file.PUT_LINE(fnd_file.LOG,'*********************** '||p_element_name);
                   FOR i IN 1..index_num
                    LOOP
                        l_assignment_action_id      := getAssignmentActionId(l_assignment_id,p_person_id,l_first_fin_date);
                        l_element_run_result_value  := l_element_run_result_value   + get_run_result_value(p_hra_from_to_date
                                                                                    ,l_assignment_action_id
                                                                                    ,p_element_name
                                                                                    ,'Pay Value'
                                                                                    ,l_first_fin_date
                                                                                    ,'IP'
                                                                                    );
                        fnd_file.PUT_LINE(fnd_file.LOG,'Value from run result for this element   :  '|| l_element_run_result_value ||'For the month of ' || l_first_fin_date);
                        l_first_fin_date:=add_months(l_first_fin_date,1);
                    END LOOP;
                     l_first_fin_date  :=fnd_conc_date.string_to_date('01' || 'APR'             || from_date);
                    Begin
                         Select actual_termination_date
                         Into   l_act_ter_date
                         From per_periods_of_service
                         Where  person_id = p_person_id;
                    Exception
                    When Others Then
                         l_act_ter_date:= to_date('31-Dec-4712');
                    End;
                    If(l_act_ter_date between l_first_fin_date And l_end_fin_date)Then
                          Begin
                               SELECT  LEVEL INTO P_MON_LEVEL
                               FROM DUAL WHERE TO_CHAR(add_months(to_date('01-MAR-2000'),level),'MON') = TO_CHAR(l_act_ter_date,'MON') connect by level <= 12;
                          Exception
                          When Others Then
                            P_MON_LEVEL:=0;
                          End;
                          period_left:= P_MON_LEVEL - index_num;
                     Else
                    period_left                := 12-index_num;
                    End If;
                     fnd_file.PUT_LINE(fnd_file.LOG,'******************** Period Left cal *************'||period_left);
                   -- l_standard_value           := get_screen_entry_value(l_assignment_id,p_element_name,l_pay_gen_date);
                       l_standard_value                        := get_run_result_value(p_hra_from_to_date
                                                                                    ,l_assignment_action_id
                                                                                    ,p_element_name
                                                                                    ,'Pay Value'
                                                                                    ,l_pay_gen_date
                                                                                    ,'IP'
                                                                                    );
                    l_element_till_date_value  := l_element_run_result_value;
                    l_project_value            := l_standard_value * period_left;
                    l_total_projected_value    := l_element_till_date_value +  l_project_value;

                    fnd_file.PUT_LINE(fnd_file.LOG,'Standard value of the element :      '||l_standard_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'value till date = total run result value from 1st financial year  :  '||l_element_till_date_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'Projected value = standard value * period left :                     '||l_project_value);
                    fnd_file.PUT_LINE(fnd_file.LOG,'total projected value  :                                             '||l_total_projected_value);
           -- END IF;
         ELSE
          -------------------------------/*Code Changes 21-Aug-2011*/
--           IF p_element_name='Conveyance Allowance'   THEN
--            fnd_file.PUT_LINE(fnd_file.LOG,'If the element is Conveyance Allowance ');
--
--       /*     ------------Modified on 5/DEC/2010------------
--              /*  value_till_date:= apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
--                                                                           ,83  ----Remove this hard coding
--                                                                           ,'Allowance Amount'
--                                                                           ,'_ASG_COMP_YTD'
--                                                                           ,'SOURCE_TEXT2'
--                                                                           ,'House Rent Allowance'
--                                                                            );              */
--
--               l_total_projected_value:=get_run_result_value(p_hra_from_to_date,l_assignment_action_id,'Conveyance Allowance','Allowance Amount',l_pay_gen_date,'IP');
--               fnd_file.PUT_LINE(fnd_file.LOG,'Conveyance Allowance  :'|| l_total_projected_value);
--
--            END IF;
          -------------------------------/*Code Changes 21-Aug-2011*/--------------
             IF p_element_name='House Rent Allowance'   THEN
            fnd_file.PUT_LINE(fnd_file.LOG,'If the element is House Rent Allowance ');
            ------------Modified on 5/DEC/2010------------
              /*  value_till_date:= apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                           ,83  ----Remove this hard coding
                                                                           ,'Allowance Amount'
                                                                           ,'_ASG_COMP_YTD'
                                                                           ,'SOURCE_TEXT2'
                                                                           ,'House Rent Allowance'
                                                                            );              */
               l_total_projected_value:=get_run_result_value(p_hra_from_to_date,l_assignment_action_id,'Taxable HRA','Annual Value',l_pay_gen_date,'IP');
               fnd_file.PUT_LINE(fnd_file.LOG,'Annual value of Taxable HRA  :'|| l_total_projected_value);
            ELSE
               value_till_date:= apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                                         ,83
                                                                                         ,'Taxable Allowances'
                                                                                         ,'_ASG_COMP_YTD'
                                                                                         ,'SOURCE_TEXT2'
                                                                                         ,p_context_value
                                                                                          ) ;
              fnd_file.PUT_LINE(fnd_file.LOG,'Value till date from balance : line 441'|| value_till_date);
               IF p_element_name LIKE ('%Reimbursement') THEN
                  l_total_projected_value:= value_till_date;
                  fnd_file.PUT_LINE(fnd_file.LOG,'Value till date from balance is the total projection value in case of  Reimbursement :'|| l_total_projected_value);
               ELSE
                  --l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Taxable Value',l_pay_gen_date,'IP');
                  --l_project_value           :=  l_standard_taxable_value * period_left;
                 -- l_total_projected_value   :=  value_till_date + l_project_value;
                    Begin
                             Select actual_termination_date
                             Into   l_act_ter_date
                             From per_periods_of_service
                             Where  person_id = p_person_id;
                          Exception
                          When Others Then
                               l_act_ter_date:= to_date('31-Dec-4712');
                          End;
                           If(l_act_ter_date between l_first_fin_date And l_end_fin_date)Then
                          Begin
                               SELECT  LEVEL INTO P_MON_LEVEL
                               FROM DUAL WHERE TO_CHAR(add_months(to_date('01-MAR-2000'),level),'MON') = TO_CHAR(l_act_ter_date,'MON') connect by level <= 12;
                          Exception
                          When Others Then
                            P_MON_LEVEL:=0;
                          End;
                              period_left:= P_MON_LEVEL - index_num;
                         Else
                              period_left                := 12-index_num;
                          End If;
                   fnd_file.PUT_LINE(fnd_file.LOG,'******************** Period Left **** Line 475  '||period_left||'value_till_date  '||value_till_date);
                           -------------------------------/*Code Changes 21-sep-2011*/--------------------
                          l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Taxable Value',l_pay_gen_date,'IP');
                          l_project_value           :=  l_standard_taxable_value * period_left;
                          l_total_projected_value   :=  value_till_date + l_project_value;
                          -------------------------------/*Code Changes 23-Aug-2011*/--------------------
                         /*For conveyance Standard Value will be taken*/

                         if (p_element_name ='Conveyance Allowance') then
                            value_till_date := apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                                         ,83
                                                                                         ,'Allowance Amount'
                                                                                         ,'_ASG_COMP_YTD'
                                                                                         ,'SOURCE_TEXT2'
                                                                                         ,p_context_value
                                                                                          ) ;
                            l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Value',l_pay_gen_date,'IP');
                           l_standard_taxable_value_1  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP');
                            l_project_value           :=  l_standard_taxable_value * period_left;
                            l_total_projected_value   :=  value_till_date+l_project_value  ;--12*l_standard_taxable_value ;--value_till_date + l_project_value;
                              fnd_file.PUT_LINE(fnd_file.LOG,'Value till date from balance :'|| value_till_date);
                         end if;
                         /*For Education Standard Value will be taken*/
                          if (p_element_name ='Education Allowance') then
                           fnd_file.PUT_LINE(fnd_file.LOG,'******************** Period Left *************'||period_left||'value_till_date  '||value_till_date);
                             value_till_date := apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                                         ,83
                                                                                         ,'Allowance Amount'
                                                                                         ,'_ASG_COMP_YTD'
                                                                                         ,'SOURCE_TEXT2'
                                                                                         ,p_context_value
                                                                                          ) ;
                            l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Value',l_pay_gen_date,'IP');
                            l_standard_taxable_value_1  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP');
                            l_project_value           :=  l_standard_taxable_value * period_left;
                            l_total_projected_value   :=  value_till_date+l_project_value  ;--12*l_standard_taxable_value ;--value_till_date + l_project_value;
                             fnd_file.PUT_LINE(fnd_file.LOG,'Value till date from balance :'|| value_till_date);
                         end if;
                          /*For Hardship Offshore Allowance Standard Value will be taken*/
                          if (p_element_name ='Hardship Offshore Allowance') then
                           fnd_file.PUT_LINE(fnd_file.LOG,'******************** Period Left *************'||period_left||'value_till_date  '||value_till_date);
                             value_till_date := apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                                         ,83
                                                                                         ,'Allowance Amount'
                                                                                         ,'_ASG_COMP_YTD'
                                                                                         ,'SOURCE_TEXT2'
                                                                                         ,p_context_value
                                                                                          ) ;
                            l_standard_taxable_value  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Standard Value',l_pay_gen_date,'IP');
                            l_standard_taxable_value_1  :=  get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP');
                            l_project_value           :=  l_standard_taxable_value * period_left;
                            l_total_projected_value   :=  value_till_date+l_project_value  ;--12*l_standard_taxable_value ;--value_till_date + l_project_value;
                             fnd_file.PUT_LINE(fnd_file.LOG,'Value till date from balance :'|| value_till_date);
                         end if;

                           -------------------------------/*Code Changes 21-Aug-2011*/
                  fnd_file.PUT_LINE(fnd_file.LOG,'*********************');
                   fnd_file.PUT_LINE(fnd_file.LOG,'Elemnt Name : '|| p_element_name);
                  fnd_file.PUT_LINE(fnd_file.LOG,'Standard Taxable value : '|| l_standard_taxable_value);
                  fnd_file.PUT_LINE(fnd_file.LOG,'Projected value :        '|| l_project_value);
                  fnd_file.PUT_LINE(fnd_file.LOG,' Total Projected value : '|| l_total_projected_value);
                  fnd_file.PUT_LINE(fnd_file.LOG,'*********************');

               END IF;
            END IF;
             END IF;
        END IF;
        IF  p_processing_type='N' THEN
        fnd_file.PUT_LINE(fnd_file.LOG,'This element is non recurring element');
                IF  p_classification_name='Allowances'  THEN
                fnd_file.PUT_LINE(fnd_file.LOG,'This element is non recurring element and allowance');

                       /*    l_total_projected_value:=apps.XXARJ_in_payroll_utility_pkg.XXARJ_IN_balance_value(l_assignment_action_id
                                                                                                              ,83
                                                                                                              ,'Taxable Allowances'
                                                                                                              ,'_ASG_COMP_YTD'
                                                                                                              ,'SOURCE_TEXT2'
                                                                                                              ,p_context_value
                                                                                                              ) ;  */
 ------------------------------------------------                                                                                                            
                    FOR i IN 1..index_num
                    LOOP
                        l_assignment_action_id      := getAssignmentActionId(l_assignment_id,p_person_id,l_first_fin_date);
                        l_element_run_result_value  := l_element_run_result_value   + get_run_result_value(p_hra_from_to_date
                                                                                    ,l_assignment_action_id
                                                                                    ,p_element_name
                                                                                    ,'Pay Value'
                                                                                    ,l_first_fin_date
                                                                                    ,'IP'
                                                                                    );
                        fnd_file.PUT_LINE(fnd_file.LOG,'Value from run result for this element   :  '|| l_element_run_result_value ||'For the month of ' || l_first_fin_date);
                        l_first_fin_date:=add_months(l_first_fin_date,1);
                    END LOOP;
                   
-------------------------------------------------------
                             l_total_projected_value:= l_element_run_result_value;  --get_run_result_value(p_hra_from_to_date,l_assignment_action_id,p_element_name,'Pay Value',l_pay_gen_date,'IP'); --value_till_date; updated on 2nd nov
                          fnd_file.PUT_LINE(fnd_file.LOG,' Total Projected value is the balance value : '|| l_total_projected_value);

                 ELSIF   p_classification_name='Earnings'  THEN
                  fnd_file.PUT_LINE(fnd_file.LOG,'This element is non recurring element and earning');
                        l_total_projected_value:=l_element_till_date_value;
                        fnd_file.PUT_LINE(fnd_file.LOG,' Total Projected value is the value till date : '|| l_total_projected_value);
                END IF;
                p_non_rec                 :=l_total_projected_value;
    END IF;
    p_period_left:=period_left;
    dbms_output.put_line(l_total_projected_value);
RETURN  l_total_projected_value ;
EXCEPTION
   WHEN OTHERS THEN
        fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function get_projection_value:     '||SQLCODE||'   '||SQLERRM);
END;
---------------------------------------------------------------------------------------------------------------------------
--- Function: getAssignmentActionId
--- Purpose : This function fetches assignment action id and assignment id(out parameter) against a employee number,date
---------------------------------------------------------------------------------------------------------------------------
FUNCTION getAssignmentActionId(p_assignment_id           OUT   NUMBER
                              ,p_person_id               IN    NUMBER
                              ,p_effective_date          IN    DATE
                               )RETURN NUMBER
AS
assignment_action_id     NUMBER:=0;
BEGIN
    SELECT   MAX(paa.assignment_action_id)
             ,paa.assignment_id
    INTO      assignment_action_id,p_assignment_id
    FROM      pay_assignment_actions         paa
             ,pay_payroll_actions            ppa
             ,per_time_periods               ptp
             ,per_all_assignments_f          paaf
             ,pay_run_types_f                prtf
    WHERE     PPA.action_type                in ('R','Q','I','B')
    AND       PPA.action_status              = 'C'
    AND       paa.payroll_action_id          = ppa.payroll_action_id
    AND       PAA.action_status              = 'C'
    AND       ppa.payroll_id                 = ptp.payroll_id
    AND       ptp.time_period_id             = ppa.time_period_id
    AND       paa.assignment_id              = paaf.assignment_id
    AND       paaf.person_id                 = p_person_id
    and       prtf.run_type_id               = paa.run_type_id
    and       prtf.run_type_name   not like '%Process Separate%'      ---- updated for separate run
    AND       paaf.business_group_id         =fnd_profile.value('PER_BUSINESS_GROUP_ID')
    AND       p_effective_date               BETWEEN prtf.effective_start_date AND prtf.effective_end_date
    AND       ppa.effective_date             BETWEEN p_effective_date          AND last_day(p_effective_date)
    AND       (p_effective_date              BETWEEN paaf.effective_start_date AND paaf.effective_end_date
               OR  paaf.effective_start_date BETWEEN p_effective_date          AND last_day(p_effective_date))
    GROUP BY  paa.assignment_id;
    RETURN  assignment_action_id;
EXCEPTION
    WHEN NO_DATA_FOUND THEN
         RETURN assignment_action_id;
    WHEN OTHERS THEN
         fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function getAssignmentActionId: '||SQLCODE||'   '||SQLERRM);
END getAssignmentActionId;
FUNCTION get_run_comments_value  (
                       p_assignment_action_id   IN  NUMBER
                       ,p_input_value_name       IN  VARCHAR2
                       ,p_date                   IN  DATE
                       )RETURN VARCHAR2
AS
l_value        VARCHAR2(1000);--NUMBER := '0';
l_value_number NUMBER:=0;
BEGIN
      SELECT    (prrv.result_value)  --fnd_number.canonical_to_number(prrv.result_value)     result_value
      INTO      l_value
      FROM      pay_run_result_values       prrv
               ,pay_run_results             prr
               ,pay_element_types_f         petf
               ,pay_input_values_f          pivf
      WHERE     prrv.run_result_id           = prr.run_result_id
      AND       prr.element_type_id          = petf.element_type_id
      AND       pivf.input_value_id          = prrv.input_value_id
      AND       prr.assignment_action_id     = p_assignment_action_id
       AND       pivf.name = p_input_value_name
      AND       petf.element_name                   = 'PLG Payroll Exception'
      AND       (petf.legislation_code              = 'IN' OR petf.business_group_id = 81)---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       (pivf.legislation_code              = 'IN' OR pivf.business_group_id = 81)---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       petf.element_type_id                = pivf.element_type_id
      AND       p_date BETWEEN petf.effective_start_date AND petf.effective_end_date
      AND       p_date BETWEEN pivf.effective_start_date AND pivf.effective_end_date;
  RETURN l_value;
EXCEPTION
    WHEN OTHERS THEN
          l_value := ' ';
           RETURN l_value;
END get_run_comments_value;
----------------------------------------------------------------------------------------------------
---Function :get_run_result_value
---Purpose  :This function fetches value
---Parameter: IN Parameter->Assignment action id
---                         Element Name
---                         Input value name
---                         Type
---                         date
---           OUT Parameter->Date (when fetches a date from run result instead of number )
----------------------------------------------------------------------------------------------------
FUNCTION get_run_result_value  (p_hra_from_to_date       OUT DATE
                               ,p_assignment_action_id   IN  NUMBER
                               ,p_element_name           IN  VARCHAR2
                               ,p_input_value_name       IN  VARCHAR2
                               ,p_date                   IN  DATE
                               ,p_type                   IN  VARCHAR2
                               )RETURN NUMBER
AS
l_value        VARCHAR2(1000);--NUMBER := '0';
l_value_number NUMBER:=0;
BEGIN
      SELECT    sum(prrv.result_value)  --fnd_number.canonical_to_number(prrv.result_value)     result_value
      INTO      l_value
      FROM      pay_run_result_values       prrv
               ,pay_run_results             prr
               ,pay_element_types_f         petf
               ,pay_input_values_f          pivf
      WHERE     prrv.run_result_id           = prr.run_result_id
      AND       prr.element_type_id          = petf.element_type_id
      AND       pivf.input_value_id          = prrv.input_value_id
      AND       prr.assignment_action_id     = p_assignment_action_id
      AND       ( (pivf.name  = p_input_value_name                  AND p_type='IP' )
                OR (pivf.name IN('Taxable Value' ,'Taxable Amount') AND p_type='TA_TV' )
                )
      AND       petf.element_name                   = p_element_name
      AND       (petf.legislation_code              = 'IN' OR petf.business_group_id = fnd_profile.value('PER_BUSINESS_GROUP_ID'))---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       (pivf.legislation_code              = 'IN' OR pivf.business_group_id = fnd_profile.value('PER_BUSINESS_GROUP_ID'))---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       petf.element_type_id                = pivf.element_type_id
      AND       p_date BETWEEN petf.effective_start_date AND petf.effective_end_date
      AND       p_date BETWEEN pivf.effective_start_date AND pivf.effective_end_date;
      BEGIN
          l_value_number:=TO_NUMBER(NVL(l_value,0));
          RETURN l_value_number;
      EXCEPTION
      WHEN OTHERS THEN
           p_hra_from_to_date:=FND_CONC_DATE.STRING_TO_DATE(l_value);
           RETURN 0;
      END;
EXCEPTION
    WHEN OTHERS THEN
         fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function get_run_result_value: '||SQLCODE||'   '||SQLERRM);
         RETURN 0;
END get_run_result_value;
---------------------------------------------------------------------------
--- FUNCTION get_screen_entry_value
----Purpose :To fetch screen enrty value of an input value of a element
----------------------------------------------------------------------------
FUNCTION get_screen_entry_value(p_assignment_id NUMBER,
                              p_element_name  VARCHAR2,
                              p_date          DATE
                              )RETURN NUMBER
AS
l_basic_rate      NUMBER := 0;
BEGIN
      SELECT NVL(SUM(fnd_number.canonical_to_number(peevf.screen_entry_value)),0)
      INTO   l_basic_rate
      FROM   pay_element_types_f              petf,
           pay_element_entries_f            peef,
           pay_element_entry_values_f       peevf,
           pay_input_values_f               pivf
      WHERE  peef.element_entry_id            =  peevf.element_entry_id
      AND  peef.assignment_id                =  p_assignment_id
      AND  petf.element_name                 =  p_element_name
      AND  (petf.legislation_code            =  'IN' OR petf.business_group_id =  fnd_profile.value('PER_BUSINESS_GROUP_ID'))---fnd_profile.value('PER_BUSINESS_GROUP_ID')) --83)-- fnd_profile.value('PER_BUSINESS_GROUP_ID'))
      AND  PIVF.NAME                         IN ('Standard Value','Allowance Amount')
      AND  (pivf.legislation_code            =  'IN' OR pivf.business_group_id =  fnd_profile.value('PER_BUSINESS_GROUP_ID'))---fnd_profile.value('PER_BUSINESS_GROUP_ID')) --83)-- fnd_profile.value('PER_BUSINESS_GROUP_ID'))
      AND  petf.element_type_id              =  pivf.element_type_id
      AND  peevf.input_value_id              =  pivf.input_value_id
      AND  p_date BETWEEN petf.effective_start_date     AND petf.effective_end_date
      --AND  p_date BETWEEN peef.effective_start_date     AND peef.effective_end_date
      --AND  p_date BETWEEN peevf.effective_start_date    AND peevf.effective_end_date
      AND  (p_date BETWEEN peef.effective_start_date     AND peef.effective_end_date
      OR    peef.effective_start_date BETWEEN  p_date and last_day( p_date))
      AND  (p_date BETWEEN peevf.effective_start_date    AND peevf.effective_end_date
      OR  peevf.effective_start_date BETWEEN  p_date and last_day( p_date))
     -- AND  peef.effective_start_date BETWEEN p_date and last_day(p_date)
     -- AND  peevf.effective_start_date BETWEEN p_date and last_day(p_date)
      AND  p_date BETWEEN pivf.effective_start_date     AND pivf.effective_end_date;
      RETURN l_basic_rate;
EXCEPTION
     WHEN no_data_found THEN
          RETURN l_basic_rate;
     WHEN OTHERS THEN
          RETURN l_basic_rate;
          fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Function get_screen_entry_value: '||SQLCODE||'   '||SQLERRM);
END get_screen_entry_value;
-------------------------------------------------------------------------------
--- PROCEDURE XXARJ_PAYSLIP_GENERATION_PRC
----This is the main procedure which will be called from concurrent program
----Parameter:IN Parameter->1)employee number
----                        2)month
----                        3)Year
--------------------------------------------------------------------------------
PROCEDURE XXARJ_PAYSLIP_GENERATION_PRC(p_errbuf        OUT VARCHAR2
                                      ,p_retcode       OUT NUMBER
                                     , p_person_id     IN NUMBER
                                      ,p_month         IN  VARCHAR2
                                      ,p_year          IN  NUMBER
                                 )
IS
--Cursor  Declaration
----------------------------------------------------
---CURSOR get_personal_details
---Purpose :This cursor fetches employee details
---Parameter->Assignment id and date
----------------------------------------------------
CURSOR get_personal_details  (c_asg_id NUMBER
                             ,c_date   DATE
                             ) IS
SELECT papf.employee_number         Emp_no
      ,initcap(papf.full_name)      Emp_name
      ,pj.name                      Designation
      ,pg.name                      Grade_name
      ,hrl.location_code            Location_name
      ,papf.original_date_of_hire  Original_date_of_hire
      ,pea.segment1                Acc_no
      ,HR_GENERAL.DECODE_LOOKUP('IN_BANK',pea.SEGMENT3)||' '||HR_GENERAL.DECODE_LOOKUP('IN_BANK_BRANCH',pea.SEGMENT4)  Bank
     -- ,pea.segment3|| pea.segment4 Bank
      ,papf.per_information4       Pan_no
      ,papf.per_information8       Pf_no
      ,papf.per_information9       Esi_no
      ,haou.name                   Department
      ,popmf.org_payment_method_name  Pay_mode
     -- ,ppt.payment_type_name       Pay_mode

FROM  per_all_people_f              papf
    ,per_all_assignments_f          paaf
    ,per_jobs                       pj
    ,per_grades                     pg
    ,hr_locations                   hrl
    ,pay_personal_payment_methods_f pppmf
    ,pay_external_accounts          pea
    ,per_periods_of_service         ppos
    ,hr_all_organization_units      haou
    ,pay_payment_types              ppt
    ,pay_org_payment_methods_f      popmf

WHERE papf.person_id               = paaf.person_id
AND   paaf.job_id                  = pj.job_id(+)
AND   paaf.grade_id                = pg.grade_id(+)
AND   paaf.location_id             = hrl.location_id(+)
AND   paaf.assignment_id           = pppmf.assignment_id(+)
AND   pea.external_account_id (+)  = pppmf.external_account_id
AND   pppmf.ORG_PAYMENT_METHOD_ID  = popmf.ORG_PAYMENT_METHOD_ID(+)
AND   ppos.period_of_service_id    = paaf.period_of_service_id
AND   haou.organization_id         = paaf.organization_id
AND   popmf.payment_type_iD        = ppt.payment_type_id (+)
AND   paaf.assignment_id           = c_asg_id
--AND   c_date BETWEEN  NVL(PPPMF.EFFECTIVE_START_DATE, to_date('01-Jan-1900','DD-Mon-YYYY'))   AND NVL(PPPMF.EFFECTIVE_END_DATE, to_date('31-Dec-4712','DD-Mon-YYYY'))
AND    ( c_date BETWEEN papf.effective_start_date           AND papf.effective_end_date
            AND  c_date   BETWEEN PAAF.effective_start_date AND paaf.effective_end_date
        or    (
              ppos.actual_termination_date         BETWEEN  c_date                 AND last_day( c_date)
              AND     ppos.actual_termination_date BETWEEN papf.effective_start_date AND papf.effective_end_date
              AND     ppos.actual_termination_date BETWEEN PAAF.effective_start_date AND PAAF.effective_end_date
              )
        or    (
              papf.original_date_of_hire         BETWEEN  c_date         AND last_day( c_date)
              AND     papf.original_date_of_hire BETWEEN papf.effective_start_date AND papf.effective_end_date
              AND     papf.original_date_of_hire BETWEEN paaf.effective_start_date AND paaf.effective_end_date
              )
            ) ;
--------------------------------------------------------------------------------------------------------------------------
---CURSOR get_earn_deduct_elements
---This cursor fetches all the earnign and allowance elements from run result processed in a particular month when type is EA
---and deduction elements when type is D .The flag denotes whether the element is retro element or not.
----------------------------------------------------------------------------------------------------------------------------
CURSOR get_earn_deduct_elements (p_assign_action_id  IN NUMBER
                                ,p_date              IN DATE
                                ,p_type              IN VARCHAR2
                           )IS
SELECT  DISTINCT petf.element_type_id                                     element_type_id
               , petf.element_name                                        element_name
                ,decode(nvl(prcuv.creator_id ,0),0,'T','F')               Retro_flag
FROM     pay_run_results                 prr
      ,  pay_element_types_f             petf
      ,  pay_input_values_f              pivf
      ,  pay_element_classifications     pec
      ,  pay_retro_component_usages_v    prcuv
      ,  pay_element_span_usages         pesu
WHERE    prr.element_type_id                = petf.element_type_id
 AND     prr.assignment_action_id           = p_assign_action_id
 AND     pivf.name                          = 'Pay Value'
 AND     (petf.legislation_code = 'IN'      OR petf.business_group_id = fnd_profile.value('PER_BUSINESS_GROUP_ID'))---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
 AND     (pivf.legislation_code = 'IN'      OR pivf.business_group_id = fnd_profile.value('PER_BUSINESS_GROUP_ID'))---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
 AND     petf.element_type_id               = pivf.element_type_id
 AND     pec.classification_id              = petf.classification_id
 AND     prcuv.creator_id (+)               =petf.element_type_id
 AND     pesu.retro_component_usage_id(+)   =prcuv.retro_component_usage_id
 AND     pec.legislation_code               ='IN'
 AND   (
           ( pec.classification_name            IN ('Voluntary Deductions' ,'Involuntary Deductions','Tax Deductions','Employee Charges','Perquisites') and p_type ='D')
        OR
           ( pec.classification_name        IN('Earnings','Allowances') and p_type ='EA')
      )
AND     p_date BETWEEN petf.effective_start_date AND petf.effective_end_date
AND     p_date BETWEEN pivf.effective_start_date AND pivf.effective_end_date
AND     petf.element_name not like 'Retro%'
ORDER BY petf.element_name;
-------------------------------------------------------------------------
--- CURSOR retroElement
---Purpose:This cursor fetches the corresponding retro element if exits
-------------------------------------------------------------------------
CURSOR retroElement(p_element_type_id NUMBER
                    ) IS
SELECT petf.element_name,
       petf.element_type_id
FROM  pay_retro_component_usages_v    prcuv
     ,pay_element_span_usages         pesu
     ,pay_element_types_f             petf
WHERE   prcuv.creator_id               = p_element_type_id
AND     prcuv.retro_component_usage_id = pesu.retro_component_usage_id
AND     petf.element_type_id           = pesu.retro_element_type_id;
-------------------------------------------------------------------------
--- CURSOR retroBaseElement
---It fetches the base or creator element of a retro element
-------------------------------------------------------------------------
CURSOR retroBaseElement(p_element_type_id NUMBER
                       ) IS
SELECT  petf.element_name,
        petf.element_type_id
FROM    pay_retro_component_usages_v prcuv
      , pay_element_span_usages      pesu
      , pay_element_types_f          petf
 WHERE  prcuv.retro_component_usage_id = pesu.retro_component_usage_id
 AND    petf.element_type_id            = prcuv.creator_id
 AND    pesu.retro_element_type_id      =p_element_type_id;
------------------------------------------------------------------------------------------------------------
--- CURSOR projection
--- This picks all the elements which are processed from 1st month(01-Apr) of financial year to till date.
------------------------------------------------------------------------------------------------------------
CURSOR projection (c_asg_id     NUMBER
                  ,c_first_date DATE
                  ,c_date       DATE
                  )IS
  SELECT   distinct petf.element_name                  element_name
            , petf.processing_type                     processing_type
            , pec.classification_name                  classification_type
          --  , ppa.effective_date
        --    ,PETEI.EEI_INFORMATION1                     rem_flag
            ,PETF.element_information1                  context_value

FROM         pay_run_results              prr
          ,pay_element_types_f          petf
          ,pay_assignment_actions       paa
          ,pay_element_classifications  pec
          ,pay_payroll_actions          ppa
          ,PAY_ELEMENT_TYPE_EXTRA_INFO  PETEI
WHERE      prr.element_type_id          = petf.element_type_id
AND        paa.assignment_action_id     = prr.assignment_action_id
AND        pec.classification_id        = petf.classification_id
AND        paa.payroll_action_id        = ppa.payroll_action_id
AND        PETEI.ELEMENT_TYPE_ID(+)     =PETF.ELEMENT_TYPE_ID
AND        PPA.action_type              IN ('R','Q','I','B')
AND        ppa.action_status            = 'C'
AND        paa.action_status            = 'C'
AND        paa.assignment_id            =  c_asg_id
AND       (petf.legislation_code        = 'IN' OR petf.business_group_id =  fnd_profile.value('PER_BUSINESS_GROUP_ID'))---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))--83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
AND        petf.element_name            NOT LIKE 'Retro%'
AND        pec.classification_name      IN  ('Earnings','Allowances')
AND        ppa.effective_date        BETWEEN c_first_date AND  last_day(c_date)
ORDER BY petf.element_name;
--   AND        c_first_date              BETWEEN petf.effective_start_date AND   petf.effective_end_date
--   AND        last_day(c_date)          BETWEEN petf.effective_start_date AND   petf.effective_end_date

/*        SELECT   distinct petf.element_name         element_name
                , petf.processing_type      processing_type
                , pec.classification_name   classification_type
                , ppa.effective_date

  FROM         pay_run_results              prr
              ,pay_element_types_f          petf
              ,pay_assignment_actions       paa
              ,pay_element_classifications  pec
              ,pay_payroll_actions          ppa
    WHERE      prr.element_type_id          = petf.element_type_id
    AND        paa.assignment_action_id     = prr.assignment_action_id
    AND        pec.classification_id        = petf.classification_id
    AND        paa.payroll_action_id        = ppa.payroll_action_id
    AND        PPA.action_type              IN ('R','Q','I','B')
    AND        ppa.action_status            = 'C'
    AND        paa.action_status            = 'C'
    AND        paa.assignment_id            =  c_asg_id
    AND       (petf.legislation_code        = 'IN' OR petf.business_group_id =83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
    AND        petf.element_name            NOT LIKE 'Retro%'
    AND        pec.classification_name      IN  ('Earnings','Allowances')
    AND        ppa.effective_date        BETWEEN c_first_date AND  last_day(c_date);
--   AND        c_first_date              BETWEEN petf.effective_start_date AND   petf.effective_end_date
--   AND        last_day(c_date)          BETWEEN petf.effective_start_date AND   petf.effective_end_date */
------------------------------------------------------------------------------------------------------------
---CURSOR get_house_rent_info
---This cursor fetches the details of 'House Rent Information' if it is attached to an employee
------------------------------------------------------------------------------------------------------------
CURSOR get_house_rent_info(c_asg_id NUMBER
                          )IS
SELECT SUM(prrv.result_value),COUNT(*)
FROM      pay_element_types_f    petf,
          pay_assignment_actions paa,
          pay_run_results        prr,
          pay_run_result_values  prrv
WHERE     paa.assignment_id        = c_asg_id
AND       paa.assignment_action_id = prr.assignment_action_id
AND       prr.element_type_id      = petf.element_type_id
AND       prr.run_result_id        = prrv.run_result_id
AND       petf.element_name        = 'House Rent Information';           /***we will do it by out parameter ***/
-------
-------
--Variables Declaration
l_date                      DATE:= NULL;
l_hra_from_to_date          DATE;
l_date_of_hire              DATE;
l_start_date                DATE;
l_end_date                  DATE;
l_from                      DATE;
to_from                     DATE;
l_emp_no                    VARCHAR2(100);
l_emp_name                  VARCHAR2(100);
l_designation               VARCHAR2(100);
l_grade                     VARCHAR2(100);
l_location                  VARCHAR2(100);
l_acc_no                    VARCHAR2(100);
l_bank                      VARCHAR2(100);
l_pan_no                    VARCHAR2(100);
l_pf_no                     VARCHAR2(100);
l_esi_no                    VARCHAR2(100);
l_paymode                   VARCHAR2(40);
l_department                VARCHAR2(100);
l_furniture_cost            VARCHAR2(100);
l_words                     VARCHAR2(1000);
l_site_days                 NUMBER;
l_payable_days              NUMBER;
l_total_days                NUMBER;
l_retro_value               NUMBER;
l_gross                     NUMBER:=0;
l_deduction                 NUMBER:=0;
l_rent_paid                 NUMBER;
l_row_count                 NUMBER;
l_run_result_value          NUMBER;
l_hra_exempted              NUMBER;
l_comp_rent_paid            NUMBER;
l_comp_from                 NUMBER;
l_comp_to                   NUMBER;
l_taxable_rfa               NUMBER;
l_taxable_hra               NUMBER;
l_net                       NUMBER:=0;
l_assignment_action_id      NUMBER:= 0;
l_assignment_id             NUMBER:= 0;
l_result                    NUMBER;
--  chap_V1_A_total             VARCHAR2(150);
chap_V1_A_total              NUMBER:=0;
l_standard_value            NUMBER;
l_tot_non_rec               NUMBER;
l_total_n_rec               NUMBER:=0;
l_taxable_income            NUMBER;
l_inc_tax_liability         NUMBER;
l_surcharge                 NUMBER;
l_edu_cess                  NUMBER;
l_net_tax                   NUMBER;
l_tax_this_mon              NUMBER;
l_proff_tax                 NUMBER;
l_other_income              NUMBER;
l_other_inc_id              NUMBER;
l_other_inc                 NUMBER;
l_chap_VIA_id               NUMBER;
l_chap_VIA                  NUMBER;
row_count                   NUMBER:=1;
element_name                VARCHAR2(1000);
l_processing_type           VARCHAR2(100);
l_element_type_id           NUMBER;
l_element_type_id1          NUMBER;
element_value               NUMBER;
retro_value                 NUMBER;
ret_date                    DATE;
l_first_date                DATE;
rec_count                   NUMBER:=1;
l_gross_salary              NUMBER;
count1                      NUMBER:=0;
l_Sec_HE_Cess               NUMBER;
l_exempted_amt              NUMBER;
l_business_group_id         NUMBER;
l_tax_id                    NUMBER;
l_pf_def_bal_id             NUMBER;
l_pf_till_date              NUMBER;
l_period_left               NUMBER;
l_pf_val                    NUMBER;
l_exempted_amount           number;
l_tax_till_date             NUMBER;
 L_ASS_AC_ID                NUMBER;
 L_ASS_ID                   NUMBER;
 L_EX_DAYS                  NUMBER;
 L_MSG                      VARCHAR2(5000);
 l_overtime                 NUMBER;
 l_att_r_val                NUMBER;
 l_comm                     VARCHAR2(2000);
 l_prev_emp_sal             NUMBER;
 l_prev_emp_tax             NUMBER;
----
--Array Declarations
----
Type var_type is table of varchar2(1000) index by BINARY_integer;
TYPE earning_ele_name IS RECORD(element_name      VARCHAR2(70)
                               ,run_result_value  NUMBER(16,2)
                               ,processing_type   VARCHAR2(20)
                                );
TYPE array_earning IS TABLE OF earning_ele_name INDEX BY BINARY_INTEGER;
array_earn array_earning ;
TYPE Chapter_V1A is RECORD (element_name varchar2(70),input_name varchar2(70),res_value number);
chap_V1A Chapter_V1A;
type array_chap_V1A is table of Chapter_V1A index by binary_integer;
array_chap_ele array_chap_V1A;
          I NUMBER:=1;
          J NUMBER:=1;
--------------------type for retro----------------------------------------
TYPE ELE_RET_REC IS RECORD  (   element_name     VARCHAR2(70),
                                element_value    NUMBER(16,2),
                                retro_element    VARCHAR2(100),
                                retro_value      NUMBER,
                                total            NUMBER,
                                deduction        varchar2(100),
                                ded_value        number
                            );
TYPE ele_ret_tab IS TABLE OF ELE_RET_REC INDEX BY BINARY_INTEGER;
ele_ret_arr ele_ret_tab ;
--------------------------------------------------------------------------
BEGIN

     fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<?xml version="1.0" ?>');
-----
--1)Formation of date of payslip generation
--2)Formation of first date of financial year
-----
     l_date := FND_CONC_DATE.STRING_TO_DATE('01' ||UPPER(p_month)||p_year);
     l_first_date:= FND_CONC_DATE.STRING_TO_DATE('01' ||'APR'||p_year);
     l_assignment_action_id:=getAssignmentActionId(l_assignment_id, p_person_id,l_date);
-----
--If the assignment action id is found then there is payroll run
--If not then no payroll process for the particular month
-----
      IF l_assignment_action_id IS NULL OR l_assignment_action_id =0 THEN
          fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<Message>');
          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<SHOW_ERR>Y</SHOW_ERR>');
          fnd_file.PUT_LINE(fnd_file.LOG,'1: Assignment Action id'||l_assignment_action_id );
          fnd_file.PUT_LINE(fnd_file.OUTPUT,   '</Message>');
      ELSE
          fnd_file.PUT_LINE(fnd_file.OUTPUT,   '<PAYSLIP_DETAILS>');
          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<SHOW_ERR>N</SHOW_ERR>');
          fnd_file.PUT_LINE(fnd_file.LOG,'2:Assignment Action id'||l_assignment_action_id );
---
--Business group id
---
l_business_group_id:=fnd_profile.value('PER_BUSINESS_GROUP_ID');
---
--Tax unit id
---
begin
select tax_unit_id
into   l_tax_id
from pay_assignment_actions
where assignment_action_id = l_assignment_action_id;
exception when others then
fnd_file.PUT_LINE(fnd_file.LOG,'Tax unit id');
l_tax_id:=0;
end;

-----
--Chapter VI-A Deduction Elements
-----
      fnd_file.PUT_LINE(fnd_file.LOG,'2: Assignment id'||l_assignment_id);

     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80CCD';
     array_chap_ele(1) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80CCE';
     array_chap_ele(2) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80CCF';
     array_chap_ele(3) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80D';
     array_chap_ele(4) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80DD';
     array_chap_ele(5) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80DDB';
     array_chap_ele(6):=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80E';
     array_chap_ele(7):=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80GG';
     array_chap_ele(8) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deduction under Section 80U';
     array_chap_ele(9) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80G UE';
     array_chap_ele(10) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80G LE';
     array_chap_ele(11) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80G FP';
     array_chap_ele(12) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80GGA';
     array_chap_ele(13) :=chap_V1A;
     chap_V1A.element_name:='Form16 Deduction Information';
     chap_V1A.input_name  :='Deductions Sec 80U';
     array_chap_ele(14) :=chap_V1A;
     chap_V1A.element_name:='Previous Employment Information';
     chap_V1A.input_name  :='PF Deduction';
     array_chap_ele(15) :=chap_V1A;
----
--Personal Details and calculation of total days in a month
----
fnd_file.PUT_LINE(fnd_file.LOG,'Before open fetch');
     OPEN  get_personal_details(l_assignment_id,l_date);
     FETCH get_personal_details
     INTO  l_emp_no      ,
           l_emp_name    ,
           l_designation ,
           l_grade       ,
           l_location    ,
           l_date_of_hire,
           l_acc_no      ,
           l_bank        ,
           l_pan_no      ,
           l_pf_no       ,
           l_esi_no      ,
           l_department  ,
           l_paymode     ;
     CLOSE get_personal_details;
     BEGIN
     SELECT    sum(prrv.result_value)  --fnd_number.canonical_to_number(prrv.result_value)     result_value
      INTO      l_att_r_val
      FROM      pay_run_result_values       prrv
               ,pay_run_results             prr
               ,pay_element_types_f         petf
               ,pay_input_values_f          pivf
      WHERE     prrv.run_result_id           = prr.run_result_id
      AND       prr.element_type_id          = petf.element_type_id
      AND       pivf.input_value_id          = prrv.input_value_id
      AND       prr.assignment_action_id     = 42365810
      AND       pivf.name in ('Day_1','Day_2','Day_3','Day_4','Day_5','Day_6','Day_7','Day_8','Day_9','Day_10')
      AND       petf.element_name                   in ('Retro Attendance Details01','Retro Attendance Details02','Retro Attendance Details03')
      AND       (petf.legislation_code              = 'IN' OR petf.business_group_id = 81)---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       (pivf.legislation_code              = 'IN' OR pivf.business_group_id = 81)---FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))  --83)-- FND_PROFILE.value('PER_BUSINESS_GROUP_ID'))
      AND       petf.element_type_id                = pivf.element_type_id
      AND       l_date BETWEEN petf.effective_start_date AND petf.effective_end_date
      AND       l_date BETWEEN pivf.effective_start_date AND pivf.effective_end_date;
     EXCEPTION WHEN OTHERS THEN
     l_att_r_val :=0;
     END;

     l_total_days := (last_day(l_date)-l_date) + 1 ;
   l_payable_days  :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Payable Days','Days',l_date,'IP')+l_att_r_val;
   l_site_days     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Site Allowance','Site Days',l_date,'IP');
   l_overtime     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Overtime','Hours',l_date,'IP');
  fnd_file.PUT_LINE(fnd_file.LOG,'After open fetch');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Personal_details>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Employee_Name><![CDATA['||l_emp_name                   || ']]></Employee_Name>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Emp_No><![CDATA['       ||l_emp_no                    || ']]></Emp_No>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Designation><![CDATA['  ||l_designation                 || ']]></Designation>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Grade><![CDATA['        ||l_grade                       || ']]></Grade>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Location><![CDATA['     ||l_location                    || ']]></Location>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Date_of_hire>'          ||l_date_of_hire                || '</Date_of_hire>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<ACC_no><![CDATA['       ||l_acc_no                      || ']]></ACC_no>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Bank><![CDATA['         ||l_bank                        || ']]></Bank>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Pan>'                   ||l_pan_no                      || '</Pan>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Pf_no>'                 ||l_pf_no                       || '</Pf_no>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Esi_no>'                ||l_esi_no                      || '</Esi_no>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Site_days>'             ||l_site_days                   || '</Site_days>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Total_days>'            ||l_total_days                  || '</Total_days>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Department><![CDATA['   ||l_department                  || ']]></Department>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Paymode><![CDATA['      ||l_paymode                     || ']]></Paymode>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<month>'                 ||trim(to_char(l_date,'Month')) || '</month>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<year>'                  ||trim(to_char(p_year))         || '</year>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Personal_details>');
------------------ Updated on 28th sep--------
fnd_file.PUT_LINE(fnd_file.OUTPUT, '<l_overtime>'           ||l_overtime                      ||  '   </l_overtime>');
IF l_payable_days > l_total_days THEN
L_EX_DAYS := l_payable_days - l_total_days ;
begin
select get_run_comments_value(l_assignment_action_id,'Comments1',l_date)||' '||get_run_comments_value(l_assignment_action_id,'Comments2',l_date)||' '||get_run_comments_value(l_assignment_action_id,'Comments3',l_date)||' '||get_run_comments_value(l_assignment_action_id,'Comments4',l_date)||' '||get_run_comments_value(l_assignment_action_id,'Comments5',l_date)
into l_comm
from dual;
exception when others then
l_comm := ' ';
end;
L_MSG := L_EX_DAYS ||' Days For Previous Month .'||l_comm;
fnd_file.PUT_LINE(fnd_file.OUTPUT, '<L_MSG>'           ||L_MSG                      ||  '   </L_MSG>');
END IF;
---------------------------------------------

----
--Start of loop for Fetching earning elements and corresponding retro elements
----
     FOR I IN get_earn_deduct_elements(l_assignment_action_id,l_date,'EA')
     LOOP
         element_value:=XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(ret_date,l_assignment_action_id,
                                                                        I.element_name,'Pay Value',l_date,'IP');
----
--If the element fetched from run result is not retro
----
         IF I.Retro_flag='F' THEN
             ele_ret_arr(rec_count).element_name :=I.element_name;
             ele_ret_arr(rec_count).element_value:=element_value;

----
--To fetch corresponding retro element of a non retro element
----
             OPEN  retroElement(I.element_type_id);
             FETCH retroElement INTO element_name,l_element_type_id;

----
--If the retro element is fetched then calculation of non retro element value
----
                  IF retroElement%ROWCOUNT>0 THEN
                     retro_value:=XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(ret_date,l_assignment_action_id,
                                                                                         element_name,'Pay Value',l_date,'IP');
                      ele_ret_arr(rec_count).retro_element:=element_name;
                      ele_ret_arr(rec_count).retro_value  :=retro_value;
                  END IF;
             CLOSE retroElement;
                  rec_count:=rec_count+1;
         END IF;
----
--If the element fetched from run result is  retro
----
         IF I.Retro_flag='T' THEN
----
--To fetch corresponding base/creator element of a  retro element
----
            OPEN retroBaseElement(I.element_type_id);
            FETCH retroBaseElement INTO element_name,l_element_type_id;
                  IF retroBaseElement%ROWCOUNT>0 THEN
----
--To check if the base/creator element fetched is processed in the present month by using assignment action id
----
                      BEGIN
                          SELECT element_type_id
                          INTO l_element_type_id1
                          FROM pay_run_results PRR
                          WHERE PRR.element_type_id      = l_element_type_id
                          AND   prr.assignment_action_id = l_assignment_action_id;
                      EXCEPTION
                          WHEN NO_DATA_FOUND THEN
                                ele_ret_arr(rec_count).element_name :=element_name;
                                ele_ret_arr(rec_count).element_value:=0;
                                ele_ret_arr(rec_count).retro_element:=I.element_name;
                                ele_ret_arr(rec_count).retro_value  :=element_value;
                                rec_count:=rec_count+1;
                          WHEN OTHERS THEN
                               NULL;
                               fnd_file.PUT_LINE(fnd_file.LOG,'ERROR : '||SQLCODE||'   '||SQLERRM);
                      END;
----
--If no rows fetched then its neither a retro element or creator/base element
----
                  ELSE
                        ele_ret_arr(rec_count).element_name :=I.element_name;
                        ele_ret_arr(rec_count).element_value:=element_value;
                        ele_ret_arr(rec_count).retro_element:=' ';
                        ele_ret_arr(rec_count).retro_value  :=0;
                        rec_count:=rec_count+1;
                  END IF;
            CLOSE retroBaseElement;
         END IF;
     END LOOP;    --End of loop for Fetching earning elements and corresponding retro elements
     fnd_file.PUT_LINE(fnd_file.LOG,'30');

  --***************************************
     BEGIN
      SELECT   MAX(paa.assignment_action_id)
             ,paa.assignment_id
    INTO      L_ASS_AC_ID,L_ASS_ID
    FROM      pay_assignment_actions         paa
             ,pay_payroll_actions            ppa
             ,per_time_periods               ptp
             ,per_all_assignments_f          paaf
             ,pay_run_types_f                prtf
    WHERE     PPA.action_type                in ('R','Q','I','B')
    AND       PPA.action_status              = 'C'
    AND       paa.payroll_action_id          = ppa.payroll_action_id
    AND       PAA.action_status              = 'C'
    AND       ppa.payroll_id                 = ptp.payroll_id
    AND       ptp.time_period_id             = ppa.time_period_id
    AND       paa.assignment_id              = paaf.assignment_id
    AND       paaf.person_id                 = p_person_id
    and       prtf.run_type_id               = paa.run_type_id
    and       prtf.run_type_name    like '%Process Separate%'      ---- updated for separate run
    AND       paaf.business_group_id         =fnd_profile.value('PER_BUSINESS_GROUP_ID')
    AND       l_date               BETWEEN prtf.effective_start_date AND prtf.effective_end_date
    AND       ppa.effective_date             BETWEEN l_date          AND last_day(l_date)
    AND       (l_date              BETWEEN paaf.effective_start_date AND paaf.effective_end_date
               OR  paaf.effective_start_date BETWEEN l_date          AND last_day(l_date))
    GROUP BY  paa.assignment_id;
     EXCEPTION WHEN OTHERS THEN
     L_ASS_AC_ID := NULL;
     L_ASS_ID    :=NULL;
      fnd_file.PUT_LINE(fnd_file.LOG,'NO SEPARATE RUN ACTION ID');
     END;
    IF L_ASS_AC_ID IS NOT NULL THEN
     FOR I IN get_earn_deduct_elements(L_ASS_AC_ID,l_date,'EA')
     LOOP
         element_value:=XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(ret_date,L_ASS_AC_ID,
                                                                        I.element_name,'Pay Value',l_date,'IP');
          --Others_N := nvl(element_value,0);
          ele_ret_arr(rec_count).element_name :=I.element_name;
          ele_ret_arr(rec_count).element_value:=element_value;
           ele_ret_arr(rec_count).retro_value  :=0;
          -- fnd_file.PUT_LINE(fnd_file.LOG,'INSIDE SEPARETE LOOP '||L_ASS_AC_ID||'element_name  '|| ele_ret_arr(rec_count).element_name||ele_ret_arr(rec_count).element_value);
          rec_count := rec_count +1;
          fnd_file.PUT_LINE(fnd_file.LOG,'INSIDE SEPARETE LOOP '||L_ASS_AC_ID||'element_name  '|| I.element_name||l_date);

    END LOOP;
    END IF;



 -- ******************************************
     ----
--Fetching deduction elements by passing assignment action id,date,type D means deduction
--and sum of all deduction element values
----
    rec_count:=1;
     For rec_get_deduction_elements IN get_earn_deduct_elements(l_assignment_action_id,l_date,'D')
     LOOP

        l_run_result_value     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,rec_get_deduction_elements.element_name,'Pay Value',l_date,'IP');
        l_deduction            :=l_deduction+l_run_result_value;
        ele_ret_arr(rec_count).deduction :=rec_get_deduction_elements.element_name;
        ele_ret_arr(rec_count).ded_value :=nvl(l_run_result_value,0);
        rec_count:=rec_count+1;
    /*    IF l_run_result_value <> 0 THEN
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_details>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_Element_Name><![CDATA['   || ele_ret_arr(rec_count).deduction || ']]></Deduction_Element_Name>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_Element_Value>'           ||ele_ret_arr(rec_count).ded_value                       ||  '   </Deduction_Element_Value>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Deduction_details>');
        END IF; */
     END LOOP;
      For rec_get_deduction_elements IN get_earn_deduct_elements(L_ASS_AC_ID,l_date,'D')
         LOOP
          l_run_result_value     :=get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,rec_get_deduction_elements.element_name,'Pay Value',l_date,'IP');
          l_deduction            :=l_deduction+l_run_result_value;
          ele_ret_arr(rec_count).deduction :=rec_get_deduction_elements.element_name;
          ele_ret_arr(rec_count).ded_value :=nvl(l_run_result_value,0);
          rec_count:=rec_count+1;

          END LOOP;
          FOR I IN 1..ele_ret_arr.COUNT
           LOOP
            IF ele_ret_arr(I).ded_value  <> 0 THEN
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_details>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_Element_Name><![CDATA['   || ele_ret_arr(I).deduction || ']]></Deduction_Element_Name>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_Element_Value>'           ||ele_ret_arr(I).ded_value                       ||  '   </Deduction_Element_Value>');
            fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Deduction_details>');
            END IF;

            END LOOP;
----
--Calculation of gross and rate of earning elements
----
     FOR I IN 1..ele_ret_arr.COUNT
     LOOP
          ele_ret_arr(I).total:=nvl(ele_ret_arr(I).element_value,0) + nvl(ele_ret_arr(I).RETRO_VALUE,0);
          IF ele_ret_arr(I).element_name = 'Thailand Allowance' THEN
            BEGIN
            SELECT NVL(SUM(fnd_number.canonical_to_number(peevf.screen_entry_value)),0)
            INTO   l_standard_value
            FROM   pay_element_types_f              petf,
                 pay_element_entries_f            peef,
                 pay_element_entry_values_f       peevf,
                 pay_input_values_f               pivf
            WHERE  peef.element_entry_id            =  peevf.element_entry_id
            AND  peef.assignment_id                =  L_ASS_ID
            AND  petf.element_name                 =  'Thailand Allowance'
            AND  (petf.legislation_code            =  'IN' OR petf.business_group_id =  fnd_profile.value('PER_BUSINESS_GROUP_ID'))---fnd_profile.value('PER_BUSINESS_GROUP_ID')) --83)-- fnd_profile.value('PER_BUSINESS_GROUP_ID'))
            AND  PIVF.NAME                         IN ('Standard Value','Bonus Amount')
            AND  (pivf.legislation_code            =  'IN' OR pivf.business_group_id =  fnd_profile.value('PER_BUSINESS_GROUP_ID'))---fnd_profile.value('PER_BUSINESS_GROUP_ID')) --83)-- fnd_profile.value('PER_BUSINESS_GROUP_ID'))
            AND  petf.element_type_id              =  pivf.element_type_id
            AND  peevf.input_value_id              =  pivf.input_value_id
            AND  l_date BETWEEN petf.effective_start_date     AND petf.effective_end_date
            --AND  p_date BETWEEN peef.effective_start_date     AND peef.effective_end_date
            --AND  p_date BETWEEN peevf.effective_start_date    AND peevf.effective_end_date
            AND  (l_date BETWEEN peef.effective_start_date     AND peef.effective_end_date
            OR    peef.effective_start_date BETWEEN  l_date and last_day( l_date))
            AND  (l_date BETWEEN peevf.effective_start_date    AND peevf.effective_end_date
            OR  peevf.effective_start_date BETWEEN  l_date and last_day( l_date))
           -- AND  peef.effective_start_date BETWEEN p_date and last_day(p_date)
           -- AND  peevf.effective_start_date BETWEEN p_date and last_day(p_date)
            AND  l_date BETWEEN pivf.effective_start_date     AND pivf.effective_end_date;
            EXCEPTION WHEN OTHERS THEN
            l_standard_value :=0;
            END;
          --l_standard_value    :=get_screen_entry_value(L_ASS_ID,ele_ret_arr(I).element_name,l_date);
          else
          l_standard_value    :=get_run_result_value(ret_date,l_assignment_action_id,ele_ret_arr(I).element_name,'Standard Value',l_date,'IP');--get_screen_entry_value(l_assignment_id,ele_ret_arr(I).element_name,l_date);
          END IF;
          l_gross             :=l_gross+NVL(ele_ret_arr(I).total,0);
          --fnd_file.PUT_LINE(fnd_file.LOG,'eraning print  '||'element_name  '|| ele_ret_arr(I).element_name);
          IF
              ele_ret_arr(I).element_value <> 0 OR  ele_ret_arr(I).RETRO_VALUE <> 0 THEN
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<EARNING_ROW>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<EARNING_ELEMENT_NAME><![CDATA['|| ele_ret_arr(I).element_name         || ']]></EARNING_ELEMENT_NAME>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||round(ele_ret_arr(I).element_value,1)|| '</Payable>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Rate>'                         ||l_standard_value                     || '</Rate>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Arrears>'                      ||ele_ret_arr(I).RETRO_VALUE           || '</Arrears>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Total>'                        ||round(ele_ret_arr(I).total,1)        || '</Total>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduct>'                       ||ele_ret_arr(I).deduction             || '</Deduct>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Ded_value>'                    ||round(ele_ret_arr(I).ded_value,1)    || '</Ded_value>');
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'</EARNING_ROW>');
         END IF;
     END LOOP;
----
--Calculation of net pay
----
  --   l_net:=l_gross-l_deduction;
   --  l_words:=notoword(l_net);
        IF l_gross > 0 THEN
     l_net:=l_gross-l_deduction;
     ELSE
     l_net:=l_deduction;
     END IF;
     l_words:=notoword(l_net);
----
--Fetching elements for projection coloumn and calculation of total non recurring element values
----
     FOR rec_projection in projection(l_assignment_id,l_first_date,l_date)
     LOOP
          DBMS_OUTPUT.PUT_LINE(rec_projection.element_name);
         l_processing_type             :=rec_projection.processing_type;
         l_run_result_value            :=get_projection_value(p_person_id,
                                                              rec_projection.element_name,
                                                              p_month,
                                                              p_year,
                                                              rec_projection.classification_type,
                                                              l_processing_type,
                                                              l_tot_non_rec
                                                             -- ,rec_projection.rem_flag
                                                              ,rec_projection.context_value
                                                              ,l_period_left
                                                              );
          array_earn(J).element_name    :=rec_projection.element_name;
          IF rec_projection.element_name = 'House Rent Allowance'
          OR rec_projection.element_name ='Conveyance Allowance'
          OR rec_projection.element_name ='Education Allowance' THEN
          l_retro_value := 0;
          ELSE
          l_retro_value :=nvl(XXARJ_ELEMENT_VALUE_TILL_FNC (l_assignment_id,'Pay Value','Retro '||rec_projection.element_name,l_first_date,add_months(l_date,-1)),0);--XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(ret_date,l_assignment_action_id, 'Retro '||rec_projection.element_name,'Pay Value',l_date,'IP');
          END IF;
          array_earn(J).run_result_value:=l_run_result_value+l_retro_value;
          fnd_file.PUT_LINE(fnd_file.log,'****************** ELEMENT **************'||'Retro '||rec_projection.element_name||'      '|| l_retro_value||'Projected Value '||l_run_result_value);
          array_earn(J).processing_type :=l_processing_type;
          IF L_ASS_AC_ID is not null then
          l_total_n_rec :=XXARJ_PAYSLIP_GENERATION_PKG.get_run_result_value(ret_date,L_ASS_AC_ID,'Thailand Allowance','Pay Value',l_date,'IP');
           fnd_file.PUT_LINE(fnd_file.LOG,'############# Others as Thailand Allowance  :' ||' '||l_total_n_rec);
          END IF;
          l_total_n_rec                 :=l_total_n_rec+NVL(l_tot_non_rec,0);
          J:=J+1;
     END LOOP;
     ------
  /*   FOR i in  1 .. array_earn.COUNT
     loop
     fnd_file.PUT_LINE(fnd_file.log,'****************** ELEMENT **************'||array_earn(i).element_name );
     end loop;
     */
     ------
     FOR j IN 1 .. array_earn.COUNT
     LOOP
 --fnd_file.PUT_LINE(fnd_file.log,'______________________ ELEMENT _______________________________'||array_earn(j).element_name||'  '||array_earn(J).run_result_value );
          IF array_earn(J).processing_type = 'R' THEN
                  IF UPPER(p_month)  IN('JUN','SEP','DEC','MAR')  THEN
                    -- IF array_earn(J).element_name NOT LIKE '%Reimbursement%' THEN
                        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<ANNUAL_EARNING>');
                        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<EARNING_ELEMENT_NAME><![CDATA['||array_earn(J).element_name        || ']]></EARNING_ELEMENT_NAME>');
                         IF array_earn(J).element_name = 'Telephone Reimbursement' THEN
                          array_earn(J).run_result_value := XXARJ_NET_SAL_FNC(l_assignment_action_id,'Telephone Reimbursement Taxable Amount','_ASG_YTD');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                          ELSIF array_earn(J).element_name = 'Medical Reimbursement' THEN
                          array_earn(J).run_result_value := XXARJ_NET_SAL_FNC(l_assignment_action_id,'Medical Reimbursement Taxable Amount','_ASG_YTD');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                          ELSIF array_earn(J).element_name = 'Driver Reimbursement' THEN
                          array_earn(J).run_result_value := XXARJ_NET_SAL_FNC(l_assignment_action_id,'Driver Reimbursement Taxable Amount','_ASG_YTD');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                          ELSIF array_earn(J).element_name = 'Petrol Reimbursement' THEN
                          array_earn(J).run_result_value := XXARJ_NET_SAL_FNC(l_assignment_action_id,'Petrol Reimbursement Taxable Amount','_ASG_YTD');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                          ELSE
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                        END IF;
                        fnd_file.PUT_LINE(fnd_file.OUTPUT,'</ANNUAL_EARNING>');
                    -- END IF;
                     ELSE
                       --fnd_file.PUT_LINE(fnd_file.log,'****************** JUN **************' );
                       IF array_earn(J).element_name NOT LIKE '%Reimbursement%'AND array_earn(J).run_result_value <> 0  THEN
                        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<ANNUAL_EARNING>');
                        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<EARNING_ELEMENT_NAME><![CDATA['||array_earn(J).element_name        || ']]></EARNING_ELEMENT_NAME>');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable>'                      ||array_earn(J).run_result_value    || '</Payable>');
                          fnd_file.PUT_LINE(fnd_file.OUTPUT,'</ANNUAL_EARNING>');
                        END IF;
                  END IF ;
          END IF;
     END LOOP;
     --fnd_file.PUT_LINE(fnd_file.LOG,': *********************************'    ||l_pf_def_bal_id );
--- Added on 7/DEC/2010
--PPF contribution
---
l_pf_def_bal_id     := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id('Employee Statutory PF Contribution' ,'_ASG_YTD',l_business_group_id,'IN');
--fnd_file.PUT_LINE(fnd_file.LOG,': *********************************'    ||l_pf_def_bal_id );
BEGIN
l_pf_till_date      := pay_balance_pkg.get_value(l_pf_def_bal_id, l_assignment_action_id);
EXCEPTION WHEN OTHERS THEN
fnd_file.PUT_LINE(fnd_file.LOG,': *********************************'    ||SQLERRM );
END;
l_standard_value    := get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Employee Statutory PF Contribution','Standard Value',l_date,'IP');
l_pf_val:=l_pf_till_date + (l_standard_value * l_period_left);
fnd_file.PUT_LINE(fnd_file.OUTPUT,'<PF>'                 || l_pf_val                 || '</PF>');
fnd_file.PUT_LINE(fnd_file.LOG,': Defined Balance id'    ||l_pf_def_bal_id );
fnd_file.PUT_LINE(fnd_file.LOG,': Value till date of PF' ||l_pf_till_date );
fnd_file.PUT_LINE(fnd_file.LOG,': standard value OF PF'  ||l_standard_value );
fnd_file.PUT_LINE(fnd_file.LOG,': Total PF Projection '  ||l_pf_val );
----
--House rent information
----
     l_from        :=FND_CONC_DATE.STRING_TO_DATE('01' ||'APR'||p_year);
     to_from       :=add_months(l_from,11);
     OPEN get_house_rent_info(l_assignment_id);
     FETCH get_house_rent_info
     INTO  l_rent_paid
          ,l_row_count;
     CLOSE get_house_rent_info;
-----Modified on 5/DEC/2010------------
     IF  l_row_count >1 THEN
        -- l_taxable_hra :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Taxable HRA','Pay Value',l_date,'IP');
         l_taxable_hra :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Taxable HRA','Annual Value',l_date,'IP');
         l_exempted_amt:= APPS.XXARJ_in_payroll_utility_pkg.XXARJ_get_exempted_amt(l_business_group_id,l_assignment_action_id,l_tax_id,'House Rent Allowance',l_date);
         l_hra_exempted:=l_exempted_amt - l_taxable_hra;
         fnd_file.PUT_LINE(fnd_file.LOG,'############# Issues Annual value in Taxable HRA:' ||' '||l_taxable_hra);
         fnd_file.PUT_LINE(fnd_file.LOG,'############# Issues Taxable exempted amt from XXARJ_in_payroll_utility_pkg :' ||' '||l_exempted_amt);
         fnd_file.PUT_LINE(fnd_file.LOG,'############# HRA exempted is  :' ||' '||l_hra_exempted);
----------------------------------------
        fnd_file.PUT_LINE(fnd_file.OUTPUT, '<HRA_CALCULATION>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Rent_Paid>'         || l_rent_paid            || '</Rent_Paid>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<From>'              || l_from                 || '</From>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<To>'                || to_from                || '</To>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<HRA_Exempted>'      ||l_hra_exempted          || '</HRA_Exempted>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Gross>'             ||l_gross                 || '</Gross>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction>'         ||l_deduction             || '</Deduction>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Net>'               ||l_net                   || '</Net>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<words>'             ||l_words                 || '</words>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<month>'             ||to_char(l_date,'Month') || '</month>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<year>'              ||p_year                  || '</year>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT, '</HRA_CALCULATION>');
     END IF;
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Others_N>'            ||l_total_n_rec                 || '</Others_N>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Gross>'               ||l_gross                       || '</Gross>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction>'           ||l_deduction                   || '</Deduction>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Net>'                 ||l_net                         || '</Net>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<words>'               ||l_words                       || '</words>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Fyear>'               ||trim(to_char(l_from,'YYYY'))  || '</Fyear>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<TYear>'               ||trim(to_char(to_from,'YYYY')) || '</TYear>');
----
--Calxulation of 1)site days 2) payable days 3) furniture cost using function get_run_result_value
----
     l_site_days     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Site Allowance','Site Days',l_date,'IP');
    -- l_payable_days  :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Payable Days','Days',l_date,'IP');
     l_furniture_cost:=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Projected Company Accommodation','Furniture Cost',l_date,'IP');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Payable_days>'        ||l_payable_days                || '</Payable_days>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Furniture>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,' <furniture_cost>'|| l_furniture_cost|| '</furniture_cost>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,' <furniture_cost>'        ||' '|| '</furniture_cost>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,' <Taxable_Furniture_Perk>'||' '|| '</Taxable_Furniture_Perk>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Furniture>');
----
--Company Accommodation
----
     l_comp_rent_paid:=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Company Accommodation','Rent Paid by Employer',l_date,'IP');
     l_taxable_rfa   :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Company Accommodation','Pay Value',            l_date,'IP');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '<COMPANY_ACCOMODATION>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<CRent_Paid>'      || l_comp_rent_paid|| '</CRent_Paid>');
     l_comp_from     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Company Accommodation','Benefit Start Date',   l_date,'IP');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<CFrom>'          || l_hra_from_to_date     || '</CFrom>');
     l_comp_to       :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Company Accommodation','Benefit End Date',     l_date,'IP');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<CTo>'            || l_hra_from_to_date       || '</CTo>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<CTaxable_RFA>'    ||l_taxable_rfa     || '</CTaxable_RFA>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '</COMPANY_ACCOMODATION>');
----
--Deduction Under Chapter VI A Starts
----
     FOR elem in 1..array_chap_ele.COUNT
     LOOP
            l_result:=0;
            l_result:=get_run_result_value(l_hra_from_to_date,
                                           l_assignment_action_id,
                                           array_chap_ele(elem).element_name,
                                           array_chap_ele(elem).input_name,
                                           l_date,
                                           'IP');
            --chap_V1_A_total                :=TO_NUMBER(chap_V1_A_total)+l_result;
            chap_V1_A_total                :=chap_V1_A_total+l_result;
            array_chap_ele(elem).res_value :=  l_result;
            IF l_result <>0 then
                fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Deduction_under_chap_V1A>');
                row_count:=row_count+1;
                fnd_file.PUT_LINE(fnd_file.OUTPUT,'<RowCount>'    ||row_count     || '</RowCount>');
                fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_chap_V1A_element>'      || array_chap_ele(elem).input_name|| '</Deduction_chap_V1A_element>');
                fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_chap_V1A_element_value>'|| array_chap_ele(elem).res_value   || '</Deduction_chap_V1A_element_value>');
                fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Deduction_under_chap_V1A>');
            END IF;
     END LOOP;
     IF row_count>1 THEN
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_Message>Y</Deduction_Message>');
       -- fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_Message>'             || 'Y'             || '</Deduction_Message>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Total_value>'                   || 'Total'         || '</Total_value>');
        fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_chap_V1A_total>'      || chap_V1_A_total || '</Deduction_chap_V1A_total>');
     END IF;
----
--Form 16 Income Tax Information
----
     IF L_ASS_AC_ID is not null then

     l_taxable_income   :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Total Income',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Tax Information','Total Income',l_date,'IP'),0);
     l_inc_tax_liability:=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Tax on Total Income',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Tax Information','Tax on Total Income',l_date,'IP'),0);
     l_surcharge        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Surcharge',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Tax Information','Surcharge',l_date,'IP'),0);
     l_edu_cess         :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Education Cess',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Tax Information','Education Cess',l_date,'IP'),0);
     ------Modified on 5/DEC/2010-----------
   --  l_net_tax          :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Income Tax till Date',l_date,'IP');
     l_Sec_HE_Cess      :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Sec and HE Cess',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Tax Information','Sec and HE Cess',l_date,'IP'),0);
     l_net_tax:=round(l_inc_tax_liability + l_edu_cess + l_Sec_HE_Cess,1);
     l_edu_cess:=l_edu_cess + l_Sec_HE_Cess;
     ---------------------------------

     l_tax_this_mon     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Income Tax','Pay Value',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Income Tax','Pay Value',l_date,'IP'),0);
        For rec_get_deduction_elements IN get_earn_deduct_elements(L_ASS_AC_ID,l_date,'D')
         LOOP
          l_run_result_value     :=get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,rec_get_deduction_elements.element_name,'Pay Value',l_date,'IP');
          l_tax_this_mon := l_tax_this_mon+l_run_result_value;
          END LOOP;
     l_proff_tax        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Professional Tax Deduction','Pay Value',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Professional Tax Deduction','Pay Value',l_date,'IP'),0);
     l_proff_tax        := l_proff_tax *12;
     l_proff_tax        := get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Information','Employment Tax',l_date,'IP');
     l_other_inc_id     := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id('Other Income','_ASG_RUN');
     l_other_inc        := pay_balance_pkg.get_value(l_other_inc_id, l_assignment_action_id);
     l_chap_VIA_id      := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id('Chapter VIA Deductions','_ASG_RUN');
     l_chap_VIA         := pay_balance_pkg.get_value(l_chap_VIA_id, l_assignment_action_id);
     l_gross_salary     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Information','Salary',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Information','Salary',l_date,'IP'),0);
     l_exempted_amount     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Information','Allowances Exempt',l_date,'IP')+NVL(get_run_result_value(l_hra_from_to_date,L_ASS_AC_ID,'Form16 Income Information','Allowances Exempt',l_date,'IP'),0);
     l_tax_till_date    := XXARJ_NET_SAL_FNC(l_assignment_action_id,'F16 TDS','_ASG_PTD')+NVL(XXARJ_NET_SAL_FNC(L_ASS_AC_ID,'F16 TDS','_ASG_PTD'),0);
       FND_FILE.PUT_LINE(FND_FILE.LOG,'**~~~~~~~***Tax**~~~~~****  :'||l_tax_till_date||'     '||l_tax_this_mon);
     l_tax_till_date    := l_tax_till_date-l_tax_this_mon;
     l_prev_emp_sal        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Earnings',l_date,'IP');
     l_prev_emp_tax        :=nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Tax Deduction',l_date,'IP'),0)+nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Cess',l_date,'IP'),0)+nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Sec and HE Cess',l_date,'IP'),0);
     ELSE
     l_taxable_income   :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Total Income',l_date,'IP');
     l_inc_tax_liability:=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Tax on Total Income',l_date,'IP');
     l_surcharge        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Surcharge',l_date,'IP');
     l_edu_cess         :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Education Cess',l_date,'IP');
     ------Modified on 5/DEC/2010-----------
   --  l_net_tax          :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Income Tax till Date',l_date,'IP');
     l_Sec_HE_Cess      :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Tax Information','Sec and HE Cess',l_date,'IP');
     l_net_tax:=round(l_inc_tax_liability + l_edu_cess + l_Sec_HE_Cess,1);
     l_edu_cess:=l_edu_cess + l_Sec_HE_Cess;
     ---------------------------------
     l_tax_this_mon     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Income Tax','Pay Value',l_date,'IP');
     l_proff_tax        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Professional Tax Deduction','Pay Value',l_date,'IP');
     l_proff_tax        := l_proff_tax *12;
     l_other_inc_id     := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id('Other Income','_ASG_RUN');
     l_other_inc        := pay_balance_pkg.get_value(l_other_inc_id, l_assignment_action_id);
     l_chap_VIA_id      := XXARJ_pay_payroll_reports_pkg.get_defined_bal_id('Chapter VIA Deductions','_ASG_RUN');
     l_chap_VIA         := pay_balance_pkg.get_value(l_chap_VIA_id, l_assignment_action_id);
     l_gross_salary     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Information','Salary',l_date,'IP');
     l_exempted_amount     :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Form16 Income Information','Allowances Exempt',l_date,'IP');
     l_tax_till_date    := XXARJ_NET_SAL_FNC(l_assignment_action_id,'F16 TDS','_ASG_PTD');
     l_prev_emp_sal        :=get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Earnings',l_date,'IP');
     l_prev_emp_tax        :=nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Tax Deduction',l_date,'IP'),0)+nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Cess',l_date,'IP'),0)+nvl(get_run_result_value(l_hra_from_to_date,l_assignment_action_id,'Previous Employment Information','Previous Sec and HE Cess',l_date,'IP'),0);
     l_tax_till_date    := l_tax_till_date-l_tax_this_mon;
     END IF;
    fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Exempted_amount>'  || round(l_exempted_amount,1)    || '</Exempted_amount>');
    fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Tax_till_date>'  || round(l_tax_till_date,1)    || '</Tax_till_date>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '<Others>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Taxable_income>'  || round(l_taxable_income,1)    || '</Taxable_income>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Tax_liability>'   || round(l_inc_tax_liability,1) || '</Tax_liability>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Surcharge>'       || round(l_surcharge,1)         || '</Surcharge>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Educational_cess>'|| round(l_edu_cess,1)           || '</Educational_cess>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Net_tax>'         || round(l_net_tax,1)           || '</Net_tax>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Tax_this_month>'  || round(l_tax_this_mon,1)      || '</Tax_this_month>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Proff_tax>'       || round(l_proff_tax,1)         || '</Proff_tax>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Other_income>'    || round(l_other_inc,1)         || '</Other_income>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Deduction_VIA>'   || round(chap_V1_A_total,1)          || '</Deduction_VIA>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<Gross_salary>'    || round(l_gross_salary,1)      || '</Gross_salary>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<prev_emp_sal>'    || round(l_prev_emp_sal,1)      || '</prev_emp_sal>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,'<prev_emp_tax>'    || round(l_prev_emp_tax,1)      || '</prev_emp_tax>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT, '</Others>');
     fnd_file.PUT_LINE(fnd_file.OUTPUT,   '</PAYSLIP_DETAILS>');
 END IF;
EXCEPTION
WHEN OTHERS THEN
      fnd_file.PUT_LINE(fnd_file.LOG,'ERROR in Procedure XXARJ_PAYSLIP_GENERATION_PRC: '||sqlerrm||SQLCODE||'   '||SQLERRM);
END XXARJ_PAYSLIP_GENERATION_PRC;
END XXARJ_PAYSLIP_GENERATION_PKG;