2021-02-02 04:19:16 +00:00
|
|
|
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 {
|
2021-02-02 05:51:33 +00:00
|
|
|
GlAccountID string
|
|
|
|
PeriodID string
|
|
|
|
Principal *User
|
2021-02-02 04:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetGlBalanceByParams is a GL balance helper function
|
|
|
|
func GetGlBalanceByParams(params GlBalanceParams) *ledger_models.GlBalance {
|
|
|
|
sugar.Debug("ops.getGlBalanceByParams: 📥")
|
2021-02-02 05:51:33 +00:00
|
|
|
obj, ok := glBalanceCache.get(params.PeriodID, params.GlAccountID)
|
2021-02-02 04:19:16 +00:00
|
|
|
if ok {
|
|
|
|
sugar.Debug("ops.getGlBalanceByParams: 👍 📤 🎯")
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
ledgerParams := gl_balance.NewGetGlBalancesParamsWithTimeout(getTimeout)
|
2021-02-02 05:51:33 +00:00
|
|
|
ledgerParams.GlAccountID = ¶ms.GlAccountID
|
|
|
|
ledgerParams.PeriodID = ¶ms.PeriodID
|
|
|
|
response, restErr := ledgerClient.GlBalance.GetGlBalances(ledgerParams, params.Principal.Auth)
|
2021-02-02 04:19:16 +00:00
|
|
|
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
|
|
|
|
}
|
2021-02-02 05:51:33 +00:00
|
|
|
glBalanceCache.put(params.PeriodID, params.GlAccountID, theGlBalance)
|
2021-02-02 04:19:16 +00:00
|
|
|
sugar.Debugf("ops.getGlBalanceByParams: 👍 📤")
|
|
|
|
return theGlBalance
|
|
|
|
}
|