diff --git a/backend/controllers/appControllers/invoiceController/create.js b/backend/controllers/appControllers/invoiceController/create.js index e0fcee83c..44633b002 100644 --- a/backend/controllers/appControllers/invoiceController/create.js +++ b/backend/controllers/appControllers/invoiceController/create.js @@ -47,6 +47,7 @@ const create = async (req, res) => { let paymentStatus = calculate.sub(total, discount) === 0 ? 'paid' : 'unpaid'; body['paymentStatus'] = paymentStatus; + body['createdBy'] = req.admin._id; // Creating a new document in the collection const result = await new Model(body).save(); const fileId = 'invoice-' + result._id + '.pdf'; diff --git a/backend/controllers/appControllers/offerController/create.js b/backend/controllers/appControllers/offerController/create.js index daeb9e192..a3aab01bf 100644 --- a/backend/controllers/appControllers/offerController/create.js +++ b/backend/controllers/appControllers/offerController/create.js @@ -33,6 +33,7 @@ const create = async (req, res) => { body['taxTotal'] = taxTotal; body['total'] = total; body['items'] = items; + body['createdBy'] = req.admin._id; // Creating a new document in the collection const result = await new Model(body).save(); diff --git a/backend/controllers/appControllers/paymentInvoiceController/create.js b/backend/controllers/appControllers/paymentInvoiceController/create.js index f470fe650..77261546a 100644 --- a/backend/controllers/appControllers/paymentInvoiceController/create.js +++ b/backend/controllers/appControllers/paymentInvoiceController/create.js @@ -37,7 +37,7 @@ const create = async (req, res) => { message: `The Max Amount you can add is ${maxAmount}`, }); } - + req.body['createdBy'] = req.admin._id; const result = await Model.create(req.body); const fileId = 'payment-invoice-report-' + result._id + '.pdf'; diff --git a/backend/controllers/appControllers/quoteController/create.js b/backend/controllers/appControllers/quoteController/create.js index f77ea8c4d..ec40179b3 100644 --- a/backend/controllers/appControllers/quoteController/create.js +++ b/backend/controllers/appControllers/quoteController/create.js @@ -33,6 +33,7 @@ const create = async (req, res) => { body['taxTotal'] = taxTotal; body['total'] = total; body['items'] = items; + body['createdBy'] = req.admin._id; // Creating a new document in the collection const result = await new Model(body).save(); diff --git a/backend/middlewares/permission.js b/backend/middlewares/permission.js index c96a31d25..366214468 100644 --- a/backend/middlewares/permission.js +++ b/backend/middlewares/permission.js @@ -1,6 +1,7 @@ //this middleware will check if the user has permission const roles = { + admin: ['create', 'read', 'update', 'delete', 'download', 'upload'], staffAdmin: ['create', 'read', 'update', 'delete', 'download', 'upload'], staff: ['create', 'read', 'update', 'download', 'upload'], createOnly: ['create', 'read', 'download', 'upload'], diff --git a/backend/models/appModels/Client.js b/backend/models/appModels/Client.js index 2c1aca611..721abb5b3 100644 --- a/backend/models/appModels/Client.js +++ b/backend/models/appModels/Client.js @@ -10,6 +10,7 @@ const clientSchema = new mongoose.Schema({ type: Boolean, default: true, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, company: { type: String, trim: true, diff --git a/backend/models/appModels/Invoice.js b/backend/models/appModels/Invoice.js index c8a2d8251..b709d3ed0 100644 --- a/backend/models/appModels/Invoice.js +++ b/backend/models/appModels/Invoice.js @@ -6,6 +6,7 @@ const invoiceSchema = new mongoose.Schema({ type: Boolean, default: false, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, number: { type: Number, required: true, diff --git a/backend/models/appModels/Lead.js b/backend/models/appModels/Lead.js index 6eca9f37f..45d8cc84f 100644 --- a/backend/models/appModels/Lead.js +++ b/backend/models/appModels/Lead.js @@ -6,6 +6,7 @@ const leadSchema = new mongoose.Schema({ type: Boolean, default: false, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, enabled: { type: Boolean, default: true, diff --git a/backend/models/appModels/Offer.js b/backend/models/appModels/Offer.js index aba968e95..af4e29fa5 100644 --- a/backend/models/appModels/Offer.js +++ b/backend/models/appModels/Offer.js @@ -6,6 +6,7 @@ const offerSchema = new mongoose.Schema({ type: Boolean, default: false, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, number: { type: Number, required: true, diff --git a/backend/models/appModels/PaymentInvoice.js b/backend/models/appModels/PaymentInvoice.js index 614433482..eabf5467c 100644 --- a/backend/models/appModels/PaymentInvoice.js +++ b/backend/models/appModels/PaymentInvoice.js @@ -7,6 +7,7 @@ const paymentInvoiceSchema = new mongoose.Schema({ type: Boolean, default: false, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, number: { type: Number, required: true, diff --git a/backend/models/appModels/Quote.js b/backend/models/appModels/Quote.js index d520f87ca..111309032 100644 --- a/backend/models/appModels/Quote.js +++ b/backend/models/appModels/Quote.js @@ -6,6 +6,7 @@ const quoteSchema = new mongoose.Schema({ type: Boolean, default: false, }, + createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', autopopulate: true, required: true }, converted: { type: Boolean, default: false, diff --git a/frontend/src/pages/Invoice/index.jsx b/frontend/src/pages/Invoice/index.jsx index bc15de8ce..82d6f5fad 100644 --- a/frontend/src/pages/Invoice/index.jsx +++ b/frontend/src/pages/Invoice/index.jsx @@ -38,12 +38,12 @@ export default function Invoice() { { title: 'Total', dataIndex: 'total', - render: (amount) => moneyRowFormatter({ amount }), + render: (total) => moneyRowFormatter({ amount: total }), }, { title: 'Balance', dataIndex: 'credit', - render: (amount) => moneyRowFormatter({ amount }), + render: (credit) => moneyRowFormatter({ amount: credit }), }, { title: 'Status', @@ -70,6 +70,11 @@ export default function Invoice() { return {paymentStatus && paymentStatus.toUpperCase()}; }, }, + { + title: 'Created By', + dataIndex: ['createdBy', 'name'], + render: (createdBy) => (createdBy ? createdBy : 'Adminstrator'), + }, ]; const config = {