# Quotation API

## Get Quotations

Retrieve quotations for an organization.

**Endpoint:** `POST https://api.quick.myquickapp.com/sales/orderdetail/`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body - List Quotations

```json
{
  "org_id": "12345",
  "userid": "123"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "*",
    "Access-Control-Allow-Methods": "GET,POST,OPTIONS"
  },
  "body": {
    "quotations": [
      {
        "id": 40001,
        "orgid": 12345,
        "quotation_number": "QUO-2024-0001",
        "quotation_type": "quotation",
        "partner": {
          "id": 917013,
          "partnername": "Customer Name",
          "display_name": "Customer Name"
        },
        "quotation_status": "draft",
        "quotation_date": "2024-03-10T10:00:00",
        "subtotal": 1000.00,
        "tax_amount": 150.00,
        "quotation_total": 1150.00,
        "valid_until": "2024-04-09",
        "comments": "Quotation for services",
        "created_at": "2024-03-10T10:30:00"
      }
    ],
    "pagination": {
      "page_number": 1,
      "page_size": 25,
      "total_items": 1,
      "total_pages": 1,
      "has_next": false,
      "has_previous": false
    }
  }
}
```

---

## Create Quotation

Create a new quotation.

**Endpoint:** `POST https://api.quick.myquickapp.com/sales/addline`

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "create_quotation",
  "partner": "917013",
  "quotation_number": "QUO-2024-0001",
  "quotation_type": "quotation",
  "quotation_status": "draft",
  "quotation_date": "2024-03-10T10:00:00",
  "valid_until": "2024-04-09",
  "comments": "Quotation for services",
  "quotation_reference": "RFQ-123",
  "line_items": [
    {
      "product_id": 201,
      "product_name": "Product Name",
      "description": "Product description",
      "quantity": 10,
      "price": 100.00,
      "discount": 0,
      "tax_rate": 15.0,
      "tax_included": true,
      "subtotal": 1000.00,
      "tax_amount": 150.00,
      "total": 1150.00
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Quotation created successfully",
    "quotation": {
      "id": 40001,
      "orgid": 12345,
      "quotation_number": "QUO-2024-0001",
      "quotation_type": "quotation",
      "partner": "917013",
      "quotation_status": "draft",
      "quotation_date": "2024-03-10T10:00:00",
      "valid_until": "2024-04-09",
      "comments": "Quotation for services",
      "subtotal": 1000.00,
      "tax_amount": 150.00,
      "quotation_total": 1150.00
    }
  }
}
```

---

## Add Quotation Line

Add a line item to an existing quotation.

**Endpoint:** `POST https://api.quick.myquickapp.com/sales/addline`

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "add_line",
  "quotation_id": 40001,
  "product_id": 202,
  "product_name": "Another Product",
  "description": "Another description",
  "quantity": 5,
  "price": 50.00,
  "discount": 10,
  "tax_rate": 15.0,
  "tax_included": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Line item added successfully",
    "line_item": {
      "id": 50001,
      "quotation_id": 40001,
      "product_id": 202,
      "description": "Another description",
      "quantity": 5,
      "price": 50.00,
      "discount": 10,
      "tax_rate": 15.0,
      "subtotal": 225.00,
      "tax_amount": 33.75,
      "total": 258.75
    }
  }
}
```

---

## Edit Quotation

Update an existing quotation.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "edit_quotation",
  "quotation_id": 40001,
  "quotation_number": "QUO-2024-0001",
  "quotation_status": "sent",
  "valid_until": "2024-04-15",
  "comments": "Updated quotation for services",
  "quotation_reference": "RFQ-123"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Quotation updated successfully",
    "quotation": {
      "id": 40001,
      "quotation_number": "QUO-2024-0001",
      "quotation_status": "sent",
      "valid_until": "2024-04-15",
      "comments": "Updated quotation for services"
    }
  }
}
```

---

## Convert Quotation to Invoice

Convert a quotation to an invoice.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "convert_to_invoice",
  "quotation_id": 40001,
  "invoicetype": "invoiceout"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Quotation converted to invoice successfully",
    "invoice": {
      "id": 50001,
      "orgid": 12345,
      "invoicenumber": "INV-2024-0002",
      "invoicetype": "invoiceout",
      "partner": "917013",
      "invoicestatus": "draft",
      "subtotal": 1150.00,
      "tax_amount": 172.50,
      "invoicetotal": 1322.50
    }
  }
}
```

---

## Cancel Quotation

Cancel a quotation.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "cancel_quotation",
  "quotation_id": 40001
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Quotation cancelled successfully"
  }
}
```

---

## Quotation Status

| Status | Description |
|--------|-------------|
| `draft` | Quotation is being created |
| `sent` | Quotation has been sent to customer |
| `accepted` | Quotation has been accepted |
| `converted` | Quotation has been converted to invoice |
| `cancelled` | Quotation has been cancelled |
| `expired` | Quotation has expired |

---

## Quotation Types

| Type | Description |
|------|-------------|
| `quotation` | Standard quotation |
| `proforma` | Proforma invoice |
| `estimate` | Estimate |

---

## Quotation Fields

### Header Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `partner` | string | Yes | Partner ID |
| `quotation_number` | string | No | Quotation number (auto-generated if empty) |
| `quotation_type` | string | Yes | `quotation`, `proforma`, or `estimate` |
| `quotation_status` | string | Yes | `draft`, `sent`, `accepted`, etc. |
| `quotation_date` | datetime | Yes | Date of quotation |
| `valid_until` | date | Yes | Expiration date |
| `comments` | string | No | Notes |
| `quotation_reference` | string | No | Reference number |

### Line Item Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `product_id` | string | Yes | Product ID |
| `quantity` | decimal | Yes | Quantity |
| `price` | decimal | Yes | Unit price |
| `discount` | decimal | No | Discount percentage |
| `tax_rate` | decimal | Yes | Tax rate |
| `tax_included` | boolean | Yes | Whether tax is included |

---

## Search Quotations

### Search by Number

```json
{
  "org_id": "12345",
  "search_key": "QUO-2024"
}
```

### Search by Customer

```json
{
  "org_id": "12345",
  "search_key": "Customer Name"
}
```

---

## Quotation Totals

### Get Quotation Total

```json
{
  "org_id": "12345",
  "quotation_id": 40001,
  "calculate_total": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "quotation_id": 40001,
    "subtotal": 1150.00,
    "tax_amount": 172.50,
    "discount_total": 0,
    "quotation_total": 1322.50,
    "currency": "ZAR"
  }
}
```
