Wednesday, September 3, 2014

Terminate Contingent Worker - HRMS APIs

--
declare
   --
   --Common Variables
   l_terminate_cwk_flag          varchar2(1) := 'N';
   l_terminate_msg               varchar2(600);
   l_person_id                   number := 123456;
   l_le_terminate_cwk_exception  exception;
 
   --- DECLARE variables for hr_contingent_worker_api.actual_termination_placement
   --- IN variables
   l_effective_date              date := trunc(sysdate);
   l_termination_reason          per_periods_of_placement.leaving_reason%type := 'AGE_REACHED';
   l_person_type_id              per_person_types.person_type_id%type := 1120;
   l_period_of_service_id        per_periods_of_placement.period_of_service_id%type;
   l_actual_termination_date     per_periods_of_placement.actual_termination_date%type :=trunc(sysdate);
   l_last_standard_process_date  per_periods_of_placement.last_standard_process_date%type := trunc(sysdate+10);
   l_object_version_number       per_periods_of_placement.object_version_number%type;
   l_start_date                  per_periods_of_placement.date_start%type;
   l_notif_term_date             date;

   --- OUT variables
   l_supervisor_warning         boolean := false;
   l_event_warning              boolean := false;
   l_interview_warning          boolean := false;
   l_review_warning             boolean := false;
   l_recruiter_warning          boolean := false;
   l_asg_future_changes_warning boolean := false;
   l_entries_changed_warning    varchar2(300);
   l_pay_proposal_warning       boolean := false;
   l_dod_warning                boolean := false;

   --- DECLARE variables for hr_contingent_worker_api.final_process_placement
   --- IN variables
   l_final_process_date             per_periods_of_service.final_process_date%type;
 
   --- OUT variables
   l_org_now_no_manager_warning     boolean := false;
   --
begin
   --
   begin
      select pos.period_of_placement_id, pos.object_version_number, date_start
        into l_period_of_service_id, l_object_version_number, l_start_date
        from per_periods_of_placement pos
       where pos.person_id = l_person_id;
     
   exception                                                        
      when others then
         l_terminate_msg  := 'Error while selecting cwk details : '||substr(sqlerrm,1,150);
         raise l_le_terminate_cwk_exception;
   end;
   --
   savepoint terminate_cwk_s1;  
   --
   begin
      /*
      This API covers the first step in terminating a period of placement and
      all current assignments for a cwk, identified by person_id and date_start.    
      You can use the API to set the actual termination date, the last standard
      process date, the new assignment status and the new person type
      */
       hr_contingent_worker_api.actual_termination_placement
                      (p_validate                      => false                
                      ,p_effective_date                => l_effective_date        
                      ,p_person_id                     => l_person_id          
                      ,p_date_start                    => l_start_date
                      ,p_person_type_id                => l_person_type_id        
                      ,p_actual_termination_date       => l_actual_termination_date
                      ,p_termination_reason            => l_termination_reason
                      --In/Out
                      ,p_object_version_number         => l_object_version_number                      
                      ,p_last_standard_process_date    => l_last_standard_process_date
                      --Out
                      ,p_supervisor_warning               => l_supervisor_warning  
                      ,p_event_warning                    => l_event_warning    
                      ,p_interview_warning                => l_interview_warning  
                      ,p_review_warning                   => l_review_warning    
                      ,p_recruiter_warning                => l_recruiter_warning      
                      ,p_asg_future_changes_warning       => l_asg_future_changes_warning
                      ,p_entries_changed_warning          => l_entries_changed_warning  
                      ,p_pay_proposal_warning             => l_pay_proposal_warning    
                      ,p_dod_warning                      => l_dod_warning            
                      );

         if l_object_version_number is null then
            l_terminate_cwk_flag := 'N';
            l_terminate_msg      := 'Warning validating API: hr_contingent_worker_api.actual_termination_placement';
            raise l_le_terminate_cwk_exception;
         end if;

         l_terminate_cwk_flag := 'Y';
   exception
      when others then
         l_terminate_msg  := 'Error validating API: hr_contingent_worker_api.actual_termination_placement : '||substr(sqlerrm,1,150);
         raise l_le_terminate_cwk_exception;
   end; --hr_contingent_worker_api.actual_termination_placement

   if l_terminate_cwk_flag = 'Y' then
      begin
         /*
         This API covers the second step in terminating a period of placement and
         all current assignments for an cwk.  It updates the period of placement
         details and date-effectively deletes all the contingent worker assignments
         as of the final process date.
         */
         hr_contingent_worker_api.final_process_placement (
                              p_validate                      => false
                             ,p_person_id                     => l_person_id
                             ,p_date_start                    => l_start_date
                             --In/Out
                             ,p_object_version_number         => l_object_version_number
                             ,p_final_process_date            => l_final_process_date
                             --Out
                             ,p_org_now_no_manager_warning    => l_org_now_no_manager_warning
                             ,p_asg_future_changes_warning    => l_asg_future_changes_warning
                             ,p_entries_changed_warning       => l_entries_changed_warning );
      exception
         when others then
            l_terminate_msg := 'Error validating API: hr_contingent_worker_api.final_process_placement : '||substr(sqlerrm,1,150);
            raise l_le_terminate_cwk_exception;
      end; --hr_contingent_worker_api.final_process_placement

   end if;                                  
   --
   commit;
   --
exception    
   when l_le_terminate_cwk_exception then
      dbms_output.put_line(l_terminate_msg);
      rollback to terminate_cwk_s1;
   when others then
      dbms_output.put_line('Terminate CWK. Error OTHERS while validating: '||sqlerrm);
      rollback to terminate_cwk_s1;
end;
--

No comments:

Post a Comment