Delimiter //
/**
* doit être appelé apres LOADER_RECLAIMS_NORMALIZE_MAP_ENTRIES
**/
Drop Procedure If Exists LOADER_RECLAIMS_NORMALIZE_MAP_DETAILS_AMOUNT//
Create Procedure LOADER_RECLAIMS_NORMALIZE_MAP_DETAILS_AMOUNT(
    In batchnum Int
)
Begin

    Update
        LOADER_STATUS STS
        Inner Join LOADER_RECLAIMS LRD
            On LRD.LOADER_STATUS_ID_LOADER_STATUS = STS.ID_LOADER_STATUS
		Inner Join ENTRIES ENT
			On LRD.ENTRIES_ID_ENTRIES = ENT.ID_ENTRIES
    Set
--         LRD.RECLAIMS_DETAILS_AMOUNT =  Coalesce(NullIf(ENT.ENTRIES_ENT_BALANCE, 0), Coalesce(ENT.ENTRIES_ENT_DEBIT, 0) - Coalesce(ENT.ENTRIES_ENT_CREDIT, 0))
        LRD.RECLAIMS_DETAILS_AMOUNT =  Coalesce(ENT.ENTRIES_ENT_BALANCE, Coalesce(ENT.ENTRIES_ENT_DEBIT, 0) - Coalesce(ENT.ENTRIES_ENT_CREDIT, 0))
    Where
        STS.LOADER_STATUS_BATCH_NUM = batchnum
		And LRD.RECLAIMS_DETAILS_AMOUNT Is null
		And STS.LOADER_STATUS_ERRCOUNT = 0
    ;

End//
Delimiter ;
