phx-node-test-1
Version:
PHX NODE
62 lines • 2.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateValue = exports.sumTotalFee = exports.getTotalAdmissionTuition = exports.findAdjustmentForTuition = exports.parseToObject = exports.nextYearDate = exports.timeYearActive = exports.currentTime = void 0;
const constant_1 = require("./constant");
const tuition_1 = require("./types/tuition");
exports.currentTime = new Date();
exports.timeYearActive = new Date().toISOString().slice(0, 10);
exports.currentTime.setFullYear(exports.currentTime.getFullYear() + 1);
exports.nextYearDate = exports.currentTime.toISOString().slice(0, 10);
const parseToObject = (value) => {
return value
.split("\n")
.filter((line) => line.trim() && !line.startsWith("#"))
.reduce((acc, line) => {
const [key, value] = line.split("=");
if (key && value) {
acc[key.trim()] = value.trim();
}
return acc;
}, {});
};
exports.parseToObject = parseToObject;
const findAdjustmentForTuition = (list_detail_fee_adjustment) => {
const listAdjustmentFeeForTuition = list_detail_fee_adjustment.filter(({ tuition_fee_adjustment: { fee_type_code, tuition_fee_project_code: { code }, }, }) => {
const isDescFee = fee_type_code === tuition_1.FEE_TYPE.DESC;
return isDescFee && code === constant_1.CODE_TUITION;
});
return listAdjustmentFeeForTuition;
};
exports.findAdjustmentForTuition = findAdjustmentForTuition;
const getTotalAdmissionTuition = (list_detail_promo) => {
const { ADMISSION_TUITION } = tuition_1.DETAIL_PROMO_TYPE;
const admissionPromoForTuition = list_detail_promo.filter(({ code }) => code === ADMISSION_TUITION);
return (0, exports.sumTotalFee)(admissionPromoForTuition);
};
exports.getTotalAdmissionTuition = getTotalAdmissionTuition;
const sumTotalFee = (listFee, isFeeAdjustment = false) => {
var _a;
const listFeeLength = listFee.length;
if (listFeeLength === 0)
return 0;
let sumTotalFee = 0;
for (const feeItem of listFee) {
let totalPromo = 0;
if (isFeeAdjustment) {
totalPromo = ((_a = feeItem === null || feeItem === void 0 ? void 0 : feeItem.tuition_fee_adjustment) === null || _a === void 0 ? void 0 : _a.total_fee) || 0;
}
else {
totalPromo = (feeItem === null || feeItem === void 0 ? void 0 : feeItem.total_promo) || (feeItem === null || feeItem === void 0 ? void 0 : feeItem.value) || 0;
}
sumTotalFee += totalPromo;
}
return sumTotalFee;
};
exports.sumTotalFee = sumTotalFee;
const generateValue = (value) => {
if (!value)
return 0;
return Math.abs(value);
};
exports.generateValue = generateValue;
//# sourceMappingURL=helper.js.map