?? class.rateengine.php
字號:
" WHERE $CLAUSE_DATE AND id_cc_card = '".$A2B->id_card."' AND id_cc_package_offer = '$id_cc_package_offer' "; $pack_result = $A2B -> instance_table -> SQLExec ($A2B -> DBHandle, $QUERY); if (is_array($pack_result) && count($pack_result)>0){ $freetimetocall_used = $pack_result[0][0]; }else{ $freetimetocall_used = 0; } $A2B -> write_log ('line:'.__LINE__." - PACK USED TIME : $QUERY ; RESULT -> $freetimetocall_used"); if ($this -> debug_st) echo ('line:'.__LINE__." - PACK USED TIME : $QUERY ; RESULT -> $freetimetocall_used"); $this -> freetimetocall_left[$K] = $freetimetocall - $freetimetocall_used; if ($this -> freetimetocall_left[$K] < 0) $this -> freetimetocall_left[$K] = 0; } } if ($this -> debug_st) print_r($this -> freetimetocall_left); // **************** END PACKAGE PARAMETERS **************** $credit -= $connectcharge; $credit -= $disconnectcharge; //$credit -= ($initblock/60)*$rateinitial; $this -> ratecard_obj[$K]['timeout']=0; // CHECK IF THE USER IS ALLOW TO CALL WITH ITS CREDIT AMOUNT if ($credit < $A2B->agiconfig['min_credit_2call']){ return "ERROR CT1"; //NO ENOUGH CREDIT TO CALL THIS NUMBER } // if ($rateinitial==0) return "ERROR RATEINITIAL($rateinitial)"; $TIMEOUT = 0; if ($rateinitial<=0){ $this -> ratecard_obj[$K]['timeout']= $A2B->agiconfig['maxtime_tocall_negatif_free_route']; // 90 min if ($this -> debug_st) print_r($this -> ratecard_obj[$K]); return $TIMEOUT; } // 2 KIND OF CALCULATION : PROGRESSIVE RATE & FLAT RATE // IF FLAT RATE if (empty($chargea) || $chargea==0 || empty($timechargea) || $timechargea==0 ){ $num_min = $credit/$rateinitial; if ($this -> debug_st) echo "num_min:$num_min ($credit/$rateinitial)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo "num_sec:$num_sec \n"; if ($billingblock > 0) { $mod_sec = $num_sec % $billingblock; $num_sec=$num_sec-$mod_sec; } $TIMEOUT = $num_sec; // IF PROGRESSIVE RATE }else{ if ($this -> debug_st) echo "CYCLE A TIMEOUT:$TIMEOUT\n"; // CYCLE A $credit -= $stepchargea; //if ($credit<=0) return "ERROR CT2"; //NO ENOUGH CREDIT TO CALL THIS NUMBER if ($credit<=0){ if ($this -> freetimetocall_left[$K] > 0){ $this -> ratecard_obj[$K]['timeout'] = $this -> freetimetocall_left[$K]; if ($this -> debug_st) print_r($this -> ratecard_obj[$K]); return $this -> freetimetocall_left[$K]; }else{ return "ERROR CT2"; //NO ENOUGH CREDIT TO CALL THIS NUMBER } } if (!($chargea>0)) return "ERROR CHARGEA($chargea)"; $num_min = $credit/$chargea; if ($this -> debug_st) echo " CYCLEA num_min:$num_min ($credit/$chargea)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " CYCLEA num_sec:$num_sec \n"; if ($billingblocka > 0) { $mod_sec = $num_sec % $billingblocka; $num_sec=$num_sec-$mod_sec; } if (($num_sec>$timechargea) && !(empty($chargeb) || $chargeb==0 || empty($timechargeb) || $timechargeb==0) ){ $TIMEOUT += $timechargea; $credit -= ($chargea/60) * $timechargea; if ($this -> debug_st) echo " CYCLE B TIMEOUT:$TIMEOUT\n"; // CYCLE B $credit -= $stepchargeb; if ($credit<=0){ $this -> ratecard_obj[$K]['timeout'] = $TIMEOUT + $this -> freetimetocall_left[$K]; return $TIMEOUT + $this -> freetimetocall_left[$K]; //NO ENOUGH CREDIT TO GO TO THE CYCLE B } if (!($chargeb>0)) return "ERROR CHARGEB($chargeb)"; $num_min = $credit/$chargeb; if ($this -> debug_st) echo " CYCLEB num_min:$num_min ($credit/$chargeb)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " CYCLEB num_sec:$num_sec \n"; if ($billingblockb > 0) { $mod_sec = $num_sec % $billingblockb; $num_sec=$num_sec-$mod_sec; } if (($num_sec>$timechargeb) && !(empty($chargec) || $chargec==0 || empty($timechargec) || $timechargec==0) ) { $TIMEOUT += $timechargeb; $credit -= ($chargeb/60) * $timechargeb; if ($this -> debug_st) echo " CYCLE C TIMEOUT:$TIMEOUT\n"; // CYCLE C $credit -= $stepchargec; if ($credit<=0){ $this -> ratecard_obj[$K]['timeout'] = $TIMEOUT + $this -> freetimetocall_left[$K]; return $TIMEOUT + $this -> freetimetocall_left[$K]; //NO ENOUGH CREDIT TO GO TO THE CYCLE C } if (!($chargec>0)) return "ERROR CHARGEC($chargec)"; $num_min = $credit/$chargec; if ($this -> debug_st) echo " CYCLEC num_min:$num_min ($credit/$chargec)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " CYCLEC num_sec:$num_sec \n"; if ($billingblockc > 0) { $mod_sec = $num_sec % $billingblockc; $num_sec=$num_sec-$mod_sec; } if (($num_sec>$timechargec)){ if ($this -> debug_st) echo " OUT CYCLE C TIMEOUT:$TIMEOUT\n"; $TIMEOUT += $timechargec; $credit -= ($chargec/60) * $timechargec; // IF CYCLE C IS FINISH USE THE RATEINITIAL $num_min = $credit/$rateinitial; if ($this -> debug_st) echo " OUT CYCLEC num_min:$num_min ($credit/$rateinitial)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " OUT CYCLEC num_sec:$num_sec \n"; if ($billingblock > 0) { $mod_sec = $num_sec % $billingblock; $num_sec=$num_sec-$mod_sec; } $TIMEOUT += $num_sec; // THIS IS THE END }else{ $TIMEOUT += $num_sec; } }else{ if (($num_sec>$timechargeb)){ $TIMEOUT += $timechargeb; if ($this -> debug_st) echo " OUT CYCLE B TIMEOUT:$TIMEOUT\n"; $credit -= ($chargeb/60) * $timechargeb; // IF CYCLE B IS FINISH USE THE RATEINITIAL $num_min = $credit/$rateinitial; if ($this -> debug_st) echo " OUT CYCLEB num_min:$num_min ($credit/$rateinitial)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " OUT CYCLEB num_sec:$num_sec \n"; if ($billingblock > 0) { $mod_sec = $num_sec % $billingblock; $num_sec=$num_sec-$mod_sec; } $TIMEOUT += $num_sec; // THIS IS THE END }else{ $TIMEOUT += $num_sec; } } }else{ if (($num_sec>$timechargea)){ $TIMEOUT += $timechargea; if ($this -> debug_st) echo " OUT CYCLE A TIMEOUT:$TIMEOUT\n"; $credit -= ($chargea/60) * $timechargea; // IF CYCLE A IS FINISH USE THE RATEINITIAL $num_min = $credit/$rateinitial; if ($this -> debug_st) echo " OUT CYCLEA num_min:$num_min ($credit/$rateinitial)\n"; $num_sec = intval($num_min * 60); if ($this -> debug_st) echo " OUT CYCLEA num_sec:$num_sec \n";; if ($billingblock > 0) { $mod_sec = $num_sec % $billingblock; $num_sec=$num_sec-$mod_sec; } $TIMEOUT += $num_sec; // THIS IS THE END }else{ $TIMEOUT += $num_sec; } } } $this -> ratecard_obj[$K]['timeout']=$TIMEOUT + $this -> freetimetocall_left[$K]; if ($this -> debug_st) print_r($this -> ratecard_obj[$K]); RETURN $TIMEOUT + $this -> freetimetocall_left[$K]; } /* RATE ENGINE - CALCUL COST OF THE CALL * CALCUL THE CREDIT COSUMED BY THE CALL */ function rate_engine_calculcost (&$A2B, $callduration, $K=0, $freetimetocall_used){ $K = $this->usedratecard; $buyrate = round(abs($this -> ratecard_obj[$K][9]),4); $buyrateinitblock = $this -> ratecard_obj[$K][10]; $buyrateincrement = $this -> ratecard_obj[$K][11]; $rateinitial = round(abs($this -> ratecard_obj[$K][12]),4); $initblock = $this -> ratecard_obj[$K][13]; $billingblock = $this -> ratecard_obj[$K][14]; $connectcharge = round(abs($this -> ratecard_obj[$K][15]),4); $disconnectcharge = round(abs($this -> ratecard_obj[$K][16]),4); $stepchargea = $this -> ratecard_obj[$K][17]; $chargea = round(abs($this -> ratecard_obj[$K][18]),4); $timechargea = $this -> ratecard_obj[$K][19]; $billingblocka = $this -> ratecard_obj[$K][20]; $stepchargeb = $this -> ratecard_obj[$K][21]; $chargeb = round(abs($this -> ratecard_obj[$K][22]),4); $timechargeb = $this -> ratecard_obj[$K][23]; $billingblockb = $this -> ratecard_obj[$K][24]; $stepchargec = $this -> ratecard_obj[$K][25]; $chargec = round(abs($this -> ratecard_obj[$K][26]),4); $timechargec = $this -> ratecard_obj[$K][27]; $billingblockc = $this -> ratecard_obj[$K][28]; if (!is_numeric($freetimetocall_used)) $freetimetocall_used=0; if ($this -> debug_st) echo "CALLDURATION: $callduration - freetimetocall_used=$freetimetocall_used\n\n"; $A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CC_RATE_ENGINE_CALCULCOST: K=$K - CALLDURATION:$callduration - freetimetocall_used=$freetimetocall_used]"); $cost =0; $cost -= $connectcharge; $cost -= $disconnectcharge; // CALCULATION BUYRATE COST $buyratecallduration = $callduration; $buyratecost =0; if ($buyratecallduration<$buyrateinitblock) $buyratecallduration=$buyrateinitblock; if ($buyrateincrement > 0) { $mod_sec = $buyratecallduration % $buyrateincrement; if ($mod_sec>0) $buyratecallduration += ($buyrateincrement - $mod_sec); } $buyratecost -= ($buyratecallduration/60) * $buyrate; if ($this -> debug_st) echo "1. cost: $cost\n buyratecost:$buyratecost\n"; $callduration = $callduration - $freetimetocall_used; // 2 KIND OF CALCULATION : PROGRESSIVE RATE & FLAT RATE // IF FLAT RATE if (empty($chargea) || $chargea==0 || empty($timechargea) || $timechargea==0 ){ if ($callduration<$initblock) $callduration=$initblock; if ($billingblock > 0) { $mod_sec = $callduration % $billingblock; if ($mod_sec>0) $callduration += ($billingblock - $mod_sec); } $cost -= ($callduration/60) * $rateinitial; if ($this -> debug_st) echo "1.a cost: $cost\n"; $A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[TEMP - CC_RATE_ENGINE_CALCULCOST: 1. COST: $cost]:[ ($callduration/60) * $rateinitial ]"); // IF PROGRESSIVE RATE }else{ if ($this -> debug_st) echo "CYCLE A COST:$cost\n"; // CYCLE A $cost -= $stepchargea; if ($this -> debug_st) echo "1.A cost: $cost\n\n"; if ($callduration>$timechargea){ $duration_report = $callduration-$timechargea; $callduration=$timechargea; } if ($billingblocka > 0) { $mod_sec = $callduration % $billingblocka; if ($mod_sec>0) $callduration += ($billingblocka - $mod_sec); } $cost -= ($callduration/60) * $chargea; if (($duration_report>0) && !(empty($chargeb) || $chargeb==0 || empty($timechargeb) || $timechargeb==0) ) { $callduration=$duration_report; $duration_report=0; // CYCLE B $cost -= $stepchargeb; if ($this -> debug_st) echo "1.B cost: $cost\n\n"; if ($callduration>$timechargeb){ $duration_report = $callduration-$timechargeb; $callduration=$timechargeb; } if ($billingblockb > 0) { $mod_sec = $callduration % $billingblockb; if ($mod_sec>0) $callduration += ($billingblockb - $mod_sec); } $cost -= ($callduration/60) * $chargeb; // change chargea -> chargeb thanks to Abbas :D if (($duration_report>0) && !(empty($chargec) || $chargec==0 || empty($timechargec) || $timechargec==0) ) { $callduration=$duration_report; $duration_report=0; // CYCLE C $cost -= $stepchargec; if ($this -> debug_st) echo "1.C cost: $cost\n\n"; if ($callduration>$timechargec){ $duration_report = $callduration-$timechargec; $callduration=$timechargec; } if ($billingblockc > 0) { $mod_sec = $callduration % $billingblockc; if ($mod_sec>0) $callduration += ($billingblockc - $mod_sec); } $cost -= ($callduration/60) * $chargec; } } if ($duration_report>0){ if ($duration_report<$initblock) $duration_report=$initblock; if ($billingblock > 0) { $mod_sec = $duration_report % $billingblock; if ($mod_sec>0) $duration_report += ($billingblock - $mod_sec); } $cost -= ($duration_report/60) * $rateinitial; $A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[TEMP - CC_RATE_ENGINE_CALCULCOST: 2. DURATION_REPORT:$duration_report - COST: $cost]"); } } $cost = round($cost,4); if ($this -> debug_st) echo "FINAL COST: $cost\n\n"; $A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CC_RATE_ENGINE_CALCULCOST: K=$K - BUYCOST: $buyratecost - SELLING COST: $cost]"); $this -> lastcost = $cost; $this -> lastbuycost = $buyratecost; } /* SORT_ASC : Tri en ordre ascendant SORT_DESC : Tri en ordre descendant */ function array_csort() { $args = func_get_args(); $marray = array_shift($args); $i=0; $msortline = "return(array_multisort("; foreach ($args as $arg) { $i++; if (is_string($arg)) { foreach ($marray as $row) { $sortarr[$i][] = $row[$arg]; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -