OK. I misunderstood what you meant by a 'flat fee'.

Try this in P9 and drag down.

=IF($O9=0,"",IF($R9>=1,$O9-$R9,$R9*$O9+$S9))

Is that 100% there now?