FPSMS-frontend
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

5 місяці тому
1 тиждень тому
1 тиждень тому
1 тиждень тому
5 місяці тому
5 місяці тому
5 місяці тому
1 тиждень тому
5 місяці тому
1 тиждень тому
1 тиждень тому
1 тиждень тому
1 тиждень тому
3 дні тому
1 тиждень тому
3 дні тому
1 тиждень тому
1 тиждень тому
1 тиждень тому
1 тиждень тому
3 дні тому
1 тиждень тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. "use client";
  2. import { CreateItemInputs } from "@/app/api/settings/item/actions";
  3. import {
  4. GridColDef,
  5. GridRowModel,
  6. GridRenderEditCellParams,
  7. GridEditInputCell,
  8. GridRowSelectionModel,
  9. useGridApiRef,
  10. } from "@mui/x-data-grid";
  11. import { MutableRefObject, useCallback, useMemo, useState } from "react";
  12. import { useFormContext } from "react-hook-form";
  13. import { useTranslation } from "react-i18next";
  14. import { Box, Grid, Tooltip, Typography } from "@mui/material";
  15. import { GridApiCommunity } from "@mui/x-data-grid/internals";
  16. import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil";
  17. import { DetailedProdScheduleLineResult, DetailedProdScheduleResult, ScheduleType } from "@/app/api/scheduling";
  18. import ProdTimeColumn from "./ProdTimeColumn";
  19. import ScheduleTable, { Column } from "../ScheduleTable/ScheduleTable";
  20. type Props = {
  21. apiRef: MutableRefObject<GridApiCommunity>;
  22. isEdit: boolean;
  23. type: ScheduleType;
  24. onReleaseClick: (item: DetailedProdScheduleLineResult) => void;
  25. onEditClick: (rowId: number) => void;
  26. handleEditChange: (rowId: number, fieldName: keyof DetailedProdScheduleLineResult, newValue: number | string) => void;
  27. onSaveClick: (item: DetailedProdScheduleLineResult) => void;
  28. onCancelClick: (rowId: number) => void;
  29. };
  30. const ViewByFGDetails: React.FC<Props> = ({
  31. apiRef,
  32. isEdit,
  33. type,
  34. onReleaseClick,
  35. onEditClick,
  36. handleEditChange,
  37. onSaveClick,
  38. onCancelClick
  39. }) => {
  40. const {
  41. t,
  42. i18n: { language },
  43. } = useTranslation("schedule");
  44. const {
  45. getValues,
  46. formState: { errors, defaultValues, touchedFields },
  47. } = useFormContext<DetailedProdScheduleResult>();
  48. const columns = useMemo<Column<DetailedProdScheduleLineResult>[]>(
  49. () => [
  50. {
  51. field: "jobNo",
  52. label: t("Job No."),
  53. type: "read-only",
  54. },
  55. {
  56. field: "code",
  57. label: t("code"),
  58. type: "read-only",
  59. },
  60. {
  61. field: "name",
  62. label: t("name"),
  63. type: "read-only",
  64. },
  65. {
  66. field: "type",
  67. label: t("type"),
  68. type: "read-only",
  69. renderCell: (row) => <>{t(row.type)}</>,
  70. },
  71. {
  72. field: "demandQty",
  73. label: t("Demand Qty"),
  74. type: "input-number",
  75. style: { textAlign: "right" } as any, // Use 'as any' to bypass strict CSS validation
  76. renderCell: (row) => <>{integerFormatter.format(row.demandQty ?? 0)}</>,
  77. },
  78. {
  79. field: "uomName",
  80. label: t("UoM"),
  81. type: "read-only",
  82. renderCell: (row) => <>{row.uomName}</>,
  83. },
  84. // --- Added Avg Usage, Stock, Days Left, and Job Order Count ---
  85. {
  86. field: "avgQtyLastMonth", // This MUST match the key in the object
  87. label: t("最近每日用量"),
  88. type: "read-only",
  89. // Ensure 'row' has the property 'avgQtyLastMonth'
  90. renderCell: (row) => <>{decimalFormatter.format(row.avgQtyLastMonth ?? 0)}</>,
  91. },
  92. {
  93. field: "stockQty",
  94. label: t("存貨量"),
  95. type: "read-only",
  96. style: { textAlign: "right" } as any,
  97. renderCell: (row) => <>{decimalFormatter.format(row.stockQty ?? 0)}</>,
  98. },
  99. {
  100. field: "daysLeft",
  101. label: t("可用日"),
  102. type: "read-only",
  103. style: { textAlign: "right" } as any,
  104. renderCell: (row) => <>{row.daysLeft ?? 0}</>,
  105. },
  106. {
  107. field: "outputQty",
  108. label: t("每批次生產數"),
  109. type: "read-only",
  110. style: { textAlign: "right", fontWeight: "bold" } as any,
  111. renderCell: (row) => <>{row.outputQty ?? 0}</>,
  112. },
  113. {
  114. field: "needNoOfJobOrder",
  115. label: t("生產批次"),
  116. type: "read-only",
  117. style: { textAlign: "right", fontWeight: "bold" } as any,
  118. renderCell: (row) => <>{row.needNoOfJobOrder ?? 0}</>,
  119. },
  120. // -------------------------------------------------------------
  121. {
  122. field: "priority",
  123. label: t("Production Priority"),
  124. type: "read-only",
  125. style: { textAlign: "right" } as any,
  126. },
  127. ],
  128. [t]
  129. );
  130. return (
  131. <Grid container spacing={2}>
  132. <Grid item xs={12}>
  133. <ScheduleTable<DetailedProdScheduleLineResult>
  134. type={type}
  135. items={getValues("prodScheduleLines")}
  136. columns={columns}
  137. isAutoPaging={false}
  138. isEditable={true}
  139. isEdit={isEdit}
  140. hasCollapse={true}
  141. onReleaseClick={onReleaseClick}
  142. onEditClick={onEditClick}
  143. handleEditChange={handleEditChange}
  144. onSaveClick={onSaveClick}
  145. onCancelClick={onCancelClick}
  146. />
  147. </Grid>
  148. </Grid>
  149. );
  150. }; // Added missing closing brace
  151. export default ViewByFGDetails;