| @@ -65,7 +65,7 @@ const CompanySearch: React.FC<Props> = ({ companys }) => { | |||||
| }, | }, | ||||
| { name: "companyCode", label: t("Company Code") }, | { name: "companyCode", label: t("Company Code") }, | ||||
| { name: "name", label: t("Company Name") }, | { name: "name", label: t("Company Name") }, | ||||
| { name: "brNo", label: t("brNo") }, | |||||
| { name: "brNo", label: t("Br No.") }, | |||||
| { name: "contactName", label: t("Contact Name") }, | { name: "contactName", label: t("Contact Name") }, | ||||
| { name: "phone", label: t("Contact No.") }, | { name: "phone", label: t("Contact No.") }, | ||||
| { name: "email", label: t("Contact Email") }, | { name: "email", label: t("Contact Email") }, | ||||
| @@ -10,6 +10,8 @@ import { downloadFile } from "@/app/utils/commonUtil"; | |||||
| import { dateTypeCombo } from "@/app/utils/comboUtil"; | import { dateTypeCombo } from "@/app/utils/comboUtil"; | ||||
| import { FormHelperText } from "@mui/material"; | import { FormHelperText } from "@mui/material"; | ||||
| import { errorDialog, errorDialogWithContent } from "../Swal/CustomAlerts"; | import { errorDialog, errorDialogWithContent } from "../Swal/CustomAlerts"; | ||||
| import { TeamResult } from "@/app/api/team"; | |||||
| import { SessionStaff } from "@/config/authConfig"; | |||||
| interface Props { | interface Props { | ||||
| projects: ProjectResult[]; | projects: ProjectResult[]; | ||||
| @@ -2,15 +2,16 @@ import React from "react"; | |||||
| import GenerateProjectPandLReportLoading from "./GenerateProjectPandLReportLoading"; | import GenerateProjectPandLReportLoading from "./GenerateProjectPandLReportLoading"; | ||||
| import { fetchProjects } from "@/app/api/projects"; | import { fetchProjects } from "@/app/api/projects"; | ||||
| import GenerateProjectPandLReport from "./GenerateProjectPandLReport"; | import GenerateProjectPandLReport from "./GenerateProjectPandLReport"; | ||||
| import { getUserStaff } from "@/app/utils/commonUtil"; | |||||
| interface SubComponents { | interface SubComponents { | ||||
| Loading: typeof GenerateProjectPandLReportLoading; | Loading: typeof GenerateProjectPandLReportLoading; | ||||
| } | } | ||||
| const GenerateProjectPandLReportWrapper: React.FC & SubComponents = async () => { | const GenerateProjectPandLReportWrapper: React.FC & SubComponents = async () => { | ||||
| const projects = await fetchProjects(); | |||||
| const [projects, userStaff] = await Promise.all([fetchProjects(), getUserStaff()]); | |||||
| return <GenerateProjectPandLReport projects={projects} />; | |||||
| return <GenerateProjectPandLReport projects={userStaff?.teamId ? projects.filter(project => project.teamId === userStaff.teamId) : projects}/>; | |||||
| }; | }; | ||||
| GenerateProjectPandLReportWrapper.Loading = GenerateProjectPandLReportLoading; | GenerateProjectPandLReportWrapper.Loading = GenerateProjectPandLReportLoading; | ||||
| @@ -36,6 +36,8 @@ import ManageAccountsIcon from "@mui/icons-material/ManageAccounts"; | |||||
| import EmojiEventsIcon from "@mui/icons-material/EmojiEvents"; | import EmojiEventsIcon from "@mui/icons-material/EmojiEvents"; | ||||
| import { | import { | ||||
| GENERATE_REPORTS, | GENERATE_REPORTS, | ||||
| IMPORT_INVOICE, | |||||
| IMPORT_RECEIPT, | |||||
| MAINTAIN_MASTERDATA, | MAINTAIN_MASTERDATA, | ||||
| MAINTAIN_PROJECT, | MAINTAIN_PROJECT, | ||||
| MAINTAIN_TASK_TEMPLATE, | MAINTAIN_TASK_TEMPLATE, | ||||
| @@ -140,7 +142,7 @@ const NavigationContent: React.FC<Props> = ({ abilities }) => { | |||||
| icon: <Payments />, | icon: <Payments />, | ||||
| label: "Invoice", | label: "Invoice", | ||||
| path: "/invoice", | path: "/invoice", | ||||
| isHidden: ![VIEW_MASTERDATA, MAINTAIN_MASTERDATA].some((ability) => | |||||
| isHidden: ![IMPORT_INVOICE, IMPORT_RECEIPT].some((ability) => | |||||
| abilities!.includes(ability), | abilities!.includes(ability), | ||||
| ), | ), | ||||
| }, | }, | ||||
| @@ -9,22 +9,24 @@ import { FinancialStatusReportFilter } from "@/app/api/reports"; | |||||
| import { fetchAllClientSubsidiaryProjects } from "@/app/api/clientprojects/actions"; | import { fetchAllClientSubsidiaryProjects } from "@/app/api/clientprojects/actions"; | ||||
| import { fetchProjectsFinancialStatusReport } from "@/app/api/reporte1/action"; | import { fetchProjectsFinancialStatusReport } from "@/app/api/reporte1/action"; | ||||
| import { downloadFile } from "@/app/utils/commonUtil"; | import { downloadFile } from "@/app/utils/commonUtil"; | ||||
| import { SessionStaff } from "@/config/authConfig"; | |||||
| //import { DownloadReportButton } from './DownloadReportButton'; | //import { DownloadReportButton } from './DownloadReportButton'; | ||||
| interface Props { | interface Props { | ||||
| projects: FinancialStatus[]; | projects: FinancialStatus[]; | ||||
| teamCombo : TeamCombo[]; | teamCombo : TeamCombo[]; | ||||
| userStaff: SessionStaff; | |||||
| } | } | ||||
| type SearchQuery = Partial<Omit<TeamCombo, "id">>; | type SearchQuery = Partial<Omit<TeamCombo, "id">>; | ||||
| type SearchParamNames = keyof SearchQuery; | type SearchParamNames = keyof SearchQuery; | ||||
| const GenFinancialStatusReport: React.FC<Props> = ({ projects, teamCombo }) => { | |||||
| const GenFinancialStatusReport: React.FC<Props> = ({ projects, teamCombo, userStaff }) => { | |||||
| const { t } = useTranslation("projects"); | const { t } = useTranslation("projects"); | ||||
| const combo = teamCombo.map(combo => {return `${combo.code} - ${combo.name}`}) | const combo = teamCombo.map(combo => {return `${combo.code} - ${combo.name}`}) | ||||
| const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | ||||
| () => [ | () => [ | ||||
| { label: t("Team"), paramName: "code", type: "select", options: combo, }, | |||||
| { label: t("Team"), paramName: "code", type: "select", options: combo, needAll: !Boolean(userStaff.isTeamLead) }, | |||||
| // { | // { | ||||
| // label: "Status", | // label: "Status", | ||||
| // label2: "Remained Date To", | // label2: "Remained Date To", | ||||
| @@ -3,6 +3,7 @@ import { fetchProjectsFinancialStatus, fetchTeamCombo } from "@/app/api/reporte1 | |||||
| import React from "react"; | import React from "react"; | ||||
| import FinancialStatusReportGen from "./FinancialStatusReportGen"; | import FinancialStatusReportGen from "./FinancialStatusReportGen"; | ||||
| import FinancialStatusReportGenLoading from "./FinancialStatusReportGenLoading"; | import FinancialStatusReportGenLoading from "./FinancialStatusReportGenLoading"; | ||||
| import { getUserStaff } from "@/app/utils/commonUtil"; | |||||
| interface SubComponents { | interface SubComponents { | ||||
| Loading: typeof FinancialStatusReportGenLoading; | Loading: typeof FinancialStatusReportGenLoading; | ||||
| @@ -11,9 +12,9 @@ interface SubComponents { | |||||
| const FinancialStatusReportGenWrapper: React.FC & SubComponents = async () => { | const FinancialStatusReportGenWrapper: React.FC & SubComponents = async () => { | ||||
| const clentprojects = await fetchProjectsFinancialStatus(); | const clentprojects = await fetchProjectsFinancialStatus(); | ||||
| const teamCombo = await fetchTeamCombo() | |||||
| const [teamCombo, userStaff] = await Promise.all([fetchTeamCombo(), getUserStaff()]) | |||||
| return <FinancialStatusReportGen projects={clentprojects} teamCombo={teamCombo}/>; | |||||
| return <FinancialStatusReportGen projects={clentprojects} userStaff={userStaff} teamCombo={!Boolean(userStaff?.isTeamLead) ? teamCombo : teamCombo.filter(team => team.id === userStaff?.teamId)}/>; | |||||
| }; | }; | ||||
| FinancialStatusReportGenWrapper.Loading = FinancialStatusReportGenLoading; | FinancialStatusReportGenWrapper.Loading = FinancialStatusReportGenLoading; | ||||
| @@ -8,37 +8,30 @@ import { LateStart } from "@/app/api/report"; | |||||
| import { apiPath } from '../../../auth/utils'; | import { apiPath } from '../../../auth/utils'; | ||||
| import { fetchTeamCombo } from "@/app/api/team/actions"; | import { fetchTeamCombo } from "@/app/api/team/actions"; | ||||
| import SearchBox, { Criterion } from "@/components/SearchBox"; | import SearchBox, { Criterion } from "@/components/SearchBox"; | ||||
| import { combo, comboProp } from "@/app/api/team"; | |||||
| import { TeamResult, combo, comboProp } from "@/app/api/team"; | |||||
| import { Customer } from "@/app/api/customer"; | import { Customer } from "@/app/api/customer"; | ||||
| import { downloadFile } from "@/app/utils/commonUtil"; | import { downloadFile } from "@/app/utils/commonUtil"; | ||||
| import { fetchLateStartReport } from "@/app/api/reports/actions"; | import { fetchLateStartReport } from "@/app/api/reports/actions"; | ||||
| import { LateStartReportRequest } from "@/app/api/reports"; | import { LateStartReportRequest } from "@/app/api/reports"; | ||||
| import { Subsidiary } from "@/app/api/subsidiary"; | import { Subsidiary } from "@/app/api/subsidiary"; | ||||
| import { SessionStaff } from "@/config/authConfig"; | |||||
| //import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; | //import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; | ||||
| interface Props { | interface Props { | ||||
| teams: TeamResult[]; | |||||
| projects: LateStart[]; | projects: LateStart[]; | ||||
| clients: Customer[]; | clients: Customer[]; | ||||
| subsidiaries: Subsidiary[]; | subsidiaries: Subsidiary[]; | ||||
| userStaff: SessionStaff; | |||||
| } | } | ||||
| type SearchQuery = Partial<Omit<LateStartReportRequest, "id">>; | type SearchQuery = Partial<Omit<LateStartReportRequest, "id">>; | ||||
| type SearchParamNames = keyof SearchQuery; | type SearchParamNames = keyof SearchQuery; | ||||
| const ProgressByClientSearch: React.FC<Props> = ({ projects, clients,subsidiaries }) => { | |||||
| const ProgressByClientSearch: React.FC<Props> = ({ teams, userStaff, projects, clients,subsidiaries }) => { | |||||
| //console.log(customers) | //console.log(customers) | ||||
| const { t } = useTranslation("projects"); | const { t } = useTranslation("projects"); | ||||
| const [teamCombo, setteamCombo] = useState<comboProp[]>([]) | |||||
| const teamCombo = teams.map(team => `${team.code} - ${team.name}`) | |||||
| const [isLoading, setIsLoading] = useState(true) | const [isLoading, setIsLoading] = useState(true) | ||||
| const getTeamCombo = async() => { | |||||
| try { | |||||
| const response = await fetchTeamCombo() | |||||
| console.log(response.records) | |||||
| setteamCombo(response.records) | |||||
| setIsLoading(false) | |||||
| } catch (err) { | |||||
| console.log(err) | |||||
| } | |||||
| } | |||||
| const clientCombo = clients.map(client => ({ | const clientCombo = clients.map(client => ({ | ||||
| value: `client: ${client.id}` , | value: `client: ${client.id}` , | ||||
| label: `${client.code} - ${client.name}`, | label: `${client.code} - ${client.name}`, | ||||
| @@ -51,13 +44,9 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ | |||||
| group: t("Subsidiary") | group: t("Subsidiary") | ||||
| })) | })) | ||||
| useEffect(() => { | |||||
| getTeamCombo() | |||||
| }, []) | |||||
| const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | ||||
| () => [ | () => [ | ||||
| { label: "Team", paramName: "teamId", type: "select", options: teamCombo.map(team => team.label) }, | |||||
| { label: "Team", paramName: "teamId", type: "select", options: teamCombo, needAll: !Boolean(userStaff?.isTeamLead) }, | |||||
| //{ label: "Client", paramName: "clientId", type: "autocomplete", options: clients.map(customer => `${customer.code}-${customer.name}`) }, | //{ label: "Client", paramName: "clientId", type: "autocomplete", options: clients.map(customer => `${customer.code}-${customer.name}`) }, | ||||
| { label: t("Client"), paramName: "clientId", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, | { label: t("Client"), paramName: "clientId", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, | ||||
| { | { | ||||
| @@ -67,7 +56,7 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ | |||||
| type: "dateRange", | type: "dateRange", | ||||
| }, | }, | ||||
| ], | ], | ||||
| [t, teamCombo, clients], | |||||
| [t, teamCombo, clients, userStaff], | |||||
| ); | ); | ||||
| return ( | return ( | ||||
| @@ -81,7 +70,7 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ | |||||
| try { | try { | ||||
| // const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! | // const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! | ||||
| // const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id!! | // const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id!! | ||||
| const teamId = teamCombo.find(team => team.label === query.teamId)?.id || 0; | |||||
| const teamId = teams.find(team => `${team.code} - ${team.name}` === query.teamId)?.id || 0; | |||||
| const clientId = clients.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id || 0; | const clientId = clients.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id || 0; | ||||
| const remainedDate = query.remainedDate || "1900-01-01"; | const remainedDate = query.remainedDate || "1900-01-01"; | ||||
| const remainedDateTo = query.remainedDateTo || "2100-12-31"; | const remainedDateTo = query.remainedDateTo || "2100-12-31"; | ||||
| @@ -4,17 +4,23 @@ import LateStartReportGen from "./LateStartReportGen"; | |||||
| import LateStartReportGenLoading from "./LateStartReportGenLoading"; | import LateStartReportGenLoading from "./LateStartReportGenLoading"; | ||||
| 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 { getUserStaff } from "@/app/utils/commonUtil"; | |||||
| import { fetchTeam } from "@/app/api/team"; | |||||
| interface SubComponents { | interface SubComponents { | ||||
| Loading: typeof LateStartReportGenLoading; | Loading: typeof LateStartReportGenLoading; | ||||
| } | } | ||||
| const LateStartReportGenWrapper: React.FC & SubComponents = async () => { | const LateStartReportGenWrapper: React.FC & SubComponents = async () => { | ||||
| const clentprojects = await fetchProjectsLateStart(); | |||||
| const customers = await fetchAllCustomers(); | |||||
| const subsidiaries = await fetchAllSubsidiaries(); | |||||
| const [clentprojects, customers, subsidiaries, userStaff, teams] = await Promise.all([ | |||||
| fetchProjectsLateStart(), | |||||
| fetchAllCustomers(), | |||||
| fetchAllSubsidiaries(), | |||||
| getUserStaff(), | |||||
| fetchTeam(), | |||||
| ]); | |||||
| return <LateStartReportGen projects={clentprojects} clients={customers} subsidiaries={subsidiaries}/>; | |||||
| return <LateStartReportGen userStaff={userStaff} teams={!Boolean(userStaff?.isTeamLead) ? teams : teams.filter(team => team.id === userStaff?.teamId)} projects={clentprojects} clients={customers} subsidiaries={subsidiaries}/>; | |||||
| }; | }; | ||||
| LateStartReportGenWrapper.Loading = LateStartReportGenLoading; | LateStartReportGenWrapper.Loading = LateStartReportGenLoading; | ||||
| @@ -124,7 +124,7 @@ export default async function middleware( | |||||
| isAuth = [VIEW_STAFF_PROFILE].some((ability) => abilities.includes(ability)); | isAuth = [VIEW_STAFF_PROFILE].some((ability) => abilities.includes(ability)); | ||||
| } | } | ||||
| if (req.nextUrl.pathname.startsWith('/invoice')) { | if (req.nextUrl.pathname.startsWith('/invoice')) { | ||||
| isAuth = [IMPORT_INVOICE].some((ability) => abilities.includes(ability)); | |||||
| isAuth = [IMPORT_INVOICE, IMPORT_RECEIPT].some((ability) => abilities.includes(ability)); | |||||
| } | } | ||||
| if (req.nextUrl.pathname.startsWith('/dashboard')) { | if (req.nextUrl.pathname.startsWith('/dashboard')) { | ||||
| isAuth = [VIEW_DASHBOARD_ALL, VIEW_DASHBOARD_SELF].some((ability) => abilities.includes(ability)); | isAuth = [VIEW_DASHBOARD_ALL, VIEW_DASHBOARD_SELF].some((ability) => abilities.includes(ability)); | ||||