diff --git a/combine.go b/combine.go index 4ff1043..5fb80a1 100644 --- a/combine.go +++ b/combine.go @@ -3,6 +3,7 @@ package cdr import ( "fmt" "strings" + "time" ) func CombineTextCDRs(cdrLines []Line, prices []Price) ([]Text, error) { @@ -144,43 +145,60 @@ func CombineCallCDRs(cdrLines []Line, prices []Price) ([]Call, error) { uniqueCalls[idx] = append(uniqueCalls[idx], l) } + ret := make([]Call, len(uniqueCalls)) + i := 0 for k, v := range uniqueCalls { - fmt.Printf("[%s] %d\n", k, len(v)) - for i, c := range v { - fmt.Printf("\t%d (%d) [%25s]: (%12s): %12s->%12s (%s)\n", i, c.Leg, c.Account, c.CLI, c.From, c.To, c.Reason) - } - fmt.Println() - } - - /* - ret := make([]Call, 0) - for _, l := range cdrLines { - if l.Kind != VoiceLine { - continue + /* + fmt.Printf("[%s] %d\n", k, len(v)) + for i, c := range v { + fmt.Printf("\t%d (%d) [%25s]: (%12s): %12s->%12s (%s)\n", i, c.Leg, c.Account, c.CLI, c.From, c.To, c.Reason) } - + fmt.Println() + */ + var legPrice Price + for _, leg := range v { switch { // HS -> PBX (non-roaming) case l.CLI == l.From && l.Source == CALL_FROM_HANDSET_SOURCE && l.Destination == CALL_FROM_HANDSET_DESTINATION: - - // PBX -> HS (roaming+non-roaming) + // This leg consists of the airtime (outgoing call from the HS perspective) + legPrice = CALL_NATIONAL_DESTINATION_AIRTIME_FROM_HANDSET + // PBX -> HS (roaming + non-roaming) case l.From == l.To && l.Source == CALL_TO_HANDSET_SOURCE && l.Destination == CALL_TO_HANDSET_DESTINATION: - - // HS -> Regular (non-roaming) - case l.CLI == l.From && l.Source == CALL_FROM_HANDSET_SOURCE: - - // HS -> Regular (roaming) + // This leg consists of the airtime + legPrice = CALL_NATIONAL_DESTINATION_AIRTIME_TO_HANDSET + // PBX -> destination, HS -> destination (non-roaming) + case l.CLI == l.From && l.From != l.To && l.Source == CALL_FROM_PBX_SOURCE: + // This leg consists of routing a call from a PBX through our platform + fallthrough + case l.CLI == l.From && l.From != l.To && l.Source == CALL_FROM_HANDSET_SOURCE: + // The costs are defined by the call's destination + legPrice = destinationToPrice[l.Destination] + // HS -> destination (roaming), HS -> PBX (roaming) case l.CLI == l.From && l.Source != CALL_FROM_HANDSET_SOURCE && l.Reason == ORIG: - // Regular -> HS (roaming) + // source -> HS (roaming) case l.CLI != l.From && l.Source == CALL_TO_HANDSET_SOURCE && l.Reason == ROAM: + // We only know the destination country - // Regular -> HS (non-roaming) does not exist in the CSV + // Source -> HS (non-roaming) (i.e. incoming calls) does not exist in the CSV default: } + fmt.Printf("(%12s->%12s) leg %d, price: %+v\n", l.CLI, l.To, l.Leg, legPrice) + } + ret[i] = Call{ + From: "asdf", + To: "asdkflj", + Duration: time.Duration{}, + Cost: 0, + Price: 0, } + ret[i].Legs = make([]PricedLine, len(v)) + for j, leg := range v { + ret[i].Legs[j] = leg + } + i++ + } - fmt.Printf("destinationPrice: %+v\n", destinationToPrice) - */ + fmt.Printf("destinationPrice: %+v\n", destinationToPrice) return nil, fmt.Errorf("not yet implemented") }