feat(reporting-allocation): add helper method for billable query with custom alias and enhance logging for debugging
- Introduced a new method to build billable queries with customizable table aliases, improving query flexibility. - Enhanced logging throughout the reporting allocation process to aid in debugging and provide clearer insights into query generation and utilization state calculations.
This commit is contained in:
@@ -15,6 +15,25 @@ enum IToggleOptions {
|
||||
}
|
||||
|
||||
export default class ReportingAllocationController extends ReportingControllerBase {
|
||||
// Helper method to build billable query with custom table alias
|
||||
private static buildBillableQueryWithAlias(selectedStatuses: { billable: boolean; nonBillable: boolean }, tableAlias: string = 'tasks'): string {
|
||||
const { billable, nonBillable } = selectedStatuses;
|
||||
|
||||
if (billable && nonBillable) {
|
||||
// Both are enabled, no need to filter
|
||||
return "";
|
||||
} else if (billable && !nonBillable) {
|
||||
// Only billable is enabled - show only billable tasks
|
||||
return ` AND ${tableAlias}.billable IS TRUE`;
|
||||
} else if (!billable && nonBillable) {
|
||||
// Only non-billable is enabled - show only non-billable tasks
|
||||
return ` AND ${tableAlias}.billable IS FALSE`;
|
||||
} else {
|
||||
// Neither selected - this shouldn't happen in normal UI flow
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static async getTimeLoggedByProjects(projects: string[], users: string[], key: string, dateRange: string[], archived = false, user_id = "", billable: { billable: boolean; nonBillable: boolean }): Promise<any> {
|
||||
try {
|
||||
const projectIds = projects.map(p => `'${p}'`).join(",");
|
||||
@@ -545,7 +564,7 @@ export default class ReportingAllocationController extends ReportingControllerBa
|
||||
? ""
|
||||
: `AND p.id NOT IN (SELECT project_id FROM archived_projects WHERE project_id = p.id AND user_id = '${req.user?.id}') `;
|
||||
|
||||
const billableQuery = this.buildBillableQuery(billable);
|
||||
const billableQuery = this.buildBillableQueryWithAlias(billable, 't');
|
||||
const members = (req.body.members || []) as string[];
|
||||
|
||||
// Prepare members filter
|
||||
|
||||
@@ -262,9 +262,35 @@ const MembersTimeSheet = forwardRef<MembersTimeSheetRef, MembersTimeSheetProps>(
|
||||
}
|
||||
};
|
||||
|
||||
// Create stable references for selected items to prevent unnecessary re-renders
|
||||
const selectedTeamIds = React.useMemo(() =>
|
||||
teams.filter(team => team.selected).map(t => t.id).join(','),
|
||||
[teams]
|
||||
);
|
||||
|
||||
const selectedProjectIds = React.useMemo(() =>
|
||||
filterProjects.filter(project => project.selected).map(p => p.id).join(','),
|
||||
[filterProjects]
|
||||
);
|
||||
|
||||
const selectedCategoryIds = React.useMemo(() =>
|
||||
categories.filter(category => category.selected).map(c => c.id).join(','),
|
||||
[categories]
|
||||
);
|
||||
|
||||
const selectedMemberIds = React.useMemo(() =>
|
||||
members.filter(member => member.selected).map(m => m.id).join(','),
|
||||
[members]
|
||||
);
|
||||
|
||||
const selectedUtilizationIds = React.useMemo(() =>
|
||||
utilization.filter(item => item.selected).map(u => u.id).join(','),
|
||||
[utilization]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
fetchChartData();
|
||||
}, [duration, dateRange, billable, archived, teams, filterProjects, categories, members, utilization]);
|
||||
}, [duration, dateRange, billable, archived, noCategory, selectedTeamIds, selectedProjectIds, selectedCategoryIds, selectedMemberIds, selectedUtilizationIds]);
|
||||
|
||||
const exportChart = () => {
|
||||
if (chartRef.current) {
|
||||
|
||||
Reference in New Issue
Block a user