(8.1.10) Incurred cost
Title | Incurred cost |
---|---|
Description | It sums up the Total Time Spent of your issues, times the Cost per hour |
Objective | Get to know what is the incurred cost of the project |
Audience |
|
What does a Jira Project Represent? | A Jira Project of any type, where time tracking is a valuable asset |
Focus | Project tracking and monitorization |
Configuration
1. Create a Projectrak Number field called "Cost".
2. Create a Projectrak Script field called "Incurred cost".
3. Insert the following Groovy script and modify according to your instance into "Incurred cost" field
Pre-requisites:
- Projectrak Numeric field called "Cost"
Description: Sums the total time spent of the current project issues, then it calculates the cost per the total time spent
Use in: It should be used as a Projectrak Script field
Variables in context:
- project [com.atlassian.jira.project.Project]: The current project
COST_FIELD_ID: Line 12 in the script. In the example we are using 21. Please use the ID that corresponds to your "Cost Size" field
Groovy Script
package deiser.profields.scripts import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.security.JiraAuthenticationContext import com.deiser.jira.profields.api.field.FieldService import com.deiser.jira.profields.api.field.number.NumberField import com.deiser.jira.profields.api.value.ValueService import java.text.NumberFormat // Configuration def COST_FIELD_ID = 21 // Components def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class) def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class) def issueManager = ComponentAccessor.issueManager def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext // Get the fields def costField = fieldService.get(COST_FIELD_ID) // Get the field values in the current project def cost = valueService.getValue(project, (NumberField) costField) ?: 0 // Get the total time spent def totalTimeSpent = issueManager.getIssueIdsForProject(project.id) .collect { issueManager.getIssueObject(it) } .collect { it.timeSpent ?: 0 } totalTimeSpent = totalTimeSpent ? totalTimeSpent.sum() : 0 // Seconds to hours totalTimeSpent /= 3600 // Return the cost per the total time spent def numberFormat = NumberFormat.getInstance(jiraAuthenticationContext.locale) numberFormat.maximumFractionDigits = 0 numberFormat.minimumFractionDigits = 0 numberFormat.groupingUsed = false return numberFormat.format((cost * totalTimeSpent).longValue())
4. Configure the project's layout including all of the fields created,.
5. Associate the Layout to the project you need this information to be applied to.
6. The result should be something like this: (please, keep in mind that this is only an example and your results should vary from what it is shown in the screenshot).