# Journal API

## Get Journals

Retrieve journal list for an organization.

**Endpoint:** `POST https://api.quick.myquickapp.com/accounting/journals/entries`

### Request Headers

```
Authorization: Bearer {api_key}
Content-Type: application/json
language: en
```

### Request Body - List Journals

```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": {
    "journals": [
      {
        "id": "journal_1",
        "name": "Sales Journal",
        "code": "SAL",
        "type": "Sales",
        "active": true,
        "orgid": 12345,
        "description": "Journal for sales invoices"
      },
      {
        "id": "journal_2",
        "name": "Purchase Journal",
        "code": "PUR",
        "type": "Purchase",
        "active": true,
        "orgid": 12345,
        "description": "Journal for purchase bills"
      },
      {
        "id": "journal_3",
        "name": "Cash Journal",
        "code": "CASH",
        "type": "Cash",
        "active": true,
        "orgid": 12345,
        "description": "Journal for cash transactions"
      },
      {
        "id": "journal_4",
        "name": "Bank Journal",
        "code": "BANK",
        "type": "Bank",
        "active": true,
        "orgid": 12345,
        "description": "Journal for bank transactions"
      }
    ]
  }
}
```

---

## Get Journal Details

Get details for a specific journal.

### Request Body

```json
{
  "org_id": "12345",
  "journal_id": "journal_1"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "journal": {
      "id": "journal_1",
      "name": "Sales Journal",
      "code": "SAL",
      "type": "Sales",
      "active": true,
      "default_account": "sales_101",
      "description": "Journal for sales invoices",
      "created_at": "2024-01-15T10:30:00"
    },
    "journal_items": [
      {
        "id": 70001,
        "journal_id": "journal_1",
        "date": "2024-03-10",
        "description": "Invoice INV-2024-0001",
        "account_id": "acc_101",
        "account_code": "1000",
        "account_name": "Bank Account",
        "debit": 0,
        "credit": 1150.00,
        "attached_invoice": 50001
      }
    ]
  }
}
```

---

## Create Journal Entry

Create a new manual journal entry.

**Endpoint:** `POST https://api.quick.myquickapp.com/accounting/submit-coa/`

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "create_journal",
  "journal_id": "journal_3",
  "journal_date": "2024-03-10",
  "narration": "Monthly expenses payment",
  "line_items": [
    {
      "account_id": "acc_401",
      "account_code": "4000",
      "account_name": "Cost of Goods Sold",
      "debit": 5000.00,
      "credit": 0
    },
    {
      "account_id": "acc_101",
      "account_code": "1000",
      "account_name": "Bank Account",
      "debit": 0,
      "credit": 5000.00
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Journal entry created successfully",
    "journal_entry": {
      "id": "entry_123",
      "journal_id": "journal_3",
      "journal_date": "2024-03-10",
      "narration": "Monthly expenses payment",
      "status": "posted",
      "created_at": "2024-03-10T14:00:00"
    },
    "journal_items": [
      {
        "id": 70003,
        "journal_entry_id": "entry_123",
        "account_id": "acc_401",
        "debit": 5000.00,
        "credit": 0
      },
      {
        "id": 70004,
        "journal_entry_id": "entry_123",
        "account_id": "acc_101",
        "debit": 0,
        "credit": 5000.00
      }
    ],
    "total_debits": 5000.00,
    "total_credits": 5000.00
  }
}
```

---

## Edit Journal Entry

Update an existing journal entry.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "edit_journal",
  "journal_entry_id": "entry_123",
  "journal_date": "2024-03-11",
  "narration": "Updated monthly expenses payment",
  "line_items": [
    {
      "account_id": "acc_401",
      "account_code": "4000",
      "account_name": "Cost of Goods Sold",
      "debit": 6000.00,
      "credit": 0
    },
    {
      "account_id": "acc_101",
      "account_code": "1000",
      "account_name": "Bank Account",
      "debit": 0,
      "credit": 6000.00
    }
  ]
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Journal entry updated successfully",
    "journal_entry": {
      "id": "entry_123",
      "journal_date": "2024-03-11",
      "narration": "Updated monthly expenses payment",
      "updated_at": "2024-03-10T15:00:00"
    },
    "total_debits": 6000.00,
    "total_credits": 6000.00
  }
}
```

---

## Delete Journal Entry

Delete a journal entry.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "delete_journal",
  "journal_entry_id": "entry_123"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Journal entry deleted successfully"
  }
}
```

---

## Post Journal Entry

Post a journal entry to the general ledger.

### Request Body

```json
{
  "org_id": "12345",
  "userid": "123",
  "action": "post_journal",
  "journal_entry_id": "entry_123"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "message": "Journal entry posted successfully",
    "journal_entry": {
      "id": "entry_123",
      "status": "posted",
      "posted_at": "2024-03-10T16:00:00"
    }
  }
}
```

---

## Journal Types

| Type | Description | Default Code |
|------|-------------|--------------|
| `Sales` | Sales invoices | SAL |
| `Purchase` | Purchase bills | PUR |
| `Cash` | Cash transactions | CASH |
| `Bank` | Bank transactions | BANK |
| `Journal` | General journal | JNL |
| `Sales Return` | Sales returns | SRT |
| `Purchase Return` | Purchase returns | PRT |

---

## Journal Entry Fields

### Header Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `journal_id` | string | Yes | Journal ID |
| `journal_date` | date | Yes | Date of entry |
| `narration` | string | No | Description |
| `reference` | string | No | Reference number |

### Line Item Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `account_id` | string | Yes | Account ID |
| `debit` | decimal | Conditional | Debit amount (if credit is 0) |
| `credit` | decimal | Conditional | Credit amount (if debit is 0) |
| `description` | string | No | Line description |
| `attached_invoice` | string | No | Attached invoice ID |

---

## Journal Entries by Date Range

### Request Body

```json
{
  "org_id": "12345",
  "date_from": "2024-03-01",
  "date_to": "2024-03-31",
  "journal_id": "journal_1"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "journal_entries": [
      {
        "id": "entry_123",
        "journal_id": "journal_1",
        "journal_date": "2024-03-10",
        "narration": "Monthly expenses payment",
        "status": "posted",
        "total_debits": 5000.00,
        "total_credits": 5000.00
      }
    ],
    "summary": {
      "total_debits": 5000.00,
      "total_credits": 5000.00,
      "entry_count": 1
    }
  }
}
```

---

## Journal Summary by Account

### Request Body

```json
{
  "org_id": "12345",
  "account_id": "acc_101",
  "date_from": "2024-01-01",
  "date_to": "2024-12-31"
}
```

### Response

```json
{
  "statusCode": 200,
  "headers": {...},
  "body": {
    "account": {
      "id": "acc_101",
      "code": "1000",
      "name": "Bank Account"
    },
    "opening_balance": 45000.00,
    "total_debits": 15000.00,
    "total_credits": 10000.00,
    "closing_balance": 50000.00,
    "journal_items": [
      {
        "id": 70001,
        "date": "2024-03-10",
        "journal": "Sales Journal",
        "description": "Invoice INV-2024-0001",
        "debit": 0,
        "credit": 1150.00,
        "balance": 48850.00
      }
    ]
  }
}
```
