Bladeren bron

minor modification to the checks

bmallred 10 jaren geleden
bovenliggende
commit
e0a4998caf
2 gewijzigde bestanden met toevoegingen van 12 en 9 verwijderingen
  1. 12 4
      commit.go
  2. 0 5
      general.ledger

+ 12 - 4
commit.go

@ -133,14 +133,14 @@ func (t *Transaction) FromString(text string) error {
133 133
				break
134 134
			}
135 135
136
			account := fields[0]
136
			account := fields[1]
137 137
			debit := true
138 138
139
			if strings.HasPrefix(fields[1], "-") {
139
			if strings.HasPrefix(fields[2], "-") {
140 140
				debit = false
141 141
			}
142 142
			value := new(big.Rat)
143
			value.SetString(fields[1][1:])
143
			value.SetString(fields[2][1:])
144 144
145 145
			t.Accounts = append(
146 146
				t.Accounts,
@ -154,10 +154,18 @@ func (t *Transaction) FromString(text string) error {
154 154
		}
155 155
	}
156 156
157
	if len(t.Accounts) == 0 {
158
		return errors.New("Transaction does not have any accounts")
159
	}
160
157 161
	// Check that they balance
158 162
	balance := new(big.Rat)
159 163
	for _, a := range t.Accounts {
160
		balance.Add(balance, a.Amount)
164
		if a.Debit {
165
			balance.Add(balance, a.Amount)
166
		} else {
167
			balance.Sub(balance, a.Amount)
168
		}
161 169
	}
162 170
	if balance.FloatString(2) != "0.00" {
163 171
		return errors.New("Transaction does not balance")

+ 0 - 5
general.ledger

@ -12,8 +12,3 @@
12 12
	cash	+5.00
13 13
	sheep	+5.00
14 14
15
2015-01-05	@general	blah
16
	savings	-10.00
17
	cash	+5.00
18
	sheep	+5.00
19