inspired by https://github.com/apache/fineract/pull/1262/files see https://issues.apache.org/jira/browse/FINERACT-1127