UNPKG

phx-node

Version:

PHX NODE

187 lines 11.2 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var PHXSettingFormulaPromotion_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.PHXSettingFormulaPromotion = void 0; const common_1 = require("@nestjs/common"); const helper_1 = require("../../../lib/helper"); const constant_1 = require("../../../lib/constant"); const grpc_client_system_service_1 = require("../../grpc-client/grpc-client-system.service"); const setting_formula_promotion_1 = require("../../../query/tuition/setting-formula-promotion"); const tuition_1 = require("../../../lib/types/tuition"); // Service xử lý setting công thức ưu đãi học phí let PHXSettingFormulaPromotion = PHXSettingFormulaPromotion_1 = class PHXSettingFormulaPromotion { constructor(grpcClientSystemService) { this.grpcClientSystemService = grpcClientSystemService; this.logger = new common_1.Logger(PHXSettingFormulaPromotion_1.name); } // Lấy ra cài đặt công thức bằng mã công thức và loại cài đặt getSettingFormulaPromoByCode(code, setting_type, //loại cài đặt (tuition - cài đặt học phí, service - cài đặt phí dịch vụ) hostname) { return __awaiter(this, void 0, void 0, function* () { try { const res = yield this.grpcClientSystemService.query({ query: setting_formula_promotion_1.GET_SETTING_FORMULA_PROMOTION_QUERY, variables: { code, setting_type }, hostname, }); if (res) { return res.tuition_setting_formula_promotion; } else { return []; } } catch (error) { this.logger.error(`${hostname}:error`); return []; } }); } // Hàm này trả về 1 năm và 2 kỳ học, bao gồm tổng tiền học niêm yết, tổng ưu đãi theo setting và tổng ưu đãi không theo setting generateTuitionAfterPromotion(feeDebtRecord, listSettingBySchoolId) { const recordLength = feeDebtRecord.length; const dataTuitionByYear = { total_tuition: 0, total_promotion_computed: 0, total_promotion_reference: 0, }; const listDataTuitionBySemester = []; if (recordLength <= 0) { return { dataTuitionByYear, listDataTuitionBySemester, }; } for (const recordItem of feeDebtRecord) { const { total_tuition, school_term: { id }, } = recordItem; const totalToPay = (0, helper_1.generateValue)(total_tuition); const { totalPromotionComputed, totalPromotionReference } = this.getTotalPromotionForEarlyPromo(listSettingBySchoolId, recordItem); listDataTuitionBySemester.push({ school_term_id: id, total_tuition: totalToPay, total_promotion_computed: totalPromotionComputed, // Tổng ưu đãi dùng để tính ra ưu đãi đóng sớm total_promotion_reference: totalPromotionReference, // Tổng ưu đãi học phí (ko bao gồm ưu đãi đóng sớm) Để tính tổng tiền phải đóng }); dataTuitionByYear.total_tuition += totalToPay; dataTuitionByYear.total_promotion_computed += totalPromotionComputed; dataTuitionByYear.total_promotion_reference += totalPromotionReference; } return { dataTuitionByYear, listDataTuitionBySemester, }; } // Công thức ưu đãi đóng sớm getTotalPromotionForEarlyPromo(listSettingRes, recordItem // tiến trình đóng phí ) { // Công thức tính dựa theo lựa chọn // Tổng tiền ưu đãi đóng sớm = % Ưu đãi đóng sớm x (Tổng học phí niêm yết - Ưu đãi chính sách - Ưu đãi học bổng) const settingItem = listSettingRes[0]; const { total_promotion_tuition_seniority, total_promotion_tuition_scholar_ship, total_promotion_tuition_policy, tuition_fee_detail_promotions, list_detail_fee_adjustment, } = recordItem; const { ADMISSION_TUITION, ADMISSION_SERVICE, SERVICE } = tuition_1.DETAIL_PROMO_TYPE; const totalPromotionAdmissionForTuition = (0, helper_1.getTotalDetailPromoByCode)(tuition_fee_detail_promotions, ADMISSION_TUITION); // Giảm trừ bổ sung cho học phí const adjustmentFees = (0, helper_1.findAdjustmentForTuition)(list_detail_fee_adjustment); const isFeeAdjustment = true; const totalFeeAdjustmentTuition = (0, helper_1.sumTotalFee)(adjustmentFees, isFeeAdjustment); const totalPromotionAdmissionForService = (0, helper_1.getTotalDetailPromoByCode)(tuition_fee_detail_promotions, ADMISSION_SERVICE); const totalPromotionService = (0, helper_1.getTotalDetailPromoByCode)(tuition_fee_detail_promotions, SERVICE); let totalPromotionComputed = 0; // Tổng ưu đãi dùng để tính ra ưu đãi đóng sớm const totalPromotionReference = this.getTotalPromotionReference(recordItem); // Tổng ưu đãi học phí (ko bao gồm ưu đãi đóng sớm) Để tính tổng tiền phải đóng if (settingItem) { const { list_setting_detail } = settingItem; const listSettingLength = list_setting_detail.length; if (listSettingLength === 0) return { totalPromotionReference, totalPromotionComputed }; list_setting_detail.forEach((settingDetail) => { const { code } = settingDetail; switch (code) { case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_POLICY: { totalPromotionComputed += (0, helper_1.generateValue)(total_promotion_tuition_policy); break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_SCHOLARSHIP: { totalPromotionComputed += (0, helper_1.generateValue)(total_promotion_tuition_scholar_ship); break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_SENIORITY: { totalPromotionComputed += (0, helper_1.generateValue)(total_promotion_tuition_seniority); break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_ADMISSION: { totalPromotionComputed += totalPromotionAdmissionForTuition; break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_ADMISSION_SERVICE: { totalPromotionComputed += (0, helper_1.generateValue)(totalPromotionAdmissionForService); break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_SERVICE: { totalPromotionComputed += (0, helper_1.generateValue)(totalPromotionService); break; } case constant_1.SETTING_KEY_EARLY_PROMOTION_TUITION_ADJUSTMENT: { totalPromotionComputed += (0, helper_1.generateValue)(totalFeeAdjustmentTuition); break; } default: { break; } } }); } return { totalPromotionReference, totalPromotionComputed }; } // Tổng ưu đãi học phí (ko bao gồm ưu đãi đóng sớm) Để tính tổng tiền phải đóng getTotalPromotionReference(recordItem // tiến trình đóng phí ) { const { total_promotion_tuition_seniority, total_promotion_tuition_scholar_ship, total_promotion_tuition_policy, tuition_fee_detail_promotions, list_detail_fee_adjustment, } = recordItem; const totalPromotionAdmissionForTuition = (0, helper_1.getTotalDetailPromoByCode)(tuition_fee_detail_promotions, tuition_1.DETAIL_PROMO_TYPE.ADMISSION_TUITION); // Giảm trừ bổ sung cho học phí const adjustmentFees = (0, helper_1.findAdjustmentForTuition)(list_detail_fee_adjustment); const isFeeAdjustment = true; const totalFeeAdjustmentTuition = (0, helper_1.sumTotalFee)(adjustmentFees, isFeeAdjustment); const totalPromotion = (0, helper_1.generateValue)(total_promotion_tuition_seniority) + (0, helper_1.generateValue)(total_promotion_tuition_scholar_ship) + (0, helper_1.generateValue)(total_promotion_tuition_policy) + totalPromotionAdmissionForTuition + totalFeeAdjustmentTuition; return totalPromotion; } getFormulaSettingBySchoolId(listFormulaSetting, schoolId) { return listFormulaSetting.filter(({ school_id }) => school_id === schoolId); } // Công thức giới hạn ưu đãi anh chị em checkIsLimitBySibling(listSetting) { if (listSetting.length === 0) return false; const { list_setting_detail } = listSetting[0]; const { code } = list_setting_detail[0]; // Giới hạn theo con cả return code === constant_1.SETTING_KEY_LIMIT_BY_SIBLING_BY_FIRST_CHILD; } }; exports.PHXSettingFormulaPromotion = PHXSettingFormulaPromotion; exports.PHXSettingFormulaPromotion = PHXSettingFormulaPromotion = PHXSettingFormulaPromotion_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [grpc_client_system_service_1.PHXGrpcClientSystemService]) ], PHXSettingFormulaPromotion); //# sourceMappingURL=tuititon-formular-setting.service.js.map