# Stock Takes API

## Get Stock Items

Retrieve stock levels for all products.

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/ops/getdata`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body - List Stock

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "list",
  "page_size": 25,
  "page_number": 1
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "*",
    "Access-Control-Allow-Methods": "GET,POST,OPTIONS"
  },
  "body": {
    "stock_items": [
      {
        "id": 101,
        "product_id": 201,
        "product_name": "Product Name",
        "sku": "PROD-001",
        "current_stock": 100,
        "min_stock_level": 20,
        "max_stock_level": 500,
        "warehouse_id": "wh_1",
        "location_id": "loc_1",
        "last_stock_check": "2024-03-10T10:00:00"
      }
    ],
    "pagination": {
      "page_number": 1,
      "page_size": 25,
      "total_items": 100,
      "total_pages": 4,
      "has_next": true,
      "has_previous": false
    }
  }
}
```

---

## Get Stock Details by Product

Get detailed stock information for a specific product.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_details",
  "product_id": 201,
  "include_warehouses": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "product_id": 201,
    "product_name": "Product Name",
    "sku": "PROD-001",
    "current_stock": 100,
    "min_stock_level": 20,
    "max_stock_level": 500,
    "stock_details": [
      {
        "warehouse_id": "wh_1",
        "warehouse_name": "Main Warehouse",
        "location_id": "loc_1",
        "location_name": "Aisle 1",
        "stock_quantity": 60
      },
      {
        "warehouse_id": "wh_2",
        "warehouse_name": "Secondary Warehouse",
        "location_id": "loc_2",
        "location_name": "Aisle 2",
        "stock_quantity": 40
      }
    ],
    "last_stock_check": "2024-03-10T10:00:00"
  }
}
```

---

## Create Stock Take

Create a new stock take (physical count).

**Endpoint:** `POST https://api.quick.myquickapp.com/inventory/ops/getdata`

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_take",
  "take_name": "March 2024 Stock Take",
  "description": "Quarterly physical count",
  "stock_items": [
    {
      "product_id": 201,
      "product_name": "Product Name",
      "sku": "PROD-001",
      "physical_count": 95,
      "previous_stock": 100,
      "warehouse_id": "wh_1",
      "location_id": "loc_1"
    },
    {
      "product_id": 202,
      "product_name": "Another Product",
      "sku": "PROD-002",
      "physical_count": 50,
      "previous_stock": 50,
      "warehouse_id": "wh_1",
      "location_id": "loc_2"
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock take created successfully",
    "stock_take_id": "take_12345",
    "stock_move_id": "move_12345",
    "details": [
      {
        "product_id": 201,
        "product_name": "Product Name",
        "sku": "PROD-001",
        "physical_count": 95,
        "previous_stock": 100,
        "adjustment": -5,
        "location": "Main Warehouse - Aisle 1"
      }
    ]
  }
}
```

---

## Stock Adjustment

Adjust stock levels for one or more products.

### Request Body - Single Product

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_adjustment",
  "product_id": 201,
  "qty_locations": {
    "loc_1": 95
  },
  "adjustment_type": "decrease",
  "reference": "Stock count correction",
  "notes": "Adjusted based on physical count"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock adjusted successfully",
    "stock_move_id": "move_12346",
    "details": [
      {
        "location_id": "loc_1",
        "warehouse_id": "wh_1",
        "warehouse_name": "Main Warehouse",
        "previous_stock": 100,
        "new_stock": 95,
        "change": -5,
        "adjustment_type": "decrease"
      }
    ]
  }
}
```

### Request Body - Multiple Products

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_adjustment",
  "stock_items": [
    {
      "product_id": 201,
      "qty_locations": {
        "loc_1": 95
      },
      "adjustment_type": "decrease"
    },
    {
      "product_id": 202,
      "qty_locations": {
        "loc_2": 55
      },
      "adjustment_type": "increase"
    }
  ],
  "reference": "Monthly stock adjustment",
  "notes": "Adjusted all products based on physical count"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock adjusted successfully",
    "stock_move_id": "move_12347",
    "details": [
      {
        "product_id": 201,
        "product_name": "Product Name",
        "sku": "PROD-001",
        "adjustments": [
          {
            "location_id": "loc_1",
            "previous_stock": 100,
            "new_stock": 95,
            "change": -5,
            "adjustment_type": "decrease"
          }
        ]
      },
      {
        "product_id": 202,
        "product_name": "Another Product",
        "sku": "PROD-002",
        "adjustments": [
          {
            "location_id": "loc_2",
            "previous_stock": 50,
            "new_stock": 55,
            "change": 5,
            "adjustment_type": "increase"
          }
        ]
      }
    ]
  }
}
```

---

## Stock Transfer

Transfer stock between locations or warehouses.

### Request Body - Transfer Between Locations

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_transfer",
  "product_id": 201,
  "from_location_id": "loc_1",
  "to_location_id": "loc_2",
  "quantity": 10,
  "reference": "Transfer between locations",
  "notes": "Transferred 10 units to location 2"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock transferred successfully",
    "stock_move_id": "move_12348",
    "details": {
      "product_id": 201,
      "from_location": "Main Warehouse - Aisle 1",
      "to_location": "Main Warehouse - Aisle 2",
      "quantity": 10,
      "from_new_stock": 85,
      "to_new_stock": 45
    }
  }
}
```

### Request Body - Transfer Between Warehouses

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_transfer",
  "product_id": 201,
  "from_warehouse_id": "wh_1",
  "to_warehouse_id": "wh_2",
  "from_location_id": "loc_1",
  "to_location_id": "loc_2",
  "quantity": 20,
  "reference": "Inter-warehouse transfer",
  "notes": "Transferred stock between warehouses"
}
```

---

## Low Stock Alerts

Get products with stock below minimum level.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "low_stock",
  "include_warehouse_details": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "low_stock_items": [
      {
        "product_id": 201,
        "product_name": "Product Name",
        "sku": "PROD-001",
        "current_stock": 15,
        "min_stock_level": 20,
        "stock_deficit": 5,
        "warehouses": [
          {
            "warehouse_id": "wh_1",
            "warehouse_name": "Main Warehouse",
            "location_id": "loc_1",
            "stock_quantity": 15
          }
        ]
      }
    ],
    "total_low_stock_items": 1
  }
}
```

---

## Reorder Rules

### Create Reorder Rule

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "reorder_rule",
  "product_id": 201,
  "min_stock_level": 20,
  "max_stock_level": 100,
  "reorder_quantity": 50,
  "reorder_type": "automatic",
  "warehouse_id": "wh_1"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Reorder rule created successfully",
    "reorder_rule": {
      "id": "rule_123",
      "product_id": 201,
      "min_stock_level": 20,
      "max_stock_level": 100,
      "reorder_quantity": 50,
      "reorder_type": "automatic",
      "warehouse_id": "wh_1"
    }
  }
}
```

### Edit Reorder Rule

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "reorder_rule",
  "rule_id": "rule_123",
  "min_stock_level": 25,
  "max_stock_level": 120,
  "reorder_quantity": 60
}
```

---

## Stock Move History

Get stock movement history for a product.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_history",
  "product_id": 201,
  "date_from": "2024-03-01",
  "date_to": "2024-03-31",
  "page_size": 25,
  "page_number": 1
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "stock_history": [
      {
        "move_id": 12345,
        "move_type": "invoice",
        "document_number": "INV-2024-0001",
        "product_id": 201,
        "product_name": "Product Name",
        "quantity": 10,
        "move_direction": "out",
        "from_location": "Main Warehouse - Aisle 1",
        "to_location": "",
        "date": "2024-03-10T10:00:00",
        "status": "completed"
      },
      {
        "move_id": 12346,
        "move_type": "adjustment",
        "document_number": "ADJ-001",
        "product_id": 201,
        "product_name": "Product Name",
        "quantity": -5,
        "move_direction": "out",
        "from_location": "Main Warehouse - Aisle 1",
        "to_location": "",
        "date": "2024-03-15T11:00:00",
        "status": "completed"
      }
    ],
    "pagination": {
      "page_number": 1,
      "page_size": 25,
      "total_items": 2,
      "total_pages": 1,
      "has_next": false,
      "has_previous": false
    }
  }
}
```

---

## Stock Take Templates

### Create Stock Take Template

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "stock_take_template",
  "template_name": "Monthly Stock Take",
  "description": "Standard monthly stock take",
  "frequency": "monthly",
  "next_run_date": "2024-04-01",
  "stock_items": [
    {
      "product_id": 201,
      "warehouse_id": "wh_1",
      "location_id": "loc_1"
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Stock take template created successfully",
    "template_id": "temp_123"
  }
}
```
