Changeset 6 for www/finance/include.php


Ignore:
Timestamp:
Jan 16, 2008, 8:40:08 PM (17 years ago)
Author:
george
Message:

Upraveno: Aktualizace výpočtů tarifů ve financích.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/finance/include.php

    r4 r6  
    44function RecalculateTariffs($Period = 1)
    55{
    6   global $Tarify, $MaxSpeed, $Internet, $SpeedElement, $Database;
     6  global $Tarify, $MaxSpeed, $Internet, $SpeedElement, $BaseSpeedElement, $Database;
    77   
     8  $ResidualPrice = $Internet;
     9  $ResidualSpeed = $MaxSpeed;
     10 
    811  $Tarify = array();
    912  $DbResult = $Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY speed_factor');
     
    2326    $Row = $DbResult->fetch_array();
    2427    $Tarify[$Index]['user_count'] = $Row[0];   
    25     $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count'];
    26     $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
    27     $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units'];
     28    switch($Tarif['group_id'])
     29    {
     30      case 1:
     31        $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count'];
     32        $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     33        $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units'];
    2834   
    29     if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet
    30       $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1);
    31       else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count'];
    32     $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor'];
     35        if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet
     36          $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1);
     37          else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count'];
     38        $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor'];
     39        break;
     40      case 2:
     41        $ResidualPrice -= $Tarif['price'] * $Tarify[$Index]['user_count'];
     42        $ResidualSpeed -= $Tarif['min_speed'] * $Tarify[$Index]['user_count'];
     43        $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     44        break;
     45      case 3:
     46        $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     47        break;
     48    }
    3349  }
    34   $PricePerUnit = $Internet / $TotalTarifUnits;
    35   $SpeedPerUnit = $MaxSpeed * 1024 / $TotalTarifSpeedUnits;
     50  $PricePerUnit = $ResidualPrice / $TotalTarifUnits;
     51  $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits;
     52 
    3653  // Recalculate price
    37   $SpeedElement = 256*1024;
    3854  foreach($Tarify as $Index => $Tarif)
    3955  {
    40     $Tarify[$Index]['price'] = round($Tarif['price_units'] * $PricePerUnit);
    41     $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit);
    42     $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $SpeedElement);
     56    switch($Tarif['group_id'])
     57    {
     58      case 1:
     59        $Tarify[$Index]['price'] = round($Tarif['price_units'] * $PricePerUnit);
     60        $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit);
     61        $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $BaseSpeedElement * 1024);
     62        break;
     63      case 2:
     64        $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
     65        $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
     66        break;
     67      case 3:
     68        $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
     69        $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
     70        break;
     71    }
    4372    $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']);
    44     //echo($Tarify[$Index]['price'].'<br>');
    4573  }               
    4674}
     
    4977{
    5078  global $kWh, $Internet, $Sprava, $DatumOdecteni, $InternetUsers, $SpravaUsers, $InternetSegmentId,
    51     $MaxSpeed, $RealMaxSpeed, $SpeedReserve, $Database;
     79    $MaxSpeed, $RealMaxSpeed, $SpeedReserve, $BaseSpeedElement, $Database;
    5280   
    5381  $DbResult = $Database->query("SELECT * FROM finance_charge WHERE period=".$Period);
     
    5886  $RealMaxSpeed = $Row['internet_speed'];
    5987  $SpeedReserve = $Row['internet_speed_reserve'];
     88  $BaseSpeedElement = $Row['base_speed_element'];
    6089  $MaxSpeed = $RealMaxSpeed - $SpeedReserve;
    6190
Note: See TracChangeset for help on using the changeset viewer.