fix: #71 account startDate endDate

This commit is contained in:
BaoXuebin 2024-03-09 10:43:07 +08:00
parent 5159755109
commit 942c859572
1 changed files with 24 additions and 6 deletions

View File

@ -319,21 +319,39 @@ func LoadLedgerAccounts(ledgerId string) error {
key := words[2]
temp = accountMap[key]
account := Account{Acc: key, Type: nil}
// 货币单位
if len(words) >= 4 {
account.Currency = words[3]
}
if words[1] == "open" {
account.StartDate = words[0]
if account.StartDate != "" && temp.StartDate != "" && account.StartDate >= temp.StartDate {
// 重复定义的账户,取最早的开始时间为准
continue
}
// 货币单位
if len(words) >= 4 {
account.Currency = words[3]
}
} else if words[1] == "close" {
account.EndDate = words[0]
if account.EndDate != "" && temp.EndDate != "" && account.EndDate < temp.EndDate {
// 重复定义的账户,取最晚的开始时间为准
continue
}
}
if temp.StartDate != "" {
if account.StartDate == "" {
account.StartDate = temp.StartDate
}
if temp.EndDate != "" {
if account.EndDate == "" {
account.EndDate = temp.EndDate
}
if account.Currency == "" {
account.Currency = temp.Currency
}
// 如果结束时间小于开始时间,则结束时间为空
if account.EndDate != "" && account.StartDate > account.EndDate {
account.EndDate = ""
}
accountMap[key] = account
}
}