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