- name
- ledger_error_correction
- tier
- 3
- task
- T24
- description
- This skill corrects ledger errors by posting correction vouchers. Keywords include "error correction", "feilretting", "korrektur", "correction d'erreurs", "corrección de errores", "Fehlerbehebung", "wrong account", "duplicate voucher", "missing VAT", "incorrect amount", "errors in the general ledger".
# Ledger Error Correction
Post correction vouchers based on ledger posting data. 3 calls.
## Turn 1: 2 parallel GETs
```
GET /ledger/account?number=<all_accounts_from_prompt>,1920,2400,2710&fields=id,number,name
GET /ledger/posting?dateFrom=2026-01-01&dateTo=2026-02-28&fields=account(number),amount,amountGross,voucher(id),date,supplier(id),customer(id)&count=500
```
ONE call for ALL accounts (comma-separated). Always include 1920, 2400, and 2710.
CRITICAL: Request BOTH `amount` AND `amountGross` fields. For postings with vatType, amount=NET but amountGross=GROSS. You need both to decide whether to use vatType on corrections.
NOTE: The posting response can be large (100+ postings). If truncated, you still have enough data — focus on finding the 4 error vouchers by matching account numbers and amounts from the prompt.
## MANDATORY ANALYSIS (before Turn 2)
After receiving the posting data, you MUST analyze BEFORE making corrections. For EACH of the 4 errors:
1. **Find the original voucher**: scan postings for the error account + approximate amount
2. **List ALL postings on that voucher** (same voucher ID): expense, VAT (2710?), counter (1920/2400?)
3. **Check amountGross vs amount on the expense posting**: if amountGross > amount, the original used auto-VAT (vatType). The prompt amounts are always GROSS.
4. **Write the exact correction amounts** you will use
CRITICAL: The prompt gives GROSS amounts. Expense postings on the ledger show GROSS in `amountGross` and NET in `amount`. Use `amountGross` values from the posting data.
## Turn 2: POST ONE combined correction voucher (1 call)
Combine ALL 4 corrections into a SINGLE voucher with sequential row numbers.
IMPORTANT: Use `amountGross` and `amountGrossCurrency` on every posting. Do NOT use `amount` (it is read-only and will be ignored → zero postings).
```json
POST /ledger/voucher
{
"date": "<today>",
"description": "Korreksjoner",
"postings": [...]
}
```
### Error 1: Wrong account
**FIRST** check if the original expense posting had VAT: is there a 2710 posting on the same voucher? Is amountGross > amount on the expense?
**If VAT was applied** (amountGross > amount, 2710 exists on voucher): use vatType with GROSS amount:
```json
{"date": "<today>", "account": {"id": <correct_acct_id>}, "amountGross": <GROSS_amount>, "amountGrossCurrency": <GROSS_amount>, "vatType": {"id": 1}, "description": "Korreksjon: feil konto", "row": 1},
{"date": "<today>", "account": {"id": <wrong_acct_id>}, "amountGross": -<GROSS_amount>, "amountGrossCurrency": -<GROSS_amount>, "vatType": {"id": 1}, "description": "Korreksjon: feil konto", "row": 2}
```
**If NO VAT** (amountGross = amount, no 2710 on voucher): do NOT use vatType, use the amount directly:
```json
{"date": "<today>", "account": {"id": <correct_acct_id>}, "amountGross": <amount>, "amountGrossCurrency": <amount>, "description": "Korreksjon: feil konto", "row": 1},
{"date": "<today>", "account": {"id": <wrong_acct_id>}, "amountGross": -<amount>, "amountGrossCurrency": -<amount>, "description": "Korreksjon: feil konto", "row": 2}
```
### Error 2: Duplicate voucher
**FIRST** check VAT on the original (same as Error 1).
**If VAT** (2710 on same voucher): use vatType with GROSS amount:
```json
{"date": "<today>", "account": {"id": <expense_id>}, "amountGross": -<GROSS_from_prompt>, "amountGrossCurrency": -<GROSS_from_prompt>, "vatType": {"id": 1}, "description": "Korreksjon: duplikat", "row": N},
{"date": "<today>", "account": {"id": <counter_id>}, "amountGross": <GROSS_from_prompt>, "amountGrossCurrency": <GROSS_from_prompt>, "description": "Korreksjon: duplikat", "row": N+1}
```
**If NO VAT**: do NOT use vatType:
```json
{"date": "<today>", "account": {"id": <expense_id>}, "amountGross": -<amount>, "amountGrossCurrency": -<amount>, "description": "Korreksjon: duplikat", "row": N},
{"date": "<today>", "account": {"id": <counter_id>}, "amountGross": <amount>, "amountGrossCurrency": <amount>, "description": "Korreksjon: duplikat", "row": N+1}
```
### Error 3: Missing VAT line (NO vatType — direct posting)
VAT = amount_excl_from_prompt × 0.25. Credit the counter-account from the original posting.
```json
{"date": "<today>", "account": {"id": <vat_2710_id>}, "amountGross": <vat_amount>, "amountGrossCurrency": <vat_amount>, "description": "Korreksjon: manglende MVA", "row": N},
{"date": "<today>", "account": {"id": <counter_id>}, "amountGross": -<vat_amount>, "amountGrossCurrency": -<vat_amount>, "description": "Korreksjon: manglende MVA", "row": N+1}
```
If counter is 2400, add `"supplier": {"id": <from_original>}`.
### Error 4: Incorrect amount
gross_excess = prompt_posted_gross - prompt_correct_gross. **FIRST** check VAT on the original (same as above).
**If VAT** (2710 on same voucher): use vatType with GROSS excess:
```json
{"date": "<today>", "account": {"id": <expense_id>}, "amountGross": -<gross_excess>, "amountGrossCurrency": -<gross_excess>, "vatType": {"id": 1}, "description": "Korreksjon: feil beløp", "row": N},
{"date": "<today>", "account": {"id": <counter_id>}, "amountGross": <gross_excess>, "amountGrossCurrency": <gross_excess>, "description": "Korreksjon: feil beløp", "row": N+1}
```
**If NO VAT** (amountGross = amount, no 2710): do NOT use vatType:
```json
{"date": "<today>", "account": {"id": <expense_id>}, "amountGross": -<excess>, "amountGrossCurrency": -<excess>, "description": "Korreksjon: feil beløp", "row": N},
{"date": "<today>", "account": {"id": <counter_id>}, "amountGross": <excess>, "amountGrossCurrency": <excess>, "description": "Korreksjon: feil beløp", "row": N+1}
```
**3 calls, 0 errors.**
## STRICT RULES
- EVERY posting MUST use `amountGross` AND `amountGrossCurrency`. NEVER use `amount` (read-only, ignored).
- **VAT check is MANDATORY for every error**: check if 2710 exists on the same voucher AND amountGross > amount on the expense posting. Only use `vatType: {"id": 1}` if BOTH conditions are true. Some accounts (e.g. 7100) are locked to VAT code 0 and will 422 if you use vatType 1.
- If original HAD VAT → use vatType 1 with GROSS amounts on expense postings.
- If original had NO VAT → do NOT use vatType, post amounts directly.
- Counter-account corrections (1920, 2400) must NEVER use vatType — post amounts directly.
- Error 3 (missing VAT) is special: post directly to 2710 and counter WITHOUT vatType.
- Account 2400 postings REQUIRE `"supplier": {"id": <from_original_posting>}` — without it: 422
- Account 1500 postings REQUIRE `"customer": {"id": <from_original_posting>}` — without it: 422
- Find supplier/customer IDs from the GET /ledger/posting response (same voucher as the error)
- Correction date: today's date
- Row numbers: sequential across all corrections (1, 2, 3, 4, 5, ...)
- All corrections in ONE POST /ledger/voucher. Do NOT make separate POST calls.
- The prompt amounts are GROSS. Use them with vatType ONLY if the original had VAT (2710 on voucher).
在 GitHub 查看