private fun validateTotalCurrent(tsn: Tsn, form19: Boolean) {
        when (tsn.type) {
            ItemType.MATERIAL, ItemType.EQUIPMENT, ItemType.RESOURCE_MATERIAL, ItemType.RESOURCE_MACHINE,
            ItemType.RESOURCE_EQUIPMENT, ItemType.WORKER, ItemType.RESOURCE_TRANSPORT -> {
                val expected = if (form19) tsn.pricePerUnitCur.getDecimalOrZero() else tsn.pricePerUnitBase.getDecimalOrZero()
                    .multiply(tsn.consumptionTotal.getDecimalOrZero())
                    .multiply(tsn.winterRise.getDecimalOrOne())
                    .multiply(
                        tsn.coefficients
                            .flatMap { it.values }
                            .map { it.getDecimalOrOne() }
                            .fold(BigDecimal.ONE, BigDecimal::multiply)
                    )
                    .multiply( tsn.recountCoefficients.map { it.getDecimalOrZero() }.sumOf { it }
                        .let { if (it.compareTo(BigDecimal.ZERO) == 0) BigDecimal.ONE else it })

                val expectedSecond = (tsn.totalBase.getDecimalOrZero())
                    .multiply( tsn.recountCoefficients.map { it.getDecimalOrZero() }.sumOf { it }
                        .let { if (it.compareTo(BigDecimal.ZERO) == 0) BigDecimal.ONE else it })

                val actual = tsn.totalCurrent.getDecimalOrZero()

                val validationSucceed = isEqual(actual, expected) || isEqual(actual, expectedSecond)

                tsn.totalCurrent.validationResult = if (validationSucceed) {
                    ValidationResult.SUCCESS
                } else {
                    ValidationResult.INCORRECT_CALCULATION
                }
            }
            ItemType.TRANSPORT -> {
                validateCurrentBase(tsn.consumptionTotal, tsn.machineOperation)
            }
            ItemType.COST -> {
                tsn.tsn.forEach { innerTsn ->
                    validateTotalCurrent(innerTsn, form19) }

                validateCurrentBase(tsn.quantityTotal, tsn.workersSalary)
                validateCurrentBase(tsn.quantityTotal, tsn.machineOperation)
                validateCurrentBase(tsn.quantityTotal, tsn.machinistSalary)
                validateCurrentBase(tsn.quantityTotal, tsn.materialResources)
                validateCurrentBase(tsn.quantityTotal, tsn.equipmentCosts)
                validateCurrentBase(tsn.quantityTotal, tsn.otherCosts)
            }
            ItemType.MACHINE -> {
                val expected = (tsn.pricePerUnitBase.getDecimalOrZero())
                    .multiply(tsn.consumptionTotal.getDecimalOrZero())
                    .multiply(tsn.winterRise.getDecimalOrOne())
                    .multiply(
                        tsn.coefficients
                            .flatMap { it.values }
                            .map { it.getDecimalOrOne() }
                            .fold(BigDecimal.ONE, BigDecimal::multiply)
                    ).multiply( tsn.recountCoefficients.map { it.getDecimalOrZero() }.sumOf { it }
                        .let { if (it.compareTo(BigDecimal.ZERO) == 0) BigDecimal.ONE else it })

                val expectedSecond = tsn.totalBase.getDecimalOrZero()
                    .multiply( tsn.recountCoefficients.map { it.getDecimalOrZero() }.sumOf { it }
                        .let { if (it.compareTo(BigDecimal.ZERO) == 0) BigDecimal.ONE else it })

                val actual = tsn.totalCurrent.getDecimalOrZero()

                val validationSucceed = isEqual(actual, expected) || isEqual(actual, expectedSecond)

                tsn.totalCurrent.validationResult = if (validationSucceed) {
                    ValidationResult.SUCCESS
                } else {
                    ValidationResult.INCORRECT_CALCULATION
                }
                validateCurrentBase(tsn.consumptionTotal, tsn.machineOperation)
                validateCurrentBase(tsn.consumptionTotal, tsn.machinistSalary)
            }

        }
    }
Эта функция содержит рекурсию?