1.3 KiB
Feature: Fix INACBG Total Claim Calculation
Problem: When a user adds a new INACBG code, the total claim amount does not increase as expected. Instead, it seems to reset or absorb the new code's value into the base offset. This happens because the Base Offset calculation logic uses the current list of selected codes (which includes the new code) to calculate the offset from the original total. Formula used: Offset = OriginalTotal - Sum(CurrentCodes) If user adds code: Offset = Original - (Old + New) Final Total = Offset + (Old + New) = Original.
Solution: We must distinguish between "Original Codes" (loaded from DB) and "Current Codes" (live state). The Base Offset should strictly be: BaseOffset = OriginalTotal - Sum(OriginalCodes)
Steps:
- Add
initialLoadedCodesstate toINACBG_Admin_Ruangan.tsx. - Populate checking
initialLoadedCodesinloadBillingAktifHistorywhen data is loaded from DB. - Update
useEffectcalculation logic to validly calculate Base Offset usinginitialLoadedCodesinstead ofselectedInacbgCodesduring initialization. - Ensure
baseKlaimOffsetis calculated only once.
Refined Logic:
- If
!hasInitializedBaseRef.current:- Calculate
Sum(InitialCodes). Offset = OriginalTotal - Sum(InitialCodes).- Set
BaseOffset. - Mark initialized.
- Calculate
- Always:
FinalTotal = BaseOffset + Sum(CurrentCodes).