Skip to content

Commit

Permalink
Merge pull request idurar#590 from idurar/feat/invoice-createdBy
Browse files Browse the repository at this point in the history
add createdBy to invoice table
  • Loading branch information
salahlalami authored Oct 22, 2023
2 parents 355c005 + c67c0ae commit 2b24b26
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions backend/middlewares/permission.js
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/Invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/Lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/Offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/PaymentInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/models/appModels/Quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/Invoice/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -70,6 +70,11 @@ export default function Invoice() {
return <Tag color={color}>{paymentStatus && paymentStatus.toUpperCase()}</Tag>;
},
},
{
title: 'Created By',
dataIndex: ['createdBy', 'name'],
render: (createdBy) => (createdBy ? createdBy : 'Adminstrator'),
},
];

const config = {
Expand Down

0 comments on commit 2b24b26

Please sign in to comment.