File size: 3,995 Bytes
c3a45c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
# SPDX-License-Identifier: CC-BY-4.0
# Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
title: VAT return from invoices
tiers: rule 1, procedure 2, example 3, mistakes 2
---
# VAT return from invoices

For tasks that give sales and purchase invoices and a rate table and ask for the VAT per invoice
and the return totals.

<!-- tier: 1 -->
## Rule

**The task's own files and stated rules always win over this page; use this page only for what
the task leaves open.**

1. **The request states the method: use it word for word.** Which rate applies, how net and
   gross amounts are treated, how to round, and what the totals are. The points below only
   explain the usual meaning of those sentences.
2. **The rate comes from the task's rate table**: the row for the invoice's own category whose
   validity range contains the invoice date. Read the request for whether a range's last day
   is included.
3. **A rate given in percent is divided by 100 once** before it is used as a factor.
4. **Amounts are used as they stand in the file.** Never rescale them.
5. **Net basis:** VAT = net x rate. **Gross basis:** net = gross / (1 + rate), VAT = gross -
   net.
6. **Output VAT** is the VAT on sales; **input VAT** is the VAT on purchases. **Payable =
   output - input**, negative when input is larger.
7. **Every invoice gets a line**, also one whose VAT is 0.00.
8. If an invoice lacks what the method needs, see
   `/knowledge/agent-workflow/missing-information.md`.

<!-- tier: 2 -->
## Procedure

1. Read the request's method sentence and the answer shape. Read the rate table and the
   invoices completely.
2. Write one script file that, for each invoice: finds the table row by category and date;
   turns the percent into a factor; computes the VAT by the invoice's basis; rounds as the
   request says, with exact decimals.
3. In the same script: sum the VAT of sales into output VAT and of purchases into input VAT;
   payable = output - input; print every line and the three totals.
4. Estimate one line by hand to catch a slip of rate or scale. If the script's line is a
   hundred times off, the slip is in the script.
5. Let the script write the answer in the request's shape: a list of lines if the shape shows a
   list, numbers where it shows numbers.
6. Check once: number of lines = number of invoices; output + input = sum of all lines; the
   sign of payable. Then finish.

<!-- tier: 3 -->
## Worked example

Illustration only, with invented data. Your task's data differs: take no fact, count or
expected result from this example.

Rate table (percent): `general` 20 throughout; `print` 10 up to and including 30 June and 5
from 1 July; `export` 0. The request says: half up to 0.01; gross means net = gross / (1 +
rate).

| Invoice | Date | Direction | Category | Amount | Basis | Rate | VAT |
|---|---|---|---|---|---|---|---|
| A | 30 June | sale | print | 300.00 | net | 10 | 30.00 |
| B | 1 July | sale | print | 300.00 | net | 5 | 15.00 |
| C | 3 July | purchase | general | 600.00 | gross | 20 | 100.00 |
| D | 5 July | sale | export | 950.00 | net | 0 | 0.00 |
| E | 9 July | purchase | print | 210.00 | gross | 5 | 10.00 |

A and B are one day apart; the rate changed between them. C: net = 600.00 / 1.20 = 500.00, VAT
= 100.00 (not 600.00 x 0.20). E: net = 210.00 / 1.05 = 200.00, VAT = 10.00.

Output VAT = 30.00 + 15.00 + 0.00 = 45.00. Input VAT = 100.00 + 10.00 = 110.00.
Payable = 45.00 - 110.00 = -65.00.

<!-- tier: 2 -->
## Common mistakes

- Replacing the request's stated method by another, or debating it at length.
- Using the wrong side of a rate change on its boundary dates.
- Dividing the percent by 100 twice, or deciding the amounts are in another unit.
- Computing VAT on a gross amount as gross x rate.
- Counting a purchase in output VAT, or leaving an invoice out of a total.
- Writing payable as a positive number when input VAT is larger.
- Writing the lines as an object keyed by invoice where the shape shows a list.