Search This Blog

Monday, January 20, 2020

Oracle Apps R12 Get_Net_Accrual Technical Details

--------------------------------------------------------------------*/
DECLARE
P_Assignment_ID                   Number := 22432;
P_Plan_ID                          Number := 61;
P_Payroll_ID                       Number:= 61;
P_Business_Group_ID               Number := 81;
P_Assignment_Action_ID             Number := -1;
P_Calculation_Date                 Date := TO_DATE('31-DEC-2019');
P_Accrual_Start_Date               Date;-- default null
P_Accrual_Latest_Balance          Number;-- default null
P_Calling_Point                   Varchar2(20):= 'FRM';
P_Start_Date                      Date;
P_End_Date                       Date;
P_Accrual_End_Date               Date;
P_Accrual                        Number;
P_Net_Entitlement               Number;
g_package  varchar2(50) := '  per_accrual_calc_functions.';

  l_proc        varchar2(72) := g_package||'Get_Net_Accrual';
  l_absence     number := 0;   --changed for bug 6914353
  l_accrual     number;
  l_other       number := 0;   --changed for bug 6914353
  l_carryover   number;
  l_start_date  date;
  l_end_date    date;
  l_accrual_end_date date;
  l_defined_balance_id number;

  l_atd         date; --added for bug 6418568

  cursor c_get_balance is
  select defined_balance_id
  from pay_accrual_plans
  where accrual_plan_id = p_plan_id;

  --added for bug 6418568
  cursor c_get_atd is
   select nvl(pps.ACTUAL_TERMINATION_DATE,to_date('31/12/4712','dd/mm/yyyy'))
   from per_periods_of_service pps, per_all_assignments_f paaf
   where paaf.person_id = pps.person_id
    and paaf.period_of_service_id = pps.period_of_service_id
    and paaf.Assignment_ID = P_Assignment_ID
    and P_Calculation_Date between paaf.effective_start_date and paaf.effective_end_date;


begin


  open c_get_balance;
  fetch c_get_balance into l_defined_balance_id;
  close c_get_balance;

  if p_calling_point = 'BP' and
     l_defined_balance_id is not null and
     p_assignment_action_id <> -1 then
  --
    /* Procedure called from batch process, so
       get latest balance. */

    p_net_entitlement := pay_balance_pkg.get_value(
                            p_defined_balance_id => l_defined_balance_id
                           ,p_assignment_action_id => p_assignment_action_id
                            );
  --
  else
  --

    per_accrual_calc_functions.get_accrual(p_assignment_id => p_assignment_id,
                p_plan_id => p_plan_id,
                p_calculation_date => p_calculation_date,
                p_business_group_id => p_business_group_id,
        p_payroll_id => p_payroll_id,
                p_assignment_action_id => p_assignment_action_id,
                p_accrual_start_date => p_accrual_start_date,
                p_accrual_latest_balance => p_accrual_latest_balance,
                p_start_date => l_start_date,
                p_end_date => l_end_date,
        p_accrual_end_date => l_accrual_end_date,
                p_accrual => l_accrual);

    --start changes for bug 6418568
    open c_get_atd;
    fetch c_get_atd into l_atd;
    close c_get_atd;

    if l_accrual_end_date is not null then
    --
     l_absence := per_accrual_calc_functions.get_absence(p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
     p_start_date => l_start_date,
     p_calculation_date => l_end_date);

     l_other := per_accrual_calc_functions.get_other_net_contribution(
     p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
                             p_start_date => l_start_date,
                             p_calculation_date => l_end_date
     );
    else
    --
     if l_atd >= P_Calculation_Date then
--
      l_absence := per_accrual_calc_functions.get_absence(p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
     p_start_date => l_start_date,
     p_calculation_date => l_end_date);

      l_other := per_accrual_calc_functions.get_other_net_contribution(
     p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
                             p_start_date => l_start_date,
                             p_calculation_date => l_end_date
     );
--
     end if;
    --
    end if;
    --end changes for bug 6418568

l_carryover :=0;  -- 12880652
    l_carryover := per_accrual_calc_functions.get_carry_over(
                             p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
                             p_start_date => l_start_date,
                             p_calculation_date => l_end_date);
-- 12880652

if P_Calculation_Date > l_atd and l_carryover <> 0 then
     l_other := per_accrual_calc_functions.get_other_net_contribution(
  p_assignment_id => p_assignment_id,
        p_plan_id => p_plan_id,
                           p_start_date => l_start_date,
                           p_calculation_date => l_end_date
       );

l_absence := per_accrual_calc_functions.get_absence(p_assignment_id => p_assignment_id,
                             p_plan_id => p_plan_id,
     p_start_date => l_start_date,
     p_calculation_date => l_end_date); -- added new 12880652


 end if;
-- 12880652

    --
    -- Set up values in the return parameters.
    --
    DBMS_OUTPUT.PUT_LINE( 'l_accrual->'||l_accrual||'->l_absence->'||l_absence||'--l_other->'|| l_other ||'-CARRYOVER-'|| l_carryover);
    p_net_entitlement := l_accrual - l_absence + l_other + l_carryover;
    p_accrual := l_accrual;
    p_start_date := l_start_date;
    p_end_date := l_end_date;
    p_accrual_end_date := l_accrual_end_date;
  --
  end if;

  --
 

--
end ;
--