2023-10-05

[Oracle]How to adjust Asset

--參考資料 https://doyensys.com/blogs/api-for-fixed-asset-adjustments/
DECLARE
  L_TRANS_REC                 FA_API_TYPES.TRANS_REC_TYPE;
  L_ASSET_HDR_REC             FA_API_TYPES.ASSET_HDR_REC_TYPE;
  L_ASSET_FIN_REC_ADJ         FA_API_TYPES.ASSET_FIN_REC_TYPE; --這邊查看可以調整那些欄位
  L_ASSET_FIN_REC_NEW         FA_API_TYPES.ASSET_FIN_REC_TYPE;
  L_ASSET_FIN_MRC_TBL_NEW     FA_API_TYPES.ASSET_FIN_TBL_TYPE;
  L_INV_TRANS_REC             FA_API_TYPES.INV_TRANS_REC_TYPE;
  L_INV_TBL                   FA_API_TYPES.INV_TBL_TYPE;
  L_INV_RATE_TBL              FA_API_TYPES.INV_RATE_TBL_TYPE;
  L_ASSET_DEPRN_REC_ADJ       FA_API_TYPES.ASSET_DEPRN_REC_TYPE; --這邊查看可以調整那些欄位
  L_ASSET_DEPRN_REC_NEW       FA_API_TYPES.ASSET_DEPRN_REC_TYPE;
  L_ASSET_DEPRN_MRC_TBL_NEW   FA_API_TYPES.ASSET_DEPRN_TBL_TYPE;
  L_INV_REC                   FA_API_TYPES.INV_REC_TYPE;
  L_GROUP_RECLASS_OPTIONS_REC FA_API_TYPES.GROUP_RECLASS_OPTIONS_REC_TYPE;
  L_RETURN_STATUS             VARCHAR2(1);
  L_MESG_COUNT                NUMBER := 0;
  L_MESG_LEN                  NUMBER;
  L_MESG                      VARCHAR2(4000);

  P_ASSET_ID                  NUMBER;
BEGIN
  FND_PROFILE.PUT('PRINT_DEBUG', 'Y');

  DBMS_OUTPUT.ENABLE(1000000);

  FA_SRVR_MSG.INIT_SERVER_MESSAGE;
  FA_DEBUG_PKG.INITIALIZE;

  SELECT ASSET_ID
    INTO P_ASSET_ID
    FROM FA_ADDITIONS
   WHERE 1=1
     AND ASSET_NUMBER = 'TEST0912-2';
     
  --asset header info 
  L_ASSET_HDR_REC.ASSET_ID       := P_ASSET_ID; --Asset Id from fa_additions 
  L_ASSET_HDR_REC.BOOK_TYPE_CODE := 'TJ资产帐'; --帳本 TW资产帐、TJ资产帐

  --L_ASSET_FIN_REC_ADJ.DATE_PLACED_IN_SERVICE := I.DATE_PLACED_SERVICE;
  L_ASSET_FIN_REC_ADJ.LIFE_IN_MONTHS := 11; --SELECT * FROM FA_METHODS WHERE METHOD_CODE = 'STL'
  L_ASSET_FIN_REC_ADJ.DEPRN_METHOD_CODE := 'STL'; --不知道為什麼,但必要存在

  FA_ADJUSTMENT_PUB.DO_ADJUSTMENT(P_API_VERSION           => 1.0,
                                  P_INIT_MSG_LIST         => FND_API.G_FALSE,
                                  P_COMMIT                => FND_API.G_FALSE,
                                  P_VALIDATION_LEVEL      => FND_API.G_VALID_LEVEL_FULL,
                                  X_RETURN_STATUS         => L_RETURN_STATUS,
                                  X_MSG_COUNT             => L_MESG_COUNT,
                                  X_MSG_DATA              => L_MESG,
                                  P_CALLING_FN            => 'ADJ_TEST_SCRIPT',
                                  PX_TRANS_REC            => L_TRANS_REC,
                                  PX_ASSET_HDR_REC        => L_ASSET_HDR_REC,
                                  P_ASSET_FIN_REC_ADJ     => L_ASSET_FIN_REC_ADJ,
                                  X_ASSET_FIN_REC_NEW     => L_ASSET_FIN_REC_NEW,
                                  X_ASSET_FIN_MRC_TBL_NEW => L_ASSET_FIN_MRC_TBL_NEW,
                                  PX_INV_TRANS_REC        => L_INV_TRANS_REC,
                                  PX_INV_TBL              => L_INV_TBL,
                                  --PX_INV_RATE_TBL => L_INV_RATE_TBL,
                                  P_ASSET_DEPRN_REC_ADJ       => L_ASSET_DEPRN_REC_ADJ,
                                  X_ASSET_DEPRN_REC_NEW       => L_ASSET_DEPRN_REC_NEW,
                                  X_ASSET_DEPRN_MRC_TBL_NEW   => L_ASSET_DEPRN_MRC_TBL_NEW,
                                  P_GROUP_RECLASS_OPTIONS_REC => L_GROUP_RECLASS_OPTIONS_REC);

  DBMS_OUTPUT.PUT_LINE(SQLERRM || 'STATUS :' || L_RETURN_STATUS);

  IF (L_RETURN_STATUS <> FND_API.G_RET_STS_SUCCESS) THEN
    FA_DEBUG_PKG.DUMP_DEBUG_MESSAGES(MAX_MESGS => 0);
    L_MESG_COUNT := FND_MSG_PUB.COUNT_MSG;
  
    IF L_MESG_COUNT > 0 THEN
      L_MESG := SUBSTR(FND_MSG_PUB.GET(FND_MSG_PUB.G_FIRST, FND_API.G_FALSE), 1, 512);
      DBMS_OUTPUT.PUT_LINE(SUBSTR(L_MESG, 1, 255));
      FOR I IN 1 .. L_MESG_COUNT -1 LOOP
        L_MESG := SUBSTR(FND_MSG_PUB.GET(FND_MSG_PUB.G_NEXT, FND_API.G_FALSE), 1, 512);
        DBMS_OUTPUT.PUT_LINE(SUBSTR(L_MESG, 1, 255));
      END LOOP;
      FND_MSG_PUB.DELETE_MSG();
    END IF;
  ELSE
    DBMS_OUTPUT.PUT_LINE('SUCCESS');
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('THID' || TO_CHAR(L_TRANS_REC.TRANSACTION_HEADER_ID));
  END IF;
END;

沒有留言:

張貼留言