# Create Corrected Receipt

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /Documents/corrected-receipt:
    post:
      summary: Create Corrected Receipt
      deprecated: false
      description: |
        สร้างใบทดแทนเพื่อแก้ไขข้อมูลใบเสร็จรับเงินหลังกรมสรรมพากรอนุมัติแล้ว
        ระบบจะสร้างเอกสารใหม่และเชื่อมโยงกับเอกสารอ้างอิง
      operationId: CreateCorrectedReceipt
      tags:
        - eTaxGo/Document Management
        - Documents
      parameters:
        - name: Ocp-Apim-Subscription-Key
          in: header
          description: รหัส subscription key ของลูกค้า
          required: true
          example: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6
          schema:
            type: string
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CorrectedReceiptRequest'
            example:
              documentNo: T2024001233
              refDocumentNo: T2024001234
              reasonCode: RCTC01
              reason: null
              createdDate: '2024-01-15T00:00:00'
              issueDateTime: '2024-01-15T10:30:00'
              buyerDetail:
                taxID: '1234567890123'
                customerType: TXID
                customerName: บริษัท เอ็กซแซมเปิ้ล จำกัด
                address: 123/45 ถนนตัวอย่าง
                subDistrict: สามเสนใน
                district: พญาไท
                province: กรุงเทพมหานคร
                postCode: '10400'
              mobile: '0812345678'
              email: customer@example.com
              itemProducts:
                - productCode: P001
                  productName: สินค้าตัวอย่าง
                  quantity: 1
                  pricePerItem: 1000
                  unitName: ชิ้น
                  discount: 0
                  percentVAT: 7
              discount:
                description: Year End Discount
                amount: 0
      responses:
        '200':
          description: สร้างสำเร็จ — `status.isSuccess` = true
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      isSuccess:
                        type: boolean
                        examples:
                          - true
                    x-apidog-orders:
                      - isSuccess
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      newDocumentNumber:
                        type: string
                        description: เลขที่เอกสารใหม่ที่สร้างขึ้น
                        examples:
                          - T2024001235
                      originalDocumentNumber:
                        type: string
                        description: เลขที่เอกสารอ้างอิง
                        examples:
                          - T2024001234
                      correctedAmount:
                        type: number
                        description: ยอดเงินรวม VAT ของเอกสารใหม่
                        examples:
                          - 1070
                      cancellationReasonCode:
                        type: string
                        examples:
                          - RCTC01
                      rdSubmissionStatus:
                        type: string
                        description: สถานะการอนุมัติของกรมสรรพากร (RD)
                        examples:
                          - PENDING
                      createdAt:
                        type: string
                        description: วันเวลาที่สร้างเอกสาร (GMT+7, ไม่มี timezone suffix)
                        examples:
                          - '2024-01-15T10:30:00'
                        nullable: true
                    x-apidog-orders:
                      - newDocumentNumber
                      - originalDocumentNumber
                      - correctedAmount
                      - cancellationReasonCode
                      - rdSubmissionStatus
                      - createdAt
                    x-apidog-ignore-properties: []
                x-apidog-orders:
                  - status
                  - data
                x-apidog-ignore-properties: []
              example:
                status:
                  isSuccess: true
                data:
                  newDocumentNumber: T2024001235
                  originalDocumentNumber: T2024001234
                  correctedAmount: 1070
                  cancellationReasonCode: RCTC01
                  rdSubmissionStatus: PENDING
                  createdAt: '2024-01-15T10:30:00'
          headers: {}
          x-apidog-name: ''
        '400':
          description: >
            ล้มเหลว — `status.isSuccess` ไม่ถูก return (default false)

            `errors[].description` เป็น free-text มีหลาย message เช่น:

            - `"RefDocumentNo is required."`

            - `"ReasonCode must be one of: RCTC01, RCTC02, RCTC03, RCTC04,
            RCTC99."`

            - `"Reason is required when ReasonCode is RCTC99."`

            - `"Reason must not be provided for ReasonCode RCTC01, RCTC02,
            RCTC03, or RCTC04."`

            - `"PostCode '10400' does not match SubDistrict 'xxx'."`

            - `"Original receipt 'RCT202605270041' not found or is not a Receipt
            (T01)."`

            - `"ProductCode(s) not in original receipt: P001. New items cannot
            be added in a corrected receipt; only existing items can be
            edited."`

            - `"Duplicate ProductCode in ItemProducts: P001."`

            - `"ProductName is required."`

            - `"Quantity is required."`

            - `"Quantity cannot be negative."`

            - `"PricePerItem is required."`

            - `"PricePerItem cannot be negative."`

            - `"UnitName is required."`

            - `"UnitName must not exceed 128 characters."`

            - `"Discount cannot be negative."`

            - `"PercentVAT is required."`

            - `"PercentVAT must be 0 or 7."`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
              example:
                status:
                  code: '4001'
                  description: Business error with more than 1 errors
                data:
                  errors:
                    - subCode: E1102
                      description: >-
                        Original receipt 'RCT202605270041' not found or is not a
                        Receipt (T01).
          headers: {}
          x-apidog-name: ''
        '401':
          description: Unauthorized
          headers: {}
          x-apidog-name: ''
      security:
        - bearer: []
      x-apidog-folder: eTaxGo/Document Management
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/351895/apis/api-36769216-run
components:
  schemas:
    CorrectedReceiptRequest:
      type: object
      required:
        - refDocumentNo
        - reasonCode
      properties:
        documentNo:
          type: string
          description: >-
            เลขที่เอกสารใหม่ — ไม่ระบุก็ได้ ระบบออกให้อัตโนมัติ
            (ต้องเปิดตั้งค่าเลขอัตโนมัติ)
          examples:
            - T2024001233
          nullable: true
        refDocumentNo:
          type: string
          description: เลขที่เอกสารอ้างอิงที่ต้องการแก้ไข
          examples:
            - T2024001234
        reasonCode:
          type: string
          description: |
            รหัสเหตุผลการแก้ไข:
            - RCTC01 = ชื่อผิด (ห้ามส่ง reason)
            - RCTC02 = ที่อยู่ผิด (ห้ามส่ง reason)
            - RCTC03 = รับคืนสินค้า/ยกเลิกบริการ ทั้งจำนวน (ห้ามส่ง reason)
            - RCTC04 = รับคืนสินค้า/ยกเลิกบริการ บางส่วน (ห้ามส่ง reason)
            - RCTC99 = เหตุผลอื่น (ต้องระบุ reason สูงสุด 200 ตัวอักษร)
          enum:
            - RCTC01
            - RCTC02
            - RCTC03
            - RCTC04
            - RCTC99
          examples:
            - RCTC01
        reason:
          type: string
          description: คำอธิบายเหตุผล (required เฉพาะ RCTC99, สูงสุด 200 ตัวอักษร)
          maxLength: 200
          examples:
            - null
          nullable: true
        createdDate:
          type: string
          description: วันที่สร้างเอกสาร format YYYY-MM-DDTHH:mm:ss (GMT+7)
          examples:
            - '2024-01-15T00:00:00'
          nullable: true
        issueDateTime:
          type: string
          description: วันเวลาที่ออกเอกสาร format YYYY-MM-DDTHH:mm:ss (GMT+7)
          examples:
            - '2024-01-15T10:30:00'
          nullable: true
        buyerDetail:
          type: object
          description: |
            ข้อมูลผู้ซื้อที่ต้องการแก้ไข
            ถ้าไม่ระบุ ระบบจะใช้ข้อมูลผู้ซื้อจากเอกสารอ้างอิงโดยอัตโนมัติ
          required:
            - taxID
            - customerType
            - customerName
            - address
            - subDistrict
            - district
            - province
            - postCode
          properties:
            taxID:
              type: string
              description: 'TXID/NIDN: 13 หลัก, CCPT: 6 หรือ 9 หลัก'
              examples:
                - '1234567890123'
            customerType:
              type: string
              description: TXID = นิติบุคคล, NIDN = บุคคลธรรมดา, CCPT = ต่างชาติ
              enum:
                - TXID
                - NIDN
                - CCPT
              examples:
                - TXID
            customerName:
              type: string
              description: ชื่อลูกค้า
              examples:
                - บริษัท เอ็กซแซมเปิ้ล จำกัด
            address:
              type: string
              description: ที่อยู่
              examples:
                - 123/45 ถนนตัวอย่าง
            subDistrict:
              type: string
              description: แขวง/ตำบล (ชื่อภาษาไทย — ระบบแปลงเป็นรหัสให้อัตโนมัติ)
              examples:
                - สามเสนใน
            district:
              type: string
              description: เขต/อำเภอ
              examples:
                - พญาไท
            province:
              type: string
              description: จังหวัด
              examples:
                - กรุงเทพมหานคร
            postCode:
              type: string
              description: รหัสไปรษณีย์ (ต้องตรงกับ subDistrict)
              examples:
                - '10400'
          x-apidog-orders:
            - taxID
            - customerType
            - customerName
            - address
            - subDistrict
            - district
            - province
            - postCode
          x-apidog-ignore-properties: []
          nullable: true
        mobile:
          type: string
          description: เบอร์โทรศัพท์ในประเทศไทย (9-10 หลัก)
          examples:
            - '0812345678'
          nullable: true
        email:
          type: string
          description: email ผู้ซื้อ
          examples:
            - customer@example.com
          nullable: true
        itemProducts:
          type: array
          description: รายการสินค้าที่แก้ไข (ถ้าไม่ระบุ ใช้รายการจากเอกสารอ้างอิง)
          items:
            $ref: '#/components/schemas/CorrectedReceiptItem'
          nullable: true
        discount:
          type: object
          description: ข้อมูลส่วนลด
          properties:
            description:
              type: string
              description: เหตุผลในการลด
              examples:
                - Year End Discount
              nullable: true
            amount:
              type: number
              description: ส่วนลดเป็นจำนวนเงิน
              examples:
                - 0
          x-apidog-orders:
            - description
            - amount
          x-apidog-ignore-properties: []
          nullable: true
      x-apidog-orders:
        - documentNo
        - refDocumentNo
        - reasonCode
        - reason
        - createdDate
        - issueDateTime
        - buyerDetail
        - mobile
        - email
        - itemProducts
        - discount
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    CorrectedReceiptItem:
      type: object
      description: >-
        productCode ต้องตรงกับรายการในเอกสารอ้างอิง
        (ไม่สามารถเพิ่มรายการใหม่ได้)
      required:
        - productCode
        - productName
        - quantity
        - pricePerItem
        - unitName
        - percentVAT
      properties:
        productCode:
          type: string
          description: รหัสสินค้า
          examples:
            - P001
        productName:
          type: string
          description: ชื่อสินค้า/บริการ
          examples:
            - สินค้าตัวอย่าง
        quantity:
          type: number
          description: จำนวนหน่วยของสินค้าในรายการนี้  (≥ 0)
          examples:
            - 1
        pricePerItem:
          type: number
          description: ราคาต่อหน่วย ไม่รวม VAT (≥ 0)
          examples:
            - 1000
        unitName:
          type: string
          description: หน่วยของสินค้า (สูงสุด 128 ตัวอักษร)
          maxLength: 128
          examples:
            - ชิ้น
        discount:
          type: number
          description: ส่วนลดต่อรายการ (≥ 0) ถ้าไม่ระบุ ค่าเริ่มต้นคือ 0
          examples:
            - 0
        percentVAT:
          type: number
          description: อัตรา VAT เป็นเปอร์เซ็นต์ (ต้องเป็น 0 หรือ 7 เท่านั้น)
          enum:
            - 0
            - 7
          examples:
            - 7
      x-apidog-orders:
        - productCode
        - productName
        - quantity
        - pricePerItem
        - unitName
        - discount
        - percentVAT
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    ErrorEnvelope:
      type: object
      description: |
        HTTP 400 — business error
        `isSuccess` ไม่ถูก serialize (default false ถูก omit)
      properties:
        status:
          type: object
          properties:
            code:
              type: string
              description: '"4001" = 1 error, "4002" = หลาย errors'
              examples:
                - '4001'
            description:
              type: string
              examples:
                - Business error with more than 1 errors
          x-apidog-orders:
            - code
            - description
          x-apidog-ignore-properties: []
        data:
          type: object
          properties:
            errors:
              type: array
              items:
                type: object
                properties:
                  subCode:
                    type: string
                    description: >-
                      "E1102" = business error, "EXT9999" = internal server
                      error
                    examples:
                      - E1102
                  description:
                    type: string
                    description: ข้อความ error (free-text)
                    examples:
                      - Document not found
                x-apidog-orders:
                  - subCode
                  - description
                x-apidog-ignore-properties: []
          x-apidog-orders:
            - errors
          x-apidog-ignore-properties: []
      x-apidog-orders:
        - status
        - data
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
  securitySchemes:
    bearerAuth:
      type: jwt
      scheme: bearer
      bearerFormat: JWT
      description: ใส่ JWT Token ในรูปแบบ Bearer {token}
    bearer:
      type: http
      scheme: bearer
servers:
  - url: https://api.gofive.co.th
    description: Production
security:
  - bearerAuth: []
    x-apidog:
      schemeGroups:
        - id: uyL_cJmK7q60QJZRTi5ot
          schemeIds:
            - bearerAuth
      required: true
      use:
        id: uyL_cJmK7q60QJZRTi5ot
      scopes:
        uyL_cJmK7q60QJZRTi5ot:
          bearerAuth: []

```
