{
  "name": "create_thai_invoice",
  "slug": "invoice-generator",
  "description": {
    "th": "เตรียมใบเสนอราคา ใบแจ้งหนี้ หรือใบเสร็จรับเงินภาษาไทย/อังกฤษ คิด VAT 7% ส่วนลด หัก ณ ที่จ่าย และ QR พร้อมเพย์ ได้ยอดรวมและลิงก์เปิดหน้าเว็บที่กรอกข้อมูลไว้แล้วให้ผู้ใช้ตรวจและดาวน์โหลด PDF",
    "en": "Prepares a Thai or English quotation, invoice or receipt with 7% VAT, discounts, withholding tax and a PromptPay QR. Returns the totals and a link to a prefilled page where the user checks it and downloads the PDF."
  },
  "inputSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "type": {
        "description": "Document type; default invoice.",
        "type": "string",
        "enum": [
          "quotation",
          "invoice",
          "receipt"
        ]
      },
      "language": {
        "description": "Printed language; default the caller language.",
        "type": "string",
        "enum": [
          "th",
          "en"
        ]
      },
      "date": {
        "description": "Document date, YYYY-MM-DD (Gregorian); default today.",
        "type": "string"
      },
      "dueDate": {
        "description": "Invoice only: due date, YYYY-MM-DD (Gregorian); default date + creditDays.",
        "type": "string"
      },
      "creditDays": {
        "description": "Credit days; default 30.",
        "type": "integer",
        "minimum": 0,
        "maximum": 3650
      },
      "validDays": {
        "description": "Quotation: days the price holds; default 30.",
        "type": "integer",
        "minimum": 0,
        "maximum": 3650
      },
      "number": {
        "description": "Document number, e.g. IV-2569-0001.",
        "type": "string",
        "maxLength": 40
      },
      "refNo": {
        "description": "Number of the document this one follows (e.g. the quotation).",
        "type": "string",
        "maxLength": 40
      },
      "paymentMethod": {
        "description": "Receipt: how it was paid (cash, transfer ...).",
        "type": "string",
        "maxLength": 60
      },
      "notes": {
        "description": "Notes printed on the document.",
        "type": "string",
        "maxLength": 1000
      },
      "paymentTerms": {
        "description": "Payment terms / bank account details.",
        "type": "string",
        "maxLength": 1000
      },
      "seller": {
        "description": "The seller (issuer).",
        "type": "object",
        "properties": {
          "name": {
            "description": "Name.",
            "type": "string",
            "maxLength": 120
          },
          "address": {
            "description": "Address, one text (new lines allowed).",
            "type": "string",
            "maxLength": 300
          },
          "taxId": {
            "description": "13-digit tax ID; a foreign ID is allowed (a warning is returned).",
            "type": "string",
            "maxLength": 20
          },
          "branch": {
            "description": "Branch, e.g. สำนักงานใหญ่ or 00001.",
            "type": "string",
            "maxLength": 40
          },
          "phone": {
            "description": "Phone.",
            "type": "string",
            "maxLength": 40
          },
          "email": {
            "description": "Email.",
            "type": "string",
            "maxLength": 80
          }
        },
        "additionalProperties": false
      },
      "customer": {
        "description": "The customer.",
        "type": "object",
        "properties": {
          "name": {
            "description": "Name.",
            "type": "string",
            "maxLength": 120
          },
          "address": {
            "description": "Address, one text (new lines allowed).",
            "type": "string",
            "maxLength": 300
          },
          "taxId": {
            "description": "13-digit tax ID; a foreign ID is allowed (a warning is returned).",
            "type": "string",
            "maxLength": 20
          },
          "branch": {
            "description": "Branch, e.g. สำนักงานใหญ่ or 00001.",
            "type": "string",
            "maxLength": 40
          },
          "phone": {
            "description": "Phone.",
            "type": "string",
            "maxLength": 40
          },
          "email": {
            "description": "Email.",
            "type": "string",
            "maxLength": 80
          }
        },
        "additionalProperties": false
      },
      "lines": {
        "description": "Items, 1 to 50.",
        "type": "array",
        "minItems": 1,
        "maxItems": 50,
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "description": "Item description (required).",
              "type": "string",
              "maxLength": 600
            },
            "quantity": {
              "description": "Quantity, above 0, up to 4 decimals; default 1.",
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 999999999
                },
                {
                  "type": "string",
                  "pattern": "^\\d+(\\.\\d{1,4})?$"
                }
              ]
            },
            "unit": {
              "description": "Unit, e.g. ชิ้น, hour.",
              "type": "string",
              "maxLength": 20
            },
            "unitPrice": {
              "description": "Price per unit, baht.",
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^\\s*(฿\\s*)?(\\d+|\\d{1,3}(,\\d{3})+)(\\.\\d{1,2})?\\s*$"
                }
              ]
            },
            "discount": {
              "description": "Discount on this line, baht. Not with discountPercent.",
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0
                },
                {
                  "type": "string",
                  "pattern": "^\\s*(฿\\s*)?(\\d+|\\d{1,3}(,\\d{3})+)(\\.\\d{1,2})?\\s*$"
                }
              ]
            },
            "discountPercent": {
              "description": "Discount on this line, percent (0–100). Not with discount.",
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                },
                {
                  "type": "string",
                  "pattern": "^\\d+(\\.\\d{1,2})?$"
                }
              ]
            }
          },
          "required": [
            "description",
            "unitPrice"
          ],
          "additionalProperties": false
        }
      },
      "discount": {
        "description": "Discount on the whole document, baht. Not with discountPercent.",
        "anyOf": [
          {
            "type": "number",
            "minimum": 0
          },
          {
            "type": "string",
            "pattern": "^\\s*(฿\\s*)?(\\d+|\\d{1,3}(,\\d{3})+)(\\.\\d{1,2})?\\s*$"
          }
        ]
      },
      "discountPercent": {
        "description": "Discount on the whole document, percent (0–100). Not with discount.",
        "anyOf": [
          {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$"
          }
        ]
      },
      "vat": {
        "description": "VAT 7%: none, exclude (added on top) or include (in the prices); default none.",
        "type": "string",
        "enum": [
          "none",
          "exclude",
          "include"
        ]
      },
      "withholdingRate": {
        "description": "Withholding tax percent on the amount before VAT; default 0.",
        "type": "number",
        "enum": [
          0,
          1,
          2,
          3,
          5
        ]
      },
      "promptPayId": {
        "description": "Not for receipts: PromptPay ID; the page shows a QR for the net amount.",
        "type": "string",
        "maxLength": 24
      }
    },
    "required": [
      "lines"
    ],
    "additionalProperties": false
  }
}
