Use zero Numeric for export instead of hardcoding 0,00
This commit is contained in:
parent
0478d82c1f
commit
6686904539
@ -43,8 +43,8 @@ func (ynab *YNABExport) ExportAssignments(context context.Context, w io.Writer)
|
|||||||
assignment.Group,
|
assignment.Group,
|
||||||
assignment.Category,
|
assignment.Category,
|
||||||
assignment.Amount.String() + "€",
|
assignment.Amount.String() + "€",
|
||||||
"0,00€",
|
NewZeroNumeric().String() + "€",
|
||||||
"0,00€",
|
NewZeroNumeric().String() + "€",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := csv.Write(row)
|
err := csv.Write(row)
|
||||||
@ -129,9 +129,9 @@ func GetTransactionRow(transaction GetAllTransactionsForBudgetRow) []string {
|
|||||||
row = append(row, transaction.Memo)
|
row = append(row, transaction.Memo)
|
||||||
|
|
||||||
if transaction.Amount.IsPositive() {
|
if transaction.Amount.IsPositive() {
|
||||||
row = append(row, "0,00€", transaction.Amount.String()+"€")
|
row = append(row, NewZeroNumeric().String()+"€", transaction.Amount.String()+"€")
|
||||||
} else {
|
} else {
|
||||||
row = append(row, transaction.Amount.String()[1:]+"€", "0,00€")
|
row = append(row, transaction.Amount.String()[1:]+"€", NewZeroNumeric().String()+"€")
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(row, string(transaction.Status))
|
return append(row, string(transaction.Status))
|
||||||
|
@ -303,27 +303,38 @@ func trimLastChar(s string) string {
|
|||||||
return s[:len(s)-size]
|
return s[:len(s)-size]
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAmount(inflow string, outflow string) (Numeric, error) {
|
func ParseNumeric(text string) (Numeric, error) {
|
||||||
// Remove trailing currency
|
// Remove trailing currency
|
||||||
inflow = strings.Replace(trimLastChar(inflow), ",", ".", 1)
|
text = trimLastChar(text)
|
||||||
outflow = strings.Replace(trimLastChar(outflow), ",", ".", 1)
|
|
||||||
|
// Unify decimal separator
|
||||||
|
text = strings.Replace(text, ",", ".", 1)
|
||||||
|
|
||||||
num := Numeric{}
|
num := Numeric{}
|
||||||
err := num.Set(inflow)
|
err := num.Set(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return num, fmt.Errorf("parse inflow %s: %w", inflow, err)
|
return num, fmt.Errorf("parse numeric %s: %w", text, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return num, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAmount(inflow string, outflow string) (Numeric, error) {
|
||||||
|
in, err := ParseNumeric(inflow)
|
||||||
|
if err != nil {
|
||||||
|
return in, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.IsZero() {
|
||||||
|
return in, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// if inflow is zero, use outflow
|
// if inflow is zero, use outflow
|
||||||
if num.Int.Int64() != 0 {
|
out, err := ParseNumeric("-" + outflow)
|
||||||
return num, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = num.Set("-" + outflow)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return num, fmt.Errorf("parse outflow %s: %w", inflow, err)
|
return out, err
|
||||||
}
|
}
|
||||||
return num, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ynab *YNABImport) GetAccount(context context.Context, name string) (*Account, error) {
|
func (ynab *YNABImport) GetAccount(context context.Context, name string) (*Account, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user