mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
AccountS - debitUnits for concreteBalance, Balance SetDecimalValue and DecimalValue export methods
This commit is contained in:
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -48,3 +49,20 @@ func (cb *concreteBalance) debit(cgrEv *utils.CGREventWithOpts,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// debitUnits is a direct debit of balance units
|
||||
func (cb *concreteBalance) debitUnits(unts *decimal.Big, incrm *decimal.Big) (dbted *decimal.Big, err error) {
|
||||
// toDo: handle *balanceLimit
|
||||
dbted = unts
|
||||
if cb.blnCfg.DecimalValue().Cmp(unts) == -1 {
|
||||
dbted = utils.DivideBig(cb.blnCfg.DecimalValue(), incrm).RoundToInt()
|
||||
}
|
||||
rmain := utils.SubstractBig(cb.blnCfg.DecimalValue(), dbted)
|
||||
flt64, ok := rmain.Float64()
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("failed representing decimal <%s> as float64", rmain)
|
||||
}
|
||||
cb.blnCfg.Value = flt64
|
||||
cb.blnCfg.SetDecimalValue(rmain)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -87,6 +87,16 @@ func (b *Balance) Compile() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetDecimalValue populates the internal decimal value
|
||||
func (b *Balance) SetDecimalValue(dVal *decimal.Big) {
|
||||
b.val = dVal
|
||||
}
|
||||
|
||||
// DecimalValue returns the internal decimal value
|
||||
func (b *Balance) DecimalValue() *decimal.Big {
|
||||
return b.val
|
||||
}
|
||||
|
||||
// ActionProfiles is a sortable list of ActionProfiles
|
||||
type AccountProfiles []*AccountProfile
|
||||
|
||||
|
||||
@@ -31,3 +31,7 @@ func MultiplyBig(x, y *decimal.Big) *decimal.Big {
|
||||
func AddBig(x, y *decimal.Big) *decimal.Big {
|
||||
return new(decimal.Big).Add(x, y)
|
||||
}
|
||||
|
||||
func SubstractBig(x, y *decimal.Big) *decimal.Big {
|
||||
return new(decimal.Big).Sub(x, y)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user