FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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