fix bugs on margin calculation and margin reports

especially for credit notes