more services

v0.1.49 v0.1.49
Vernon Keenan 2021-02-01 21:51:33 -08:00
parent 9a90f18d58
commit 3fc2004190
2 changed files with 33 additions and 8 deletions

View File

@ -7,23 +7,23 @@ import (
// GlBalanceParams is a parameter struct // GlBalanceParams is a parameter struct
type GlBalanceParams struct { type GlBalanceParams struct {
glAccountID string GlAccountID string
periodID string PeriodID string
principal *User Principal *User
} }
// GetGlBalanceByParams is a GL balance helper function // GetGlBalanceByParams is a GL balance helper function
func GetGlBalanceByParams(params GlBalanceParams) *ledger_models.GlBalance { func GetGlBalanceByParams(params GlBalanceParams) *ledger_models.GlBalance {
sugar.Debug("ops.getGlBalanceByParams: 📥") sugar.Debug("ops.getGlBalanceByParams: 📥")
obj, ok := glBalanceCache.get(params.periodID, params.glAccountID) obj, ok := glBalanceCache.get(params.PeriodID, params.GlAccountID)
if ok { if ok {
sugar.Debug("ops.getGlBalanceByParams: 👍 📤 🎯") sugar.Debug("ops.getGlBalanceByParams: 👍 📤 🎯")
return obj return obj
} }
ledgerParams := gl_balance.NewGetGlBalancesParamsWithTimeout(getTimeout) ledgerParams := gl_balance.NewGetGlBalancesParamsWithTimeout(getTimeout)
ledgerParams.GlAccountID = &params.glAccountID ledgerParams.GlAccountID = &params.GlAccountID
ledgerParams.PeriodID = &params.periodID ledgerParams.PeriodID = &params.PeriodID
response, restErr := ledgerClient.GlBalance.GetGlBalances(ledgerParams, params.principal.Auth) response, restErr := ledgerClient.GlBalance.GetGlBalances(ledgerParams, params.Principal.Auth)
if restErr != nil { if restErr != nil {
sugar.Errorf("ops.getGlBalanceByParams: 💣 ⛔ %s", restErr.Error()) sugar.Errorf("ops.getGlBalanceByParams: 💣 ⛔ %s", restErr.Error())
return nil return nil
@ -32,7 +32,7 @@ func GetGlBalanceByParams(params GlBalanceParams) *ledger_models.GlBalance {
for _, itm := range response.Payload.Data { for _, itm := range response.Payload.Data {
theGlBalance = itm // singleton theGlBalance = itm // singleton
} }
glBalanceCache.put(params.periodID, params.glAccountID, theGlBalance) glBalanceCache.put(params.PeriodID, params.GlAccountID, theGlBalance)
sugar.Debugf("ops.getGlBalanceByParams: 👍 📤") sugar.Debugf("ops.getGlBalanceByParams: 👍 📤")
return theGlBalance return theGlBalance
} }

View File

@ -5,8 +5,33 @@ import (
"time" "time"
"code.tnxs.net/taxnexus/lib/api/ledger/ledger_client/period" "code.tnxs.net/taxnexus/lib/api/ledger/ledger_client/period"
"code.tnxs.net/taxnexus/lib/api/ledger/ledger_models"
) )
// GetPeriodByID is a first class object retrieval method
func GetPeriodByID(recordID *string, principal *User) (*ledger_models.Period, error) {
ledgerParams := period.NewGetPeriodsParams()
ledgerParams.PeriodID = recordID
periodResponse, restErr := ledgerClient.Period.GetPeriods(ledgerParams, principal.Auth)
if restErr != nil {
return nil, fmt.Errorf("devops.getPeriodByID: 💣 ⛔ getPeriod error: %w", restErr)
}
return periodResponse.Payload.Data[0], nil
}
// GetPeriodByDate is a first class object retrieval method
func GetPeriodByDate(accountID *string, theDate time.Time, principal *User) (*ledger_models.Period, error) {
ledgerParams := period.NewGetPeriodsParams()
ledgerParams.AccountID = accountID
dateString := theDate.Format(dateFormat)
ledgerParams.Date = &dateString
periodResponse, restErr := ledgerClient.Period.GetPeriods(ledgerParams, principal.Auth)
if restErr != nil {
return nil, fmt.Errorf("devops.getPeriodByDate: 💣 ⛔ getPeriod error: %w", restErr)
}
return periodResponse.Payload.Data[0], nil
}
// CalendarPeriod is a parameter type // CalendarPeriod is a parameter type
type CalendarPeriod struct { type CalendarPeriod struct {
ID string ID string