FrenchTaxRules.kt

// EV Supervision Lite — built by Kevin Vavelin, Codetics
// https://codetics.fr
// Copyright (c) 2026 Kevin Vavelin, Codetics
// SPDX-License-Identifier: LicenseRef-Codetics-Attribution-1.0

package fr.codetics.ev_server.services.fiscal

import java.math.BigDecimal
import java.time.LocalDate
import tools.jackson.databind.PropertyNamingStrategies
import tools.jackson.databind.annotation.JsonNaming

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class TaxSource(val label: String, val url: String)

/**
 * French social-security and tax parameters for the charging of electric vehicles, for one year.
 *
 * These values help prepare payroll and tax returns; they are not legal advice. They were collected on
 * 2 December 2026 from URSSAF/BOSS doctrine as relayed by the sources listed, and must be checked by the
 * payroll manager or the accountant. [confirmed] is false for a year whose values were not yet published:
 * the latest known values are then carried over.
 */
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
data class FrenchTaxRules(
    val year: Int,
    val confirmed: Boolean,
    val checkedOn: LocalDate,
    /** Charging at a workplace charging point creates no benefit in kind until this date (inclusive). */
    val workplaceChargingExemptUntil: LocalDate,
    /** Electricity paid by the employer for a 100 % electric company car stays out of the benefit until this date. */
    val companyCarElectricityExcludedUntil: LocalDate,
    /** Abatement on the benefit in kind of a 100 % electric company car valued at the flat rate, and its yearly ceiling. */
    val electricCarAbatementRate: BigDecimal,
    val electricCarAbatementCeiling: BigDecimal,
    /** The same abatement when the benefit is valued on actual costs. */
    val electricCarActualAbatementRate: BigDecimal,
    val electricCarActualAbatementCeiling: BigDecimal,
    /** Cars made available from this date must meet the bonus écologique environmental score for the abatement. */
    val ecoScoreRequiredSince: LocalDate,
    /** Home charging point kept by the employee: exempt share of its cost and yearly ceiling (under / over 5 years old). */
    val homeStationExemptRate: BigDecimal,
    val homeStationCeiling: BigDecimal,
    val oldHomeStationExemptRate: BigDecimal,
    val oldHomeStationCeiling: BigDecimal,
    /** Standard VAT rate on charging services, and the deductible share of VAT on electricity for company vehicles. */
    val vatRate: BigDecimal,
    val vatElectricityDeductibleShare: BigDecimal,
    val sources: List<TaxSource>,
) {
    companion object {
        private val CHECKED_ON: LocalDate = LocalDate.of(2026, 12, 2)
        private val END_2027: LocalDate = LocalDate.of(2027, 12, 31)

        val SOURCES =
            listOf(
                TaxSource(
                    "Urssaf — Les avantages en nature « véhicule » et « borne de recharge électrique »",
                    "https://www.urssaf.fr/accueil/actualites/an-vehicule-borne-recharge.html",
                ),
                TaxSource(
                    "Arrêté du 25 février 2025 (avantages en nature véhicule et borne)",
                    "https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000051254024",
                ),
                TaxSource("BOSS — Avantages en nature", "https://boss.gouv.fr/portail/accueil/avantages-en-nature.html"),
                TaxSource("BOSS — Frais professionnels", "https://boss.gouv.fr/portail/accueil/frais-professionnels.html"),
                TaxSource(
                    "BOFiP — Exclusions du droit à déduction de la TVA (carburants et électricité)",
                    "https://bofip.impots.gouv.fr/bofip/1112-PGP.html/identifiant=BOI-TVA-DED-30-30-20",
                ),
                TaxSource(
                    "Arrêté du 30 octobre 2025 — déclaration des quantités d'électricité des aménageurs (TIRUERT/IRICC)",
                    "https://aida.ineris.fr/reglementation/arrete-301025-relatif-a-declaration-dematerialisee-quantites-delectricite-consommees",
                ),
                TaxSource(
                    "Facturation électronique entre entreprises — calendrier",
                    "https://www.economie.gouv.fr/node/3241932",
                ),
            )

        private val YEARS: Map<Int, FrenchTaxRules> =
            listOf(
                    // 2025: only the flat-rate ceiling and the home charging point ceiling were found; the others are estimates.
                    rules(2025, false, BigDecimal("4582.00"), BigDecimal("2000.30"), BigDecimal("1043.50"), BigDecimal("1565.30")),
                    rules(2026, true, BigDecimal("4641.60"), BigDecimal("2026.30"), BigDecimal("1057.10"), BigDecimal("1585.50")),
                )
                .associateBy { it.year }

        private fun rules(
            year: Int,
            confirmed: Boolean,
            ceiling: BigDecimal,
            actualCeiling: BigDecimal,
            homeStationCeiling: BigDecimal,
            oldHomeStationCeiling: BigDecimal,
        ) =
            FrenchTaxRules(
                year = year,
                confirmed = confirmed,
                checkedOn = CHECKED_ON,
                workplaceChargingExemptUntil = END_2027,
                companyCarElectricityExcludedUntil = END_2027,
                electricCarAbatementRate = BigDecimal("0.70"),
                electricCarAbatementCeiling = ceiling,
                electricCarActualAbatementRate = BigDecimal("0.50"),
                electricCarActualAbatementCeiling = actualCeiling,
                ecoScoreRequiredSince = LocalDate.of(2025, 2, 1),
                homeStationExemptRate = BigDecimal("0.50"),
                homeStationCeiling = homeStationCeiling,
                oldHomeStationExemptRate = BigDecimal("0.75"),
                oldHomeStationCeiling = oldHomeStationCeiling,
                vatRate = BigDecimal("0.20"),
                vatElectricityDeductibleShare = BigDecimal.ONE,
                sources = SOURCES,
            )

        /** The rules of [year]; a later year reuses the latest known values, marked as not confirmed. */
        fun of(year: Int): FrenchTaxRules {
            YEARS[year]?.let { return it }
            val latest = YEARS.keys.filter { it <= year }.maxOrNull() ?: YEARS.keys.min()
            return requireNotNull(YEARS[latest]).copy(year = year, confirmed = false)
        }
    }
}