UNPKG

phx-react

Version:

PHX REACT

237 lines 26.3 kB
"use strict"; exports.__esModule = true; exports.PHXFormTuitionV3 = void 0; var tslib_1 = require("tslib"); var react_1 = tslib_1.__importStar(require("react")); var format_number_1 = require("../../utils/format-number"); var Skeleton_1 = require("../Skeleton"); var EmptyRecord_1 = require("../EmptyRecord"); var constants_1 = require("../../utils/constants"); var clientQueryV3_1 = tslib_1.__importDefault(require("../Func/clientQueryV3")); var query_1 = require("../../query"); var outline_1 = require("@heroicons/react/24/outline"); var PHXFormTuitionV3 = function (_a) { var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; var _m = _a.isProcessByMonth, isProcessByMonth = _m === void 0 ? false : _m, school_id = _a.school_id, school_year_id = _a.school_year_id, setDiscountPromotionObject = _a.setDiscountPromotionObject, setShowModalPromotionObject = _a.setShowModalPromotionObject, setShowModalService = _a.setShowModalService, user_code = _a.user_code; var _o = (0, react_1.useState)(false), isLoadingTable = _o[0], setIsLoadingTable = _o[1]; var _p = (0, react_1.useState)([]), listDebtRecordByStudent = _p[0], setListDebtRecordByStudent = _p[1]; var _q = (0, react_1.useState)([]), listDebtRecordByMonth = _q[0], setListDebtRecordByMonth = _q[1]; var generateValueToView = function (value) { if (!value) return 0; return value > 0 ? (0, format_number_1.toVND)(value) : "(".concat((0, format_number_1.toVND)(-value), ")"); }; var fetchData = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var res, _a, tuition_fee_debt_record, tuition_fee_debt_record_by_month; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: setIsLoadingTable(true); return [4 /*yield*/, (0, clientQueryV3_1["default"])({ query: query_1.getTuitionDebtRecordByUserCodeV3, variables: { school_id: school_id, user_code: user_code, school_year_id: school_year_id } })]; case 1: res = _b.sent(); if (res) { _a = res.data, tuition_fee_debt_record = _a.tuition_fee_debt_record, tuition_fee_debt_record_by_month = _a.tuition_fee_debt_record_by_month; setListDebtRecordByStudent(tuition_fee_debt_record); setListDebtRecordByMonth(tuition_fee_debt_record_by_month); } setIsLoadingTable(false); return [2 /*return*/]; } }); }); }; (0, react_1.useEffect)(function () { if (school_year_id) { fetchData(); } }, [school_year_id, isProcessByMonth]); var checkIsHasPromoPolicy = function (listFee) { return listFee === null || listFee === void 0 ? void 0 : listFee.some(function (item) { return item.total_promotion_tuition_policy; }); }; var totalFeeByCode = function (listData, code) { var total = listData === null || listData === void 0 ? void 0 : listData.reduce( // eslint-disable-next-line @typescript-eslint/no-shadow function (total, item) { return total + Number(item[code]); }, 0); return total; }; var getDebtAndCreditLastYear = function (listDebtRecord) { // Tìm ra dư có và dư có và dư nợ của năm ngoái (chính là bản ghi học kỳ 1) var dataLastYear = listDebtRecord === null || listDebtRecord === void 0 ? void 0 : listDebtRecord.filter(function (item) { var _a; return ((_a = item.school_term) === null || _a === void 0 ? void 0 : _a.coefficient) === constants_1.KEY_COEFFICIENT_SEMESTER_I; }); return dataLastYear || []; }; var getDebtAndCreditCurrentYear = function (listDebtRecord) { // Tìm ra dư có và dư có và dư nợ của năm ngoái (chính là bản ghi học kỳ 1) var dataLastYear = listDebtRecord === null || listDebtRecord === void 0 ? void 0 : listDebtRecord.filter(function (item) { var _a; return ((_a = item.school_term) === null || _a === void 0 ? void 0 : _a.coefficient) === constants_1.KEY_COEFFICIENT_SEMESTER_II; }); return dataLastYear || []; }; // Tạo ra những row detail của các đầu mục lớn vd (1., 2. ...) var createRowDetail = function (title, key) { var listDebtRecord = isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent; var isHasData = listDebtRecord.some(function (item) { return item[key]; }); if (isHasData) { return (react_1["default"].createElement("tr", null, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-white pl-6 text-xs text-gray-900 drop-shadow-md' }, title), listDebtRecord === null || listDebtRecord === void 0 ? void 0 : listDebtRecord.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item[key]))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, key))))); } else { return react_1["default"].createElement(react_1["default"].Fragment, null); } }; var generateIconLock = function (isLocked) { return isLocked ? react_1["default"].createElement(outline_1.LockClosedIcon, { "aria-hidden": 'true', className: 'ml-1 h-4 w-4' }) : react_1["default"].createElement(react_1["default"].Fragment, null); }; var getIsLockedYear = function (listDebtRecord) { return listDebtRecord.every(function (_a) { var is_locked = _a.is_locked; return is_locked === true; }); }; return (react_1["default"].createElement(react_1["default"].Fragment, null, isLoadingTable ? (react_1["default"].createElement(Skeleton_1.PHXSkeleton, { type: 'table' })) : listDebtRecordByStudent.length > 0 ? (react_1["default"].createElement("div", { className: 'rounded-lg bg-white shadow ring-1 ring-black ring-opacity-5' }, react_1["default"].createElement("div", { className: 'overflow-x-auto rounded-lg' }, react_1["default"].createElement("div", { className: 'min-w-full align-middle shadow ring-black ring-opacity-5' }, react_1["default"].createElement("div", { className: 'relative overflow-auto' }, react_1["default"].createElement("table", { className: 'w-full table-fixed border-separate border-spacing-0\t divide-y divide-gray-300' }, react_1["default"].createElement("thead", null, react_1["default"].createElement("tr", null, react_1["default"].createElement("th", { className: 'sticky left-0 w-[210px] border-r bg-white px-3 py-2 pl-8 text-left align-top text-xs font-semibold text-gray-500 drop-shadow-md xl:drop-shadow-none', scope: 'col' }, "Chi ti\u1EBFt kho\u1EA3n ph\u00ED"), (_b = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _b === void 0 ? void 0 : _b.map(function (item, index) { var _a, _b; return (react_1["default"].createElement("th", { key: index, className: 'w-[210px] border-r bg-white px-3 py-2 pl-2 text-left align-top text-xs font-semibold text-gray-500', scope: 'col' }, react_1["default"].createElement("p", { className: 'flex text-center' }, isProcessByMonth ? (_a = item.school_month) === null || _a === void 0 ? void 0 : _a.name : (_b = item.school_term) === null || _b === void 0 ? void 0 : _b.name, generateIconLock(item.is_locked)))); }), react_1["default"].createElement("th", { className: 'w-[210px] bg-white px-3 py-2 pl-2 text-left align-top text-xs font-semibold text-gray-500', scope: 'col' }, react_1["default"].createElement("p", { className: 'flex text-center' }, "C\u1EA3 n\u0103m", generateIconLock(getIsLockedYear(isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)))))), react_1["default"].createElement("tbody", { className: 'divide-y divide-gray-200 bg-white' }, react_1["default"].createElement("tr", { className: 'bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "1. D\u01B0 n\u1EE3 \u0111\u1EA7u k\u1EF3"), (_c = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _c === void 0 ? void 0 : _c.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(item.last_period_debt_balance - item.last_period_credit_balance))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(totalFeeByCode(getDebtAndCreditLastYear(listDebtRecordByStudent), 'last_period_debt_balance') - totalFeeByCode(getDebtAndCreditLastYear(listDebtRecordByStudent), 'last_period_credit_balance')))), react_1["default"].createElement("tr", { className: 'bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "2. Kho\u1EA3n thu"), (_d = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _d === void 0 ? void 0 : _d.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_tuition + item.total_required_service + item.total_not_required_service + item.total_adjustment_additional))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_tuition') + totalFeeByCode(listDebtRecordByStudent, 'total_required_service') + totalFeeByCode(listDebtRecordByStudent, 'total_not_required_service') + totalFeeByCode(listDebtRecordByStudent, 'total_adjustment_additional')))), react_1["default"].createElement("tr", null, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-white pl-6 text-xs text-gray-900 drop-shadow-md' }, "H\u1ECDc ph\u00ED ni\u00EAm y\u1EBFt"), (_e = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _e === void 0 ? void 0 : _e.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_tuition))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_tuition')))), react_1["default"].createElement("tr", { className: "".concat(setShowModalService ? 'hover:cursor-pointer hover:bg-gray-50' : ''), onClick: function () { if (!setShowModalService) { return; } setShowModalService(true); } }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-white pl-6 text-xs text-gray-900 drop-shadow-md' }, "D\u1ECBch v\u1EE5 b\u1EAFt bu\u1ED9c"), (_f = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _f === void 0 ? void 0 : _f.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_required_service))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_required_service')))), createRowDetail('Dịch vụ tuỳ chọn', 'total_not_required_service'), createRowDetail('Phí phụ thu', 'total_adjustment_additional'), react_1["default"].createElement("tr", { className: 'bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "3. Kho\u1EA3n gi\u1EA3m tr\u1EEB"), (_g = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _g === void 0 ? void 0 : _g.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_promotion_early + item.total_promotion_tuition_scholar_ship + item.total_promotion_tuition_policy + item.total_promotion_tuition_seniority + item.total_promotion_admission + item.total_promotion_service + item.total_adjustment_refund + item.total_refund))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_promotion_early') + totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_scholar_ship') + totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_policy') + totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_seniority') + totalFeeByCode(listDebtRecordByStudent, 'total_promotion_admission') + totalFeeByCode(listDebtRecordByStudent, 'total_promotion_service') + totalFeeByCode(listDebtRecordByStudent, 'total_adjustment_refund') + totalFeeByCode(listDebtRecordByStudent, 'total_refund')))), createRowDetail('Ưu đãi đóng sớm', 'total_promotion_early'), createRowDetail('Ưu đãi học bổng', 'total_promotion_tuition_scholar_ship'), checkIsHasPromoPolicy(listDebtRecordByStudent) && (react_1["default"].createElement("tr", { className: "".concat(setShowModalPromotionObject ? 'hover:cursor-pointer hover:bg-gray-50' : ''), onClick: function () { if (!setShowModalPromotionObject) { return; } setShowModalPromotionObject(true); setDiscountPromotionObject(Number((totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_policy') / totalFeeByCode(listDebtRecordByStudent, 'total_tuition')) * 100).toFixed(1)); } }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-white pl-6 text-xs text-gray-900 drop-shadow-md' }, "\u01AFu \u0111\u00E3i \u0111\u1ED1i t\u01B0\u1EE3ng"), (_h = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _h === void 0 ? void 0 : _h.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_promotion_tuition_policy))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_policy'))))), createRowDetail('Ưu đãi thâm niên', 'total_promotion_tuition_seniority'), createRowDetail('Ưu đãi tuyển sinh', 'total_promotion_admission'), createRowDetail('Ưu đãi phí dịch vụ', 'total_promotion_service'), createRowDetail('Giảm trừ bổ sung', 'total_adjustment_refund'), createRowDetail('Hoàn tiền dịch vụ', 'total_refund'), react_1["default"].createElement("tr", { className: 'bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "4. Ph\u1EA3i thu (4=1+2-3)"), (_j = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _j === void 0 ? void 0 : _j.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(item.last_period_debt_balance + item.total_tuition + item.total_required_service + item.total_not_required_service + item.total_adjustment_additional - item.total_promotion_early - item.total_promotion_tuition_scholar_ship - item.total_promotion_tuition_policy - item.total_promotion_tuition_seniority - item.total_promotion_admission - item.total_promotion_service - item.total_adjustment_refund - item.total_refund - item.last_period_credit_balance))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(totalFeeByCode(getDebtAndCreditLastYear(listDebtRecordByStudent), 'last_period_debt_balance') + totalFeeByCode(listDebtRecordByStudent, 'total_tuition') + totalFeeByCode(listDebtRecordByStudent, 'total_required_service') + totalFeeByCode(listDebtRecordByStudent, 'total_not_required_service') + totalFeeByCode(listDebtRecordByStudent, 'total_adjustment_additional') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_early') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_scholar_ship') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_policy') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_tuition_seniority') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_admission') - totalFeeByCode(listDebtRecordByStudent, 'total_promotion_service') - totalFeeByCode(listDebtRecordByStudent, 'total_adjustment_refund') - totalFeeByCode(listDebtRecordByStudent, 'total_refund') - totalFeeByCode(getDebtAndCreditLastYear(listDebtRecordByStudent), 'last_period_credit_balance')))), react_1["default"].createElement("tr", { className: 'border-t bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "5. \u0110\u00E3 \u0111\u00F3ng"), (_k = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _k === void 0 ? void 0 : _k.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(item.total_payment))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, (0, format_number_1.toVND)(totalFeeByCode(listDebtRecordByStudent, 'total_payment')))), react_1["default"].createElement("tr", { className: 'border-t bg-gray-100' }, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-gray-100 pl-2 text-xs text-gray-900 drop-shadow-md' }, "6. Ti\u1EC1n thi\u1EBFu/(th\u1EEBa)"), (_l = (isProcessByMonth ? listDebtRecordByMonth : listDebtRecordByStudent)) === null || _l === void 0 ? void 0 : _l.map(function (item, index) { return (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(item.last_debt_balance - item.last_credit_balance))); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' }, generateValueToView(totalFeeByCode(getDebtAndCreditCurrentYear(listDebtRecordByStudent), 'last_debt_balance') - totalFeeByCode(getDebtAndCreditCurrentYear(listDebtRecordByStudent), 'last_credit_balance')))), !isProcessByMonth && (react_1["default"].createElement("tr", null, react_1["default"].createElement("td", { className: 'sticky left-0 whitespace-nowrap border-r border-t bg-white pl-2 text-xs text-gray-900 drop-shadow-md' }, "7. File PDF thu ph\u00ED"), listDebtRecordByStudent === null || listDebtRecordByStudent === void 0 ? void 0 : listDebtRecordByStudent.map(function (itemDebt, index) { var _a, _b; var linkDeliveredEmail = ((_a = itemDebt.profile_student) === null || _a === void 0 ? void 0 : _a.tuition_notice_delivered_emails) || []; var listEmailFilterWithSchoolTermId = (linkDeliveredEmail === null || linkDeliveredEmail === void 0 ? void 0 : linkDeliveredEmail.filter(function (item) { var _a, _b; return ((_a = itemDebt.school_term) === null || _a === void 0 ? void 0 : _a.id) === ((_b = item.tuition_notice_campaign) === null || _b === void 0 ? void 0 : _b.school_term_id); })) || []; var linkPdfNewest = ''; if (listEmailFilterWithSchoolTermId.length > 0) { linkPdfNewest = (_b = listEmailFilterWithSchoolTermId[0]) === null || _b === void 0 ? void 0 : _b.link_pdf_cdn; } return linkPdfNewest ? (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, react_1["default"].createElement("a", { // ref={linkRef} className: 'pt-3 text-xs text-blue-600 hover:cursor-pointer hover:text-blue-800 hover:underline', href: linkPdfNewest, rel: 'noreferrer', target: '_blank' }, "pdf file"))) : (react_1["default"].createElement("td", { key: index, className: 'whitespace-nowrap border-r border-t px-2 py-2 text-xs text-gray-900' }, "---")); }), react_1["default"].createElement("td", { className: 'whitespace-nowrap border-t px-2 py-2 text-xs text-gray-900' })))))))))) : (react_1["default"].createElement(EmptyRecord_1.PHXEmptyRecord, null)))); }; exports.PHXFormTuitionV3 = PHXFormTuitionV3; //# sourceMappingURL=FormTuitionV3.js.map