EN · DE · RU · FR · ES

#1374: CurrencyHelper.kt

projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt Kotlin class, projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt 84 lines · 44 code · 35 comments · 5 blank
Purpose: Source file: projectforge/framework/utils/CurrencyHelper.kt. CurrencyHelper.kt is part of the ProjectForge open-source project management application.

Source (first 100 lines)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.framework.utils

import java.math.BigDecimal
import java.math.RoundingMode

object CurrencyHelper {
    /**
     * @param net If null then zero is returned.
     * @param vat
     * @return Gross amount or net if vat is null or zero.
     */
    @JvmStatic
    fun getGrossAmount(net: BigDecimal?, vat: BigDecimal?): BigDecimal {
        if (net == null) {
            return BigDecimal.ZERO
        }
        return if (NumberHelper.isZeroOrNull(vat)) {
            net
        } else {
            net.multiply(BigDecimal.ONE.add(vat))
        }
    }

    /**
     * Calculates net amount from gross amount and VAT rate.
     * Formula: Net = Gross / (1 + VAT)
     *
     * @param gross If null then zero is returned.
     * @param vat VAT rate as decimal (e.g., 0.19 for 19%)
     * @return Net amount (rounded to 2 decimal places) or gross if vat is null or zero.
     */
    @JvmStatic
    fun getNetAmount(gross: BigDecimal?, vat: BigDecimal?): BigDecimal {
        if (gross == null) {
            return BigDecimal.ZERO
        }
        return if (NumberHelper.isZeroOrNull(vat)) {
            gross
        } else {
            val divisor = BigDecimal.ONE.add(vat)
            gross.divide(divisor, 2, RoundingMode.HALF_UP)
        }
    }

    @JvmOverloads
    @JvmStatic
    fun multiply(val1: BigDecimal?, val2: BigDecimal?, round: Boolean = false): BigDecimal {
        val ret = if (val1 == null) {
            val2 ?: BigDecimal.ZERO
        } else if (val2 == null) {
            val1
        } else {
            val1.multiply(val2)
        }
        return if (round) {
            ret.setScale(2, RoundingMode.HALF_UP)
        } else {
            ret
        }
    }
}

Git History

868d6abb7 2025 -> 2026
7a88efc65 WIP: Import of creditor invoices
63081666f Source file headers: 2024-> 2025.
ba2479571 Migration stuff in progress...
b6092df09 Copyright 2023 -> 2024

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
index 10a199366..e30c6198c 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

7a88efc65

WIP: Import of creditor invoices
7a88efc65e53c291d88df1f29f6b5b88eec85581
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
index f110c7828..10a199366 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
@@ -44,6 +44,27 @@ object CurrencyHelper {
         }
     }
 
+    /**
+     * Calculates net amount from gross amount and VAT rate.
+     * Formula: Net = Gross / (1 + VAT)
+     *
+     * @param gross If null then zero is returned.
+     * @param vat VAT rate as decimal (e.g., 0.19 for 19%)
+     * @return Net amount (rounded to 2 decimal places) or gross if vat is null or zero.
+     */
+    @JvmStatic
+    fun getNetAmount(gross: BigDecimal?, vat: BigDecimal?): BigDecimal {
+        if (gross == null) {
+            return BigDecimal.ZERO
+        }
+        return if (NumberHelper.isZeroOrNull(vat)) {
+            gross
+        } else {
+            val divisor = BigDecimal.ONE.add(vat)
+            gross.divide(divisor, 2, RoundingMode.HALF_UP)
+        }
+    }
+
     @JvmOverloads
     @JvmStatic
     fun multiply(val1: BigDecimal?, val2: BigDecimal?, round: Boolean = false): BigDecimal {

63081666f

Source file headers: 2024-> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
index bbc012701..f110c7828 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

ba2479571

Migration stuff in progress...
ba2479571a8408c62933df2d28125748a7a56383
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
index fe18fa69a..bbc012701 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
@@ -24,6 +24,7 @@
 package org.projectforge.framework.utils
 
 import java.math.BigDecimal
+import java.math.RoundingMode
 
 object CurrencyHelper {
     /**
@@ -43,14 +44,20 @@ object CurrencyHelper {
         }
     }
 
+    @JvmOverloads
     @JvmStatic
-    fun multiply(val1: BigDecimal?, val2: BigDecimal?): BigDecimal {
-        return if (val1 == null) {
+    fun multiply(val1: BigDecimal?, val2: BigDecimal?, round: Boolean = false): BigDecimal {
+        val ret = if (val1 == null) {
             val2 ?: BigDecimal.ZERO
         } else if (val2 == null) {
             val1
         } else {
             val1.multiply(val2)
         }
+        return if (round) {
+            ret.setScale(2, RoundingMode.HALF_UP)
+        } else {
+            ret
+        }
     }
 }

b6092df09

Copyright 2023 -> 2024
b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
index 8004b052d..fe18fa69a 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/utils/CurrencyHelper.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //