;doc: csv: improve Setting amounts

This commit is contained in:
Simon Michael 2023-01-20 09:24:31 -10:00
parent ac7b59bcfa
commit 3f558596ec

View File

@ -3494,11 +3494,11 @@ various amount-setting situations:
1. **If the amount is in a single CSV field:**\ 1. **If the amount is in a single CSV field:**\
a. **If its sign indicates direction of flow:**\ a. **If its sign indicates direction of flow:**\
Assign it to `amountN`, to set the Nth posting's amount. N is usually 1 or 2 but can go up to 99. Assign it to `amountN`, to set the Nth posting's amount.
(Or you can use numberless `amount` if you want the extra effects of that form.) N is usually 1 or 2 but can go up to 99.
b. **If its sign is always the same, and another field indicates direction:**\ b. **If another field indicates direction of flow:**\
Use one or more conditional rules to set the appropriate sign. Eg: Use one or more conditional rules to set the appropriate amount sign. Eg:
```rules ```rules
# assume a withdrawal unless Type contains "deposit": # assume a withdrawal unless Type contains "deposit":
amount1 -%Amount amount1 -%Amount
@ -3509,11 +3509,11 @@ various amount-setting situations:
2. **If the amount is in one of two CSV fields (eg Debit and Credit):**\ 2. **If the amount is in one of two CSV fields (eg Debit and Credit):**\
a. **If both fields are unsigned:**\ a. **If both fields are unsigned:**\
Assign to `amountN-in` and `amountN-out`. Assign the fields to `amountN-in` and `amountN-out`.
This sets posting N's amount to whichever of these has a non-zero value, This sets posting N's amount to whichever of these has a non-zero value.
and negates the "-out" value. If it's the -out value, the amount will be negated.
b. **If either field is signed (can contain a minus sign):**\ b. **If either field is signed:**\
Use a [conditional rule](#if-block) to flip the sign when needed. Use a [conditional rule](#if-block) to flip the sign when needed.
Eg below, the -out value already has a minus sign so we undo hledger's automatic Eg below, the -out value already has a minus sign so we undo hledger's automatic
negating by [negating once more](#amount-signs) negating by [negating once more](#amount-signs)
@ -3541,10 +3541,10 @@ various amount-setting situations:
3. **If you want posting 2's amount converted to cost:**\ 3. **If you want posting 2's amount converted to cost:**\
Use the unnumbered `amount` (or `amount-in` and `amount-out`) syntax. Use the unnumbered `amount` (or `amount-in` and `amount-out`) syntax.
4. **If the CSV has the balance instead of the transaction amount:**\ 4. **If the CSV has only balance amounts, not transaction amounts:**\
Assign to `balanceN`, which sets posting N's amount indirectly via a Assign to `balanceN`, to set a [balance assignment](#balance-assignments) on the Nth posting,
[balance assignment](#balance-assignments). causing the posting's amount to be calculated automatically.
(Old syntax: `balance`, equivalent to `balance1`.) `balance` with no number is equivalent to `balance1`.
In this situation hledger is more likely to guess the wrong default account name, In this situation hledger is more likely to guess the wrong default account name,
so you may need to set that explicitly. so you may need to set that explicitly.