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

add column for grantcodes in ui and csv export #140

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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