Example #1
0
function getMaxCallTime($from, $to)
{
    $customer = getCustomerByPhone($from);
    include_tariff($customer['tariffid']);
    $call_cost = getCost($from, $to, $customer['tariffid']);
    return floor($customer['balance'] / $call_cost['costPerUnit']) * $call_cost['unitSize'];
}
Example #2
0
 $fh = isset($options['file']) ? fopen($options['file'], 'r') : fopen('php://stdin', 'r');
 $customer_list = getCustomerList();
 $error = array();
 $i = 0;
 while ($f_line = fgets($fh)) {
     // increment file line counter
     ++$i;
     // change line to associative array
     $cdr = parseRow($f_line);
     // check values of cdr array
     $cdr_error = validCDR($cdr);
     if ($cdr_error === TRUE) {
         $tariff_id = $customer_list[$cdr['caller']]['tariffid'];
         //include customer tariff
         if (!isset($tariffs[$tariff_id])) {
             include_tariff($tariff_id);
             if (!isset($tariffs[$tariff_id])) {
                 $error['errors'][] = array('line' => $i, 'line_content' => $f_line, 'error' => 'Can\'t find tariff ' . $tariff_id . ' in tariff files.');
                 continue;
             }
         }
         // set call type
         $call_type = parseCallType($cdr['call_type']);
         if ($call_type === NULL) {
             die('Call type is not correct. Please use incoming or outgoing.' . PHP_EOL);
         }
         // generate unix timestamp
         $call_start = mktime($cdr['call_start_hour'], $cdr['call_start_min'], $cdr['call_start_sec'], $cdr['call_start_month'], $cdr['call_start_day'], $cdr['call_start_year']);
         // no payments for incoming call else calculate cost for call
         $call_cost = getCost($cdr['caller'], $cdr['callee'], $tariff_id);
         switch ($call_type) {