Tuesday, 19 February 2013

Custom workflow timeout issue


Faced a problem in a custom workflow in time out node.
Have created a workflow with timeout node.


The workflow initiated from a custom form which registered in a custom application. Even if the time out node has been added in wf, still time out has not been worked. Process stuck at the node where timeout has been added. The reason I have found when workflow background process runs, the time out called from WF_ENGINE.ProcessTimeOut(itemtype in varchar2) package. And the package has only considered APPS schema or more precisely it checks the the owner of the workflow is in apps schema.

As the owner of the wf is custom application so each time wf process stuck at the timeout node and its wait for the response.


procedure ProcessTimeOut(itemtype in varchar2)
is
  resource_busy exception;
  pragma exception_init(resource_busy, -00054);

  l_itemtype      varchar2(8);
  l_itemkey       varchar2(240);
  l_actid         pls_integer;
  pntfstatus      varchar2(8);
  pntfresult      varchar2(30);

  -- Select one timeout activity that matches itemtype
  -- NOTE: Two separate cursors are used for itemtype and no-itemtype
  -- cases to get better execution plans.


  -- select everything but completed and error.
  -- avoid "not in" which disables index in RBO
  cursor curs_itype is
    select
         S.ROWID ROW_ID
    from WF_ITEM_ACTIVITY_STATUSES S
    where S.DUE_DATE < SYSDATE
    and S.ACTIVITY_STATUS in ('ACTIVE','WAITING','NOTIFIED',
                              'SUSPEND','DEFERRED')
    and S.ITEM_TYPE = itemtype;

  cursor curs_noitype is
    select
         S.ROWID ROW_ID
    from WF_ITEM_ACTIVITY_STATUSES S
    where S.DUE_DATE < SYSDATE
    and S.ACTIVITY_STATUS in ('ACTIVE','WAITING','NOTIFIED',
                              'SUSPEND','DEFERRED');

  idarr RowidArrayTyp;
  arrsize pls_integer;
  eligible boolean;
  schema   varchar2(30);

begin
  -- Fetch eligible rows into array
  arrsize := 0;
  if (itemtype is not null) then
    -- Fetch by itemtype
    for id in curs_itype loop
      arrsize := arrsize + 1;
      idarr(arrsize) := id.row_id;
    end loop;
  else
    -- Fetch all itemtypes
    for id in curs_noitype loop
      arrsize := arrsize + 1;
      idarr(arrsize) := id.row_id;
    end loop;
  end if;

  -- Process all eligible rows found
  for i in 1 .. arrsize loop
    -- Lock row, and check if still eligible for execution
    -- To check eligibility, do original select only add rowid condition.
    -- Note ok to use no-itemtype variant since itemtype can't change
    -- and was already filtered for in original select.
    -- select everything but completed and error. avoid "not in" which
    -- disables index in RBO.
    begin
      select
        S.ITEM_TYPE, S.ITEM_KEY, S.PROCESS_ACTIVITY
      into l_itemtype, l_itemkey, l_actid
      from WF_ITEM_ACTIVITY_STATUSES S , WF_ITEMS WI
      where S.DUE_DATE < SYSDATE
      and S.ACTIVITY_STATUS in ('WAITING','NOTIFIED','SUSPEND',
                                'DEFERRED','ACTIVE')
      and S.ROWID = idarr(i)
      and WI.item_type   = S.ITEM_TYPE
      and WI.item_key    = S.ITEM_KEY
      for update of S.ACTIVITY_STATUS, WI.item_type , wi.item_key NOWAIT;

      -- check if schema matched
        schema := Wf_Engine.GetItemAttrText(l_itemtype,l_itemkey,
                    wf_engine.eng_schema, ignore_notfound=>TRUE);
                   
        ---*** XX Added
        --- For time out feature wf only consider APPS schema.
        --- We have registered our custom packages in the XX schema
        --- So delibaretly we are bypassing schema value as APPS
        If Schema = 'XX'
        then
            schema :='APPS';
        End if;
        ---*** XX End
         
 
      if (schema is null or
          schema = Wf_Engine.Current_Schema) then
        eligible := TRUE;
      else
        eligible := FALSE;
      end if;
    exception
      when resource_busy or no_data_found then
        -- If row already locked, or no longer eligible to run,
        -- continue on to next item in list.
        eligible := FALSE;
    end;

    if (eligible) then
      -- Set the status to COMPLETE:#TIMEOUT.
      Wf_Item_Activity_Status.Create_Status(l_itemtype, l_itemkey, l_actid,
          wf_engine.eng_completed, wf_engine.eng_timedout);

      begin
       begin
        begin
          savepoint wf_savepoint;
          -- If there is a function attached, call it in timeout mode to
          -- give the function one last chance to complete and override
          -- the timeout.
          Wf_Engine_Util.Execute_Post_NTF_Function(l_itemtype, l_itemkey,
              l_actid, wf_engine.eng_timeout, pntfstatus, pntfresult);
          if (pntfstatus = wf_engine.eng_completed) then
            -- Post-notification function found and returned a completed
            -- status.
            -- Complete activity with result of post-notification function.
            Wf_Engine_Util.Complete_Activity(l_itemtype, l_itemkey, l_actid,
                pntfresult, FALSE);
          else
            -- Either had no post-notification function, or result was still
            -- not complete.
            -- In either case, complete activity with #TIMEOUT.
            Wf_Engine_Util.Complete_Activity(l_itemtype, l_itemkey, l_actid,
                wf_engine.eng_timedout);
          end if;
        exception
          when others then
            -- If anything in this process raises an exception:
            -- 1. rollback any work in this process thread
            -- Raise an exception for the next exception handler to finish
            -- remaining steps.
            rollback to wf_savepoint;
            raise;
        end;
       exception
         when NO_SAVEPOINT then
           -- Catch any savepoint error in case of a commit happened.
           Wf_Core.Token('ACTIVITY', Wf_Engine.GetActivityLabel(l_actid));
           Wf_Core.Raise('WFENG_COMMIT_IN_COMPLETE');
       end;
      exception
        when OTHERS then
          -- Remaining steps for completing activity raises an exception:
          -- 2. set this activity to error status
          -- 3. execute the error process (if any)
          -- 4. clear the error to continue with next activity
          Wf_Core.Context('Wf_Engine', 'ProcessTimeout', l_itemkey, l_itemtype,
              to_char(l_actid));
          Wf_Item_Activity_Status.Set_Error(l_itemtype, l_itemkey, l_actid,
              wf_engine.eng_exception, FALSE);
          Wf_Engine_Util.Execute_Error_Process(l_itemtype, l_itemkey,
              l_actid, wf_engine.eng_exception);
          Wf_Core.Clear;
      end;
    end if;

    -- bug 7828862 - Resynch apps context from cached values if it changed
    wfa_sec.Restore_Ctx();

    -- For eligible row: Commit work to insure this activity
    --   thread doesn't interfere with others.
    -- For non-eligible row: Commit to release the lock.
    commit;
    Fnd_Concurrent.Set_Preferred_RBS;

  end loop;

exception
  when others then
    Wf_Core.Context('Wf_Engine', 'ProcessTimeout', l_itemkey, l_itemtype,
                    to_char(l_actid));
    raise;
end ProcessTimeOut;


Tuesday, 22 January 2013

R12 Supplier Contact creation API


AP_SUP_SITE_CONTACT_INT interface used in 11i for loading supplier contact. Currently in R12 contacts can not be loaded using the interface table.

ap_vendor_pub_pkg.create_vendor_contact API is used in R12 and the program has to be registered as a concurrent program.
### Sample R12 Code    

BEGIN
     v_party_usg_assignment_id := NULL;
      v_relationship_id := NULL;
      v_directional_flag := NULL;
      v_rel_rowid := NULL;
      fnd_file.put_line (fnd_file.LOG,
                            'Vendor code :'
                         || rec.vendor_name
                         || '  Vendor site code :'
                         || rec.vendor_site_code
                         || '  Person Last Name : '
                         || rec.person_last_name
                        );
      l_vendor_contact.vendor_id := rec.vendor_id;
      l_vendor_contact.vendor_site_id := rec.vendor_site_id;
      l_vendor_contact.org_id := rec.org_id;
      l_vendor_contact.person_first_name := rec.person_first_name;
      l_vendor_contact.person_middle_name := rec.person_middle_name;
      l_vendor_contact.person_last_name := rec.person_last_name;
     l_vendor_contact.phone := rec.phone;
      l_vendor_contact.email_address := rec.email_address;
      p_init_msg_list := fnd_api.g_true;
      p_commit := fnd_api.g_false;
      x_return_status := NULL;
      x_msg_count := NULL;
      x_msg_data := NULL;

      IF rec.process_flag = 'I'
      THEN
         fnd_file.put_line (fnd_file.LOG, 'Creating contacts....');
         ap_vendor_pub_pkg.create_vendor_contact
                  (p_api_version             => p_api_version,
                   p_init_msg_list           => p_init_msg_list,
                   p_commit                  => p_commit,
                   x_return_status           => x_return_status,
                   x_msg_count               => x_msg_count,
                   x_msg_data                => x_msg_data,
                   p_vendor_contact_rec      => l_vendor_contact,
                   x_vendor_contact_id       => l_vendor_contact.vendor_contact_id,
                   x_per_party_id            => l_vendor_contact.per_party_id,
                   x_rel_party_id            => l_vendor_contact.relationship_id,
                   x_rel_id                  => l_vendor_contact.rel_party_id,
                   x_org_contact_id          => l_vendor_contact.org_contact_id,
                   x_party_site_id           => l_vendor_contact.party_site_id
                  );
         error_handling (rec.r_id, x_return_status, x_msg_count, x_msg_data);
         fnd_file.put_line (fnd_file.LOG, '*************');
      END IF;
END;



Friday, 11 January 2013

Text Attachment content print

Various files are attached in the documents like PO, Requisition, Invoice etc. If an attachment is a text type then  it is possible to print the content of the attachment .

One of the example various PO terms and conditions are added in the PO header or line level. The following script will help print in the report.


/* Formatted on 2013/01/11 23:36 (Formatter Plus v4.8.8) */
DECLARE
   CURSOR cur_file_info (i_hdr_id NUMBER)
   IS
      SELECT DISTINCT seq_num, media_id
                 FROM fnd_attached_docs_form_vl
                WHERE pk1_value = i_hdr_id
                  AND category_description = 'To Supplier'
                  AND datatype_name = 'File'
             ORDER BY seq_num;
BEGIN
   BEGIN
      l_file_content := NULL;

      FOR get_file_content IN cur_file_info (:po_header_id)
      LOOP
         SELECT file_id, file_name
           INTO l_file_id, l_file_name
           FROM fnd_lobs
          WHERE file_content_type = 'text/plain'
            AND file_id = get_file_content.media_id;

         populate_file_content (l_file_id, l_file_content);
      END LOOP;
   END;
END;






PROCEDURE populate_file_content (i_file_id NUMBER, i_file_content OUT VARCHAR2)
IS
   l_blob                   BLOB;
   l_clob                   CLOB             := EMPTY_CLOB ();
   l_src_offset             NUMBER           := 1;
   l_dest_offset            NUMBER           := 1;
   l_blob_csid              INTEGER          := 0;
   v_lang_context           INTEGER          := 0;
   l_warning                NUMBER;
   l_amount                 BINARY_INTEGER;
   l_buffer_size   CONSTANT BINARY_INTEGER   := 32767;
   l_buffer                 VARCHAR2 (32767) := NULL;
   --l_file_content           VARCHAR2 (32767) := NULL;
   l_offset                 NUMBER           := 1;
BEGIN
   l_buffer := NULL;
   DBMS_LOB.createtemporary (l_blob, TRUE);
   DBMS_LOB.createtemporary (l_clob, TRUE);

   SELECT file_data
     INTO l_blob
     FROM fnd_lobs
    WHERE file_id = i_file_id;

   IF DBMS_LOB.getlength (l_blob) > 0
   THEN
      DBMS_LOB.converttoclob (l_clob,
                              l_blob,
                              DBMS_LOB.getlength (l_blob),
                              l_dest_offset,
                              l_src_offset,
                              1,
                              v_lang_context,
                              l_warning
                             );
   END IF;

   l_amount := l_buffer_size;

   WHILE l_amount >= l_buffer_size
   LOOP
      BEGIN
         DBMS_LOB.READ (lob_loc      => l_clob,
                        amount       => l_amount,
                        offset       => l_offset,
                        buffer       => l_buffer
                       );
         l_buffer := REPLACE (l_buffer, CHR (13), '');
         l_offset := l_offset + l_amount;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;
   END LOOP;

   i_file_content := l_buffer;
EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;





Friday, 28 December 2012

R12 Vendor/Supplier Bank Details Query


Employee as a supplier Bank details

SELECT aps.vendor_id, apss.vendor_site_id, aps.vendor_name,
       apss.vendor_site_code, ieb.bank_name, ieb.country,
       iebb.bank_branch_name, iebb.eft_swift_code, iebb.branch_number,
       ieba.bank_account_num, ieba.bank_account_name, iban
  FROM ap.ap_suppliers aps,
       per_all_people_f papf,
       ap.ap_supplier_sites_all apss,
       apps.iby_ext_bank_accounts ieba,
       apps.iby_account_owners iao,
       apps.iby_ext_banks_v ieb,
       apps.iby_ext_bank_branches_v iebb
 WHERE aps.vendor_id = apss.vendor_id
   AND iao.account_owner_party_id = aps.party_id
   AND ieba.ext_bank_account_id = iao.ext_bank_account_id
   AND ieb.bank_party_id = iebb.bank_party_id
   AND ieba.branch_id = iebb.branch_party_id
   AND ieba.bank_id = ieb.bank_party_id
   AND aps.employee_id = papf.person_id
   AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
                           AND papf.effective_end_date


Supplier Bank details (Not an Employee)


SELECT aps.vendor_id, apss.vendor_site_id, aps.vendor_name,
       apss.vendor_site_code, ieb.bank_name, ieb.country,
       iebb.bank_branch_name, iebb.eft_swift_code, iebb.branch_number,
       ieba.bank_account_num, ieba.bank_account_name, iban
  FROM ap.ap_suppliers aps,
       ap.ap_supplier_sites_all apss,
       apps.iby_ext_bank_accounts ieba,
       apps.iby_account_owners iao,
       apps.iby_ext_banks_v ieb,
       apps.iby_ext_bank_branches_v iebb
 WHERE aps.vendor_id = apss.vendor_id
   AND iao.account_owner_party_id = aps.party_id
   AND ieba.ext_bank_account_id = iao.ext_bank_account_id
   AND ieb.bank_party_id = iebb.bank_party_id
   AND ieba.branch_id = iebb.branch_party_id
   AND ieba.bank_id = ieb.bank_party_id

Check series information exists in CE_PAYMENT_DOCUMENTS table.

R12 Internal Bank Details query


SELECT   hou.NAME "OPERATING UNIT", cbbv.bank_name, cbbv.bank_branch_name,
         cba.bank_account_name, hp.party_name "LEGAL ENTITY",
         cbau.ar_use_enable_flag "RECEIVABLES_ACCOUNT_USE",
         cbau.ap_use_enable_flag "PAYABLES_ACCOUNT_USE",
         cba.bank_account_num "ACCOUNT_NUMBER",
         cba.bank_account_type "ACCOUNT TYPE", cba.iban_number,
         cba.currency_code, cba.multi_currency_allowed_flag, cba.description,
         gcck1.concatenated_segments "CASH ACCOUNT",
         gcck2.concatenated_segments "BANK_CHARGES_ACCOUNT",
         gcck3.concatenated_segments "FOREIGN_EXCHANGE_CHARGES",
         gcck4.concatenated_segments "CASH_CLEARING_ACCOUNT",
         gcck5.concatenated_segments "BANK_ERRORS_ACCOUNT",
         gcck6.concatenated_segments "FUTURE_DATED_PAYMENT_ACCOUNT",
         cba.ap_amount_tolerance "PAYMENT_TOLERANCE_AMOUNT",
         cba.ap_percent_tolerance "PAYMENT_TOLERANCE_PERCENTAGE",
         cba.ar_amount_tolerance "RECEIPT_TOLERANCE_AMOUNT",
         cba.ar_percent_tolerance "RECEIPT_TOLERANCE_PERCENTAGE",
         cba.ce_amount_tolerance "CASHFLOW_TOLERANCE_AMOUNT",
         cba.ce_percent_tolerance "CASHFLOW_TOLERANCE_PERCENTAGE",
         cba.recon_oi_amount_tolerance "OPEN_INT_TOLERANCE_AMOUNT",
         cba.recon_oi_percent_tolerance "OPEN_INT_TOLERANCE_PERCENTAGE",
         gcck7.concatenated_segments "ON_ACCOUNT_ACCOUNT",
         gcck8.concatenated_segments "UNAPPLIED_ACCOUNT",
         gcck9.concatenated_segments "UNIDENTIFIED_ACCOUNT",
         gcck10.concatenated_segments "ASSET_ACCOUNT",
         gcck11.concatenated_segments "REMITTANCE_ACCOUNT",
         gcck12.concatenated_segments "RECEIPT_CLEARING_ACCOUNT"
    FROM ce_bank_accounts cba,
         ce_bank_acct_uses_all cbau,
         ce_gl_accounts_ccid cgac,
         ce_bank_branches_v cbbv,
         hr_operating_units hou,
         hz_parties hp,
         gl_code_combinations_kfv gcck1,
         gl_code_combinations_kfv gcck2,
         gl_code_combinations_kfv gcck3,
         gl_code_combinations_kfv gcck4,
         gl_code_combinations_kfv gcck5,
         gl_code_combinations_kfv gcck6,
         gl_code_combinations_kfv gcck7,
         gl_code_combinations_kfv gcck8,
         gl_code_combinations_kfv gcck9,
         gl_code_combinations_kfv gcck10,
         gl_code_combinations_kfv gcck11,
         gl_code_combinations_kfv gcck12
   WHERE cbbv.bank_party_id = cba.bank_id
     AND cbbv.branch_party_id = cba.bank_branch_id
     AND cba.bank_account_id = cbau.bank_account_id
     AND cgac.bank_acct_use_id = cbau.bank_acct_use_id
     AND cbau.org_id = hou.organization_id
     AND hp.party_id = cba.account_owner_party_id
     AND gcck1.code_combination_id = cgac.ap_asset_ccid
     AND gcck2.code_combination_id = cgac.bank_charges_ccid
     AND gcck3.code_combination_id = cba.fx_charge_ccid
     AND gcck4.code_combination_id = cgac.cash_clearing_ccid
     AND gcck5.code_combination_id(+) = cgac.bank_errors_ccid
     AND gcck6.code_combination_id(+) = cgac.future_dated_payment_ccid
     AND gcck7.code_combination_id = cgac.on_account_ccid
     AND gcck8.code_combination_id = cgac.unapplied_ccid
     AND gcck9.code_combination_id = cgac.unidentified_ccid
     AND gcck10.code_combination_id(+) = cgac.asset_code_combination_id
     AND gcck11.code_combination_id = cgac.remittance_ccid

Thursday, 20 December 2012

Payslip Report



Using the following view I have created the payslip report.
Based on the requirement I have made the view which is working very well.

Guidance for change:
Earning and deduction elements has to be replaced.
Total earning and Total deductions has be calculated accordingly.
For faster output , make it materialized view.




CREATE OR REPLACE FORCE VIEW xx_payslip_register_v (action_type,
                                                    --employment_category,
                                                    --grade,
                                                    --job,
                                                    --LOCATION,
                                                    employee_number,
                                                    full_name,
                                                    payroll_name,
                                                    period,
                                                    business_group_id,
                                                    request_id,
                                                    pfno,
                                                    epsno,
                                                    assignment_action_id,
                                                    assignment_id,
                                                    payroll_id,
                                                    time_period_id,
                                                    basic,
                                                    basic_arrear,
                                                    dpay,
                                                    dpay_arrear,
                                                    interim_allowance,
                                                    personal_pay,
                                                    personal_pay_arrear,
                                                    da,
                                                    arrear_da,
                                                    deputation_allowance,
                                                    deputation_allowance_arrear,
                                                    ppay2,
                                                    ppay2_arrear,
                                                    site_allowance,
                                                    site_allowance_arrear,
                                                    hardship_allowance,
                                                    hardship_allowance_arrear,
                                                    house_rent_allowance,
                                                    house_rent_allowance_arrear,
                                                    cca,
                                                    cca_arrear,
                                                    sbihf_subsidy,
                                                    sbihf_howrah_subsidy,
                                                    hdfc_subsidy,
                                                    miscelleneous_earnings,
                                                    tot_earnings,
                                                    pf,
                                                    epf,
                                                    pension_fund,
                                                    vpf,
                                                    lic,
                                                    ptax,
                                                    itax,
                                                    company_accomodation,
                                                    festival_advance_deduction,
                                                    cooperative_deduction,
                                                    car_loan_interest,
                                                    car_loan_deduction,
                                                    car_repair_loan_interest,
                                                    officer_car_repair_loan,
                                                    officer_sundry_laon_interest,
                                                    officer_sundry_loan_deduction,
                                                    company_housing_loan_interest,
                                                    company_housing_loan,
                                                    sbihf,
                                                    sbi_howrah,
                                                    hdfc,
                                                    furniture_loan_interest,
                                                    furniture_loan,
                                                    pf_loan,
                                                    recreation_club_deduction,
                                                    hire_fixed_assests,
                                                    salary_advance_deduction,
                                                    car_expense_recovery,
                                                    personal_expense_recovery,
                                                    income_tax_arrear,
                                                    officer_tiffin,
                                                    rd,
                                                    donation,
                                                    miscelleneous_deduction,
                                                    coin_carryover_april,
                                                    coin_carryover,
                                                    arrears_pt,
                                                    basic_adjustment,
                                                    car_loan_deduction_adjustment,
                                                    stat_pf_arrear,
                                                    vol_pf_arrear,
                                                    pf_arrear_adj,
                                                    vpf_arrear_adj,
                                                    tot_deductions,
                                                    tot_deductions_wo_income_tax,
                                                    net_pay,
                                                    net_pay_wo_income_tax
                                                   )
AS
   SELECT   action_type,
                        --bnr_employment_cat (period, assignment_id) employment_category,
                        --bnr_employee_grade (period, assignment_id) grade,
                        --bnr_employee_job (period, assignment_id) job,
                        --bnr_employee_location (period, assignment_id) LOCATION,
                        employee_number, full_name, payroll_name, period,
            business_group_id, request_id, pfno, epsno, assignment_action_id,
            assignment_id, payroll_id, time_period_id,
            SUM (NVL (basic, 0)) basic,
            SUM (NVL (basic_arrear, 0)) basic_arrear, SUM (NVL (dpay, 0))
                                                                         dpay,
            SUM (NVL (dpay_arrear, 0)) dpay_arrear,
            SUM (NVL (interim_allowance, 0)) interim_allowance,
            SUM (NVL (personal_pay, 0)) personal_pay,
            SUM (NVL (personal_pay_arrear, 0)) personal_pay_arrear,
            SUM (NVL (da, 0)) da, SUM (NVL (arrear_da, 0)) arrear_da,
            SUM (NVL (deputation_allowance, 0)) deputation_allowance,
            SUM
               (NVL (deputation_allowance_arrear, 0)
               ) deputation_allowance_arrear,
            SUM (NVL (ppay2, 0)) ppay2,
            SUM (NVL (ppay2_arrear, 0)) ppay2_arrear,
            SUM (NVL (site_allowance, 0)) site_allowance,
            SUM (NVL (site_allowance_arrear, 0)) site_allowance_arrear,
            SUM (NVL (hardship_allowance, 0) + NVL (hsal_adj, 0)
                ) hardship_allowance,
            SUM (NVL (hardship_allowance_arrear, 0))
                                                    hardship_allowance_arrear,
            SUM (NVL (house_rent_allowance, 0) + NVL (hra_adj, 0)
                ) house_rent_allowance,
            SUM
               (NVL (house_rent_allowance_arrear, 0)
               ) house_rent_allowance_arrear,
            SUM (NVL (cca, 0)) cca, SUM (NVL (cca_arrear, 0)) cca_arrear,
            SUM (NVL (sbihf_subsidy, 0)) sbihf_subsidy,
            SUM (NVL (sbihf_howrah_subsidy, 0)) sbihf_howrah_subsidy,
            SUM (NVL (hdfc_subsidy, 0)) hdfc_subsidy,
            SUM (NVL (miscelleneous_earnings, 0)) miscelleneous_earnings,
            SUM (  NVL (basic, 0)
                 + NVL (basic_arrear, 0)
                 + NVL (dpay, 0)
                 + NVL (house_rent_allowance, 0)
                 + NVL (house_rent_allowance_arrear, 0)
                 + NVL (dpay_arrear, 0)
                 + NVL (interim_allowance, 0)
                 + NVL (personal_pay, 0)
                 + NVL (personal_pay_arrear, 0)
                 + NVL (arrear_da, 0)
                 + NVL (deputation_allowance, 0)
                 + NVL (deputation_allowance_arrear, 0)
                 + NVL (ppay2, 0)
                 + NVL (ppay2_arrear, 0)
                 + NVL (site_allowance, 0)
                 + NVL (site_allowance_arrear, 0)
                 + NVL (hardship_allowance, 0)
                 + NVL (hardship_allowance_arrear, 0)
                 + NVL (cca, 0)
                 + NVL (cca_arrear, 0)
                 + NVL (sbihf_subsidy, 0)
                 + NVL (sbihf_howrah_subsidy, 0)
                 + NVL (hdfc_subsidy, 0)
                 + NVL (miscelleneous_earnings, 0)
                 + NVL (da, 0)
                 + NVL (hsal_adj, 0)
                 + NVL (hra_adj, 0)
                ) tot_earnings,
            SUM (NVL (pf, 0)) pf, SUM (NVL (epf, 0)) epf,
            SUM (NVL (pension_fund, 0)) pension_fund, SUM (NVL (vpf, 0)) vpf,
            SUM (NVL (lic, 0)) lic, SUM (NVL (ptax, 0)) ptax,
            SUM (NVL (itax, 0)) itax,
            SUM (NVL (company_accomodation, 0)) company_accomodation,
            SUM (NVL (festival_advance_deduction, 0)
                ) festival_advance_deduction,
            SUM (NVL (cooperative_deduction, 0)) cooperative_deduction,
            SUM (NVL (car_loan_interest, 0)) car_loan_interest,
            SUM (NVL (car_loan_deduction, 0)) car_loan_deduction,
            SUM (NVL (car_repair_loan_interest, 0)) car_repair_loan_interest,
            SUM (NVL (officer_car_repair_loan, 0)) officer_car_repair_loan,
            SUM
               (NVL (officer_sundry_laon_interest, 0)
               ) officer_sundry_laon_interest,
            SUM
               (NVL (officer_sundry_loan_deduction, 0)
               ) officer_sundry_loan_deduction,
            SUM
               (NVL (company_housing_loan_interest, 0)
               ) company_housing_loan_interest,
            SUM (NVL (company_housing_loan, 0)) company_housing_loan,
            SUM (NVL (sbihf, 0)) sbihf, SUM (NVL (sbi_howrah, 0)) sbi_howrah,
            SUM (NVL (hdfc, 0)) hdfc,
            SUM (NVL (furniture_loan_interest, 0)) furniture_loan_interest,
            SUM (NVL (furniture_loan, 0)) furniture_loan,
            SUM (NVL (pf_loan, 0)) pf_loan,
            SUM (NVL (recreation_club_deduction, 0))
                                                    recreation_club_deduction,
            SUM (NVL (hire_fixed_assests, 0)) hire_fixed_assests,
            SUM (NVL (salary_advance_deduction, 0)) salary_advance_deduction,
            SUM (NVL (car_expense_recovery, 0)) car_expense_recovery,
            SUM (NVL (personal_expense_recovery, 0))
                                                    personal_expense_recovery,
            SUM (NVL (income_tax_arrear, 0)) income_tax_arrear,
            SUM (NVL (officer_tiffin, 0)) officer_tiffin, SUM (NVL (rd, 0))
                                                                           rd,
            SUM (NVL (donation, 0)) donation,
            SUM (NVL (miscelleneous_deduction, 0)) miscelleneous_deduction,
            SUM (NVL (coin_carryover_april, 0)) coin_carryover_april,
            --bnr_coin_cf_calc (period, assignment_id) coin_carryover,
            0 coin_carryover,
            SUM (NVL (arrears_pt, 0)) arrears_pt,
            SUM (NVL (basic_adjustment, 0)) basic_adjustment,
            SUM
               (NVL (car_loan_deduction_adjustment, 0)
               ) car_loan_deduction_adjustment,
            SUM (NVL (stat_pf_arrear, 0)) stat_pf_arrear,
            SUM (NVL (vol_pf_arrear, 0)) vol_pf_arrear,
            SUM (NVL (pf_arrear_adj, 0)) pf_arrear_adj,
            SUM (NVL (vpf_arrear_adj, 0)) vpf_arrear_adj,
            SUM (  NVL (pf, 0)
                 + NVL (vpf, 0)
                 + NVL (lic, 0)
                 + NVL (ptax, 0)
                 + NVL (itax, 0)
                 + NVL (company_accomodation, 0)
                 + NVL (festival_advance_deduction, 0)
                 + NVL (cooperative_deduction, 0)
                 + NVL (car_loan_interest, 0)
                 + NVL (car_loan_deduction, 0)
                 + NVL (car_repair_loan_interest, 0)
                 + NVL (officer_car_repair_loan, 0)
                 + NVL (officer_sundry_laon_interest, 0)
                 + NVL (officer_sundry_loan_deduction, 0)
                 + NVL (company_housing_loan_interest, 0)
                 + NVL (company_housing_loan, 0)
                 + NVL (sbihf, 0)
                 + NVL (sbi_howrah, 0)
                 + NVL (hdfc, 0)
                 + NVL (furniture_loan_interest, 0)
                 + NVL (furniture_loan, 0)
                 + NVL (pf_loan, 0)
                 + NVL (recreation_club_deduction, 0)
                 + NVL (hire_fixed_assests, 0)
                 + NVL (salary_advance_deduction, 0)
                 + NVL (car_expense_recovery, 0)
                 + NVL (personal_expense_recovery, 0)
                 + NVL (income_tax_arrear, 0)
                 + NVL (officer_tiffin, 0)
                 + NVL (rd, 0)
                 + NVL (donation, 0)
                 + NVL (miscelleneous_deduction, 0)
                 + NVL (coin_carryover_april, 0)
                 --+ bnr_coin_cf_calc (period, assignment_id)
                 + NVL (arrears_pt, 0)
                 + NVL (basic_adjustment, 0)
                 + NVL (car_loan_deduction_adjustment, 0)
                 + NVL (stat_pf_arrear, 0)
                 + NVL (vol_pf_arrear, 0)
                 + NVL (pf_arrear_adj, 0)
                 + NVL (vpf_arrear_adj, 0)
                ) tot_deductions,
            SUM
               (  NVL (pf, 0)
                + NVL (vpf, 0)
                + NVL (lic, 0)
                + NVL (ptax, 0)
                + NVL (company_accomodation, 0)
                + NVL (festival_advance_deduction, 0)
                + NVL (cooperative_deduction, 0)
                + NVL (car_loan_interest, 0)
                + NVL (car_loan_deduction, 0)
                + NVL (car_repair_loan_interest, 0)
                + NVL (officer_car_repair_loan, 0)
                + NVL (officer_sundry_laon_interest, 0)
                + NVL (officer_sundry_loan_deduction, 0)
                + NVL (company_housing_loan_interest, 0)
                + NVL (company_housing_loan, 0)
                + NVL (sbihf, 0)
                + NVL (sbi_howrah, 0)
                + NVL (hdfc, 0)
                + NVL (furniture_loan_interest, 0)
                + NVL (furniture_loan, 0)
                + NVL (pf_loan, 0)
                + NVL (recreation_club_deduction, 0)
                + NVL (hire_fixed_assests, 0)
                + NVL (salary_advance_deduction, 0)
                + NVL (car_expense_recovery, 0)
                + NVL (personal_expense_recovery, 0)
                + NVL (income_tax_arrear, 0)
                + NVL (officer_tiffin, 0)
                + NVL (rd, 0)
                + NVL (donation, 0)
                + NVL (miscelleneous_deduction, 0)
                + NVL (coin_carryover_april, 0)
                --+ bnr_coin_cf_calc (period, assignment_id)
                + NVL (arrears_pt, 0)
                + NVL (basic_adjustment, 0)
                + NVL (car_loan_deduction_adjustment, 0)
                + NVL (stat_pf_arrear, 0)
                + NVL (vol_pf_arrear, 0)
                + NVL (pf_arrear_adj, 0)
                + NVL (vpf_arrear_adj, 0)
               ) tot_deductions_wo_income_tax,
              SUM (  NVL (basic, 0)
                   + NVL (basic_arrear, 0)
                   + NVL (dpay, 0)
                   + NVL (house_rent_allowance, 0)
                   + NVL (house_rent_allowance_arrear, 0)
                   + NVL (dpay_arrear, 0)
                   + NVL (interim_allowance, 0)
                   + NVL (personal_pay, 0)
                   + NVL (personal_pay_arrear, 0)
                   + NVL (arrear_da, 0)
                   + NVL (deputation_allowance, 0)
                   + NVL (deputation_allowance_arrear, 0)
                   + NVL (ppay2, 0)
                   + NVL (ppay2_arrear, 0)
                   + NVL (site_allowance, 0)
                   + NVL (site_allowance_arrear, 0)
                   + NVL (hardship_allowance, 0)
                   + NVL (hardship_allowance_arrear, 0)
                   + NVL (cca, 0)
                   + NVL (cca_arrear, 0)
                   + NVL (sbihf_subsidy, 0)
                   + NVL (sbihf_howrah_subsidy, 0)
                   + NVL (hdfc_subsidy, 0)
                   + NVL (miscelleneous_earnings, 0)
                   + NVL (da, 0)
                   + NVL (hsal_adj, 0)
                   + NVL (hra_adj, 0)
                  )
            - SUM (  NVL (pf, 0)
                   + NVL (vpf, 0)
                   + NVL (lic, 0)
                   + NVL (ptax, 0)
                   + NVL (itax, 0)
                   + NVL (company_accomodation, 0)
                   + NVL (festival_advance_deduction, 0)
                   + NVL (cooperative_deduction, 0)
                   + NVL (car_loan_interest, 0)
                   + NVL (car_loan_deduction, 0)
                   + NVL (car_repair_loan_interest, 0)
                   + NVL (officer_car_repair_loan, 0)
                   + NVL (officer_sundry_laon_interest, 0)
                   + NVL (officer_sundry_loan_deduction, 0)
                   + NVL (company_housing_loan_interest, 0)
                   + NVL (company_housing_loan, 0)
                   + NVL (sbihf, 0)
                   + NVL (sbi_howrah, 0)
                   + NVL (hdfc, 0)
                   + NVL (furniture_loan_interest, 0)
                   + NVL (furniture_loan, 0)
                   + NVL (pf_loan, 0)
                   + NVL (recreation_club_deduction, 0)
                   + NVL (hire_fixed_assests, 0)
                   + NVL (salary_advance_deduction, 0)
                   + NVL (car_expense_recovery, 0)
                   + NVL (personal_expense_recovery, 0)
                   + NVL (income_tax_arrear, 0)
                   + NVL (officer_tiffin, 0)
                   + NVL (rd, 0)
                   + NVL (donation, 0)
                   + NVL (miscelleneous_deduction, 0)
                   + NVL (coin_carryover_april, 0)
                   -- + bnr_coin_cf_calc (period, assignment_id)
                   + NVL (arrears_pt, 0)
                   + NVL (basic_adjustment, 0)
                   + NVL (car_loan_deduction_adjustment, 0)
                   + NVL (stat_pf_arrear, 0)
                   + NVL (vol_pf_arrear, 0)
                   + NVL (pf_arrear_adj, 0)
                   + NVL (vpf_arrear_adj, 0)
                  ) net_pay,
              SUM (  NVL (basic, 0)
                   + NVL (basic_arrear, 0)
                   + NVL (dpay, 0)
                   + NVL (house_rent_allowance, 0)
                   + NVL (house_rent_allowance_arrear, 0)
                   + NVL (dpay_arrear, 0)
                   + NVL (interim_allowance, 0)
                   + NVL (personal_pay, 0)
                   + NVL (personal_pay_arrear, 0)
                   + NVL (arrear_da, 0)
                   + NVL (deputation_allowance, 0)
                   + NVL (deputation_allowance_arrear, 0)
                   + NVL (ppay2, 0)
                   + NVL (ppay2_arrear, 0)
                   + NVL (site_allowance, 0)
                   + NVL (site_allowance_arrear, 0)
                   + NVL (hardship_allowance, 0)
                   + NVL (hardship_allowance_arrear, 0)
                   + NVL (cca, 0)
                   + NVL (cca_arrear, 0)
                   + NVL (sbihf_subsidy, 0)
                   + NVL (sbihf_howrah_subsidy, 0)
                   + NVL (hdfc_subsidy, 0)
                   + NVL (miscelleneous_earnings, 0)
                   + NVL (da, 0)
                   + NVL (hsal_adj, 0)
                   + NVL (hra_adj, 0)
                  )
            - SUM (  NVL (pf, 0)
                   + NVL (vpf, 0)
                   + NVL (lic, 0)
                   + NVL (ptax, 0)
                   + NVL (company_accomodation, 0)
                   + NVL (festival_advance_deduction, 0)
                   + NVL (cooperative_deduction, 0)
                   + NVL (car_loan_interest, 0)
                   + NVL (car_loan_deduction, 0)
                   + NVL (car_repair_loan_interest, 0)
                   + NVL (officer_car_repair_loan, 0)
                   + NVL (officer_sundry_laon_interest, 0)
                   + NVL (officer_sundry_loan_deduction, 0)
                   + NVL (company_housing_loan_interest, 0)
                   + NVL (company_housing_loan, 0)
                   + NVL (sbihf, 0)
                   + NVL (sbi_howrah, 0)
                   + NVL (hdfc, 0)
                   + NVL (furniture_loan_interest, 0)
                   + NVL (furniture_loan, 0)
                   + NVL (pf_loan, 0)
                   + NVL (recreation_club_deduction, 0)
                   + NVL (hire_fixed_assests, 0)
                   + NVL (salary_advance_deduction, 0)
                   + NVL (car_expense_recovery, 0)
                   + NVL (personal_expense_recovery, 0)
                   + NVL (income_tax_arrear, 0)
                   + NVL (officer_tiffin, 0)
                   + NVL (rd, 0)
                   + NVL (donation, 0)
                   + NVL (miscelleneous_deduction, 0)
                   + NVL (coin_carryover_april, 0)
                   --+ bnr_coin_cf_calc (period, assignment_id)
                   + NVL (arrears_pt, 0)
                   + NVL (basic_adjustment, 0)
                   + NVL (car_loan_deduction_adjustment, 0)
                   + NVL (stat_pf_arrear, 0)
                   + NVL (vol_pf_arrear, 0)
                   + NVL (pf_arrear_adj, 0)
                   + NVL (vpf_arrear_adj, 0)
                  ) net_pay_wo_income_tax
       FROM (SELECT ppa.action_type, papf.employee_number, papf.full_name,
                    ppf.payroll_name, papf.per_information8 pfno,
                    papf.per_information13 epsno, paa.assignment_action_id,
                    paaf.assignment_id, paaf.payroll_id, ppa.time_period_id,
                    TO_CHAR (ppa.effective_date, 'MON-YYYY') period,
                    ppa.business_group_id, ppa.request_id,
                    DECODE (prr1.element_name,
                            'Officer_Basic', prrv1.result_value
                           ) basic,
                    DECODE (prr1.element_name,
                            'Officer_Basic_Arrear', prrv1.result_value
                           ) basic_arrear,
                    DECODE (prr1.element_name,
                            'Officer_DPay', prrv1.result_value
                           ) dpay,
                    DECODE (prr1.element_name,
                            'Officer_DPay_Arrear', prrv1.result_value
                           ) dpay_arrear,
                    DECODE (prr1.element_name,
                            'Officer_Interim_Allowance', prrv1.result_value
                           ) interim_allowance,
                    DECODE (prr1.element_name,
                            'Officer_Personal_Pay', prrv1.result_value
                           ) personal_pay,
                    DECODE
                          (prr1.element_name,
                           'Officer_Personal_Pay_Arrear', prrv1.result_value
                          ) personal_pay_arrear,
                    DECODE (prr1.element_name,
                            'Officer_Dearness_Allowance', prrv1.result_value
                           ) da,
                    DECODE (prr1.element_name,
                            'Officer_Dearness_Allowance_Arrear', prrv1.result_value
                           ) arrear_da,
                    DECODE
                        (prr1.element_name,
                         'Officer_Deputation_Allowance', prrv1.result_value
                        ) deputation_allowance,
                    DECODE
                       (prr1.element_name,
                        'Officer_Deputation_Allowance_Arrear', prrv1.result_value
                       ) deputation_allowance_arrear,
                    DECODE (prr1.element_name,
                            'Officer_PPay2', prrv1.result_value
                           ) ppay2,
                    DECODE (prr1.element_name,
                            'Officer_PPay2_Arrear', prrv1.result_value
                           ) ppay2_arrear,
                    DECODE (prr1.element_name,
                            'Officer_Site_Allowance', prrv1.result_value
                           ) site_allowance,
                    DECODE
                       (prr1.element_name,
                        'Officer_Site_Allowance_Arrear', prrv1.result_value
                       ) site_allowance_arrear,
                    DECODE (prr1.element_name,
                            'Officer_Hardship_Allowance', prrv1.result_value
                           ) hardship_allowance,
                    DECODE
                       (prr1.element_name,
                        'Officer_Hardship_Allowance_Arrear', prrv1.result_value
                       ) hardship_allowance_arrear,
                    DECODE
                        (prr1.element_name,
                         'Officer_House_Rent_Allowance', prrv1.result_value
                        ) house_rent_allowance,
                    DECODE
                       (prr1.element_name,
                        'Officer_House_Rent_Allowance_Arrear', prrv1.result_value
                       ) house_rent_allowance_arrear,
                    DECODE (prr1.element_name,
                            'Officer_CCA', prrv1.result_value
                           ) cca,
                    DECODE (prr1.element_name,
                            'Officer_CCA_Arrear', prrv1.result_value
                           ) cca_arrear,
                    DECODE (prr1.element_name,
                            'Officer_SBIHF_Subsidy', prrv1.result_value
                           ) sbihf_subsidy,
                    DECODE
                          (prr1.element_name,
                           'Officer_SBI_Howrah_Subsidy', prrv1.result_value
                          ) sbihf_howrah_subsidy,
                    DECODE (prr1.element_name,
                            'Officer_HDFC_Subsidy', prrv1.result_value
                           ) hdfc_subsidy,
                    DECODE
                       (prr1.element_name,
                        'Officer_Miscelleneous_Earnings', prrv1.result_value
                       ) miscelleneous_earnings,
                    DECODE (prr1.element_name,
                            'Employee Statutory PF Contribution', prrv1.result_value
                           ) pf,
                    DECODE (prr1.element_name,
                            'Employer PF Contribution', prrv1.result_value
                           ) epf,
                    DECODE (prr1.element_name,
                            'EPS Contribution', prrv1.result_value
                           ) pension_fund,
                    DECODE (prr1.element_name,
                            'Employee Voluntary PF Contribution', prrv1.result_value
                           ) vpf,
                    DECODE (prr1.element_name,
                            'Officer_LIC', prrv1.result_value
                           ) lic,
                    DECODE (prr1.element_name,
                            'Professional Tax Deduction', prrv1.result_value
                           ) ptax,
                    DECODE (prr1.element_name,
                            'Income Tax', prrv1.result_value
                           ) itax,
                    DECODE
                        (prr1.element_name,
                         'Officer_Company_Accomodation', prrv1.result_value
                        ) company_accomodation,
                    DECODE
                       (prr1.element_name,
                        'Officer_Festival_Advance_Deduction', prrv1.result_value
                       ) festival_advance_deduction,
                    DECODE
                       (prr1.element_name,
                        'Officer_Cooperative_Deduction', prrv1.result_value
                       ) cooperative_deduction,
                    DECODE
                       (prr1.element_name,
                        'Officer_Car_Loan_Interest_Deduction', prrv1.result_value
                       ) car_loan_interest,
                    DECODE (prr1.element_name,
                            'Officer_Car_Loan_Deduction', prrv1.result_value
                           ) car_loan_deduction,
                    DECODE
                       (prr1.element_name,
                        'Officer_Car_Repair_Loan_Interest_Deduction', prrv1.result_value
                       ) car_repair_loan_interest,
                    DECODE
                       (prr1.element_name,
                        'Officer_Car_Repair_Loan_Deduction', prrv1.result_value
                       ) officer_car_repair_loan,
                    DECODE
                       (prr1.element_name,
                        'Officer_Sundry_Loan_Interest_Deduction', prrv1.result_value
                       ) officer_sundry_laon_interest,
                    DECODE
                       (prr1.element_name,
                        'Officer_Sundry_Loan_Deduction', prrv1.result_value
                       ) officer_sundry_loan_deduction,
                    DECODE
                       (prr1.element_name,
                        'Officer_Company_Housing_Loan_Interest_Deduction', prrv1.result_value
                       ) company_housing_loan_interest,
                    DECODE
                       (prr1.element_name,
                        'Officer_Company_Housing_Loan_Deduction', prrv1.result_value
                       ) company_housing_loan,
                    DECODE (prr1.element_name,
                            'Officer_SBIHF', prrv1.result_value
                           ) sbihf,
                    DECODE (prr1.element_name,
                            'Officer_SBI_Howrah', prrv1.result_value
                           ) sbi_howrah,
                    DECODE (prr1.element_name,
                            'Officer_HDFC', prrv1.result_value
                           ) hdfc,
                    DECODE
                       (prr1.element_name,
                        'Officer_Furniture_Loan_Interest_Deduction', prrv1.result_value
                       ) furniture_loan_interest,
                    DECODE
                          (prr1.element_name,
                           'Officer_Furniture_Loan_Deduction', prrv1.result_value
                          ) furniture_loan,
                    DECODE (prr1.element_name,
                            'Officer_PF_Loan_Deduction', prrv1.result_value
                           ) pf_loan,
                    DECODE
                        (prr1.element_name,
                         'Officer_Recreation_Club', prrv1.result_value
                        ) recreation_club_deduction,
                    DECODE (prr1.element_name,
                            'Officer_Hire_Fixed_Assests', prrv1.result_value
                           ) hire_fixed_assests,
                    DECODE
                       (prr1.element_name,
                        'Officer_Salary_Advance_Deduction', prrv1.result_value
                       ) salary_advance_deduction,
                    DECODE
                        (prr1.element_name,
                         'Officer_Car_Expense_Recovery', prrv1.result_value
                        ) car_expense_recovery,
                    DECODE
                       (prr1.element_name,
                        'Officer_Personal_Expense_Recovery', prrv1.result_value
                       ) personal_expense_recovery,
                    DECODE (prr1.element_name,
                            'Officer_Income_Tax_Arrear', prrv1.result_value
                           ) income_tax_arrear,
                    DECODE (prr1.element_name,
                            'Officer_Tiffin', prrv1.result_value
                           ) officer_tiffin,
                    DECODE (prr1.element_name,
                            'Officer_Recurring_Deposit', prrv1.result_value
                           ) rd,
                    DECODE (prr1.element_name,
                            'Officer_Donation', prrv1.result_value
                           ) donation,
                    DECODE
                       (prr1.element_name,
                        'Officer_Miscelleneous_Deduction', prrv1.result_value
                       ) miscelleneous_deduction,
                    DECODE
                        (prr1.element_name,
                         'Officer_Coin_Carryover_April', prrv1.result_value
                        ) coin_carryover_april,
                    NULL coin_carryover,
                    DECODE (prr1.element_name,
                            'Arrears Professional Tax', prrv1.result_value
                           ) arrears_pt,
                    DECODE (prr1.element_name,
                            'Officer_Basic_Adjustment', prrv1.result_value
                           ) basic_adjustment,
                    DECODE
                       (prr1.element_name,
                        'Officer_Car_Loan_Deduction_Adjustment', prrv1.result_value
                       ) car_loan_deduction_adjustment,
                    DECODE (prr1.element_name,
                            'Officer_Hardship_Allowance_Adjustment', prrv1.result_value
                           ) hsal_adj,
                    DECODE
                          (prr1.element_name,
                           'Officer_House_Rent_Allowance_Adjustment', prrv1.result_value
                          ) hra_adj,
                    DECODE
                       (prr1.element_name,
                        'Officer_Professional_Tax_Arrear_Adjustment', prrv1.result_value
                       ) ptax_adj,
                    DECODE (prr1.element_name,
                            'Officer_Net_Pay_Adjustment', prrv1.result_value
                           ) net_pay_adj,
                    DECODE (prr1.element_name,
                            'Arrears Employee Statutory PF', prrv1.result_value
                           ) stat_pf_arrear,
                    DECODE (prr1.element_name,
                            'Arrears Employee Voluntary PF', prrv1.result_value
                           ) vol_pf_arrear,
                    DECODE (prr1.element_name,
                            'Officer_PF_Arrear_Adjustment', prrv1.result_value
                           ) pf_arrear_adj,
                    DECODE (prr1.element_name,
                            'Officer_VPF_Arrear_Adjustment', prrv1.result_value
                           ) vpf_arrear_adj,
                    DECODE (prr1.element_name,
                            'Officer_Income_Tax_Adjustment', prrv1.result_value
                           ) it_adjustment
               FROM per_all_people_f papf,
                    per_all_assignments_f paaf,
                    pay_assignment_actions paa,
                    pay_payroll_actions ppa,
                    pay_payrolls_f ppf,
                    (SELECT rrs.assignment_action_id, rrs.run_result_id,
                            etytl.element_name
                       FROM pay_run_results rrs, pay_element_types_f_tl etytl
                      WHERE rrs.element_type_id = etytl.element_type_id
                        AND etytl.LANGUAGE = USERENV ('LANG')) prr1,
                    (SELECT rrv.run_result_id, invtl.NAME, rrv.result_value
                       FROM pay_input_values_f_tl invtl,
                            pay_run_result_values rrv
                      WHERE invtl.LANGUAGE = USERENV ('LANG')
                        AND rrv.input_value_id = invtl.input_value_id) prrv1
              WHERE TRUNC (SYSDATE) BETWEEN papf.effective_start_date
                                        AND papf.effective_end_date
                --AND papf.current_employee_flag = 'Y'
                AND paaf.person_id = papf.person_id
                AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
                                        AND paaf.effective_end_date
                AND paaf.primary_flag = 'Y'
                AND paa.assignment_id = paaf.assignment_id
                AND ppa.payroll_action_id = paa.payroll_action_id
                AND ppa.action_type IN ('R', 'Q')
                AND paa.run_type_id = 63                         --IN (61, 63)
                AND ppf.payroll_id = ppa.payroll_id
                AND ppf.payroll_id = 61
                AND TRUNC (SYSDATE) BETWEEN ppf.effective_start_date
                                        AND ppf.effective_end_date
                AND prr1.assignment_action_id(+) = paa.assignment_action_id
                AND prrv1.run_result_id(+) = prr1.run_result_id
                --AND TO_CHAR (ppa.effective_date, 'MON-YYYY') = 'JAN-2010'
                AND prrv1.NAME = 'Pay Value')
   GROUP BY employee_number,
            full_name,
            payroll_name,
            period,
            business_group_id,
            request_id,
            pfno,
            epsno,
            assignment_action_id,
            assignment_id,
            payroll_id,
            time_period_id,
            action_type,
            coin_carryover;