diff --git a/nomad-front-end/src/components/AccountsComponents/AccountsForm.jsx b/nomad-front-end/src/components/AccountsComponents/AccountsForm.jsx index 9a4fb43..87e8e47 100644 --- a/nomad-front-end/src/components/AccountsComponents/AccountsForm.jsx +++ b/nomad-front-end/src/components/AccountsComponents/AccountsForm.jsx @@ -37,6 +37,18 @@ const AccountsForm = props => { }) } + const fetchCosts = () => { + if (dateRange) { + values.dateRange = dateRange.map(date => date.format('YYYY-MM-DD')) + } + + if (type !== 'Grants') { + props.getCosts(token, values) + } else { + props.getGrantsCosts(token, { dateRange: values.dateRange }) + } + } + if (!dateRange) { return Modal.confirm({ title: 'Date range not defined', @@ -47,18 +59,11 @@ const AccountsForm = props => { ), onOk() { - if (dateRange) { - values.dateRange = dateRange.map(date => date.format('YYYY-MM-DD')) - } - - if (type !== 'Grants') { - props.getCosts(token, values) - } else { - props.getGrantsCosts(token, { dateRange: values.dateRange }) - } + fetchCosts() } }) } + fetchCosts() } return ( diff --git a/nomad-front-end/src/components/AccountsComponents/GrantForm.jsx b/nomad-front-end/src/components/AccountsComponents/GrantForm.jsx index 663acea..651cce4 100644 --- a/nomad-front-end/src/components/AccountsComponents/GrantForm.jsx +++ b/nomad-front-end/src/components/AccountsComponents/GrantForm.jsx @@ -1,5 +1,5 @@ import React from 'react' -import { Form, Button, Input, Space, Modal, message } from 'antd' +import { Form, Button, Input, Space, Modal, message, InputNumber } from 'antd' import { QuestionCircleOutlined, CloseOutlined } from '@ant-design/icons' import SelectGrpUsr from '../Forms/SelectGrpUsr/SelectGrpUsr' @@ -80,7 +80,6 @@ const GrantForm = props => { } }) - console.log(usrGrpIdArray) const reqObject = { ...values, include: props.tagsState.map(i => ({ isGroup: i.type === 'group', id: i.id, name: i.name })) @@ -114,6 +113,15 @@ const GrantForm = props => { + + + { title: 'Description', dataIndex: 'description' }, + { + title: 'Costing multiplier', + dataIndex: 'multiplier', + width: 150, + align: 'center' + }, { title: 'Include', align: 'center', diff --git a/nomad-front-end/src/components/AccountsComponents/infoModalCosting.jsx b/nomad-front-end/src/components/AccountsComponents/infoModalCosting.jsx index ab109cd..5a433ca 100644 --- a/nomad-front-end/src/components/AccountsComponents/infoModalCosting.jsx +++ b/nomad-front-end/src/components/AccountsComponents/infoModalCosting.jsx @@ -11,11 +11,12 @@ const infoModalConfig = { Grants

- This calculation will work only if grants have been preset. In "Set Grants" table you can - assign either individual users or whole group to a grant. If you assign individual user and - his own group to two different grants, the experiments that were originated by the user will - be charged to the grant corresponding to the user and not to the one corresponding to the - whole group. + This calculation will work only if grants have been preset and it is based on instrument + costing and costing multiplier in the time of archiving of the experiments. In "Set Grants" + table you can assign either individual users or whole group to a grant. If you assign + individual user and his own group to two different grants, the experiments that were + originated by the user will be charged to the grant corresponding to the user and not to the + one corresponding to the whole group.

{ const { instrumentId } = req.params @@ -144,12 +144,12 @@ export const approveClaims = async (req, res) => { req.body.map(async id => { const claim = await Claim.findById(id) const instrument = await Instrument.findById(claim.instrument, 'cost') - const grantId = await getGrantId(claim.user, claim.group) + const { grantId, multiplier } = await getGrantInfo(claim.user, claim.group) claim.status = 'Approved' claim.grantCosting = { grantId, - cost: +claim.expTime * instrument.cost + cost: +claim.expTime * instrument.cost * multiplier } await claim.save() diff --git a/nomad-rest-api/controllers/data.js b/nomad-rest-api/controllers/data.js index d120d72..9fca839 100644 --- a/nomad-rest-api/controllers/data.js +++ b/nomad-rest-api/controllers/data.js @@ -13,7 +13,7 @@ import User from '../models/user.js' import Instrument from '../models/instrument.js' import { getIO } from '../socket.js' import { getNMRiumDataObj } from '../utils/nmriumUtils.js' -import { getGrantId } from '../utils/accountsUtils.js' +import { getGrantInfo } from '../utils/accountsUtils.js' export const postData = async (req, res) => { const { datasetName, expNo, dataPath } = req.body @@ -61,11 +61,11 @@ export const postData = async (req, res) => { //Calculation of costs for grants - const grantId = await getGrantId(experiment.user.id, experiment.group.id) + const { grantId, multiplier } = await getGrantInfo(experiment.user.id, experiment.group.id) experiment.grantCosting = { grantId, - cost: moment.duration(experiment.totalExpTime).asHours() * instrument.cost + cost: moment.duration(experiment.totalExpTime).asHours() * instrument.cost * multiplier } await experiment.save() diff --git a/nomad-rest-api/models/grant.js b/nomad-rest-api/models/grant.js index 2103fd9..3134535 100644 --- a/nomad-rest-api/models/grant.js +++ b/nomad-rest-api/models/grant.js @@ -16,7 +16,12 @@ const grantSchema = new Schema({ required: true } } - ] + ], + multiplier: { + type: Number, + required: true, + default: 1 + } }) export default model('Grant', grantSchema) diff --git a/nomad-rest-api/utils/accountsUtils.js b/nomad-rest-api/utils/accountsUtils.js index c1ac2b3..f732b13 100644 --- a/nomad-rest-api/utils/accountsUtils.js +++ b/nomad-rest-api/utils/accountsUtils.js @@ -51,7 +51,7 @@ const getSearchParamsClaims = dateRange => { return searchParamsClaims } -const getGrantId = async (userId, groupId) => { +const getGrantInfo = async (userId, groupId) => { let grant = await Grant.findOne({ include: { $elemMatch: { id: userId } @@ -67,10 +67,10 @@ const getGrantId = async (userId, groupId) => { } if (grant) { - return Promise.resolve(grant._id) + return Promise.resolve({ grantId: grant._id, multiplier: grant.multiplier }) } else { return Promise.resolve(undefined) } } -export { checkDuplicate, getSearchParams, getSearchParamsClaims, getGrantId } +export { checkDuplicate, getSearchParams, getSearchParamsClaims, getGrantInfo }