1.01
This commit is contained in:
parent
024da168eb
commit
71b041b726
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*/node_modules/
|
*/node_modules/
|
||||||
*/build/
|
*/build/
|
||||||
|
|
||||||
|
**/node_modules/
|
||||||
|
**/build/
|
||||||
|
.DS_Store
|
||||||
|
.env
|
||||||
File diff suppressed because one or more lines are too long
602
backend/src/db/api/payment.js
Normal file
602
backend/src/db/api/payment.js
Normal file
@ -0,0 +1,602 @@
|
|||||||
|
const db = require('../models');
|
||||||
|
const FileDBApi = require('./file');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const Utils = require('../utils');
|
||||||
|
|
||||||
|
const Sequelize = db.Sequelize;
|
||||||
|
const Op = Sequelize.Op;
|
||||||
|
|
||||||
|
module.exports = class PaymentDBApi {
|
||||||
|
static async create(data, options) {
|
||||||
|
const currentUser = (options && options.currentUser) || { id: null };
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
const payment = await db.payment.create(
|
||||||
|
{
|
||||||
|
id: data.id || undefined,
|
||||||
|
|
||||||
|
amountpaid: data.amountpaid || null,
|
||||||
|
paymentmode: data.paymentmode || null,
|
||||||
|
chequeno: data.chequeno || null,
|
||||||
|
bankname: data.bankname || null,
|
||||||
|
transactionid: data.transactionid || null,
|
||||||
|
ddnumber: data.ddnumber || null,
|
||||||
|
ddissuingbank: data.ddissuingbank || null,
|
||||||
|
receiptnumber: data.receiptnumber || null,
|
||||||
|
discountpercentage: data.discountpercentage || null,
|
||||||
|
discountamount: data.discountamount || null,
|
||||||
|
discountreason: data.discountreason || null,
|
||||||
|
ddissuedate: data.ddissuedate || null,
|
||||||
|
remainingbalance: data.remainingbalance || null,
|
||||||
|
paymentdate: data.paymentdate || null,
|
||||||
|
importHash: data.importHash || null,
|
||||||
|
createdById: currentUser.id,
|
||||||
|
updatedById: currentUser.id,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await payment.setStudent(data.student || null, {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await payment.setInvoice(data.invoice || null, {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async bulkImport(data, options) {
|
||||||
|
const currentUser = (options && options.currentUser) || { id: null };
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
// Prepare data - wrapping individual data transformations in a map() method
|
||||||
|
const paymentData = data.map((item, index) => ({
|
||||||
|
id: item.id || undefined,
|
||||||
|
|
||||||
|
amountpaid: item.amountpaid || null,
|
||||||
|
paymentmode: item.paymentmode || null,
|
||||||
|
chequeno: item.chequeno || null,
|
||||||
|
bankname: item.bankname || null,
|
||||||
|
transactionid: item.transactionid || null,
|
||||||
|
ddnumber: item.ddnumber || null,
|
||||||
|
ddissuingbank: item.ddissuingbank || null,
|
||||||
|
receiptnumber: item.receiptnumber || null,
|
||||||
|
discountpercentage: item.discountpercentage || null,
|
||||||
|
discountamount: item.discountamount || null,
|
||||||
|
discountreason: item.discountreason || null,
|
||||||
|
ddissuedate: item.ddissuedate || null,
|
||||||
|
remainingbalance: item.remainingbalance || null,
|
||||||
|
paymentdate: item.paymentdate || null,
|
||||||
|
importHash: item.importHash || null,
|
||||||
|
createdById: currentUser.id,
|
||||||
|
updatedById: currentUser.id,
|
||||||
|
createdAt: new Date(Date.now() + index * 1000),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Bulk create items
|
||||||
|
const payment = await db.payment.bulkCreate(paymentData, { transaction });
|
||||||
|
|
||||||
|
// For each item created, replace relation files
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async update(id, data, options) {
|
||||||
|
const currentUser = (options && options.currentUser) || { id: null };
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
const payment = await db.payment.findByPk(id, {}, { transaction });
|
||||||
|
|
||||||
|
const updatePayload = {};
|
||||||
|
|
||||||
|
if (data.amountpaid !== undefined)
|
||||||
|
updatePayload.amountpaid = data.amountpaid;
|
||||||
|
|
||||||
|
if (data.paymentmode !== undefined)
|
||||||
|
updatePayload.paymentmode = data.paymentmode;
|
||||||
|
|
||||||
|
if (data.chequeno !== undefined) updatePayload.chequeno = data.chequeno;
|
||||||
|
|
||||||
|
if (data.bankname !== undefined) updatePayload.bankname = data.bankname;
|
||||||
|
|
||||||
|
if (data.transactionid !== undefined)
|
||||||
|
updatePayload.transactionid = data.transactionid;
|
||||||
|
|
||||||
|
if (data.ddnumber !== undefined) updatePayload.ddnumber = data.ddnumber;
|
||||||
|
|
||||||
|
if (data.ddissuingbank !== undefined)
|
||||||
|
updatePayload.ddissuingbank = data.ddissuingbank;
|
||||||
|
|
||||||
|
if (data.receiptnumber !== undefined)
|
||||||
|
updatePayload.receiptnumber = data.receiptnumber;
|
||||||
|
|
||||||
|
if (data.discountpercentage !== undefined)
|
||||||
|
updatePayload.discountpercentage = data.discountpercentage;
|
||||||
|
|
||||||
|
if (data.discountamount !== undefined)
|
||||||
|
updatePayload.discountamount = data.discountamount;
|
||||||
|
|
||||||
|
if (data.discountreason !== undefined)
|
||||||
|
updatePayload.discountreason = data.discountreason;
|
||||||
|
|
||||||
|
if (data.ddissuedate !== undefined)
|
||||||
|
updatePayload.ddissuedate = data.ddissuedate;
|
||||||
|
|
||||||
|
if (data.remainingbalance !== undefined)
|
||||||
|
updatePayload.remainingbalance = data.remainingbalance;
|
||||||
|
|
||||||
|
if (data.paymentdate !== undefined)
|
||||||
|
updatePayload.paymentdate = data.paymentdate;
|
||||||
|
|
||||||
|
updatePayload.updatedById = currentUser.id;
|
||||||
|
|
||||||
|
await payment.update(updatePayload, { transaction });
|
||||||
|
|
||||||
|
if (data.student !== undefined) {
|
||||||
|
await payment.setStudent(
|
||||||
|
data.student,
|
||||||
|
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.invoice !== undefined) {
|
||||||
|
await payment.setInvoice(
|
||||||
|
data.invoice,
|
||||||
|
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async deleteByIds(ids, options) {
|
||||||
|
const currentUser = (options && options.currentUser) || { id: null };
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
const payment = await db.payment.findAll({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
[Op.in]: ids,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sequelize.transaction(async (transaction) => {
|
||||||
|
for (const record of payment) {
|
||||||
|
await record.update({ deletedBy: currentUser.id }, { transaction });
|
||||||
|
}
|
||||||
|
for (const record of payment) {
|
||||||
|
await record.destroy({ transaction });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async remove(id, options) {
|
||||||
|
const currentUser = (options && options.currentUser) || { id: null };
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
const payment = await db.payment.findByPk(id, options);
|
||||||
|
|
||||||
|
await payment.update(
|
||||||
|
{
|
||||||
|
deletedBy: currentUser.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
transaction,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
await payment.destroy({
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async findBy(where, options) {
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
const payment = await db.payment.findOne({ where }, { transaction });
|
||||||
|
|
||||||
|
if (!payment) {
|
||||||
|
return payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = payment.get({ plain: true });
|
||||||
|
|
||||||
|
output.student = await payment.getStudent({
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
output.invoice = await payment.getInvoice({
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async findAll(filter, options) {
|
||||||
|
const limit = filter.limit || 0;
|
||||||
|
let offset = 0;
|
||||||
|
let where = {};
|
||||||
|
const currentPage = +filter.page;
|
||||||
|
|
||||||
|
offset = currentPage * limit;
|
||||||
|
|
||||||
|
const orderBy = null;
|
||||||
|
|
||||||
|
const transaction = (options && options.transaction) || undefined;
|
||||||
|
|
||||||
|
let include = [
|
||||||
|
{
|
||||||
|
model: db.students,
|
||||||
|
as: 'student',
|
||||||
|
|
||||||
|
where: filter.student
|
||||||
|
? {
|
||||||
|
[Op.or]: [
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
[Op.in]: filter.student
|
||||||
|
.split('|')
|
||||||
|
.map((term) => Utils.uuid(term)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: {
|
||||||
|
[Op.or]: filter.student
|
||||||
|
.split('|')
|
||||||
|
.map((term) => ({ [Op.iLike]: `%${term}%` })),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
model: db.fees,
|
||||||
|
as: 'invoice',
|
||||||
|
|
||||||
|
where: filter.invoice
|
||||||
|
? {
|
||||||
|
[Op.or]: [
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
[Op.in]: filter.invoice
|
||||||
|
.split('|')
|
||||||
|
.map((term) => Utils.uuid(term)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: {
|
||||||
|
[Op.or]: filter.invoice
|
||||||
|
.split('|')
|
||||||
|
.map((term) => ({ [Op.iLike]: `%${term}%` })),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (filter) {
|
||||||
|
if (filter.id) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
['id']: Utils.uuid(filter.id),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.chequeno) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike('payment', 'chequeno', filter.chequeno),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.bankname) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike('payment', 'bankname', filter.bankname),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.transactionid) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike(
|
||||||
|
'payment',
|
||||||
|
'transactionid',
|
||||||
|
filter.transactionid,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ddnumber) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike('payment', 'ddnumber', filter.ddnumber),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ddissuingbank) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike(
|
||||||
|
'payment',
|
||||||
|
'ddissuingbank',
|
||||||
|
filter.ddissuingbank,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.receiptnumber) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike(
|
||||||
|
'payment',
|
||||||
|
'receiptnumber',
|
||||||
|
filter.receiptnumber,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.discountreason) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
[Op.and]: Utils.ilike(
|
||||||
|
'payment',
|
||||||
|
'discountreason',
|
||||||
|
filter.discountreason,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.amountpaidRange) {
|
||||||
|
const [start, end] = filter.amountpaidRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
amountpaid: {
|
||||||
|
...where.amountpaid,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
amountpaid: {
|
||||||
|
...where.amountpaid,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.discountpercentageRange) {
|
||||||
|
const [start, end] = filter.discountpercentageRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
discountpercentage: {
|
||||||
|
...where.discountpercentage,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
discountpercentage: {
|
||||||
|
...where.discountpercentage,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.discountamountRange) {
|
||||||
|
const [start, end] = filter.discountamountRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
discountamount: {
|
||||||
|
...where.discountamount,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
discountamount: {
|
||||||
|
...where.discountamount,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ddissuedateRange) {
|
||||||
|
const [start, end] = filter.ddissuedateRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
ddissuedate: {
|
||||||
|
...where.ddissuedate,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
ddissuedate: {
|
||||||
|
...where.ddissuedate,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.remainingbalanceRange) {
|
||||||
|
const [start, end] = filter.remainingbalanceRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
remainingbalance: {
|
||||||
|
...where.remainingbalance,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
remainingbalance: {
|
||||||
|
...where.remainingbalance,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.paymentdateRange) {
|
||||||
|
const [start, end] = filter.paymentdateRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
paymentdate: {
|
||||||
|
...where.paymentdate,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
paymentdate: {
|
||||||
|
...where.paymentdate,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.active !== undefined) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
active: filter.active === true || filter.active === 'true',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.paymentmode) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
paymentmode: filter.paymentmode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.createdAtRange) {
|
||||||
|
const [start, end] = filter.createdAtRange;
|
||||||
|
|
||||||
|
if (start !== undefined && start !== null && start !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
['createdAt']: {
|
||||||
|
...where.createdAt,
|
||||||
|
[Op.gte]: start,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end !== undefined && end !== null && end !== '') {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
['createdAt']: {
|
||||||
|
...where.createdAt,
|
||||||
|
[Op.lte]: end,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryOptions = {
|
||||||
|
where,
|
||||||
|
include,
|
||||||
|
distinct: true,
|
||||||
|
order:
|
||||||
|
filter.field && filter.sort
|
||||||
|
? [[filter.field, filter.sort]]
|
||||||
|
: [['createdAt', 'desc']],
|
||||||
|
transaction: options?.transaction,
|
||||||
|
logging: console.log,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!options?.countOnly) {
|
||||||
|
queryOptions.limit = limit ? Number(limit) : undefined;
|
||||||
|
queryOptions.offset = offset ? Number(offset) : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { rows, count } = await db.payment.findAndCountAll(queryOptions);
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows: options?.countOnly ? [] : rows,
|
||||||
|
count: count,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error executing query:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async findAllAutocomplete(query, limit, offset) {
|
||||||
|
let where = {};
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
where = {
|
||||||
|
[Op.or]: [
|
||||||
|
{ ['id']: Utils.uuid(query) },
|
||||||
|
Utils.ilike('payment', 'amountpaid', query),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const records = await db.payment.findAll({
|
||||||
|
attributes: ['id', 'amountpaid'],
|
||||||
|
where,
|
||||||
|
limit: limit ? Number(limit) : undefined,
|
||||||
|
offset: offset ? Number(offset) : undefined,
|
||||||
|
orderBy: [['amountpaid', 'ASC']],
|
||||||
|
});
|
||||||
|
|
||||||
|
return records.map((record) => ({
|
||||||
|
id: record.id,
|
||||||
|
label: record.amountpaid,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
72
backend/src/db/migrations/1751746080332.js
Normal file
72
backend/src/db/migrations/1751746080332.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.createTable(
|
||||||
|
'payment',
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
type: Sequelize.DataTypes.UUID,
|
||||||
|
defaultValue: Sequelize.DataTypes.UUIDV4,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
createdById: {
|
||||||
|
type: Sequelize.DataTypes.UUID,
|
||||||
|
references: {
|
||||||
|
key: 'id',
|
||||||
|
model: 'users',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
updatedById: {
|
||||||
|
type: Sequelize.DataTypes.UUID,
|
||||||
|
references: {
|
||||||
|
key: 'id',
|
||||||
|
model: 'users',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createdAt: { type: Sequelize.DataTypes.DATE },
|
||||||
|
updatedAt: { type: Sequelize.DataTypes.DATE },
|
||||||
|
deletedAt: { type: Sequelize.DataTypes.DATE },
|
||||||
|
importHash: {
|
||||||
|
type: Sequelize.DataTypes.STRING(255),
|
||||||
|
allowNull: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.dropTable('payment', { transaction });
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
51
backend/src/db/migrations/1751746246913.js
Normal file
51
backend/src/db/migrations/1751746246913.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'paymentmode',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.ENUM,
|
||||||
|
|
||||||
|
values: ['value'],
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'paymentmode', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
47
backend/src/db/migrations/1751746291276.js
Normal file
47
backend/src/db/migrations/1751746291276.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'chequeno',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'chequeno', { transaction });
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
47
backend/src/db/migrations/1751746323389.js
Normal file
47
backend/src/db/migrations/1751746323389.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'bankname',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'bankname', { transaction });
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746355023.js
Normal file
49
backend/src/db/migrations/1751746355023.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'transactionid',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'transactionid', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
47
backend/src/db/migrations/1751746389970.js
Normal file
47
backend/src/db/migrations/1751746389970.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'ddnumber',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'ddnumber', { transaction });
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746418978.js
Normal file
49
backend/src/db/migrations/1751746418978.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'ddissuingbank',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'ddissuingbank', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746452878.js
Normal file
49
backend/src/db/migrations/1751746452878.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'receiptnumber',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'receiptnumber', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746485119.js
Normal file
49
backend/src/db/migrations/1751746485119.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'discountpercentage',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'discountpercentage', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746520699.js
Normal file
49
backend/src/db/migrations/1751746520699.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'discountamount',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'discountamount', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746554451.js
Normal file
49
backend/src/db/migrations/1751746554451.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'discountreason',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'discountreason', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746599620.js
Normal file
49
backend/src/db/migrations/1751746599620.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'ddissuedate',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.DATE,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'ddissuedate', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746638160.js
Normal file
49
backend/src/db/migrations/1751746638160.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'remainingbalance',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'remainingbalance', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
49
backend/src/db/migrations/1751746667725.js
Normal file
49
backend/src/db/migrations/1751746667725.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.addColumn(
|
||||||
|
'payment',
|
||||||
|
'paymentdate',
|
||||||
|
{
|
||||||
|
type: Sequelize.DataTypes.DATE,
|
||||||
|
},
|
||||||
|
{ transaction },
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {QueryInterface} queryInterface
|
||||||
|
* @param {Sequelize} Sequelize
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
/**
|
||||||
|
* @type {Transaction}
|
||||||
|
*/
|
||||||
|
const transaction = await queryInterface.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await queryInterface.removeColumn('payment', 'paymentdate', {
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
177
backend/src/db/models/payment.js
Normal file
177
backend/src/db/models/payment.js
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
const config = require('../../config');
|
||||||
|
const providers = config.providers;
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const bcrypt = require('bcrypt');
|
||||||
|
const moment = require('moment');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
|
||||||
|
module.exports = function (sequelize, DataTypes) {
|
||||||
|
const payment = sequelize.define(
|
||||||
|
'payment',
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
defaultValue: DataTypes.UUIDV4,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
amountpaid: {
|
||||||
|
type: DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
|
||||||
|
paymentmode: {
|
||||||
|
type: DataTypes.ENUM,
|
||||||
|
|
||||||
|
values: ['value'],
|
||||||
|
},
|
||||||
|
|
||||||
|
chequeno: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
bankname: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
transactionid: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
ddnumber: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
ddissuingbank: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
receiptnumber: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
discountpercentage: {
|
||||||
|
type: DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
|
||||||
|
discountamount: {
|
||||||
|
type: DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
|
||||||
|
discountreason: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
},
|
||||||
|
|
||||||
|
ddissuedate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
},
|
||||||
|
|
||||||
|
remainingbalance: {
|
||||||
|
type: DataTypes.DECIMAL,
|
||||||
|
},
|
||||||
|
|
||||||
|
paymentdate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
},
|
||||||
|
|
||||||
|
importHash: {
|
||||||
|
type: DataTypes.STRING(255),
|
||||||
|
allowNull: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: true,
|
||||||
|
paranoid: true,
|
||||||
|
freezeTableName: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
// Hooks for receipt number generation and balance calculations
|
||||||
|
payment.addHook('beforeCreate', async (paymentInstance, options) => {
|
||||||
|
// Generate receipt number: YYYY-MM-sequence
|
||||||
|
const datePart = moment().format('YYYY-MM');
|
||||||
|
// Count existing payments this month
|
||||||
|
const count = await sequelize.models.payment.count({
|
||||||
|
where: Sequelize.where(
|
||||||
|
Sequelize.fn('to_char', Sequelize.col('createdAt'), 'YYYY-MM'),
|
||||||
|
datePart
|
||||||
|
),
|
||||||
|
transaction: options.transaction,
|
||||||
|
});
|
||||||
|
paymentInstance.receiptnumber = `${datePart}-${count + 1}`;
|
||||||
|
// Default payment date
|
||||||
|
if (!paymentInstance.paymentdate) {
|
||||||
|
paymentInstance.paymentdate = new Date();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
payment.addHook('afterCreate', async (paymentInstance, options) => {
|
||||||
|
const transaction = options.transaction;
|
||||||
|
// Update invoice outstanding if linked
|
||||||
|
if (paymentInstance.invoiceId) {
|
||||||
|
const feeRecord = await sequelize.models.fees.findByPk(
|
||||||
|
paymentInstance.invoiceId,
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
if (feeRecord) {
|
||||||
|
const newOutstanding = parseFloat(feeRecord.outstanding || 0) - parseFloat(paymentInstance.amountpaid || 0);
|
||||||
|
feeRecord.outstanding = newOutstanding;
|
||||||
|
if (newOutstanding <= 0) {
|
||||||
|
feeRecord.status = 'Paid';
|
||||||
|
}
|
||||||
|
await feeRecord.save({ transaction });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update student overall outstanding balance
|
||||||
|
if (paymentInstance.studentId) {
|
||||||
|
const studentRecord = await sequelize.models.students.findByPk(
|
||||||
|
paymentInstance.studentId,
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
if (studentRecord) {
|
||||||
|
const newBal = parseFloat(studentRecord.outstanding || 0) - parseFloat(paymentInstance.amountpaid || 0);
|
||||||
|
studentRecord.outstanding = newBal;
|
||||||
|
await studentRecord.save({ transaction });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Trigger notifications
|
||||||
|
try {
|
||||||
|
const notifyHelper = require('../../services/notifications/helpers');
|
||||||
|
await notifyHelper.sendPaymentNotification(paymentInstance);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Payment notification error:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
payment.associate = (db) => {
|
||||||
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
||||||
|
|
||||||
|
//end loop
|
||||||
|
|
||||||
|
db.payment.belongsTo(db.students, {
|
||||||
|
as: 'student',
|
||||||
|
foreignKey: {
|
||||||
|
name: 'studentId',
|
||||||
|
},
|
||||||
|
constraints: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
db.payment.belongsTo(db.fees, {
|
||||||
|
as: 'invoice',
|
||||||
|
foreignKey: {
|
||||||
|
name: 'invoiceId',
|
||||||
|
},
|
||||||
|
constraints: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
db.payment.belongsTo(db.users, {
|
||||||
|
as: 'createdBy',
|
||||||
|
});
|
||||||
|
|
||||||
|
db.payment.belongsTo(db.users, {
|
||||||
|
as: 'updatedBy',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return payment;
|
||||||
|
};
|
||||||
@ -118,6 +118,7 @@ module.exports = {
|
|||||||
'students',
|
'students',
|
||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
|
'payment',
|
||||||
,
|
,
|
||||||
];
|
];
|
||||||
await queryInterface.bulkInsert(
|
await queryInterface.bulkInsert(
|
||||||
@ -1573,6 +1574,31 @@ primary key ("roles_permissionsId", "permissionId")
|
|||||||
permissionId: getId('DELETE_PERMISSIONS'),
|
permissionId: getId('DELETE_PERMISSIONS'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
roles_permissionsId: getId('Administrator'),
|
||||||
|
permissionId: getId('CREATE_PAYMENT'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
roles_permissionsId: getId('Administrator'),
|
||||||
|
permissionId: getId('READ_PAYMENT'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
roles_permissionsId: getId('Administrator'),
|
||||||
|
permissionId: getId('UPDATE_PAYMENT'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
roles_permissionsId: getId('Administrator'),
|
||||||
|
permissionId: getId('DELETE_PAYMENT'),
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
|
|||||||
@ -23,6 +23,8 @@ const Library = db.library;
|
|||||||
|
|
||||||
const Students = db.students;
|
const Students = db.students;
|
||||||
|
|
||||||
|
const Payment = db.payment;
|
||||||
|
|
||||||
const AdmissionsData = [
|
const AdmissionsData = [
|
||||||
{
|
{
|
||||||
application_id: 'A001',
|
application_id: 'A001',
|
||||||
@ -49,7 +51,7 @@ const AdmissionsData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
status: 'Rejected',
|
status: 'Accepted',
|
||||||
|
|
||||||
application_date: new Date('2023-09-03'),
|
application_date: new Date('2023-09-03'),
|
||||||
},
|
},
|
||||||
@ -59,10 +61,20 @@ const AdmissionsData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
status: 'Rejected',
|
status: 'Pending',
|
||||||
|
|
||||||
application_date: new Date('2023-09-04'),
|
application_date: new Date('2023-09-04'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
application_id: 'A005',
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
status: 'Pending',
|
||||||
|
|
||||||
|
application_date: new Date('2023-09-05'),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const AttendanceData = [
|
const AttendanceData = [
|
||||||
@ -105,6 +117,16 @@ const AttendanceData = [
|
|||||||
|
|
||||||
present: true,
|
present: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
date: new Date('2023-09-10'),
|
||||||
|
|
||||||
|
present: true,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const CoursesData = [
|
const CoursesData = [
|
||||||
@ -139,6 +161,14 @@ const CoursesData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
course_name: 'Biology Basics',
|
||||||
|
|
||||||
|
course_code: 'BIO101',
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const DepartmentsData = [
|
const DepartmentsData = [
|
||||||
@ -165,6 +195,12 @@ const DepartmentsData = [
|
|||||||
|
|
||||||
head_of_department: 'Dr. Marie Curie',
|
head_of_department: 'Dr. Marie Curie',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'Biology',
|
||||||
|
|
||||||
|
head_of_department: 'Dr. Charles Darwin',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const EventsData = [
|
const EventsData = [
|
||||||
@ -199,6 +235,14 @@ const EventsData = [
|
|||||||
|
|
||||||
end_date: new Date('2023-12-05'),
|
end_date: new Date('2023-12-05'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
event_name: 'Alumni Meet',
|
||||||
|
|
||||||
|
start_date: new Date('2023-12-15'),
|
||||||
|
|
||||||
|
end_date: new Date('2023-12-15'),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ExamsData = [
|
const ExamsData = [
|
||||||
@ -233,6 +277,14 @@ const ExamsData = [
|
|||||||
|
|
||||||
exam_date: new Date('2023-11-05'),
|
exam_date: new Date('2023-11-05'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
exam_name: 'Project Presentation',
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
exam_date: new Date('2023-11-30'),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const FacultyData = [
|
const FacultyData = [
|
||||||
@ -275,19 +327,19 @@ const FacultyData = [
|
|||||||
|
|
||||||
// type code here for "relation_many" field
|
// type code here for "relation_many" field
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
first_name: 'Angela',
|
||||||
|
|
||||||
|
last_name: 'Martin',
|
||||||
|
|
||||||
|
email: 'angela.martin@example.com',
|
||||||
|
|
||||||
|
// type code here for "relation_many" field
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const FeesData = [
|
const FeesData = [
|
||||||
{
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
amount: 1500,
|
|
||||||
|
|
||||||
due_date: new Date('2023-10-01'),
|
|
||||||
|
|
||||||
status: 'Paid',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
@ -317,6 +369,26 @@ const FeesData = [
|
|||||||
|
|
||||||
status: 'Paid',
|
status: 'Paid',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amount: 1500,
|
||||||
|
|
||||||
|
due_date: new Date('2023-10-01'),
|
||||||
|
|
||||||
|
status: 'Unpaid',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amount: 1500,
|
||||||
|
|
||||||
|
due_date: new Date('2023-10-01'),
|
||||||
|
|
||||||
|
status: 'Unpaid',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const GradesData = [
|
const GradesData = [
|
||||||
@ -351,6 +423,14 @@ const GradesData = [
|
|||||||
|
|
||||||
score: 88.5,
|
score: 88.5,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
score: 92,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const LibraryData = [
|
const LibraryData = [
|
||||||
@ -359,7 +439,7 @@ const LibraryData = [
|
|||||||
|
|
||||||
author: 'Thomas H. Cormen',
|
author: 'Thomas H. Cormen',
|
||||||
|
|
||||||
status: 'CheckedOut',
|
status: 'Available',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -367,7 +447,7 @@ const LibraryData = [
|
|||||||
|
|
||||||
author: 'Donald E. Knuth',
|
author: 'Donald E. Knuth',
|
||||||
|
|
||||||
status: 'CheckedOut',
|
status: 'Available',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -385,6 +465,14 @@ const LibraryData = [
|
|||||||
|
|
||||||
status: 'Available',
|
status: 'Available',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
book_title: 'Artificial Intelligence: A Modern Approach',
|
||||||
|
|
||||||
|
author: 'Stuart Russell',
|
||||||
|
|
||||||
|
status: 'CheckedOut',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const StudentsData = [
|
const StudentsData = [
|
||||||
@ -443,6 +531,192 @@ const StudentsData = [
|
|||||||
|
|
||||||
// type code here for "relation_many" field
|
// type code here for "relation_many" field
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
first_name: 'Emily',
|
||||||
|
|
||||||
|
last_name: 'Davis',
|
||||||
|
|
||||||
|
email: 'emily.davis@example.com',
|
||||||
|
|
||||||
|
date_of_birth: new Date('1998-11-05'),
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_many" field
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const PaymentData = [
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amountpaid: 91.53,
|
||||||
|
|
||||||
|
paymentmode: 'value',
|
||||||
|
|
||||||
|
chequeno: 'Alfred Kinsey',
|
||||||
|
|
||||||
|
bankname: 'Frederick Sanger',
|
||||||
|
|
||||||
|
transactionid: 'Konrad Lorenz',
|
||||||
|
|
||||||
|
ddnumber: 'Theodosius Dobzhansky',
|
||||||
|
|
||||||
|
ddissuingbank: 'Francis Crick',
|
||||||
|
|
||||||
|
receiptnumber: 'Pierre Simon de Laplace',
|
||||||
|
|
||||||
|
discountpercentage: 50.21,
|
||||||
|
|
||||||
|
discountamount: 24.93,
|
||||||
|
|
||||||
|
discountreason: 'Jean Baptiste Lamarck',
|
||||||
|
|
||||||
|
ddissuedate: new Date(Date.now()),
|
||||||
|
|
||||||
|
remainingbalance: 76.33,
|
||||||
|
|
||||||
|
paymentdate: new Date(Date.now()),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amountpaid: 19.91,
|
||||||
|
|
||||||
|
paymentmode: 'value',
|
||||||
|
|
||||||
|
chequeno: 'Sigmund Freud',
|
||||||
|
|
||||||
|
bankname: 'Franz Boas',
|
||||||
|
|
||||||
|
transactionid: 'Max Delbruck',
|
||||||
|
|
||||||
|
ddnumber: 'Richard Feynman',
|
||||||
|
|
||||||
|
ddissuingbank: 'Joseph J. Thomson',
|
||||||
|
|
||||||
|
receiptnumber: 'August Kekule',
|
||||||
|
|
||||||
|
discountpercentage: 50.34,
|
||||||
|
|
||||||
|
discountamount: 84.54,
|
||||||
|
|
||||||
|
discountreason: 'Carl Gauss (Karl Friedrich Gauss)',
|
||||||
|
|
||||||
|
ddissuedate: new Date(Date.now()),
|
||||||
|
|
||||||
|
remainingbalance: 81.15,
|
||||||
|
|
||||||
|
paymentdate: new Date(Date.now()),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amountpaid: 12.58,
|
||||||
|
|
||||||
|
paymentmode: 'value',
|
||||||
|
|
||||||
|
chequeno: 'Edwin Hubble',
|
||||||
|
|
||||||
|
bankname: 'B. F. Skinner',
|
||||||
|
|
||||||
|
transactionid: 'John Dalton',
|
||||||
|
|
||||||
|
ddnumber: 'Werner Heisenberg',
|
||||||
|
|
||||||
|
ddissuingbank: 'Nicolaus Copernicus',
|
||||||
|
|
||||||
|
receiptnumber: 'Paul Ehrlich',
|
||||||
|
|
||||||
|
discountpercentage: 35.76,
|
||||||
|
|
||||||
|
discountamount: 67.75,
|
||||||
|
|
||||||
|
discountreason: 'Gregor Mendel',
|
||||||
|
|
||||||
|
ddissuedate: new Date(Date.now()),
|
||||||
|
|
||||||
|
remainingbalance: 49.69,
|
||||||
|
|
||||||
|
paymentdate: new Date(Date.now()),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amountpaid: 13.29,
|
||||||
|
|
||||||
|
paymentmode: 'value',
|
||||||
|
|
||||||
|
chequeno: 'Galileo Galilei',
|
||||||
|
|
||||||
|
bankname: 'Thomas Hunt Morgan',
|
||||||
|
|
||||||
|
transactionid: 'Tycho Brahe',
|
||||||
|
|
||||||
|
ddnumber: 'Gertrude Belle Elion',
|
||||||
|
|
||||||
|
ddissuingbank: 'Joseph J. Thomson',
|
||||||
|
|
||||||
|
receiptnumber: 'Stephen Hawking',
|
||||||
|
|
||||||
|
discountpercentage: 92.82,
|
||||||
|
|
||||||
|
discountamount: 52.86,
|
||||||
|
|
||||||
|
discountreason: 'Erwin Schrodinger',
|
||||||
|
|
||||||
|
ddissuedate: new Date(Date.now()),
|
||||||
|
|
||||||
|
remainingbalance: 58.85,
|
||||||
|
|
||||||
|
paymentdate: new Date(Date.now()),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
|
amountpaid: 95.62,
|
||||||
|
|
||||||
|
paymentmode: 'value',
|
||||||
|
|
||||||
|
chequeno: 'Heike Kamerlingh Onnes',
|
||||||
|
|
||||||
|
bankname: 'Hans Bethe',
|
||||||
|
|
||||||
|
transactionid: 'Louis Victor de Broglie',
|
||||||
|
|
||||||
|
ddnumber: 'Isaac Newton',
|
||||||
|
|
||||||
|
ddissuingbank: 'Edward O. Wilson',
|
||||||
|
|
||||||
|
receiptnumber: 'Max Planck',
|
||||||
|
|
||||||
|
discountpercentage: 34.86,
|
||||||
|
|
||||||
|
discountamount: 23.48,
|
||||||
|
|
||||||
|
discountreason: 'Louis Victor de Broglie',
|
||||||
|
|
||||||
|
ddissuedate: new Date(Date.now()),
|
||||||
|
|
||||||
|
remainingbalance: 37.63,
|
||||||
|
|
||||||
|
paymentdate: new Date(Date.now()),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
@ -491,6 +765,17 @@ async function associateAdmissionWithStudent() {
|
|||||||
if (Admission3?.setStudent) {
|
if (Admission3?.setStudent) {
|
||||||
await Admission3.setStudent(relatedStudent3);
|
await Admission3.setStudent(relatedStudent3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedStudent4 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Admission4 = await Admissions.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Admission4?.setStudent) {
|
||||||
|
await Admission4.setStudent(relatedStudent4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateAttendanceWithStudent() {
|
async function associateAttendanceWithStudent() {
|
||||||
@ -537,6 +822,17 @@ async function associateAttendanceWithStudent() {
|
|||||||
if (Attendance3?.setStudent) {
|
if (Attendance3?.setStudent) {
|
||||||
await Attendance3.setStudent(relatedStudent3);
|
await Attendance3.setStudent(relatedStudent3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedStudent4 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Attendance4 = await Attendance.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Attendance4?.setStudent) {
|
||||||
|
await Attendance4.setStudent(relatedStudent4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateAttendanceWithCourse() {
|
async function associateAttendanceWithCourse() {
|
||||||
@ -583,6 +879,17 @@ async function associateAttendanceWithCourse() {
|
|||||||
if (Attendance3?.setCourse) {
|
if (Attendance3?.setCourse) {
|
||||||
await Attendance3.setCourse(relatedCourse3);
|
await Attendance3.setCourse(relatedCourse3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedCourse4 = await Courses.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Courses.count())),
|
||||||
|
});
|
||||||
|
const Attendance4 = await Attendance.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Attendance4?.setCourse) {
|
||||||
|
await Attendance4.setCourse(relatedCourse4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateCourseWithDepartment() {
|
async function associateCourseWithDepartment() {
|
||||||
@ -629,6 +936,17 @@ async function associateCourseWithDepartment() {
|
|||||||
if (Course3?.setDepartment) {
|
if (Course3?.setDepartment) {
|
||||||
await Course3.setDepartment(relatedDepartment3);
|
await Course3.setDepartment(relatedDepartment3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedDepartment4 = await Departments.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
||||||
|
});
|
||||||
|
const Course4 = await Courses.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Course4?.setDepartment) {
|
||||||
|
await Course4.setDepartment(relatedDepartment4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateExamWithCourse() {
|
async function associateExamWithCourse() {
|
||||||
@ -675,6 +993,17 @@ async function associateExamWithCourse() {
|
|||||||
if (Exam3?.setCourse) {
|
if (Exam3?.setCourse) {
|
||||||
await Exam3.setCourse(relatedCourse3);
|
await Exam3.setCourse(relatedCourse3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedCourse4 = await Courses.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Courses.count())),
|
||||||
|
});
|
||||||
|
const Exam4 = await Exams.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Exam4?.setCourse) {
|
||||||
|
await Exam4.setCourse(relatedCourse4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
@ -723,6 +1052,17 @@ async function associateFeeWithStudent() {
|
|||||||
if (Fee3?.setStudent) {
|
if (Fee3?.setStudent) {
|
||||||
await Fee3.setStudent(relatedStudent3);
|
await Fee3.setStudent(relatedStudent3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedStudent4 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Fee4 = await Fees.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Fee4?.setStudent) {
|
||||||
|
await Fee4.setStudent(relatedStudent4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateGradeWithStudent() {
|
async function associateGradeWithStudent() {
|
||||||
@ -769,6 +1109,17 @@ async function associateGradeWithStudent() {
|
|||||||
if (Grade3?.setStudent) {
|
if (Grade3?.setStudent) {
|
||||||
await Grade3.setStudent(relatedStudent3);
|
await Grade3.setStudent(relatedStudent3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedStudent4 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Grade4 = await Grades.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Grade4?.setStudent) {
|
||||||
|
await Grade4.setStudent(relatedStudent4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateGradeWithExam() {
|
async function associateGradeWithExam() {
|
||||||
@ -815,6 +1166,17 @@ async function associateGradeWithExam() {
|
|||||||
if (Grade3?.setExam) {
|
if (Grade3?.setExam) {
|
||||||
await Grade3.setExam(relatedExam3);
|
await Grade3.setExam(relatedExam3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedExam4 = await Exams.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Exams.count())),
|
||||||
|
});
|
||||||
|
const Grade4 = await Grades.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Grade4?.setExam) {
|
||||||
|
await Grade4.setExam(relatedExam4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateStudentWithDepartment() {
|
async function associateStudentWithDepartment() {
|
||||||
@ -861,10 +1223,135 @@ async function associateStudentWithDepartment() {
|
|||||||
if (Student3?.setDepartment) {
|
if (Student3?.setDepartment) {
|
||||||
await Student3.setDepartment(relatedDepartment3);
|
await Student3.setDepartment(relatedDepartment3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relatedDepartment4 = await Departments.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
||||||
|
});
|
||||||
|
const Student4 = await Students.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Student4?.setDepartment) {
|
||||||
|
await Student4.setDepartment(relatedDepartment4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
|
|
||||||
|
async function associatePaymentWithStudent() {
|
||||||
|
const relatedStudent0 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Payment0 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 0,
|
||||||
|
});
|
||||||
|
if (Payment0?.setStudent) {
|
||||||
|
await Payment0.setStudent(relatedStudent0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedStudent1 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Payment1 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 1,
|
||||||
|
});
|
||||||
|
if (Payment1?.setStudent) {
|
||||||
|
await Payment1.setStudent(relatedStudent1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedStudent2 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Payment2 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 2,
|
||||||
|
});
|
||||||
|
if (Payment2?.setStudent) {
|
||||||
|
await Payment2.setStudent(relatedStudent2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedStudent3 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Payment3 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Payment3?.setStudent) {
|
||||||
|
await Payment3.setStudent(relatedStudent3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedStudent4 = await Students.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Students.count())),
|
||||||
|
});
|
||||||
|
const Payment4 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Payment4?.setStudent) {
|
||||||
|
await Payment4.setStudent(relatedStudent4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function associatePaymentWithInvoice() {
|
||||||
|
const relatedInvoice0 = await Fees.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Fees.count())),
|
||||||
|
});
|
||||||
|
const Payment0 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 0,
|
||||||
|
});
|
||||||
|
if (Payment0?.setInvoice) {
|
||||||
|
await Payment0.setInvoice(relatedInvoice0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedInvoice1 = await Fees.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Fees.count())),
|
||||||
|
});
|
||||||
|
const Payment1 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 1,
|
||||||
|
});
|
||||||
|
if (Payment1?.setInvoice) {
|
||||||
|
await Payment1.setInvoice(relatedInvoice1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedInvoice2 = await Fees.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Fees.count())),
|
||||||
|
});
|
||||||
|
const Payment2 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 2,
|
||||||
|
});
|
||||||
|
if (Payment2?.setInvoice) {
|
||||||
|
await Payment2.setInvoice(relatedInvoice2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedInvoice3 = await Fees.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Fees.count())),
|
||||||
|
});
|
||||||
|
const Payment3 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 3,
|
||||||
|
});
|
||||||
|
if (Payment3?.setInvoice) {
|
||||||
|
await Payment3.setInvoice(relatedInvoice3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedInvoice4 = await Fees.findOne({
|
||||||
|
offset: Math.floor(Math.random() * (await Fees.count())),
|
||||||
|
});
|
||||||
|
const Payment4 = await Payment.findOne({
|
||||||
|
order: [['id', 'ASC']],
|
||||||
|
offset: 4,
|
||||||
|
});
|
||||||
|
if (Payment4?.setInvoice) {
|
||||||
|
await Payment4.setInvoice(relatedInvoice4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: async (queryInterface, Sequelize) => {
|
up: async (queryInterface, Sequelize) => {
|
||||||
await Admissions.bulkCreate(AdmissionsData);
|
await Admissions.bulkCreate(AdmissionsData);
|
||||||
@ -889,6 +1376,8 @@ module.exports = {
|
|||||||
|
|
||||||
await Students.bulkCreate(StudentsData);
|
await Students.bulkCreate(StudentsData);
|
||||||
|
|
||||||
|
await Payment.bulkCreate(PaymentData);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
|
|
||||||
@ -913,6 +1402,10 @@ module.exports = {
|
|||||||
await associateStudentWithDepartment(),
|
await associateStudentWithDepartment(),
|
||||||
|
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
|
|
||||||
|
await associatePaymentWithStudent(),
|
||||||
|
|
||||||
|
await associatePaymentWithInvoice(),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -938,5 +1431,7 @@ module.exports = {
|
|||||||
await queryInterface.bulkDelete('library', null, {});
|
await queryInterface.bulkDelete('library', null, {});
|
||||||
|
|
||||||
await queryInterface.bulkDelete('students', null, {});
|
await queryInterface.bulkDelete('students', null, {});
|
||||||
|
|
||||||
|
await queryInterface.bulkDelete('payment', null, {});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
87
backend/src/db/seeders/20250705200800.js
Normal file
87
backend/src/db/seeders/20250705200800.js
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
const { v4: uuid } = require('uuid');
|
||||||
|
const db = require('../models');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const config = require('../../config');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* @param{import("sequelize").QueryInterface} queryInterface
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
async up(queryInterface) {
|
||||||
|
const createdAt = new Date();
|
||||||
|
const updatedAt = new Date();
|
||||||
|
|
||||||
|
/** @type {Map<string, string>} */
|
||||||
|
const idMap = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} key
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function getId(key) {
|
||||||
|
if (idMap.has(key)) {
|
||||||
|
return idMap.get(key);
|
||||||
|
}
|
||||||
|
const id = uuid();
|
||||||
|
idMap.set(key, id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
function createPermissions(name) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: getId(`CREATE_${name.toUpperCase()}`),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name: `CREATE_${name.toUpperCase()}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: getId(`READ_${name.toUpperCase()}`),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name: `READ_${name.toUpperCase()}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: getId(`UPDATE_${name.toUpperCase()}`),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name: `UPDATE_${name.toUpperCase()}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: getId(`DELETE_${name.toUpperCase()}`),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name: `DELETE_${name.toUpperCase()}`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const entities = ['payment'];
|
||||||
|
|
||||||
|
const createdPermissions = entities.flatMap(createPermissions);
|
||||||
|
|
||||||
|
// Add permissions to database
|
||||||
|
await queryInterface.bulkInsert('permissions', createdPermissions);
|
||||||
|
// Get permissions ids
|
||||||
|
const permissionsIds = createdPermissions.map((p) => p.id);
|
||||||
|
// Get admin role
|
||||||
|
const adminRole = await db.roles.findOne({
|
||||||
|
where: { name: config.roles.admin },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (adminRole) {
|
||||||
|
// Add permissions to admin role if it exists
|
||||||
|
await adminRole.addPermissions(permissionsIds);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.bulkDelete(
|
||||||
|
'permissions',
|
||||||
|
entities.flatMap(createPermissions),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -45,6 +45,8 @@ const rolesRoutes = require('./routes/roles');
|
|||||||
|
|
||||||
const permissionsRoutes = require('./routes/permissions');
|
const permissionsRoutes = require('./routes/permissions');
|
||||||
|
|
||||||
|
const paymentRoutes = require('./routes/payment');
|
||||||
|
|
||||||
const getBaseUrl = (url) => {
|
const getBaseUrl = (url) => {
|
||||||
if (!url) return '';
|
if (!url) return '';
|
||||||
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
||||||
@ -194,6 +196,12 @@ app.use(
|
|||||||
permissionsRoutes,
|
permissionsRoutes,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
'/api/payment',
|
||||||
|
passport.authenticate('jwt', { session: false }),
|
||||||
|
paymentRoutes,
|
||||||
|
);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/api/openai',
|
'/api/openai',
|
||||||
passport.authenticate('jwt', { session: false }),
|
passport.authenticate('jwt', { session: false }),
|
||||||
|
|||||||
486
backend/src/routes/payment.js
Normal file
486
backend/src/routes/payment.js
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
const express = require('express');
|
||||||
|
|
||||||
|
const PaymentService = require('../services/payment');
|
||||||
|
const PaymentDBApi = require('../db/api/payment');
|
||||||
|
const wrapAsync = require('../helpers').wrapAsync;
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
const { parse } = require('json2csv');
|
||||||
|
|
||||||
|
const { checkCrudPermissions } = require('../middlewares/check-permissions');
|
||||||
|
|
||||||
|
router.use(checkCrudPermissions('payment'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* components:
|
||||||
|
* schemas:
|
||||||
|
* Payment:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
|
||||||
|
* chequeno:
|
||||||
|
* type: string
|
||||||
|
* default: chequeno
|
||||||
|
* bankname:
|
||||||
|
* type: string
|
||||||
|
* default: bankname
|
||||||
|
* transactionid:
|
||||||
|
* type: string
|
||||||
|
* default: transactionid
|
||||||
|
* ddnumber:
|
||||||
|
* type: string
|
||||||
|
* default: ddnumber
|
||||||
|
* ddissuingbank:
|
||||||
|
* type: string
|
||||||
|
* default: ddissuingbank
|
||||||
|
* receiptnumber:
|
||||||
|
* type: string
|
||||||
|
* default: receiptnumber
|
||||||
|
* discountreason:
|
||||||
|
* type: string
|
||||||
|
* default: discountreason
|
||||||
|
|
||||||
|
* amountpaid:
|
||||||
|
* type: integer
|
||||||
|
* format: int64
|
||||||
|
* discountpercentage:
|
||||||
|
* type: integer
|
||||||
|
* format: int64
|
||||||
|
* discountamount:
|
||||||
|
* type: integer
|
||||||
|
* format: int64
|
||||||
|
* remainingbalance:
|
||||||
|
* type: integer
|
||||||
|
* format: int64
|
||||||
|
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* tags:
|
||||||
|
* name: Payment
|
||||||
|
* description: The Payment managing API
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment:
|
||||||
|
* post:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Add new item
|
||||||
|
* description: Add new item
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* properties:
|
||||||
|
* data:
|
||||||
|
* description: Data of the updated item
|
||||||
|
* type: object
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: The item was successfully added
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 405:
|
||||||
|
* description: Invalid input data
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.post(
|
||||||
|
'/',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
const referer =
|
||||||
|
req.headers.referer ||
|
||||||
|
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
||||||
|
const link = new URL(referer);
|
||||||
|
await PaymentService.create(
|
||||||
|
req.body.data,
|
||||||
|
req.currentUser,
|
||||||
|
true,
|
||||||
|
link.host,
|
||||||
|
);
|
||||||
|
const payload = true;
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/budgets/bulk-import:
|
||||||
|
* post:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Bulk import items
|
||||||
|
* description: Bulk import items
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* properties:
|
||||||
|
* data:
|
||||||
|
* description: Data of the updated items
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: The items were successfully imported
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 405:
|
||||||
|
* description: Invalid input data
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
router.post(
|
||||||
|
'/bulk-import',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
const referer =
|
||||||
|
req.headers.referer ||
|
||||||
|
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
||||||
|
const link = new URL(referer);
|
||||||
|
await PaymentService.bulkImport(req, res, true, link.host);
|
||||||
|
const payload = true;
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/{id}:
|
||||||
|
* put:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Update the data of the selected item
|
||||||
|
* description: Update the data of the selected item
|
||||||
|
* parameters:
|
||||||
|
* - in: path
|
||||||
|
* name: id
|
||||||
|
* description: Item ID to update
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* requestBody:
|
||||||
|
* description: Set new item data
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* description: ID of the updated item
|
||||||
|
* type: string
|
||||||
|
* data:
|
||||||
|
* description: Data of the updated item
|
||||||
|
* type: object
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* required:
|
||||||
|
* - id
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: The item data was successfully updated
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 400:
|
||||||
|
* description: Invalid ID supplied
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Item not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.put(
|
||||||
|
'/:id',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
await PaymentService.update(req.body.data, req.body.id, req.currentUser);
|
||||||
|
const payload = true;
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/{id}:
|
||||||
|
* delete:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Delete the selected item
|
||||||
|
* description: Delete the selected item
|
||||||
|
* parameters:
|
||||||
|
* - in: path
|
||||||
|
* name: id
|
||||||
|
* description: Item ID to delete
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: The item was successfully deleted
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 400:
|
||||||
|
* description: Invalid ID supplied
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Item not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.delete(
|
||||||
|
'/:id',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
await PaymentService.remove(req.params.id, req.currentUser);
|
||||||
|
const payload = true;
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/deleteByIds:
|
||||||
|
* post:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Delete the selected item list
|
||||||
|
* description: Delete the selected item list
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* properties:
|
||||||
|
* ids:
|
||||||
|
* description: IDs of the updated items
|
||||||
|
* type: array
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: The items was successfully deleted
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Items not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.post(
|
||||||
|
'/deleteByIds',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
await PaymentService.deleteByIds(req.body.data, req.currentUser);
|
||||||
|
const payload = true;
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment:
|
||||||
|
* get:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Get all payment
|
||||||
|
* description: Get all payment
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Payment list successfully received
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Data not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.get(
|
||||||
|
'/',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
const filetype = req.query.filetype;
|
||||||
|
|
||||||
|
const currentUser = req.currentUser;
|
||||||
|
const payload = await PaymentDBApi.findAll(req.query, { currentUser });
|
||||||
|
if (filetype && filetype === 'csv') {
|
||||||
|
const fields = [
|
||||||
|
'id',
|
||||||
|
'chequeno',
|
||||||
|
'bankname',
|
||||||
|
'transactionid',
|
||||||
|
'ddnumber',
|
||||||
|
'ddissuingbank',
|
||||||
|
'receiptnumber',
|
||||||
|
'discountreason',
|
||||||
|
|
||||||
|
'amountpaid',
|
||||||
|
'discountpercentage',
|
||||||
|
'discountamount',
|
||||||
|
'remainingbalance',
|
||||||
|
'ddissuedate',
|
||||||
|
'paymentdate',
|
||||||
|
];
|
||||||
|
const opts = { fields };
|
||||||
|
try {
|
||||||
|
const csv = parse(payload.rows, opts);
|
||||||
|
res.status(200).attachment(csv);
|
||||||
|
res.send(csv);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/count:
|
||||||
|
* get:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Count all payment
|
||||||
|
* description: Count all payment
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Payment count successfully received
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Data not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.get(
|
||||||
|
'/count',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
const currentUser = req.currentUser;
|
||||||
|
const payload = await PaymentDBApi.findAll(req.query, null, {
|
||||||
|
countOnly: true,
|
||||||
|
currentUser,
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/autocomplete:
|
||||||
|
* get:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Find all payment that match search criteria
|
||||||
|
* description: Find all payment that match search criteria
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Payment list successfully received
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Data not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.get('/autocomplete', async (req, res) => {
|
||||||
|
const payload = await PaymentDBApi.findAllAutocomplete(
|
||||||
|
req.query.query,
|
||||||
|
req.query.limit,
|
||||||
|
req.query.offset,
|
||||||
|
);
|
||||||
|
|
||||||
|
res.status(200).send(payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/payment/{id}:
|
||||||
|
* get:
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* tags: [Payment]
|
||||||
|
* summary: Get selected item
|
||||||
|
* description: Get selected item
|
||||||
|
* parameters:
|
||||||
|
* - in: path
|
||||||
|
* name: id
|
||||||
|
* description: ID of item to get
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Selected item successfully received
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/Payment"
|
||||||
|
* 400:
|
||||||
|
* description: Invalid ID supplied
|
||||||
|
* 401:
|
||||||
|
* $ref: "#/components/responses/UnauthorizedError"
|
||||||
|
* 404:
|
||||||
|
* description: Item not found
|
||||||
|
* 500:
|
||||||
|
* description: Some server error
|
||||||
|
*/
|
||||||
|
router.get(
|
||||||
|
'/:id',
|
||||||
|
wrapAsync(async (req, res) => {
|
||||||
|
const payload = await PaymentDBApi.findBy({ id: req.params.id });
|
||||||
|
|
||||||
|
res.status(200).send(payload);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
router.use('/', require('../helpers').commonErrorHandler);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
114
backend/src/services/payment.js
Normal file
114
backend/src/services/payment.js
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
const db = require('../db/models');
|
||||||
|
const PaymentDBApi = require('../db/api/payment');
|
||||||
|
const processFile = require('../middlewares/upload');
|
||||||
|
const ValidationError = require('./notifications/errors/validation');
|
||||||
|
const csv = require('csv-parser');
|
||||||
|
const axios = require('axios');
|
||||||
|
const config = require('../config');
|
||||||
|
const stream = require('stream');
|
||||||
|
|
||||||
|
module.exports = class PaymentService {
|
||||||
|
static async create(data, currentUser) {
|
||||||
|
const transaction = await db.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await PaymentDBApi.create(data, {
|
||||||
|
currentUser,
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async bulkImport(req, res, sendInvitationEmails = true, host) {
|
||||||
|
const transaction = await db.sequelize.transaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await processFile(req, res);
|
||||||
|
const bufferStream = new stream.PassThrough();
|
||||||
|
const results = [];
|
||||||
|
|
||||||
|
await bufferStream.end(Buffer.from(req.file.buffer, 'utf-8')); // convert Buffer to Stream
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
bufferStream
|
||||||
|
.pipe(csv())
|
||||||
|
.on('data', (data) => results.push(data))
|
||||||
|
.on('end', async () => {
|
||||||
|
console.log('CSV results', results);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.on('error', (error) => reject(error));
|
||||||
|
});
|
||||||
|
|
||||||
|
await PaymentDBApi.bulkImport(results, {
|
||||||
|
transaction,
|
||||||
|
ignoreDuplicates: true,
|
||||||
|
validate: true,
|
||||||
|
currentUser: req.currentUser,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async update(data, id, currentUser) {
|
||||||
|
const transaction = await db.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
let payment = await PaymentDBApi.findBy({ id }, { transaction });
|
||||||
|
|
||||||
|
if (!payment) {
|
||||||
|
throw new ValidationError('paymentNotFound');
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedPayment = await PaymentDBApi.update(id, data, {
|
||||||
|
currentUser,
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
return updatedPayment;
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async deleteByIds(ids, currentUser) {
|
||||||
|
const transaction = await db.sequelize.transaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await PaymentDBApi.deleteByIds(ids, {
|
||||||
|
currentUser,
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async remove(id, currentUser) {
|
||||||
|
const transaction = await db.sequelize.transaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await PaymentDBApi.remove(id, {
|
||||||
|
currentUser,
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -58,11 +58,37 @@ module.exports = class SearchService {
|
|||||||
library: ['book_title', 'author'],
|
library: ['book_title', 'author'],
|
||||||
|
|
||||||
students: ['first_name', 'last_name', 'email'],
|
students: ['first_name', 'last_name', 'email'],
|
||||||
|
|
||||||
|
payment: [
|
||||||
|
'chequeno',
|
||||||
|
|
||||||
|
'bankname',
|
||||||
|
|
||||||
|
'transactionid',
|
||||||
|
|
||||||
|
'ddnumber',
|
||||||
|
|
||||||
|
'ddissuingbank',
|
||||||
|
|
||||||
|
'receiptnumber',
|
||||||
|
|
||||||
|
'discountreason',
|
||||||
|
],
|
||||||
};
|
};
|
||||||
const columnsInt = {
|
const columnsInt = {
|
||||||
fees: ['amount'],
|
fees: ['amount'],
|
||||||
|
|
||||||
grades: ['score'],
|
grades: ['score'],
|
||||||
|
|
||||||
|
payment: [
|
||||||
|
'amountpaid',
|
||||||
|
|
||||||
|
'discountpercentage',
|
||||||
|
|
||||||
|
'discountamount',
|
||||||
|
|
||||||
|
'remainingbalance',
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let allFoundRecords = [];
|
let allFoundRecords = [];
|
||||||
|
|||||||
1
frontend/json/runtimeError.json
Normal file
1
frontend/json/runtimeError.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
274
frontend/src/components/Payment/CardPayment.tsx
Normal file
274
frontend/src/components/Payment/CardPayment.tsx
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ImageField from '../ImageField';
|
||||||
|
import ListActionsPopover from '../ListActionsPopover';
|
||||||
|
import { useAppSelector } from '../../stores/hooks';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import { Pagination } from '../Pagination';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import LoadingSpinner from '../LoadingSpinner';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { hasPermission } from '../../helpers/userPermissions';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
payment: any[];
|
||||||
|
loading: boolean;
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
currentPage: number;
|
||||||
|
numPages: number;
|
||||||
|
onPageChange: (page: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const CardPayment = ({
|
||||||
|
payment,
|
||||||
|
loading,
|
||||||
|
onDelete,
|
||||||
|
currentPage,
|
||||||
|
numPages,
|
||||||
|
onPageChange,
|
||||||
|
}: Props) => {
|
||||||
|
const asideScrollbarsStyle = useAppSelector(
|
||||||
|
(state) => state.style.asideScrollbarsStyle,
|
||||||
|
);
|
||||||
|
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
||||||
|
const darkMode = useAppSelector((state) => state.style.darkMode);
|
||||||
|
const corners = useAppSelector((state) => state.style.corners);
|
||||||
|
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
||||||
|
|
||||||
|
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
||||||
|
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_PAYMENT');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={'p-4'}>
|
||||||
|
{loading && <LoadingSpinner />}
|
||||||
|
<ul
|
||||||
|
role='list'
|
||||||
|
className='grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-3 2xl:grid-cols-4 xl:gap-x-8'
|
||||||
|
>
|
||||||
|
{!loading &&
|
||||||
|
payment.map((item, index) => (
|
||||||
|
<li
|
||||||
|
key={item.id}
|
||||||
|
className={`overflow-hidden ${
|
||||||
|
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
||||||
|
} border ${focusRing} border-gray-200 dark:border-dark-700 ${
|
||||||
|
darkMode ? 'aside-scrollbars-[slate]' : asideScrollbarsStyle
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`flex items-center ${bgColor} p-6 gap-x-4 border-b border-gray-900/5 bg-gray-50 dark:bg-dark-800 relative`}
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
href={`/payment/payment-view/?id=${item.id}`}
|
||||||
|
className='text-lg font-bold leading-6 line-clamp-1'
|
||||||
|
>
|
||||||
|
{item.amountpaid}
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<div className='ml-auto '>
|
||||||
|
<ListActionsPopover
|
||||||
|
onDelete={onDelete}
|
||||||
|
itemId={item.id}
|
||||||
|
pathEdit={`/payment/payment-edit/?id=${item.id}`}
|
||||||
|
pathView={`/payment/payment-view/?id=${item.id}`}
|
||||||
|
hasUpdatePermission={hasUpdatePermission}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<dl className='divide-y divide-stone-300 dark:divide-dark-700 px-6 py-4 text-sm leading-6 h-64 overflow-y-auto'>
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Student
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{dataFormatter.studentsOneListFormatter(item.student)}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Invoice
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{dataFormatter.feesOneListFormatter(item.invoice)}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Amountpaid
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.amountpaid}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Paymentmode
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.paymentmode}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Chequeno
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.chequeno}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Bankname
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.bankname}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Transactionid
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.transactionid}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Ddnumber
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.ddnumber}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Ddissuingbank
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.ddissuingbank}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Receiptnumber
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.receiptnumber}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Discountpercentage
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.discountpercentage}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Discountamount
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.discountamount}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Discountreason
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.discountreason}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Ddissuedate
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.ddissuedate)}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Remainingbalance
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{item.remainingbalance}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex justify-between gap-x-4 py-3'>
|
||||||
|
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||||
|
Paymentdate
|
||||||
|
</dt>
|
||||||
|
<dd className='flex items-start gap-x-2'>
|
||||||
|
<div className='font-medium line-clamp-4'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.paymentdate)}
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
{!loading && payment.length === 0 && (
|
||||||
|
<div className='col-span-full flex items-center justify-center h-40'>
|
||||||
|
<p className=''>No data to display</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
<div className={'flex items-center justify-center my-6'}>
|
||||||
|
<Pagination
|
||||||
|
currentPage={currentPage}
|
||||||
|
numPages={numPages}
|
||||||
|
setCurrentPage={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CardPayment;
|
||||||
186
frontend/src/components/Payment/ListPayment.tsx
Normal file
186
frontend/src/components/Payment/ListPayment.tsx
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import CardBox from '../CardBox';
|
||||||
|
import ImageField from '../ImageField';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import ListActionsPopover from '../ListActionsPopover';
|
||||||
|
import { useAppSelector } from '../../stores/hooks';
|
||||||
|
import { Pagination } from '../Pagination';
|
||||||
|
import LoadingSpinner from '../LoadingSpinner';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { hasPermission } from '../../helpers/userPermissions';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
payment: any[];
|
||||||
|
loading: boolean;
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
currentPage: number;
|
||||||
|
numPages: number;
|
||||||
|
onPageChange: (page: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ListPayment = ({
|
||||||
|
payment,
|
||||||
|
loading,
|
||||||
|
onDelete,
|
||||||
|
currentPage,
|
||||||
|
numPages,
|
||||||
|
onPageChange,
|
||||||
|
}: Props) => {
|
||||||
|
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
||||||
|
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_PAYMENT');
|
||||||
|
|
||||||
|
const corners = useAppSelector((state) => state.style.corners);
|
||||||
|
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='relative overflow-x-auto p-4 space-y-4'>
|
||||||
|
{loading && <LoadingSpinner />}
|
||||||
|
{!loading &&
|
||||||
|
payment.map((item) => (
|
||||||
|
<div key={item.id}>
|
||||||
|
<CardBox hasTable isList className={'rounded shadow-none'}>
|
||||||
|
<div
|
||||||
|
className={`flex rounded dark:bg-dark-900 border border-stone-300 items-center overflow-hidden`}
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
href={`/payment/payment-view/?id=${item.id}`}
|
||||||
|
className={
|
||||||
|
'flex-1 px-4 py-6 h-24 flex divide-x-2 divide-stone-300 items-center overflow-hidden`}> dark:divide-dark-700 overflow-x-auto'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Student</p>
|
||||||
|
<p className={'line-clamp-2'}>
|
||||||
|
{dataFormatter.studentsOneListFormatter(item.student)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Invoice</p>
|
||||||
|
<p className={'line-clamp-2'}>
|
||||||
|
{dataFormatter.feesOneListFormatter(item.invoice)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Amountpaid</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.amountpaid}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Paymentmode</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.paymentmode}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Chequeno</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.chequeno}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Bankname</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.bankname}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Transactionid
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.transactionid}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Ddnumber</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.ddnumber}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Ddissuingbank
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.ddissuingbank}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Receiptnumber
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.receiptnumber}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Discountpercentage
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>
|
||||||
|
{item.discountpercentage}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Discountamount
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.discountamount}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Discountreason
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.discountreason}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Ddissuedate</p>
|
||||||
|
<p className={'line-clamp-2'}>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.ddissuedate)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>
|
||||||
|
Remainingbalance
|
||||||
|
</p>
|
||||||
|
<p className={'line-clamp-2'}>{item.remainingbalance}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'flex-1 px-3'}>
|
||||||
|
<p className={'text-xs text-gray-500 '}>Paymentdate</p>
|
||||||
|
<p className={'line-clamp-2'}>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.paymentdate)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<ListActionsPopover
|
||||||
|
onDelete={onDelete}
|
||||||
|
itemId={item.id}
|
||||||
|
pathEdit={`/payment/payment-edit/?id=${item.id}`}
|
||||||
|
pathView={`/payment/payment-view/?id=${item.id}`}
|
||||||
|
hasUpdatePermission={hasUpdatePermission}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardBox>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{!loading && payment.length === 0 && (
|
||||||
|
<div className='col-span-full flex items-center justify-center h-40'>
|
||||||
|
<p className=''>No data to display</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={'flex items-center justify-center my-6'}>
|
||||||
|
<Pagination
|
||||||
|
currentPage={currentPage}
|
||||||
|
numPages={numPages}
|
||||||
|
setCurrentPage={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListPayment;
|
||||||
481
frontend/src/components/Payment/TablePayment.tsx
Normal file
481
frontend/src/components/Payment/TablePayment.tsx
Normal file
@ -0,0 +1,481 @@
|
|||||||
|
import React, { useEffect, useState, useMemo } from 'react';
|
||||||
|
import { createPortal } from 'react-dom';
|
||||||
|
import { ToastContainer, toast } from 'react-toastify';
|
||||||
|
import BaseButton from '../BaseButton';
|
||||||
|
import CardBoxModal from '../CardBoxModal';
|
||||||
|
import CardBox from '../CardBox';
|
||||||
|
import {
|
||||||
|
fetch,
|
||||||
|
update,
|
||||||
|
deleteItem,
|
||||||
|
setRefetch,
|
||||||
|
deleteItemsByIds,
|
||||||
|
} from '../../stores/payment/paymentSlice';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { Field, Form, Formik } from 'formik';
|
||||||
|
import { DataGrid, GridColDef } from '@mui/x-data-grid';
|
||||||
|
import { loadColumns } from './configurePaymentCols';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import { dataGridStyles } from '../../styles';
|
||||||
|
|
||||||
|
const perPage = 10;
|
||||||
|
|
||||||
|
const TableSamplePayment = ({
|
||||||
|
filterItems,
|
||||||
|
setFilterItems,
|
||||||
|
filters,
|
||||||
|
showGrid,
|
||||||
|
}) => {
|
||||||
|
const notify = (type, msg) => toast(msg, { type, position: 'bottom-center' });
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const pagesList = [];
|
||||||
|
const [id, setId] = useState(null);
|
||||||
|
const [currentPage, setCurrentPage] = useState(0);
|
||||||
|
const [filterRequest, setFilterRequest] = React.useState('');
|
||||||
|
const [columns, setColumns] = useState<GridColDef[]>([]);
|
||||||
|
const [selectedRows, setSelectedRows] = useState([]);
|
||||||
|
const [sortModel, setSortModel] = useState([
|
||||||
|
{
|
||||||
|
field: '',
|
||||||
|
sort: 'desc',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const {
|
||||||
|
payment,
|
||||||
|
loading,
|
||||||
|
count,
|
||||||
|
notify: paymentNotify,
|
||||||
|
refetch,
|
||||||
|
} = useAppSelector((state) => state.payment);
|
||||||
|
const { currentUser } = useAppSelector((state) => state.auth);
|
||||||
|
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
||||||
|
const bgColor = useAppSelector((state) => state.style.bgLayoutColor);
|
||||||
|
const corners = useAppSelector((state) => state.style.corners);
|
||||||
|
const numPages =
|
||||||
|
Math.floor(count / perPage) === 0 ? 1 : Math.ceil(count / perPage);
|
||||||
|
for (let i = 0; i < numPages; i++) {
|
||||||
|
pagesList.push(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadData = async (page = currentPage, request = filterRequest) => {
|
||||||
|
if (page !== currentPage) setCurrentPage(page);
|
||||||
|
if (request !== filterRequest) setFilterRequest(request);
|
||||||
|
const { sort, field } = sortModel[0];
|
||||||
|
|
||||||
|
const query = `?page=${page}&limit=${perPage}${request}&sort=${sort}&field=${field}`;
|
||||||
|
dispatch(fetch({ limit: perPage, page, query }));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (paymentNotify.showNotification) {
|
||||||
|
notify(paymentNotify.typeNotification, paymentNotify.textNotification);
|
||||||
|
}
|
||||||
|
}, [paymentNotify.showNotification]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentUser) return;
|
||||||
|
loadData();
|
||||||
|
}, [sortModel, currentUser]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (refetch) {
|
||||||
|
loadData(0);
|
||||||
|
dispatch(setRefetch(false));
|
||||||
|
}
|
||||||
|
}, [refetch, dispatch]);
|
||||||
|
|
||||||
|
const [isModalInfoActive, setIsModalInfoActive] = useState(false);
|
||||||
|
const [isModalTrashActive, setIsModalTrashActive] = useState(false);
|
||||||
|
|
||||||
|
const handleModalAction = () => {
|
||||||
|
setIsModalInfoActive(false);
|
||||||
|
setIsModalTrashActive(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteModalAction = (id: string) => {
|
||||||
|
setId(id);
|
||||||
|
setIsModalTrashActive(true);
|
||||||
|
};
|
||||||
|
const handleDeleteAction = async () => {
|
||||||
|
if (id) {
|
||||||
|
await dispatch(deleteItem(id));
|
||||||
|
await loadData(0);
|
||||||
|
setIsModalTrashActive(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateFilterRequests = useMemo(() => {
|
||||||
|
let request = '&';
|
||||||
|
filterItems.forEach((item) => {
|
||||||
|
const isRangeFilter = filters.find(
|
||||||
|
(filter) =>
|
||||||
|
filter.title === item.fields.selectedField &&
|
||||||
|
(filter.number || filter.date),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isRangeFilter) {
|
||||||
|
const from = item.fields.filterValueFrom;
|
||||||
|
const to = item.fields.filterValueTo;
|
||||||
|
if (from) {
|
||||||
|
request += `${item.fields.selectedField}Range=${from}&`;
|
||||||
|
}
|
||||||
|
if (to) {
|
||||||
|
request += `${item.fields.selectedField}Range=${to}&`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const value = item.fields.filterValue;
|
||||||
|
if (value) {
|
||||||
|
request += `${item.fields.selectedField}=${value}&`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return request;
|
||||||
|
}, [filterItems, filters]);
|
||||||
|
|
||||||
|
const deleteFilter = (value) => {
|
||||||
|
const newItems = filterItems.filter((item) => item.id !== value);
|
||||||
|
|
||||||
|
if (newItems.length) {
|
||||||
|
setFilterItems(newItems);
|
||||||
|
} else {
|
||||||
|
loadData(0, '');
|
||||||
|
|
||||||
|
setFilterItems(newItems);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
loadData(0, generateFilterRequests);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (id) => (e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
const name = e.target.name;
|
||||||
|
|
||||||
|
setFilterItems(
|
||||||
|
filterItems.map((item) => {
|
||||||
|
if (item.id !== id) return item;
|
||||||
|
if (name === 'selectedField') return { id, fields: { [name]: value } };
|
||||||
|
|
||||||
|
return { id, fields: { ...item.fields, [name]: value } };
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
setFilterItems([]);
|
||||||
|
loadData(0, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPageChange = (page: number) => {
|
||||||
|
loadData(page);
|
||||||
|
setCurrentPage(page);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentUser) return;
|
||||||
|
|
||||||
|
loadColumns(handleDeleteModalAction, `payment`, currentUser).then(
|
||||||
|
(newCols) => setColumns(newCols),
|
||||||
|
);
|
||||||
|
}, [currentUser]);
|
||||||
|
|
||||||
|
const handleTableSubmit = async (id: string, data) => {
|
||||||
|
if (!_.isEmpty(data)) {
|
||||||
|
await dispatch(update({ id, data }))
|
||||||
|
.unwrap()
|
||||||
|
.then((res) => res)
|
||||||
|
.catch((err) => {
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDeleteRows = async (selectedRows) => {
|
||||||
|
await dispatch(deleteItemsByIds(selectedRows));
|
||||||
|
await loadData(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const controlClasses =
|
||||||
|
'w-full py-2 px-2 my-2 rounded dark:placeholder-gray-400 ' +
|
||||||
|
` ${bgColor} ${focusRing} ${corners} ` +
|
||||||
|
'dark:bg-slate-800 border';
|
||||||
|
|
||||||
|
const dataGrid = (
|
||||||
|
<div className='relative overflow-x-auto'>
|
||||||
|
<DataGrid
|
||||||
|
autoHeight
|
||||||
|
rowHeight={64}
|
||||||
|
sx={dataGridStyles}
|
||||||
|
className={'datagrid--table'}
|
||||||
|
getRowClassName={() => `datagrid--row`}
|
||||||
|
rows={payment ?? []}
|
||||||
|
columns={columns}
|
||||||
|
initialState={{
|
||||||
|
pagination: {
|
||||||
|
paginationModel: {
|
||||||
|
pageSize: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
disableRowSelectionOnClick
|
||||||
|
onProcessRowUpdateError={(params) => {
|
||||||
|
console.log('Error', params);
|
||||||
|
}}
|
||||||
|
processRowUpdate={async (newRow, oldRow) => {
|
||||||
|
const data = dataFormatter.dataGridEditFormatter(newRow);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await handleTableSubmit(newRow.id, data);
|
||||||
|
return newRow;
|
||||||
|
} catch {
|
||||||
|
return oldRow;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
sortingMode={'server'}
|
||||||
|
checkboxSelection
|
||||||
|
onRowSelectionModelChange={(ids) => {
|
||||||
|
setSelectedRows(ids);
|
||||||
|
}}
|
||||||
|
onSortModelChange={(params) => {
|
||||||
|
params.length
|
||||||
|
? setSortModel(params)
|
||||||
|
: setSortModel([{ field: '', sort: 'desc' }]);
|
||||||
|
}}
|
||||||
|
rowCount={count}
|
||||||
|
pageSizeOptions={[10]}
|
||||||
|
paginationMode={'server'}
|
||||||
|
loading={loading}
|
||||||
|
onPaginationModelChange={(params) => {
|
||||||
|
onPageChange(params.page);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{filterItems && Array.isArray(filterItems) && filterItems.length ? (
|
||||||
|
<CardBox>
|
||||||
|
<Formik
|
||||||
|
initialValues={{
|
||||||
|
checkboxes: ['lorem'],
|
||||||
|
switches: ['lorem'],
|
||||||
|
radio: 'lorem',
|
||||||
|
}}
|
||||||
|
onSubmit={() => null}
|
||||||
|
>
|
||||||
|
<Form>
|
||||||
|
<>
|
||||||
|
{filterItems &&
|
||||||
|
filterItems.map((filterItem) => {
|
||||||
|
return (
|
||||||
|
<div key={filterItem.id} className='flex mb-4'>
|
||||||
|
<div className='flex flex-col w-full mr-3'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
Filter
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='selectedField'
|
||||||
|
id='selectedField'
|
||||||
|
component='select'
|
||||||
|
value={filterItem?.fields?.selectedField || ''}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
>
|
||||||
|
{filters.map((selectOption) => (
|
||||||
|
<option
|
||||||
|
key={selectOption.title}
|
||||||
|
value={`${selectOption.title}`}
|
||||||
|
>
|
||||||
|
{selectOption.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
{filters.find(
|
||||||
|
(filter) =>
|
||||||
|
filter.title === filterItem?.fields?.selectedField,
|
||||||
|
)?.type === 'enum' ? (
|
||||||
|
<div className='flex flex-col w-full mr-3'>
|
||||||
|
<div className='text-gray-500 font-bold'>Value</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValue'
|
||||||
|
id='filterValue'
|
||||||
|
component='select'
|
||||||
|
value={filterItem?.fields?.filterValue || ''}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
>
|
||||||
|
<option value=''>Select Value</option>
|
||||||
|
{filters
|
||||||
|
.find(
|
||||||
|
(filter) =>
|
||||||
|
filter.title ===
|
||||||
|
filterItem?.fields?.selectedField,
|
||||||
|
)
|
||||||
|
?.options?.map((option) => (
|
||||||
|
<option key={option} value={option}>
|
||||||
|
{option}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
) : filters.find(
|
||||||
|
(filter) =>
|
||||||
|
filter.title ===
|
||||||
|
filterItem?.fields?.selectedField,
|
||||||
|
)?.number ? (
|
||||||
|
<div className='flex flex-row w-full mr-3'>
|
||||||
|
<div className='flex flex-col w-full mr-3'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
From
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValueFrom'
|
||||||
|
placeholder='From'
|
||||||
|
id='filterValueFrom'
|
||||||
|
value={
|
||||||
|
filterItem?.fields?.filterValueFrom || ''
|
||||||
|
}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
To
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValueTo'
|
||||||
|
placeholder='to'
|
||||||
|
id='filterValueTo'
|
||||||
|
value={filterItem?.fields?.filterValueTo || ''}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : filters.find(
|
||||||
|
(filter) =>
|
||||||
|
filter.title ===
|
||||||
|
filterItem?.fields?.selectedField,
|
||||||
|
)?.date ? (
|
||||||
|
<div className='flex flex-row w-full mr-3'>
|
||||||
|
<div className='flex flex-col w-full mr-3'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
From
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValueFrom'
|
||||||
|
placeholder='From'
|
||||||
|
id='filterValueFrom'
|
||||||
|
type='datetime-local'
|
||||||
|
value={
|
||||||
|
filterItem?.fields?.filterValueFrom || ''
|
||||||
|
}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col w-full'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
To
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValueTo'
|
||||||
|
placeholder='to'
|
||||||
|
id='filterValueTo'
|
||||||
|
type='datetime-local'
|
||||||
|
value={filterItem?.fields?.filterValueTo || ''}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className='flex flex-col w-full mr-3'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
Contains
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
className={controlClasses}
|
||||||
|
name='filterValue'
|
||||||
|
placeholder='Contained'
|
||||||
|
id='filterValue'
|
||||||
|
value={filterItem?.fields?.filterValue || ''}
|
||||||
|
onChange={handleChange(filterItem.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<div className=' text-gray-500 font-bold'>
|
||||||
|
Action
|
||||||
|
</div>
|
||||||
|
<BaseButton
|
||||||
|
className='my-2'
|
||||||
|
type='reset'
|
||||||
|
color='danger'
|
||||||
|
label='Delete'
|
||||||
|
onClick={() => {
|
||||||
|
deleteFilter(filterItem.id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<div className='flex'>
|
||||||
|
<BaseButton
|
||||||
|
className='my-2 mr-3'
|
||||||
|
color='success'
|
||||||
|
label='Apply'
|
||||||
|
onClick={handleSubmit}
|
||||||
|
/>
|
||||||
|
<BaseButton
|
||||||
|
className='my-2'
|
||||||
|
color='info'
|
||||||
|
label='Cancel'
|
||||||
|
onClick={handleReset}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
</CardBox>
|
||||||
|
) : null}
|
||||||
|
<CardBoxModal
|
||||||
|
title='Please confirm'
|
||||||
|
buttonColor='info'
|
||||||
|
buttonLabel={loading ? 'Deleting...' : 'Confirm'}
|
||||||
|
isActive={isModalTrashActive}
|
||||||
|
onConfirm={handleDeleteAction}
|
||||||
|
onCancel={handleModalAction}
|
||||||
|
>
|
||||||
|
<p>Are you sure you want to delete this item?</p>
|
||||||
|
</CardBoxModal>
|
||||||
|
|
||||||
|
{dataGrid}
|
||||||
|
|
||||||
|
{selectedRows.length > 0 &&
|
||||||
|
createPortal(
|
||||||
|
<BaseButton
|
||||||
|
className='me-4'
|
||||||
|
color='danger'
|
||||||
|
label={`Delete ${selectedRows.length === 1 ? 'Row' : 'Rows'}`}
|
||||||
|
onClick={() => onDeleteRows(selectedRows)}
|
||||||
|
/>,
|
||||||
|
document.getElementById('delete-rows-button'),
|
||||||
|
)}
|
||||||
|
<ToastContainer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TableSamplePayment;
|
||||||
289
frontend/src/components/Payment/configurePaymentCols.tsx
Normal file
289
frontend/src/components/Payment/configurePaymentCols.tsx
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import BaseIcon from '../BaseIcon';
|
||||||
|
import { mdiEye, mdiTrashCan, mdiPencilOutline } from '@mdi/js';
|
||||||
|
import axios from 'axios';
|
||||||
|
import {
|
||||||
|
GridActionsCellItem,
|
||||||
|
GridRowParams,
|
||||||
|
GridValueGetterParams,
|
||||||
|
} from '@mui/x-data-grid';
|
||||||
|
import ImageField from '../ImageField';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import DataGridMultiSelect from '../DataGridMultiSelect';
|
||||||
|
import ListActionsPopover from '../ListActionsPopover';
|
||||||
|
|
||||||
|
import { hasPermission } from '../../helpers/userPermissions';
|
||||||
|
|
||||||
|
type Params = (id: string) => void;
|
||||||
|
|
||||||
|
export const loadColumns = async (
|
||||||
|
onDelete: Params,
|
||||||
|
entityName: string,
|
||||||
|
|
||||||
|
user,
|
||||||
|
) => {
|
||||||
|
async function callOptionsApi(entityName: string) {
|
||||||
|
if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await axios(`/${entityName}/autocomplete?limit=100`);
|
||||||
|
return data.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasUpdatePermission = hasPermission(user, 'UPDATE_PAYMENT');
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'student',
|
||||||
|
headerName: 'Student',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
sortable: false,
|
||||||
|
type: 'singleSelect',
|
||||||
|
getOptionValue: (value: any) => value?.id,
|
||||||
|
getOptionLabel: (value: any) => value?.label,
|
||||||
|
valueOptions: await callOptionsApi('students'),
|
||||||
|
valueGetter: (params: GridValueGetterParams) =>
|
||||||
|
params?.value?.id ?? params?.value,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'invoice',
|
||||||
|
headerName: 'Invoice',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
sortable: false,
|
||||||
|
type: 'singleSelect',
|
||||||
|
getOptionValue: (value: any) => value?.id,
|
||||||
|
getOptionLabel: (value: any) => value?.label,
|
||||||
|
valueOptions: await callOptionsApi('fees'),
|
||||||
|
valueGetter: (params: GridValueGetterParams) =>
|
||||||
|
params?.value?.id ?? params?.value,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'amountpaid',
|
||||||
|
headerName: 'Amountpaid',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'paymentmode',
|
||||||
|
headerName: 'Paymentmode',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'singleSelect',
|
||||||
|
valueOptions: ['value'],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'chequeno',
|
||||||
|
headerName: 'Chequeno',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'bankname',
|
||||||
|
headerName: 'Bankname',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'transactionid',
|
||||||
|
headerName: 'Transactionid',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'ddnumber',
|
||||||
|
headerName: 'Ddnumber',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'ddissuingbank',
|
||||||
|
headerName: 'Ddissuingbank',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'receiptnumber',
|
||||||
|
headerName: 'Receiptnumber',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'discountpercentage',
|
||||||
|
headerName: 'Discountpercentage',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'discountamount',
|
||||||
|
headerName: 'Discountamount',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'discountreason',
|
||||||
|
headerName: 'Discountreason',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'ddissuedate',
|
||||||
|
headerName: 'Ddissuedate',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'dateTime',
|
||||||
|
valueGetter: (params: GridValueGetterParams) =>
|
||||||
|
new Date(params.row.ddissuedate),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'remainingbalance',
|
||||||
|
headerName: 'Remainingbalance',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'paymentdate',
|
||||||
|
headerName: 'Paymentdate',
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 120,
|
||||||
|
filterable: false,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
|
||||||
|
editable: hasUpdatePermission,
|
||||||
|
|
||||||
|
type: 'dateTime',
|
||||||
|
valueGetter: (params: GridValueGetterParams) =>
|
||||||
|
new Date(params.row.paymentdate),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
minWidth: 30,
|
||||||
|
headerClassName: 'datagrid--header',
|
||||||
|
cellClassName: 'datagrid--cell',
|
||||||
|
getActions: (params: GridRowParams) => {
|
||||||
|
return [
|
||||||
|
<div key={params?.row?.id}>
|
||||||
|
<ListActionsPopover
|
||||||
|
onDelete={onDelete}
|
||||||
|
itemId={params?.row?.id}
|
||||||
|
pathEdit={`/payment/payment-edit/?id=${params?.row?.id}`}
|
||||||
|
pathView={`/payment/payment-view/?id=${params?.row?.id}`}
|
||||||
|
hasUpdatePermission={hasUpdatePermission}
|
||||||
|
/>
|
||||||
|
</div>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
@ -153,6 +153,14 @@ const menuAside: MenuAsideItem[] = [
|
|||||||
icon: icon.mdiShieldAccountOutline ?? icon.mdiTable,
|
icon: icon.mdiShieldAccountOutline ?? icon.mdiTable,
|
||||||
permissions: 'READ_PERMISSIONS',
|
permissions: 'READ_PERMISSIONS',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: '/payment/payment-list',
|
||||||
|
label: 'Payment',
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
icon: icon.mdiTable ?? icon.mdiTable,
|
||||||
|
permissions: 'READ_PAYMENT',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
href: '/profile',
|
href: '/profile',
|
||||||
label: 'Profile',
|
label: 'Profile',
|
||||||
|
|||||||
@ -42,6 +42,7 @@ const Dashboard = () => {
|
|||||||
const [students, setStudents] = React.useState(loadingMessage);
|
const [students, setStudents] = React.useState(loadingMessage);
|
||||||
const [roles, setRoles] = React.useState(loadingMessage);
|
const [roles, setRoles] = React.useState(loadingMessage);
|
||||||
const [permissions, setPermissions] = React.useState(loadingMessage);
|
const [permissions, setPermissions] = React.useState(loadingMessage);
|
||||||
|
const [payment, setPayment] = React.useState(loadingMessage);
|
||||||
|
|
||||||
const [widgetsRole, setWidgetsRole] = React.useState({
|
const [widgetsRole, setWidgetsRole] = React.useState({
|
||||||
role: { value: '', label: '' },
|
role: { value: '', label: '' },
|
||||||
@ -67,6 +68,7 @@ const Dashboard = () => {
|
|||||||
'students',
|
'students',
|
||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
|
'payment',
|
||||||
];
|
];
|
||||||
const fns = [
|
const fns = [
|
||||||
setUsers,
|
setUsers,
|
||||||
@ -83,6 +85,7 @@ const Dashboard = () => {
|
|||||||
setStudents,
|
setStudents,
|
||||||
setRoles,
|
setRoles,
|
||||||
setPermissions,
|
setPermissions,
|
||||||
|
setPayment,
|
||||||
];
|
];
|
||||||
|
|
||||||
const requests = entities.map((entity, index) => {
|
const requests = entities.map((entity, index) => {
|
||||||
@ -692,6 +695,38 @@ const Dashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{hasPermission(currentUser, 'READ_PAYMENT') && (
|
||||||
|
<Link href={'/payment/payment-list'}>
|
||||||
|
<div
|
||||||
|
className={`${
|
||||||
|
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
||||||
|
} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||||
|
>
|
||||||
|
<div className='flex justify-between align-center'>
|
||||||
|
<div>
|
||||||
|
<div className='text-lg leading-tight text-gray-500 dark:text-gray-400'>
|
||||||
|
Payment
|
||||||
|
</div>
|
||||||
|
<div className='text-3xl leading-tight font-semibold'>
|
||||||
|
{payment}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<BaseIcon
|
||||||
|
className={`${iconsColor}`}
|
||||||
|
w='w-16'
|
||||||
|
h='h-16'
|
||||||
|
size={48}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
path={icon.mdiTable || icon.mdiTable}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</SectionMain>
|
</SectionMain>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -87,6 +87,111 @@ const FeesView = () => {
|
|||||||
<p>{fees?.status ?? 'No data'}</p>
|
<p>{fees?.status ?? 'No data'}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<>
|
||||||
|
<p className={'block font-bold mb-2'}>Payment Invoice</p>
|
||||||
|
<CardBox
|
||||||
|
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
||||||
|
hasTable
|
||||||
|
>
|
||||||
|
<div className='overflow-x-auto'>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Amountpaid</th>
|
||||||
|
|
||||||
|
<th>Paymentmode</th>
|
||||||
|
|
||||||
|
<th>Chequeno</th>
|
||||||
|
|
||||||
|
<th>Bankname</th>
|
||||||
|
|
||||||
|
<th>Transactionid</th>
|
||||||
|
|
||||||
|
<th>Ddnumber</th>
|
||||||
|
|
||||||
|
<th>Ddissuingbank</th>
|
||||||
|
|
||||||
|
<th>Receiptnumber</th>
|
||||||
|
|
||||||
|
<th>Discountpercentage</th>
|
||||||
|
|
||||||
|
<th>Discountamount</th>
|
||||||
|
|
||||||
|
<th>Discountreason</th>
|
||||||
|
|
||||||
|
<th>Ddissuedate</th>
|
||||||
|
|
||||||
|
<th>Remainingbalance</th>
|
||||||
|
|
||||||
|
<th>Paymentdate</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{fees.payment_invoice &&
|
||||||
|
Array.isArray(fees.payment_invoice) &&
|
||||||
|
fees.payment_invoice.map((item: any) => (
|
||||||
|
<tr
|
||||||
|
key={item.id}
|
||||||
|
onClick={() =>
|
||||||
|
router.push(`/payment/payment-view/?id=${item.id}`)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<td data-label='amountpaid'>{item.amountpaid}</td>
|
||||||
|
|
||||||
|
<td data-label='paymentmode'>{item.paymentmode}</td>
|
||||||
|
|
||||||
|
<td data-label='chequeno'>{item.chequeno}</td>
|
||||||
|
|
||||||
|
<td data-label='bankname'>{item.bankname}</td>
|
||||||
|
|
||||||
|
<td data-label='transactionid'>
|
||||||
|
{item.transactionid}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='ddnumber'>{item.ddnumber}</td>
|
||||||
|
|
||||||
|
<td data-label='ddissuingbank'>
|
||||||
|
{item.ddissuingbank}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='receiptnumber'>
|
||||||
|
{item.receiptnumber}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountpercentage'>
|
||||||
|
{item.discountpercentage}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountamount'>
|
||||||
|
{item.discountamount}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountreason'>
|
||||||
|
{item.discountreason}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='ddissuedate'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.ddissuedate)}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='remainingbalance'>
|
||||||
|
{item.remainingbalance}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='paymentdate'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.paymentdate)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{!fees?.payment_invoice?.length && (
|
||||||
|
<div className={'text-center py-4'}>No data</div>
|
||||||
|
)}
|
||||||
|
</CardBox>
|
||||||
|
</>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
278
frontend/src/pages/payment/[paymentId].tsx
Normal file
278
frontend/src/pages/payment/[paymentId].tsx
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import React, { ReactElement, useEffect, useState } from 'react';
|
||||||
|
import DatePicker from 'react-datepicker';
|
||||||
|
import 'react-datepicker/dist/react-datepicker.css';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
|
||||||
|
import { Field, Form, Formik } from 'formik';
|
||||||
|
import FormField from '../../components/FormField';
|
||||||
|
import BaseDivider from '../../components/BaseDivider';
|
||||||
|
import BaseButtons from '../../components/BaseButtons';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import FormCheckRadio from '../../components/FormCheckRadio';
|
||||||
|
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
||||||
|
import FormFilePicker from '../../components/FormFilePicker';
|
||||||
|
import FormImagePicker from '../../components/FormImagePicker';
|
||||||
|
import { SelectField } from '../../components/SelectField';
|
||||||
|
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
||||||
|
import { SwitchField } from '../../components/SwitchField';
|
||||||
|
import { RichTextField } from '../../components/RichTextField';
|
||||||
|
|
||||||
|
import { update, fetch } from '../../stores/payment/paymentSlice';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import ImageField from '../../components/ImageField';
|
||||||
|
|
||||||
|
const EditPayment = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const initVals = {
|
||||||
|
student: null,
|
||||||
|
|
||||||
|
invoice: null,
|
||||||
|
|
||||||
|
amountpaid: '',
|
||||||
|
|
||||||
|
paymentmode: '',
|
||||||
|
|
||||||
|
chequeno: '',
|
||||||
|
|
||||||
|
bankname: '',
|
||||||
|
|
||||||
|
transactionid: '',
|
||||||
|
|
||||||
|
ddnumber: '',
|
||||||
|
|
||||||
|
ddissuingbank: '',
|
||||||
|
|
||||||
|
receiptnumber: '',
|
||||||
|
|
||||||
|
discountpercentage: '',
|
||||||
|
|
||||||
|
discountamount: '',
|
||||||
|
|
||||||
|
discountreason: '',
|
||||||
|
|
||||||
|
ddissuedate: new Date(),
|
||||||
|
|
||||||
|
remainingbalance: '',
|
||||||
|
|
||||||
|
paymentdate: new Date(),
|
||||||
|
};
|
||||||
|
const [initialValues, setInitialValues] = useState(initVals);
|
||||||
|
|
||||||
|
const { payment } = useAppSelector((state) => state.payment);
|
||||||
|
|
||||||
|
const { paymentId } = router.query;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetch({ id: paymentId }));
|
||||||
|
}, [paymentId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof payment === 'object') {
|
||||||
|
setInitialValues(payment);
|
||||||
|
}
|
||||||
|
}, [payment]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof payment === 'object') {
|
||||||
|
const newInitialVal = { ...initVals };
|
||||||
|
|
||||||
|
Object.keys(initVals).forEach((el) => (newInitialVal[el] = payment[el]));
|
||||||
|
|
||||||
|
setInitialValues(newInitialVal);
|
||||||
|
}
|
||||||
|
}, [payment]);
|
||||||
|
|
||||||
|
const handleSubmit = async (data) => {
|
||||||
|
await dispatch(update({ id: paymentId, data }));
|
||||||
|
await router.push('/payment/payment-list');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('Edit payment')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title={'Edit payment'}
|
||||||
|
main
|
||||||
|
>
|
||||||
|
{''}
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox>
|
||||||
|
<Formik
|
||||||
|
enableReinitialize
|
||||||
|
initialValues={initialValues}
|
||||||
|
onSubmit={(values) => handleSubmit(values)}
|
||||||
|
>
|
||||||
|
<Form>
|
||||||
|
<FormField label='Student' labelFor='student'>
|
||||||
|
<Field
|
||||||
|
name='student'
|
||||||
|
id='student'
|
||||||
|
component={SelectField}
|
||||||
|
options={initialValues.student}
|
||||||
|
itemRef={'students'}
|
||||||
|
showField={'first_name'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Invoice' labelFor='invoice'>
|
||||||
|
<Field
|
||||||
|
name='invoice'
|
||||||
|
id='invoice'
|
||||||
|
component={SelectField}
|
||||||
|
options={initialValues.invoice}
|
||||||
|
itemRef={'fees'}
|
||||||
|
showField={'amount'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Amountpaid'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='amountpaid'
|
||||||
|
placeholder='Amountpaid'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentmode'>
|
||||||
|
<FormCheckRadioGroup>
|
||||||
|
<FormCheckRadio type='radio' label='value'>
|
||||||
|
<Field type='radio' name='paymentmode' value='value' />
|
||||||
|
</FormCheckRadio>
|
||||||
|
</FormCheckRadioGroup>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Chequeno'>
|
||||||
|
<Field name='chequeno' placeholder='Chequeno' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Bankname'>
|
||||||
|
<Field name='bankname' placeholder='Bankname' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Transactionid'>
|
||||||
|
<Field name='transactionid' placeholder='Transactionid' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddnumber'>
|
||||||
|
<Field name='ddnumber' placeholder='Ddnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuingbank'>
|
||||||
|
<Field name='ddissuingbank' placeholder='Ddissuingbank' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Receiptnumber'>
|
||||||
|
<Field name='receiptnumber' placeholder='Receiptnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountpercentage'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountpercentage'
|
||||||
|
placeholder='Discountpercentage'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountamount'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountamount'
|
||||||
|
placeholder='Discountamount'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountreason'>
|
||||||
|
<Field name='discountreason' placeholder='Discountreason' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuedate'>
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
initialValues.ddissuedate
|
||||||
|
? new Date(
|
||||||
|
dayjs(initialValues.ddissuedate).format(
|
||||||
|
'YYYY-MM-DD hh:mm',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(date) =>
|
||||||
|
setInitialValues({ ...initialValues, ddissuedate: date })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Remainingbalance'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='remainingbalance'
|
||||||
|
placeholder='Remainingbalance'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentdate'>
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
initialValues.paymentdate
|
||||||
|
? new Date(
|
||||||
|
dayjs(initialValues.paymentdate).format(
|
||||||
|
'YYYY-MM-DD hh:mm',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(date) =>
|
||||||
|
setInitialValues({ ...initialValues, paymentdate: date })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<BaseDivider />
|
||||||
|
<BaseButtons>
|
||||||
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
<BaseButton type='reset' color='info' outline label='Reset' />
|
||||||
|
<BaseButton
|
||||||
|
type='reset'
|
||||||
|
color='danger'
|
||||||
|
outline
|
||||||
|
label='Cancel'
|
||||||
|
onClick={() => router.push('/payment/payment-list')}
|
||||||
|
/>
|
||||||
|
</BaseButtons>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
EditPayment.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'UPDATE_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditPayment;
|
||||||
276
frontend/src/pages/payment/payment-edit.tsx
Normal file
276
frontend/src/pages/payment/payment-edit.tsx
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import React, { ReactElement, useEffect, useState } from 'react';
|
||||||
|
import DatePicker from 'react-datepicker';
|
||||||
|
import 'react-datepicker/dist/react-datepicker.css';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
|
||||||
|
import { Field, Form, Formik } from 'formik';
|
||||||
|
import FormField from '../../components/FormField';
|
||||||
|
import BaseDivider from '../../components/BaseDivider';
|
||||||
|
import BaseButtons from '../../components/BaseButtons';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import FormCheckRadio from '../../components/FormCheckRadio';
|
||||||
|
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
||||||
|
import FormFilePicker from '../../components/FormFilePicker';
|
||||||
|
import FormImagePicker from '../../components/FormImagePicker';
|
||||||
|
import { SelectField } from '../../components/SelectField';
|
||||||
|
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
||||||
|
import { SwitchField } from '../../components/SwitchField';
|
||||||
|
import { RichTextField } from '../../components/RichTextField';
|
||||||
|
|
||||||
|
import { update, fetch } from '../../stores/payment/paymentSlice';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import ImageField from '../../components/ImageField';
|
||||||
|
|
||||||
|
const EditPaymentPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const initVals = {
|
||||||
|
student: null,
|
||||||
|
|
||||||
|
invoice: null,
|
||||||
|
|
||||||
|
amountpaid: '',
|
||||||
|
|
||||||
|
paymentmode: '',
|
||||||
|
|
||||||
|
chequeno: '',
|
||||||
|
|
||||||
|
bankname: '',
|
||||||
|
|
||||||
|
transactionid: '',
|
||||||
|
|
||||||
|
ddnumber: '',
|
||||||
|
|
||||||
|
ddissuingbank: '',
|
||||||
|
|
||||||
|
receiptnumber: '',
|
||||||
|
|
||||||
|
discountpercentage: '',
|
||||||
|
|
||||||
|
discountamount: '',
|
||||||
|
|
||||||
|
discountreason: '',
|
||||||
|
|
||||||
|
ddissuedate: new Date(),
|
||||||
|
|
||||||
|
remainingbalance: '',
|
||||||
|
|
||||||
|
paymentdate: new Date(),
|
||||||
|
};
|
||||||
|
const [initialValues, setInitialValues] = useState(initVals);
|
||||||
|
|
||||||
|
const { payment } = useAppSelector((state) => state.payment);
|
||||||
|
|
||||||
|
const { id } = router.query;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetch({ id: id }));
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof payment === 'object') {
|
||||||
|
setInitialValues(payment);
|
||||||
|
}
|
||||||
|
}, [payment]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof payment === 'object') {
|
||||||
|
const newInitialVal = { ...initVals };
|
||||||
|
Object.keys(initVals).forEach((el) => (newInitialVal[el] = payment[el]));
|
||||||
|
setInitialValues(newInitialVal);
|
||||||
|
}
|
||||||
|
}, [payment]);
|
||||||
|
|
||||||
|
const handleSubmit = async (data) => {
|
||||||
|
await dispatch(update({ id: id, data }));
|
||||||
|
await router.push('/payment/payment-list');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('Edit payment')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title={'Edit payment'}
|
||||||
|
main
|
||||||
|
>
|
||||||
|
{''}
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox>
|
||||||
|
<Formik
|
||||||
|
enableReinitialize
|
||||||
|
initialValues={initialValues}
|
||||||
|
onSubmit={(values) => handleSubmit(values)}
|
||||||
|
>
|
||||||
|
<Form>
|
||||||
|
<FormField label='Student' labelFor='student'>
|
||||||
|
<Field
|
||||||
|
name='student'
|
||||||
|
id='student'
|
||||||
|
component={SelectField}
|
||||||
|
options={initialValues.student}
|
||||||
|
itemRef={'students'}
|
||||||
|
showField={'first_name'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Invoice' labelFor='invoice'>
|
||||||
|
<Field
|
||||||
|
name='invoice'
|
||||||
|
id='invoice'
|
||||||
|
component={SelectField}
|
||||||
|
options={initialValues.invoice}
|
||||||
|
itemRef={'fees'}
|
||||||
|
showField={'amount'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Amountpaid'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='amountpaid'
|
||||||
|
placeholder='Amountpaid'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentmode'>
|
||||||
|
<FormCheckRadioGroup>
|
||||||
|
<FormCheckRadio type='radio' label='value'>
|
||||||
|
<Field type='radio' name='paymentmode' value='value' />
|
||||||
|
</FormCheckRadio>
|
||||||
|
</FormCheckRadioGroup>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Chequeno'>
|
||||||
|
<Field name='chequeno' placeholder='Chequeno' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Bankname'>
|
||||||
|
<Field name='bankname' placeholder='Bankname' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Transactionid'>
|
||||||
|
<Field name='transactionid' placeholder='Transactionid' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddnumber'>
|
||||||
|
<Field name='ddnumber' placeholder='Ddnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuingbank'>
|
||||||
|
<Field name='ddissuingbank' placeholder='Ddissuingbank' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Receiptnumber'>
|
||||||
|
<Field name='receiptnumber' placeholder='Receiptnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountpercentage'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountpercentage'
|
||||||
|
placeholder='Discountpercentage'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountamount'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountamount'
|
||||||
|
placeholder='Discountamount'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountreason'>
|
||||||
|
<Field name='discountreason' placeholder='Discountreason' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuedate'>
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
initialValues.ddissuedate
|
||||||
|
? new Date(
|
||||||
|
dayjs(initialValues.ddissuedate).format(
|
||||||
|
'YYYY-MM-DD hh:mm',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(date) =>
|
||||||
|
setInitialValues({ ...initialValues, ddissuedate: date })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Remainingbalance'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='remainingbalance'
|
||||||
|
placeholder='Remainingbalance'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentdate'>
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
initialValues.paymentdate
|
||||||
|
? new Date(
|
||||||
|
dayjs(initialValues.paymentdate).format(
|
||||||
|
'YYYY-MM-DD hh:mm',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(date) =>
|
||||||
|
setInitialValues({ ...initialValues, paymentdate: date })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<BaseDivider />
|
||||||
|
<BaseButtons>
|
||||||
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
<BaseButton type='reset' color='info' outline label='Reset' />
|
||||||
|
<BaseButton
|
||||||
|
type='reset'
|
||||||
|
color='danger'
|
||||||
|
outline
|
||||||
|
label='Cancel'
|
||||||
|
onClick={() => router.push('/payment/payment-list')}
|
||||||
|
/>
|
||||||
|
</BaseButtons>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
EditPaymentPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'UPDATE_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditPaymentPage;
|
||||||
192
frontend/src/pages/payment/payment-list.tsx
Normal file
192
frontend/src/pages/payment/payment-list.tsx
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
import { mdiChartTimelineVariant } from '@mdi/js';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import { uniqueId } from 'lodash';
|
||||||
|
import React, { ReactElement, useState } from 'react';
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
import TablePayment from '../../components/Payment/TablePayment';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import axios from 'axios';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import CardBoxModal from '../../components/CardBoxModal';
|
||||||
|
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
||||||
|
import { setRefetch, uploadCsv } from '../../stores/payment/paymentSlice';
|
||||||
|
|
||||||
|
import { hasPermission } from '../../helpers/userPermissions';
|
||||||
|
|
||||||
|
const PaymentTablesPage = () => {
|
||||||
|
const [filterItems, setFilterItems] = useState([]);
|
||||||
|
const [csvFile, setCsvFile] = useState<File | null>(null);
|
||||||
|
const [isModalActive, setIsModalActive] = useState(false);
|
||||||
|
const [showTableView, setShowTableView] = useState(false);
|
||||||
|
|
||||||
|
const { currentUser } = useAppSelector((state) => state.auth);
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const [filters] = useState([
|
||||||
|
{ label: 'Chequeno', title: 'chequeno' },
|
||||||
|
{ label: 'Bankname', title: 'bankname' },
|
||||||
|
{ label: 'Transactionid', title: 'transactionid' },
|
||||||
|
{ label: 'Ddnumber', title: 'ddnumber' },
|
||||||
|
{ label: 'Ddissuingbank', title: 'ddissuingbank' },
|
||||||
|
{ label: 'Receiptnumber', title: 'receiptnumber' },
|
||||||
|
{ label: 'Discountreason', title: 'discountreason' },
|
||||||
|
|
||||||
|
{ label: 'Amountpaid', title: 'amountpaid', number: 'true' },
|
||||||
|
{
|
||||||
|
label: 'Discountpercentage',
|
||||||
|
title: 'discountpercentage',
|
||||||
|
number: 'true',
|
||||||
|
},
|
||||||
|
{ label: 'Discountamount', title: 'discountamount', number: 'true' },
|
||||||
|
{ label: 'Remainingbalance', title: 'remainingbalance', number: 'true' },
|
||||||
|
{ label: 'Ddissuedate', title: 'ddissuedate', date: 'true' },
|
||||||
|
{ label: 'Paymentdate', title: 'paymentdate', date: 'true' },
|
||||||
|
|
||||||
|
{ label: 'Student', title: 'student' },
|
||||||
|
|
||||||
|
{ label: 'Invoice', title: 'invoice' },
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'Paymentmode',
|
||||||
|
title: 'paymentmode',
|
||||||
|
type: 'enum',
|
||||||
|
options: ['value'],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const hasCreatePermission =
|
||||||
|
currentUser && hasPermission(currentUser, 'CREATE_PAYMENT');
|
||||||
|
|
||||||
|
const addFilter = () => {
|
||||||
|
const newItem = {
|
||||||
|
id: uniqueId(),
|
||||||
|
fields: {
|
||||||
|
filterValue: '',
|
||||||
|
filterValueFrom: '',
|
||||||
|
filterValueTo: '',
|
||||||
|
selectedField: '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
newItem.fields.selectedField = filters[0].title;
|
||||||
|
setFilterItems([...filterItems, newItem]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPaymentCSV = async () => {
|
||||||
|
const response = await axios({
|
||||||
|
url: '/payment?filetype=csv',
|
||||||
|
method: 'GET',
|
||||||
|
responseType: 'blob',
|
||||||
|
});
|
||||||
|
const type = response.headers['content-type'];
|
||||||
|
const blob = new Blob([response.data], { type: type });
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = window.URL.createObjectURL(blob);
|
||||||
|
link.download = 'paymentCSV.csv';
|
||||||
|
link.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onModalConfirm = async () => {
|
||||||
|
if (!csvFile) return;
|
||||||
|
await dispatch(uploadCsv(csvFile));
|
||||||
|
dispatch(setRefetch(true));
|
||||||
|
setCsvFile(null);
|
||||||
|
setIsModalActive(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onModalCancel = () => {
|
||||||
|
setCsvFile(null);
|
||||||
|
setIsModalActive(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('Payment')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title='Payment'
|
||||||
|
main
|
||||||
|
>
|
||||||
|
{''}
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
||||||
|
{hasCreatePermission && (
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
href={'/payment/payment-new'}
|
||||||
|
color='info'
|
||||||
|
label='New Item'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
color='info'
|
||||||
|
label='Filter'
|
||||||
|
onClick={addFilter}
|
||||||
|
/>
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
color='info'
|
||||||
|
label='Download CSV'
|
||||||
|
onClick={getPaymentCSV}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{hasCreatePermission && (
|
||||||
|
<BaseButton
|
||||||
|
color='info'
|
||||||
|
label='Upload CSV'
|
||||||
|
onClick={() => setIsModalActive(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className='md:inline-flex items-center ms-auto'>
|
||||||
|
<div id='delete-rows-button'></div>
|
||||||
|
</div>
|
||||||
|
</CardBox>
|
||||||
|
|
||||||
|
<CardBox className='mb-6' hasTable>
|
||||||
|
<TablePayment
|
||||||
|
filterItems={filterItems}
|
||||||
|
setFilterItems={setFilterItems}
|
||||||
|
filters={filters}
|
||||||
|
showGrid={false}
|
||||||
|
/>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
<CardBoxModal
|
||||||
|
title='Upload CSV'
|
||||||
|
buttonColor='info'
|
||||||
|
buttonLabel={'Confirm'}
|
||||||
|
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
||||||
|
isActive={isModalActive}
|
||||||
|
onConfirm={onModalConfirm}
|
||||||
|
onCancel={onModalCancel}
|
||||||
|
>
|
||||||
|
<DragDropFilePicker
|
||||||
|
file={csvFile}
|
||||||
|
setFile={setCsvFile}
|
||||||
|
formats={'.csv'}
|
||||||
|
/>
|
||||||
|
</CardBoxModal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PaymentTablesPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'READ_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentTablesPage;
|
||||||
228
frontend/src/pages/payment/payment-new.tsx
Normal file
228
frontend/src/pages/payment/payment-new.tsx
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
import {
|
||||||
|
mdiAccount,
|
||||||
|
mdiChartTimelineVariant,
|
||||||
|
mdiMail,
|
||||||
|
mdiUpload,
|
||||||
|
} from '@mdi/js';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import React, { ReactElement } from 'react';
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
|
||||||
|
import { Field, Form, Formik } from 'formik';
|
||||||
|
import FormField from '../../components/FormField';
|
||||||
|
import BaseDivider from '../../components/BaseDivider';
|
||||||
|
import BaseButtons from '../../components/BaseButtons';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import FormCheckRadio from '../../components/FormCheckRadio';
|
||||||
|
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
||||||
|
import FormFilePicker from '../../components/FormFilePicker';
|
||||||
|
import FormImagePicker from '../../components/FormImagePicker';
|
||||||
|
import { SwitchField } from '../../components/SwitchField';
|
||||||
|
|
||||||
|
import { SelectField } from '../../components/SelectField';
|
||||||
|
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
||||||
|
import { RichTextField } from '../../components/RichTextField';
|
||||||
|
|
||||||
|
import { create } from '../../stores/payment/paymentSlice';
|
||||||
|
import { useAppDispatch } from '../../stores/hooks';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
student: '',
|
||||||
|
|
||||||
|
invoice: '',
|
||||||
|
|
||||||
|
amountpaid: '',
|
||||||
|
|
||||||
|
paymentmode: '',
|
||||||
|
|
||||||
|
chequeno: '',
|
||||||
|
|
||||||
|
bankname: '',
|
||||||
|
|
||||||
|
transactionid: '',
|
||||||
|
|
||||||
|
ddnumber: '',
|
||||||
|
|
||||||
|
ddissuingbank: '',
|
||||||
|
|
||||||
|
receiptnumber: '',
|
||||||
|
|
||||||
|
discountpercentage: '',
|
||||||
|
|
||||||
|
discountamount: '',
|
||||||
|
|
||||||
|
discountreason: '',
|
||||||
|
|
||||||
|
ddissuedate: '',
|
||||||
|
|
||||||
|
remainingbalance: '',
|
||||||
|
|
||||||
|
paymentdate: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const PaymentNew = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const handleSubmit = async (data) => {
|
||||||
|
await dispatch(create(data));
|
||||||
|
await router.push('/payment/payment-list');
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('New Item')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title='New Item'
|
||||||
|
main
|
||||||
|
>
|
||||||
|
{''}
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox>
|
||||||
|
<Formik
|
||||||
|
initialValues={initialValues}
|
||||||
|
onSubmit={(values) => handleSubmit(values)}
|
||||||
|
>
|
||||||
|
<Form>
|
||||||
|
<FormField label='Student' labelFor='student'>
|
||||||
|
<Field
|
||||||
|
name='student'
|
||||||
|
id='student'
|
||||||
|
component={SelectField}
|
||||||
|
options={[]}
|
||||||
|
itemRef={'students'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Invoice' labelFor='invoice'>
|
||||||
|
<Field
|
||||||
|
name='invoice'
|
||||||
|
id='invoice'
|
||||||
|
component={SelectField}
|
||||||
|
options={[]}
|
||||||
|
itemRef={'fees'}
|
||||||
|
></Field>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Amountpaid'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='amountpaid'
|
||||||
|
placeholder='Amountpaid'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentmode'>
|
||||||
|
<FormCheckRadioGroup>
|
||||||
|
<FormCheckRadio type='radio' label='value'>
|
||||||
|
<Field type='radio' name='paymentmode' value='value' />
|
||||||
|
</FormCheckRadio>
|
||||||
|
</FormCheckRadioGroup>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Chequeno'>
|
||||||
|
<Field name='chequeno' placeholder='Chequeno' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Bankname'>
|
||||||
|
<Field name='bankname' placeholder='Bankname' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Transactionid'>
|
||||||
|
<Field name='transactionid' placeholder='Transactionid' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddnumber'>
|
||||||
|
<Field name='ddnumber' placeholder='Ddnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuingbank'>
|
||||||
|
<Field name='ddissuingbank' placeholder='Ddissuingbank' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Receiptnumber'>
|
||||||
|
<Field name='receiptnumber' placeholder='Receiptnumber' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountpercentage'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountpercentage'
|
||||||
|
placeholder='Discountpercentage'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountamount'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='discountamount'
|
||||||
|
placeholder='Discountamount'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Discountreason'>
|
||||||
|
<Field name='discountreason' placeholder='Discountreason' />
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Ddissuedate'>
|
||||||
|
<Field
|
||||||
|
type='datetime-local'
|
||||||
|
name='ddissuedate'
|
||||||
|
placeholder='Ddissuedate'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Remainingbalance'>
|
||||||
|
<Field
|
||||||
|
type='number'
|
||||||
|
name='remainingbalance'
|
||||||
|
placeholder='Remainingbalance'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<FormField label='Paymentdate'>
|
||||||
|
<Field
|
||||||
|
type='datetime-local'
|
||||||
|
name='paymentdate'
|
||||||
|
placeholder='Paymentdate'
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<BaseDivider />
|
||||||
|
<BaseButtons>
|
||||||
|
<BaseButton type='submit' color='info' label='Submit' />
|
||||||
|
<BaseButton type='reset' color='info' outline label='Reset' />
|
||||||
|
<BaseButton
|
||||||
|
type='reset'
|
||||||
|
color='danger'
|
||||||
|
outline
|
||||||
|
label='Cancel'
|
||||||
|
onClick={() => router.push('/payment/payment-list')}
|
||||||
|
/>
|
||||||
|
</BaseButtons>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PaymentNew.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'CREATE_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentNew;
|
||||||
191
frontend/src/pages/payment/payment-table.tsx
Normal file
191
frontend/src/pages/payment/payment-table.tsx
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
import { mdiChartTimelineVariant } from '@mdi/js';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import { uniqueId } from 'lodash';
|
||||||
|
import React, { ReactElement, useState } from 'react';
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
import TablePayment from '../../components/Payment/TablePayment';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import axios from 'axios';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import CardBoxModal from '../../components/CardBoxModal';
|
||||||
|
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
||||||
|
import { setRefetch, uploadCsv } from '../../stores/payment/paymentSlice';
|
||||||
|
|
||||||
|
import { hasPermission } from '../../helpers/userPermissions';
|
||||||
|
|
||||||
|
const PaymentTablesPage = () => {
|
||||||
|
const [filterItems, setFilterItems] = useState([]);
|
||||||
|
const [csvFile, setCsvFile] = useState<File | null>(null);
|
||||||
|
const [isModalActive, setIsModalActive] = useState(false);
|
||||||
|
const [showTableView, setShowTableView] = useState(false);
|
||||||
|
|
||||||
|
const { currentUser } = useAppSelector((state) => state.auth);
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const [filters] = useState([
|
||||||
|
{ label: 'Chequeno', title: 'chequeno' },
|
||||||
|
{ label: 'Bankname', title: 'bankname' },
|
||||||
|
{ label: 'Transactionid', title: 'transactionid' },
|
||||||
|
{ label: 'Ddnumber', title: 'ddnumber' },
|
||||||
|
{ label: 'Ddissuingbank', title: 'ddissuingbank' },
|
||||||
|
{ label: 'Receiptnumber', title: 'receiptnumber' },
|
||||||
|
{ label: 'Discountreason', title: 'discountreason' },
|
||||||
|
|
||||||
|
{ label: 'Amountpaid', title: 'amountpaid', number: 'true' },
|
||||||
|
{
|
||||||
|
label: 'Discountpercentage',
|
||||||
|
title: 'discountpercentage',
|
||||||
|
number: 'true',
|
||||||
|
},
|
||||||
|
{ label: 'Discountamount', title: 'discountamount', number: 'true' },
|
||||||
|
{ label: 'Remainingbalance', title: 'remainingbalance', number: 'true' },
|
||||||
|
{ label: 'Ddissuedate', title: 'ddissuedate', date: 'true' },
|
||||||
|
{ label: 'Paymentdate', title: 'paymentdate', date: 'true' },
|
||||||
|
|
||||||
|
{ label: 'Student', title: 'student' },
|
||||||
|
|
||||||
|
{ label: 'Invoice', title: 'invoice' },
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'Paymentmode',
|
||||||
|
title: 'paymentmode',
|
||||||
|
type: 'enum',
|
||||||
|
options: ['value'],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const hasCreatePermission =
|
||||||
|
currentUser && hasPermission(currentUser, 'CREATE_PAYMENT');
|
||||||
|
|
||||||
|
const addFilter = () => {
|
||||||
|
const newItem = {
|
||||||
|
id: uniqueId(),
|
||||||
|
fields: {
|
||||||
|
filterValue: '',
|
||||||
|
filterValueFrom: '',
|
||||||
|
filterValueTo: '',
|
||||||
|
selectedField: '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
newItem.fields.selectedField = filters[0].title;
|
||||||
|
setFilterItems([...filterItems, newItem]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPaymentCSV = async () => {
|
||||||
|
const response = await axios({
|
||||||
|
url: '/payment?filetype=csv',
|
||||||
|
method: 'GET',
|
||||||
|
responseType: 'blob',
|
||||||
|
});
|
||||||
|
const type = response.headers['content-type'];
|
||||||
|
const blob = new Blob([response.data], { type: type });
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = window.URL.createObjectURL(blob);
|
||||||
|
link.download = 'paymentCSV.csv';
|
||||||
|
link.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onModalConfirm = async () => {
|
||||||
|
if (!csvFile) return;
|
||||||
|
await dispatch(uploadCsv(csvFile));
|
||||||
|
dispatch(setRefetch(true));
|
||||||
|
setCsvFile(null);
|
||||||
|
setIsModalActive(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onModalCancel = () => {
|
||||||
|
setCsvFile(null);
|
||||||
|
setIsModalActive(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('Payment')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title='Payment'
|
||||||
|
main
|
||||||
|
>
|
||||||
|
{''}
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
||||||
|
{hasCreatePermission && (
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
href={'/payment/payment-new'}
|
||||||
|
color='info'
|
||||||
|
label='New Item'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
color='info'
|
||||||
|
label='Filter'
|
||||||
|
onClick={addFilter}
|
||||||
|
/>
|
||||||
|
<BaseButton
|
||||||
|
className={'mr-3'}
|
||||||
|
color='info'
|
||||||
|
label='Download CSV'
|
||||||
|
onClick={getPaymentCSV}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{hasCreatePermission && (
|
||||||
|
<BaseButton
|
||||||
|
color='info'
|
||||||
|
label='Upload CSV'
|
||||||
|
onClick={() => setIsModalActive(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className='md:inline-flex items-center ms-auto'>
|
||||||
|
<div id='delete-rows-button'></div>
|
||||||
|
</div>
|
||||||
|
</CardBox>
|
||||||
|
<CardBox className='mb-6' hasTable>
|
||||||
|
<TablePayment
|
||||||
|
filterItems={filterItems}
|
||||||
|
setFilterItems={setFilterItems}
|
||||||
|
filters={filters}
|
||||||
|
showGrid={true}
|
||||||
|
/>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
<CardBoxModal
|
||||||
|
title='Upload CSV'
|
||||||
|
buttonColor='info'
|
||||||
|
buttonLabel={'Confirm'}
|
||||||
|
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
||||||
|
isActive={isModalActive}
|
||||||
|
onConfirm={onModalConfirm}
|
||||||
|
onCancel={onModalCancel}
|
||||||
|
>
|
||||||
|
<DragDropFilePicker
|
||||||
|
file={csvFile}
|
||||||
|
setFile={setCsvFile}
|
||||||
|
formats={'.csv'}
|
||||||
|
/>
|
||||||
|
</CardBoxModal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PaymentTablesPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'READ_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentTablesPage;
|
||||||
188
frontend/src/pages/payment/payment-view.tsx
Normal file
188
frontend/src/pages/payment/payment-view.tsx
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import React, { ReactElement, useEffect } from 'react';
|
||||||
|
import Head from 'next/head';
|
||||||
|
import DatePicker from 'react-datepicker';
|
||||||
|
import 'react-datepicker/dist/react-datepicker.css';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { fetch } from '../../stores/payment/paymentSlice';
|
||||||
|
import { saveFile } from '../../helpers/fileSaver';
|
||||||
|
import dataFormatter from '../../helpers/dataFormatter';
|
||||||
|
import ImageField from '../../components/ImageField';
|
||||||
|
import LayoutAuthenticated from '../../layouts/Authenticated';
|
||||||
|
import { getPageTitle } from '../../config';
|
||||||
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
||||||
|
import SectionMain from '../../components/SectionMain';
|
||||||
|
import CardBox from '../../components/CardBox';
|
||||||
|
import BaseButton from '../../components/BaseButton';
|
||||||
|
import BaseDivider from '../../components/BaseDivider';
|
||||||
|
import { mdiChartTimelineVariant } from '@mdi/js';
|
||||||
|
import { SwitchField } from '../../components/SwitchField';
|
||||||
|
import FormField from '../../components/FormField';
|
||||||
|
|
||||||
|
const PaymentView = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { payment } = useAppSelector((state) => state.payment);
|
||||||
|
|
||||||
|
const { id } = router.query;
|
||||||
|
|
||||||
|
function removeLastCharacter(str) {
|
||||||
|
console.log(str, `str`);
|
||||||
|
return str.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetch({ id }));
|
||||||
|
}, [dispatch, id]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{getPageTitle('View payment')}</title>
|
||||||
|
</Head>
|
||||||
|
<SectionMain>
|
||||||
|
<SectionTitleLineWithButton
|
||||||
|
icon={mdiChartTimelineVariant}
|
||||||
|
title={removeLastCharacter('View payment')}
|
||||||
|
main
|
||||||
|
>
|
||||||
|
<BaseButton
|
||||||
|
color='info'
|
||||||
|
label='Edit'
|
||||||
|
href={`/payment/payment-edit/?id=${id}`}
|
||||||
|
/>
|
||||||
|
</SectionTitleLineWithButton>
|
||||||
|
<CardBox>
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Student</p>
|
||||||
|
|
||||||
|
<p>{payment?.student?.first_name ?? 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Invoice</p>
|
||||||
|
|
||||||
|
<p>{payment?.invoice?.amount ?? 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Amountpaid</p>
|
||||||
|
<p>{payment?.amountpaid || 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Paymentmode</p>
|
||||||
|
<p>{payment?.paymentmode ?? 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Chequeno</p>
|
||||||
|
<p>{payment?.chequeno}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Bankname</p>
|
||||||
|
<p>{payment?.bankname}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Transactionid</p>
|
||||||
|
<p>{payment?.transactionid}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Ddnumber</p>
|
||||||
|
<p>{payment?.ddnumber}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Ddissuingbank</p>
|
||||||
|
<p>{payment?.ddissuingbank}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Receiptnumber</p>
|
||||||
|
<p>{payment?.receiptnumber}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Discountpercentage</p>
|
||||||
|
<p>{payment?.discountpercentage || 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Discountamount</p>
|
||||||
|
<p>{payment?.discountamount || 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Discountreason</p>
|
||||||
|
<p>{payment?.discountreason}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField label='Ddissuedate'>
|
||||||
|
{payment.ddissuedate ? (
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
payment.ddissuedate
|
||||||
|
? new Date(
|
||||||
|
dayjs(payment.ddissuedate).format('YYYY-MM-DD hh:mm'),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p>No Ddissuedate</p>
|
||||||
|
)}
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<div className={'mb-4'}>
|
||||||
|
<p className={'block font-bold mb-2'}>Remainingbalance</p>
|
||||||
|
<p>{payment?.remainingbalance || 'No data'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField label='Paymentdate'>
|
||||||
|
{payment.paymentdate ? (
|
||||||
|
<DatePicker
|
||||||
|
dateFormat='yyyy-MM-dd hh:mm'
|
||||||
|
showTimeSelect
|
||||||
|
selected={
|
||||||
|
payment.paymentdate
|
||||||
|
? new Date(
|
||||||
|
dayjs(payment.paymentdate).format('YYYY-MM-DD hh:mm'),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p>No Paymentdate</p>
|
||||||
|
)}
|
||||||
|
</FormField>
|
||||||
|
|
||||||
|
<BaseDivider />
|
||||||
|
|
||||||
|
<BaseButton
|
||||||
|
color='info'
|
||||||
|
label='Back'
|
||||||
|
onClick={() => router.push('/payment/payment-list')}
|
||||||
|
/>
|
||||||
|
</CardBox>
|
||||||
|
</SectionMain>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PaymentView.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return (
|
||||||
|
<LayoutAuthenticated permission={'READ_PAYMENT'}>
|
||||||
|
{page}
|
||||||
|
</LayoutAuthenticated>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentView;
|
||||||
@ -311,6 +311,111 @@ const StudentsView = () => {
|
|||||||
</CardBox>
|
</CardBox>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
|
<>
|
||||||
|
<p className={'block font-bold mb-2'}>Payment Student</p>
|
||||||
|
<CardBox
|
||||||
|
className='mb-6 border border-gray-300 rounded overflow-hidden'
|
||||||
|
hasTable
|
||||||
|
>
|
||||||
|
<div className='overflow-x-auto'>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Amountpaid</th>
|
||||||
|
|
||||||
|
<th>Paymentmode</th>
|
||||||
|
|
||||||
|
<th>Chequeno</th>
|
||||||
|
|
||||||
|
<th>Bankname</th>
|
||||||
|
|
||||||
|
<th>Transactionid</th>
|
||||||
|
|
||||||
|
<th>Ddnumber</th>
|
||||||
|
|
||||||
|
<th>Ddissuingbank</th>
|
||||||
|
|
||||||
|
<th>Receiptnumber</th>
|
||||||
|
|
||||||
|
<th>Discountpercentage</th>
|
||||||
|
|
||||||
|
<th>Discountamount</th>
|
||||||
|
|
||||||
|
<th>Discountreason</th>
|
||||||
|
|
||||||
|
<th>Ddissuedate</th>
|
||||||
|
|
||||||
|
<th>Remainingbalance</th>
|
||||||
|
|
||||||
|
<th>Paymentdate</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{students.payment_student &&
|
||||||
|
Array.isArray(students.payment_student) &&
|
||||||
|
students.payment_student.map((item: any) => (
|
||||||
|
<tr
|
||||||
|
key={item.id}
|
||||||
|
onClick={() =>
|
||||||
|
router.push(`/payment/payment-view/?id=${item.id}`)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<td data-label='amountpaid'>{item.amountpaid}</td>
|
||||||
|
|
||||||
|
<td data-label='paymentmode'>{item.paymentmode}</td>
|
||||||
|
|
||||||
|
<td data-label='chequeno'>{item.chequeno}</td>
|
||||||
|
|
||||||
|
<td data-label='bankname'>{item.bankname}</td>
|
||||||
|
|
||||||
|
<td data-label='transactionid'>
|
||||||
|
{item.transactionid}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='ddnumber'>{item.ddnumber}</td>
|
||||||
|
|
||||||
|
<td data-label='ddissuingbank'>
|
||||||
|
{item.ddissuingbank}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='receiptnumber'>
|
||||||
|
{item.receiptnumber}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountpercentage'>
|
||||||
|
{item.discountpercentage}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountamount'>
|
||||||
|
{item.discountamount}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='discountreason'>
|
||||||
|
{item.discountreason}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='ddissuedate'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.ddissuedate)}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='remainingbalance'>
|
||||||
|
{item.remainingbalance}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-label='paymentdate'>
|
||||||
|
{dataFormatter.dateTimeFormatter(item.paymentdate)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{!students?.payment_student?.length && (
|
||||||
|
<div className={'text-center py-4'}>No data</div>
|
||||||
|
)}
|
||||||
|
</CardBox>
|
||||||
|
</>
|
||||||
|
|
||||||
<BaseDivider />
|
<BaseDivider />
|
||||||
|
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
|||||||
236
frontend/src/stores/payment/paymentSlice.ts
Normal file
236
frontend/src/stores/payment/paymentSlice.ts
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit';
|
||||||
|
import axios from 'axios';
|
||||||
|
import {
|
||||||
|
fulfilledNotify,
|
||||||
|
rejectNotify,
|
||||||
|
resetNotify,
|
||||||
|
} from '../../helpers/notifyStateHandler';
|
||||||
|
|
||||||
|
interface MainState {
|
||||||
|
payment: any;
|
||||||
|
loading: boolean;
|
||||||
|
count: number;
|
||||||
|
refetch: boolean;
|
||||||
|
rolesWidgets: any[];
|
||||||
|
notify: {
|
||||||
|
showNotification: boolean;
|
||||||
|
textNotification: string;
|
||||||
|
typeNotification: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: MainState = {
|
||||||
|
payment: [],
|
||||||
|
loading: false,
|
||||||
|
count: 0,
|
||||||
|
refetch: false,
|
||||||
|
rolesWidgets: [],
|
||||||
|
notify: {
|
||||||
|
showNotification: false,
|
||||||
|
textNotification: '',
|
||||||
|
typeNotification: 'warn',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetch = createAsyncThunk('payment/fetch', async (data: any) => {
|
||||||
|
const { id, query } = data;
|
||||||
|
const result = await axios.get(`payment${query || (id ? `/${id}` : '')}`);
|
||||||
|
return id
|
||||||
|
? result.data
|
||||||
|
: { rows: result.data.rows, count: result.data.count };
|
||||||
|
});
|
||||||
|
|
||||||
|
export const deleteItemsByIds = createAsyncThunk(
|
||||||
|
'payment/deleteByIds',
|
||||||
|
async (data: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await axios.post('payment/deleteByIds', { data });
|
||||||
|
} catch (error) {
|
||||||
|
if (!error.response) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deleteItem = createAsyncThunk(
|
||||||
|
'payment/deletePayment',
|
||||||
|
async (id: string, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await axios.delete(`payment/${id}`);
|
||||||
|
} catch (error) {
|
||||||
|
if (!error.response) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const create = createAsyncThunk(
|
||||||
|
'payment/createPayment',
|
||||||
|
async (data: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const result = await axios.post('payment', { data });
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (!error.response) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const uploadCsv = createAsyncThunk(
|
||||||
|
'payment/uploadCsv',
|
||||||
|
async (file: File, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const data = new FormData();
|
||||||
|
data.append('file', file);
|
||||||
|
data.append('filename', file.name);
|
||||||
|
|
||||||
|
const result = await axios.post('payment/bulk-import', data, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (!error.response) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const update = createAsyncThunk(
|
||||||
|
'payment/updatePayment',
|
||||||
|
async (payload: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const result = await axios.put(`payment/${payload.id}`, {
|
||||||
|
id: payload.id,
|
||||||
|
data: payload.data,
|
||||||
|
});
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (!error.response) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const paymentSlice = createSlice({
|
||||||
|
name: 'payment',
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
setRefetch: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.refetch = action.payload;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
builder.addCase(fetch.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
builder.addCase(fetch.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(fetch.fulfilled, (state, action) => {
|
||||||
|
if (action.payload.rows && action.payload.count >= 0) {
|
||||||
|
state.payment = action.payload.rows;
|
||||||
|
state.count = action.payload.count;
|
||||||
|
} else {
|
||||||
|
state.payment = action.payload;
|
||||||
|
}
|
||||||
|
state.loading = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItemsByIds.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItemsByIds.fulfilled, (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
fulfilledNotify(state, 'Payment has been deleted');
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItemsByIds.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItem.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItem.fulfilled, (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
fulfilledNotify(state, `${'Payment'.slice(0, -1)} has been deleted`);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(deleteItem.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(create.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
builder.addCase(create.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(create.fulfilled, (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
fulfilledNotify(state, `${'Payment'.slice(0, -1)} has been created`);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(update.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
builder.addCase(update.fulfilled, (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
fulfilledNotify(state, `${'Payment'.slice(0, -1)} has been updated`);
|
||||||
|
});
|
||||||
|
builder.addCase(update.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addCase(uploadCsv.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
resetNotify(state);
|
||||||
|
});
|
||||||
|
builder.addCase(uploadCsv.fulfilled, (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
fulfilledNotify(state, 'Payment has been uploaded');
|
||||||
|
});
|
||||||
|
builder.addCase(uploadCsv.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
rejectNotify(state, action);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Action creators are generated for each case reducer function
|
||||||
|
export const { setRefetch } = paymentSlice.actions;
|
||||||
|
|
||||||
|
export default paymentSlice.reducer;
|
||||||
@ -18,6 +18,7 @@ import librarySlice from './library/librarySlice';
|
|||||||
import studentsSlice from './students/studentsSlice';
|
import studentsSlice from './students/studentsSlice';
|
||||||
import rolesSlice from './roles/rolesSlice';
|
import rolesSlice from './roles/rolesSlice';
|
||||||
import permissionsSlice from './permissions/permissionsSlice';
|
import permissionsSlice from './permissions/permissionsSlice';
|
||||||
|
import paymentSlice from './payment/paymentSlice';
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
@ -40,6 +41,7 @@ export const store = configureStore({
|
|||||||
students: studentsSlice,
|
students: studentsSlice,
|
||||||
roles: rolesSlice,
|
roles: rolesSlice,
|
||||||
permissions: permissionsSlice,
|
permissions: permissionsSlice,
|
||||||
|
payment: paymentSlice,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user