Issue #23254:fix gain/loss calculation

https://github.com/xtuple/qt-client/pull/432/files into 4.7 line