Skip to content

Commit

Permalink
Merge pull request #140 from hunxjunedo/main
Browse files Browse the repository at this point in the history
add column for grantcodes in ui and csv export
  • Loading branch information
tomlebl authored Oct 7, 2024
2 parents bace713 + e7b9169 commit f5a0100
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 && <Tooltip title={`ID: ${record.grantCode?.grantId} \n mutiplier: ${record.grantCode?.multiplier}`}>
<p style={{ color: 'blue' }}>See Grants Info</p>
</Tooltip>)
}

})
}
//Getting dynamic table headers from the first data object
props.data[0].costsPerInstrument.forEach((cost, index) => {
columns.push({
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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 = [
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion nomad-rest-api/controllers/admin/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f5a0100

Please sign in to comment.