Initial commit: IT Nexus Web-App
This commit is contained in:
71
frontend/src/utils/afaUtils.js
Normal file
71
frontend/src/utils/afaUtils.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* AfA (Abschreibung) Utility-Funktionen
|
||||
* Lineare Abschreibungsberechnung für das Anlagevermögen-Modul
|
||||
*/
|
||||
|
||||
/**
|
||||
* Berechnet AfA-Werte für ein Asset
|
||||
* @param {number} purchasePrice - Anschaffungswert in €
|
||||
* @param {number} usefulLifeYears - Nutzungsdauer in Jahren
|
||||
* @param {number} residualValue - Restwert nach Abschreibung (Standard: 0)
|
||||
* @param {string} purchaseDateStr - Kaufdatum als ISO-String (YYYY-MM-DD)
|
||||
* @returns {object|null} AfA-Werte oder null bei fehlenden Pflichtfeldern
|
||||
*/
|
||||
export function calculateAfa(purchasePrice, usefulLifeYears, residualValue = 0, purchaseDateStr) {
|
||||
if (!purchasePrice || !usefulLifeYears || !purchaseDateStr) return null;
|
||||
|
||||
const price = parseFloat(purchasePrice);
|
||||
const years = parseInt(usefulLifeYears);
|
||||
const residual = parseFloat(residualValue) || 0;
|
||||
|
||||
if (price <= 0 || years <= 0) return null;
|
||||
|
||||
const purchaseDate = new Date(purchaseDateStr);
|
||||
const now = new Date();
|
||||
const yearsSincePurchase = (now - purchaseDate) / (1000 * 60 * 60 * 24 * 365.25);
|
||||
|
||||
const annualDepreciation = (price - residual) / years;
|
||||
const cumulativeDepreciation = Math.min(price - residual, annualDepreciation * yearsSincePurchase);
|
||||
const currentBookValue = Math.max(residual, price - cumulativeDepreciation);
|
||||
|
||||
const fullyDepreciatedDate = new Date(purchaseDate);
|
||||
fullyDepreciatedDate.setFullYear(fullyDepreciatedDate.getFullYear() + years);
|
||||
|
||||
const isFullyDepreciated = now >= fullyDepreciatedDate;
|
||||
|
||||
return {
|
||||
annualDepreciation,
|
||||
cumulativeDepreciation,
|
||||
currentBookValue,
|
||||
fullyDepreciatedDate,
|
||||
isFullyDepreciated,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert einen Wert als Euro-String (deutsche Notation)
|
||||
* @param {number} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatEuro(value) {
|
||||
if (value === null || value === undefined || isNaN(value)) return '–';
|
||||
return value.toLocaleString('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + ' €';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die empfohlene Standard-Nutzungsdauer für einen Asset-Typ zurück
|
||||
* @param {string} type - Asset-Typ
|
||||
* @returns {number} Nutzungsdauer in Jahren
|
||||
*/
|
||||
export function getDefaultUsefulLife(type) {
|
||||
const defaults = {
|
||||
'Notebook': 3,
|
||||
'Monitor': 3,
|
||||
'Headset': 3,
|
||||
'Maschine': 8,
|
||||
'Werkzeug': 5,
|
||||
'Sonstiges': 5,
|
||||
'Other': 5,
|
||||
};
|
||||
return defaults[type] || 5;
|
||||
}
|
||||
Reference in New Issue
Block a user