Oracle EBS AP 付款界面 撤销逻辑代码

Oracle EBS AP 付款界面 撤销逻辑代码

PACKAGE BODY PAY_ACTIONS_VOID IS

PROCEDURE Void(event Varchar2) IS

  l_amount NUMBER;
  l_check_prepay_unapply VARCHAR2(1) := 'N';

BEGIN
  if (event = 'PRE-FORM') then
    -- Enable/disable the void option according to function
    -- security.
    --
    if (:parameter.ap_apxpawkb_void = 'Y') then
      Hide_View('PAY_ACTIONS_HIDE_VOID');
    else
      Show_View('PAY_ACTIONS_HIDE_VOID');
    end if; 

  elsif (event = 'PRE-RECORD') then
    -- To enable or disable the void option check both the status of the
    -- payment and whether the function is allowed.
    --

    if (:parameter.ap_apxpawkb_void = 'Y') then
      if (:parameter.payment_status in ('ISSUED','NEGOTIABLE','STOP INITIATED')) then

        -- bug 1973908  For a payment on a prepayment, get sum of amounts of 
        -- invoices applied on that prepayment. You can void payment only if sum=0.

        BEGIN
        SELECT SUM(NVL(aid.amount,0))
        INTO   l_amount
        FROM   ap_invoice_payments aip,ap_invoices ai,
               ap_invoice_distributions aid,ap_invoice_distributions aid2
        WHERE  aip.check_id                = :pay_sum_folder.check_id
        AND    ai.invoice_id               = aip.invoice_id
        AND    ai.invoice_type_lookup_code = 'PREPAYMENT'
        AND    ai.invoice_id               = aid2.invoice_id
        AND    aid2.line_type_lookup_code  = 'ITEM'
        AND    aid.prepay_distribution_id  = aid2.invoice_distribution_id;

        EXCEPTION 
          WHEN  NO_DATA_FOUND
          THEN  l_amount := 0; 
        END;

        IF (NVL(l_amount,0) != 0) THEN
          App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                         ENABLED, PROPERTY_OFF);
        ELSE
          -- bug9441420 we would not allow the voiding of a check paying a 
          -- check for which the prepayment unapplication has not been accted
          -- and prepayment application is accounted
          BEGIN

          SELECT 'Y'
            INTO l_check_prepay_unapply
        FROM dual
       WHERE EXISTS
             (SELECT 1
            FROM ap_invoice_distributions_all aid_prepay,
                 ap_invoice_payments_all aip,
                         ap_invoices_all ai_prepay,
             ap_invoice_distributions_all aid,
             ap_invoice_distributions_all aidp
                   WHERE aip.check_id = :pay_sum_folder.check_id
                     AND aip.invoice_id = ai_prepay.invoice_id
                     AND ai_prepay.invoice_type_lookup_code = 'PREPAYMENT'
             AND aid_prepay.invoice_id = ai_prepay.invoice_id
             AND aid_prepay.invoice_distribution_id = aid.prepay_distribution_id
             AND aid.prepay_distribution_id IS NOT NULL
             AND aid.parent_reversal_id IS NOT NULL
             AND aid.amount > 0
             AND nvl(aid.posted_flag, 'N') = 'N'
             AND aid.invoice_id = aidp.invoice_id
             AND aid.invoice_line_number = aidp.invoice_line_number
             AND aid.parent_reversal_id  = aidp.invoice_distribution_id
             AND aid.prepay_distribution_id = aidp.prepay_distribution_id
             AND nvl(aidp.posted_flag, 'N') = 'Y');
          EXCEPTION
            WHEN OTHERS THEN
              NULL;
          END;

          IF l_check_prepay_unapply = 'Y' THEN

            App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                                 ENABLED, PROPERTY_OFF);
          ELSE

            App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                                 ENABLED, PROPERTY_ON);
            :PAY_ACTIONS.void := 'N';

          END IF;

        END IF;
      else
        App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                     ENABLED, PROPERTY_OFF);
      end if;
      IF :pay_sum_folder.payment_type = 'N' THEN
         App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                                    ENABLED,PROPERTY_ON);
      END IF;
    else
      App_Item_Property.Set_Property('PAY_ACTIONS.VOID',
                     ENABLED, PROPERTY_OFF);
    end if;

  elsif (event = 'WHEN-CHECKBOX-CHANGED') then
    
    -- Check mutually exclusive fields
    --
    PAY_ACTIONS.REISSUE('MUTEX');
    PAY_ACTIONS.PRINT_REMITTANCE('MUTEX');
    PAY_ACTIONS.INITIATE_RELEASE_STOP('MUTEX');

    -- Initialize dependent fields
    --
    PAY_ACTIONS.VOID_DATE('INIT');
    --Bug2431590 Interchanged the following calls. Initialisation of invoice_action
    --is not happening if we get an error in gl_date validation.

    PAY_ACTIONS.INVOICE_ACTION('INIT');
    PAY_ACTIONS.GL_DATE('INIT');

  elsif (event = 'MUTEX') then
    -- Do not bother unsetting the checkbox if void is not allowed
    -- via function security.
    --
    if (:parameter.ap_apxpawkb_void = 'N') then
      return;
    end if;

    -- Set to 'N' since another mutually exclusive
    -- action has been selected
    --
    :PAY_ACTIONS.void := 'N';

    -- Initialize dependent fields
    --
    PAY_ACTIONS.VOID_DATE('INIT');
    PAY_ACTIONS.GL_DATE('INIT');
    PAY_ACTIONS.INVOICE_ACTION('INIT');
  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.VOID', 'EVENT', event);
  end if;
END;

PROCEDURE Void_Date(event Varchar2) IS
BEGIN

 --Bug fix: 2249708 Moved the foll fix from within the IF condition and
 --and placed it here, as parameter.payment_max_gl_date should be initialized any 
 --logic is checked around it.
  -- Bug 2144818  
  -- Initialize the parameter.payment_max_gl_date
  :parameter.payment_max_gl_date := :pay_sum_folder.max_payment_gl_date;

 --

  if (event in ('PRE-RECORD','INIT')) then
    App_Field.Set_Dependent_Field('INIT',
                  (:PAY_ACTIONS.VOID = 'Y'),
                                  'PAY_ACTIONS.VOID_DATE');
    App_Field.Set_Required_Field('INIT',
                 (:PAY_ACTIONS.VOID = 'Y'),
                                 'PAY_ACTIONS.VOID_DATE');
    if (event = 'INIT' and :PAY_ACTIONS.void = 'Y') then
      :PAY_ACTIONS.void_date := sysdate;
    end if;
    /*When validate condition added for Bug 1455643*/
  elsif (event = 'WHEN-VALIDATE-ITEM') then
    if (:PAY_ACTIONS.void = 'Y') then
      -- bug 2642104 add this hook for Federal 
      APPCORE_CUSTOM.EVENT('FVAPTPVD');
            -- Fix for 1939138 modified the above IF statement and wrote the
      -- below one
      IF :parameter.payment_max_gl_date IS NOT NULL THEN
        if (:PAY_ACTIONS.void_date < :parameter.payment_max_gl_date) then
          -- Bug 2144818  
          -- Initialize the parameter.payment_max_gl_date
          :parameter.payment_max_gl_date := :pay_sum_folder.max_payment_gl_date;
        --Introduced calendar_aware parameter in app_date.date_to_chardate
        -- procedure for bug#11774150
          Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_INVPAY_DATE',
               'GL_DATE', app_date.date_to_chardate(dateval=>:parameter.payment_max_gl_date,calendar_aware=>APP_DATE.calendar_aware_alt));    
        end if;
      ELSE
        IF :PAY_ACTIONS.void_date < :pay_sum_folder.max_payment_gl_date THEN
             --Introduced calendar_aware parameter in app_date.date_to_chardate
             -- procedure for bug#11774150
          Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_INVPAY_DATE',
                        'GL_DATE',
                     app_date.date_to_chardate(dateval=>:pay_sum_folder.max_payment_gl_date,calendar_aware=>APP_DATE.calendar_aware_alt));
        END IF ;
      END IF ;

      -- Bug3343314 ----
      -- the void date should not proceed the maturity date
      IF
      (
        :pay_sum_folder.status_lookup_code = 'NEGOTIABLE' AND
        --IBY: SP :pay_sum_folder.future_dated_payment_flag = 'Y' AND
/* Added nvl condition for bug 10099424 */
        :pay_actions.void_date < nvl(:pay_sum_folder.maturity_exchange_date,:pay_sum_folder.future_pay_due_date)
      )
      THEN
          --Introduced calendar_aware parameter in app_date.date_to_chardate
          --procedure for bug#11774150
        FORM_UTILITIES.DISPLAY_FAILURE_MESSAGE
        (
          'AP_VOID_DATE_BEF_MAT_DATE',
          'GL_DATE',
          app_date.date_to_chardate(dateval=>:pay_sum_folder.maturity_exchange_date,calendar_aware=>APP_DATE.calendar_aware_alt)
        );
      END IF;
      -- Bug3343314 ----

    end if;
  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.VOID_DATE',
                   'EVENT', event);
  end if;
END;

PROCEDURE GL_Date(event Varchar2) IS
  gl_date     Date;
  period_name Varchar2(15);
BEGIN
  if (event in ('PRE-RECORD','INIT')) then
    App_Field.Set_Dependent_Field('INIT',
                  (:PAY_ACTIONS.VOID = 'Y'),
                                  'PAY_ACTIONS.GL_DATE');
    App_Field.Set_Required_Field('INIT',
                 (:PAY_ACTIONS.VOID = 'Y'),
                                 'PAY_ACTIONS.GL_DATE');
    if (event = 'INIT' and :PAY_ACTIONS.void = 'Y') then
   
    -- 
    -- Fix for 1162722. Commenting out the following line. Assigning
    -- pay_actions.void_date to pay_actions.gl_date
    -- 
    -- :PAY_ACTIONS.gl_date := :parameter.payment_check_date;

       :PAY_ACTIONS.gl_date := :PAY_ACTIONS.void_date;

      -- Validate GL Date
      --
      PAY_ACTIONS.GL_DATE('WHEN-VALIDATE-ITEM');
    end if;
  elsif (event = 'WHEN-VALIDATE-ITEM') then
    if (:PAY_ACTIONS.void = 'Y') then
      -- Fix for 1939138 commented below IF statement
      --
      -- if (:PAY_ACTIONS.gl_date < :parameter.payment_max_gl_date) then
      --   Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_INVPAY_DATE','GL_DATE',
      --                        to_char(:parameter.payment_max_gl_date,
      --                              'DD-MON-YYYY'));
      -- end if;
      -- 
      -- Fix for 1939138 modified the above IF statement and wrote the
      -- below one
      IF :parameter.payment_max_gl_date IS NOT NULL THEN
        if (:PAY_ACTIONS.gl_date < :parameter.payment_max_gl_date) then
          --Introduced calendar_aware parameter in app_date.date_to_chardate
          --procedure for bug#11774150
          Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_INVPAY_DATE',
                           'GL_DATE',
            app_date.date_to_chardate(dateval=>:parameter.payment_max_gl_date,calendar_aware=>APP_DATE.calendar_aware_alt));
        end if;
      ELSE
        IF :PAY_ACTIONS.gl_date < :pay_sum_folder.max_payment_gl_date THEN
          --Introduced calendar_aware parameter in app_date.date_to_chardate
          --procedure for bug#11774150
          Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_INVPAY_DATE',
                        'GL_DATE',
               app_date.date_to_chardate(dateval=>:pay_sum_folder.max_payment_gl_date,calendar_aware=>APP_DATE.calendar_aware_alt));
        END IF ;
      END IF ;

    /* Added for bug 10099424 */
    IF (:pay_sum_folder.status_lookup_code = 'NEGOTIABLE' AND 
      :PAY_ACTIONS.gl_date < nvl(:pay_sum_folder.maturity_exchange_date,:pay_sum_folder.future_pay_due_date)) THEN
           --Introduced calendar_aware parameter in app_date.date_to_chardate
           --procedure for bug#11774150
          Form_Utilities.Display_Failure_Message('AP_VOID_DATE_BEF_MAT_DATE',
                                    'GL_DATE',
                                   app_date.date_to_chardate(dateval=>:pay_sum_folder.max_payment_gl_date,calendar_aware=>APP_DATE.calendar_aware_alt));
        END IF ;
    /* Addition for bug 10099424 ends */
      -- Check if void date is in an open period
      --
      AP_UTILITIES_PKG.GET_ONLY_OPEN_GL_DATE(:PAY_ACTIONS.gl_date,
                           period_name,
                         gl_date,
                                             :PAY_SUM_FOLDER.org_id);

      if (gl_date is null) then
        Form_Utilities.Display_Failure_Message('AP_ALL_NOT_OPEN_PERIOD');
      else
        :PAY_ACTIONS.void_period_name := period_name;
        --
        -- get_only_open_gl_date() returns the start_date of an open period
        -- so if gl_date supplied by user is in an open period, we should not
        -- blindly reset it to the start of the period
        --
        if (gl_date > :PAY_ACTIONS.gl_date) then
          :PAY_ACTIONS.gl_date := gl_date;
        end if;
      end if;

      -- For bug 2461087. Added by LGOPALSA
      -- Validating against gl_date to check whether AX is enabled during 
      -- that period.
            
      -- Bug 4340434 - Removing references to AX for R12
      -- PAY_ACTIONS_VOID.AX_AUTO_OFF_CHK(:PAY_ACTIONS.gl_Date);

    else 
      -- For bug 2461087. Added by LGOPALSA
      -- Resetting the list item if AX is not enabled.

      :PAY_ACTIONS.Invoice_Action := 'NONE';
       /* bug 2982690.*/
      PAY_ACTIONS_VOID.FOR_FUNCTION_SECURITY;
      App_Item_Property.Set_Property('PAY_ACTIONS.Invoice_Action', ALTERABLE, PROPERTY_OFF);
    end if;

  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.GL_DATE',
                   'EVENT', event);
  end if;
END;

PROCEDURE Invoice_Action(event Varchar2) IS
  v_account_dist                         NUMBER;
BEGIN
  if (event in ('PRE-RECORD','INIT')) then
      App_Field.Set_Dependent_Field('INIT',
                    (:PAY_ACTIONS.VOID = 'Y'),
                                 'PAY_ACTIONS.INVOICE_ACTION');
 
    if (:PAY_ACTIONS.VOID <> 'Y') then
     
        :PAY_ACTIONS.Invoice_Action := 'NONE';
         /* bug 2982690.*/
        PAY_ACTIONS_VOID.FOR_FUNCTION_SECURITY;
        App_Item_Property.Set_Property('PAY_ACTIONS.Invoice_Action', ALTERABLE, PROPERTY_FALSE);

    end if;
    if (event = 'INIT') then
 
      -- Initialize dependent fields
      --
      PAY_ACTIONS.HOLD_NAME('INIT');
    end if;
 
  elsif (event = 'WHEN-LIST-CHANGED') then
    -- Initialize dependent fields
    --
    PAY_ACTIONS.HOLD_NAME('INIT');

    if (:PAY_ACTIONS.invoice_action = 'HOLD') then
      -- Navigate to Hold window
      --
      App_Window.Set_Window_Position('HOLD_WINDOW',
                     'CENTER',
                     'PAY_ACTIONS_WINDOW');
      Go_Item('PAY_ACTIONS.HOLD_NAME');

    --Events Project - 2544746 - The fixes for bugs 1913277 and 2237152
    --are being removed as we will now allow invoice cancellation 
    --regardless of whether accounting has been created.
    /*  
    elsif (:PAY_ACTIONS.invoice_action = 'CANCEL') then

      -- Bug 1913277
      -- validate if the payments have been accounted, if they have not
      -- verify if the invoice or invoices have been accounted if they have, 
      -- show a message and do not allow the user to cancel the invoice 
      -- when voiding the check.

      --2237152, prevent the code below from executing if we are accounting
      --at "CLEARING ONLY"
      --SLA Project: Remove this condition, since it will be accounted 'ALWAYS'

  --   IF :parameter.when_payment_accounted <> 'CLEARING ONLY' then

      SELECT count(ad.invoice_distribution_id)
        INTO v_account_dist
        FROM ap_invoice_distributions ad,
             ap_invoice_payments ap
       WHERE ap.invoice_id = ad.invoice_id
         AND ap.check_id = :pay_sum_folder.check_id
         AND ad.posted_flag = 'Y'
         AND ROWNUM = 1
         AND EXISTS ( SELECT invoice_payment_id
                      FROM ap_invoice_payments
                     WHERE check_id = :pay_sum_folder.check_id
                       AND posted_flag = 'N' 
                   );

      if v_account_dist > 0 then 
         FND_MESSAGE.SET_NAME('SQLAP','AP_INVALID_INV_ACTION');
         FND_MESSAGE.ERROR;
         :PAY_ACTIONS.invoice_action := 'NONE';
         raise form_trigger_failure;
      end if;

--     END IF; 
     */ -- Events Project 2544746 

    end if;
  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.INVOICE_ACTION',
                   'EVENT', event);
  end if;
END;

PROCEDURE Hold_Name(event Varchar2) IS
BEGIN
  if (event = 'INIT') then
    :PAY_ACTIONS.hold_name := '';

    -- Initialize dependent fields
    --
    PAY_ACTIONS.HOLD_REASON('INIT');
  elsif (event = 'WHEN-VALIDATE-ITEM') then
    -- Initialize dependent fields
    --
    PAY_ACTIONS.HOLD_REASON('INIT');
  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.HOLD_NAME',
                   'EVENT', event);
  end if;
END;

PROCEDURE Hold_Reason(event Varchar2) IS
BEGIN
  if (event in ('PRE-RECORD','INIT')) then
    App_Field.Set_Dependent_Field('INIT',
                    'PAY_ACTIONS.HOLD_NAME',
                                  'PAY_ACTIONS.HOLD_REASON');
    if (event = 'INIT' and :PAY_ACTIONS.hold_name is not null) then
      :PAY_ACTIONS.hold_reason := :PAY_ACTIONS.hold_default_reason;
    end if;
  elsif (event = 'WHEN-VALIDATE-ITEM') then
    if (:PAY_ACTIONS.hold_name is not null and
        :PAY_ACTIONS.hold_reason is null) then
      :PAY_ACTIONS.hold_reason := :PAY_ACTIONS.hold_default_reason;
    end if;
  else
    APP_EXCEPTION.INVALID_ARGUMENT('PAY_ACTIONS.HOLD_REASON',
                   'EVENT', event);
  end if;
END;

/* Bug 2982690 */
PROCEDURE FOR_FUNCTION_SECURITY IS
l_message_text fnd_new_messages.message_text%TYPE;
BEGIN

      If (get_list_element_count('PAY_ACTIONS.INVOICE_ACTION') = 1) and
          :PARAMETER.AP_APXPAWKB_INVOICE_HOLDS = 'Y' then
              Fnd_Message.Set_Name('SQLAP', 'AP_ACTION_LIST_HOLD');
              l_message_text := Fnd_Message.Get;
          Add_List_Element('PAY_ACTIONS.INVOICE_ACTION', 2, l_message_text, 'HOLD');

      End If;
         
      If (get_list_element_count('PAY_ACTIONS.INVOICE_ACTION')  = 2) and
          :PARAMETER.AP_APXPAWKB_INVOICE_CANCEL = 'Y' then
            If :PARAMETER.AP_APXPAWKB_INVOICE_HOLDS = 'Y' Then
              Fnd_Message.Set_Name('SQLAP', 'AP_ACTION_LIST_CANCEL');
              l_message_text := Fnd_Message.Get;
              Add_List_Element('PAY_ACTIONS.INVOICE_ACTION', 3, l_message_text, 'CANCEL');
            End if;
      elsIf (get_list_elEment_count('PAY_ACTIONS.INVOICE_ACTION') = 1) 
          and :PARAMETER.AP_APXPAWKB_INVOICE_CANCEL = 'Y' then
              --Bug3078873
              Fnd_Message.Set_Name('SQLAP', 'AP_ACTION_LIST_CANCEL');
              l_message_text := Fnd_Message.Get;
              Add_List_Element('PAY_ACTIONS.INVOICE_ACTION', 2, l_message_text, 'HOLD');
      End if;

END;

/* Bug 2982690 */


END PAY_ACTIONS_VOID;

PAY_ACTIONS.VOID

-- 刘轶鹤

猜你喜欢

转载自blog.csdn.net/AlexLiu_2019/article/details/129952401
今日推荐