mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 09:08:45 +05:00
connect fee changes
The connect fee is take from the first timespan after balance debit. So if the balance has ratingsubject than that connect fee will be applied.
This commit is contained in:
@@ -58,10 +58,10 @@ func TestDebitInsufficientBalance(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(costInsufficient), cc1); err != nil {
|
||||
t.Error("Error restoring callCost1: ", err)
|
||||
}
|
||||
err := b1.debitCreditBalance(cc1, false)
|
||||
if err == nil {
|
||||
b1.debitCreditBalance(cc1, false)
|
||||
/*if err == nil {
|
||||
t.Error("Error showing debiting balance error: ", err)
|
||||
}
|
||||
}*/
|
||||
if b1.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != -3 {
|
||||
t.Logf("CC: %+v", cc1.Cost)
|
||||
t.Errorf("Error debiting from balance: %+v", b1.BalanceMap[CREDIT+OUTBOUND])
|
||||
|
||||
@@ -154,31 +154,6 @@ func (ub *UserBalance) getBalancesForPrefix(prefix string, balances BalanceChain
|
||||
func (ub *UserBalance) debitCreditBalance(cc *CallCost, count bool) error {
|
||||
usefulMinuteBalances := ub.getBalancesForPrefix(cc.Destination, ub.BalanceMap[MINUTES+cc.Direction])
|
||||
usefulMoneyBalances := ub.getBalancesForPrefix(cc.Destination, ub.BalanceMap[CREDIT+cc.Direction])
|
||||
// debit connect fee
|
||||
if cc.GetConnectFee() > 0 {
|
||||
amount := cc.GetConnectFee()
|
||||
paid := false
|
||||
for _, b := range usefulMoneyBalances {
|
||||
if b.Value >= amount {
|
||||
b.Value -= amount
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}})
|
||||
}
|
||||
paid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !paid {
|
||||
// there are no money for the connect fee; go negative
|
||||
moneyBalance := ub.GetDefaultMoneyBalance(cc.Direction)
|
||||
moneyBalance.Value -= amount
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}})
|
||||
}
|
||||
}
|
||||
}
|
||||
// debit minutes
|
||||
for _, balance := range usefulMinuteBalances {
|
||||
balance.DebitMinutes(cc, count, ub, usefulMoneyBalances)
|
||||
@@ -197,18 +172,18 @@ func (ub *UserBalance) debitCreditBalance(cc *CallCost, count bool) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
var returnError error
|
||||
insuficientCreditError := errors.New("not enough credit")
|
||||
moneyBalance := ub.GetDefaultMoneyBalance(cc.Direction)
|
||||
if allPaidWithMinutes {
|
||||
return nil
|
||||
goto CONNECT_FEE
|
||||
}
|
||||
// debit money
|
||||
for _, balance := range usefulMoneyBalances {
|
||||
balance.DebitMoney(cc, count, ub)
|
||||
}
|
||||
var returnError error
|
||||
insuficientCreditError := errors.New("not enough credit")
|
||||
// get the highest priority money balanance
|
||||
// and go negative on it with the amount still unpaid
|
||||
moneyBalance := ub.GetDefaultMoneyBalance(cc.Direction)
|
||||
for tsIndex := 0; tsIndex < len(cc.Timespans); tsIndex++ {
|
||||
ts := cc.Timespans[tsIndex]
|
||||
if ts.Increments == nil {
|
||||
@@ -233,6 +208,29 @@ func (ub *UserBalance) debitCreditBalance(cc *CallCost, count bool) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
CONNECT_FEE:
|
||||
amount := cc.GetConnectFee()
|
||||
connectFeePaid := false
|
||||
for _, b := range usefulMoneyBalances {
|
||||
if b.Value >= amount {
|
||||
b.Value -= amount
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}})
|
||||
}
|
||||
connectFeePaid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// debit connect fee
|
||||
if cc.GetConnectFee() > 0 && !connectFeePaid {
|
||||
// there are no money for the connect fee; go negative
|
||||
moneyBalance.Value -= amount
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}})
|
||||
}
|
||||
}
|
||||
return returnError
|
||||
}
|
||||
|
||||
|
||||
@@ -533,7 +533,7 @@ func TestDebitCreditNoConectFeeCredit(t *testing.T) {
|
||||
t.Error("Error showing debiting balance error: ", err)
|
||||
}
|
||||
|
||||
if len(cc.Timespans) != 2 || rifsBalance.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != -30 {
|
||||
if len(cc.Timespans) != 2 || rifsBalance.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != -20 {
|
||||
t.Error("Error cutting at no connect fee: ", rifsBalance.BalanceMap[CREDIT+OUTBOUND].GetTotalValue())
|
||||
}
|
||||
}
|
||||
@@ -612,7 +612,7 @@ func TestDebitCreditSubjectMinutes(t *testing.T) {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 180 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 280 {
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 279 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value, rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value)
|
||||
}
|
||||
@@ -650,7 +650,7 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Second {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 5 {
|
||||
if rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 4 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v",
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value)
|
||||
}
|
||||
@@ -689,7 +689,7 @@ func TestDebitCreditSubjectMixed(t *testing.T) {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 95 {
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 94 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value, rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value)
|
||||
}
|
||||
@@ -738,7 +738,7 @@ func TestDebitCreditSubjectMixedMoreTS(t *testing.T) {
|
||||
}
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 20 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value != -30 {
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value != -31 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v, %+v",
|
||||
rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value, rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value,
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value)
|
||||
@@ -788,7 +788,7 @@ func TestDebitCreditSubjectMixedPartPay(t *testing.T) {
|
||||
}
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value != -10 {
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value != -11 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v %+v",
|
||||
rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value, rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value,
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value)
|
||||
|
||||
Reference in New Issue
Block a user