add beancount syntax check api
This commit is contained in:
parent
2839749306
commit
735e322942
|
|
@ -39,3 +39,8 @@ func GetLedgerPriceFilePath(dataPath string) string {
|
|||
func GetLedgerMonthsFilePath(dataPath string) string {
|
||||
return dataPath + "/month/months.bean"
|
||||
}
|
||||
|
||||
func GetLedgerIndexFilePath(dataPath string) string {
|
||||
LogInfo(dataPath, dataPath+"/index.bean")
|
||||
return dataPath + "/index.bean"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ func RegisterRouter(router *gin.Engine) {
|
|||
authorized.POST("/file", service.UpdateLedgerSourceFileContent)
|
||||
authorized.POST("/import/alipay", service.ImportAliPayCSV)
|
||||
authorized.POST("/import/wx", service.ImportWxPayCSV)
|
||||
authorized.GET("/ledger/check", service.CheckLedger)
|
||||
authorized.DELETE("/ledger", service.DeleteLedger)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
|
|
@ -207,6 +208,27 @@ func DeleteLedger(c *gin.Context) {
|
|||
OK(c, "OK")
|
||||
}
|
||||
|
||||
func CheckLedger(c *gin.Context) {
|
||||
var stderr bytes.Buffer
|
||||
ledgerConfig := script.GetLedgerConfigFromContext(c)
|
||||
cmd := exec.Command("bean-check", script.GetLedgerIndexFilePath(ledgerConfig.DataPath))
|
||||
cmd.Stderr = &stderr
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
errors := strings.Split(stderr.String(), "\r\n")
|
||||
result := make([]string, 0)
|
||||
for _, e := range errors {
|
||||
if e == "" {
|
||||
continue
|
||||
}
|
||||
result = append(result, e)
|
||||
}
|
||||
OK(c, result)
|
||||
} else {
|
||||
OK(c, string(output))
|
||||
}
|
||||
}
|
||||
|
||||
func createNewLedger(loginForm LoginForm, ledgerId string) (*script.Config, error) {
|
||||
// create new ledger
|
||||
serverConfig := script.GetServerConfig()
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ func saveTransaction(c *gin.Context, addTransactionForm AddTransactionForm, ledg
|
|||
}
|
||||
// 判断是否涉及多币种的转换
|
||||
if account.Currency != ledgerConfig.OperatingCurrency && entry.Account != ledgerConfig.OpeningBalances {
|
||||
autoBalance = true
|
||||
// 根据 number 的正负来判断是买入还是卖出
|
||||
if entry.Number.GreaterThan(decimal.NewFromInt(0)) {
|
||||
// {351.729 CNY, 2021-09-29}
|
||||
|
|
|
|||
Loading…
Reference in New Issue