Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expenditure service #17

Open
bernardarhia opened this issue May 28, 2024 · 0 comments
Open

Expenditure service #17

bernardarhia opened this issue May 28, 2024 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation implementaion

Comments

@bernardarhia
Copy link
Contributor

import mongoose, { Schema, Document, Model } from 'mongoose';

interface IExpense extends Document {
item: string;
itemId: string;
quantity: number;
amountPerQuantity: number;
totalAmount: number;
description: string;
modeOfPayment: 'cash' | 'mobileMoney' | 'bank';
expenseHead?: number;
subExpense?: number;
receiptNumber: string;
academicYear: number;
term: string;
recordedBy: string;
time: string;
date: string;
warehouseId: string;
accountId: string;
}

interface IMobileMoneyPayment extends IExpense {
referenceNumber: string;
paymentNumber: string;
networkType: string;
}

interface IBankPayment extends IExpense {
referenceNumber: string;
bankAccount: string;
bankName: string;
bankBranch: string;
}

const baseOptions = {
discriminatorKey: 'modeOfPayment',
collection: 'expenses',
};

const ExpenseSchema: Schema = new Schema(
{
item: { type: String, required: true },
itemId: { type: String, required: true },
quantity: { type: Number, required: true },
amountPerQuantity: { type: Number, required: true },
totalAmount: { type: Number, required: true },
description: { type: String, required: true },
modeOfPayment: { type: String, required: true, enum: ['cash', 'mobileMoney', 'bank'] },
expenseHead: { type: Number, required: false },
subExpense: { type: Number, required: false },
receiptNumber: { type: String, required: true },
academicYear: { type: Number, required: true },
term: { type: String, required: true },
recordedBy: { type: String, required: true },
time: { type: String, required: true },
date: { type: String, required: true },
warehouseId: { type: String, required: true },
accountId: { type: String, required: true },
},
baseOptions
);

const Expense: Model = mongoose.model('Expense', ExpenseSchema);

const MobileMoneyPaymentSchema: Schema = new Schema({
referenceNumber: { type: String, required: true },
paymentNumber: { type: String, required: true },
networkType: { type: String, required: true },
});

const BankPaymentSchema: Schema = new Schema({
referenceNumber: { type: String, required: true },
bankAccount: { type: String, required: true },
bankName: { type: String, required: true },
bankBranch: { type: String, required: true },
});

const MobileMoneyPayment: Model = Expense.discriminator(
'mobileMoney',
MobileMoneyPaymentSchema
);

const BankPayment: Model = Expense.discriminator(
'bank',
BankPaymentSchema
);

export { Expense, MobileMoneyPayment, BankPayment, IExpense, IMobileMoneyPayment, IBankPayment };

use the schema to create the expenditure service. Change interface name to ExpenditureProps. Any interface with I change it to interfaceNameProps. When storing or updating the data, make sure you save the expenditure with it's mode of payment. Validate the mode of payment and the fields corresponding to it

@bernardarhia bernardarhia added documentation Improvements or additions to documentation implementaion labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation implementaion
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants