/
Checking Account Budget Overflow
Checking Account Budget Overflow
Checking budget overflow for every worklog entry is costly operation. But if your accounts are small and does not contain a lot of worklogs you can check account budget before worklog entry automatically.
import com.atlassian.jira.component.ComponentAccessor;
import com.deniz.jira.worklog.accounting.*;
import com.deniz.jira.worklog.services.*;
import java.util.*;
import java.time.*;
if (account == null) {
return;
}
def accountService = ComponentAccessor.getOSGiComponentInstanceOfType(AccountService.class);
def timesheetService = ComponentAccessor.getOSGiComponentInstanceOfType(TimesheetService.class);
def accounts = [account.id];
def start = ZonedDateTime.now().minusYears(30);
def end = ZonedDateTime.now().plusYears(30);
def worklogs = timesheetService.getAccountWorklogs(start, end, false, null, null, null, (Integer[]) accounts) ;
def totalTimeSpent = 0;
worklogs.projects.each { p ->
p.issues.each { i ->
i.workLogs.each { w ->
totalTimeSpent+=w.timeSpent;
}
}
}
if (totalTimeSpent > account.budget) {
return "You are over budget for this account";
};
Above code does not check budget hierarchy. It just checks budget itself.
, multiple selections available,
Related content
Log Work Custom Field
Log Work Custom Field
Read with this
Worklog Verification Scripts
Worklog Verification Scripts
Read with this
Before Worklog Delete
Before Worklog Delete
Read with this
Prevent Users to Submit Their Timesheet If Daily Required Hours are not Completed
Prevent Users to Submit Their Timesheet If Daily Required Hours are not Completed
Read with this
Worklog Scripts
Worklog Scripts
Read with this
Programmer Manual (API)
Programmer Manual (API)
Read with this