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 .vscode
bindata.go bindata.go
*.exe *.exe
beancount-gs
gin.log gin.log
config.json config.json

View File

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

View File

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

View File

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

View File

@ -10,6 +10,11 @@ func isWindows() bool {
return os == "windows" return os == "windows"
} }
func isMacOS() bool {
os := runtime.GOOS
return os == "darwin"
}
func OpenBrowser(url string) { func OpenBrowser(url string) {
if isWindows() { if isWindows() {
cmd := exec.Command("cmd", "/C", "start", url) cmd := exec.Command("cmd", "/C", "start", url)
@ -17,5 +22,11 @@ func OpenBrowser(url string) {
if err != nil { if err != nil {
LogSystemError("Failed to open browser, error is " + err.Error()) 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 { func saveTransaction(c *gin.Context, addTransactionForm AddTransactionForm, ledgerConfig *script.Config) error {
// 账户是否平衡 // 账户是否平衡
sumVal := sum(addTransactionForm.Entries, ledgerConfig.OpeningBalances) sumVal := sum(addTransactionForm.Entries, ledgerConfig.OpeningBalances)
val, _ := decimal.NewFromString("0.01") val, _ := decimal.NewFromString("0.1")
if sumVal.Abs().GreaterThan(val) { if sumVal.Abs().GreaterThan(val) {
if c != nil { if c != nil {
TransactionNotBalance(c) TransactionNotBalance(c)
@ -143,7 +143,7 @@ func saveTransaction(c *gin.Context, addTransactionForm AddTransactionForm, ledg
if entry.Account == ledgerConfig.OpeningBalances { if entry.Account == ledgerConfig.OpeningBalances {
line += fmt.Sprintf("\r\n %s", entry.Account) line += fmt.Sprintf("\r\n %s", entry.Account)
} else { } 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 { if account.Currency != ledgerConfig.OperatingCurrency && entry.Account != ledgerConfig.OpeningBalances {