# Banking API

## Get Bank Accounts

Retrieve bank account list for an organization.

**Endpoint:** `POST https://api.quick.myquickapp.com/accounting/banking`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body - List Bank Accounts

```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": {
    "bank_accounts": [
      {
        "id": "bank_1",
        "name": "Main Bank Account",
        "account_number": "1234567890",
        "bank_name": "First Bank",
        "account_type": "Current",
        "currency": "ZAR",
        "opening_balance": 50000.00,
        "current_balance": 52000.00,
        "is_active": true,
        "reconciliation_status": "reconciled",
        "last_reconciliation": "2024-03-01"
      },
      {
        "id": "bank_2",
        "name": "Savings Account",
        "account_number": "0987654321",
        "bank_name": "Standard Bank",
        "account_type": "Savings",
        "currency": "ZAR",
        "opening_balance": 10000.00,
        "current_balance": 11500.00,
        "is_active": true,
        "reconciliation_status": "pending",
        "last_reconciliation": "2024-02-01"
      }
    ]
  }
}
```

---

## Get Bank Account Details

Get details for a specific bank account.

### Request Body

```json
{
  "org_id": "12345",
  "bank_account_id": "bank_1"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "bank_account": {
      "id": "bank_1",
      "name": "Main Bank Account",
      "account_number": "1234567890",
      "bank_name": "First Bank",
      "account_type": "Current",
      "currency": "ZAR",
      "opening_balance": 50000.00,
      "current_balance": 52000.00,
      "account_code": "1000",
      "is_active": true,
      "created_at": "2024-01-15T10:30:00"
    },
    "bank_statements": [
      {
        "id": "stmt_123",
        "statement_date": "2024-03-31",
        "opening_balance": 50000.00,
        "closing_balance": 52000.00,
        "total_deposits": 15000.00,
        "total_withdrawals": 13000.00,
        "status": "reconciled",
        "reconciled_at": "2024-04-01"
      }
    ]
  }
}
```

---

## Get Bank Statement Lines

Retrieve bank statement lines (transactions).

### Request Body

```json
{
  "org_id": "12345",
  "bank_account_id": "bank_1",
  "statement_id": "stmt_123",
  "date_from": "2024-03-01",
  "date_to": "2024-03-31"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "statement_lines": [
      {
        "id": "line_1",
        "date": "2024-03-10",
        "description": "Invoice INV-2024-0001",
        "reference": "INV-2024-0001",
        "amount": 1150.00,
        "type": "deposit",
        "status": "reconciled",
        "reconciled_date": "2024-04-01",
        "matched_transaction": "trans_123"
      },
      {
        "id": "line_2",
        "date": "2024-03-15",
        "description": "Payment to vendor",
        "reference": "BILL-2024-0001",
        "amount": 500.00,
        "type": "withdrawal",
        "status": "reconciled",
        "reconciled_date": "2024-04-01",
        "matched_transaction": "trans_124"
      },
      {
        "id": "line_3",
        "date": "2024-03-20",
        "description": "Bank fees",
        "reference": "",
        "amount": 25.00,
        "type": "withdrawal",
        "status": "unreconciled",
        "reconciled_date": null,
        "matched_transaction": null
      }
    ],
    "summary": {
      "total_deposits": 1150.00,
      "total_withdrawals": 525.00,
      "reconciled_count": 2,
      "unreconciled_count": 1
    }
  }
}
```

---

## Reconcile Bank Statement

Reconcile bank statement lines.

### Request Body - Reconcile Single Line

```json
{
  "org_id": "12345",
  "bank_account_id": "bank_1",
  "line_id": "line_3",
  "match_type": "invoice",
  "match_id": "50001",
  "reconciled_date": "2024-04-01"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Line reconciled successfully",
    "reconciled_line": {
      "id": "line_3",
      "status": "reconciled",
      "reconciled_date": "2024-04-01",
      "matched_transaction": "trans_125"
    }
  }
}
```

### Request Body - Reconcile Multiple Lines

```json
{
  "org_id": "12345",
  "bank_account_id": "bank_1",
  "reconciliation": [
    {
      "line_id": "line_1",
      "match_type": "invoice",
      "match_id": "50001"
    },
    {
      "line_id": "line_2",
      "match_type": "bill",
      "match_id": "50002"
    }
  ],
  "reconciled_date": "2024-04-01"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Statement reconciled successfully",
    "reconciled_lines": [
      {
        "id": "line_1",
        "status": "reconciled"
      },
      {
        "id": "line_2",
        "status": "reconciled"
      }
    ],
    "unreconciled_lines": []
  }
}
```

---

## Bank Reconciliation Report

Get bank reconciliation report.

### Request Body

```json
{
  "org_id": "12345",
  "bank_account_id": "bank_1",
  "date_from": "2024-03-01",
  "date_to": "2024-03-31",
  "include_unreconciled": true
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "reconciliation": {
      "bank_account": {
        "id": "bank_1",
        "name": "Main Bank Account"
      },
      "period": {
        "start": "2024-03-01",
        "end": "2024-03-31"
      },
      "bank_statement": {
        "opening_balance": 50000.00,
        "closing_balance": 52000.00,
        "total_deposits": 15000.00,
        "total_withdrawals": 13000.00
      },
      "book_balance": {
        "opening_balance": 50000.00,
        "closing_balance": 52000.00,
        "total_deposits": 15000.00,
        "total_withdrawals": 13000.00
      },
      "reconciliation_difference": 0.00,
      "reconciled_items": 10,
      "unreconciled_items": 2
    },
    "unreconciled_items": [
      {
        "id": "line_3",
        "date": "2024-03-20",
        "description": "Bank fees",
        "amount": 25.00,
        "type": "withdrawal"
      },
      {
        "id": "line_4",
        "date": "2024-03-25",
        "description": "Direct debit",
        "amount": 100.00,
        "type": "withdrawal"
      }
    ]
  }
}
```

---

## Create Bank Transaction

Create a bank transaction (deposit or withdrawal).

### Request Body - Deposit

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "deposit",
  "bank_account_id": "bank_1",
  "date": "2024-03-10",
  "amount": 1150.00,
  "reference": "INV-2024-0001",
  "description": "Payment from customer",
  "account_id": "acc_101",
  "attached_invoice": 50001
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Transaction created successfully",
    "transaction": {
      "id": "trans_126",
      "bank_account_id": "bank_1",
      "type": "deposit",
      "date": "2024-03-10",
      "amount": 1150.00,
      "reference": "INV-2024-0001",
      "description": "Payment from customer",
      "status": "cleared"
    }
  }
}
```

### Request Body - Withdrawal

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "withdrawal",
  "bank_account_id": "bank_1",
  "date": "2024-03-15",
  "amount": 500.00,
  "reference": "BILL-2024-0001",
  "description": "Payment to vendor",
  "account_id": "acc_201",
  "attached_bill": 50002
}
```

---

## Bank Statement Import

### Request Body - Import Statement

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "import_statement",
  "bank_account_id": "bank_1",
  "statement_date": "2024-03-31",
  "opening_balance": 50000.00,
  "closing_balance": 52000.00,
  "lines": [
    {
      "date": "2024-03-10",
      "description": "Invoice INV-2024-0001",
      "amount": 1150.00,
      "type": "deposit"
    },
    {
      "date": "2024-03-15",
      "description": "Payment to vendor",
      "amount": 500.00,
      "type": "withdrawal"
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Statement imported successfully",
    "statement_id": "stmt_124",
    "lines_imported": 2
  }
}
```

---

## Bank Account Types

| Type | Description |
|------|-------------|
| `Current` | Current/checking account |
| `Savings` | Savings account |
| `Credit` | Credit card account |
| `Loan` | Loan account |
| `Investment` | Investment account |

---

## Transaction Types

| Type | Description |
|------|-------------|
| `deposit` | Money coming in (credit) |
| `withdrawal` | Money going out (debit) |
| `transfer` | Transfer between accounts |
| `fee` | Bank fees |
| `interest` | Interest earned/paid |
