Saturday, September 6, 2014

HRMS API: Create Personal Pay Method

DECLARE
   p_effective_date               DATE;
   p_percentage                   NUMBER          DEFAULT NULL;
   p_amount                       NUMBER          DEFAULT NULL;
   p_priority                     NUMBER          DEFAULT NULL;

   p_segment1                     VARCHAR2 (1000) := NULL;
   p_segment2                     VARCHAR2 (1000) := NULL;
   p_segment3                     VARCHAR2 (1000) := NULL;
   p_personal_payment_method_id   NUMBER;
   p_external_account_id          NUMBER;
   p_object_version_number        NUMBER;
   p_effective_start_date         DATE;
   p_effective_end_date           DATE;
   p_comment_id                   NUMBER;
   v_err                          VARCHAR2 (1000);
BEGIN
   FOR i IN (SELECT *
               FROM xx_upload_bank_accounts
              WHERE assignment_id IS NOT NULL AND valid_flag = 'N')
   LOOP
      BEGIN
         SELECT ass.effective_start_date
           INTO p_effective_date
           FROM per_all_assignments_f ass
          WHERE ass.assignment_id = i.assignment_id
            AND effective_end_date = TO_DATE ('31/12/4712', 'DD/MM/YYYY');
         p_percentage := 100;
         p_priority := 1;
         IF i.org_payment_method_name = 'Cash'
         THEN
            p_segment1 := NULL;
            p_segment2 := NULL;
            p_segment3 := NULL;
         ELSE
            p_segment1 := i.bank_name;
            p_segment2 := '000';
            p_segment3 := i.account_number;
         END IF;
         BEGIN
            hr_personal_pay_method_api.create_personal_pay_method
               (p_effective_date                  => p_effective_date,
                p_assignment_id                   => i.assignment_id,
                p_org_payment_method_id           => i.org_payment_method_id,
                p_percentage                      => p_percentage,
                p_amount                          => p_amount,
                p_priority                        => p_priority,
                p_territory_code                  => 'EG',
                p_segment1                        => p_segment1,
                p_segment2                        => p_segment2,
                p_segment3                        => p_segment3,
                p_personal_payment_method_id      => p_personal_payment_method_id,
                p_external_account_id             => p_external_account_id,
                p_object_version_number           => p_object_version_number,
                p_effective_start_date            => p_effective_start_date,
                p_effective_end_date              => p_effective_end_date,
                p_comment_id                      => p_comment_id
               );
            DBMS_OUTPUT.put_line (p_personal_payment_method_id);
            UPDATE xx_upload_bank_accounts xx
               SET xx.valid_flag = 'Y',
                   err = NULL
             WHERE xx.employee_number = i.employee_number;
         EXCEPTION
            WHEN OTHERS
            THEN
               DBMS_OUTPUT.put_line (SQLERRM);
               v_err := NULL;
               v_err := SQLERRM;
               p_segment1 := NULL;
               p_segment2 := NULL;
               p_segment3 := NULL;
               UPDATE xx_upload_bank_accounts xx
                  SET xx.valid_flag = 'N',
                      xx.err = v_err
                WHERE xx.employee_number = i.employee_number;
         END;
      EXCEPTION
         WHEN OTHERS
         THEN
            p_effective_date := NULL;
            UPDATE xx_upload_bank_accounts xx
               SET xx.valid_flag = 'N',
                   xx.err = 'No Effective date found for the Assignment'
             WHERE xx.employee_number = i.employee_number;
      END;
   END LOOP;
   COMMIT;
END;
--PAY_PERSONAL_PAYMENT_METHODS_F
--PAY_PAYMENT_TYPES
--pay_external_accounts