Add professor share calculation and financial reporting feature
Introduces per-class payout configuration (percentage or hourly rate, plus an optional per-session expense allowance), pure calculation utilities for professor payout/net profit/receivables, and a new financial-reports API surface with per-class, per-session, and date-range/monthly reports. Also adds full CRUD for institutional expenses used in the range report, and wires up the new permissions and roles. Fixes a pre-existing ReferenceError (missing parseImportDate import) in paymentService that blocked creating payments with dated transactions.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// /components/expenses/expenseValidator.js
|
||||
'use strict';
|
||||
|
||||
const AppError = require('../../utils/AppError');
|
||||
|
||||
const validateBody = (body, { isUpdate = false } = {}) => {
|
||||
const details = {};
|
||||
|
||||
if (!isUpdate || body.title !== undefined) {
|
||||
if (!body.title || !String(body.title).trim()) {
|
||||
details.title = 'عنوان هزینه الزامی است';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUpdate || body.amount !== undefined) {
|
||||
if (body.amount === undefined || body.amount === null || Number(body.amount) <= 0) {
|
||||
details.amount = 'مبلغ هزینه باید بیشتر از صفر باشد';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUpdate || body.date !== undefined) {
|
||||
if (!body.date || Number.isNaN(new Date(body.date).getTime())) {
|
||||
details.date = 'تاریخ هزینه الزامی و باید معتبر باشد';
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(details).length) {
|
||||
throw new AppError('VALIDATION_FAILED', details);
|
||||
}
|
||||
};
|
||||
|
||||
const validateCreateExpense = (req, res, next) => {
|
||||
try {
|
||||
validateBody(req.body, { isUpdate: false });
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
|
||||
const validateUpdateExpense = (req, res, next) => {
|
||||
try {
|
||||
validateBody(req.body, { isUpdate: true });
|
||||
next();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { validateCreateExpense, validateUpdateExpense };
|
||||
Reference in New Issue
Block a user