Browse Source

minor modification to the checks

bmallred 10 years ago
parent
commit
e0a4998caf
2 changed files with 12 additions and 9 deletions
  1. 12 4
      commit.go
  2. 0 5
      general.ledger

+ 12 - 4
commit.go

133
				break
133
				break
134
			}
134
			}
135
135
136
			account := fields[0]
136
			account := fields[1]
137
			debit := true
137
			debit := true
138
138
139
			if strings.HasPrefix(fields[1], "-") {
139
			if strings.HasPrefix(fields[2], "-") {
140
				debit = false
140
				debit = false
141
			}
141
			}
142
			value := new(big.Rat)
142
			value := new(big.Rat)
143
			value.SetString(fields[1][1:])
143
			value.SetString(fields[2][1:])
144
144
145
			t.Accounts = append(
145
			t.Accounts = append(
146
				t.Accounts,
146
				t.Accounts,
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
	// Check that they balance
161
	// Check that they balance
158
	balance := new(big.Rat)
162
	balance := new(big.Rat)
159
	for _, a := range t.Accounts {
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
	if balance.FloatString(2) != "0.00" {
170
	if balance.FloatString(2) != "0.00" {
163
		return errors.New("Transaction does not balance")
171
		return errors.New("Transaction does not balance")

+ 0 - 5
general.ledger

12
	cash	+5.00
12
	cash	+5.00
13
	sheep	+5.00
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