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.
 
 

85 lines
2.3 KiB

  1. "use client";
  2. import { clientAuthFetch } from "@/app/utils/clientAuthFetch";
  3. import { NEXT_PUBLIC_API_URL } from "@/config/api";
  4. export interface ReportOption {
  5. label: string;
  6. value: string;
  7. }
  8. export interface TruckRoutingSummaryPrecheck {
  9. unpickedOrderCount: number;
  10. hasUnpickedOrders: boolean;
  11. }
  12. export async function fetchTruckRoutingStoreOptions(): Promise<ReportOption[]> {
  13. const response = await clientAuthFetch(
  14. `${NEXT_PUBLIC_API_URL}/truck-routing-summary/store-options`,
  15. {
  16. method: "GET",
  17. headers: { "Content-Type": "application/json" },
  18. }
  19. );
  20. if (!response.ok) {
  21. throw new Error(`Failed to fetch store options: ${response.status}`);
  22. }
  23. const data = await response.json();
  24. if (!Array.isArray(data)) return [];
  25. return data.map((item: any) => ({
  26. label: item?.label ?? item?.value ?? "",
  27. value: item?.value ?? "",
  28. }));
  29. }
  30. export async function fetchTruckRoutingLaneOptions(storeId?: string): Promise<ReportOption[]> {
  31. const qs = storeId ? `?storeId=${encodeURIComponent(storeId)}` : "";
  32. const response = await clientAuthFetch(
  33. `${NEXT_PUBLIC_API_URL}/truck-routing-summary/lane-options${qs}`,
  34. {
  35. method: "GET",
  36. headers: { "Content-Type": "application/json" },
  37. }
  38. );
  39. if (!response.ok) {
  40. throw new Error(`Failed to fetch lane options: ${response.status}`);
  41. }
  42. const data = await response.json();
  43. if (!Array.isArray(data)) return [];
  44. return data.map((item: any) => ({
  45. label: item?.label ?? item?.value ?? "",
  46. value: item?.value ?? "",
  47. }));
  48. }
  49. export async function fetchTruckRoutingSummaryPrecheck(params: {
  50. storeId: string;
  51. truckLanceCode: string;
  52. date: string;
  53. }): Promise<TruckRoutingSummaryPrecheck> {
  54. const qs = new URLSearchParams({
  55. storeId: params.storeId,
  56. truckLanceCode: params.truckLanceCode,
  57. date: params.date,
  58. }).toString();
  59. const response = await clientAuthFetch(
  60. `${NEXT_PUBLIC_API_URL}/truck-routing-summary/precheck?${qs}`,
  61. {
  62. method: "GET",
  63. headers: { "Content-Type": "application/json" },
  64. }
  65. );
  66. if (!response.ok) {
  67. throw new Error(`Failed to precheck routing summary: ${response.status}`);
  68. }
  69. const data = await response.json();
  70. return {
  71. unpickedOrderCount: Number(data?.unpickedOrderCount ?? 0),
  72. hasUnpickedOrders: Boolean(data?.hasUnpickedOrders),
  73. };
  74. }