diff --git a/nomad-front-end/src/components/AccountsComponents/AccountsTable.jsx b/nomad-front-end/src/components/AccountsComponents/AccountsTable.jsx index 86038f4..b19d83e 100644 --- a/nomad-front-end/src/components/AccountsComponents/AccountsTable.jsx +++ b/nomad-front-end/src/components/AccountsComponents/AccountsTable.jsx @@ -1,9 +1,10 @@ import React from 'react' -import { Table } from 'antd' +import { Table, Tooltip } from 'antd' import classes from './AccountsTable.module.css' const AccountsTable = props => { + console.log(props) const columns = [ { title: props.header, @@ -16,6 +17,23 @@ const AccountsTable = props => { } ] + //add the grantcode if it exists + if (props.data[0].grantCode) { + columns.push({ + title: 'Grant Code', + width: 35, + dataIndex: 'grantCode', + key: 'grantCode', + fixed: 'left', + align: 'center', + render: (text, record) => { + return (record.grantCode && +

See Grants Info

+
) + } + + }) + } //Getting dynamic table headers from the first data object props.data[0].costsPerInstrument.forEach((cost, index) => { columns.push({ @@ -61,6 +79,7 @@ const AccountsTable = props => { const data = props.data.map((entry, key) => { const newEntry = { name: entry.name, + grantCode: entry.grantCode || undefined, totalCost: entry.totalCost, key } diff --git a/nomad-front-end/src/components/NavBar/PageHeader/Controls/AccountingControls.jsx b/nomad-front-end/src/components/NavBar/PageHeader/Controls/AccountingControls.jsx index 318c21c..79ffb7f 100644 --- a/nomad-front-end/src/components/NavBar/PageHeader/Controls/AccountingControls.jsx +++ b/nomad-front-end/src/components/NavBar/PageHeader/Controls/AccountingControls.jsx @@ -8,7 +8,8 @@ import { CloudDownloadOutlined } from '@ant-design/icons' const AccountingControls = props => { const { setGrantsVisible, tableData, tableHeader, accType } = props const standardColumns = { - grants: ['Grant Code', 'Description', 'Users', 'Manual Cost', 'Auto Cost', 'Total Cost [£]'] + grants: ['Grant Code', 'Description', 'Users', 'Manual Cost', 'Auto Cost', 'Total Cost [£]'], + users: ['Grant Code ID', 'Grant Code Multiplier'] } const columnsParser = (head, data, type) => { let columns = [] @@ -17,6 +18,9 @@ const AccountingControls = props => { columns = standardColumns.grants } else { columns = [head] + if (type === 'Users') { + columns = [...columns, ...standardColumns.users] + } let presentColumns = data[0].costsPerInstrument presentColumns.forEach(({ instrument }) => { const newColumnsToAdd = [ @@ -54,6 +58,18 @@ const AccountingControls = props => { } else { data.forEach(row => { let FlatRow = [row.name] + + //add the grantcodes + let grantCodeInfo = ['--', '--'] + if (row.grantCode) { + grantCodeInfo = [row.grantCode.grantId, row.grantCode.multiplier] + } + if (type === 'Users') { + //only add if its users + FlatRow = [...FlatRow, ...grantCodeInfo] + } + + row.costsPerInstrument.forEach(instrumentData => { const { cost, expTimeAuto, expTimeClaims } = instrumentData FlatRow = [...FlatRow, expTimeClaims, expTimeAuto, cost] diff --git a/nomad-rest-api/controllers/admin/accounts.js b/nomad-rest-api/controllers/admin/accounts.js index abea389..577c311 100644 --- a/nomad-rest-api/controllers/admin/accounts.js +++ b/nomad-rest-api/controllers/admin/accounts.js @@ -9,6 +9,7 @@ import Instrument from '../../models/instrument.js' import Grant from '../../models/grant.js' import { checkDuplicate, + getGrantInfo, getSearchParams, getSearchParamsClaims } from '../../utils/accountsUtils.js' @@ -82,10 +83,11 @@ export async function getCosts(req, res) { await Promise.all( usrArray.map(async usrId => { - const user = await User.findById(usrId) + const [user, grantCode] = await Promise.all([User.findById(usrId), getGrantInfo(usrId)]) const usrInactive = !user.isActive || user.group.toString() !== groupId const newEntry = { name: `${user.username} - ${user.fullName} ${usrInactive ? '(Inactive)' : ''}`, + grantCode, costsPerInstrument: [], totalCost: 0 }