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