# Mobile API (Step 1)

This folder contains API endpoints for your React Native app.

## Files

- `config.php` - API settings, CORS headers, JSON helpers.
- `db.php` - MySQL connection.
- `auth.php` - Token generation and validation.
- `login.php` - Login endpoint (POST).
- `sales_report.php` - Sales report endpoint (GET, Bearer token required).

## Important VPS setup

1. Upload the `mobile_api` folder to your VPS project root.
2. Edit `mobile_api/config.php`:
   - Change `MOBILE_API_SECRET` to a strong random secret.
3. Edit `mobile_api/db.php` with your VPS database credentials if needed.

## Endpoint 1: Login

- URL: `https://your-domain.com/mobile_api/login.php`
- Method: `POST`
- Body (JSON):

```json
{
  "login": "admin",
  "password": "your_password"
}
```

Login can use username or email in `login`.

## Endpoint 2: Sales Report

- URL: `https://your-domain.com/mobile_api/sales_report.php`
- Method: `GET`
- Header:
  - `Authorization: Bearer {token_from_login}`

### Query params

- `start_date` (required format `YYYY-MM-DD`, default today)
- `end_date` (required format `YYYY-MM-DD`, default today)
- `branch_id` (optional, default `0` = all)
- `store_id` (optional, default `0` = all)
- `limit` (optional, 1-200, default 100)

### Example

`https://your-domain.com/mobile_api/sales_report.php?start_date=2026-05-01&end_date=2026-05-05&branch_id=1&store_id=1&limit=50`

## Quotations (mobile create / manage)

All quotation endpoints require `Authorization: Bearer {token}`.

### Lookup items

- `GET /mobile_api/quotation_lookup.php?resource=items&search=tea&category_id=0&limit=100`

### Lookup customers

- `GET /mobile_api/quotation_lookup.php?resource=customers&search=ali&page=1&limit=30`

### List quotations

- `GET /mobile_api/quotations.php?store_id=1&status=draft&search=&limit=50&offset=0`

### Quotation detail

- `GET /mobile_api/quotations.php?id=8&store_id=1`

### Create quotation

- `POST /mobile_api/quotation_write.php`

```json
{
  "action": "create",
  "store_id": 1,
  "customer_id": 18,
  "customer_name": "customer 11",
  "subtotal": 500,
  "tax_amount": 90,
  "discount_amount": 0,
  "net_amount": 590,
  "remarks": "",
  "items": [
    {
      "item_id": 1,
      "item_name": "test",
      "quantity": 1,
      "unit_price": 500,
      "total_price": 590,
      "tax_rate": 18,
      "line_discount_percent": 0,
      "remarks": ""
    }
  ]
}
```

### Update quotation

Same body as create with `"action": "update"` and `"quotation_id": 8`. Only the creator can update; converted quotations cannot be edited.

### Update status

```json
{
  "action": "update_status",
  "quotation_id": 8,
  "store_id": 1,
  "status": "sent"
}
```

### Delete quotation

```json
{
  "action": "delete",
  "quotation_id": 8,
  "store_id": 1
}
```

