diff --git a/accounts/concretebalance.go b/accounts/concretebalance.go index 65bb9ec78..a536270c0 100644 --- a/accounts/concretebalance.go +++ b/accounts/concretebalance.go @@ -19,8 +19,6 @@ along with this program. If not, see package accounts import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" "github.com/ericlagergren/decimal" @@ -66,7 +64,6 @@ type concreteBalance struct { func (cB *concreteBalance) debitAbstracts(aUnits *decimal.Big, cgrEv *utils.CGREvent) (ec *utils.EventCharges, err error) { evNm := cgrEv.AsDataProvider() - fmt.Printf("debitAbstracts, aUnits: %s, ev: %+v\n", aUnits, cgrEv) // pass the general balance filters var pass bool if pass, err = cB.fltrS.Pass(cgrEv.Tenant, cB.blnCfg.FilterIDs, evNm); err != nil { @@ -81,7 +78,6 @@ func (cB *concreteBalance) debitAbstracts(aUnits *decimal.Big, cB.fltrS, cgrEv.Tenant, evNm); err != nil { return } - fmt.Printf("costIcrm: %+v\n", costIcrm) if ec, err = maxDebitAbstractsFromConcretes(aUnits, cB.acntID, []*concreteBalance{cB}, cB.connMgr, cgrEv, @@ -90,7 +86,6 @@ func (cB *concreteBalance) debitAbstracts(aUnits *decimal.Big, costIcrm); err != nil { return } - fmt.Printf("received ec: %s\n", utils.ToIJSON(ec)) return } diff --git a/accounts/libaccounts.go b/accounts/libaccounts.go index 731405b15..c581e7de5 100644 --- a/accounts/libaccounts.go +++ b/accounts/libaccounts.go @@ -301,7 +301,6 @@ func maxDebitAbstractsFromConcretes(aUnits *decimal.Big, paidConcrtUnts = cloneUnitsFromConcretes(cncrtBlncs) ec = utils.NewEventCharges() ec.Merge(ecDbt) - fmt.Printf("ecDbt: %s\n", utils.ToIJSON(ecDbt)) if i == 0 { // no estimation done, covering full break } diff --git a/utils/accountprofile.go b/utils/accountprofile.go index 19904678f..7a6b01b0b 100644 --- a/utils/accountprofile.go +++ b/utils/accountprofile.go @@ -179,7 +179,7 @@ func (uF *UnitFactor) Equals(nUf *UnitFactor) (eq bool) { uF.Factor != nil && nUf.Factor == nil { return } - if uF.Factor == nil && nUf == nil { + if uF.Factor == nil && nUf.Factor == nil { return true } return uF.Factor.Compare(nUf.Factor) == 0 diff --git a/utils/eventcharges.go b/utils/eventcharges.go index ce29f33a8..4626d5d64 100644 --- a/utils/eventcharges.go +++ b/utils/eventcharges.go @@ -193,7 +193,15 @@ type ChargingInterval struct { // CompressEquals compares two ChargingIntervals for aproximate equality, ignoring compress field func (cIl *ChargingInterval) CompressEquals(nCil *ChargingInterval) (eq bool) { - return + if len(cIl.Increments) != len(nCil.Increments) { + return + } + for i, chIr := range cIl.Increments { + if !chIr.CompressEquals(nCil.Increments[i]) { + return + } + } + return true } // ChargingIncrement represents one unit charged inside an interval @@ -203,6 +211,15 @@ type ChargingIncrement struct { CompressFactor int } +func (cI *ChargingIncrement) CompressEquals(chIh *ChargingIncrement) (eq bool) { + if cI.Units == nil && chIh.Units != nil || + cI.Units != nil && chIh.Units == nil { + return + } + return cI.Units.Compare(chIh.Units) == 0 && + cI.AccountChargeID == chIh.AccountChargeID +} + // AccountCharge represents one Account charge type AccountCharge struct { AccountID string @@ -217,5 +234,43 @@ type AccountCharge struct { // Equals compares two AccountCharges func (ac *AccountCharge) Equals(nAc *AccountCharge) (eq bool) { - return + if ac.AttributeIDs == nil && nAc.AttributeIDs != nil || + ac.AttributeIDs != nil && nAc.AttributeIDs == nil || + len(ac.AttributeIDs) != len(nAc.AttributeIDs) { + return + } + for i := range ac.AttributeIDs { + if ac.AttributeIDs[i] != nAc.AttributeIDs[i] { + return + } + } + if ac.JoinedChargeIDs == nil && nAc.JoinedChargeIDs != nil || + ac.JoinedChargeIDs != nil && nAc.JoinedChargeIDs == nil || + len(ac.JoinedChargeIDs) != len(nAc.JoinedChargeIDs) { + return + } + for i := range ac.JoinedChargeIDs { + if ac.JoinedChargeIDs[i] != nAc.JoinedChargeIDs[i] { + return + } + } + if ac.AccountID != nAc.AccountID || + ac.BalanceID != nAc.BalanceID || + ac.UnitFactorID != nAc.UnitFactorID || + ac.RatingID != nAc.RatingID { + return + } + if ac.Units == nil && nAc.Units != nil || + ac.Units != nil && nAc.Units == nil { + return + } + if ac.BalanceLimit == nil && nAc.BalanceLimit != nil || + ac.BalanceLimit != nil && nAc.BalanceLimit == nil { + return + } + if ac.Units == nil && nAc.Units == nil || + ac.BalanceLimit == nil && nAc.BalanceLimit == nil { + return true + } + return ac.Units.Compare(nAc.Units) == 0 && ac.BalanceLimit.Compare(nAc.BalanceLimit) == 0 } diff --git a/utils/librates.go b/utils/librates.go index 4694804fa..13b55a82f 100644 --- a/utils/librates.go +++ b/utils/librates.go @@ -142,7 +142,35 @@ type RateSIncrement struct { // Equals compares two RateSIntervals func (rIl *RateSInterval) Equals(nRil *RateSInterval) (eq bool) { - return // ToDo + if rIl.IntervalStart == nil && nRil.IntervalStart != nil || + rIl.IntervalStart != nil && nRil.IntervalStart == nil || + len(rIl.Increments) != len(nRil.Increments) { + return + } + if rIl.IntervalStart.Compare(nRil.IntervalStart) != 0 || + rIl.CompressFactor != nRil.CompressFactor { + return + } + for i, rtIn := range rIl.Increments { + if !rtIn.Equals(nRil.Increments[i]) { + return + } + } + return true +} + +func (rI *RateSIncrement) Equals(rtIn *RateSIncrement) (eq bool) { + if rI.Usage == nil && rtIn.Usage != nil || + rI.Usage != nil && rtIn.Usage == nil || + rI.IncrementStart == nil && rtIn.IncrementStart != nil || + rI.IncrementStart != nil && rtIn.IncrementStart == nil { + return + } + return rI.Usage.Compare(rtIn.Usage) == 0 && + rI.IncrementStart.Compare(rtIn.IncrementStart) == 0 && + rI.CompressFactor == rtIn.CompressFactor && + rI.IntervalRateIndex == rtIn.IntervalRateIndex && + rI.Rate.UID() == rtIn.Rate.UID() } // RateProfileCost is the cost returned by RateS at cost queries