summaryrefslogtreecommitdiff
path: root/lib/po/vendor-table/validations.ts
blob: 70b3d87a65e001254b379e635623edc3caaf6819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
  createSearchParamsCache,
  parseAsArrayOf,
  parseAsInteger,
  parseAsString,
  parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"

import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { VendorPO } from "./types"

export const vendorPoSearchParamsCache = createSearchParamsCache({
  // UI 모드나 플래그 관련
  flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),

  // 페이징
  page: parseAsInteger.withDefault(1),
  perPage: parseAsInteger.withDefault(10),

  // 정렬 (최종수정일 기준 내림차순)
  sort: getSortingStateParser<VendorPO>().withDefault([
    { id: "lastModifiedDate", desc: true },
  ]),

  // 벤더 PO 관련 필드
  contractNo: parseAsString.withDefault(""), // PO/계약번호
  contractName: parseAsString.withDefault(""), // 계약명/자재내역
  projectName: parseAsString.withDefault(""), // 프로젝트
  contractStatus: parseAsString.withDefault(""), // 계약상태
  contractType: parseAsString.withDefault(""), // 계약종류
  currency: parseAsString.withDefault(""), // 계약통화
  paymentTerms: parseAsString.withDefault(""), // 지불조건
  deliveryTerms: parseAsString.withDefault(""), // 인도조건
  purchaseManager: parseAsString.withDefault(""), // 구매/계약담당
  
  // 날짜 관련
  poReceiveDate: parseAsString.withDefault(""), // PO/계약수신일
  contractDate: parseAsString.withDefault(""), // 계약체결일
  lastModifiedDate: parseAsString.withDefault(""), // 최종수정일
  
  // 기타
  lcNo: parseAsString.withDefault(""), // L/C No.
  priceIndexTarget: parseAsStringEnum(["true", "false"]).withDefault(""), // 납품대금 연동제 대상
  linkedContractNo: parseAsString.withDefault(""), // 연계 PO/계약번호
  lastModifiedBy: parseAsString.withDefault(""), // 최종수정자
  
  // 벤더 필터링 (내부적으로 사용)
  vendorId: parseAsInteger.withDefault(0), // 특정 벤더의 PO만 조회

  // 고급 필터(Advanced) & 검색
  filters: getFiltersStateParser().withDefault([]),
  joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
  search: parseAsString.withDefault(""),
})

// 최종 타입
export type GetVendorPOSchema = Awaited<ReturnType<typeof vendorPoSearchParamsCache.parse>>