We've added custom discounts in our system and I will probably try to never do that again.
Intefering with the Sales Order calculations, is a slippery slope. Later, you need to take into account the impact on the invoice, retAs (if you will use them), revenue arrangements, etc. It cost us A LOT and till now we're trubleshooting resulting bugs.
I think you are trying to generate automated Journal entries based on the sales order values.
Did you consider using dynamic allocation schedules?