mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
adding connect fee only in first timestamp
This commit is contained in:
@@ -527,12 +527,12 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
utils.Logger.Err(fmt.Sprintf("<Rater> Going negative on account %s with AllowNegative: false", cd.GetAccountKey()))
|
||||
}
|
||||
leftCC.Timespans.Decompress()
|
||||
for _, ts := range leftCC.Timespans {
|
||||
for tsIndex, ts := range leftCC.Timespans {
|
||||
if ts.Increments == nil {
|
||||
ts.createIncrementsSlice()
|
||||
}
|
||||
|
||||
if ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
if tsIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
|
||||
inc := &Increment{
|
||||
Duration: 0,
|
||||
@@ -553,7 +553,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
|
||||
for incIndex, increment := range ts.Increments {
|
||||
|
||||
if incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
if tsIndex == 0 && incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
// go to nextincrement
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ func (b *Balance) debitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
return nil, errors.New("timespan with no rate interval assigned")
|
||||
}
|
||||
|
||||
if ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee {
|
||||
if tsIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee && ok {
|
||||
|
||||
inc := &Increment{
|
||||
Duration: 0,
|
||||
@@ -433,7 +433,7 @@ func (b *Balance) debitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
maxCost, strategy := ts.RateInterval.GetMaxCost()
|
||||
for incIndex, inc := range ts.Increments {
|
||||
|
||||
if incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee {
|
||||
if tsIndex == 0 && incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee && ok {
|
||||
// go to nextincrement
|
||||
continue
|
||||
}
|
||||
@@ -546,6 +546,7 @@ func (b *Balance) debitMoney(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
var ok bool
|
||||
//log.Print("cc: " + utils.ToJSON(cc))
|
||||
if debitConnectFee {
|
||||
|
||||
// this is the first add, debit the connect fee
|
||||
if ok, debitedConnectFeeBalance = ub.DebitConnectionFee(cc, moneyBalances, count, true); !ok {
|
||||
// balance is blocker
|
||||
@@ -568,7 +569,7 @@ func (b *Balance) debitMoney(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
return nil, errors.New("timespan with no rate interval assigned")
|
||||
}
|
||||
|
||||
if ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee {
|
||||
if tsIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && debitConnectFee && ok {
|
||||
|
||||
inc := &Increment{
|
||||
Duration: 0,
|
||||
@@ -594,7 +595,7 @@ func (b *Balance) debitMoney(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
// check standard subject tags
|
||||
//log.Printf("INC: %+v", inc)
|
||||
|
||||
if incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
if tsIndex == 0 && incIndex == 0 && ts.RateInterval.Rating.ConnectFee > 0 && ok {
|
||||
// go to nextincrement
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed *time.Duration) (time.
|
||||
|
||||
// Attempts to refund a duration, error on failure
|
||||
func (self *SMGSession) refund(refundDuration time.Duration) error {
|
||||
|
||||
if refundDuration == 0 { // Nothing to refund
|
||||
return nil
|
||||
}
|
||||
@@ -154,12 +155,16 @@ func (self *SMGSession) refund(refundDuration time.Duration) error {
|
||||
if refundDuration <= tsDuration {
|
||||
|
||||
lastRefundedIncrementIndex := -1
|
||||
|
||||
for j := len(ts.Increments) - 1; j >= 0; j-- {
|
||||
increment := ts.Increments[j]
|
||||
|
||||
if increment.Duration <= refundDuration {
|
||||
|
||||
refundIncrements = append(refundIncrements, increment)
|
||||
refundDuration -= increment.Duration
|
||||
lastRefundedIncrementIndex = j
|
||||
|
||||
} else {
|
||||
break //increment duration is larger, cannot refund increment
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user