various fixes on margin :
- fix on sortorder
- fix for credit notes
- fix for total
use ifsql function
Merge pull request #756 from cbattarel/3.3

various fixes on margin :