package app import ( "code.tnxs.net/taxnexus/lib/api/ledger/ledger_client/gl_balance" "code.tnxs.net/taxnexus/lib/api/ledger/ledger_models" ) // GlBalanceParams is a parameter struct type GlBalanceParams struct { GlAccountID string PeriodID string Principal *User } // GetGlBalanceByParams is a GL balance helper function func GetGlBalanceByParams(params GlBalanceParams) *ledger_models.GlBalance { sugar.Debug("ops.getGlBalanceByParams: 📥") obj, ok := glBalanceCache.get(params.PeriodID, params.GlAccountID) if ok { sugar.Debug("ops.getGlBalanceByParams: 👍 📤 🎯") return obj } ledgerParams := gl_balance.NewGetGlBalancesParamsWithTimeout(getTimeout) ledgerParams.GlAccountID = ¶ms.GlAccountID ledgerParams.PeriodID = ¶ms.PeriodID response, restErr := ledgerClient.GlBalance.GetGlBalances(ledgerParams, params.Principal.Auth) if restErr != nil { sugar.Errorf("ops.getGlBalanceByParams: 💣 ⛔ %s", restErr.Error()) return nil } theGlBalance := &ledger_models.GlBalance{} for _, itm := range response.Payload.Data { theGlBalance = itm // singleton } glBalanceCache.put(params.PeriodID, params.GlAccountID, theGlBalance) sugar.Debugf("ops.getGlBalanceByParams: 👍 📤") return theGlBalance }