Просмотр исходного кода

[Prod Schedule] Update rough

master
cyril.tsui 1 месяц назад
Родитель
Сommit
fb837d468d
7 измененных файлов: 66 добавлений и 48 удалений
  1. +22
    -1
      src/app/api/scheduling/actions.ts
  2. +12
    -12
      src/app/api/scheduling/index.ts
  3. +3
    -3
      src/components/RoughScheduleDetail/DetailInfoCard.tsx
  4. +1
    -1
      src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx
  5. +5
    -6
      src/components/RoughScheduleDetail/RoughScheudleDetailView.tsx
  6. +16
    -18
      src/components/RoughScheduleDetail/ViewByBomDetails.tsx
  7. +7
    -7
      src/components/RoughScheduleDetail/ViewByFGDetails.tsx

+ 22
- 1
src/app/api/scheduling/actions.ts Просмотреть файл

@@ -4,13 +4,14 @@ import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
import { serverFetchJson } from "@/app/utils/fetchUtil"
import { BASE_API_URL } from "@/config/api"
import { cache } from "react"
import { ScheduleType } from ".";

export interface SearchProdSchedule {
scheduleAt?: string;
schedulePeriod?: string;
schedulePeriodTo?: string;
totalEstProdCount?: number;
type?: "manual" | "detailed" | "rough";
types?: ScheduleType[];
pageSize?: number;
pageNum?: number;
}
@@ -40,4 +41,24 @@ export const fetchProdSchedules = cache(async (data: SearchProdSchedule | null)
tags: ["prodSchedules"]
}
})
})

export const testRoughSchedule = cache(async () => {
return serverFetchJson(`${BASE_API_URL}/productionSchedule/testRoughSchedule`, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: {
tags: ["prodSchedules"]
}
})
})

export const testDetailSchedule = cache(async () => {
return serverFetchJson(`${BASE_API_URL}/productionSchedule/testDetailSchedule`, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: {
tags: ["prodSchedules"]
}
})
})

+ 12
- 12
src/app/api/scheduling/index.ts Просмотреть файл

@@ -3,9 +3,9 @@ import { BASE_API_URL } from "@/config/api"
import { cache } from "react"
import "server-only"

export type ScheduleType = "rough" | "detail";
export type ScheduleType = "all" | "rough" | "detailed" | "manual";

export interface ProdScheduleResult {
export interface RoughProdScheduleResult {
id: number;
scheduleAt: number[];
schedulePeriod: number[];
@@ -13,13 +13,13 @@ export interface ProdScheduleResult {
totalEstProdCount: number;
totalFGType: number;
type: string;
prodScheduleLinesByFg: ProdScheduleLineResultByFg[];
prodScheduleLinesByFgByDate: { [assignDate: number]: ProdScheduleLineResultByFg[] };
prodScheduleLinesByBom: ProdScheduleLineResultByBom[];
prodScheduleLinesByBomByDate: { [assignDate: number]: ProdScheduleLineResultByBomByDate[] };
prodScheduleLinesByFg: RoughProdScheduleLineResultByFg[];
prodScheduleLinesByFgByDate: { [assignDate: number]: RoughProdScheduleLineResultByFg[] };
prodScheduleLinesByBom: RoughProdScheduleLineResultByBom[];
prodScheduleLinesByBomByDate: { [assignDate: number]: RoughProdScheduleLineResultByBomByDate[] };
}

export interface ProdScheduleLineResultByFg {
export interface RoughProdScheduleLineResultByFg {
id: number;
code: string;
name: string;
@@ -30,10 +30,10 @@ export interface ProdScheduleLineResultByFg {
estCloseBal: number;
priority: number;
assignDate: number;
bomMaterials: ProdScheduleLineBomMaterialResult[];
bomMaterials: RoughProdScheduleLineBomMaterialResult[];
}

export interface ProdScheduleLineBomMaterialResult {
export interface RoughProdScheduleLineBomMaterialResult {
id: number;
code: string;
name: string;
@@ -43,7 +43,7 @@ export interface ProdScheduleLineBomMaterialResult {
uomName: string;
}

export interface ProdScheduleLineResultByBom {
export interface RoughProdScheduleLineResultByBom {
id: number,
code: string,
name: string,
@@ -60,7 +60,7 @@ export interface ProdScheduleLineResultByBom {
uomName: string,
}

export interface ProdScheduleLineResultByBomByDate {
export interface RoughProdScheduleLineResultByBomByDate {
id: number,
code: string,
name: string,
@@ -72,7 +72,7 @@ export interface ProdScheduleLineResultByBomByDate {
}

export const fetchProdScheduleDetail = cache(async (id: number) => {
return serverFetchJson<ProdScheduleResult>(`${BASE_API_URL}/productionSchedule/detail/${id}`, {
return serverFetchJson<RoughProdScheduleResult>(`${BASE_API_URL}/productionSchedule/detail/${id}`, {
method: "GET",
headers: { "Content-Type": "application/json" },
next: {


+ 3
- 3
src/components/RoughScheduleDetail/DetailInfoCard.tsx Просмотреть файл

@@ -18,7 +18,7 @@ import { InputDataGridProps, TableRow } from "../InputDataGrid/InputDataGrid";
import { TypeEnum } from "@/app/utils/typeEnum";
import { NumberInputProps } from "@/components/CreateItem/NumberInputProps";
import { arrayToDateString, integerFormatter } from "@/app/utils/formatUtil";
import { ProdScheduleResult } from "@/app/api/scheduling";
import { RoughProdScheduleResult } from "@/app/api/scheduling";
import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";

@@ -38,12 +38,12 @@ const DetailInfoCard: React.FC<Props> = ({ isEditing }) => {
getValues,
watch,
formState: { errors, defaultValues, touchedFields },
} = useFormContext<ProdScheduleResult>();
} = useFormContext<RoughProdScheduleResult>();

// const [details, setDetails] = useState(null);

useEffect(() => {
console.log("[debug] record details", getValues)
console.log("[debug] record details", getValues())
// setDetails(recordDetails);
}, [getValues])



+ 1
- 1
src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx Просмотреть файл

@@ -15,7 +15,7 @@ type Props = {

const RoughScheduleDetailWrapper: React.FC<Props> & SubComponents = async ({ id, type }) => {
const prodSchedule = id ? await fetchProdScheduleDetail(id) : undefined
return (
<RoughScheduleDetailView
isEditMode={Boolean(id)}


+ 5
- 6
src/components/RoughScheduleDetail/RoughScheudleDetailView.tsx Просмотреть файл

@@ -24,13 +24,13 @@ import ViewByFGDetails from "@/components/RoughScheduleDetail/ViewByFGDetails";
import ViewByBomDetails from "@/components/RoughScheduleDetail/ViewByBomDetails";
import ScheduleTable from "@/components/ScheduleTable";
import { Column } from "@/components/ScheduleTable/ScheduleTable";
import { ProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
import { RoughProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
import { arrayToDayjs, dayjsToDateString } from "@/app/utils/formatUtil";

type Props = {
isEditMode: boolean;
type: ScheduleType;
defaultValues: Partial<ProdScheduleResult> | undefined;
defaultValues: Partial<RoughProdScheduleResult> | undefined;
// qcChecks: ItemQc[]
};

@@ -42,7 +42,6 @@ const RoughScheduleDetailView: React.FC<Props> = ({
// console.log(type)
const apiRef = useGridApiRef();
const params = useSearchParams()
console.log(params.get("id"))
const [serverError, setServerError] = useState("");
const [tabIndex, setTabIndex] = useState(0);
const { t } = useTranslation("schedule")
@@ -51,7 +50,7 @@ const RoughScheduleDetailView: React.FC<Props> = ({
//const title = "Demand Forecast Detail"

// console.log(typeId)
const formProps = useForm<ProdScheduleResult>({
const formProps = useForm<RoughProdScheduleResult>({
defaultValues: defaultValues ? defaultValues : {
},
});
@@ -88,7 +87,7 @@ const RoughScheduleDetailView: React.FC<Props> = ({
router.replace(`/scheduling/rough`);
};

const onSubmit = useCallback<SubmitHandler<ProdScheduleResult>>(
const onSubmit = useCallback<SubmitHandler<RoughProdScheduleResult>>(
async (data, event) => {
let hasErrors = false;
console.log(errors)
@@ -109,7 +108,7 @@ const RoughScheduleDetailView: React.FC<Props> = ({
);

// multiple tabs
const onSubmitError = useCallback<SubmitErrorHandler<ProdScheduleResult>>(
const onSubmitError = useCallback<SubmitErrorHandler<RoughProdScheduleResult>>(
(errors) => { },
[]
);


+ 16
- 18
src/components/RoughScheduleDetail/ViewByBomDetails.tsx Просмотреть файл

@@ -21,7 +21,7 @@ import { RiceBowl } from "@mui/icons-material";
// import EditableSearchResults, { Column } from "@/components/SearchResults/EditableSearchResults";
import { decimalFormatter } from "@/app/utils/formatUtil";
import { GridRenderCellParams } from "@mui/x-data-grid";
import { ProdScheduleLineResultByBom, ProdScheduleLineResultByBomByDate, ProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
import { RoughProdScheduleLineResultByBom, RoughProdScheduleLineResultByBomByDate, RoughProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
import ScheduleTable from "@/components/ScheduleTable";
import { Column } from "@/components/ScheduleTable/ScheduleTable";

@@ -63,7 +63,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
control,
getValues,
formState: { errors, defaultValues, touchedFields },
} = useFormContext<ProdScheduleResult>();
} = useFormContext<RoughProdScheduleResult>();
// const apiRef = useGridApiRef();

const { fields } = useFieldArray({
@@ -165,7 +165,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.availableQty) == "number") {
return decimalFormatter.format(row.availableQty)
}
@@ -180,7 +180,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.totalDemandQty) == "number") {
return decimalFormatter.format(row.totalDemandQty)
}
@@ -194,7 +194,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty1) == "number") {
return decimalFormatter.format(row.demandQty1)
}
@@ -208,7 +208,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty2) == "number") {
return decimalFormatter.format(row.demandQty2)
}
@@ -222,7 +222,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty3) == "number") {
return decimalFormatter.format(row.demandQty3)
}
@@ -236,7 +236,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty4) == "number") {
return decimalFormatter.format(row.demandQty4)
}
@@ -249,7 +249,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty5) == "number") {
return decimalFormatter.format(row.demandQty5)
}
@@ -263,7 +263,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty6) == "number") {
return decimalFormatter.format(row.demandQty6)
}
@@ -277,7 +277,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBom) => {
renderCell: (row: RoughProdScheduleLineResultByBom) => {
if (typeof (row.demandQty7) == "number") {
return decimalFormatter.format(row.demandQty7)
}
@@ -288,7 +288,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
[t]
);

const columns = useMemo<Column<ProdScheduleLineResultByBomByDate>[]>(
const columns = useMemo<Column<RoughProdScheduleLineResultByBomByDate>[]>(
() => [
{
field: "code",
@@ -317,7 +317,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBomByDate) => {
renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
if (typeof (row.availableQty) == "number") {
return decimalFormatter.format(row.availableQty)
}
@@ -331,7 +331,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
style: {
textAlign: "right",
},
renderCell: (row: ProdScheduleLineResultByBomByDate) => {
renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
if (typeof (row.demandQty) == "number") {
return decimalFormatter.format(row.demandQty)
}
@@ -342,15 +342,13 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
[]
);

console.log(getValues("prodScheduleLinesByBom"))

return (
<Grid container spacing={2}>
<Grid item xs={12} key={"all"}>
<Typography variant="overline" display="block" marginBlockEnd={1}>
{t("Material Demand List (7 Days)")}
</Typography>
<ScheduleTable<ProdScheduleLineResultByBom>
<ScheduleTable<RoughProdScheduleLineResultByBom>
// index={7}
type={type}
items={getValues("prodScheduleLinesByBom")}
@@ -368,7 +366,7 @@ const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod })
<Typography variant="overline" display="block" marginBlockEnd={1}>
{`${t("Material Demand Date")}: ${date}`}
</Typography>
<ScheduleTable<ProdScheduleLineResultByBomByDate>
<ScheduleTable<RoughProdScheduleLineResultByBomByDate>
// index={index}
type={type}
items={getValues("prodScheduleLinesByBomByDate")[index + 1]} // Use the corresponding records for the day


+ 7
- 7
src/components/RoughScheduleDetail/ViewByFGDetails.tsx Просмотреть файл

@@ -21,7 +21,7 @@ import { RiceBowl } from "@mui/icons-material";
import ScheduleTable from "@/components/ScheduleTable";
import { Column } from "@/components/ScheduleTable/ScheduleTable";
import { arrayToDayjs, dayjsToDateString, decimalFormatter, integerFormatter } from "@/app/utils/formatUtil";
import { ProdScheduleLineResultByFg, ProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
import { RoughProdScheduleLineResultByFg, RoughProdScheduleResult, ScheduleType } from "@/app/api/scheduling";

type Props = {
apiRef: MutableRefObject<GridApiCommunity>
@@ -50,7 +50,7 @@ const ViewByFGDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod }) =
control,
getValues,
formState: { errors, defaultValues, touchedFields },
} = useFormContext<ProdScheduleResult>();
} = useFormContext<RoughProdScheduleResult>();

const { fields } = useFieldArray({
control,
@@ -125,7 +125,7 @@ const ViewByFGDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod }) =
});
};

const columns = useMemo<Column<ProdScheduleLineResultByFg>[]>(
const columns = useMemo<Column<RoughProdScheduleLineResultByFg>[]>(
() => [
{
field: "code",
@@ -177,7 +177,7 @@ const ViewByFGDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod }) =
[]
);

const overallColumns = useMemo<Column<ProdScheduleLineResultByFg>[]>(
const overallColumns = useMemo<Column<RoughProdScheduleLineResultByFg>[]>(
() => [
{
field: "code",
@@ -270,7 +270,7 @@ const ViewByFGDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod }) =
<Typography variant="overline" display="block" marginBlockEnd={1}>
{t("FG Demand List (7 Days)")}
</Typography>
<ScheduleTable<ProdScheduleLineResultByFg>
<ScheduleTable<RoughProdScheduleLineResultByFg>
// index={7}
type={type}
items={getValues("prodScheduleLinesByFg")}
@@ -288,9 +288,9 @@ const ViewByFGDetails: React.FC<Props> = ({ apiRef, isEdit, type, dayPeriod }) =
<Typography variant="overline" display="block" marginBlockEnd={1}>
{`${t("FG Demand Date")}: ${date}`}
</Typography>
<ScheduleTable<ProdScheduleLineResultByFg>
<ScheduleTable<RoughProdScheduleLineResultByFg>
type={type}
items={getValues("prodScheduleLinesByFgByDate")[index + 1]} // Use the corresponding records for the day
items={getValues("prodScheduleLinesByFgByDate") && Object.entries(getValues("prodScheduleLinesByFgByDate")).length > 0 ? getValues("prodScheduleLinesByFgByDate")[index + 1] : []} // Use the corresponding records for the day
columns={columns}
setPagingController={updatePagingController}
pagingController={pagingController[index]}


Загрузка…
Отмена
Сохранить