Merge branch 'main' of github.com:BaoXuebin/beancount-gs into main

This commit is contained in:
BaoXuebin 2021-12-22 23:25:25 +08:00
commit e65836c00f
6 changed files with 27 additions and 9 deletions

1
.gitignore vendored
View File

@ -3,5 +3,6 @@
.vscode
bindata.go
*.exe
beancount-gs
gin.log
config.json

View File

@ -43,7 +43,7 @@
**docker**
```shell
docker run --name benacount-gs -dp 10000:80 \
docker run --name beancount-gs -dp 10000:80 \
-w /app \
-v "/data/beancount:/data/beancount" \
-v "/data/beancount/icons:/app/public/icons" \

View File

@ -209,10 +209,14 @@ func LoadLedgerConfigMap() error {
if err != nil {
return err
}
err = json.Unmarshal(fileContent, &ledgerConfigMap)
if err != nil {
LogSystemError("Failed unmarshal ledger_config file (" + path + ")")
return err
if string(fileContent) != "" {
err = json.Unmarshal(fileContent, &ledgerConfigMap)
if err != nil {
LogSystemError("Failed unmarshal ledger_config file (" + path + ")")
return err
}
} else {
ledgerConfigMap = make(map[string]Config)
}
LogSystemInfo("Success load ledger_config file (" + path + ")")
}

View File

@ -3,11 +3,13 @@ package script
import "os"
func GetServerConfigFilePath() string {
return "./config/config.json"
currentPath, _ := os.Getwd()
return currentPath + "/config/config.json"
}
func GetServerWhiteListFilePath() string {
return "./config/white_list.json"
currentPath, _ := os.Getwd()
return currentPath + "/config/white_list.json"
}
func GetServerLedgerConfigFilePath() string {

View File

@ -10,6 +10,11 @@ func isWindows() bool {
return os == "windows"
}
func isMacOS() bool {
os := runtime.GOOS
return os == "darwin"
}
func OpenBrowser(url string) {
if isWindows() {
cmd := exec.Command("cmd", "/C", "start", url)
@ -17,5 +22,11 @@ func OpenBrowser(url string) {
if err != nil {
LogSystemError("Failed to open browser, error is " + err.Error())
}
} else if isMacOS() {
cmd := exec.Command("open", url)
err := cmd.Start()
if err != nil {
LogSystemError("Failed to open browser, error is " + err.Error())
}
}
}

View File

@ -121,7 +121,7 @@ func AddTransactions(c *gin.Context) {
func saveTransaction(c *gin.Context, addTransactionForm AddTransactionForm, ledgerConfig *script.Config) error {
// 账户是否平衡
sumVal := sum(addTransactionForm.Entries, ledgerConfig.OpeningBalances)
val, _ := decimal.NewFromString("0.01")
val, _ := decimal.NewFromString("0.1")
if sumVal.Abs().GreaterThan(val) {
if c != nil {
TransactionNotBalance(c)
@ -143,7 +143,7 @@ func saveTransaction(c *gin.Context, addTransactionForm AddTransactionForm, ledg
if entry.Account == ledgerConfig.OpeningBalances {
line += fmt.Sprintf("\r\n %s", entry.Account)
} else {
line += fmt.Sprintf("\r\n %s %s %s", entry.Account, entry.Number.Round(2).String(), account.Currency)
line += fmt.Sprintf("\r\n %s %s %s", entry.Account, entry.Number.Round(2).StringFixedBank(2), account.Currency)
}
// 判断是否设计多币种的转换
if account.Currency != ledgerConfig.OperatingCurrency && entry.Account != ledgerConfig.OpeningBalances {