|
|
@@ -41,33 +41,45 @@ const ApproverAllCardList: React.FC<ApproverAllCardListProps> = ({ |
|
|
const data = await getApproverStockTakeRecords(); |
|
|
const data = await getApproverStockTakeRecords(); |
|
|
const list = Array.isArray(data) ? data : []; |
|
|
const list = Array.isArray(data) ? data : []; |
|
|
|
|
|
|
|
|
// 找出最新一轮的 planStartDate |
|
|
|
|
|
const withPlanStart = list.filter((s) => s.planStartDate); |
|
|
|
|
|
if (withPlanStart.length === 0) { |
|
|
|
|
|
|
|
|
// 用 stockTakeRoundId 聚合輪次;舊資料 roundId 可能為 null,fallback 到 stockTakeId |
|
|
|
|
|
const roundGroups = new Map<number, AllPickedStockTakeListReponse[]>(); |
|
|
|
|
|
list.forEach((s) => { |
|
|
|
|
|
const roundKey = s.stockTakeRoundId ?? s.stockTakeId; |
|
|
|
|
|
const existing = roundGroups.get(roundKey) ?? []; |
|
|
|
|
|
existing.push(s); |
|
|
|
|
|
roundGroups.set(roundKey, existing); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (roundGroups.size === 0) { |
|
|
setSessions([]); |
|
|
setSessions([]); |
|
|
setPage(0); |
|
|
setPage(0); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const latestPlanStart = withPlanStart |
|
|
|
|
|
.map((s) => s.planStartDate as string) |
|
|
|
|
|
.sort((a, b) => dayjs(b).valueOf() - dayjs(a).valueOf())[0]; |
|
|
|
|
|
|
|
|
|
|
|
// 这一轮下所有 section 的卡片 |
|
|
|
|
|
const roundSessions = list.filter((s) => s.planStartDate === latestPlanStart); |
|
|
|
|
|
|
|
|
const allRounds = Array.from(roundGroups.values()); |
|
|
|
|
|
const latestRoundSessions = allRounds |
|
|
|
|
|
.sort((a, b) => { |
|
|
|
|
|
const aLatest = Math.max( |
|
|
|
|
|
...a.map((s) => dayjs(s.planStartDate ?? s.startTime ?? 0).valueOf()) |
|
|
|
|
|
); |
|
|
|
|
|
const bLatest = Math.max( |
|
|
|
|
|
...b.map((s) => dayjs(s.planStartDate ?? s.startTime ?? 0).valueOf()) |
|
|
|
|
|
); |
|
|
|
|
|
return bLatest - aLatest; |
|
|
|
|
|
})[0]; |
|
|
|
|
|
|
|
|
// 汇总这一轮的总 item / lot 数 |
|
|
// 汇总这一轮的总 item / lot 数 |
|
|
const totalItems = roundSessions.reduce( |
|
|
|
|
|
|
|
|
const totalItems = latestRoundSessions.reduce( |
|
|
(sum, s) => sum + (s.totalItemNumber || 0), |
|
|
(sum, s) => sum + (s.totalItemNumber || 0), |
|
|
0 |
|
|
0 |
|
|
); |
|
|
); |
|
|
const totalLots = roundSessions.reduce( |
|
|
|
|
|
|
|
|
const totalLots = latestRoundSessions.reduce( |
|
|
(sum, s) => sum + (s.totalInventoryLotNumber || 0), |
|
|
(sum, s) => sum + (s.totalInventoryLotNumber || 0), |
|
|
0 |
|
|
0 |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// 用这一轮里的第一条作为代表,覆盖汇总数字 |
|
|
// 用这一轮里的第一条作为代表,覆盖汇总数字 |
|
|
const representative = roundSessions[0]; |
|
|
|
|
|
|
|
|
const representative = latestRoundSessions[0]; |
|
|
const mergedRound: AllPickedStockTakeListReponse = { |
|
|
const mergedRound: AllPickedStockTakeListReponse = { |
|
|
...representative, |
|
|
...representative, |
|
|
totalItemNumber: totalItems, |
|
|
totalItemNumber: totalItems, |
|
|
@@ -120,6 +132,7 @@ const ApproverAllCardList: React.FC<ApproverAllCardListProps> = ({ |
|
|
const planStart = session.planStartDate |
|
|
const planStart = session.planStartDate |
|
|
? dayjs(session.planStartDate).format(OUTPUT_DATE_FORMAT) |
|
|
? dayjs(session.planStartDate).format(OUTPUT_DATE_FORMAT) |
|
|
: "-"; |
|
|
: "-"; |
|
|
|
|
|
const roundLabel = session.stockTakeRoundId ?? session.stockTakeId; |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Grid key={session.stockTakeId} item xs={12} sm={6} md={4}> |
|
|
<Grid key={session.stockTakeId} item xs={12} sm={6} md={4}> |
|
|
@@ -140,7 +153,7 @@ const ApproverAllCardList: React.FC<ApproverAllCardListProps> = ({ |
|
|
> |
|
|
> |
|
|
<CardContent sx={{ pb: 1, flexGrow: 1 }}> |
|
|
<CardContent sx={{ pb: 1, flexGrow: 1 }}> |
|
|
<Typography variant="subtitle1" fontWeight={600} sx={{ mb: 0.5 }}> |
|
|
<Typography variant="subtitle1" fontWeight={600} sx={{ mb: 0.5 }}> |
|
|
{t("Stock Take Round")}: {planStart} |
|
|
|
|
|
|
|
|
{t("Stock Take Round")}: #{roundLabel} |
|
|
</Typography> |
|
|
</Typography> |
|
|
<Typography variant="body2" color="text.secondary"> |
|
|
<Typography variant="body2" color="text.secondary"> |
|
|
{t("Plan Start Date")}: {planStart} |
|
|
{t("Plan Start Date")}: {planStart} |
|
|
|