Handle amount in import and display
This commit is contained in:
parent
db7f0bfb7b
commit
696469f6c2
@ -123,7 +123,16 @@ func GetAmount(inflow string, outflow string) (pgtype.Numeric, error) {
|
||||
num := pgtype.Numeric{}
|
||||
err := num.Set(inflow)
|
||||
if err != nil {
|
||||
return num, fmt.Errorf("Could not inflow %s: %w", inflow, err)
|
||||
return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err)
|
||||
}
|
||||
|
||||
if num.Int.Int64() != 0 {
|
||||
return num, nil
|
||||
}
|
||||
|
||||
err = num.Set("-" + outflow)
|
||||
if err != nil {
|
||||
return num, fmt.Errorf("Could not parse outflow %s: %w", inflow, err)
|
||||
}
|
||||
return num, nil
|
||||
}
|
||||
|
@ -43,3 +43,13 @@ func (tx Transaction) GetAmount() float64 {
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
func (tx Transaction) GetAmountString() string {
|
||||
amount := tx.GetAmount()
|
||||
return fmt.Sprintf("%.2f", amount)
|
||||
}
|
||||
|
||||
func (tx Transaction) GetPositive() bool {
|
||||
amount := tx.GetAmount()
|
||||
return amount >= 0
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
<td>
|
||||
<a href="transaction/{{.ID}}">{{.Memo}}</a>
|
||||
</td>
|
||||
<td>{{.GetAmount}}</td>
|
||||
<td style="text-align: right;{{if .GetPositive()}}{{else}}color: red;{{end}}">{{.GetAmount}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user