**BUSINESS EVENT DETECTION**
Business event detection occurs when there is a new contract or amendment of an existing one. Since the primary key of the loan transaction table ("loan") is the deal_id, for any time data is loaded, checks will be done based on the primary key on each of the fields in that table. Where the primary key never existed, the record is a new contract. Where the primary key already exists, check should be made to see if the current version of data loaded has any differing fields. If so, it is a contract change.
The procedure should be able to detect when there are such contract changes and return the respective business event types on the loan_business_event table. The PREPAYMENT event will be triggered by the source_event_type "PREPAYMENT" from the loan_source_event table (this is because there is no way to know if this happens unless there is a trigger that informs you). The prepayment amount and date should also be indicated in the source_event. After the contract changes, the "END OF DAY" events will continue each time a COB is run until the maturity of the deal. *Note that a PREPAYMENT will mean that the customer will finish repaying earlier than was agreed in the initial contract terms.