Hello
I think I have find solution, a2b version 1.7.1.
First, I think we must not working on the trunk selection, we must look the ratecard (tariffplan) that included in Call Plan.
So, first I delete (or mark with //) this section:
Code:
//1) REMOVE THOSE THAT HAVE A SMALLER DIALPREFIX
//$max_len_prefix = strlen($result[0][7]);
//for ($i=1;$i<count($result);$i++) {
// if ( strlen($result[$i][7]) < $max_len_prefix) break;
//}
//$result = array_slice ($result, 0, $i);
After I have added the next code beetwen 1) and 2)
Code:
//4) REMOVE THOSE THAT HAVE A SAME RATECARD ID
$myresult = array();
$myresult = $result;
$mysearchvalue = array();
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: MYRESULT before sort \n".print_r($myresult, true));
// Sorting - 3 - tariff plan, 5 - dialprefix
$myresult = $this -> array_csort($myresult,'3',SORT_NUMERIC,'5',SORT_NUMERIC,SORT_DESC);
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: MYRESULT after sort \n".print_r($myresult, true));
$countdelete = 1;
$resultcount = 0;
for ($ii=0;$ii<count($result)-1;$ii++)
{
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: Begin for II value ".$ii."]");
$mysearchvalue[$resultcount] = $myresult[0];
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: MYSEARCHCVALUE".print_r($mysearchvalue,true)."]");
if (count($myresult)>0){
foreach($myresult as $j=>$i){
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: foreach J:".print_r($j, true));
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine:mysearchvalue[3]:".$mysearchvalue[$resultcount][3]);
if ($mysearchvalue[$resultcount][3] == $i[3]) {
unset($myresult[$j]);
$countdelete = $countdelete+1;
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: COUNTDELETE: ".$countdelete."]");
}
}
$myresult = array_values($myresult);
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: Count MYRESULT after foreach".count($myresult)."]");
$resultcount++;
}
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: End for II value ".$ii."]");
}
unset($mysearchvalue[$resultcount]);
$mysearchvalue = array_values($mysearchvalue);
unset($myresult);
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: RESULTCOUNT".$resultcount."]");
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: MYRESULT after delete \n".print_r($myresult, true));
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: MYSEARCHVALUE after delete \n".print_r($mysearchvalue, true));
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: Count Total result after 4 ".count($myresult)."]");
$result=$mysearchvalue;
unset($mysearchvalue);
if ($this->webui) $A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: RESULT after delete \n".print_r($result, true));
I have do the next algoritm:
I have 4 provider with different dial preffix and price.
Each provider(vendor) have self ratecard and trunk.
P1, P2, P3, P4
We are calling to 79055555658
in RateEngine after RateEnginere do SELECT is the following data:
RateCard ID Provayder DialPrefix BuyRate
1 P1 79055 0.04644
4 P2 7905 0.0598
3 P3 7905 0.06487
2 P4 7905 0.06487
1 P1 7905 0.0486
3 P3 790 0.03825
2 P4 790 0.03825
1 P1 790 0.0378
4 P2 79 0.0365
1 P1 79 0.0378
4 P2 7 0.023
3 P3 7 0.0461
2 P4 7 0.0508
1 P1 7 0.0108
I do the following sort:
Sort by field RateCardID ASC and dialprefix DESC
And after all we became this table:
RateCard ID Provayder DialPrefix BuyRate
1 P1 79055 0.04644
2 P4 7905 0.06487
3 P3 7905 0.06487
4 P2 7905 0.0598
and after work this code:
//2) TAKE THE VALUE OF LCTYPE
we became the next
RateCard ID Provayder DialPrefix BuyRate
1 P1 79055 0.04644
4 P2 7905 0.0598
2 P4 7905 0.06487
3 P3 7905 0.06487
So, it all.
Now this code is working in my production server and all is working fine.
Please test
Thanks