realestate-jp
Version:
不動産関連のユーティリティ関数を提供するライブラリ
48 lines (47 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRentSummary = getRentSummary;
const constants_js_1 = require("../constants.js");
const utils_js_1 = require("./utils.js");
/**
* 家賃支払いのサマリーを計算する
*
* @param rent 月額家賃
* @param years 契約年数(デフォルト: 1年)
* @param fee 月額維持費(デフォルト: 0)
* @param renewCycle 契約更新の頻度(年単位、デフォルト: 0=更新なし)
* @param renewFee 更新料(月数単位、デフォルト: 0)
* @param raiseRate 更新時の家賃値上げ率(% 単位、デフォルト: 0)
* @returns 支払いサマリー情報
*
* @example 使用例
* ```ts
* import { getRentSummary } from "@japanese/realestate";
*
* const summary = getRentSummary(85000, 10, 5000, 2, 1, 5);
* console.log(summary);
* ```
*/
function getRentSummary(rent, years = 1, fee = 0, renewCycle = 0, renewFee = 0, raiseRate = 0) {
let totalPayment = 0;
let currentRent = rent;
for (let year = 1; year <= years; year++) {
const isRenewal = year > 1 && (0, utils_js_1.isRenewalYear)(year, renewCycle);
if (isRenewal && raiseRate > 0) {
currentRent *= 1 + raiseRate / 100;
}
totalPayment += (0, utils_js_1.calculateAnnualPayment)(currentRent, fee, renewFee, isRenewal);
}
// 初年度の月額合計(値上げは考慮しない)
const monthlyTotal = (0, utils_js_1.calculateMonthlyTotal)(rent, fee);
// 初年度の年間支払額
const annualTotal = monthlyTotal * constants_js_1.MONTHS_PER_YEAR;
// 契約期間全体の平均月額支払額を計算
const averageMonthly = totalPayment / (years * constants_js_1.MONTHS_PER_YEAR);
return {
monthlyTotal,
annualTotal,
totalPayment: Math.round(totalPayment),
averageMonthly: Math.round(averageMonthly),
};
}