FPSMS-frontend
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

226 行
5.8 KiB

  1. "use server";
  2. import { BASE_API_URL } from "@/config/api";
  3. import { serverFetchJson } from "@/app/utils/fetchUtil";
  4. import { cache } from "react";
  5. import type { MessageResponse } from "@/app/api/shop/actions";
  6. // Export types/interfaces (these are safe to import in client components)
  7. export interface StockIssueResult {
  8. id: number;
  9. itemId: number;
  10. itemCode: string;
  11. itemDescription: string;
  12. lotId: number;
  13. lotNo: string;
  14. storeLocation: string | null;
  15. requiredQty: number | null;
  16. actualPickQty: number | null;
  17. missQty: number;
  18. badItemQty: number;
  19. bookQty: number;
  20. issueQty: number;
  21. issueRemark: string | null;
  22. pickerName: string | null;
  23. handleStatus: string;
  24. handleDate: string | null;
  25. handledBy: number | null;
  26. }
  27. export interface ExpiryItemResult {
  28. id: number;
  29. itemId: number;
  30. itemCode: string;
  31. itemDescription: string | null;
  32. lotId: number;
  33. lotNo: string | null;
  34. storeLocation: string | null;
  35. expiryDate: string | null;
  36. remainingQty: number;
  37. }
  38. export interface StockIssueLists {
  39. missItems: StockIssueResult[];
  40. badItems: StockIssueResult[];
  41. expiryItems: ExpiryItemResult[];
  42. }
  43. // Server actions (these work from both server and client components)
  44. export const PreloadList = () => {
  45. fetchList();
  46. };
  47. export const fetchMissItemList = cache(async (issueCategory: string = "lot_issue") => {
  48. return serverFetchJson<StockIssueResult[]>(
  49. `${BASE_API_URL}/pickExecution/issues/missItem?issueCategory=${issueCategory}`,
  50. {
  51. next: { tags: ["Miss Item List"] },
  52. },
  53. );
  54. });
  55. export const fetchBadItemList = cache(async (issueCategory: string = "lot_issue") => {
  56. return serverFetchJson<StockIssueResult[]>(
  57. `${BASE_API_URL}/pickExecution/issues/badItem?issueCategory=${issueCategory}`,
  58. {
  59. next: { tags: ["Bad Item List"] },
  60. },
  61. );
  62. });
  63. export const fetchExpiryItemList = cache(async () => {
  64. return serverFetchJson<ExpiryItemResult[]>(
  65. `${BASE_API_URL}/pickExecution/issues/expiryItem`,
  66. {
  67. next: { tags: ["Expiry Item List"] },
  68. },
  69. );
  70. });
  71. export const fetchList = cache(async (issueCategory: string = "lot_issue"): Promise<StockIssueLists> => {
  72. const [missItems, badItems, expiryItems] = await Promise.all([
  73. fetchMissItemList(issueCategory),
  74. fetchBadItemList(issueCategory),
  75. fetchExpiryItemList(),
  76. ]);
  77. return {
  78. missItems,
  79. badItems,
  80. expiryItems,
  81. };
  82. });
  83. export async function submitMissItem(issueId: number, handler: number) {
  84. return serverFetchJson<MessageResponse>(
  85. `${BASE_API_URL}/pickExecution/submitMissItem`,
  86. {
  87. method: "POST",
  88. headers: {
  89. "Content-Type": "application/json",
  90. },
  91. body: JSON.stringify({ issueId, handler }),
  92. },
  93. );
  94. }
  95. export async function batchSubmitMissItem(issueIds: number[], handler: number) {
  96. return serverFetchJson<MessageResponse>(
  97. `${BASE_API_URL}/pickExecution/batchSubmitMissItem`,
  98. {
  99. method: "POST",
  100. headers: {
  101. "Content-Type": "application/json",
  102. },
  103. body: JSON.stringify({ issueIds, handler }),
  104. },
  105. );
  106. }
  107. export async function submitBadItem(issueId: number, handler: number) {
  108. return serverFetchJson<MessageResponse>(
  109. `${BASE_API_URL}/pickExecution/submitBadItem`,
  110. {
  111. method: "POST",
  112. headers: {
  113. "Content-Type": "application/json",
  114. },
  115. body: JSON.stringify({ issueId, handler }),
  116. },
  117. );
  118. }
  119. export async function batchSubmitBadItem(issueIds: number[], handler: number) {
  120. return serverFetchJson<MessageResponse>(
  121. `${BASE_API_URL}/pickExecution/batchSubmitBadItem`,
  122. {
  123. method: "POST",
  124. headers: {
  125. "Content-Type": "application/json",
  126. },
  127. body: JSON.stringify({ issueIds, handler }),
  128. },
  129. );
  130. }
  131. export async function submitExpiryItem(lotLineId: number, handler: number) {
  132. return serverFetchJson<MessageResponse>(
  133. `${BASE_API_URL}/pickExecution/submitExpiryItem`,
  134. {
  135. method: "POST",
  136. headers: {
  137. "Content-Type": "application/json",
  138. },
  139. body: JSON.stringify({ lotLineId, handler }),
  140. },
  141. );
  142. }
  143. export async function batchSubmitExpiryItem(lotLineIds: number[], handler: number) {
  144. return serverFetchJson<MessageResponse>(
  145. `${BASE_API_URL}/pickExecution/batchSubmitExpiryItem`,
  146. {
  147. method: "POST",
  148. headers: {
  149. "Content-Type": "application/json",
  150. },
  151. body: JSON.stringify({ lotLineIds, handler }),
  152. },
  153. );
  154. }
  155. export interface LotIssueDetailResponse {
  156. lotId: number | null;
  157. lotNo: string | null;
  158. itemId: number;
  159. itemCode: string | null;
  160. itemDescription: string | null;
  161. storeLocation: string | null;
  162. issues: IssueDetailItem[];
  163. }
  164. export interface IssueDetailItem {
  165. issueId: number;
  166. pickerName: string | null;
  167. missQty: number | null;
  168. issueQty: number | null;
  169. pickOrderCode: string;
  170. doOrderCode: string | null;
  171. joOrderCode: string | null;
  172. issueRemark: string | null;
  173. }
  174. export async function getLotIssueDetails(
  175. lotId: number,
  176. itemId: number,
  177. issueType: "miss" | "bad"
  178. ) {
  179. return serverFetchJson<LotIssueDetailResponse>(
  180. `${BASE_API_URL}/pickExecution/lotIssueDetails?lotId=${lotId}&itemId=${itemId}&issueType=${issueType}`,
  181. {
  182. method: "GET",
  183. headers: {
  184. "Content-Type": "application/json",
  185. },
  186. }
  187. );
  188. }
  189. export async function submitIssueWithQty(
  190. lotId: number,
  191. itemId: number,
  192. issueType: "miss" | "bad",
  193. submitQty: number,
  194. handler: number
  195. ){return serverFetchJson<MessageResponse>(
  196. `${BASE_API_URL}/pickExecution/submitIssueWithQty`,
  197. {
  198. method: "POST",
  199. headers: {
  200. "Content-Type": "application/json",
  201. },
  202. body: JSON.stringify({ lotId, itemId, issueType, submitQty, handler }),
  203. }
  204. );
  205. }