@@ -100,6 +100,7 @@ export interface ProjectCompletionReportRequest { | |||
startDate: String; | |||
endDate: String; | |||
outstanding: Boolean; | |||
teamId?: number | |||
} | |||
export interface CostAndExpenseReportFilter { | |||
team: string[]; | |||
@@ -3,13 +3,22 @@ import GenerateMonthlyWorkHoursReportLoading from "./GenerateMonthlyWorkHoursRep | |||
import { fetchProjects } from "@/app/api/projects"; | |||
import GenerateMonthlyWorkHoursReport from "./GenerateMonthlyWorkHoursReport"; | |||
import { fetchStaff } from "@/app/api/staff"; | |||
import { getServerSession } from "next-auth"; | |||
import { authOptions } from "@/config/authConfig"; | |||
import { TEAM_LEAD } from "@/middleware"; | |||
interface SubComponents { | |||
Loading: typeof GenerateMonthlyWorkHoursReportLoading; | |||
} | |||
const GenerateMonthlyWorkHoursReportWrapper: React.FC & SubComponents = async () => { | |||
const staffs = await fetchStaff(); | |||
const session: any = await getServerSession(authOptions) | |||
const teamId = session.staff?.team.id | |||
const role = session!.role | |||
let staffs = await fetchStaff(); | |||
if (role === TEAM_LEAD) { | |||
staffs = staffs.filter((staff) => staff.teamId === teamId); | |||
} | |||
return <GenerateMonthlyWorkHoursReport staffs={staffs}/>; | |||
}; | |||
@@ -12,6 +12,7 @@ import { downloadFile } from "@/app/utils/commonUtil"; | |||
import { fetchProjectCompletionReport } from "@/app/api/reports/actions"; | |||
interface Props { | |||
teamId: number| null | |||
} | |||
type SearchQuery = Partial<Omit<ProjectCompletionReportFilter, "id">>; | |||
@@ -19,6 +20,7 @@ type SearchParamNames = keyof SearchQuery; | |||
const ProjectCompletionReport: React.FC<Props> = ( | |||
{ | |||
teamId | |||
} | |||
) => { | |||
const { t } = useTranslation("report"); | |||
@@ -28,8 +30,8 @@ const ProjectCompletionReport: React.FC<Props> = ( | |||
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | |||
() => [ | |||
{ | |||
label: t("startDate"), | |||
label2: t("endDate"), | |||
label: t("Completion Date From"), | |||
label2: t("Completion Date To"), | |||
paramName: "startDate", | |||
type: "dateRange", | |||
}, | |||
@@ -50,37 +52,26 @@ const ProjectCompletionReport: React.FC<Props> = ( | |||
formType={"download"} | |||
criteria={searchCriteria} | |||
onSearch={async (query: any) => { | |||
console.log(query); | |||
let postData: ProjectCompletionReportRequest = { | |||
startDate: "", | |||
endDate: dayjs().format(INPUT_DATE_FORMAT).toString(), | |||
outstanding: false | |||
outstanding: query.outstanding && query.outstanding === "Outstanding Accounts Receivable" | |||
}; | |||
if (query.endDate && query.endDate.length > 0) { | |||
postData.endDate = query.endDate; | |||
if (query.startDateTo && query.startDateTo.length > 0) { | |||
postData.endDate = query.startDateTo; | |||
} | |||
if (teamId) { | |||
postData.teamId = teamId | |||
} | |||
// check if start date exist | |||
if (query.startDate.length === 0) { | |||
setError(t("Start Date cant be empty")); | |||
} else { | |||
postData.startDate = query.startDate; | |||
if (query.outstanding && query.outstanding === "Outstanding Accounts Receivable") { | |||
// outstanding report | |||
postData.outstanding = true | |||
} | |||
console.log(postData) | |||
const response = | |||
await fetchProjectCompletionReport( | |||
postData | |||
); | |||
// normal report | |||
const response = await fetchProjectCompletionReport(postData); | |||
if (response) { | |||
downloadFile( | |||
new Uint8Array(response.blobValue), | |||
response.filename!! | |||
); | |||
downloadFile(new Uint8Array(response.blobValue), response.filename!!); | |||
} | |||
} | |||
}} | |||
@@ -3,14 +3,20 @@ import { fetchAllCustomers } from "@/app/api/customer"; | |||
import { fetchTeam } from "@/app/api/team"; | |||
import ProjectCompletionReportLoading from "./ProjectCompletionReportLoading"; | |||
import ProjectCompletionReport from "./ProjectCompletionReport"; | |||
import { getServerSession } from "next-auth"; | |||
import { authOptions } from "@/config/authConfig"; | |||
import { TEAM_LEAD } from "@/middleware"; | |||
interface SubComponents { | |||
Loading: typeof ProjectCompletionReportLoading; | |||
} | |||
const ProjectCompletionReportWrapper: React.FC & SubComponents = async () => { | |||
return <ProjectCompletionReport/> | |||
const session: any = await getServerSession(authOptions) | |||
const teamId = session.staff?.team.id | |||
const role = session!.role | |||
return <ProjectCompletionReport teamId={role === TEAM_LEAD && session.staff?.team ? teamId : null}/> | |||
}; | |||
ProjectCompletionReportWrapper.Loading = ProjectCompletionReportLoading; | |||
@@ -16,12 +16,13 @@ interface Props { | |||
team: TeamResult[] | |||
customer: Customer[] | |||
subsidiaries: Subsidiary[] | |||
needAll: boolean | |||
} | |||
type SearchQuery = Partial<Omit<ProjectResourceOverconsumptionReportFilter, "id">>; | |||
type SearchParamNames = keyof SearchQuery; | |||
const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer, subsidiaries }) => { | |||
const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer, subsidiaries, needAll }) => { | |||
const { t } = useTranslation("report"); | |||
console.log(customer) | |||
const statusCombo = ["Overconsumption", "Potential Overconsumption"] | |||
@@ -46,7 +47,7 @@ const ResourceOverconsumptionReport: React.FC<Props> = ({ team, customer, subsid | |||
paramName: "team", | |||
type: "select", | |||
options: teamCombo, | |||
needAll: true | |||
needAll: needAll | |||
}, | |||
{ | |||
label: t("Client"), | |||
@@ -4,24 +4,35 @@ import ResourceOverconsumptionReport from "./ResourceOverconsumptionReport"; | |||
import { fetchTeam } from "@/app/api/team"; | |||
import { fetchAllCustomers } from "@/app/api/customer"; | |||
import { fetchAllSubsidiaries } from "@/app/api/subsidiary"; | |||
import { getServerSession } from "next-auth"; | |||
import { authOptions } from "@/config/authConfig"; | |||
import { TEAM_LEAD } from "@/middleware"; | |||
interface SubComponents { | |||
Loading: typeof ResourceOvercomsumptionReportLoading; | |||
} | |||
const ResourceOvercomsumptionReportWrapper: React.FC & SubComponents = async () => { | |||
const session: any = await getServerSession(authOptions) | |||
const teamId = session.staff?.team.id | |||
const role = session!.role | |||
let needAll = true | |||
let teams = await fetchTeam() | |||
const [ | |||
teams, | |||
customers, | |||
subsidiaries] | |||
= await Promise.all( | |||
[ | |||
fetchTeam(), | |||
fetchAllCustomers(), | |||
fetchAllSubsidiaries() | |||
]) | |||
customers, | |||
subsidiaries] | |||
= await Promise.all( | |||
[ | |||
fetchAllCustomers(), | |||
fetchAllSubsidiaries() | |||
]) | |||
return <ResourceOverconsumptionReport team={teams} customer={customers} subsidiaries={subsidiaries}/>; | |||
if (role === TEAM_LEAD) { | |||
needAll = false | |||
teams = teams.filter((team) => team.id === teamId); | |||
} | |||
return <ResourceOverconsumptionReport team={teams} customer={customers} subsidiaries={subsidiaries} needAll={needAll}/>; | |||
}; | |||
ResourceOvercomsumptionReportWrapper.Loading = ResourceOvercomsumptionReportLoading; | |||