콘텐츠로 이동

material_supplier / material_cost 스키마 (자재비)

현장별 자재 공급자와 날짜별 자재 매입 내역을 관리하는 스키마. 자재비 화면은 material_supplier 문서(공급자 정보 + 집계) + 하위 material_cost/{YYYYMMDD}(일별 매입 내역) 구조로 구성됩니다.

저장 위치

companies/{company_id}/sites/{site_id}/material_supplier/{supplier_id}
companies/{company_id}/sites/{site_id}/material_supplier/{supplier_id}/material_cost/{YYYYMMDD}
  • supplier_id: Firestore 자동 생성 ID
  • material_cost 문서 ID는 매입 날짜의 YYYYMMDD 문자열 (같은 공급자/같은 날은 덮어쓰기)

상위: material_supplier/{supplier_id}

자재 공급자 본문. 생성 시 기본 필드만 채워지고 update_material_supplier로 상세 정보를 채웁니다. 하위 material_cost 문서가 쓰일 때 트랜잭션으로 집계 필드가 갱신됩니다.

필드 타입 설명
supplier_name string 공급자(거래처)명
main_address string 공급자 주소 (도로명)
sub_address string 상세주소
supplier_phone string 공급자 전화번호 (tel 형식)
supplier_registration_number string 사업자등록번호 (registration_number 형식)
owner_name string 대표자명
supplier_type string 업태
supplier_item string 종목
total_cost int 전체 공급가액 합계 (원)
total_tax int 전체 세액 합계 (원)
year_costs object 연도별 공급가액 { "2026": 12345000 }
year_tax object 연도별 세액
month_costs object 월별 공급가액 { "202604": 1200000 }
month_tax object 월별 세액
created_at timestamp 생성 시각 (SERVER_TIMESTAMP)
created_by string 생성자 UID
updated_at timestamp? 정보 수정 시각
updated_by string? 정보 수정자 UID

집계 필드(total_cost, total_tax, year_*, month_*)는 post_material_cost 호출 시 트랜잭션으로 재계산됩니다.

하위: material_cost/{YYYYMMDD}

날짜별 자재 매입 내역 문서. 같은 공급자·같은 날짜면 덮어쓰기됩니다.

필드 타입 설명
date timestamp 매입 날짜 (KST 00:00:00)
data LineItem[] 자재 라인 배열 (아래 LineItem)
total_sum int 라인들의 합계(total) 합
tax_sum int 라인들의 세액 합
created_at timestamp 저장 시각
created_by string 저장한 UID

LineItem

data 배열 안 각 자재 항목.

필드 타입 설명
quantity int 수량
unit_price int 단가 (원)
supply_amount int 공급가액 (원)
tax int 세액 (원)
total int 합계 (원)
item_name string? 품목명 (프론트 정의)
unit string? 단위
memo string? 비고

저장 시 다음 수식이 성립해야 합니다:

supply_amount + tax == total
quantity * unit_price == total

하나라도 어긋나면 VALIDATION_011 에러가 납니다.

첨부파일 연결

공급자 단위 첨부파일(세금계산서, 거래명세서 등)은 companies/{cid}/sites/{sid}/files/ 컬렉션에 저장되며 related_doc_id == supplier_id로 연결됩니다. 공급자 삭제 시 filesrelated_doc_id == supplier_id인 문서도 함께 정리됩니다.

예시 문서

material_supplier

{
  "supplier_name": "대한자재",
  "main_address": "서울시 강남구 테헤란로 1",
  "sub_address": "101동 202호",
  "supplier_phone": "02-1234-5678",
  "supplier_registration_number": "123-45-67890",
  "owner_name": "홍길동",
  "supplier_type": "도소매",
  "supplier_item": "건설자재",
  "total_cost": 10000000,
  "total_tax": 1000000,
  "year_costs": { "2026": 10000000 },
  "year_tax": { "2026": 1000000 },
  "month_costs": { "202604": 3000000 },
  "month_tax": { "202604": 300000 },
  "created_at": "2026-04-01T00:00:00Z",
  "created_by": "uid_admin"
}

material_cost/20260420

{
  "date": "2026-04-20T00:00:00+09:00",
  "data": [
    {
      "item_name": "시멘트 40kg",
      "quantity": 10,
      "unit_price": 5000,
      "supply_amount": 50000,
      "tax": 5000,
      "total": 55000
    },
    {
      "item_name": "철근 D10",
      "quantity": 20,
      "unit_price": 3000,
      "supply_amount": 60000,
      "tax": 6000,
      "total": 66000
    }
  ],
  "total_sum": 121000,
  "tax_sum": 11000,
  "created_at": "2026-04-20T10:00:00Z",
  "created_by": "uid_admin"
}