FPSMS-frontend
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

83 řádky
2.0 KiB

  1. "use client";
  2. import { NEXT_PUBLIC_API_URL } from "@/config/api";
  3. import { clientAuthFetch } from "@/app/utils/clientAuthFetch";
  4. export interface JobOrderListItem {
  5. id: number;
  6. code: string | null;
  7. planStart: string | null;
  8. itemCode: string | null;
  9. itemName: string | null;
  10. reqQty: number | null;
  11. stockInLineId: number | null;
  12. itemId: number | null;
  13. lotNo: string | null;
  14. }
  15. export interface PrinterStatusRequest {
  16. printerType: "dataflex" | "laser";
  17. printerIp?: string;
  18. printerPort?: number;
  19. }
  20. export interface PrinterStatusResponse {
  21. connected: boolean;
  22. message: string;
  23. }
  24. export interface OnPackQrDownloadRequest {
  25. jobOrders: {
  26. jobOrderId: number;
  27. itemCode: string;
  28. }[];
  29. }
  30. /**
  31. * Fetch job orders by plan date from GET /py/job-orders.
  32. * Client-side only; uses auth token from localStorage.
  33. */
  34. export async function fetchJobOrders(planStart: string): Promise<JobOrderListItem[]> {
  35. const url = `${NEXT_PUBLIC_API_URL}/py/job-orders?planStart=${encodeURIComponent(planStart)}`;
  36. const res = await clientAuthFetch(url, { method: "GET" });
  37. if (!res.ok) {
  38. throw new Error(`Failed to fetch job orders: ${res.status}`);
  39. }
  40. return res.json();
  41. }
  42. export async function checkPrinterStatus(
  43. request: PrinterStatusRequest,
  44. ): Promise<PrinterStatusResponse> {
  45. const url = `${NEXT_PUBLIC_API_URL}/plastic/check-printer`;
  46. const res = await clientAuthFetch(url, {
  47. method: "POST",
  48. headers: { "Content-Type": "application/json" },
  49. body: JSON.stringify(request),
  50. });
  51. const data = (await res.json()) as PrinterStatusResponse;
  52. if (!res.ok) {
  53. return data;
  54. }
  55. return data;
  56. }
  57. export async function downloadOnPackQrZip(
  58. request: OnPackQrDownloadRequest,
  59. ): Promise<Blob> {
  60. const url = `${NEXT_PUBLIC_API_URL}/plastic/download-onpack-qr`;
  61. const res = await clientAuthFetch(url, {
  62. method: "POST",
  63. headers: { "Content-Type": "application/json" },
  64. body: JSON.stringify(request),
  65. });
  66. if (!res.ok) {
  67. throw new Error((await res.text()) || "Download failed");
  68. }
  69. return res.blob();
  70. }