Skip to content

Commit

Permalink
fix: misc
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar committed Feb 3, 2023
1 parent 3bff1c1 commit 9fb9486
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 84 deletions.
70 changes: 56 additions & 14 deletions src/models/2023/personenauto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { InvalidParameters } from "../../errors.js";
import { berekenOutput, ModelOutputOnderdelen } from "../../output.js";
import { ModelParams, Voertuigtype } from "../../params.js";
import { Brandstof, ModelParams, Voertuigtype } from "../../params.js";
import { Model_1995_Tarieven } from "../1995/tarieven.js";
import { Model_Personenauto } from "../personenauto.js";
import { gewichtsTarief } from "../gewichtsTarief.js";
import { Model_2023_Opcenten } from "./opcenten.js";
import { Model_2023_Tarieven } from "./tarieven.js";

Expand Down Expand Up @@ -35,6 +35,11 @@ export function Model_2023_Personenauto(params: ModelParams) {
{
omschrijving:
"Voor een Personenauto die volledig en uitsluitend op elektriciteit of waterstof rijdt, betaalt u geen motorrijtuigenbelasting.",
referentie: {
titel: "Artikel 31 Wet op de motorrijtuigenbelasting 1994",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0006324&hoofdstuk=IV&afdeling=9&artikel=31&z=2023-01-01&g=2023-01-01",
},

subtotaal: 0,
},
]);
Expand All @@ -51,6 +56,11 @@ export function Model_2023_Personenauto(params: ModelParams) {
{
omschrijving:
"Hebt u een personenauto met een CO2-uitstoot van 0 gram per kilometer? Dan betaalt u geen motorrijtuigenbelasting.",
referentie: {
titel:
"Artikel 23b, eerste lid, Wet op de motorrijtuigenbelasting 1994",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0006324&hoofdstuk=IV&afdeling=2&artikel=23b&z=2023-01-01&g=2023-01-01",
},
subtotaal: 0,
},
]);
Expand All @@ -62,34 +72,61 @@ export function Model_2023_Personenauto(params: ModelParams) {

const onderdelen: ModelOutputOnderdelen = [];

const grondslag = Model_Personenauto({
const basis = gewichtsTarief({
gewicht,
brandstof,
tarieven: Model_2023_Tarieven[Voertuigtype.Personenauto],
tarieven: Model_2023_Tarieven[Voertuigtype.Personenauto].basis,
});

onderdelen.push({
omschrijving: `Motorrijtuigenbelasting voor een personenauto die op ${brandstof.toLowerCase()} rijdt`,
waarde: grondslag,
subtotaal: grondslag,
omschrijving: `Motorrijtuigenbelasting voor een personenauto`,
referentie: {
titel: "Artikel 23, eerste lid, Wet op de motorrijtuigenbelasting 1994",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0006324&hoofdstuk=IV&afdeling=2&artikel=23&z=2023-01-01&g=2023-01-01",
},
subtotaal: basis,
});

const opcentenGrondslag = Model_Personenauto({
if (brandstof === Brandstof.Diesel) {
const brandstoftoeslag = gewichtsTarief({
gewicht,
tarieven:
Model_2023_Tarieven[Voertuigtype.Personenauto].toeslagen[
Brandstof.Diesel
],
});

onderdelen.push({
omschrijving: `Brandstoftoeslag voor een personenauto rijdend op diesel`,
referentie: {
titel: "Artikel 23, tweede lid, Wet op de motorrijtuigenbelasting 1994",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0006324&hoofdstuk=IV&afdeling=2&artikel=23&z=2023-01-01&g=2023-01-01",
},
subtotaal: brandstoftoeslag,
});
}

const opcentenGrondslag = gewichtsTarief({
gewicht,
brandstof,
tarieven: Model_1995_Tarieven[Voertuigtype.Personenauto],
brandstoftoeslag: false,
tarieven: Model_1995_Tarieven[Voertuigtype.Personenauto].basis,
});

onderdelen.push({
omschrijving: `Motorrijtuigenbelasting voor een personenauto die op ${brandstof.toLowerCase()} rijdt (grondslag 1995)`,
waarde: opcentenGrondslag,
omschrijving: `Motorrijtuigenbelasting voor een personenauto (grondslag 1995)`,
referentie: {
titel: "Wet op de motorrijtuigenbelasting 1994 (geldig op 1 april 1995)",
url: "https://zoek.officielebekendmakingen.nl/stb-1995-152.html",
},
waarde: `€ ${opcentenGrondslag.toFixed(2)}`,
});

const opcentenPercentage = Model_2023_Opcenten(provincie);

onderdelen.push({
omschrijving: "Provinciale opcenten (berekend over grondslag 1995)",
referentie: {
titel: "Artikel 222, Provinciewet",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0005645&titeldeel=IV&hoofdstuk=XV&paragraaf=2&artikel=222&z=2023-01-01&g=2023-01-01",
},
waarde: `${opcentenPercentage * 100}%`,
subtotaal: opcentenGrondslag * opcentenPercentage,
});
Expand All @@ -106,6 +143,11 @@ export function Model_2023_Personenauto(params: ModelParams) {
onderdelen.push({
omschrijving:
"Hebt u een personenauto met een CO2-uitstoot van 1 tot en met 50 gram per kilometer? Dan geldt een halftarief. Dit betekent dat u de helft betaalt van het tarief voor een gewone personenauto. (correctie)",
referentie: {
titel:
"Artikel 23b, eerste lid, Wet op de motorrijtuigenbelasting 1994",
url: "https://wetten.overheid.nl/jci1.3:c:BWBR0006324&hoofdstuk=IV&afdeling=2&artikel=23b&z=2023-01-01&g=2023-01-01",
},
subtotaal: berekenOutput(onderdelen)._precise / -2,
});

Expand Down
71 changes: 11 additions & 60 deletions src/models/personenauto.ts → src/models/gewichtsTarief.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import { NotImplementedError } from "../errors.js";
import { Brandstof, ModelParams, Voertuigtype } from "../params.js";

type Tarieven = {
[key in Voertuigtype]: {
basis: Tarief[];
toeslagen: {
[Brandstof.Diesel]: Tarief[];
};
};
};
import type { ModelParams } from "../params.js";

type Tarief = {
threshold_kg: number;
Expand Down Expand Up @@ -48,13 +38,20 @@ function findTarief({
});
}

function berekenVastEnVariabel({
/**
* Dit is de formule voor het berekening van de grondslag voor de
* motorrijtuigenbelasting gebaseerd op de Wet op de motorrijtuigenbelasting
* 1994
*/
export function gewichtsTarief({
tarieven,
afgerondGewicht,
gewicht,
}: {
gewicht: ModelParams["gewicht"];
tarieven: Tarief[];
afgerondGewicht: number;
}) {
const afgerondGewicht = rondGewichtAf(gewicht);

let bedrag: number;

const tarief = findTarief({
Expand All @@ -80,49 +77,3 @@ function berekenVastEnVariabel({

return bedrag;
}

/**
* Dit is de formule voor het berekening van de grondslag voor de
* motorrijtuigenbelasting gebaseerd op de Wet op de motorrijtuigenbelasting
* 1994
*/
export function Model_Personenauto({
brandstof,
tarieven,
gewicht,
brandstoftoeslag = true,
}: {
gewicht: ModelParams["gewicht"];
brandstof: ModelParams["brandstof"];
tarieven: Tarieven[Voertuigtype.Personenauto];
brandstoftoeslag?: boolean;
}) {
const afgerondGewicht = rondGewichtAf(gewicht);

switch (brandstof) {
case Brandstof.Benzine:
return berekenVastEnVariabel({
afgerondGewicht,
tarieven: tarieven.basis,
});

case Brandstof.Diesel:
return (
berekenVastEnVariabel({
afgerondGewicht,
tarieven: tarieven.basis,
}) +
(brandstoftoeslag
? berekenVastEnVariabel({
afgerondGewicht,
tarieven: tarieven.toeslagen[Brandstof.Diesel],
})
: 0)
);

case Brandstof["LPG en overige (behalve elektriciteit en waterstof)"]:
case Brandstof["LPG3 en Aardgas"]:
default:
throw new NotImplementedError();
}
}
7 changes: 6 additions & 1 deletion src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ export type ModelOutputOnderdelen = {
*/
omschrijving: string;

/**
* Wet referenties die van toepassing zijn op dit onderdeel.
*/
referentie?: { titel: string; url: string };

/**
* Waarde van dit onderdeel, niet opgenomen in subtotaal.
*/
waarde?: number | string;
waarde?: string;

/**
* De motorrijtuigenbelasting per tijdvak van 3 maanden in euro's voor dit
Expand Down
7 changes: 7 additions & 0 deletions src/rdwDataToParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ function toBrandstof(rdwData: RdwData) {
throw new InvalidRdwData();
}

if (
brandstof.length === 1 &&
brandstof[0]?.brandstof_omschrijving === "Diesel"
) {
return Brandstof.Diesel;
}

// const sortedBrandstoffen = [...brandstof].sort((a, b) =>
// Number(a.brandstof_volgnummer) > Number(b.brandstof_volgnummer) ? 1 : -1
// );
Expand Down
9 changes: 0 additions & 9 deletions tests/models/2023/personenauto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ test("lage_uitstoot", () => {
});

test("invalid parameters", () => {
expect(() =>
Model_2023_Personenauto({
brandstof: "invalid" as Brandstof,
elektrisch_of_waterstof: false,
voertuigtype: Voertuigtype.Personenauto,
provincie: Provincie.Utrecht,
gewicht: 0,
})
).toThrow();
expect(() =>
Model_2023_Personenauto({
brandstof: Brandstof.Benzine,
Expand Down

0 comments on commit 9fb9486

Please sign in to comment.